[3e8cc8b] | 1 | #version 450
|
---|
| 2 | #extension GL_ARB_separate_shader_objects : enable
|
---|
| 3 |
|
---|
| 4 | struct Object {
|
---|
| 5 | mat4 model;
|
---|
| 6 | float hp;
|
---|
[4ece3bf] | 7 | bool deleted;
|
---|
[3e8cc8b] | 8 | };
|
---|
| 9 |
|
---|
| 10 | layout (binding = 0) uniform UniformBufferObject {
|
---|
| 11 | mat4 view;
|
---|
| 12 | mat4 proj;
|
---|
| 13 | } ubo;
|
---|
| 14 |
|
---|
| 15 | layout(binding = 1) readonly buffer StorageBufferObject {
|
---|
[6385d0f] | 16 | Object objects[];
|
---|
[3e8cc8b] | 17 | } sbo;
|
---|
| 18 |
|
---|
| 19 | layout(location = 0) in vec3 vertex_position;
|
---|
| 20 | layout(location = 1) in vec3 vertex_color;
|
---|
[b8efa56] | 21 | layout(location = 2) in vec2 inTexCoord;
|
---|
| 22 | layout(location = 3) in vec3 vertex_normal;
|
---|
| 23 | layout(location = 4) in uint obj_index;
|
---|
[3e8cc8b] | 24 |
|
---|
| 25 | layout(location = 0) out vec3 position_eye;
|
---|
| 26 | layout(location = 1) out vec3 color;
|
---|
[b8efa56] | 27 | layout(location = 2) out vec2 fragTexCoord;
|
---|
| 28 | layout(location = 3) out vec3 normal_eye;
|
---|
| 29 | layout(location = 4) out vec3 light_position_eye;
|
---|
| 30 | layout(location = 5) out vec3 light2_position_eye;
|
---|
[3e8cc8b] | 31 |
|
---|
| 32 | // fixed point light position
|
---|
| 33 | vec3 light_position_world = vec3(0.0, 0.0, 2.0);
|
---|
| 34 | vec3 light2_position_world = vec3(0.0, 1.5, -0.1);
|
---|
| 35 |
|
---|
| 36 | void main() {
|
---|
[6385d0f] | 37 | position_eye = vec3(ubo.view * sbo.objects[obj_index].model * vec4(vertex_position, 1.0));
|
---|
| 38 | normal_eye = normalize(vec3(ubo.view * sbo.objects[obj_index].model * vec4(vertex_normal, 0.0)));
|
---|
[3e8cc8b] | 39 |
|
---|
[6385d0f] | 40 | float hp_percent = sbo.objects[obj_index].hp / 10.0;
|
---|
| 41 | vec3 damage_color = vec3(1.0, 0.0, 0.0);
|
---|
| 42 | color = (vertex_color * hp_percent) + (damage_color * (1.0 - hp_percent));
|
---|
[3e8cc8b] | 43 |
|
---|
[b8efa56] | 44 | fragTexCoord = inTexCoord;
|
---|
| 45 |
|
---|
[6385d0f] | 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));
|
---|
[3e8cc8b] | 48 |
|
---|
[6385d0f] | 49 | if (sbo.objects[obj_index].deleted) {
|
---|
| 50 | gl_Position = vec4(0.0, 0.0, 2.0, 1.0);
|
---|
| 51 | } else {
|
---|
| 52 | gl_Position = ubo.proj * vec4(position_eye, 1.0);
|
---|
| 53 | }
|
---|
[3e8cc8b] | 54 | }
|
---|