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