Skip to content

Commit

Permalink
Fix the example lighting shaders to use both frag and diffuse colors …
Browse files Browse the repository at this point in the history
…so they work with shapes and meshes. (raysan5#4482)
  • Loading branch information
JeffM2501 authored and psxdev committed Nov 18, 2024
1 parent 8ca051c commit 200b769
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
4 changes: 3 additions & 1 deletion examples/shaders/resources/shaders/glsl100/lighting.fs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ void main()
vec3 viewD = normalize(viewPos - fragPosition);
vec3 specular = vec3(0.0);

vec4 tint = colDiffuse * fragColor;

// NOTE: Implement here your fragment shader code

for (int i = 0; i < MAX_LIGHTS; i++)
Expand Down Expand Up @@ -67,7 +69,7 @@ void main()
}
}

vec4 finalColor = (texelColor*((colDiffuse + vec4(specular, 1.0))*vec4(lightDot, 1.0)));
vec4 finalColor = (texelColor*((tint + vec4(specular, 1.0))*vec4(lightDot, 1.0)));
finalColor += texelColor*(ambient/10.0);

// Gamma correction
Expand Down
4 changes: 3 additions & 1 deletion examples/shaders/resources/shaders/glsl120/lighting.fs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ void main()
vec3 viewD = normalize(viewPos - fragPosition);
vec3 specular = vec3(0.0);

vec4 tint = colDiffuse * fragColor;

// NOTE: Implement here your fragment shader code

for (int i = 0; i < MAX_LIGHTS; i++)
Expand Down Expand Up @@ -65,7 +67,7 @@ void main()
}
}

vec4 finalColor = (texelColor*((colDiffuse + vec4(specular, 1.0))*vec4(lightDot, 1.0)));
vec4 finalColor = (texelColor*((tint + vec4(specular, 1.0))*vec4(lightDot, 1.0)));
finalColor += texelColor*(ambient/10.0);

// Gamma correction
Expand Down
8 changes: 5 additions & 3 deletions examples/shaders/resources/shaders/glsl330/lighting.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Input vertex attributes (from vertex shader)
in vec3 fragPosition;
in vec2 fragTexCoord;
//in vec4 fragColor;
in vec4 fragColor;
in vec3 fragNormal;

// Input uniform values
Expand Down Expand Up @@ -41,6 +41,8 @@ void main()
vec3 viewD = normalize(viewPos - fragPosition);
vec3 specular = vec3(0.0);

vec4 tint = colDiffuse * fragColor;

// NOTE: Implement here your fragment shader code

for (int i = 0; i < MAX_LIGHTS; i++)
Expand Down Expand Up @@ -68,8 +70,8 @@ void main()
}
}

finalColor = (texelColor*((colDiffuse + vec4(specular, 1.0))*vec4(lightDot, 1.0)));
finalColor += texelColor*(ambient/10.0)*colDiffuse;
finalColor = (texelColor*((tint + vec4(specular, 1.0))*vec4(lightDot, 1.0)));
finalColor += texelColor*(ambient/10.0)*tint;

// Gamma correction
finalColor = pow(finalColor, vec4(1.0/2.2));
Expand Down

0 comments on commit 200b769

Please sign in to comment.