1 const int n_lights = 2;
9 LightParams lights[n_lights];
12 uniform mat4 model_matrix;
13 uniform mat4 view_matrix;
14 uniform mat4 proj_matrix;
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];
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;
28 #pragma MSP stage(fragment)
29 layout(location=0) out vec4 frag_color;
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);
38 /* Expected output: vertex
44 layout(binding=5) uniform Lighting
46 LightParams lights[2];
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;
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;
65 /* Expected output: fragment
71 layout(binding=5) uniform Lighting
73 LightParams lights[2];
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];
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);