]> git.sesse.net Git - nageru/blob - sor.vert
Split the equation texture in two, which speeds up SOR by ~30%.
[nageru] / sor.vert
1 #version 450 core
2
3 layout(location=0) in vec2 position;
4 out vec2 tc, tc_left, tc_down;
5 out vec2 equation_tc_assuming_left, equation_tc_assuming_right;
6 out float element_x_idx;
7 out float element_sum_idx;
8
9 uniform sampler2D diff_flow_tex, diffusivity_tex;
10 uniform usampler2D equation_red_tex;
11
12 void main()
13 {
14         // The result of glOrtho(0.0, 1.0, 0.0, 1.0, 0.0, 1.0) is:
15         //
16         //   2.000  0.000  0.000 -1.000
17         //   0.000  2.000  0.000 -1.000
18         //   0.000  0.000 -2.000 -1.000
19         //   0.000  0.000  0.000  1.000
20         gl_Position = vec4(2.0 * position.x - 1.0, 2.0 * position.y - 1.0, -1.0, 1.0);
21         tc = position;
22         tc_left = vec2(tc.x - 0.5f / textureSize(diffusivity_tex, 0).x, tc.y);
23         tc_down = vec2(tc.x, tc.y - 0.5f / textureSize(diffusivity_tex, 0).y);
24
25         // The equation textures have half the horizontal width, so we need to adjust the texel centers.
26         // It becomes extra tricky since the SOR texture might be of odd size, and then
27         // the equation texture is not exactly half the size.
28         vec2 element_idx = position * textureSize(diff_flow_tex, 0) - 0.5f;
29         float equation_texel_number_assuming_left = element_idx.x / 2.0f;
30         float equation_texel_number_assuming_right = (element_idx.x - 1.0f) / 2.0f;
31         equation_tc_assuming_left.x = (equation_texel_number_assuming_left + 0.5f) / textureSize(equation_red_tex, 0).x;
32         equation_tc_assuming_right.x = (equation_texel_number_assuming_right + 0.5f) / textureSize(equation_red_tex, 0).x;
33         equation_tc_assuming_left.y = tc.y;
34         equation_tc_assuming_right.y = tc.y;
35
36         element_x_idx = element_idx.x;
37         element_sum_idx = element_idx.x + element_idx.y;
38 }