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