godotengine / godot

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

mix mode Light2D shadows misbehave under ViewportContainer #46153

Open danboo opened 3 years ago

danboo commented 3 years ago

Godot version: v3.2.4.rc2.official

OS/device including version: Windows 10, Nvidia 1070, GLES3

Issue description: I have a scene that contains Light2D nodes with mode set to mix. These lights have shadows enabled, with shadow_gradient_length set to 8. These lights are occluded by walls (LightOccluder2D) in the scene. This works fine when I play the scene directly.

The issue is that I want to play this scene in a sub-Viewport via a ViewportContainer, but when doing so, the shadows behave differently, and don't appear to be fully occluded. There seems to be light bleeding into the wall's LightOccludder2D.

I've reduced it to a simple example using a simple square to represent the wall occluder. This is what I see when playing the original scene and behaves as expected by showing a completely black (occluded) square.

image

After reparenting the same scene to a ViewportContainer you can see the slight gradient at the bottom of the square (difficult to see on a white background):

image

Steps to reproduce:

  1. Download the attached project.
  2. Play the DefaultViewport scene. Observe that the square is full black.
  3. Play the AlternateViewport scene. Observe that the square has a grey gradient near the bottom.

Minimal reproduction project:

BleedingShadows.zip

kuruk-mm commented 3 years ago

Ok, I can confirm this bug. Maybe it's not 100% what it's happening with @danboo, but I guess that it's related. I will give more information.

Godot version: v3.3.2.stable

OS/device including version: Linux Mint 19.03, NVIDIA GTX 1660, GLES3 I can also confirm this happening in Windows (idk exactly the hardware)

Issue description: This is only happening in GLES3, using Light2D with Mix Mode and only when we use it as a child of a Viewport.

When we draw a Light2D with Mix Mode, we don't see the alpha channel of the light (i think... see the photos because idk how to explain it correctly haha)

2DScene.tscn (GLES2/GLES3) -> No problem image

ViewportContainer.tscn (GLES2) -> No problem image

ViewportContainer.tscn (GLES3) -> Bad image

I realized that if we enable "Transparent bg" in "Viewport" it will fix the problem, but I got other problems that I don't want.

I don't know when it was introduced. It doesn't seems to be related to batch rendering, because even if I disabled it, it still happens.

Steps to reproduce:

Minimal reproduction project: Viewport2DLightTest.zip