shadowMap.vertex.fx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. #include<morphTargetsVertex>[0..maxSimultaneousMorphTargets]
  31. #include<instancesVertex>
  32. #include<bonesVertex>
  33. vec4 worldPos = finalWorld * vec4(positionUpdated, 1.0);
  34. // Normal inset Bias.
  35. #ifdef NORMAL
  36. mat3 normalWorld = mat3(finalWorld);
  37. #ifdef NONUNIFORMSCALING
  38. normalWorld = transposeMat3(inverseMat3(normalWorld));
  39. #endif
  40. vec3 worldNor = normalize(normalWorld * normal);
  41. #ifdef DIRECTIONINLIGHTDATA
  42. vec3 worldLightDir = normalize(-lightData.xyz);
  43. #else
  44. vec3 directionToLight = lightData.xyz - worldPos.xyz;
  45. vec3 worldLightDir = normalize(directionToLight);
  46. #endif
  47. float ndl = dot(worldNor, worldLightDir);
  48. float sinNL = sqrt(1.0 - ndl * ndl);
  49. float normalBias = biasAndScale.y * sinNL;
  50. worldPos.xyz -= worldNor * normalBias;
  51. #endif
  52. // Projection.
  53. gl_Position = viewProjection * worldPos;
  54. #ifdef DEPTHTEXTURE
  55. // Depth texture Linear bias.
  56. gl_Position.z += biasAndScale.x * gl_Position.w;
  57. #endif
  58. // Color Texture Linear bias.
  59. vDepthMetric = ((gl_Position.z + depthValues.x) / (depthValues.y)) + biasAndScale.x;
  60. #ifdef ALPHATEST
  61. #ifdef UV1
  62. vUV = vec2(diffuseMatrix * vec4(uv, 1.0, 0.0));
  63. #endif
  64. #ifdef UV2
  65. vUV = vec2(diffuseMatrix * vec4(uv2, 1.0, 0.0));
  66. #endif
  67. #endif
  68. }