]> git.tdb.fi Git - libs/gl.git/blob - tests/glsl/empty_loop_removal.glsl
Remove conditional and iteration statements with no effect from GLSL
[libs/gl.git] / tests / glsl / empty_loop_removal.glsl
1 uniform Lighting
2 {
3         vec4 light_dir[2];
4 };
5 uniform Transform
6 {
7         mat4 vp;
8         mat4 model;
9 };
10 const bool use_light = false;
11
12 #pragma MSP stage(vertex)
13 layout(location=0) in vec4 vertex;
14 layout(location=1) in vec3 normal;
15 out vec3 world_light_dir[2];
16 void main()
17 {
18         vec4 world_vertex = model*vertex;
19         out vec3 world_normal = mat3(model)*normal;
20         gl_Position = vp*world_vertex;
21         for(int i=0; i<2; ++i)
22                 world_light_dir[i] = light_dir[i].xyz-world_vertex.xyz*light_dir[i].w;
23 }
24
25 #pragma MSP stage(fragment)
26 layout(location=0) out vec4 frag_color;
27 void main()
28 {
29         vec3 color = vec3(0.1);
30         if(use_light)
31         {
32                 for(int i=0; i<2; ++i)
33                 {
34                         float intensity = max(dot(normalize(world_normal), world_light_dir[i]), 0.0);
35                         color += intensity;
36                 }
37         }
38         frag_color = vec4(color, 1.0);
39 }
40
41 /* Expected output: vertex
42 layout(binding=48) uniform Transform
43 {
44         mat4 vp;
45         mat4 model;
46 };
47 layout(location=0) in vec4 vertex;
48 void main()
49 {
50         gl_Position = vp*model*vertex;
51 }
52 */
53
54 /* Expected output: fragment
55 layout(location=0) out vec4 frag_color;
56 void main()
57 {
58         frag_color = vec4(vec3(0.1), 1.0);
59 }
60 */