Lambert and Gouraud
I started at the same point every lighting shader starts: diffuse lighting.
Diffuse lighting is the matte light reflected by an object’s surface:
Fun fact: colours do not actually exist. What our eyes perceive as colour is actually the sum of the wavelengths that manage to escape the surface of an object, bouncing off it. The rest of it is absorbed by the object, transforming the energy into heat. That’s why black gets hot very fast, and why cultures from hot climates prefer white.
The most known diffuse lighting technique is, of course, the Lambertian reflectance.
void main()
{
vec3 N = normalize(fragNormal);
vec3 L = normalize(lightDir);
// Predefined light directions, like sunlight, need to be inverted
float lambert = max(0, dot(N, -L));
vec3 albedo = texture(texture0, uv).rgb;
albedo *= colDiffuse;
vec3 diffuse = albedo * ambientColor * lambert;
finalColor = vec4(diffuse, fragColor.a);
}
Let there be light!
Lighting is usually done in the fragment pass, but if you are really tight on GPU spoons, here is an alternative! Do it in the vertex shader, and you will get Gouraud shading!
It looks a little bit blockier, specially around trees:
But that is enough for mobile devices, which makes Gouraud a cheap alternative and a must have in your toolbox!
If you made it this far...
Thank you! I hope you liked it!
I do not allow comments in my blog because I do not want to deal with bots. However, feel free to contact me!
And if you would like to support my work, please, consider doing so through ko-fi: