API / graphics3d/jointblock
graphics3d/jointblock
뼈 행렬 유니폼 블록. (버텍스 셰이더의 jointMatrices 를 기본 블록 유니폼이 아닌 유니폼 블록으로 넘긴다)
Joint matrix uniform block. (passes the vertex shader's jointMatrices through a uniform block instead of a default block uniform)
예제Example대체 스키닝 버텍스 셰이더에 뼈 행렬 블록 끼우기Inserting the joint matrix block into a replacement skinning vertex shader
import { JOINT_BLOCK_GLSL, JOINT_BLOCK_MAXIMUM } from "./vanilla.js";
const vertexShaderSource = `#version 300 es
layout(location = 0) in vec3 vertexPosition;
layout(location = 3) in uvec4 vertexJoints;
layout(location = 4) in vec4 vertexWeights;
${JOINT_BLOCK_GLSL}
void main() {
mat4 skinMatrix = vertexWeights.x * jointMatrices[vertexJoints.x] + vertexWeights.y * jointMatrices[vertexJoints.y];
gl_Position = skinMatrix * vec4(vertexPosition, 1.0);
}`;
console.log(vertexShaderSource.includes("uniform JointBlock"), JOINT_BLOCK_MAXIMUM);상수Constants
뼈 행렬 블록의 뼈 최대 수. (툰 렌더러 TOON_MAXIMUM_JOINTS 와 스키닝 렌더러가 같다)
Maximum joint count of the joint matrix block. (the same as the toon renderer's TOON_MAXIMUM_JOINTS and the skinning renderer)
반환Returnsnumber
버텍스 셰이더에 끼우는 뼈 행렬 블록 선언.
- 뼈 행렬 96 개는 vec4 384 칸이라 WebGL2 가 보장하는 최소 정점 유니폼 256 칸을 넘는다. 유니폼 블록은 따로 센다(MAX_UNIFORM_BLOCK_SIZE 최소 16384 바이트, 이 블록은 6144 바이트).
- 모바일에서 유니티는 스키닝 행렬을 상수 버퍼(GPU 스키닝)로, 언리얼은 뼈 버퍼를 읽어 넘기는 것과 같은 길이다.
- 인스턴스 이름이 없어 셰이더 본문은 jointMatrices[번호] 그대로 쓴다. 바인딩 자리는 ShaderProgram 이 링크 뒤에 JOINT_BLOCK_BINDING 으로 묶는다.
- SkinnedModelRenderer 에 대체 버텍스 셰이더를 줄 때는 uniform mat4 jointMatrices[96] 대신 이 선언을 끼운다.
The joint matrix block declaration inserted into a vertex shader.
- 96 joint matrices take 384 vec4 slots, over the 256 vertex uniform slots WebGL2 guarantees at minimum. A uniform block is counted separately (MAX_UNIFORM_BLOCK_SIZE is at least 16384 bytes, this block is 6144 bytes).
- On mobile, Unity passes skinning matrices through a constant buffer (GPU skinning) and Unreal reads a bone buffer, which is the same route.
- With no instance name, the shader body keeps using jointMatrices[index]. ShaderProgram binds it to JOINT_BLOCK_BINDING after linking.
- When giving SkinnedModelRenderer a replacement vertex shader, insert this declaration in place of uniform mat4 jointMatrices[96].