Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/SuperOrxoBros_HS18/data_extern/programs/skinningTwoWeightsVp.glsl @ 12175

Last change on this file since 12175 was 12175, checked in by siramesh, 5 years ago

Super Orxo Bros (Sidharth Ramesh, Nisa Balta, Jeff Ren)

File size: 2.1 KB
Line 
1// Example GLSL program for skinning with two bone weights per vertex
2
3attribute vec4 blendIndices;
4attribute vec4 blendWeights;
5
6// 3x4 matrix, passed as vec4's for compatibility with GL 2.0
7// GL 2.0 supports 3x4 matrices
8// Support 24 bones ie 24*3, but use 72 since our parser can pick that out for sizing
9uniform vec4 worldMatrix3x4Array[72];
10uniform mat4 viewProjectionMatrix;
11uniform vec4 lightPos[2];
12uniform vec4 lightDiffuseColour[2];
13
14void main()
15{
16        vec3 blendPos = vec3(0,0,0);
17        vec3 blendNorm = vec3(0,0,0);
18       
19        for (int bone = 0; bone < 2; ++bone)
20        {
21                // perform matrix multiplication manually since no 3x4 matrices
22        // ATI GLSL compiler can't handle indexing an array within an array so calculate the inner index first
23            int idx = int(blendIndices[bone]) * 3;
24        // ATI GLSL compiler can't handle unrolling the loop so do it manually
25        // ATI GLSL has better performance when mat4 is used rather than using individual dot product
26        // There is a bug in ATI mat4 constructor (Cat 7.2) when indexed uniform array elements are used as vec4 parameter so manually assign
27                mat4 worldMatrix;
28                worldMatrix[0] = worldMatrix3x4Array[idx];
29                worldMatrix[1] = worldMatrix3x4Array[idx + 1];
30                worldMatrix[2] = worldMatrix3x4Array[idx + 2];
31                worldMatrix[3] = vec4(0);
32                // now weight this into final
33            float weight = blendWeights[bone];
34                blendPos += (gl_Vertex * worldMatrix).xyz * weight;
35               
36                mat3 worldRotMatrix = mat3(worldMatrix[0].xyz, worldMatrix[1].xyz, worldMatrix[2].xyz);
37                blendNorm += (gl_Normal * worldRotMatrix) * weight;
38
39        }
40
41        // apply view / projection to position
42        gl_Position = viewProjectionMatrix * vec4(blendPos, 1);
43
44        // simple vertex lighting model
45        vec3 lightDir0 = normalize(
46                lightPos[0].xyz -  (blendPos.xyz * lightPos[0].w));
47        vec3 lightDir1 = normalize(
48                lightPos[1].xyz -  (blendPos.xyz * lightPos[1].w));
49               
50        gl_FrontSecondaryColor = vec4(0);
51        gl_FrontColor = vec4(0.5, 0.5, 0.5, 1.0) 
52                + clamp(dot(lightDir0, blendNorm), 0.0, 1.0) * lightDiffuseColour[0]
53                + clamp(dot(lightDir1, blendNorm), 0.0, 1.0) * lightDiffuseColour[1];
54
55        gl_TexCoord[0] = gl_MultiTexCoord0;
56       
57}
Note: See TracBrowser for help on using the repository browser.