Table of Contents
Click “Create” to create a new profile with current settings. A new file will be created and you can rename it and move it into any folder.
When a profile is assigned, you will be able to Create a copy, Revert current settings (reload the profile) or update the profile with current settings:
Assign a profile to the “Profile” slot to load its settings. You can find some sample profiles inside the VolumetricFog/Resources/Profiles folder:
Starting with V8, Volumetric Fog & Mist accepts profiles. A profile is a special file that contains all the settings used to customize look & feel of the Volumetric Fog.
You can define special zones (fog volumes) where fog alpha, color and other properties can change automatically. Create a fog volume from the menu GameObject / Create Other / Fog Volume. Position the fog volume over the desired area and edit the transform scale, then customize what attributes of the fog should be changed in the FogVolume script (see below).
Fog Volumes can change fog alpha, fog color, fog specular color, fog light color and sky haze alpha. But also you can assign a fog profile which holds many options:
Enable Profile Transition: when this option is enabled and a profile is assigned to the Target Profile slot, all the settings of that profile will be used in the transition. This is the most complete option to create great transitions.
Enable Alpha Transition: when enabled, will make a transition with fog alpha value (transparency of the fog) and also the sky haze alpha (transparency of the sky haze effect if used).
Enable Fog Color Transition: when enabled, the albedo color of the fog will transition to this value.
Enable Fog Specular Transition: same but affecting the fog specular color.
Enable Light Color Transition: same but affects the light color value.
Transition Duration: duration in seconds for the transition.
Target Collider: the collider that will be detected to trigger the transition. By default it uses the collider attached to the camera (if any).
Debug Mode: if enabled, it will print a debug message into the console when the collider enters or exits the volume.
Target Fog: the target Volumetric Fog & Mist that will receive the changes. By default it’s the script attached to the camera.
By default, Fog Volumes will react to any collider that contains the camera to which the fog image effect is attached (for first person controllers this is the default behaviour). But you can also assign a different collider so they will also work with third person controllers.
Check out Demo Scene #7 “MountainClimb” for an example of Fog Volumes.
Under General Settings, you can find a few options to control the order of execution of Volumetric Fog & Mist as well as some specific options for dealing with transparent objects like particles and tree billboards:
Compute Depth: this option will calculate the depth for standard Unity tree billboards and/or transparent objects included in the specific layer mask (not necessary for SpeedTree). This custom render pass will prevent these trees to be clipped when you look to the horizon or sky and there’s a billboard tree in the middle.
Render Before Transparency: this toggle controls the execution order of the image effect. If enabled fog will be rendered before any transparent object. If not (default value), it will render after everything has been rendered.
Transparency Mode: this option is only enabled if the image effect renders after transparent objects (see previous option). In this case, if the fog is very thick, it can occlude any particle or transparent object. Using this special Blend feature they will be combined with the fog color. Experiment with different Blend Power values (shown when Transparency Mode is set to Blend).
It’s important to note that proper transparency and fog support is not possible in Unity due to how the render pipeline works. Depending on the type of transparent objects you use and your scene setup one of the following 3 options may work for you:
Render Before Transparency: this option will make Volumetric Fog & Mist render before any transparent object is drawn so they are not affected nor clipped by the fog.
Pros: best performance.
Cons: a side effect of this option is that transparent objects may look weird rendered on top of the fog.
Enable Compute Depth option with Scope: Tree Billboards And Transparent Objects. This option will enable a custom depth pass and will treat transparent objects as cutout shaders. You can adjust the Cut Off value to match the best result.
Pros: transparent objects receive fog effect based on their exact depth.
Cons: requires an additional depth pass which is slower. Also some transparent objects with smooth gradients or edges may look bad since this option treats them as CutOut shaders (hard edges).
Transparency Mode set to Blend: this option can be used instead of the previous one (they are exclusive options). It renders after transparent objects have been drawn but afterwards blends the transparent objects on top of the fog with a customizable blending intensity.
Pros: looks similar to “Render Before Transparency” but with customizable blending intensity and running after all transparent objects have been drawn. This setup is required when also using Unity standard tree.
Cons: although it provides a bit better result than “Render Before Transparent”, the result is non-optimal as no depth-checking is performed.
Automatic fog light alignment with Sun
A light game object existing in the scene can act as the Sun and be assigned to Volumetric Fog & Mist. You’ll find a property in the inspector, called Sun, where you can drag and drop the desired light in your scene.
After assigning a light as the Sun, the fog will react to the sun light direction, intensity and color automatically. Click ‘Unassign’ to break the link and allow to freely customize light direction, intensity and color.
Elevated Fog & Clouds
You can make the fog start above Camera position to simulate floating smoke or even clouds! Try it assigning a value above the Camera Y position to Base Height property in the inspector.
You can increase the Max Distance beyond your Camera Far Clip plane to force the cloud layer to render beyond it and even reach the horizon. Volumetric Fog & Mist will apply a special matrix transform to achieve this effect automatically.
Check out Demo Scene #7 “MountainClimb” for an example of how to enable a dynamic cloud layer that reacts when player climbs a mountain.
Fog Colors and Lighting Model
To provide more artistic choices, Volumetric Fog provides different “colorization formulae”. This option is located under Fog Colors section:
Legacy: this is the traditional technique used in Volumetric Fog & Mist. It lerps between the ambient light and the sun or light color to provide the final fog color.
Natural: in this mode, the color lerps between the ambient and ambient + light color and the result is multiplied by the light intensity.
Single Light: in this mode, the ambient color is not used. Just the light color multiplied by the light intensity.
Note that if a Sun object is assigned, the Sun’s light intensity is added to the Light intensity parameter.
Another great feature included in the asset is the void area. This option is useful if you want a clear area around a world space position. For example, in 3rd Person View games, you may want a clear area around the character.
This option is similar to the Distance Fog feature (using Distance > 0) but Distance Fog Works having into account the distance from the Camera. So Distance parameter is useful for 1st Person View and Void Areas for 3rd Person View.
Void areas can be spherical or boxed. To make a spherical void area just move the radius slider to the left. To make it boxed, set the width and depth sliders.
Also, you can assign your character game object to the property field in this section, so the center of the void will follow it automatically.
Fog Areas can be defined to limit the rendering of the fog inside a box or sphere container.
The demo scene #6 “HighClouds” shows an example
There are 3 ways to add a Fog Area into your scene:
Method 1: Limit the fog of an existing Volumetric Fog component attached to the camera.
Use the Fog Area section:
Set the position of the fog area in Fog Area position property.
Choose a fog area topology.
Choose a radius and a falloff for spherical fog area or radius/depth/height for a box-type fog area.
Optionally assign a GameObject to the “Follow GameObject” slot. This will make the fog area to follow that game object.
Method 2: Drag & drop the fog area prefabs.
Locate the fog area prefabs inside VolumetricFog / Resources / Prefab folder:
Choose either FogBoxArea or FogSphereArea, drag and drop it into your Scene View or hierarchy:
Once the fog area is in your scene, it will automatically link to the Volumetric Fog script attached to your camera. If you need to use another camera, just change the Fog Renderer property and assign another Volumetric Fog & Mist.
Explanation: fog areas are containers for settings and storages for the fog area state values. It’s the VolumetricFog script attached to the camera which is responsible of all the rendering.
To change the dimensions of the fog area created this way, please use the transform of the fog area game object. You can change the position and the scale of the transform to match the desired dimensions and location of the fog area.
Method 3: Use the API to create fog areas.
You can also create any number of fog areas during runtime calling fog.CreateFogArea API. Please check demo scene 10 source code for quick examples.
Setting rendering order of fog areas
By default, fog areas are rendered from back to front respective to the distance to the camera. However, in some circumstances you may want to specify a different sorting method. This can be useful when you need a background layer of clouds or to overcome some undesired overlapping.
Go to Fog Area section and choose a different sorting method:
Possible options are:
Distance To camera (default)
Altitude: this fog area will be sorted depending on the altitude (difference in height with respect to the camera position).
Fixed: this option allows you to introduce a fixed rendering order. All fog areas have a default render order of 1. If you enter a value of 2, this fog area will be rendered after all fog areas have rendered so it will show on top of every other fog area.
Terrain Fit option for Fog Areas
The Terrain Fit option adjusts the fog vertical position to the surface altitude creating fog effects that slide over hills and mountains. This option is only available in fog areas.
To use this option please ensure that:
The volume covered by the fog area encloses the whole surface desired. Adjust the fog area radius, height and depth accordingly.
The Height value in Fog Geometry section is high enough.
The options provided by Terrain Fit are:
Layer Mask: determines which objects will be considered as ground. You can include the terrain layer but also any other solid objects.
Resolution: this option performs a zenithal depth pre-pass to capture the elevation of the ground. The resolution here referes to the size of the generated depth texture.
Height Over Surface: this is the height of the fog counting from the surface position.
Min / Max Altitude: let you clamp the minimum and maximum altitude of the enclosing surface to render the fog.
Fog of War
You can also set any number of void areas just calling SetFogOfWarAlpha method of the Volumetric script. Just pass the world space position, the radius or bounds and the desired new alpha for the fog. Just make sure the center and size of the fog of war (configured in the inspector) are properly set (by default the fog of war is centered on 0,0,0 with a size of 1024×1024). Optionally pass a duration to produce a smoother effect.
To make the cut permanent make sure Restore Delay is set to 0.
Call ResetFogOfWar to reset the cleared areas back to normal. For more information on using scripting with Volumetric Fog check Scripting Support
Important: Fog of War relies on z-buffer data to map world positions to the mask texture. It won’t work properly if there’s no geometry under the fog (it’s aimed to fog over terrain or any other geometry that writes to z-buffer, transparent shaders won’t work neither).
You can also place unlimited void placeholders in SceneView by placing a Fog Of War Hole. Just right click on the hierarchy panel and select Create Other -> Volumetric Fog -> Fog of War Hole:
This gameobject has a FogOfWarHole script which calls the SetFogOfWarAlpha method automatically. Use the transform position and scale to position/rescale the hole.
Point Light support
A number of point lights can be selected to illuminate the fog with different colors, ranges and intensities. The maximum number of point lights can be configured clicking on “Shader Options” button on top of Volumetric Fog & Mist inspector.
This feature can be used to achieve many visual effects, from fog gradients, glow or bloom, definitely enhancing the ambiance of your scenes.
At night, if you have the fog synced with a Sun game object, the fog will be dark. You can use this feature to illuminate the surrounding area of the characters.
Note that point light are simulated in the shader, so it’s not necessary to have real point lights in the scene. But if you have them, you can simply assign them to the slots in the Point Light section or make the asset choose them for you automatically using the slider and checking “Track Point Lights”.
If you assign a scene Point Light to a slot under Point Light section, the parameters like color, position, intensity, etc. will be driven by the Light and VolumetricFogLightParams component attached to that light:
If you don’t assign a Point Light to a slot under Point Light section, then you can freely enter custom values like position, color, intensity, etc. to create a virtual light which can illuminate the fog.
Light scattering is the physical phenomena that makes the light reflect/refract when it crosses different densities, adding shafts of light across the scene from the light source. Volumetric Fog & Mist includes a light scattering option, which approximates that effect in screen space (that means that it only works when the light source is in front of you).
To enable this option, you need to assign a light source to the Sun property and check the Enable toggle in the inspector. Then customize the effect with the different parameters in that section.
Light Scattering section is really divided in 2 effects:
Light Diffusion: this is a lightweight effect that will color the fog around the Sun as you look directly to it.
Sun Shafts: simulates the effect caused when objects occlude the light of the Sun. Please note that Sun Shafts will increase the workload on the GPU, so you may have a configuration parameter in your game to enable it in addition to the fog. Also note that Sun Shafts are designed so they work better when they cross the fog.
This option blurs the color buffer before overlaying the fog to simulate additional light scattering. Try it and experiment with different depths.
Sun Shadows (directional light + cookie support)
Enable this feature to cast Sun shadows over the fog. This option requires a directional light assigned to the Sun property in the inspector.
By default, Volumetric Fog & Mist will reuse the directional light shadow map generated by Unity.
However, it’s possible to force Volumetric Fog & Mist cast a custom shadow pass. To enable the custom shadow pass, click on “Shader Options” button and disable the “Native Directional Shadows” checkbox – do this only if you have a reason to perform a custom shadow pass, like choosing which objects can cast shadows on the fog. If unsure, leave the option enabled.
In the same “Shader Options” section you can enable support for the directional light cookie (if no cookie is assigned to the directional light, leave this option unchecked).
The “Shadow Cancellation” slider allows you to control the alpha transparency of the fog under shadows. If you set this value to 1, only lit fog by the assigned Sun light will be visible producing a Volumetric Light effect.
Use the “Jitter” parameter to reduce banding effects when using Sun Shadows feature.
If custom shadow pass is enabled in Shader Options, additional options will appear under Sun Shadows section:
The “Force Update Interval” parameter can be set to a value greater than 0 to specify the interval in seconds between shadow casting shoots. If set to zero (default value) it will shoot shadows only if the Sun changes rotation (this is usually the most efficient setting). You can set this value to 0.016 to shoot every frame (if you target 60 frames/s or set even a lower value) have the shadows always updated but this will take extra ms from your frame rate. It just depends if you have moving objects on the scene that clearly cast shadows over the fog and you want to ensure that shadows are always in sync with those objects.
The “Max Distance” will determine the maximum distance from the camera for the shadows. It does not affect performance but shadow quality. The greater the value the poor quality and vice versa. The Resolution parameter also affects shadow quality in a more direct way as this value determines the size of the shadow texture that’s produced in each shadow shoot. The default value of 3 uses a 4096×4096 texture, you can increase this value to 4 and it will use a 8192×8192 texture which is currently the maximum texture size allowed by Unity 5. You may experiment with lower resolutions as well and see if they work for you – it will improve performance and reduce VRAM (memory) usage.
The “Bias” parameter option will offset the shadow start from the object itself to prevent self-shadowing. By default, a value of 0.1 ensures this can’t happen so this value should be left as is, unless you need to change it to create special effects.
Geometry masks uses the depth information from scene objects to mask out the fog in the scene. This feature is similar to fog areas but has two key differences:
Geometry Mask affects entire fog rendering. While each fog area can have different appearance and behaviour attributes, the geometry mask affects the entire fog (including any other fog area!).
Geometry Mask can include any number of objects which allows to make very complex shapes.
The workflow for using geometry mask follows:
1.- Select the main camera and click “Shader Options” button located on top of Volumetric Fog inspector.
2.- Scroll down until you see the Fog Mask option. There’re two geometry mask modes. Normal and inverted. The inverted mode makes the fog only visible outside the mask while the normal mode does the opposite (shows fog only inside the objects only). Enable only one of the two options.
3.- Close the Shader Options section and scroll down to the bottom of inspector until you see “Geometry Mask” section.
4.- Select which layers include the objects that will make the mask.
5.- Click “Refresh” to quickly list which objects are found. If no object is found, verify that the objects belong to the same layer.
6.- Optionally use downsampling option to increase performance (only if needed).
Geometry Mask uses the meshes from scene objects to create complex and compound volumes to render the fog inside.
Those objects should be used only for the mask. For example if you have a room and you want fog inside the room only, then you can add a cube and scale it inside the room. Assign that cube to a custom layer for the mask purposes.
In order to allow the fog visible inside the objects assigned to the geometry mask, their mesh renderers need to be disabled. This is expected as the mask objects are only meant to provide their geometry for the mask.
You can combine any number of objects or meshes to create complex and irregular shapes.
If you can achieve the results using a geometry mask instead of a fog area, stick to the geometry mask. Using both geometry mask and fog areas is possible although each additional feature costs performance.
Orthographic Camera support
To enable orthographic camera support, you need to edit ‘VolumetricFogOptions.cginc’ file located in ‘VolumetricFog/Resources/Shaders’ folder:
This file contains a global macro called “FOG_ORTHO”. To enable orthographic camera support, just change the 0 to 1 so it reads:
#define FOG_ORTHO 1
VR and Single Pass Stereo Rendering
Volumetric Fog & Mist is fully compatible with VR in both “Multi” and “Single”-Pass Stereo Rendering. It has been tested with Oculus DK2 with both Oculus and OpenVR SDKs.
Important: if you enable Single Pass Stereo Rendering in Player Settings, make sure you verify that it’s reflected in Volumetric Fog & Mist inspector on your camera. Check this new option which is automatically set based on the Player Settings when the inspector is shown.
To disable XR usage, edit VolumetricFog.cs script and comment out the macro define at the top: