Trying to learn 3D programming, I am currently implementing a class which batch-renders cubes with OpenGL by pushing them to the GPU each frame. I tried to implement some crude lighting by 1) Sending each face normal to the GPU as part of the vertex attributes 2) Checking the direction of said normal and darken each fragment arbitrarily, like so:
Fragment Shader
#version 330
in vec2 ex_TexCoord;
in vec3 ex_Normal;
out vec4 out_Color;
uniform sampler2D textureSampler;
void main(void) {
float lightAmplifier = 1.0;
if (ex_Normal.z == 1.0) {
lightAmplifier = .8;
} else if (ex_Normal.x == 1.0) {
lightAmplifier = .65;
} else if (ex_Normal.x == -1.0) {
lightAmplifier = .50;
}
out_Color = vec4(texture2D(textureSampler, ex_TexCoord).rgb * lightAmplifier, 1.0);
}
Resulting in this:
While not being very good at GLSL, my intuition says this is not correct behaviour. But a number google searches later, I'm still not sure what I'm doing wrong.
>=0.99
instead of==1.0
? – Emeldaemelen