Changeset 25b47d7 in opengl-game for asteroid.vert


Ignore:
Timestamp:
Oct 17, 2018, 1:47:23 AM (6 years ago)
Author:
Dmitry Portnoy <dmp1488@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
1e3dddf, 8e8aed6
Parents:
0e0f851
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • asteroid.vert

    r0e0f851 r25b47d7  
    33#define MAX_NUM_OBJECTS 1024
    44
    5 uniform mat4 view, proj, hp;
     5uniform mat4 view, proj;
     6uniform float hp[1016];
    67
    78layout (std140) uniform models {
    89  mat4 model_mats[MAX_NUM_OBJECTS];
    910};
    10 
    11 /*
    12 layout (std140) uniform hp_uniform {
    13   mat4 hp[MAX_NUM_OBJECTS];
    14 };
    15 */
    1611
    1712layout(location = 0) in vec3 vertex_position;
     
    2924  position_eye = vec3(view * model_mats[ubo_index] * vec4(vertex_position, 1.0));
    3025  normal_eye = normalize(vec3(view * model_mats[ubo_index] * vec4(vertex_normal, 0.0)));
    31   //color = vertex_color * (hp[ubo_index][0][0] * 10.0); //(hp[ubo_index*4] / 10.0);
    32   color = vertex_color * (hp[0][0] * 2.0 / 10.0);
     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
    3331  light_position_eye = vec3(view * vec4(light_position_world, 1.0));
    3432  light2_position_eye = vec3(view * vec4(light2_position_world, 1.0));
Note: See TracChangeset for help on using the changeset viewer.