Transparent shader with Z-buffer and interlacing objects

Hi.
I’ve a shader problem.

I’m doing an application than renders human organs where the user can rotate the camera around the body and can change the alpha level of each organ independently.

I do not use Unity transparent shader because it doesn’t write to the zbuffer (some organ like the alimentary canal have parts that overlay each other (and I want to show the organ as a whole with transparancy)) → so i used 2 passes in the shader (like this : unifycommunity.com). It works fine when I display only one object.

The problem is that when I want to display several transparent objects, when I change the camera orientation, some parts are not displaying. Changing manually the render queue is not a solution because it’s the camera (controlled by the user) that determines which object are displayed first. It’s particulary annoying with veins and arteries because some parts are inside an organ and other parts are external.

I found several topics in the forum talking about this (here and also here) but haven’t found a solution adapted to my problem.

So I don’t know how to help the algorithm to display things back to front to solve this depth sorting problem without manually using render queue and ? Any hints ? Thanks by advance.

Tom

You could break your meshes up into smaller pieces such that they could be sorted. Seems cumbersome though.

Have you tried other shading styles, such as varying the alpha with the angle to the camera (like rim lighting). That can often show internal structure better than normal flat transparent shading, while still not writing to Z buffer. After all, you’re not trying to render reality.

Like this shader does.