Godot Version
4.4
Question
I am trying to create a psudo recursive 3d world, where if you fall off the world, you will see the same world under you where you will land back on.
To achieve this effect I am effectively rendering the same world from a higher perspective (a second 3d camera at the same rotation as the main camera) and overlaying that over the screen.
I am rendering the scene in 3 separate steps and layering them like such:
- the background/skybox
- the camera from above (transparent background)
- the main camera (transparent background)
This works great, however there are issues if some objects from the background are suppose to clip into an object in foreground, as they are only layered over each other and not masking properly.
I would like to get the depth texture from all the cameras and use that to properly layer all the outputs, however I haven’t seen a quick and easy way to get the depth texture from a subviewport. The only way I have researched is under each subviewport, make a quadmesh with a shader to output the depth into the subviewports texture. This approach isn’t ideal as it requires me to make a duplicate camera and subviewport for each layer I want to render.
My main questions:
- Is there an easier way to get a depth texture from multiple cameras?
- Or is there a better approach to render my recursive world as I described.
I think you are over thinking this … you can leave most of the hard work to the engine and use script to simply move objects that need to be viewed.
For example … if you fall off the world, you could simply have a separate mesh for the sides - like a cliff or something - then just set the transform of the world to a position beneath the falling player. Then you could invent a transition like a fade-in blend effect.
Also, once the player hits the ground, you could set the global_position of the player and world back to y = 0.0 to make sure there aren’t any problems with floating point numbers.
I don’t really understand the pros and cons of transparent backgrounds - doesn’t the extra transparency slow everything down?
Thank you for the quick reply!
Yes, that is true. I could resort to that if I really needed to. However my goal is to be able to see both worlds at the same time, giving it an almost fractal effect (with some fog in the future… which would need a depth texture unless I fog the whole layer.)
Here is a quick mock up of what I have working right now. The only real complaint with this example is my water is supposed to clip into the sky sphere (yes it is supposed to be a real object that encapsulates the world.) and some other small things with looking back up and the bottom world not overlapping the top at certain points.
Regardless, some suggestions on better alternatives, or on improving this method, while keeping my goal of being able to view both worlds at the same time, would be appreciated!
Thank you again for your suggestion and I will probably be resorting to that if I can’t find anything else!
Instead of a duplicate camera just try a duplicate mesh and measure FPS.
I’d go with mesh duplication if that’s suitable.
Otherwise you’ll need to do depth compositing using the Compositor.