Shaders - Overlapping transparancy

Hi all!

I’m trying to use a transparant shader on my model but i’m not quite getting the results i’m looking for. What i’m getting now is image A. As you can see, in image A overlapping transparent parts are still being shown. What i would like is image B.


Is there a specific term for how the alpha works in image B? And how would i achieve this effect in Unity?

Any help is greatly appriciated!!

This is actually a relatively hard thing to do.

To render things like they’re on image B you’d either need to use fake dithered transparency, or render the human onto a render targget as a solid object and then render data from the buffer on top of current scene.

You will not be able to achieve this kind of result using a normal transparent shader.

Actually it might be possible since image B shows no self transparency.

What needs to be done is first you got to render to depth buffer only during normal pass (so object with alpha = 0 but with draw to z buffer) and than you draw on top of it normal transparent material but with “z” less or equal.

So besicaly your mesh will have two materials.

The only problem that you will have is that your transparent objects behind are not going to be shown.

3 Likes

Nice idea, BUT directional lights with shadows use depth buffer information and assume that objects that write into depth buffer are not transparent. Most likely there are going to be artifacts.

I was using it in built in some time ago and it looked ok, you can have invisible object that cast shadows it is all about depth buffer. (naturally shadow is not going to be more transparent)

Now I don’t know about HDRP.

Gave it a thought, it can definitely cause issues, as object rendering order (AFAIK?) is not guaranteed. So if this thing is rendered BEFORE some object that is behind it, there will be a hole in the scene.

Draw both materials as transparent but first should draw to depth buffer and second normal transparency.
This way no holes in opaque objects and objects are sorted back to front.

And I think I was doing it like this, I generally had gliches with the sky as I remember but even this might have a solution.

Darn… I had no idea it would be so hard to show an object with no self transparency…!

Thanks a bunch for the ideas and suggestions! Though these are a bit above my league. I’m trying out the dithering transparency now. It’s not perfect but it works… So unless someone has an idea that my simple brain can understand, i’ll go for the dithering solution :wink:

It might be not so difficult as you think, you could give it a try, at least you will learn something new. Are you doing SRP or build-in ?

Definitly true! I’m using SRP but I just have no idea where to begin…

You can set order in the render queue to control scenarios exactly like this one. You may indeed need to make sure it renders before or after other things depending on what they expect is in the depth buffer, but that’s just a matter of changing the render order number.

I’ve used this approach before and I don’t recall running into issues once properly set up.

Note that it doesn’t have to be “two materials” as described, it can be one material with two passes - one depth only, then the normal transparent draw.

There’s “weighted blended transparency” in my signature and I recall running into a TON of issues when dealing with depth buffer writes. Basically, I’ve never figured out how to make the smoke show up in places where skybox is present. However, this is a bit different thing compared to what is trying to do.

Regarding the proposed scenario (invisible depth write), I’d expect this kind of model create holes in particle systems like smoke, and black sillhoette on objects behind it when it is used with a forward renderer. Meaning light might not blend properly.

It does need testing though, as it’s been a while since I tinkered with things like “raytraced primitives”.