Trying to learn 3D programming, I am currently implementing a class that batch displays OpenGL cubes by clicking on each frame's GPU. I tried to do some unlit lighting: 1) Sending each face normal to the GPU as part of the vertex attributes. 2) Checking the direction of the normal and dimming each fragment arbitrarily, for example:
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); }
As a result:

Although I am not very good at GLSL, my intuition says that this is not the right behavior. But a few google searches later, I'm still not sure what I'm doing wrong.
c ++ shader opengl glsl
Kaffeleffe
source share