This is the testing Godot forums! All forum posts unique to this forum will be deleted! Please use the main forums here for any posts you want to keep. All forum rules still apply.

Transparent Rendering

DschoonmakerDschoonmaker Posts: 216Member

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?

Answers

  • TwistedTwiglegTwistedTwigleg Posts: 2,561Admin

    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: 216Member

    Opaque pre-pass makes the screen texture black.

  • TwistedTwiglegTwistedTwigleg Posts: 2,561Admin
    edited May 2020

    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: 216Member

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

  • DschoonmakerDschoonmaker Posts: 216Member

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

  • TwistedTwiglegTwistedTwigleg Posts: 2,561Admin

    @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: 216Member

    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

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.