@@ -32,6 +32,13 @@ VARYING_ float nightRatio;
3232const vec3 artificialLight = vec3 (1.04 , 1.04 , 1.04 );
3333VARYING_ float vIDiff;
3434
35+ #ifdef USE_SKINNING
36+ // TODO compute reasonable value in C++
37+ layout (std140) uniform JointMatrices {
38+ mat4 joints[128 ];
39+ };
40+ #endif
41+
3542#ifdef ENABLE_DYNAMIC_SHADOWS
3643
3744uniform float xyPerspectiveBias0;
@@ -89,16 +96,35 @@ float directional_ambient(vec3 normal)
8996
9097void main(void )
9198{
99+ #ifdef USE_SKINNING
100+ uvec4 jids = inVertexJointIDs;
101+ vec4 skinPos = inVertexPosition;
102+ vec3 skinNormal = inVertexNormal;
103+ // Alternatively: Introduce neutral bone at index 0 with identity matrix
104+ if (inVertexWeights != vec4 (0.0 )) {
105+ mat4 mSkin =
106+ inVertexWeights.x * joints[jids.x] +
107+ inVertexWeights.y * joints[jids.y] +
108+ inVertexWeights.z * joints[jids.z] +
109+ inVertexWeights.w * joints[jids.w];
110+ skinPos = vec4 ((mSkin * vec4 (inVertexPosition.xyz, 1.0 )).xyz, 1.0 );
111+ skinNormal = (mSkin * vec4 (inVertexNormal, 0.0 )).xyz;
112+ }
113+ #else
114+ vec4 skinPos = inVertexPosition;
115+ vec3 skinNormal = inVertexNormal;
116+ #endif
117+
92118#ifdef USE_ARRAY_TEXTURE
93119 varTexLayer = inVertexAux;
94120#endif
95121 varTexCoord = (mTexture * vec4 (inTexCoord0.xy, 1.0 , 1.0 )).st;
96122
97- gl_Position = mWorldViewProj * inVertexPosition ;
123+ gl_Position = mWorldViewProj * skinPos ;
98124
99- vNormal = (mWorld * vec4 (inVertexNormal , 0.0 )).xyz;
100- worldPosition = (mWorld * inVertexPosition ).xyz;
101- eyeVec = - (mWorldView * inVertexPosition ).xyz;
125+ vNormal = (mWorld * vec4 (skinNormal , 0.0 )).xyz;
126+ worldPosition = (mWorld * skinPos ).xyz;
127+ eyeVec = - (mWorldView * skinPos ).xyz;
102128
103129#if (MATERIAL_TYPE == TILE_MATERIAL_PLAIN) || (MATERIAL_TYPE == TILE_MATERIAL_PLAIN_ALPHA)
104130 vIDiff = 1.0 ;
0 commit comments