Debian Codegraph @

resources/shaders/decorate_shadow/sm/depth.vert

raw
1 //uniform float far;
2 //uniform float near;
3 uniform float width;
4 uniform vec3 meshCenter;
5
6 /*uniform mat4 modelViewMX;
7 uniform mat4 prjMX;
8 */
9 void main(void)
10 {
11
12 //vec3 lightPosition = vec3(-1.0,0.0,0.0);
13 vec4 lightPosition = gl_ModelViewMatrix * gl_LightSource[0].position;
14 //Reproduce GL_LookAt behaviour
15 //create ortonormal basis for lightspace
16 vec3 newZ = normalize(lightPosition .xyz);
17 vec3 newX = normalize(cross(newZ, vec3(0.0, 0.80001, 0.0)));
18 vec3 newY = normalize(cross(newX, newZ));
19
20
21 mat4 toLightSpaceRot = mat4(
22 newX.x, newY.x, newZ.x, 0.0,
23 newX.y, newY.y, newZ.y, 0.0,
24 newX.z, newY.z, newZ.z, 0.0,
25 0.0, 0.0, 0.0, 1.0
26 );
27
28
29
30 //Perform parallel Ortographic projection
31 float nearP = - (width / 2.0);//meshCenter.z - (width / 2.0); //distance of Front clipping plane from VRP measured along VPN (a.k.a. lightDir)
32 float farP = (width / 2.0);//meshCenter.z + (width / 2.0);//distance of Back clipping plane from VRP measured along VPN (a.k.a. lightDir)
33 float leftP = meshCenter.x - width/2.0;
34 float rightP = meshCenter.x + width/2.0;
35 float bottomP = meshCenter.y - width/2.0;
36 float topP = meshCenter.y + width/2.0;
37
38
39 mat4 parallelViewProject = mat4(
40 2.0/(rightP-leftP), 0.0, 0.0, 0.0,
41 0.0, 2.0/(topP-bottomP), 0.0, 0.0,
42 0.0, 0.0, 2.0/(farP - nearP), 0.0,
43 -(rightP + leftP)/(rightP - leftP), -(topP + bottomP)/(topP-bottomP), -(farP + nearP)/(farP - nearP), 1.0
44 );
45
46
47 gl_Position = parallelViewProject
48 * toLightSpaceRot
49 * gl_Vertex;
50
51 }
52
53 /*void main(){
54 gl_Position = ftransform();
55 }*/