1 | uniform mat4 viewProjectionMatrix; |
---|
2 | uniform float numBones; |
---|
3 | uniform vec4 worldMatrix3x4Array[240]; |
---|
4 | uniform vec4 lightDiffuseColour; |
---|
5 | uniform vec4 ambient; |
---|
6 | uniform vec4 lightPos; |
---|
7 | |
---|
8 | attribute vec4 blendIndices; |
---|
9 | attribute vec4 blendWeights; |
---|
10 | |
---|
11 | |
---|
12 | void main() |
---|
13 | { |
---|
14 | vec3 blendPos = vec3(0,0,0); |
---|
15 | vec3 blendNorm = vec3(0,0,0); |
---|
16 | |
---|
17 | vec3 tmpPos = vec3(0,0,0); |
---|
18 | vec3 tmpNorm = vec3(0,0,0); |
---|
19 | |
---|
20 | |
---|
21 | int instanceOffset = int(gl_MultiTexCoord1.x) * 3 * int(numBones); |
---|
22 | for (int bone = 0; bone < 2; ++bone) |
---|
23 | { |
---|
24 | // perform matrix multiplication manually since no 3x4 matrices |
---|
25 | for (int row = 0; row < 3; ++row) |
---|
26 | { |
---|
27 | int idx = instanceOffset + int(blendIndices[bone]) * 3 + row; |
---|
28 | vec4 blendMatrixRow = worldMatrix3x4Array[idx]; |
---|
29 | tmpPos[row] = dot(blendMatrixRow, gl_Vertex); |
---|
30 | #if SHADOW_CASTER |
---|
31 | #else |
---|
32 | tmpNorm[row] = dot(blendMatrixRow.xyz, gl_Normal); |
---|
33 | #endif |
---|
34 | |
---|
35 | } |
---|
36 | // now weight this into final |
---|
37 | blendPos += tmpPos * blendWeights[bone]; |
---|
38 | #if SHADOW_CASTER |
---|
39 | #else |
---|
40 | blendNorm += tmpNorm * blendWeights[bone]; |
---|
41 | #endif |
---|
42 | } |
---|
43 | |
---|
44 | // apply view / projection to position |
---|
45 | gl_Position = viewProjectionMatrix * vec4(blendPos, 1); |
---|
46 | |
---|
47 | |
---|
48 | #if SHADOW_CASTER |
---|
49 | gl_FrontColor = ambient; |
---|
50 | #else |
---|
51 | // simple lighting model |
---|
52 | vec3 lightDir = normalize( |
---|
53 | lightPos.xyz - (blendPos.xyz * lightPos.w)); |
---|
54 | gl_FrontColor = ambient |
---|
55 | + clamp(dot(lightDir, blendNorm), 0.0, 1.0) * lightDiffuseColour; |
---|
56 | #endif |
---|
57 | gl_FrontSecondaryColor = vec4(0); |
---|
58 | gl_TexCoord[0] = gl_MultiTexCoord0; |
---|
59 | |
---|
60 | |
---|
61 | } |
---|
62 | |
---|