]> git.tdb.fi Git - libs/gl.git/blob - tests/glsl/array_in_uniform_block.glsl
Fix a logic error in Sequence
[libs/gl.git] / tests / glsl / array_in_uniform_block.glsl
1 const int n_lights = 2;
2 struct LightParams
3 {
4         vec3 direction;
5         vec3 color;
6 };
7 uniform Lighting
8 {
9         LightParams lights[n_lights];
10 };
11 uniform vec3 ambient;
12 uniform mat4 model_matrix;
13 uniform mat4 view_matrix;
14 uniform mat4 proj_matrix;
15
16 #pragma MSP stage(vertex)
17 layout(location=0) in vec4 position;
18 layout(location=1) in vec3 normal;
19 out vec3 eye_light_dir[n_lights];
20 void main()
21 {
22         for(int i=0; i<n_lights; ++i)
23                 eye_light_dir[i] = mat3(view_matrix)*lights[i].direction;
24         out vec3 eye_normal = mat3(view_matrix*model_matrix)*normal;
25         gl_Position = proj_matrix*view_matrix*model_matrix*position;
26 }
27
28 #pragma MSP stage(fragment)
29 layout(location=0) out vec4 frag_color;
30 void main()
31 {
32         vec3 color = ambient;
33         for(int i=0; i<n_lights; ++i)
34                 color += max(dot(normalize(eye_normal), eye_light_dir[i]), 0.0)*lights[i].color;
35         frag_color = vec4(color, 1.0);
36 }
37
38 /* Expected output: vertex
39 struct LightParams
40 {
41   vec3 direction;
42   vec3 color;
43 };
44 layout(binding=5) uniform Lighting
45 {
46   LightParams lights[2];
47 };
48 layout(location=0) uniform mat4 model_matrix;
49 layout(location=4) uniform mat4 view_matrix;
50 layout(location=8) uniform mat4 proj_matrix;
51 layout(location=0) in vec4 position;
52 layout(location=1) in vec3 normal;
53 layout(location=0) out vec3 eye_light_dir[2];
54 layout(location=2) out vec3 eye_normal;
55 void main()
56 {
57   for(int i = 0; i<2; ++i)
58     eye_light_dir[i] = mat3(view_matrix[0].xyz, view_matrix[1].xyz, view_matrix[2].xyz)*lights[i].direction;
59   mat4 _temp = view_matrix*model_matrix;
60   eye_normal = mat3(_temp[0].xyz, _temp[1].xyz, _temp[2].xyz)*normal;
61   gl_Position = proj_matrix*view_matrix*model_matrix*position;
62 }
63 */
64
65 /* Expected output: fragment
66 struct LightParams
67 {
68   vec3 direction;
69   vec3 color;
70 };
71 layout(binding=5) uniform Lighting
72 {
73   LightParams lights[2];
74 };
75 layout(location=12) uniform vec3 ambient;
76 layout(location=0) out vec4 frag_color;
77 layout(location=2) in vec3 eye_normal;
78 layout(location=0) in vec3 eye_light_dir[2];
79 void main()
80 {
81   vec3 color = ambient;
82   for(int i = 0; i<2; ++i)
83     color += max(dot(normalize(eye_normal), eye_light_dir[i]), 0.0)*lights[i].color;
84   frag_color = vec4(color, 1.0);
85 }
86 */