Search public documentation:
Document Changelog: Created by Daniel Wright.
- Fog Volumes
- What are Fog Volumes?
- Setup methods
- Quick Automatic Setup
- Automatic Setup Details
- Quick Manual Setup
- Manual Setup Details
- Density Functions
- Additional Settings
- Fog Volume Actor
- Fog Volume Material
- Interaction with Height Fog
- Transparency in Fog Volumes
- Performance Implications
- Best Practices
Fog Volumes were introduced in QA_APPROVED_BUILD_MAR_2007. Support for translucency fogged by fog volumes was added soon after and is in QA_APPROVED_BUILD_APRIL_2007. Particle fogging was enabled in QA_APPROVED_BUILD_MAY_2007. The constant height density function was also removed in this build, because the same functionality is available through a constant density function with a clipping mesh. This reduces the number of compiled shaders and is actually more efficient. The automatic setup method was added in QA_APPROVED_BUILD_FEB_2008, before that only the manual setup method was supported. In QA_APPROVED_BUILD_APR_2008, shader complexity was extended to include fog volume cost. In QA_APPROVED_BUILD_JUL_2008 a density setting of 0 is treated the same as bEnabled=False.
A Fog Volume essentially consists of 3 things: A density function which controls the falloff of the fog, a mesh that clips the density function and a material that defines the color of the fog. Fog Volumes are a superset of the functionality available in HeightFog, because they can be bounded by a mesh, handle multiple density functions and use a customizable material. Fog Volumes seamlessly handle the camera going inside the volume and opaque objects intersecting the volume.
There are two ways to associate a density function with the mesh that clips it, these are called the automatic and manual methods.
- Place a FogVolumeConstantDensityInfo (Found under Generic Browser->Actor Classes->Info->FogVolumeDensityInfo)
A constant density fog volume after being placed.
The automatic setup is designed to require as few clicks as possible to give the most commonly used result. When you place a new fog volume info actor a static mesh component is automatically added to it and used for rendering the fog volume, you can access this component via FogVolumeConstantDensityInfo->FogVolumeDensityInfo->AutomaticMeshComponent. When you scale or rotate the fog volume info, the automatic mesh component will also be scaled or rotated to fit the fog volume. This is important for good performance since the mesh is what gets shaded, it must bound the visible fog area tightly or there will be wasted shading calculations especially on the sphere density type. Additional automatic setup details:
- Changing DrawScale3d on the fog volume info away from 1.0 will cause the AutomaticMeshComponent to no longer match up with the size of the fog volume info.
- When you place a new spherical fog volume info, DrawScale X, Y and Z are setup such that the AutomaticMeshComponent tightly bounds the fog volume info.
- You can control the position and scaling of the AutomaticMeshComponent relative to the fog volume info by changing AutomaticMeshComponent->PrimitiveComponent->Scale, Translation, etc.
- When you create a new fog volume info, a new material instance will be created in the level and automatically applied to the AutomaticMeshComponent. This is set as FogMaterial. If you have a material selected in the Generic Browser, that material will be used as the parent, otherwise EngineMaterials.FogVolumeMaterial will be the parent. You can replace this new material instance with any fog volume compatible material of your choice, but be sure to change FogMaterial on the info actor instead of changing the actual Materials array on the AutomaticMeshComponent.
- The SimpleLightColor property of the fog volume info is a convenience property and will be set as the 'EmissiveColor' vector parameter of the AutomaticMeshComponent's material instance. If you override the material instance and it does not use an 'EmissiveColor' vector parameter, SimpleLightColor will no longer function.
- The AutomaticMeshComponent is not selectable in the editor unlike the meshes used with the manual method, you have to select the fog volume info actor itself instead.
- The AutomaticMeshComponent will have all collision, lighting and shadowing flags set appropriately.
- Place a closed static mesh
- Place a FogVolumeConstantDensityInfo (Found under Generic Browser->Actor Classes->Info->FogVolumeDensityInfo)
- Clear the newly placed fog info's AutomaticMeshComponent
- Add the static mesh to the info actor's FogVolumeActors array.
- To do this you first need to open the properties of the FogVolumeConstantDensityInfo you placed, expand DensityComponent
- Click the lock at the top left of the property window
- Select the static mesh in the viewport
- The property window should still show the info actor, since we locked it.
- Click the + to add an entry to the FogVolumeActors array
- Now click the 'use selected actor' button on the new entry.
Set the static mesh in the FogVolumeActors array. At this point the static mesh should be rendered as a fog volume.
- When you add a new FogVolumeActors entry, it will get setup with default fog volume settings, which disable collision, lighting and shadowing. The new FogVolumeActor's mesh component material will also be changed to use EngineMaterials.FogVolumeMaterial. To override this set the material on the target FogVolumeActor entry, FogMaterial is not used for the manual setup. Note: Due to a limitation of the property system, currently the defaults will be set for all entries in the FogVolumeActors array when you add a new entry! It is best to set all the entries in the FogVolumeActors array FIRST and then set their materials as you want.
- Using the manual setup allows you to have multiple meshes associated with a single fog volume info, and it allows you to animate the info or meshes separately. However it can be tedious to setup and animate multiple parts, in which case an automatic setup would be easier.
The Fog Density Function defines how thick the fog is in different parts of the world. In UE3 these density functions are represented by FogVolumeDensityInfo actors. One of these must be placed and have Fog Volume Actors assigned to it. Here are the different density functions, in order from least expensive to most.
A cube rendered with the constant density function. The location of the fog info actor is irrelevant because the density is constant everywhere.
The linear halfspace density function bounded by a cube mesh. Density starts at 0 at the plane and increases away from the plane, which is oriented in the xy plane in this example, but can be used in any orientation.
The Spherical density function, which has smooth edges. It is bounded by a mesh which is not visible in the first picture because it doesn't clip the sphere. In the second picture the mesh clips the sphere. A preview component shows the extent of the sphere density function in wireframe.
Properties of a FogVolumeSphericalDensityInfo.
The fog volume actor is what is actually rendered, and it clips the density function to the interior of the mesh. Any CLOSED static or skeletal mesh will work. This means that any ray cast through the mesh must intersect the same number of frontfaces as backfaces. On Xenon and the shader model 2 PC implementation there is a limit on the number of frontfaces or backfaces that can overlap before artifacts appear. Currently the limit is 4 backfaces overlapping or 4 frontfaces overlapping.
The material assigned to the fog volume actor must have these settings:
- Lighting model is Unlit
- Blend mode is one of the translucent modes (Translucent, Additive or Modulative)
- There must be an emissive input
- bUsedWithFogVolumes must be checked. Note that this flag is exclusive with the other usage flags, once it is set you can only use the material on fog volumes.
A minimal fog volume material setup. Opacity defaults to 1 so it does not need to be specified. The emissive input of the material is the fog volume color, the opacity input scales the fog contribution, which is calculated from the distance through the fog volume. Volumetric Lighting Guide for volumetric lighting tricks using textures. This also affects other mesh attributes such as the normal, reflection vector, etc.
Fog Volumes are not affected by height fog. This may cause artifacts in high density height fog, but it is preferable to per-vertex height fogging on the fog volume which breaks down when using large fog volumes. Intersecting fog volumes are not supported, they will be drawn as if they were completely in front or behind each other.
Fog Volumes are sorted with transparent objects, so they will draw correctly if they are completely in front or behind transparent objects. However, transparent objects that intersect with fog volumes can't be fogged correctly and efficiently on modern hardware, so they are approximated. It is important that you set the FogVolumeDensityInfo's ApproxFogLightColor to approximate the material color! This is the color that the fog volume will apply to intersecting translucent objects.
Set the ApproxFogLightColor member so that transparent objects intersecting the fog volume will be fogged correctly. Fog on Transparent objects intersecting Fog Volumes has the following limitations:
- Fog is calculated per-vertex. To minimize the resulting artifacts, increase the tessellation of the transparent meshes and avoid large translucent meshes.
- Fog transitions due to clipping from the fog volume mesh can't be represented. Instead, the axis aligned bounding box of the fog volume mesh is used to clip the fog. Fog transitions from the fog function (ie the sphere edges in the Spherical Density Function) are calculated correctly.
- The most fog interactions that can be approximated on a single transparent object is 4 height fog layers and one fog volume.
- Transparent materials using the modulative blend mode are not fogged at all, by either height fog or fog volumes.
- Transparent materials applied to skinned meshes (Skeletal meshes or Skeletal mesh decals) will not be fogged by fog volumes.
A fog volume is more expensive than a single layer of translucency in general, but a fog volume is much cheaper than 10's of layers of translucency with the same material and screen area. When replacing particle effects with a fog volume, use the shader complexity viewmode to get an idea of the relative cost. There is a some overhead involved for each fog volume that is rendered, even if it only covers a single pixel of the screen or is completely behind opaque objects. For this reason it's better to have one large fog volume than many small ones, if they occupy the same volume. Note that the fog volume mesh can be any closed mesh so it is often possible to use a single fog volume in a twisted tunnel while still having complete control over where the fog starts and stops. Fog Volumes use complex pixel shaders and several passes to get the final result, so they are completely pixel shader bound. This means that on most platforms having very high poly fog volumes will not affect performance at all. It also means that fog volumes with a lot of overdraw (overlapping frontfaces and backfaces) will have the worst performance. The simpler fog functions run faster than the most expensive ones, for example the constant density function is about 2 times faster than the spherical density function. Try to use the simplest fog function possible. Every pixel in the fog volume actor will have the same cost, regardless of how it ends up being fogged, so you should be careful to use the smallest mesh possible. For example with the spherical density function, no fog will be applied outside of the sphere, but if the mesh is larger than the sphere those unfogged pixels will still cost as much as the fogged ones. Resize the mesh to bound the sphere function as closely as possible. With the automatic setup method the sphere mesh will bound the sphere function automatically. Use a fog sheet (See Volumetric Lighting Guide) instead of a fog volume if your use case meets all of these criteria:
- The number of overlapping fog sheets is small
- The camera can't ever go into the fog, or you don't mind the fog fading out when you would have been inside of it
- Translucency doesn't intersect the fog, or the artifacts are not noticeable
Fog Volumes are best used for small to medium effects, since they can only approximate intersecting translucency and don't support nesting. Use HeightFog layers or some other method for level-wide fogging, and Fog Volumes for volumetric effects around lights or contained to parts of the level.