/
shadowmap_vp.glsl
55 lines (42 loc) · 1.41 KB
/
shadowmap_vp.glsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#version 140
in vec4 attr_Position; // bound to attribute 0 in source, in object space
in vec4 attr_TexCoord; // bound to attribute 8 in source
uniform vec3 u_LightOrigin; // light origin in world coords
uniform mat4 u_ObjectTransform; // object transform (object2world)
// The two top-rows of the diffuse stage texture transformation matrix
uniform vec4 u_DiffuseTextureMatrix[2];
// The final diffuse texture coordinate at this vertex
varying vec2 var_TexDiffuse;
const mat3 cubicTransformations[6] = mat3[6]
(
mat3(0, 0, -1,
0, -1, 0,
-1, 0, 0),
mat3(0, 0, 1,
0, -1, 0,
1, 0, 0),
mat3(1, 0, 0,
0, 0, -1,
0, 1, 0),
mat3(1, 0, 0,
0, 0, 1,
0, -1, 0),
mat3(1, 0, 0,
0, -1, 0,
0, 0, -1),
mat3(-1, 0, 0,
0, -1, 0,
0, 0, 1)
);
void main()
{
// Transform the model vertex to world space, then subtract the light origin
// to move the vertex into light space (with the light residing at 0,0,0)
vec4 lightSpacePos = u_ObjectTransform * attr_Position;
lightSpacePos.xyz -= u_LightOrigin;
vec4 fragPos = vec4(cubicTransformations[gl_InstanceID] * lightSpacePos.xyz, 1);
gl_Position.x = fragPos.x / 6 + fragPos.z * 5/6 - fragPos.z / 3 * gl_InstanceID;
gl_Position.y = fragPos.y;
gl_Position.z = -fragPos.z - 2;
gl_Position.w = -fragPos.z;
}