--- /dev/null
+uniform Lighting
+{
+ vec3 light_dir[3];
+};
+uniform mat4 model_matrix;
+uniform mat4 view_matrix;
+uniform mat4 proj_matrix;
+
+#pragma MSP stage(vertex)
+layout(location=0) in vec4 vertex;
+void main()
+{
+ out vec4 world_vertex = model_matrix*vertex;
+ vec3 eye_pos = inverse(view_matrix)[3].xyz;
+ out vec3 world_look_dir = normalize(world_vertex.xyz-eye_pos);
+ gl_Position = proj_matrix*view_matrix*world_vertex;
+}
+
+#pragma MSP stage(fragment)
+layout(location=0) out vec4 frag_color;
+float calculate_lighting(vec3 look_dir)
+{
+ float intensity = 0.0;
+ for(int i=0; i<3; ++i)
+ intensity += max(dot(look_dir, light_dir[i]), 0.0);
+ return intensity;
+}
+void main()
+{
+ float light_intensity = calculate_lighting(world_look_dir);
+ frag_color = vec4(vec3(light_intensity), 1.0);
+}
+
+/* Expected output: vertex
+layout(location=0) uniform mat4 model_matrix;
+layout(location=4) uniform mat4 view_matrix;
+layout(location=8) uniform mat4 proj_matrix;
+layout(location=0) in vec4 vertex;
+layout(location=0) out vec4 world_vertex;
+layout(location=1) out vec3 world_look_dir;
+void main()
+{
+ world_vertex = model_matrix*vertex;
+ world_look_dir = normalize(world_vertex.xyz-inverse(view_matrix)[3].xyz);
+ gl_Position = proj_matrix*view_matrix*world_vertex;
+}
+*/
+
+/* Expected output: fragment
+layout(binding=5) uniform Lighting
+{
+ vec3 light_dir[3];
+};
+layout(location=0) out vec4 frag_color;
+float calculate_lighting(vec3 look_dir)
+{
+ float intensity = 0.0;
+ for(int i = 0; i<3; ++i)
+ intensity += max(dot(look_dir, light_dir[i]), 0.0);
+ return intensity;
+}
+layout(location=1) in vec3 world_look_dir;
+void main()
+{
+ frag_color = vec4(vec3(calculate_lighting(world_look_dir)), 1.0);
+}
+*/