Raymarching for clouds - how to deal with transparency?

Hey hey people,

I’m using raymarching (using a fullscreen shader) to draw fluffy clouds. Now, I’ve quickly realized transparent objects are going to be fun. The poor mans fix would be to draw clouds before any transparent objects and maybe just make transparent things fade out over distance or use LOD to hide them.

I’ve looked at Order Independent Transparency (here GitHub - happy-turtle/oit-unity: Order-independent Transparency Implementation in Unity with Per-Pixel Linked Lists) which looks very cool but 1. is not really the problem I’m trying to fix and 2. I would still need to change my cloud shader to work with it.

It seems to me like the simplest solution is to have a separate depth buffer for transparent objects, draw them again with a material overwrite (opaque depth) before the cloud pass and combine this buffer with the existing depth buffer/sample the separate depth buffer too.

I don’t have a lot of experience with shaders and I can’t find good information on how to deal with this, so any help would be appreciated :slight_smile:

It turns out fullscreen shaders can actually write the depth buffer if “Bind Depth-Stencil” and “Depth Write” are enabled. I then execute the cloud pass “Before Rendering Transparents” and that fixes the whole issue.