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