- Home /
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. $$anonymous$$y 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 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.
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
Answer by x70x · Mar 25, 2013 at 02:27 PM
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 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.
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 $$anonymous$$acbook Pro so that's good enough for me. If I run into problems I might look into a different way of rendering the environment.
The limited flexibility of Unity's image effects was frankly a huge let-down following my Pro purchase, so I'm excited to see others having some success at working around their numerous limitations.
However, this scenario isn't working as you've described it on my end, and it never has for me before. Getting multiple cameras with their own independent image effects (or lack thereof) to work together is something I've tried and failed to achieve on numerous occasions, investing many joyless hours with little to show beyond edge-case successes and some killer buyer's remorse.
When I do precisely what you've described in this answer for myself, the "Don't-Clear transparency camera" negates the scene camera's global fog altogether. Using Forward Rendering on that camera draws the fog again, but all the clearing methods result in the particles ignoring their scene depth and drawing atop everything rendered by the scene camera, as Benproductions1 described.
In fact I'm not sure I've ever had an image effect "survive" being drawn this way, "behind" a second camera, no matter their clear flags or culling conditions. At least not without creating a hall-of-mirrors effect, losing depth information, or ruining the scene's draw order continuity.
In my experience, only the camera with the highest draw order has its image effects processed and applied to the final image properly. Any time I somehow broke this rule, for instance by manually rendering, using Blit() to explicitly control draw order, something else would break.
Would you consider putting together an example project demonstrating your cam / fx setup so I and others can learn from your success? It might be a great asset to folks like me who've searched off and on for such things forever. :)