shadowMap.vertex.fx 1.8 KB

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