Light shader causes pixel bubble around light where effect is visible

Godot Version

4.2.2 stable

Question

I have a post processing quad with a shader that detects edges of meshes. However, I wanted edges to be darker or lighter than the surrounding mesh surface based on lighting.

This is the shadercode.

void light(){
DIFFUSE_LIGHT = vec3(1.0);
SPECULAR_LIGHT = vec3(0.0);
if (LIGHT_IS_DIRECTIONAL == false){
if (is_edge == true) {
DIFFUSE_LIGHT += dot(normalize(NORMAL), normalize(LIGHT)) * LIGHT_COLOR;
}
}
}

is_edge is determined by fragment shader and passed by varying. The problem is that this omni light I have is causing a pixelated bubble around it where the effect takes place.

image

As you can see, the green cube is illuminated ( sort of) correctly, however, this white slab on the right is also illuminated because it is overlapping the range of the light.

It’s difficult to show without a video, but there’s a pixel bubble filling the range of this light which causes any edges within it to be illuminated. These pixels are massive and do not scale with distance, however there will be less pixels occupying the range of the light the farther the camera moves away.

I haven’t found anybody talk about this and I’ve run into this problem a few times when trying other shader stuff, but this is starting to annoy me. Any help is appreciated.

Still having this issue, here is a better image.

Did you ever find a solution? I’m facing the same issue.

Nope, I just trashed the idea.

Ah I see.

// Varying inputs
varying bool is_edge;
varying vec3 vertex_world_position;

void light() {
// Initialize base lighting
DIFFUSE_LIGHT = vec3(1.0);
SPECULAR_LIGHT = vec3(0.0);

if (!LIGHT_IS_DIRECTIONAL) {
    // Calculate light direction in world space
    vec3 light_dir = normalize(LIGHT_POSITION - vertex_world_position);
    float NdotL = max(0.0, dot(normalize(NORMAL), light_dir));
    
    // Calculate light attenuation
    float dist = length(LIGHT_POSITION - vertex_world_position);
    float attenuation = 1.0 / (1.0 + 0.09 * dist + 0.032 * dist * dist);
    
    if (is_edge) {
        // Modify edge lighting based on light direction and distance
        float edge_intensity = NdotL * attenuation;
        DIFFUSE_LIGHT += LIGHT_COLOR * edge_intensity;
    }
}

}