1 | #version 100 |
---|
2 | |
---|
3 | precision highp int; |
---|
4 | precision highp float; |
---|
5 | |
---|
6 | // Example GLSL ES program for skinning with two bone weights per vertex |
---|
7 | |
---|
8 | attribute vec4 vertex; |
---|
9 | attribute vec4 uv0; |
---|
10 | attribute vec3 normal; |
---|
11 | attribute vec4 blendIndices; |
---|
12 | attribute vec4 blendWeights; |
---|
13 | |
---|
14 | varying vec4 colour; |
---|
15 | varying vec4 uv; |
---|
16 | |
---|
17 | // 3x4 matrix, passed as vec4's for compatibility with GL ES 2.0 |
---|
18 | // Support 24 bones ie 24*3, but use 72 since our parser can pick that out for sizing |
---|
19 | uniform vec4 worldMatrix3x4Array[72]; |
---|
20 | uniform mat4 viewProjectionMatrix; |
---|
21 | uniform vec4 lightPos[2]; |
---|
22 | uniform vec4 lightDiffuseColour[2]; |
---|
23 | uniform vec4 ambient; |
---|
24 | uniform vec4 diffuse; |
---|
25 | |
---|
26 | void main() |
---|
27 | { |
---|
28 | vec3 blendPos = vec3(0.0); |
---|
29 | vec3 blendNorm = vec3(0.0); |
---|
30 | |
---|
31 | for (int bone = 0; bone < 2; ++bone) |
---|
32 | { |
---|
33 | // perform matrix multiplication manually since no 3x4 matrices |
---|
34 | int idx = int(blendIndices[bone]) * 3; |
---|
35 | |
---|
36 | mat4 worldMatrix; |
---|
37 | worldMatrix[0] = worldMatrix3x4Array[idx]; |
---|
38 | worldMatrix[1] = worldMatrix3x4Array[idx + 1]; |
---|
39 | worldMatrix[2] = worldMatrix3x4Array[idx + 2]; |
---|
40 | worldMatrix[3] = vec4(0.0); |
---|
41 | // now weight this into final |
---|
42 | float weight = blendWeights[bone]; |
---|
43 | blendPos += (vertex * worldMatrix).xyz * weight; |
---|
44 | |
---|
45 | mat3 worldRotMatrix = mat3(worldMatrix[0].xyz, worldMatrix[1].xyz, worldMatrix[2].xyz); |
---|
46 | blendNorm += (normal * worldRotMatrix) * weight; |
---|
47 | } |
---|
48 | |
---|
49 | // apply view / projection to position |
---|
50 | gl_Position = viewProjectionMatrix * vec4(blendPos, 1.0); |
---|
51 | |
---|
52 | // simple vertex lighting model |
---|
53 | vec3 lightDir0 = normalize( |
---|
54 | lightPos[0].xyz - (blendPos.xyz * lightPos[0].w)); |
---|
55 | vec3 lightDir1 = normalize( |
---|
56 | lightPos[1].xyz - (blendPos.xyz * lightPos[1].w)); |
---|
57 | |
---|
58 | |
---|
59 | colour = diffuse * (ambient |
---|
60 | + clamp(dot(lightDir0, blendNorm), 0.0, 1.0) * lightDiffuseColour[0] |
---|
61 | + clamp(dot(lightDir1, blendNorm), 0.0, 1.0) * lightDiffuseColour[1]); |
---|
62 | uv = uv0; |
---|
63 | } |
---|