Changeset a00eb06 in opengl-game for shaders


Ignore:
Timestamp:
Apr 10, 2021, 12:58:17 AM (3 years ago)
Author:
Dmitry Portnoy <dportnoy@…>
Branches:
feature/imgui-sdl
Children:
8d92284
Parents:
914bb99
git-author:
Dmitry Portnoy <dportnoy@…> (04/10/21 00:49:42)
git-committer:
Dmitry Portnoy <dportnoy@…> (04/10/21 00:58:17)
Message:

In VulkanGame, add a normal varying attribute to ModelVertex

Location:
shaders
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • shaders/model.frag

    r914bb99 ra00eb06  
    66layout(location = 0) in vec3 fragColor;
    77layout(location = 1) in vec2 fragTexCoord;
     8layout(location = 2) in vec3 normal_eye;
    89
    910layout(location = 0) out vec4 outColor;
    1011
    1112void main() {
    12    outColor = vec4(fragColor * texture(texSampler, fragTexCoord).rgb, 1.0);
     13   outColor = vec4(fragColor * texture(texSampler, fragTexCoord).rgb, 1.0) + vec4(normal_eye, 0.0) - vec4(normal_eye, 0.0);
    1314}
  • shaders/model.vert

    r914bb99 ra00eb06  
    1515} sbo;
    1616
     17layout (binding = 2) uniform UboInstance {
     18        mat4 model;
     19} uboInstance;
     20
    1721layout(location = 0) in vec3 inPosition;
    1822layout(location = 1) in vec3 inColor;
    1923layout(location = 2) in vec2 inTexCoord;
    20 layout(location = 3) in uint obj_index;
     24layout(location = 3) in vec3 vertex_normal;
     25layout(location = 4) in uint obj_index;
    2126
    2227layout(location = 0) out vec3 fragColor;
    2328layout(location = 1) out vec2 fragTexCoord;
     29layout(location = 2) out vec3 normal_eye;
    2430
    2531void main() {
     32   // 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)));
     34
    2635   fragColor = inColor;
    2736   fragTexCoord = inTexCoord;
Note: See TracChangeset for help on using the changeset viewer.