]> git.tdb.fi Git - libs/gl.git/blob - tests/glsl/array_in_uniform_block.glsl
Fix GLSL test cases so they pass the basic tests
[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 // Target API: OpenGL
39
40 /* Expected output: vertex
41 struct LightParams
42 {
43   vec3 direction;
44   vec3 color;
45 };
46 layout(binding=5) uniform Lighting
47 {
48   LightParams lights[2];
49 };
50 layout(location=0) uniform mat4 model_matrix;
51 layout(location=4) uniform mat4 view_matrix;
52 layout(location=8) uniform mat4 proj_matrix;
53 layout(location=0) in vec4 position;
54 layout(location=1) in vec3 normal;
55 layout(location=0) out vec3 eye_light_dir[2];
56 layout(location=2) out vec3 eye_normal;
57 void main()
58 {
59   for(int i = 0; i<2; ++i)
60     eye_light_dir[i] = mat3(view_matrix[0].xyz, view_matrix[1].xyz, view_matrix[2].xyz)*lights[i].direction;
61   mat4 _temp = view_matrix*model_matrix;
62   eye_normal = mat3(_temp[0].xyz, _temp[1].xyz, _temp[2].xyz)*normal;
63   gl_Position = proj_matrix*view_matrix*model_matrix*position;
64   gl_Position.z = gl_Position.z*2.0-gl_Position.w;
65 }
66 */
67
68 /* Expected output: fragment
69 struct LightParams
70 {
71   vec3 direction;
72   vec3 color;
73 };
74 layout(binding=5) uniform Lighting
75 {
76   LightParams lights[2];
77 };
78 layout(location=12) uniform vec3 ambient;
79 layout(location=0) out vec4 frag_color;
80 layout(location=2) in vec3 eye_normal;
81 layout(location=0) in vec3 eye_light_dir[2];
82 void main()
83 {
84   vec3 color = ambient;
85   for(int i = 0; i<2; ++i)
86     color += max(dot(normalize(eye_normal), eye_light_dir[i]), 0.0)*lights[i].color;
87   frag_color = vec4(color, 1.0);
88 }
89 */