Unity Discussions

Transparent Shader Problem (829132)

When I set objects to transparent with the default URP/Lit shader, I can see inside of them even though I set alpha to 1 and they have no texture attached. See attached images: they are identical except transparency toggle. What is causing this behavior? Is there a way to fix it?


Hi!
In order to determine which surface is closest to the camera, URP uses a depth buffer. In the opaque pass, URP draws opaque objects to this buffer. In the transparent pass, the depth buffer is used to determine if a transparent surface is visible. The transparent object itself doesn’t draw to the buffer and therefore doesn’t know if the fragment it’s drawing is the closest one.

What you can do to solve this is to force that the transparent objects write to the depth buffer. Without writing any shaders this can be done using the render objects renderer feature:

Start by assigning the relevant transparent objects a layer (chose a name e.g. TransparentWithDepth).

On the renderer in use; remove the layer from the Transparent Layer Mask in the Filtering section. This will cause all objects in the layer to not be rendered by URP. This is expected as we want to take over rendering of these objects.

Add a Render Objects renderer feature. Set the event to be after transparents, set the queue to transparents and the layer mask to only draw the TransparentWithDepth layer. In the overrides section, make sure to write to depth:
6855143--798728--Screenshot 2021-02-19 at 14.06.07.png

I hope this helps! :slight_smile:

2 Likes

It worked, YOU ARE THE BEST!! Thank you!

Which GameObject do I assign these scripts to?

Morty Proxy This is a proxified and sanitized view of the page, visit original site.