Debian Codegraph @

client/shaders/shadow/pass1_trans/opengl_vertex.glsl

raw
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
8 uniform float xyPerspectiveBias0;
9 uniform float xyPerspectiveBias1;
10 uniform float zPerspectiveBias;
11
12 CENTROID_ VARYING_ mediump vec2 varTexCoord;
13 CENTROID_ VARYING_ float varTexLayer; // actually int
14
15 vec4 getRelativePosition(in vec4 position)
16 {
17 vec2 l = position.xy - CameraPos.xy;
18 vec2 s = l / abs(l);
19 s = (1.0 - s * CameraPos.xy);
20 l /= s;
21 return vec4(l, s);
22 }
23
24 float getPerspectiveFactor(in vec4 relativePosition)
25 {
26 float pDistance = length(relativePosition.xy);
27 float pFactor = pDistance * xyPerspectiveBias0 + xyPerspectiveBias1;
28 return pFactor;
29 }
30
31 vec4 applyPerspectiveDistortion(in vec4 position)
32 {
33 vec4 l = getRelativePosition(position);
34 float pFactor = getPerspectiveFactor(l);
35 l.xy /= pFactor;
36 position.xy = l.xy * l.zw + CameraPos.xy;
37 position.z *= zPerspectiveBias;
38 return position;
39 }
40
41 void main()
42 {
43 vec4 pos = LightMVP * inVertexPosition;
44
45 tPos = applyPerspectiveDistortion(pos);
46
47 gl_Position = vec4(tPos.xyz, 1.0);
48
49 varTexCoord = (mTexture * vec4(inTexCoord0.xy, 1.0, 1.0)).st;
50 #ifdef USE_ARRAY_TEXTURE
51 varTexLayer = inVertexAux;
52 #endif
53
54 #ifdef COLORED_SHADOWS
55 varColor = inVertexColor.rgb;
56 #endif
57 }