#version 330 core // The avatar's skinning, in a renderer of your own: sona_pose_data.palette and the 76-byte vertex. uniform vec4 u_palette[216]; // 72 joints, 3 rows each: the pose's palette (or a prop's) uniform mat4 u_world; // the pose's world[16], uploaded as it is uniform mat4 u_view_proj; // your camera layout(location = 0) in vec3 a_position; // +0, float3 layout(location = 1) in vec4 a_joints; // +12, uint8 x4: a palette row each (joint x 3) layout(location = 2) in vec4 a_weights; // +16, uint8 x4, normalised: they add up to 1 layout(location = 3) in vec4 a_normal; // +20, uint8 x4, normalised layout(location = 4) in vec4 a_colour; // +24, uint8 x4, normalised: baked occlusion and alpha layout(location = 5) in vec4 a_uv01; // +28, float4: uv0, uv1 out vec3 v_normal; out vec4 v_colour; out vec4 v_uv01; vec4 row(int k) { ivec4 j = ivec4(a_joints) + k; return a_weights.x * u_palette[j.x] + a_weights.y * u_palette[j.y] + a_weights.z * u_palette[j.z] + a_weights.w * u_palette[j.w]; } void main() { vec4 r0 = row(0), r1 = row(1), r2 = row(2); vec4 p = vec4(a_position, 1.0); vec3 skinned = vec3(dot(r0, p), dot(r1, p), dot(r2, p)); vec3 n = a_normal.xyz * 2.0 - 1.0; vec3 normal = vec3(dot(r0.xyz, n), dot(r1.xyz, n), dot(r2.xyz, n)); v_normal = mat3(u_world) * normal; v_colour = a_colour; v_uv01 = a_uv01; gl_Position = u_view_proj * (u_world * vec4(skinned, 1.0)); }