2
0

pass1_trans_vertex.glsl 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 getRelativePosition(in vec4 position)
  11. {
  12. vec2 l = position.xy - CameraPos.xy;
  13. vec2 s = l / abs(l);
  14. s = (1.0 - s * CameraPos.xy);
  15. l /= s;
  16. return vec4(l, s);
  17. }
  18. float getPerspectiveFactor(in vec4 relativePosition)
  19. {
  20. float pDistance = length(relativePosition.xy);
  21. float pFactor = pDistance * xyPerspectiveBias0 + xyPerspectiveBias1;
  22. return pFactor;
  23. }
  24. vec4 applyPerspectiveDistortion(in vec4 position)
  25. {
  26. vec4 l = getRelativePosition(position);
  27. float pFactor = getPerspectiveFactor(l);
  28. l.xy /= pFactor;
  29. position.xy = l.xy * l.zw + CameraPos.xy;
  30. position.z *= zPerspectiveBias;
  31. return position;
  32. }
  33. void main()
  34. {
  35. vec4 pos = LightMVP * gl_Vertex;
  36. tPos = applyPerspectiveDistortion(LightMVP * gl_Vertex);
  37. gl_Position = vec4(tPos.xyz, 1.0);
  38. gl_TexCoord[0].st = gl_MultiTexCoord0.st;
  39. #ifdef COLORED_SHADOWS
  40. varColor = gl_Color.rgb;
  41. #endif
  42. }