Skybox drawing over geometry with ZWrite Off

Hello. I am trying to build a 3d scene with procedurally generated skybox (the one built-in) that would show stars during the night.

My setup is simple: I have a light(sun) that revolves around and it’s intensity changes with the angle so that at night it goes to 0 and then it goes to 1 again for the day. I also have a particle system with spherical emitter and “fixed” particles on it’s surface that pretend to be stars.

The particle system’s sphere emitter does not have very big radius to avoid far clipping. As a result of that sometimes very far objects get rendered behind the stars. To fix this issue I thought that I would draw the stars in the scene without adding ZBuffer information to make all geometries in the scene draw over them. This way emitter radius is not important as the stars would always be the furthest objects.

I have created simple shader for the stars with “ZWrite Off” and “ZTest Off” and well, this does not work. It seems that skybox is drawn over my stars just like any other geometry. Trying with “Queue” = “Skybox+1” does not solve the issue. I have a feeling that there is something obvious that I am missing. I would be grateful if more experienced Unity users gave me some hint.

Thanks a lot.

In the game view Unity 5 renders the sky after all opaque geometry. In the scene view and in prior versions of Unity the skybox was rendered first before anything else. So if you want something to render over the skybox it has to render to the depth, or be part of the transparent queues (>Transparency-500), or render the sky manually yourself in the background queue which is difficult if you want to use the built in procedural sky as it uses a special mesh that is not accessible.

I have solved this issue by using two cameras that always have the same position and rotation. One camera has depth setting set to -1 and it renders only skybox and stars. Second camera with depth 0 does not clear the screen but only depth buffer and renders everything except skybox and stars. This way my stars are always rendered behind objects.