1 | #version 150 |
---|
2 | |
---|
3 | mat2x4 blendTwoWeightsAntipod(vec4 blendWgt, vec4 blendIdx, vec4 dualQuaternions[24]); |
---|
4 | vec3 calculateBlendPosition(vec3 position, mat2x4 blendDQ); |
---|
5 | vec3 calculateBlendNormal(vec3 normal, mat2x4 blendDQ); |
---|
6 | |
---|
7 | uniform vec4 worldDualQuaternion2x4Array[24]; |
---|
8 | uniform mat4 viewProjectionMatrix; |
---|
9 | uniform vec4 lightPos[2]; |
---|
10 | uniform vec4 lightDiffuseColour[2]; |
---|
11 | uniform vec4 ambient; |
---|
12 | |
---|
13 | in vec4 vertex; |
---|
14 | in vec3 normal; |
---|
15 | in vec4 blendIndices; |
---|
16 | in vec4 blendWeights; |
---|
17 | in vec4 uv0; |
---|
18 | |
---|
19 | out vec4 oUv0; |
---|
20 | out vec4 ambientColour; |
---|
21 | |
---|
22 | void main() |
---|
23 | { |
---|
24 | mat2x4 blendDQ = blendTwoWeightsAntipod(blendWeights, blendIndices, worldDualQuaternion2x4Array); |
---|
25 | |
---|
26 | float len = length(blendDQ[0]); |
---|
27 | blendDQ /= len; |
---|
28 | |
---|
29 | vec3 blendPosition = calculateBlendPosition(vertex.xyz, blendDQ); |
---|
30 | |
---|
31 | //No need to normalize, the magnitude of the normal is preserved because only rotation is performed |
---|
32 | vec3 blendNormal = calculateBlendNormal(normal, blendDQ); |
---|
33 | |
---|
34 | gl_Position = viewProjectionMatrix * vec4(blendPosition, 1.0); |
---|
35 | |
---|
36 | // Lighting - support point and directional |
---|
37 | vec3 lightDir0 = normalize(lightPos[0].xyz - (blendPosition * lightPos[0].w)); |
---|
38 | vec3 lightDir1 = normalize(lightPos[1].xyz - (blendPosition * lightPos[1].w)); |
---|
39 | |
---|
40 | oUv0 = uv0; |
---|
41 | |
---|
42 | ambientColour = /*gl_FrontMaterial.diffuse **/ (ambient + (clamp(dot(lightDir0, blendNormal), 0.0, 1.0) * lightDiffuseColour[0]) + |
---|
43 | (clamp(dot(lightDir1, blendNormal), 0.0, 1.0) * lightDiffuseColour[1])); |
---|
44 | } |
---|
45 | |
---|