shadowMap.vertex.fx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Attribute
  2. attribute vec3 position;
  3. #ifdef NORMAL
  4. attribute vec3 normal;
  5. uniform vec3 lightData;
  6. #endif
  7. #include<bonesDeclaration>
  8. #include<morphTargetsVertexGlobalDeclaration>
  9. #include<morphTargetsVertexDeclaration>[0..maxSimultaneousMorphTargets]
  10. // Uniforms
  11. #include<instancesDeclaration>
  12. #include<helperFunctions>
  13. uniform mat4 viewProjection;
  14. uniform vec3 biasAndScale;
  15. uniform vec2 depthValues;
  16. varying float vDepthMetric;
  17. #ifdef ALPHATEST
  18. varying vec2 vUV;
  19. uniform mat4 diffuseMatrix;
  20. #ifdef UV1
  21. attribute vec2 uv;
  22. #endif
  23. #ifdef UV2
  24. attribute vec2 uv2;
  25. #endif
  26. #endif
  27. void main(void)
  28. {
  29. vec3 positionUpdated = position;
  30. #ifdef UV1
  31. vec2 uvUpdated = uv;
  32. #endif
  33. #include<morphTargetsVertex>[0..maxSimultaneousMorphTargets]
  34. #include<instancesVertex>
  35. #include<bonesVertex>
  36. vec4 worldPos = finalWorld * vec4(positionUpdated, 1.0);
  37. // Normal inset Bias.
  38. #ifdef NORMAL
  39. mat3 normalWorld = mat3(finalWorld);
  40. #ifdef NONUNIFORMSCALING
  41. normalWorld = transposeMat3(inverseMat3(normalWorld));
  42. #endif
  43. vec3 worldNor = normalize(normalWorld * normal);
  44. #ifdef DIRECTIONINLIGHTDATA
  45. vec3 worldLightDir = normalize(-lightData.xyz);
  46. #else
  47. vec3 directionToLight = lightData.xyz - worldPos.xyz;
  48. vec3 worldLightDir = normalize(directionToLight);
  49. #endif
  50. float ndl = dot(worldNor, worldLightDir);
  51. float sinNL = sqrt(1.0 - ndl * ndl);
  52. float normalBias = biasAndScale.y * sinNL;
  53. worldPos.xyz -= worldNor * normalBias;
  54. #endif
  55. // Projection.
  56. gl_Position = viewProjection * worldPos;
  57. #ifdef DEPTHTEXTURE
  58. // Depth texture Linear bias.
  59. gl_Position.z += biasAndScale.x * gl_Position.w;
  60. #endif
  61. // Color Texture Linear bias.
  62. vDepthMetric = ((gl_Position.z + depthValues.x) / (depthValues.y)) + biasAndScale.x;
  63. #ifdef ALPHATEST
  64. #ifdef UV1
  65. vUV = vec2(diffuseMatrix * vec4(uvUpdated, 1.0, 0.0));
  66. #endif
  67. #ifdef UV2
  68. vUV = vec2(diffuseMatrix * vec4(uv2, 1.0, 0.0));
  69. #endif
  70. #endif
  71. }