2
0

pass1_vertex.glsl 1002 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. uniform mat4 LightMVP; // world matrix
  2. uniform vec4 CameraPos; // camera position
  3. varying vec4 tPos;
  4. uniform float xyPerspectiveBias0;
  5. uniform float xyPerspectiveBias1;
  6. uniform float zPerspectiveBias;
  7. vec4 getRelativePosition(in vec4 position)
  8. {
  9. vec2 l = position.xy - CameraPos.xy;
  10. vec2 s = l / abs(l);
  11. s = (1.0 - s * CameraPos.xy);
  12. l /= s;
  13. return vec4(l, s);
  14. }
  15. float getPerspectiveFactor(in vec4 relativePosition)
  16. {
  17. float pDistance = length(relativePosition.xy);
  18. float pFactor = pDistance * xyPerspectiveBias0 + xyPerspectiveBias1;
  19. return pFactor;
  20. }
  21. vec4 applyPerspectiveDistortion(in vec4 position)
  22. {
  23. vec4 l = getRelativePosition(position);
  24. float pFactor = getPerspectiveFactor(l);
  25. l.xy /= pFactor;
  26. position.xy = l.xy * l.zw + CameraPos.xy;
  27. position.z *= zPerspectiveBias;
  28. return position;
  29. }
  30. void main()
  31. {
  32. vec4 pos = LightMVP * gl_Vertex;
  33. tPos = applyPerspectiveDistortion(pos);
  34. gl_Position = vec4(tPos.xyz, 1.0);
  35. gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
  36. }