I have a top down camera on my game, and I'm rendering a point light on my opengl fragment shader.

When the point light is far away from the floor it looks like I would expect it should look, like a perfect sphere of light.

enter image description here

But when the light is close to the floor is getting sliced not equally from the bottom but diagonally.

enter image description here

Is there something wrong with my implementation of the pointlight?


layout(location = 0) in vec2 v_position;
layout(location = 1) in vec3 v_light_position;

layout(location = 0) out vec2 position;
layout(location = 1) out vec2 light_position;

layout(binding = 0) uniform ubo {
    mat4 camera_view;
    vec3 light_color;
    float light_fade;
    float light_scatter;
    float light_intensity;

void main() {
    position = v_position;
    light_position = v_light_position;

    gl_Position = camera_view * vec4(position, 0., 1.);


layout(location = 0) out vec4 color;

void main() {
    float light_distance = distance(position, light_position.xy);

    float attenuation = 1 / (1. + light_fade * light_distance + light_scatter * (light_distance * light_distance));
    vec3 normal = texture(texture_1, uv).rgb;

    vec3 light_direction = normalize(
        vec3(light_position.x - position.x, position.y - light_position.y, light_position.z)

    float ndotl = clamp(dot(normal, light_direction), 0., 1.);

    vec3 diffuse = vec3(light_intensity) * ndotl;

    color.rgb = light_color.rgb * diffuse * attenuation;
    color.a = 1.;

Getting the light clipped with the floor has sense, but the plane is perfectly flat with no slope, so it's awkward this is happening.


1 Answer 1


Okay, the problem was not in the code but in how I was creating my normals in Blender.

I was using a vec3(.5, .5, 1.) for a flat plane when it should have been vec3(0., 0., 1.)


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .