- Timestamp:
- Jun 21, 2021, 4:12:08 PM (3 years ago)
- Branches:
- feature/imgui-sdl
- Children:
- 27e580e
- Parents:
- b01b50c
- git-author:
- Dmitry Portnoy <dportnoy@…> (06/21/21 15:13:03)
- git-committer:
- Dmitry Portnoy <dportnoy@…> (06/21/21 16:12:08)
- Location:
- shaders
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
shaders/asteroid.vert
rb01b50c r67527a5 8 8 }; 9 9 10 layout (binding = 0) uniform UniformBufferObject{10 layout (binding = 0) uniform camera_block { 11 11 mat4 view; 12 12 mat4 proj; 13 } camera; 14 15 layout(binding = 1) uniform ubo_block { 16 Object objects[1024]; 13 17 } ubo; 14 15 layout(binding = 1) readonly buffer StorageBufferObject {16 Object objects[];17 } sbo;18 18 19 19 layout(location = 0) in vec3 vertex_position; … … 35 35 36 36 void main() { 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)));37 position_eye = vec3(camera.view * ubo.objects[obj_index].model * vec4(vertex_position, 1.0)); 38 normal_eye = normalize(vec3(camera.view * ubo.objects[obj_index].model * vec4(vertex_normal, 0.0))); 39 39 40 float hp_percent = sbo.objects[obj_index].hp / 10.0;40 float hp_percent = ubo.objects[obj_index].hp / 10.0; 41 41 vec3 damage_color = vec3(1.0, 0.0, 0.0); 42 42 color = (vertex_color * hp_percent) + (damage_color * (1.0 - hp_percent)); … … 44 44 fragTexCoord = inTexCoord; 45 45 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));46 light_position_eye = vec3(camera.view * vec4(light_position_world, 1.0)); 47 light2_position_eye = vec3(camera.view * vec4(light2_position_world, 1.0)); 48 48 49 if ( sbo.objects[obj_index].deleted) {49 if (ubo.objects[obj_index].deleted) { 50 50 gl_Position = vec4(0.0, 0.0, 2.0, 1.0); 51 51 } else { 52 gl_Position = ubo.proj * vec4(position_eye, 1.0);52 gl_Position = camera.proj * vec4(position_eye, 1.0); 53 53 } 54 54 } -
shaders/explosion.vert
rb01b50c r67527a5 9 9 }; 10 10 11 layout (binding = 0) uniform UniformBufferObject{11 layout (binding = 0) uniform camera_block { 12 12 mat4 view; 13 13 mat4 proj; 14 14 float cur_time; 15 } camera; 16 17 layout(binding = 1) uniform ubo_block { 18 Object objects[1024]; 15 19 } ubo; 16 17 layout(binding = 1) readonly buffer StorageBufferObject {18 Object objects[];19 } sbo;20 20 21 21 layout(location = 0) in vec3 particle_start_velocity; … … 26 26 27 27 void main() { 28 mat4 model = sbo.objects[obj_index].model;29 float explosion_start_time = sbo.objects[obj_index].explosion_start_time;30 float explosion_duration = sbo.objects[obj_index].explosion_duration;31 bool deleted = sbo.objects[obj_index].deleted;28 mat4 model = ubo.objects[obj_index].model; 29 float explosion_start_time = ubo.objects[obj_index].explosion_start_time; 30 float explosion_duration = ubo.objects[obj_index].explosion_duration; 31 bool deleted = ubo.objects[obj_index].deleted; 32 32 33 float t = ubo.cur_time - explosion_start_time - particle_start_time;33 float t = camera.cur_time - explosion_start_time - particle_start_time; 34 34 35 35 if (t < 0.0) { … … 56 56 p += normalize(particle_start_velocity) * mod(t, explosion_duration) / explosion_duration * 0.3; 57 57 58 gl_Position = ubo.proj * ubo.view * model * vec4(p, 1.0);58 gl_Position = camera.proj * camera.view * model * vec4(p, 1.0); 59 59 } 60 60 gl_PointSize = 10.0; // size in pixels -
shaders/laser.frag
rb01b50c r67527a5 8 8 }; 9 9 10 layout(binding = 1) readonly buffer StorageBufferObject{11 Object objects[ ];12 } sbo;10 layout(binding = 1) uniform ubo_block { 11 Object objects[1024]; 12 } ubo; 13 13 14 14 layout(binding = 2) uniform sampler2D laser_texture; … … 21 21 void main() { 22 22 vec4 texel = texture(laser_texture, texcoords_fs); 23 vec3 laser_color = sbo.objects[obj_index_fs].color;23 vec3 laser_color = ubo.objects[obj_index_fs].color; 24 24 25 25 frag_color = vec4(texel.r * laser_color.r, texel.g * laser_color.g, texel.b * laser_color.b, texel.a); -
shaders/laser.vert
rb01b50c r67527a5 8 8 }; 9 9 10 layout (binding = 0) uniform UniformBufferObject{10 layout (binding = 0) uniform camera_block { 11 11 mat4 view; 12 12 mat4 proj; 13 } camera; 14 15 layout(binding = 1) uniform ubo_block { 16 Object objects[1024]; 13 17 } ubo; 14 15 layout(binding = 1) readonly buffer StorageBufferObject {16 Object objects[];17 } sbo;18 18 19 19 layout(location = 0) in vec3 vertex_position; … … 25 25 26 26 void main() { 27 vec3 position_eye = vec3( ubo.view * sbo.objects[obj_index_vs].model * vec4(vertex_position, 1.0));27 vec3 position_eye = vec3(camera.view * ubo.objects[obj_index_vs].model * vec4(vertex_position, 1.0)); 28 28 29 29 texcoords_fs = texcoords_vs; 30 30 obj_index_fs = obj_index_vs; 31 31 32 if ( sbo.objects[obj_index_vs].deleted) {32 if (ubo.objects[obj_index_vs].deleted) { 33 33 gl_Position = vec4(0.0, 0.0, 2.0, 1.0); 34 34 } else { 35 gl_Position = ubo.proj * vec4(position_eye, 1.0);35 gl_Position = camera.proj * vec4(position_eye, 1.0); 36 36 } 37 37 } -
shaders/model.vert
rb01b50c r67527a5 6 6 }; 7 7 8 layout (binding = 0) uniform UniformBufferObject{8 layout (binding = 0) uniform camera_block { 9 9 mat4 view; 10 10 mat4 proj; 11 } camera; 12 13 // TODO: Verify that I can actually store 1024 values here. They last time I checked, I think I could only store 1016 values 14 layout (binding = 1) uniform ubo_block { 15 Object objects[1024]; 11 16 } ubo; 12 13 layout(binding = 1) readonly buffer StorageBufferObject {14 Object objects[];15 } sbo;16 17 layout (binding = 2) uniform UboInstance {18 mat4 model;19 } uboInstance;20 17 21 18 layout(location = 0) in vec3 inPosition; … … 31 28 void main() { 32 29 // Using 0.0 instead of 1.0 means translations won't effect the normal 33 normal_eye = normalize(vec3( ubo.view * sbo.objects[obj_index].model * vec4(vertex_normal, 0.0)));30 normal_eye = normalize(vec3(camera.view * ubo.objects[obj_index].model * vec4(vertex_normal, 0.0))); 34 31 35 32 fragColor = inColor; 36 33 fragTexCoord = inTexCoord; 37 34 38 gl_Position = ubo.proj * ubo.view * sbo.objects[obj_index].model * vec4(inPosition, 1.0);35 gl_Position = camera.proj * camera.view * ubo.objects[obj_index].model * vec4(inPosition, 1.0); 39 36 } -
shaders/ship.vert
rb01b50c r67527a5 6 6 }; 7 7 8 layout (binding = 0) uniform UniformBufferObject{8 layout (binding = 0) uniform camera_block { 9 9 mat4 view; 10 10 mat4 proj; 11 } camera; 12 13 layout(binding = 1) uniform ubo_block { 14 Object objects[1024]; 11 15 } ubo; 12 13 layout(binding = 1) readonly buffer StorageBufferObject {14 Object objects[];15 } sbo;16 16 17 17 layout(location = 0) in vec3 vertex_position; … … 35 35 // Check Anton's book to see how to fix this 36 36 void main() { 37 position_eye = vec3( ubo.view * sbo.objects[obj_index].model * vec4(vertex_position, 1.0));37 position_eye = vec3(camera.view * ubo.objects[obj_index].model * vec4(vertex_position, 1.0)); 38 38 39 39 // Using 0.0 instead of 1.0 means translations won't effect the normal 40 normal_eye = normalize(vec3( ubo.view * sbo.objects[obj_index].model * vec4(vertex_normal, 0.0)));40 normal_eye = normalize(vec3(camera.view * ubo.objects[obj_index].model * vec4(vertex_normal, 0.0))); 41 41 42 42 color = vertex_color; … … 44 44 fragTexCoord = inTexCoord; 45 45 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));46 light_position_eye = vec3(camera.view * vec4(light_position_world, 1.0)); 47 light2_position_eye = vec3(camera.view * vec4(light2_position_world, 1.0)); 48 48 49 gl_Position = ubo.proj * vec4(position_eye, 1.0);49 gl_Position = camera.proj * vec4(position_eye, 1.0); 50 50 }
Note:
See TracChangeset
for help on using the changeset viewer.