[ad_1]

I’ve a top down digicam on my sport, and I am rendering a degree gentle on my opengl fragment shader.

When the purpose gentle is much away from the ground it appears to be like like I’d count on it ought to look, like an ideal sphere of sunshine.

enter image description here

However when the sunshine is near the ground is getting sliced not equally from the underside however diagonally.

enter image description here

Is there one thing mistaken with my implementation of the pointlight?

vertex

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

structure(location = 0) out vec2 place;
structure(location = 1) out vec2 light_position;

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

void most important() {
    place = v_position;
    light_position = v_light_position;

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

fragment

structure(location = 0) out vec4 shade;

const vec3 BRIGHTNESS = vec3(.2126, .7152, .0722);

float brightness(vec3 worth) {
    return dot(worth, BRIGHTNESS);
}

void most important() {
    vec3 light_direction = normalize(
        vec3(light_position.x - place.x, place.y - light_position.y, light_position.z)
    );

    float light_distance = distance(place, light_position.xy);

    float attenuation = 1 / (1. + light_fade * light_distance + light_scatter * (light_distance * light_distance));
    
    shade.rgb = light_color.rgb * attenuation;
    shade.a = brightness(gentle);
}

Getting the sunshine clipped with the ground has sense, however the aircraft is completely flat with no slope, so it is awkward that is occurring.

[ad_2]

Leave a Reply

Your email address will not be published. Required fields are marked *