1 | #version 100 |
---|
2 | |
---|
3 | precision mediump int; |
---|
4 | precision mediump float; |
---|
5 | |
---|
6 | attribute vec4 vertex; |
---|
7 | attribute vec4 normal; |
---|
8 | attribute vec4 uv0; |
---|
9 | attribute vec4 uv1; // pose1pos |
---|
10 | attribute vec4 uv2; // pose1norm |
---|
11 | attribute vec4 uv3; // pose2pos |
---|
12 | attribute vec4 uv4; // pose2norm |
---|
13 | |
---|
14 | varying vec2 oUv; |
---|
15 | varying vec4 colour; |
---|
16 | |
---|
17 | uniform mat4 worldViewProj; |
---|
18 | uniform vec4 anim_t; |
---|
19 | uniform vec4 objSpaceLightPos; |
---|
20 | uniform vec4 ambient; |
---|
21 | |
---|
22 | // hardware pose animation (with normals) |
---|
23 | void main() |
---|
24 | { |
---|
25 | // interpolate position |
---|
26 | vec4 posinterp = vec4(vertex.xyz + anim_t.x*uv1.xyz + anim_t.y*uv3.xyz, 1.0); |
---|
27 | |
---|
28 | // nlerp normal |
---|
29 | // nlerp normal |
---|
30 | // First apply the pose normals (these are actual normals, not offsets) |
---|
31 | vec3 ninterp = anim_t.x*uv2.xyz + anim_t.y*uv4.xyz; |
---|
32 | |
---|
33 | // Now add back any influence of the original normal |
---|
34 | // This depends on what the cumulative weighting left the normal at, if it's lacking or cancelled out |
---|
35 | //float remainder = 1.0 - min(anim_t.x + anim_t.y, 1.0); |
---|
36 | float remainder = 1.0 - min(length(ninterp), 1.0); |
---|
37 | ninterp = ninterp + (normal.xyz * remainder); |
---|
38 | ninterp = normalize(ninterp); |
---|
39 | |
---|
40 | gl_Position = worldViewProj * posinterp; |
---|
41 | oUv = uv0.xy; |
---|
42 | |
---|
43 | vec3 lightDir = normalize( |
---|
44 | objSpaceLightPos.xyz - (posinterp.xyz * objSpaceLightPos.w)); |
---|
45 | |
---|
46 | // Colour it red to make it easy to identify |
---|
47 | float lit = clamp(dot(lightDir, ninterp), 0.0, 1.0); |
---|
48 | colour = vec4((ambient.rgb + vec3(lit,lit,lit)) * vec3(1.0,0.0,0.0), 1.0); |
---|
49 | } |
---|