godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.17k stars 21.2k forks source link

Light shadow artifacts in low-resolution 2D game #84005

Open markushall opened 1 year ago

markushall commented 1 year ago

Godot version

v4.1.2.stable.flathub [399c9dc39]

System information

Godot v4.1.2.stable (399c9dc39) - Freedesktop SDK 23.08 (Flatpak runtime) - X11 - Vulkan (Mobile) - dedicated NVIDIA GeForce GTX 1660 SUPER (nvidia) - Intel(R) Core(TM) i7-3770K CPU @ 3.50GHz (8 Threads)

Issue description

I am working on a low-res (384 x 216) pixel game using the mobile renderer, and I have a problem with the light occluder producing weird artifacts. This effect increases with the distance to the light source.

Minimal reproducible example scene:

Skärmbild från 2023-10-25 15-30-10

If we zoom in a bit on the lamp and the LightOccluder2D there are stripes of what looks like some kind of inverted anti-aliasing going on, the further we get from the light source.

Skärmbild från 2023-10-25 15-32-33

Skärmbild från 2023-10-25 15-34-54

The closest I get to removing this effect is when setting Cull Mode to CounterClockWise. That makes the artifacts go away on the top side but adds them to the bottom side instead.

Skärmbild från 2023-10-25 15-36-20

Misc observations:

Steps to reproduce

  1. Start the MRP
  2. Select the 2D view
  3. Zoom in on the top right right side of the occluder. Artifacts should be visible.
  4. Run the "game". Artifacts should be visible.

Minimal reproduction project

occlusion_test.zip

Calinou commented 1 year ago

Can you notice these artifacts when running the project? I notice your project is using the canvas_items stretch mode, not viewport. Zooming a lot in the editor tends to exaggerate artifacts that won't be noticeable in real world conditions.

If we zoom in a bit on the lamp and the LightOccluder2D there are stripes of what looks like some kind of inverted anti-aliasing going on, the further we get from the light source.

This is expected, as 2D shadow resolution is limited and doesn't scale with camera zoom for performance reasons. You can change it in the project settings (Rendering > 2D > Shadow Atlas > Size).

markushall commented 1 year ago

Thanks a lot! Yes, I got a sawtooth line when running the exported project (export all, release):

image

However, I can confirm that upping the shadow atlas size (to 8192) removes the artifacts when running the example project (debug). They are still visible in the editor, but I don't think that's much of an issue.

image

In my actual project, not the example one, I had to increase the shadow atlas size to 16384 (or maybe I can set it a tad smaller) to get rid of the artifacts. I have no idea on what impact that will have have in terms of performance and memory consumption in the finished game, but I guess time will tell.

Calinou commented 1 year ago

I think the underlying issue is that there doesn't appear to be a way to control the bias used for shadow casting, like you can with shadow maps in 3D. This would likely alleviate the issue entirely in your case, without having to increase shadow resolution.

bitbrain commented 1 month ago

I can replicate this issue too on a very low resolution viewport due to 2D pixelart.

When using PCF13 and changing filter smooth, some strange "square" artifacts can be observed. In this clip I am changing the slider from filter smooth 0 to maximum and back. When maxing out the value, the artifacts become most visible:

https://github.com/user-attachments/assets/a38316b2-f0f2-4492-846a-acfd5f2abaab

Godot Engine v4.3.stable.steam.77dcf97d8 OpenGL API 3.3.0 NVIDIA 546.17 - Compatibility - Using Device: NVIDIA - NVIDIA GeForce GTX 1080