Changeset 7c929fc in opengl-game


Ignore:
Timestamp:
Dec 6, 2019, 4:21:54 AM (5 years ago)
Author:
Dmitry Portnoy <dmp1488@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
60578ce
Parents:
2b40f48
Message:

In VulkanGame, make lighting work correctly in the ship shader before the MVP matrices are applied

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • scene-notes.txt

    r2b40f48 r7c929fc  
    22In vulkan, it is upper left, so I set the projection matrix [1][1] cell to -1 to flip the y-axis and make it match opengl
    33
    4 +z goes into the screen
     4+z goes into the screen (in Vulkan)
  • shaders/ship.frag

    r2b40f48 r7c929fc  
    1515
    1616// reflectance of the object surface
     17// TODO: Eventually, I might want to move these properties into an ssbo so they differ per object
    1718vec3 Ks = vec3(1.0, 1.0, 1.0);
    18 vec3 Kd = vec3(1.0, 0.5, 0.0);
     19vec3 Kd = color;
    1920vec3 Ka = vec3(0.2, 0.2, 0.2);
    2021float specular_exponent = 100.0; // specular 'power'
     
    3132
    3233   // diffuse intensity
    33    vec3 Id = Ld * color * dot_prod;
    34    //vec3 Id = Ld * Kd * dot_prod;
     34   vec3 Id = Ld * Kd * dot_prod;
    3535
    3636   vec3 surface_to_viewer_eye = normalize(-position_eye);
     
    4343   vec3 Is = Ls * Ks * specular_factor;
    4444
    45    //outColor = vec4(Is + Id + Ia, 1.0);
    46    outColor = vec4(color, 1.0);
     45   outColor = vec4(Is + Id + Ia, 1.0);
    4746}
  • shaders/ship.vert

    r2b40f48 r7c929fc  
    2727// fixed point light position
    2828//vec3 light_position_world = vec3(0.0, 0.0, 2.0);
    29 vec3 light_position_world = vec3(0.4, 1.5, 0.8);
    30 //vec3 light_position_world = vec3(0.0, 1.0, -1.0);
     29//vec3 light_position_world = vec3(0.4, 1.5, 0.8);
     30vec3 light_position_world = vec3(0.4, 0.0, 0.2);
    3131
    3232// TODO: This does not account for scaling in the model matrix
    3333// Check Anton's book to see how to fix this
    3434void main() {
    35    position_eye = vec3(ubo.view * sbo.objects[obj_index].model * vec4(vertex_position, 1.0));
     35   //position_eye = vec3(ubo.view * sbo.objects[obj_index].model * vec4(vertex_position, 1.0));
     36   position_eye = vec3(vec4(vertex_position, 1.0));
    3637
    3738   // Using 0.0 instead of 1.0 means translations won't effect the normal
    38    normal_eye = normalize(vec3(ubo.view * sbo.objects[obj_index].model * vec4(vertex_normal, 0.0)));
     39   //normal_eye = normalize(vec3(ubo.view * sbo.objects[obj_index].model * vec4(vertex_normal, 0.0)));
     40   normal_eye = normalize(vec3(vec4(vertex_normal, 0.0)));
    3941   color = vertex_color;
    40    light_position_eye = vec3(ubo.view * vec4(light_position_world, 1.0));
     42   //light_position_eye = vec3(ubo.view * vec4(light_position_world, 1.0));
     43   light_position_eye = vec3(vec4(light_position_world, 1.0));
    4144
    4245   //gl_Position = ubo.proj * vec4(position_eye, 1.0);
  • vulkan-game.cpp

    r2b40f48 r7c929fc  
    502502
    503503   // z-range is 0 to 1, with +1 pointing into the screen
    504    shipPipeline.addObject(addVertexNormals<ShipVertex>({
     504   shipPipeline.addObject(
     505      addObjectIndex<ShipVertex>(shipPipeline.getObjects().size(),
     506      addVertexNormals<ShipVertex>({
    505507         {{  0.5f,  -0.5f,   0.5f}, {0.0f, 0.6f, 0.0f}},
    506508         {{ -0.5f,  -0.5f,   0.5f}, {0.0f, 0.6f, 0.0f}},
     
    516518         {{ -0.3f,   0.3f,   0.3f}, {0.0f, 0.0f, 0.7f}},
    517519         {{  0.3f,   0.3f,   0.3f}, {0.0f, 0.0f, 0.7f}},
    518    }), {
     520      })), {
    519521         0,   1,   2,   3,   4,   5,
    520522         6,   7,   8,   9,   10,   11,
    521    }, commandPool, graphicsQueue);
     523      }, commandPool, graphicsQueue);
    522524
    523525   shipPipeline.createDescriptorSetLayout();
  • vulkan-game.hpp

    r2b40f48 r7c929fc  
    204204
    205205      vec3 normal = normalize(cross(p2 - p1, p3 - p1));
    206       normal.z = -normal.z;
     206      //normal.z = -normal.z;
    207207
    208208      // Add the same normal for all 3 vertices
Note: See TracChangeset for help on using the changeset viewer.