Here you see a scene comprised of planes lit by a point light. In nature, the brightness for each "fragment" is determined, for the most part, by it's distance from the source and I would like to see that smooth transition here, from wall to wall.
The only variable factor is the vertex normals, and no doubt they are causing this sharp change in colour. What can be done to light the room more realistically?
Vertex Shader
#version 330
precision highp float;
uniform mat4 projection_matrix;
uniform mat4 model_matrix;
uniform mat4 view_matrix;
in vec3 vert_position;
in vec2 vert_texcoord;
in vec3 vert_normal;
out vec3 frag_normal;
out vec2 frag_texcoord;
uniform vec3 LightPosition;
out vec3 toLightVector;
void main(void)
{
vec4 world_position = model_matrix * vec4(vert_position, 1);
frag_texcoord = vert_texcoord;
frag_normal = (model_matrix * vec4(vert_normal, 0)).xyz;
toLightVector = LightPosition - world_position.xyz;
gl_Position = projection_matrix * view_matrix * world_position;
}
Fragment Shader
#version 330
precision highp float;
in vec3 frag_normal;
in vec2 frag_texcoord;
in vec3 toLightVector;
uniform sampler2D MyTexture0;
uniform vec3 LightColour;
uniform vec3 LightAttenuation;
out vec4 finalColor;
void main(void)
{
float distance = length(toLightVector);
float attFactor = LightAttenuation.x + (LightAttenuation.y * distance) + (LightAttenuation.z * distance * distance);
vec3 unitNormal = normalize(frag_normal);
vec3 unitLightVector = normalize(toLightVector);
float nDot1 = dot(unitNormal, unitLightVector);
float brightness = max(nDot1, 0);
vec3 diffuse = (brightness * LightColour) / attFactor;
finalColor = vec4(diffuse, 1.0) * texture(MyTexture0, frag_texcoord);
}