Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/Shader_HS18/programs/Example/GLSL/skinningTwoWeightsShadowCasterVp.glsl @ 12083

Last change on this file since 12083 was 12083, checked in by wiesep, 6 years ago

Reorganised shader programs

File size: 1.6 KB
Line 
1// Example GLSL program for skinning with two bone weights per vertex
2
3attribute vec4 vertex;
4attribute vec4 uv0;
5attribute vec4 blendIndices;
6attribute vec4 blendWeights;
7
8// 3x4 matrix, passed as vec4's for compatibility with GL 2.0
9// GL 2.0 supports 3x4 matrices
10// Support 24 bones ie 24*3, but use 72 since our parser can pick that out for sizing
11uniform vec4 worldMatrix3x4Array[72];
12uniform mat4 viewProjectionMatrix;
13uniform vec4 ambient;
14
15void main()
16{
17        vec3 blendPos = 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                blendPos += (vertex * worldMatrix).xyz * blendWeights[bone];
34        }
35
36        // apply view / projection to position
37        gl_Position = viewProjectionMatrix * vec4(blendPos, 1);
38       
39        gl_FrontSecondaryColor = vec4(0,0,0,0);
40        gl_FrontColor = ambient;
41        gl_TexCoord[0] = uv0;
42}
Note: See TracBrowser for help on using the repository browser.