createShadowMapInstancingVS.glsl 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #version 330
  2. precision highp float;
  3. layout (location = 0) in vec4 position;
  4. layout (location = 1) in vec4 instance_position;
  5. layout (location = 2) in vec4 instance_quaternion;
  6. layout (location = 3) in vec2 uvcoords;
  7. layout (location = 4) in vec3 vertexnormal;
  8. layout (location = 5) in vec4 instance_color;
  9. layout (location = 6) in vec3 instance_scale;
  10. uniform mat4 depthMVP;
  11. vec4 quatMul ( in vec4 q1, in vec4 q2 )
  12. {
  13. vec3 im = q1.w * q2.xyz + q1.xyz * q2.w + cross ( q1.xyz, q2.xyz );
  14. vec4 dt = q1 * q2;
  15. float re = dot ( dt, vec4 ( -1.0, -1.0, -1.0, 1.0 ) );
  16. return vec4 ( im, re );
  17. }
  18. vec4 quatFromAxisAngle(vec4 axis, in float angle)
  19. {
  20. float cah = cos(angle*0.5);
  21. float sah = sin(angle*0.5);
  22. float d = inversesqrt(dot(axis,axis));
  23. vec4 q = vec4(axis.x*sah*d,axis.y*sah*d,axis.z*sah*d,cah);
  24. return q;
  25. }
  26. //
  27. // vector rotation via quaternion
  28. //
  29. vec4 quatRotate3 ( in vec3 p, in vec4 q )
  30. {
  31. vec4 temp = quatMul ( q, vec4 ( p, 0.0 ) );
  32. return quatMul ( temp, vec4 ( -q.x, -q.y, -q.z, q.w ) );
  33. }
  34. vec4 quatRotate ( in vec4 p, in vec4 q )
  35. {
  36. vec4 temp = quatMul ( q, p );
  37. return quatMul ( temp, vec4 ( -q.x, -q.y, -q.z, q.w ) );
  38. }
  39. void main(void)
  40. {
  41. vec4 q = instance_quaternion;
  42. vec4 localcoord = quatRotate3( position.xyz*instance_scale,q);
  43. vec4 vertexPos = depthMVP * vec4( (instance_position+localcoord).xyz,1);
  44. gl_Position = vertexPos;
  45. }