Debian Codegraph @

avogadro/rendering/sphere_ao_bake_vs.glsl

raw
1 //////////////////////////////////////////////////////////////////////
2 //
3 // Ambient occlusion shader for sphere impostors
4 //
5 // This fragment shader is used for baking the ambient occlusion
6 // maps.
7 //
8 //////////////////////////////////////////////////////////////////////
9
10 //
11 // Input
12 //
13
14 #version 400
15 precision highp float;
16 // sphere center position: model coords
17 in vec3 a_pos;
18 // corner: [-radius, radius]
19 in vec2 a_corner;
20 // offset for the center of the sphere's AO map texture tile
21 in vec2 a_tileOffset;
22
23 //
24 // Output
25 //
26
27 // the sphere center position: eye coords
28 out vec3 v_pos;
29 // the sphere radius
30 out float v_radius;
31 // stretched corner: [-1.x, 1.x] (see below)
32 out vec2 v_corner;
33
34 //
35 // Uniforms
36 //
37
38 // the model-view matrix
39 uniform mat4 u_modelView;
40 // the size of the AO texture [pixels] (e.g. 1024)
41 uniform float u_textureSize;
42 // the size of a single tile in texture coords [0, 1]
43 uniform float u_tileSize;
44
45 void main()
46 {
47 // pass through radius
48 v_radius = abs(a_corner.s);
49 // position: model coords -> eye coords
50 v_pos = vec3(u_modelView * vec4(a_pos, 1.0));
51
52 // normalize corner: [-radius, radius] -> [-1, 1]
53 vec2 corner = a_corner / v_radius;
54 // enlarge texture space to trim half a texel from the tile
55 // note: v_corner is in range [-1, 1] so we add 2 / (tile size in pixels)
56 v_corner = corner * (1.0 + 2.0 / (u_textureSize * u_tileSize));
57
58 // NDC are in range [-1, 1], the * 2 - 1 translates and scales the position to [0, 1]
59 gl_Position = vec4(a_tileOffset * 2.0 - vec2(1.0) + corner * u_tileSize, 0.0, 1.0);
60 }