cancel
Showing results for 
Search instead for 
Did you mean: 

Distance Fog (using Forward renderer) - how to make it cheap?

stefanfrog
Explorer

Hello devs!

My team is working on a VR game with quite long view distances and we've been trying out different solutions:

  • Exponential height fog actor - too expensive
  • Custom post-processing material - too expensive as it requires Mobile HDR to be enabled
  • Planes with cloud textures using alpha-masking with Temporal Dithering - too expensive


Anyone got other nice practises on how to do a performant distance fog? Or is it always an expensive trade-off?

Thankful for all input!

 / Stefan

5 REPLIES 5

CarpetFace
Expert Protege

Depends on what you can get away with game play wise.  If you don't need to change it in real time, you can pre-bake it into vertex color.

That's actually a good idea, Pre-baking it should work. Thanks for the input!

Can you guys elaborate please on this technique?

Gameplay-wise, some games this technique will not work for.  For example, say you have an indoor or outdoor environment where you have game assets that you want to have distance fog appear on top of, if the game player can move relative to those assets in such a way that you would want the distant fog to disappear, then pre-baking it will not work.  But if the distant fog only appears on assets that are always going to be far away and the player (camera) can't get closer or farther from it, then you can prebake the distance into the vertex of the asset.  This pre-baking could be done using vertex color, or even texture UV.  Then in the material for that asset, you would use this distance information from the vertex color or texture UV to create a distance fog like effect.

 

The fewer operations the material has to do, the better.  So one of the cheapest ways to do pre-baked distance fog is when the distance fog and asset color is combined to form a single gradient, which means that an unlit opaque material just need to use the distance information as the UV for a single texture lookup.  

 

If the query is about how to pre-bake it.  If you are using UE's Landscapes, I do not have enough experience with them to know how or even if it is possible.  But if you are using a procedural mesh component, then you can put the information into the vertex color rather easily, but you have to either programmatically define the entire mesh, or open another mesh and then create a procedural mesh using it.  I believe both UE4 and Blender have tools for painting vertex color, but I think for this purpose it would be rather tedious.  You really want an editor only programmatic way to calculate the distances and store that with the mesh vertices.  While opening several meshes and combining them into a single procedural mesh might sound tedious just to get distance fog, keep in mind that this will also mean you've just reduced the draw call of those meshes into a single draw call, which is kind of nice.

 

Personally, I think this is good technique for very distant geometry like far away hills and mountains.  Things that are so far away that you don't need to worry about having trees or other objects on top of it.  Things that are so far away that you don't need to worry about changing the fog because the player can't move far enough for it to make a difference.  I think most VR Quest games I've seen don't go this route though, and instead just have texture backdrop.  

Thanks CarpetFace for the detailed explanation.

I don't think it'll fit my current need but is a nice technique to know about.

Cheers