pass1_trans_vertex.glsl 949 B

12345678910111213141516171819202122232425262728293031323334353637
  1. uniform mat4 LightMVP; // world matrix
  2. uniform vec4 CameraPos;
  3. varying vec4 tPos;
  4. #ifdef COLORED_SHADOWS
  5. varying vec3 varColor;
  6. #endif
  7. uniform float xyPerspectiveBias0;
  8. uniform float xyPerspectiveBias1;
  9. uniform float zPerspectiveBias;
  10. vec4 getPerspectiveFactor(in vec4 shadowPosition)
  11. {
  12. vec2 s = vec2(shadowPosition.x > CameraPos.x ? 1.0 : -1.0, shadowPosition.y > CameraPos.y ? 1.0 : -1.0);
  13. vec2 l = s * (shadowPosition.xy - CameraPos.xy) / (1.0 - s * CameraPos.xy);
  14. float pDistance = length(l);
  15. float pFactor = pDistance * xyPerspectiveBias0 + xyPerspectiveBias1;
  16. l /= pFactor;
  17. shadowPosition.xy = CameraPos.xy * (1.0 - l) + s * l;
  18. shadowPosition.z *= zPerspectiveBias;
  19. return shadowPosition;
  20. }
  21. void main()
  22. {
  23. vec4 pos = LightMVP * gl_Vertex;
  24. tPos = getPerspectiveFactor(LightMVP * gl_Vertex);
  25. gl_Position = vec4(tPos.xyz, 1.0);
  26. gl_TexCoord[0].st = gl_MultiTexCoord0.st;
  27. #ifdef COLORED_SHADOWS
  28. varColor = gl_Color.rgb;
  29. #endif
  30. }