Quick question… I want to have fog in my game that is not distance based (there should be some of that too) but based on height on the Y axis. Cliffs fading off into the great grey oblivion below and hiding the fact that they only go down 20 meters.
I don’t yet know how to go about this, but my intuition tells me I am going to need a custom shader. Also that that shader I want is probably ridiculously simple. Also that I am simpler still, when it comes to coding shaders. Anyone know how to do this/ already done it?
“Volumetric fog” is the magic word, and yes, you’ll need a custom shader (if it’s possible).
The challenge is that it’s not simply a Y position you need to take into account, but a whole range of them (from the camera’s origin to the pixel being rendered.) You could probably fake it with just one position, or by averaging or taking the minimum of the two.
You have eye position. And you have the position of vertex (or pixel) being rendered. And you know the altitude of your fog. So you compute the length of the line that goes from eye to the vertex/pixel, that is below the fog altitude. That gives the distance that is “in fog”. From that distance, you compute the fog density (using linear, exponential or whatever fog function you want).
Doing this in a vertex shader would be faster, but for large polygons this can be inaccurate. Doing this in a pixel shader would be slower, but more accurate.
This thread might be dead, but what the heck.
It sounds like the cliff doesn’t move, so you could just add a trans → gray gradient onto the texture in the editor of your choice. And what do you know, it fades into an endless gray… 20 meters. Add a bottom or gray skybox and you’re good to go.