]> git.tdb.fi Git - libs/gl.git/blob - tests/glsl/unused_variable_removal_iteration.glsl
Recognize backwards dependencies in GLSL loops
[libs/gl.git] / tests / glsl / unused_variable_removal_iteration.glsl
1 uniform Params
2 {
3         float start_height;
4         float max_height;
5         float min_height;
6         float step_size;
7 };
8
9 #pragma MSP stage(vertex)
10 layout(location=0) in vec4 position;
11 void main()
12 {
13         gl_Position = position;
14         out vec3 dir = vec3(position.xy, 1.0);
15 }
16
17 #pragma MSP stage(fragment)
18 layout(location=0) out vec4 frag_color;
19 void main()
20 {
21         vec3 ndir = normalize(dir);
22         vec3 pos = vec3(0.0, 0.0, start_height);
23         float luminance = 0.0;
24         float extinction = 0.0;
25         while(true)
26         {
27                 if(pos.z<min_height || pos.z>max_height)
28                         break;
29
30                 float density = exp(pos.z/-1000.0);
31                 luminance += density*exp(-extinction);
32
33                 extinction += density*step_size;
34                 pos += ndir*step_size;
35         }
36
37         frag_color = vec4(vec3(luminance), 1.0);
38 }
39
40 /* Expected output: vertex
41 layout(location=0) in vec4 position;
42 layout(location=0) out vec3 dir;
43 void main()
44 {
45         gl_Position = position;
46         dir = vec3(position.xy, 1.0);
47 }
48 */
49
50 /* Expected output: fragment
51 layout(binding=80) uniform Params
52 {
53         float start_height;
54         float max_height;
55         float min_height;
56         float step_size;
57 };
58 layout(location=0) out vec4 frag_color;
59 layout(location=0) in vec3 dir;
60 void main()
61 {
62         vec3 ndir = normalize(dir);
63         vec3 pos = vec3(0.0, 0.0, start_height);
64         float luminance = 0.0;
65         float extinction = 0.0;
66         while(true)
67         {
68                 if(pos.z<min_height || pos.z>max_height)
69                         break;
70                 float density = exp(pos.z/-1000.0);
71                 luminance += density*exp(-extinction);
72                 extinction += density*step_size;
73                 pos += ndir*step_size;
74         }
75         frag_color = vec4(vec3(luminance), 1.0);
76 }
77 */