Are the standard Transparent shaders broken?

So I have three objects in a scene. A fire Particle system, the sun sphere, and the planet Saturn, which is made with two meshes (one for the planet, another for the rings). There is some text on the screen also.

I have two cameras in the scene, the default camera, and a secondary one. The secondary camera is so that the Sun will draw in front of the particles, and the text will draw on top of everything.

So, here is my problem:

If I use the Transparent Specular shader for the rings on the Saturn model, they are not drawn when they pass in front of the Sun. If I use the Transparent Cutout Specular shader, they are drawn correctly. And if I use the Specular shader, they are drawn correctly. All shaders correctly draw behind the Sun and the particle system, and all shaders except the normal (non-cutout) Transparent shaders draw correctly in front of the Sun.

Attached are shots of the results with the three above shaders.

All this is leading me to believe either I have things set up wrong (please tell me if I have!), or there is a bug the standard transparent shaders; it seems like the draw order is broken. I am wondering if someone could verify this for me? Thanks a lot, I been wracking my brain to try to figure this out. I suppose I could just use the cutout shader, but the transparency effect is much smoother with the regular transparent shaders (instead of the pixellated approximation that the cutout shader uses). If needed, I will upload a UnityPackage of the project. Again, thanks a lot!!

74929--2823--$samples_125.png

Actually I don’t know what technique you’re using…
But it seems like you use the secondary camera to draw the sun after drawing the saturn planet with the ring.

If this is the case … It means that your drawing order is something like this…
SaturnPlanet(Solid) → Ring(Alpha) → Sun(Solid)

If you use Transparent/Cutout/Specular on the ring, that’s ok because it writes to z-buffer…
So that when the sun is rendered, the engine can check if the the sun is in front of the ring or not.

If you use Transparent/Specular on the ring, that’s not ok because it doesn’t write z-buffer…
So that the sun will always be rendered without knowing that the ring is there.

My assumption is that all objects using Transparent/Specular should be rendered last.

Here is the link to download built-in-shader if you want more detail:

BTW, I think you can have your work done with only one main camera… :shock:

Thanks for the explanation. The reason I had the planets on a separate layer from the Sun was so I could have lights that affected only the Sun and lights that only affected the planets. In the end, I changed just the ring component to be on the SUn layer, and it fixed the issue. the lighting on the surface was irrelevant, because being totally flat, it was the same on either layer.

I have two cameras so that the model for the Sun is always drawn in front of the particle system for the fire around it; I was under the impression that I had to do it this way so that the particles would always look like they were behind the surface (and not coming off of it). Is there a way to accomplish the same visual effect with only one camera, and is there a performance hit for having more than one? See http://forum.unity3d.com/viewtopic.php?t=10917&highlight=.

Yes, it would be a little faster (and probably less confusing) to use one camera. You can make slightly modified versions of the shaders with the Queue set to something appropriate to make the order the way you want it. Look in the “Name and Tags” section of the shader docs for more info.

–Eric

I will look into it and probably see if I can do it that way just to know how, but to be honest, using the multiple camera/layer setups actually make more sense to me (being a modeler) that mucking in shader code…I am so not a programmer :stuck_out_tongue:

In the end, for what I am doing, I get 100FPS in the editor (which is the cap), so I figure it doesn’t hurt to do it how I have set it up. As far as that goes, I have used just this setup to do things like 3D skyboxes, and it always works great and AFAIK, doesn’t really hit performance wise (at least, not on my hardware targets).