[12115] | 1 | #version 120 |
---|
| 2 | // Example GLSL program for skinning with two bone weights per vertex |
---|
| 3 | |
---|
| 4 | attribute vec4 vertex; |
---|
| 5 | attribute vec3 normal; |
---|
| 6 | attribute vec4 uv0; |
---|
| 7 | attribute vec4 blendIndices; |
---|
| 8 | attribute vec4 blendWeights; |
---|
| 9 | |
---|
| 10 | // ogre <> glsl notation is transposed |
---|
| 11 | uniform mat4x3 worldMatrix3x4Array[24]; |
---|
| 12 | uniform mat4 viewProjectionMatrix; |
---|
| 13 | uniform vec4 lightPos[2]; |
---|
| 14 | uniform vec4 lightDiffuseColour[2]; |
---|
| 15 | uniform vec4 ambient; |
---|
| 16 | uniform vec4 diffuse; |
---|
| 17 | |
---|
| 18 | void main() |
---|
| 19 | { |
---|
| 20 | vec3 blendPos = vec3(0.0, 0.0, 0.0); |
---|
| 21 | vec3 blendNorm = vec3(0.0, 0.0, 0.0); |
---|
| 22 | |
---|
| 23 | for (int bone = 0; bone < 2; ++bone) |
---|
| 24 | { |
---|
| 25 | // ATI GLSL compiler can't handle indexing an array within an array so calculate the inner index first |
---|
| 26 | int idx = int(blendIndices[bone]); |
---|
| 27 | |
---|
| 28 | // now weight this into final |
---|
| 29 | float weight = blendWeights[bone]; |
---|
| 30 | blendPos += worldMatrix3x4Array[idx]* vertex * weight; |
---|
| 31 | |
---|
| 32 | mat3 worldRotMatrix = mat3(worldMatrix3x4Array[idx]); |
---|
| 33 | blendNorm += (worldRotMatrix * normal) * weight; |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | blendNorm = normalize(blendNorm); |
---|
| 37 | |
---|
| 38 | // apply view / projection to position |
---|
| 39 | gl_Position = viewProjectionMatrix * vec4(blendPos, 1.0); |
---|
| 40 | |
---|
| 41 | // simple vertex lighting model |
---|
| 42 | vec3 lightDir0 = normalize( |
---|
| 43 | lightPos[0].xyz - (blendPos * lightPos[0].w)); |
---|
| 44 | vec3 lightDir1 = normalize( |
---|
| 45 | lightPos[1].xyz - (blendPos * lightPos[1].w)); |
---|
| 46 | |
---|
| 47 | gl_FrontColor = gl_FrontMaterial.diffuse * (ambient + (clamp(dot(lightDir0, blendNorm), 0.0, 1.0) * lightDiffuseColour[0]) + |
---|
| 48 | (clamp(dot(lightDir1, blendNorm), 0.0, 1.0) * lightDiffuseColour[1])); |
---|
| 49 | |
---|
| 50 | gl_TexCoord[0] = uv0; |
---|
| 51 | } |
---|