source: opengl-game/shaders/asteroid.vert@ 3e8cc8b

feature/imgui-sdl points-test
Last change on this file since 3e8cc8b was 3e8cc8b, checked in by Dmitry Portnoy <dmitry.portnoy@…>, 5 years ago

In VulkanGame, add the asteroid shader pipeline and start implementing asteroids flying at the player from the top of the screen

  • Property mode set to 100644
File size: 1.4 KB
Line 
1#version 450
2#extension GL_ARB_separate_shader_objects : enable
3
4struct Object {
5 mat4 model;
6 float hp;
7};
8
9layout (binding = 0) uniform UniformBufferObject {
10 mat4 view;
11 mat4 proj;
12} ubo;
13
14layout(binding = 1) readonly buffer StorageBufferObject {
15 Object objects[];
16} sbo;
17
18layout(location = 0) in vec3 vertex_position;
19layout(location = 1) in vec3 vertex_color;
20layout(location = 2) in vec3 vertex_normal;
21layout(location = 3) in uint obj_index;
22
23layout(location = 0) out vec3 position_eye;
24layout(location = 1) out vec3 color;
25layout(location = 2) out vec3 normal_eye;
26layout(location = 3) out vec3 light_position_eye;
27layout(location = 4) out vec3 light2_position_eye;
28
29// fixed point light position
30vec3 light_position_world = vec3(0.0, 0.0, 2.0);
31vec3 light2_position_world = vec3(0.0, 1.5, -0.1);
32
33void main() {
34 position_eye = vec3(ubo.view * sbo.objects[obj_index].model * vec4(vertex_position, 1.0));
35 normal_eye = normalize(vec3(ubo.view * sbo.objects[obj_index].model * vec4(vertex_normal, 0.0)));
36
37 float hp_percent = sbo.objects[obj_index].hp / 10.0;
38 vec3 damage_color = vec3(1.0, 0.0, 0.0);
39 color = (vertex_color * hp_percent) + (damage_color * (1.0 - hp_percent));
40
41 light_position_eye = vec3(ubo.view * vec4(light_position_world, 1.0));
42 light2_position_eye = vec3(ubo.view * vec4(light2_position_world, 1.0));
43
44 gl_Position = ubo.proj * vec4(position_eye, 1.0);
45}
Note: See TracBrowser for help on using the repository browser.