Is anyone privy to an equation that could determine at what distance fog would completely blank objects out (depending on the RenderSettings.fogDensity setting, natch) so I can set the required Camera farClip exactly?
The Unity manual says this:
…but I’m hoping there’s a way to be a bit more scientific than that
This specific quote refers to getting performance gains from adjusting the far plane. Fog has little to do with it, as it always stretches from near to far plane (regardless of the formula used and assuming you use Unity provided shaders).
The art of positioning your far plane comes down to placing it as close to the near plane as possible without ruining the visual experience (too much). To get performance gains, the distance between near and far plane needs to be (significantly) smaller than your level, or there will generally not be much geometry to cull.
Not at all…otherwise, objects would become more or less affected by fog as you moved the near or far clip planes, which would be highly undesirable. You change the density in the render settings.
To answer the actual question, there are 3 types of fog (linear, exp, and exp2). The Unity shaders use exp2 by default, the equation for which is F = e^((-D * z)^2). That’s from this page, which explains more about fog and might be enough to get you going.
You are right. Guess I have always misunderstood that.
At any rate, what I meant to say still stands: if the point of the question is performance, you best set the far plane to the a distance that balances performance and visual experience and then choose the fog density to match, as it isn’t the fog that affects performance.
It’s not about performance, he just wants to do the bit about making 100% fog match up with the far clip plane programmatically instead of manually. I thought about that myself once, but never got around to it, hence the above link is all you get out of me on this topic.
That makes no sense to me
Assuming F=0 means no fog, and F=1 is complete fog
then to calculate the min and max distances, you would get: log e (1) = (-D * z)^2
which is nonsense as that would make z=0, as log e (1) = 0
also log e (0) has no value, which would mean no fog would be impossible.
Sorry for replying on such an old thread, but I’m trying to do the same as mklaurence, and I would apprecaite some help
EDIT:
Alright, just realised that if F=1 means no fog, and F=0 is complete fog, then it makes a lot more sense,
basically it would mean that the distance has to be infinte for the fog to be completely opaque.