1 /**
2 *  Geometry pash shader for bone-animated meshes.  Uses standard Geometry fragment shader
3 */
4 module dash.graphics.shaders.glsl.animatedgeometry;
5 import dash.graphics.shaders.glsl;
6 
7 package:
8 
9 /// Animated Geometry Shader.  Transforms vertices by bone-weights
10 immutable string animatedGeometryVS = glslVersion ~ q{
11     layout(location = 0) in vec3 vPosition_m;
12     layout(location = 1) in vec2 vUV;
13     layout(location = 2) in vec3 vNormal_m;
14     layout(location = 3) in vec3 vTangent_m;
15     layout(location = 4) in vec4 vBone_m;
16     layout(location = 5) in vec4 vWeight_m;
17 
18     out vec4 fPosition_s;
19     out vec3 fNormal_v;
20     out vec2 fUV;
21     out vec3 fTangent_v;
22     flat out uint fObjectId;
23 
24     uniform mat4 worldView;
25     uniform mat4 worldViewProj;
26     uniform uint objectId;
27 
28     uniform mat4[100] bones;
29 
30     void main( void )
31     {
32         // Calculate vertex change from animation
33         mat4 boneTransform = bones[ int(vBone_m[ 0 ]) ] * vWeight_m[ 0 ];
34         boneTransform += bones[ int(vBone_m[ 1 ]) ] * vWeight_m[ 1 ];
35         boneTransform += bones[ int(vBone_m[ 2 ]) ] * vWeight_m[ 2 ];
36         boneTransform += bones[ int(vBone_m[ 3 ]) ] * vWeight_m[ 3 ];
37 
38         // gl_Position is like SV_Position
39         fPosition_s = worldViewProj * ( boneTransform * vec4( vPosition_m, 1.0f ) );
40         gl_Position = fPosition_s;
41         fUV = vUV;
42 
43         fNormal_v = ( worldView * boneTransform * vec4( vNormal_m, 0.0f ) ).xyz;
44         fTangent_v =  ( worldView * boneTransform * vec4( vTangent_m, 0.0f ) ).xyz;
45         fObjectId = objectId;
46     }
47 };