5 uniform mat4 model_matrix;
6 uniform mat4 view_matrix;
7 uniform mat4 proj_matrix;
9 #pragma MSP stage(vertex)
10 layout(location=0) in vec4 vertex;
13 out vec4 world_vertex = model_matrix*vertex;
14 vec3 eye_pos = inverse(view_matrix)[3].xyz;
15 out vec3 world_look_dir = normalize(world_vertex.xyz-eye_pos);
16 gl_Position = proj_matrix*view_matrix*world_vertex;
19 #pragma MSP stage(fragment)
20 layout(location=0) out vec4 frag_color;
21 float calculate_lighting(vec3 look_dir)
23 float intensity = 0.0;
24 for(int i=0; i<3; ++i)
25 intensity += max(dot(look_dir, light_dir[i]), 0.0);
30 float light_intensity = calculate_lighting(world_look_dir);
31 frag_color = vec4(vec3(light_intensity), 1.0);
34 /* Expected output: vertex
35 layout(location=0) uniform mat4 model_matrix;
36 layout(location=4) uniform mat4 view_matrix;
37 layout(location=8) uniform mat4 proj_matrix;
38 layout(location=0) in vec4 vertex;
39 layout(location=0) out vec4 world_vertex;
40 layout(location=1) out vec3 world_look_dir;
43 world_vertex = model_matrix*vertex;
44 world_look_dir = normalize(world_vertex.xyz-inverse(view_matrix)[3].xyz);
45 gl_Position = proj_matrix*view_matrix*world_vertex;
49 /* Expected output: fragment
50 layout(binding=5) uniform Lighting
54 layout(location=0) out vec4 frag_color;
55 float calculate_lighting(vec3 look_dir)
57 float intensity = 0.0;
58 for(int i = 0; i<3; ++i)
59 intensity += max(dot(look_dir, light_dir[i]), 0.0);
62 layout(location=1) in vec3 world_look_dir;
65 frag_color = vec4(vec3(calculate_lighting(world_look_dir)), 1.0);