Changeset e1308e8 in opengl-game for shaders/ship.vert


Ignore:
Timestamp:
Nov 27, 2019, 6:39:18 PM (5 years ago)
Author:
Dmitry Portnoy <dmp1488@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
055750a
Parents:
06d959f
Message:

In VulkanGame, add normals to the ship pipeline and get lighting to work

File:
1 edited

Legend:

Unmodified
Added
Removed
  • shaders/ship.vert

    r06d959f re1308e8  
    22#extension GL_ARB_separate_shader_objects : enable
    33
    4 // TODO: Figure out if the UniformBufferObject label is necessary and, if not, remove it
    54layout (binding = 0) uniform UniformBufferObject {
    65   mat4 model;
     
    1110layout(location = 0) in vec3 vertex_position;
    1211layout(location = 1) in vec3 vertex_color;
    13 //layout(location = 2) in vec3 vertex_normal;
     12layout(location = 2) in vec3 vertex_normal;
    1413//layout(location = 3) in uint ubo_index;
    1514
    16 //out vec3 position_eye, normal_eye, color, light_position_eye, light2_position_eye;
    1715layout(location = 0) out vec3 position_eye;
    1816layout(location = 1) out vec3 color;
    19 layout(location = 2) out vec3 light_position_eye;
    20 layout(location = 3) out vec3 light2_position_eye;
     17layout(location = 2) out vec3 normal_eye;
     18layout(location = 3) out vec3 light_position_eye;
    2119
    2220// 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);
     22vec3 light_position_world = vec3(0.4, 1.5, 0.8);
     23//vec3 light_position_world = vec3(0.0, 1.0, -1.0);
    2524
     25// TODO: This does not account for scaling in the model matrix
     26// Check Anton's book to see how to fix this
    2627void main() {
     28   position_eye = vec3(ubo.view * ubo.model * vec4(vertex_position, 1.0));
    2729   //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)));
    2933   //normal_eye = normalize(vec3(view * model_mats[ubo_index] * vec4(vertex_normal, 0.0)));
    3034   color = vertex_color;
    3135   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));
    3336
    3437   gl_Position = ubo.proj * vec4(position_eye, 1.0);
Note: See TracChangeset for help on using the changeset viewer.