Skip to content

Commit 10fd4de

Browse files
authored
Fix the example lighting shaders to use both frag and diffuse colors so they work with shapes and meshes. (#4482)
1 parent 5cc06f4 commit 10fd4de

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

examples/shaders/resources/shaders/glsl100/lighting.fs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ void main()
4040
vec3 viewD = normalize(viewPos - fragPosition);
4141
vec3 specular = vec3(0.0);
4242

43+
vec4 tint = colDiffuse * fragColor;
44+
4345
// NOTE: Implement here your fragment shader code
4446

4547
for (int i = 0; i < MAX_LIGHTS; i++)
@@ -67,7 +69,7 @@ void main()
6769
}
6870
}
6971

70-
vec4 finalColor = (texelColor*((colDiffuse + vec4(specular, 1.0))*vec4(lightDot, 1.0)));
72+
vec4 finalColor = (texelColor*((tint + vec4(specular, 1.0))*vec4(lightDot, 1.0)));
7173
finalColor += texelColor*(ambient/10.0);
7274

7375
// Gamma correction

examples/shaders/resources/shaders/glsl120/lighting.fs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ void main()
3838
vec3 viewD = normalize(viewPos - fragPosition);
3939
vec3 specular = vec3(0.0);
4040

41+
vec4 tint = colDiffuse * fragColor;
42+
4143
// NOTE: Implement here your fragment shader code
4244

4345
for (int i = 0; i < MAX_LIGHTS; i++)
@@ -65,7 +67,7 @@ void main()
6567
}
6668
}
6769

68-
vec4 finalColor = (texelColor*((colDiffuse + vec4(specular, 1.0))*vec4(lightDot, 1.0)));
70+
vec4 finalColor = (texelColor*((tint + vec4(specular, 1.0))*vec4(lightDot, 1.0)));
6971
finalColor += texelColor*(ambient/10.0);
7072

7173
// Gamma correction

examples/shaders/resources/shaders/glsl330/lighting.fs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Input vertex attributes (from vertex shader)
44
in vec3 fragPosition;
55
in vec2 fragTexCoord;
6-
//in vec4 fragColor;
6+
in vec4 fragColor;
77
in vec3 fragNormal;
88

99
// Input uniform values
@@ -41,6 +41,8 @@ void main()
4141
vec3 viewD = normalize(viewPos - fragPosition);
4242
vec3 specular = vec3(0.0);
4343

44+
vec4 tint = colDiffuse * fragColor;
45+
4446
// NOTE: Implement here your fragment shader code
4547

4648
for (int i = 0; i < MAX_LIGHTS; i++)
@@ -68,8 +70,8 @@ void main()
6870
}
6971
}
7072

71-
finalColor = (texelColor*((colDiffuse + vec4(specular, 1.0))*vec4(lightDot, 1.0)));
72-
finalColor += texelColor*(ambient/10.0)*colDiffuse;
73+
finalColor = (texelColor*((tint + vec4(specular, 1.0))*vec4(lightDot, 1.0)));
74+
finalColor += texelColor*(ambient/10.0)*tint;
7375

7476
// Gamma correction
7577
finalColor = pow(finalColor, vec4(1.0/2.2));

0 commit comments

Comments
 (0)