Fixes recursion bug in disambiguate_in().
[ohcount] / test / src_dir / foo_glsl.vert
1 // from OGRE3D's skinningTwoWeightsShadowCasterVp.glsl
2 // Example GLSL program for skinning with two bone weights per vertex
3
4 attribute vec4 vertex;
5 attribute vec4 uv0;
6 attribute vec4 blendIndices;
7 attribute vec4 blendWeights;
8
9 // 3x4 matrix, passed as vec4's for compatibility with GL 2.0
10 // GL 2.0 supports 3x4 matrices
11 // Support 24 bones ie 24*3, but use 72 since our parser can pick that out for sizing
12 uniform vec4 worldMatrix3x4Array[72];
13 uniform mat4 viewProjectionMatrix;
14 uniform vec4 ambient;
15
16 void main()
17 {
18         vec3 blendPos = vec3(0,0,0);
19
20         for (int bone = 0; bone < 2; ++bone)
21         {
22                 // perform matrix multiplication manually since no 3x4 matrices
23         // ATI GLSL compiler can't handle indexing an array within an array so calculate the inner index first
24             int idx = int(blendIndices[bone]) * 3;
25         // ATI GLSL compiler can't handle unrolling the loop so do it manually
26         // ATI GLSL has better performance when mat4 is used rather than using individual dot product
27         // There is a bug in ATI mat4 constructor (Cat 7.2) when indexed uniform array elements are used as vec4 parameter so manually assign
28                 mat4 worldMatrix;
29                 worldMatrix[0] = worldMatrix3x4Array[idx];
30                 worldMatrix[1] = worldMatrix3x4Array[idx + 1];
31                 worldMatrix[2] = worldMatrix3x4Array[idx + 2];
32                 worldMatrix[3] = vec4(0);
33                 // now weight this into final 
34                 blendPos += (vertex * worldMatrix).xyz * blendWeights[bone];
35         }
36
37         // apply view / projection to position
38         gl_Position = viewProjectionMatrix * vec4(blendPos, 1);
39         
40         gl_FrontSecondaryColor = vec4(0,0,0,0);
41         gl_FrontColor = ambient;
42         gl_TexCoord[0] = uv0;
43 }