godotengine / godot

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

Child of SubViewport is drawn to root viewport #89127

Open Hauke-Mundt opened 8 months ago

Hauke-Mundt commented 8 months ago

Tested versions

System information

Godot v4.2.1.stable - Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3070 Laptop GPU (NVIDIA; 31.0.15.5161) - AMD Ryzen 7 5800H with Radeon Graphics (16 Threads)

Issue description

in the docs at https://docs.godotengine.org/en/stable/tutorials/rendering/viewports.html#cameras-2d-3d camera "CameraA will display on the Root Viewport and it will draw MeshA. CameraB will be captured by the SubViewport along with MeshB. Even though MeshB is in the scene hierarchy, it will still not be drawn to the Root Viewport. Similarly, MeshA will not be visible from the SubViewport because SubViewports only capture nodes below them in the hierarchy."

When i make the same setup as in the docs, both meshes are visible with both cameras (if i do not set render layers and cull masks - which can be tricky and seems to not even be possible for the editor viewport). That camera b can see what is above it's viewport is necessary, as otherwise rendering to a subviewports would be kind of meaningless (e.g needed for post processing shaders as a buffer replacement). The other way round i am not sure ... and both contradict the docs. I am not sure what is wrong, the way subviewports behave or the docs.

Steps to reproduce

Copy the setup from the docs (screenshot above).

Minimal reproduction project (MRP)

bug.zip

monigodote commented 7 months ago

It's a problem with the docs, you have to check Own World 3D in the SubViewport, otherwise they are sharing the world, and thus, the meshes.