feature/imgui-sdl
points-test
Last change
on this file since 7bf5433 was 25b47d7, checked in by Dmitry Portnoy <dmp1488@…>, 6 years ago |
Correctly send the hp of each asteroid to the shader using a uniform array and allow the player to damage and destroy the asteroids with lasers.
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Rev | Line | |
---|
[ec4456b] | 1 | #version 410
|
---|
| 2 |
|
---|
[14ff67c] | 3 | #define MAX_NUM_OBJECTS 1024
|
---|
[93baa0e] | 4 |
|
---|
[25b47d7] | 5 | uniform mat4 view, proj;
|
---|
| 6 | uniform float hp[1016];
|
---|
[14ff67c] | 7 |
|
---|
| 8 | layout (std140) uniform models {
|
---|
| 9 | mat4 model_mats[MAX_NUM_OBJECTS];
|
---|
[e165b85] | 10 | };
|
---|
| 11 |
|
---|
[d0b9596] | 12 | layout(location = 0) in vec3 vertex_position;
|
---|
| 13 | layout(location = 1) in vec3 vertex_color;
|
---|
[9dd2eb7] | 14 | layout(location = 2) in vec3 vertex_normal;
|
---|
[14ff67c] | 15 | layout(location = 3) in uint ubo_index;
|
---|
[8b7cfcf] | 16 |
|
---|
[f7d35da] | 17 | out vec3 position_eye, normal_eye, color, light_position_eye, light2_position_eye;
|
---|
[9dd2eb7] | 18 |
|
---|
| 19 | // fixed point light position
|
---|
| 20 | vec3 light_position_world = vec3(0.0, 0.0, 2.0);
|
---|
[cf2d1e5] | 21 | vec3 light2_position_world = vec3(0.0, 1.5, -0.1);
|
---|
[ec4456b] | 22 |
|
---|
| 23 | void main() {
|
---|
[14ff67c] | 24 | position_eye = vec3(view * model_mats[ubo_index] * vec4(vertex_position, 1.0));
|
---|
[c8dc5c6] | 25 | normal_eye = normalize(vec3(view * model_mats[ubo_index] * vec4(vertex_normal, 0.0)));
|
---|
[25b47d7] | 26 |
|
---|
| 27 | float hp_percent = hp[ubo_index] / 10.0;
|
---|
| 28 | vec3 damage_color = vec3(1.0, 0.0, 0.0);
|
---|
| 29 | color = (vertex_color * hp_percent) + (damage_color * (1.0 - hp_percent));
|
---|
| 30 |
|
---|
[9dd2eb7] | 31 | light_position_eye = vec3(view * vec4(light_position_world, 1.0));
|
---|
[f7d35da] | 32 | light2_position_eye = vec3(view * vec4(light2_position_world, 1.0));
|
---|
[9dd2eb7] | 33 |
|
---|
| 34 | gl_Position = proj * vec4(position_eye, 1.0);
|
---|
[ec4456b] | 35 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.