Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2D shadow issues with multiple viewports and particles with enabled SDF collision #99228

Closed
timoschwarzer opened this issue Nov 14, 2024 · 8 comments · Fixed by #99426 or #99463
Closed

Comments

@timoschwarzer
Copy link
Contributor

Tested versions

(CC @DarioSamo)

System information

Godot v4.4.dev (76fa7b2) - Arch Linux #1 ZEN SMP PREEMPT_DYNAMIC Fri, 08 Nov 2024 17:57:58 +0000 on Wayland - X11 display driver, Multi-window, 2 monitors - Vulkan (Forward+) - dedicated Intel(R) Arc(tm) A770 Graphics (DG2) - Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz (16 threads)

Issue description

Screencast.From.2024-11-14.10-46-03.mp4
  • There is a classic split screen setup (2 viewports, same world_2d) as this bug seems to only appear when rendering in multiple viewports
  • There is a particle system with particle collisions enabled
  • The particle system is not enabled initially
  • The left viewport has a camera, that moves from position A to position B
  • The right viewport is fixed at position A
  • There is one PointLight2D L1 attached to the camera/godot icon, and one PointLight2D L2 at position B

Steps to reproduce

  • When the camera has moved to position B (= left viewport only shows light L1 and right viewport only shows light L2) and the particles are enabled, the light L1 in the left viewport has shadows from light L2.

Observations:

  • When you enlarge the right viewport to render both lights, the issue disappears:

    Screencast.From.2024-11-14.10-57-41.mp4

Minimal reproduction project (MRP)

light-bug-repro.zip

@DarioSamo
Copy link
Contributor

DarioSamo commented Nov 19, 2024

Should be fixed in #99426.

The problem was a bit complex, but basically there was a wrong dependency detection if the following steps were taken:

  • The render target is used as a uniform texture for sampling (first viewport).
  • The render target is switched to a color attachment, but the first draw list that does so didn't cover the entire area (shadow rendering for second viewport).
  • The next draw lists would fail to detect an intersection and wouldn't insert themselves as being dependent on the transition caused by the previous step. Therefore, the shadow rendering of the second viewport was being done before the first viewport was rendered, overwriting the shadow rendering performed for the first viewport.

So this problem popped up often with resources shared between subviewports, as it reuses the same atlas and therefore causes a dependency on the writes.

There's potential to optimize this to do more drawing in parallel if different textures are used per sub viewport! But that's outside the scope of my fix and something the canvas renderer would have to detect if it's worth doing.

@timoschwarzer
Copy link
Contributor Author

Thanks a lot! ❤️

@timoschwarzer
Copy link
Contributor Author

Unfortunately, there are still problems with shadows in multiple viewports. @Calinou please re-open this issue as I don't have permission to do so. I will provide a new MRP tomorrow once I've figured out and isolated the specifics.

@timoschwarzer
Copy link
Contributor Author

timoschwarzer commented Nov 20, 2024

Scene:
Image

Result:
Image

MRP:
light-bug-repro-2.zip

CC @DarioSamo

Godot v4.4.dev (a0cd8f187) - Arch Linux #1 ZEN SMP PREEMPT_DYNAMIC Sun, 17 Nov 2024 16:06:09 +0000 on Wayland - X11 display driver, Multi-window, 2 monitors - Vulkan (Forward+) - dedicated Intel(R) Arc(tm) A770 Graphics (DG2) - Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz (16 threads)

@DarioSamo
Copy link
Contributor

@timoschwarzer 4.3 stable shows me this and it's what I see when I disable the intersection code.

Image

So is it supposed to show up on the left or the right?

@DarioSamo
Copy link
Contributor

Please confirm if #99463 fixes the issue for you.

@timoschwarzer
Copy link
Contributor Author

@DarioSamo Sorry, my screenshots are a bit confusing. The left viewport has the camera attached that shows the right light. So yes, your screenshot in 4.3 renders correctly. I will test your PR in a bit.

@timoschwarzer
Copy link
Contributor Author

@DarioSamo I can confirm the issues are gone with #99463

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment