Debian Codegraph @

avogadro/rendering/sphere_ao_depth_vs.glsl

raw
1 //////////////////////////////////////////////////////////////////////
2 //
3 // Ambient occlusion shader for sphere impostors
4 //
5 // This vertex shader is used for rendering the depth texture from
6 // the light source's view.
7 //
8 //////////////////////////////////////////////////////////////////////
9
10 //
11 // Input
12 //
13 #version 400
14 precision highp float;
15 // sphere position: model coordinates
16 in vec3 a_pos;
17 // sphere corner: [-r, -r], [r, -r], [r, r], [-r, r]
18 in vec2 a_corner;
19
20 //
21 // Output
22 //
23
24 // normalized corner: [-1, 1]
25 out vec2 v_corner;
26
27 //
28 // Uniforms
29 //
30
31 // model-view matrix of the current light direction
32 uniform mat4 u_modelView;
33 // projection matrix
34 uniform mat4 u_projection;
35
36 void main()
37 {
38 // extract radius from unnormalized corner attribute
39 float radius = abs(a_corner.s);
40 // normalize corner to be in [-1, 1] range
41 v_corner = a_corner / radius;
42
43 // model coords -> eye coords
44 vec4 pos = u_modelView * vec4(a_pos, 1.0);
45 // translate position to corner taking radius into account
46 pos.xy += a_corner;
47 // eye coords -> clip coords
48 gl_Position = u_projection * pos;
49 }