1 | #version 450
|
---|
2 | #extension GL_ARB_separate_shader_objects : enable
|
---|
3 |
|
---|
4 | layout (binding = 0) uniform UniformBufferObject {
|
---|
5 | mat4 model;
|
---|
6 | mat4 view;
|
---|
7 | mat4 proj;
|
---|
8 | } ubo;
|
---|
9 |
|
---|
10 | layout(location = 0) in vec3 vertex_position;
|
---|
11 | layout(location = 1) in vec3 vertex_color;
|
---|
12 | layout(location = 2) in vec3 vertex_normal;
|
---|
13 | //layout(location = 3) in uint ubo_index;
|
---|
14 |
|
---|
15 | layout(location = 0) out vec3 position_eye;
|
---|
16 | layout(location = 1) out vec3 color;
|
---|
17 | layout(location = 2) out vec3 normal_eye;
|
---|
18 | layout(location = 3) out vec3 light_position_eye;
|
---|
19 |
|
---|
20 | // fixed point light position
|
---|
21 | //vec3 light_position_world = vec3(0.0, 0.0, 2.0);
|
---|
22 | vec3 light_position_world = vec3(0.4, 1.5, 0.8);
|
---|
23 | //vec3 light_position_world = vec3(0.0, 1.0, -1.0);
|
---|
24 |
|
---|
25 | // TODO: This does not account for scaling in the model matrix
|
---|
26 | // Check Anton's book to see how to fix this
|
---|
27 | void main() {
|
---|
28 | position_eye = vec3(ubo.view * ubo.model * vec4(vertex_position, 1.0));
|
---|
29 | //position_eye = vec3(view * model_mats[ubo_index] * vec4(vertex_position, 1.0));
|
---|
30 |
|
---|
31 | // Using 0.0 instead of 1.0 means translations won't effect the normal
|
---|
32 | normal_eye = normalize(vec3(ubo.view * ubo.model * vec4(vertex_normal, 0.0)));
|
---|
33 | //normal_eye = normalize(vec3(view * model_mats[ubo_index] * vec4(vertex_normal, 0.0)));
|
---|
34 | color = vertex_color;
|
---|
35 | light_position_eye = vec3(ubo.view * vec4(light_position_world, 1.0));
|
---|
36 |
|
---|
37 | gl_Position = ubo.proj * vec4(position_eye, 1.0);
|
---|
38 | }
|
---|