Why are all particles drawn behind my global fog?

As far as I can tell, particle effects do not seem to have any interaction with the global fog effect. All particles are always drawn behind the fog.

After doing some research I added the @ImageEffectOpaque to the GlobalFog.js, but that causes all transparent particles in the scene to disappear completely (including the fog). Is there any way to have the global fog effect interact with other transparent objects and particle effects? Did I do something wrong with @ImageEffectOpaque? I followed the advice here. Does my particle shader need to be adjusted also?

As a side note. My game uses three cameras. One that renders the skybox first. The next renders the scene and has the global fog image effect (as well as a few others). And a third that renders the GUI last on top of everything else.

In doing a little more research it seems like perhaps this is part of my problem [http://answers.unity3d.com/questions/330892/why-is-the-second-camera-interfering-with-image-ef.html][1] I don't really understand most of what they are saying though. Anyone care to help me figure out what is going on there? I think it's my multiple cameras interfering with each other somehow. [1]: http://answers.unity3d.com/questions/330892/why-is-the-second-camera-interfering-with-image-ef.html

The reason behind things getting rendered out of order, is because global fog works with the Z buffer. Transparent objects/particles do not write to the z buffer, so particles are effected as much as the objects they are covering by the fog. This is impossible to counter

1 Answer

1

I found a work-around solution where I change all of my particle effects to their own layer and add another camera that masks only that layer. I set that camera to “Don’t Clear” and then render it in front of my scene’s camera (global fog is on the scene camera), but behind my GUI camera. Seems to work fine, but I don’t know if having 4 cameras rendering on top of each other is a great idea. I guess it’s only a problem if I run into performance issues though.

Your workaround draws particles Infront of all objects, if you only ever need it to do that, then your solution works, but otherwise there is no way possible to achieve this..

I can assure you that it does work. The particle camera's clear flags are set to "Don't Clear" and only renders game objects that have the "particle" label. [Here is a screenshot][1] where the particles are clearly behind the terrain. You can't see the fog in that shot, but the particles are indeed rendering in front of the fog also. The particles do render in front of everything else when the clear flags are set to "Depth Only", but "Don't Clear" works perfectly. [1]: http://i.imgur.com/1diTmeb.jpg

Ah, yes Don't Clear still renders everything, but only the flags change the pixels... This method is btw quite slow....

Well the good news is that my game doesn't have a ton of complicated stuff to render, and I'm not targeting low end machines. All the same, it runs pretty smooth on Fastest quality settings on a Macbook Pro so that's good enough for me. If I run into problems I might look into a different way of rendering the environment.

Hmm, okay, well the answer to this is going to be more vague than you probably want, but really I just messed around until they worked. I'm not sure why the "Don't Clear" flag doesn't work for your transparency camera. I have the Global Fog effect on my scene camera which is rendered behind my particle/transparency camera. Did you try adding the @ImageEffectOpaque tag into the image effect scripts? I could look into which ones I added that to in order to get it to work.