Skip to content

Commit

Permalink
REFACTOR shader:
Browse files Browse the repository at this point in the history
- multiply texture color with normal vector
  • Loading branch information
SaumonDesMers authored and afaure42 committed Mar 3, 2024
1 parent 81dbf32 commit 97a8915
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
10 changes: 7 additions & 3 deletions shaders/simple_shader.frag
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

layout(set = 0, binding = 1) uniform sampler2D tex;

layout(location = 0) in vec3 fragColor;
layout(location = 0) in vec3 fragNormal;
layout(location = 1) in vec2 fragTexCoord;

layout(location = 0) out vec4 outColor;

void main() {
outColor = texture(tex, fragTexCoord);
void main()
{
vec3 normal = abs(normalize(fragNormal));
float intensity = normal.x * 0.200 + normal.y * 0.500 + normal.z * 0.800;

outColor = texture(tex, fragTexCoord) * intensity;
}
13 changes: 8 additions & 5 deletions shaders/simple_shader.vert
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
#version 450

layout(set = 0, binding = 0) uniform CameraMatrices {
layout(set = 0, binding = 0) uniform CameraMatrices
{
mat4 view;
mat4 projection;
}cm;

layout(push_constant) uniform PushConstants {
layout(push_constant) uniform PushConstants
{
mat4 model;
}pc;

layout(location = 0) in ivec3 positions;
layout(location = 1) in vec3 normal;
layout(location = 2) in vec2 texCoords;

layout(location = 0) out vec3 fragColor;
layout(location = 0) out vec3 fragNormal;
layout(location = 1) out vec2 fragTexCoords;

void main() {
void main()
{
gl_Position = cm.projection * cm.view * pc.model * vec4(positions, 1.0);
fragColor = normal;
fragNormal = normal;
fragTexCoords = texCoords;
}

0 comments on commit 97a8915

Please sign in to comment.