graphics3d/jointblock
뼈 행렬 유니폼 블록. (원본 graphics3d/jointblock.js)
- 뼈 행렬 96 개는 vec4 384 칸이라 WebGL2 가 보장하는 최소 정점 유니폼 256 칸(MAX_VERTEX_UNIFORM_VECTORS)을 넘는다. 데스크탑 GPU 는 4096 칸이라 넘어도 돌지만 안드로이드 크롬(갤럭시 Z 폴드3)은 링크에 실패한다. 큰 배열은 유니폼 블록으로 넘긴다. (모바일에서 유니티는 스키닝 행렬을 상수 버퍼로, 언리얼은 뼈 버퍼를 읽어 넘기는 것과 같은 길이다)
- 블록은 std140 이라 mat4 는 열 우선 vec4 넷이고 f32 16 개가 그대로 들어간다. 셰이더 본문은 jointMatrices[번호] 그대로 쓴다.
- 바인딩 자리는 ShaderProgram 이 링크 뒤에 JOINT_BLOCK_BINDING 으로 묶는다.
- SkinnedModelRenderer 에 대체 버텍스 셰이더를 줄 때는
uniform mat4 jointMatrices[96];대신 JOINT_BLOCK_GLSL 을 끼운다.
Joint matrix uniform block. (original graphics3d/jointblock.js)
- 96 joint matrices are 384 vec4 slots, which exceeds the 256 vertex uniform slots (MAX_VERTEX_UNIFORM_VECTORS) that WebGL2 guarantees at minimum. Desktop GPUs have 4096 slots so it still runs there, but Android Chrome (Galaxy Z Fold3) fails to link. Large arrays go through a uniform block. (On mobile, Unity passes skinning matrices as a constant buffer and Unreal reads a bone buffer, the same approach)
- The block is std140, so a mat4 is four column-major vec4 and 16 f32 values fit as they are. The shader body uses jointMatrices[index] unchanged.
- ShaderProgram binds the binding point to JOINT_BLOCK_BINDING after linking.
- When giving SkinnedModelRenderer a replacement vertex shader, insert JOINT_BLOCK_GLSL instead of
uniform mat4 jointMatrices[96];.
use vanilla::{JOINT_BLOCK_GLSL, JOINT_BLOCK_MAXIMUM};
let vertex_shader_source = format!("#version 300 es\nlayout(location = 0) in vec3 vertexPosition;\nlayout(location = 3) in uvec4 vertexJoints;\nlayout(location = 4) in vec4 vertexWeights;\n{}\nvoid main() {{\n\tmat4 skinMatrix = vertexWeights.x * jointMatrices[vertexJoints.x] + vertexWeights.y * jointMatrices[vertexJoints.y];\n\tgl_Position = skinMatrix * vec4(vertexPosition, 1.0);\n}}", JOINT_BLOCK_GLSL);
assert!(vertex_shader_source.contains("uniform JointBlock"));
assert_eq!(JOINT_BLOCK_MAXIMUM, 96);JointBlockBufferstruct
뼈 행렬 블록 버퍼. (원본 JointBlockBuffer, 컨텍스트마다 렌더러가 하나씩 갖는다)
Joint matrix block buffer. (original JointBlockBuffer; each renderer owns one per context)
use vanilla::JOINT_BLOCK_MAXIMUM;
// The buffer needs a GL context, so only the size is checked here. (96 joints x 64 bytes per mat4 = 6144 bytes, within the 16384 minimum of MAX_UNIFORM_BLOCK_SIZE)
assert!(JOINT_BLOCK_MAXIMUM * 64 <= 16384);생성. (버퍼를 짓지 못하면 그 오류 글을 담은 Err)
Creation. (Err carrying the error text if the buffer cannot be created)
- gl&GlContext
- GL 컨텍스트.GL context.
반환ReturnsResult<JointBlockBuffer, String> 뼈 행렬 6144 바이트를 담을 유니폼 버퍼. 버퍼를 짓지 못하면 Err(오류 글).A uniform buffer that holds 6144 bytes of joint matrices. Err(error text) if the buffer cannot be created.
뼈 행렬 올리고 바인딩 자리에 묶기. (JOINT_BLOCK_MAXIMUM 개를 넘는 뒤쪽은 버린다, 같은 값이면 올리지 않고 묶기만 한다)
Upload joint matrices and bind to the binding point. (anything past JOINT_BLOCK_MAXIMUM is dropped; if the values are unchanged it only binds without uploading)
- gl&GlContext
- 버퍼를 만든 GL 컨텍스트.The GL context that created the buffer.
- values&[f32]
- 뼈 행렬의 수. (16 의 배수)Number of joint matrices. (a multiple of 16)
지우기.
Disposes.
- gl&GlContext
- 버퍼를 만든 GL 컨텍스트.The GL context that created the buffer.
상수Constants
뼈 행렬 블록의 뼈 최대 수. (툰 렌더러 TOON_MAXIMUM_JOINTS 와 스키닝 렌더러가 같다)
Maximum joint count of the joint matrix block. (the same for the toon renderer's TOON_MAXIMUM_JOINTS and the skinning renderer)
반환Returnsusize
짝Counterpart: vanilla.js JOINT_BLOCK_MAXIMUM
모프 가중치 배열의 vec4 칸 수. (MORPH_TARGET_MAXIMUM 96 개를 네 개씩)
Number of vec4 slots in the morph weight array. (MORPH_TARGET_MAXIMUM 96 weights, four per slot)
반환Returnsusize
뼈 행렬 블록 선언. (원본 JOINT_BLOCK_GLSL)
Joint matrix block declaration. (original JOINT_BLOCK_GLSL)
반환Returns&str
짝Counterpart: vanilla.js JOINT_BLOCK_GLSL