zaycev / bevy-magic-light-2d

Experiment with computing 2D shading, lighting and shadows with Bevy Engine
Apache License 2.0
478 stars 41 forks source link

Weird darkening artifact at the top and right of the camera #53

Open luan opened 7 months ago

luan commented 7 months ago

I spent a few hours on this but I am very new to shader programming and vfx in general, ended up getting stuck trying to figure out why this happens.

The screenshots show what i'm seeing here, but basically, there's a darkening that happens at around 400px into the camera from right to left and 24x top to bottom.

Any idea why this is the case? Is it an intentional effect?

You can also see this issue on the movement example:

CleanShot 2024-02-18 at 21 09 41@2x

both an omni source and skylight:

CleanShot 2024-02-18 at 21 00 01@2x

just the skylight:

CleanShot 2024-02-18 at 21 03 42@2x

just the omni source:

CleanShot 2024-02-18 at 21 04 31@2x

GlummixX commented 7 months ago

Hi, I have identical issue. Changing reservoir_size made it less visible for me, but it introduced a weird flicker on the edges of the window. Its not that bad, since there is not much to see anyway. Proper solution would be appreciated.

        app.insert_resource(BevyMagicLight2DSettings {
            light_pass_params: LightPassParams {
                reservoir_size: 4,
                ..default()
            },
            ..default()
        });
twct commented 6 months ago

I resolved this issue for me by changing these lines: https://github.com/zaycev/bevy-magic-light-2d/blob/main/src/gi/util.rs#L28,L32


// Old
pub fn align_to_work_group_grid(size: IVec2) -> IVec2
{
    let wg_size = WORKGROUP_SIZE as i32;
    size + IVec2::new(wg_size - size.x % wg_size, wg_size - size.y % wg_size)
}

// New
pub fn align_to_work_group_grid(size: IVec2) -> IVec2 {
    let wg_size = WORKGROUP_SIZE as i32;
    // Only add padding if necessary
    IVec2::new(
        if size.x % wg_size == 0 {
            size.x
        } else {
            size.x + wg_size - size.x % wg_size
        },
        if size.y % wg_size == 0 {
            size.y
        } else {
            size.y + wg_size - size.y % wg_size
        },
    )
}
GlummixX commented 6 months ago

Great, @twct solution works better than the reservoir_size for me. There is still a flicker around the window borders, but its less noticeable, anyone else is having issues with that? It also causes the lightsource in minimal to deform. image

zaycev commented 6 months ago

@twct thanks for looking into this! @GlummixX let me check what else is missing, we are probably still sampling light out of bounds somewhere