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