# graphics3d/jointblock (vanilla.js 0.4.0)

> https://vanillapunch.com/docs/vanilla.js/0.4.0/api/graphics3d/jointblock/

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

```js
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);
```

## Functions and constants

- `JOINT_BLOCK_MAXIMUM = 96` (field, since 0.4.0): Maximum joint count of the joint matrix block. (the same as the toon renderer's TOON_MAXIMUM_JOINTS and the skinning renderer)
  - returns number
- `JOINT_BLOCK_GLSL` (field, since 0.4.0): 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].
