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