shadowMap.vertex.fx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 USEDISTANCE
  18. varying vec3 vPositionW;
  19. #endif
  20. #ifdef ALPHATEST
  21. varying vec2 vUV;
  22. uniform mat4 diffuseMatrix;
  23. #ifdef UV1
  24. attribute vec2 uv;
  25. #endif
  26. #ifdef UV2
  27. attribute vec2 uv2;
  28. #endif
  29. #endif
  30. #ifdef DEPTHCLAMP
  31. varying float z;
  32. #endif
  33. #include<clipPlaneVertexDeclaration>
  34. void main(void)
  35. {
  36. vec3 positionUpdated = position;
  37. #ifdef UV1
  38. vec2 uvUpdated = uv;
  39. #endif
  40. #include<morphTargetsVertex>[0..maxSimultaneousMorphTargets]
  41. #include<instancesVertex>
  42. #include<bonesVertex>
  43. vec4 worldPos = finalWorld * vec4(positionUpdated, 1.0);
  44. // Normal inset Bias.
  45. #ifdef NORMAL
  46. mat3 normalWorld = mat3(finalWorld);
  47. #ifdef NONUNIFORMSCALING
  48. normalWorld = transposeMat3(inverseMat3(normalWorld));
  49. #endif
  50. vec3 worldNor = normalize(normalWorld * normal);
  51. #ifdef DIRECTIONINLIGHTDATA
  52. vec3 worldLightDir = normalize(-lightData.xyz);
  53. #else
  54. vec3 directionToLight = lightData.xyz - worldPos.xyz;
  55. vec3 worldLightDir = normalize(directionToLight);
  56. #endif
  57. float ndl = dot(worldNor, worldLightDir);
  58. float sinNL = sqrt(1.0 - ndl * ndl);
  59. float normalBias = biasAndScale.y * sinNL;
  60. worldPos.xyz -= worldNor * normalBias;
  61. #endif
  62. #ifdef USEDISTANCE
  63. vPositionW = worldPos.xyz;
  64. #endif
  65. // Projection.
  66. gl_Position = viewProjection * worldPos;
  67. #ifdef DEPTHTEXTURE
  68. // Depth texture Linear bias.
  69. gl_Position.z += biasAndScale.x * gl_Position.w;
  70. #endif
  71. #ifdef DEPTHCLAMP
  72. z = gl_Position.z;
  73. gl_Position.z = 0.0;
  74. #elif !defined(USEDISTANCE)
  75. // Color Texture Linear bias.
  76. vDepthMetric = ((gl_Position.z + depthValues.x) / (depthValues.y)) + biasAndScale.x;
  77. #endif
  78. #ifdef ALPHATEST
  79. #ifdef UV1
  80. vUV = vec2(diffuseMatrix * vec4(uvUpdated, 1.0, 0.0));
  81. #endif
  82. #ifdef UV2
  83. vUV = vec2(diffuseMatrix * vec4(uv2, 1.0, 0.0));
  84. #endif
  85. #endif
  86. #include<clipPlaneVertex>
  87. }