Transparent Rendering

DschoonmakerDschoonmaker Posts: 245Member

I have two transparent objects, water and a waterfall. Unfortunately, the waterfall is not visible from underwater and the water is invisible from behind the waterfall. I know this is because I use SCREEN_TEXTURE in the shaders, but is there any way to work around this?


  • TwistedTwiglegTwistedTwigleg Posts: 2,677Admin

    If you are not already, maybe try using Opaque Pre-pass on one or both of the transparent objects?

    In 2D, I know you can use the BackBufferCopy node (documentation) to make a copy of SCREEN_TEXTURE, which you can use to allow both objects to access the SCREEN_TEXTURE, but I'm not sure how you would go about this in 3D.

  • DschoonmakerDschoonmaker Posts: 245Member

    Opaque pre-pass makes the screen texture black.

  • TwistedTwiglegTwistedTwigleg Posts: 2,677Admin
    edited May 5

    Hmm, so I guess that will not work then.

    I have no idea if this would work, or what the performance would look like, but maybe you can pass the Viewport texture to each object, and then use that instead of SCREEN_TEXTURE? One issue I can see with this potential solution is that UI elements would potentially be included, meaning you might need to have a Viewport that is dedicated just to rendering the 3D scene.

    I'll keep a look out for better/different solutions.

  • DschoonmakerDschoonmaker Posts: 245Member

    Yeah, that could work(would probably have some flaws, though).

  • DschoonmakerDschoonmaker Posts: 245Member

    Is there a way to access the depth texture in the same way?

  • TwistedTwiglegTwistedTwigleg Posts: 2,677Admin

    @Dschoonmaker said:
    Is there a way to access the depth texture in the same way?

    I do not think so, unfortunately. I think the depth texture can only be accessed once. You could have a separate Viewport that is just used for retrieving the depth texture by having a simple TextureRect node that grabs the depth texture and displays it in the Viewport, allowing it to be used.

    That said, there might be a better way. I know in Godot 4.0 there will be more low-level access to the rendering stuff, which probably would make this process easier, but that doesn't help too much with Godot 3. Each Viewport might have its own depth texture separate from the main Viewport's depth texture though.

  • DschoonmakerDschoonmaker Posts: 245Member

    Oh, yeah that would work. Accessing the depth buffer in 2D would be very useful, e.g. a quad in front of the camera for underwater fog makes the water surface invisible, but that could be worked around with a separate viewport for depth textures.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file