Changeset e1308e8 in opengl-game
- Timestamp:
- Nov 27, 2019, 6:39:18 PM (5 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 055750a
- Parents:
- 06d959f
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
shaders/ship.frag
r06d959f re1308e8 2 2 #extension GL_ARB_separate_shader_objects : enable 3 3 4 //in vec3 position_eye, normal_eye, color, light_position_eye, light2_position_eye;5 4 layout(location = 0) in vec3 position_eye; 6 5 layout(location = 1) in vec3 color; 7 layout(location = 2) in vec3 light_position_eye;8 layout(location = 3) in vec3 light 2_position_eye;6 layout(location = 2) in vec3 normal_eye; 7 layout(location = 3) in vec3 light_position_eye; 9 8 10 9 layout(location = 0) out vec4 outColor; … … 12 11 // fixed point light properties 13 12 vec3 Ls = vec3(1.0, 1.0, 1.0); 14 vec3 Ld = vec3( 1.0, 1.0, 1.0);13 vec3 Ld = vec3(0.7, 0.7, 0.7); 15 14 vec3 La = vec3(0.2, 0.2, 0.2); 16 15 17 // surface reflectance16 // reflectance of the object surface 18 17 vec3 Ks = vec3(1.0, 1.0, 1.0); 19 vec3 Kd = vec3(1.0, 1.5, 1.0);18 vec3 Kd = vec3(1.0, 0.5, 0.0); 20 19 vec3 Ka = vec3(0.2, 0.2, 0.2); 21 20 float specular_exponent = 100.0; // specular 'power' … … 29 28 30 29 vec3 direction_to_light_eye = normalize(light_position_eye - position_eye); 31 //float dot_prod = max(dot(direction_to_light_eye, normal_eye), 0.0);30 float dot_prod = max(dot(direction_to_light_eye, normal_eye), 0.0); 32 31 33 32 // diffuse intensity 34 //vec3 Id = Ld * color * dot_prod; 33 vec3 Id = Ld * color * dot_prod; 34 //vec3 Id = Ld * Kd * dot_prod; 35 35 36 vec3 direction_to_light2_eye = normalize(light2_position_eye - position_eye); 37 //float dot_prod2 = max(dot(direction_to_light2_eye, normal_eye), 0.0); 36 vec3 surface_to_viewer_eye = normalize(-position_eye); 38 37 39 // diffuse intensity 40 //vec3 Id2 = Ld * color * dot_prod2; 41 42 //vec3 surface_to_viewer_eye = normalize(-position_eye); 43 44 //vec3 reflection_eye = reflect(-direction_to_light_eye, normal_eye); 45 //float dot_prod_specular = max(dot(reflection_eye, surface_to_viewer_eye), 0.0); 46 //float specular_factor = pow(dot_prod_specular, specular_exponent); 47 48 //vec3 reflection_eye2 = reflect(-direction_to_light2_eye, normal_eye); 49 //float dot_prod_specular2 = max(dot(reflection_eye2, surface_to_viewer_eye), 0.0); 50 //float specular_factor2 = pow(dot_prod_specular2, specular_exponent); 38 vec3 reflection_eye = reflect(-direction_to_light_eye, normal_eye); 39 float dot_prod_specular = max(dot(reflection_eye, surface_to_viewer_eye), 0.0); 40 float specular_factor = pow(dot_prod_specular, specular_exponent); 51 41 52 42 // specular intensity 53 //vec3 Is = Ls * Ks * specular_factor; 54 //vec3 Is2 = Ls * Ks * specular_factor2; 43 vec3 Is = Ls * Ks * specular_factor; 55 44 56 //outColor = vec4((Is + Id + Ia + Is2 + Id2 + Ia2)/2, 1.0); 57 outColor = vec4(color, 1.0); 45 outColor = vec4(Is + Id + Ia, 1.0); 58 46 } -
shaders/ship.vert
r06d959f re1308e8 2 2 #extension GL_ARB_separate_shader_objects : enable 3 3 4 // TODO: Figure out if the UniformBufferObject label is necessary and, if not, remove it5 4 layout (binding = 0) uniform UniformBufferObject { 6 5 mat4 model; … … 11 10 layout(location = 0) in vec3 vertex_position; 12 11 layout(location = 1) in vec3 vertex_color; 13 //layout(location = 2) in vec3 vertex_normal;12 layout(location = 2) in vec3 vertex_normal; 14 13 //layout(location = 3) in uint ubo_index; 15 14 16 //out vec3 position_eye, normal_eye, color, light_position_eye, light2_position_eye;17 15 layout(location = 0) out vec3 position_eye; 18 16 layout(location = 1) out vec3 color; 19 layout(location = 2) out vec3 light_position_eye;20 layout(location = 3) out vec3 light 2_position_eye;17 layout(location = 2) out vec3 normal_eye; 18 layout(location = 3) out vec3 light_position_eye; 21 19 22 20 // fixed point light position 23 vec3 light_position_world = vec3(0.0, 0.0, 2.0); 24 vec3 light2_position_world = vec3(0.0, 1.5, -0.1); 21 //vec3 light_position_world = vec3(0.0, 0.0, 2.0); 22 vec3 light_position_world = vec3(0.4, 1.5, 0.8); 23 //vec3 light_position_world = vec3(0.0, 1.0, -1.0); 25 24 25 // TODO: This does not account for scaling in the model matrix 26 // Check Anton's book to see how to fix this 26 27 void main() { 28 position_eye = vec3(ubo.view * ubo.model * vec4(vertex_position, 1.0)); 27 29 //position_eye = vec3(view * model_mats[ubo_index] * vec4(vertex_position, 1.0)); 28 position_eye = vec3(ubo.view * ubo.model * vec4(vertex_position, 1.0)); 30 31 // Using 0.0 instead of 1.0 means translations won't effect the normal 32 normal_eye = normalize(vec3(ubo.view * ubo.model * vec4(vertex_normal, 0.0))); 29 33 //normal_eye = normalize(vec3(view * model_mats[ubo_index] * vec4(vertex_normal, 0.0))); 30 34 color = vertex_color; 31 35 light_position_eye = vec3(ubo.view * vec4(light_position_world, 1.0)); 32 light2_position_eye = vec3(ubo.view * vec4(light2_position_world, 1.0));33 36 34 37 gl_Position = ubo.proj * vec4(position_eye, 1.0); -
vulkan-game.cpp
r06d959f re1308e8 248 248 shipPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&ShipVertex::pos)); 249 249 shipPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&ShipVertex::color)); 250 shipPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&ShipVertex::normal)); 250 251 251 252 createUniformBuffers<UBO_MvpMat>(uniformBuffers_shipPipeline, uniformBuffersMemory_shipPipeline, uniformBufferInfoList_shipPipeline); … … 254 255 VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList_shipPipeline); 255 256 256 shipPipeline.addObject({ 257 // TODO: With the normals, indexing basically becomes pointless since no vertices will have exactly 258 // the same data. Add an option to make some pipelines not use indexing 259 shipPipeline.addObject(addVertexNormals<ShipVertex>({ 257 260 //back 258 261 {{ -0.5f, 0.3f, 0.0f}, {0.0f, 0.0f, 0.3f}}, … … 450 453 {{ 1.5f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.3f}}, 451 454 {{ 1.3f, 0.0f, -0.3f}, {0.0f, 0.0f, 0.3f}}, 452 } , {455 }), { 453 456 0, 1, 2, 3, 4, 5, 454 457 6, 7, 8, 9, 10, 11,
Note:
See TracChangeset
for help on using the changeset viewer.