Work in progress
Godot documentation is being updated to reflect the latest changes in version
4.0. Some documentation pages may
still state outdated information. This banner will tell you if you're reading one of such pages.
The contents of this page are up to date. If you can still find outdated information, please open an issue.
Volumetric fog and fog volumes¶
Volumetric fog is only supported in the Clustered Forward rendering backend, not Forward Mobile or Compatibility.
As described in Environment and post-processing, Godot supports various visual effects including two types of fog: traditional (non-volumetric) fog and volumetric fog. Traditional fog affects the entire scene at once and cannot be customized with Fog shaders.
Volumetric fog can be used at the same time as non-volumetric fog if desired.
On this page, you'll learn:
How to set up volumetric fog in Godot.
What fog volumes are and how they differ from "global" volumetric fog.
The Godot demo projects repository contains a volumetric fog demo.
Here is a comparison between traditional fog (which does not interact with lighting) and volumetric fog, which is able to interact with lighting:
Volumetric fog properties¶
After enabling volumetric fog in the WorldEnvironment node's Environment resource, you can edit the following properties:
Density: The base exponential density of the volumetric fog. Set this to the lowest density you want to have globally. FogVolumes can be used to add to or subtract from this density in specific areas. A value of
0.0disables global volumetric fog while allowing FogVolumes to display volumetric fog in specific areas. Fog rendering is exponential as in real life.
Albedo: The Color of the volumetric fog when interacting with lights. Mist and fog have an albedo close to white (
Color(1, 1, 1, 1)) while smoke has a darker albedo.
Emission: The emitted light from the volumetric fog. Even with emission, volumetric fog will not cast light onto other surfaces. Emission is useful to establish an ambient color. As the volumetric fog effect uses single-scattering only, fog tends to need a little bit of emission to soften the harsh shadows.
Emission Energy: The brightness of the emitted light from the volumetric fog.
GI Inject: Scales the strength of Global Illumination used in the volumetric fog's albedo color. A value of
0.0means that Global Illumination will not impact the volumetric fog. This has a small performance cost when set above
Anisotropy: The direction of scattered light as it goes through the volumetric fog. A value close to
1.0means almost all light is scattered forward. A value close to
0.0means light is scattered equally in all directions. A value close to
-1.0means light is scattered mostly backward. Fog and mist scatter light slightly forward, while smoke scatters light equally in all directions.
Length: The distance over which the volumetric fog is computed. Increase to compute fog over a greater range, decrease to add more detail when a long range is not needed. For best quality fog, keep this as low as possible.
Detail Spread: The distribution of size down the length of the froxel buffer. A higher value compresses the froxels closer to the camera and places more detail closer to the camera.
Ambient Inject: Scales the strength of ambient light used in the volumetric fog. A value of
0.0means that ambient light will not impact the volumetric fog. This has a small performance cost when set above
Sky Affect: Controls how much volumetric fog should be drawn onto the background sky. If set to
0.0, volumetric fog won't affect sky rendering at all (including FogVolumes).
Two additional properties are offered in the Temporal Reprojection section:
Temporal Reprojection > Enabled: Enables temporal reprojection in the volumetric fog. Temporal reprojection blends the current frame's volumetric fog with the last frame's volumetric fog to smooth out jagged edges. The performance cost is minimal, however it does lead to moving FogVolumes and Light3Ds "ghosting" and leaving a trail behind them. When temporal reprojection is enabled, try to avoid moving FogVolumes or Light3Ds too fast. Short-lived dynamic lighting effects should have Volumetric Fog Energy set to
0.0to avoid ghosting.
Temporal Reprojection > Amount: The amount by which to blend the last frame with the current frame. A higher number results in smoother volumetric fog, but makes "ghosting" much worse. A lower value reduces ghosting but can result in the per-frame temporal jitter becoming visible.
Unlike non-volumetric fog, volumetric fog has a finite range. This means volumetric fog cannot entirely cover a large world, as it will eventually stop being rendered in the distance.
If you wish to hide distant areas from the player, it's recommended to enable both non-volumetric fog and volumetric fog at the same time, and adjust their density accordingly.
Light interaction with volumetric fog¶
To simulate fog light scattering behavior in real life, all light types will interact with volumetric fog. How much each light will affect volumetric fog can be adjusted using the Volumetric Fog Energy property on each light. Enabling shadows on a light will also make those shadows visible on volumetric fog.
If fog light interaction is not desired for artistic reasons, this can be
globally disabled by setting Volumetric Fog > Albedo to a pure black color
in the Environment resource. Fog light interaction can also be disabled for
specific lights by setting its Volumetric Fog Energy to
0. Doing so will
also improve performance slightly by excluding the light from volumetric fog
Using volumetric fog as a volumetric lighting solution¶
While not physically accurate, it is possible to tune volumetric fog's settings to work as volumetric lighting solution. This means that unlit parts of the environment will not be darkened anymore by fog, but light will still be able to make fog brighter in specific areas.
This can be done by setting volumetric fog density to the lowest permitted value
greater than zero (
0.0001), then increasing the Volumetric Fog Energy
property on lights to much higher values than the default to compensate. Values
100000 usually work well for this.
Balancing performance and quality¶
There are a few project settings available to adjust volumetric fog performance and quality:
Rendering > Environment > Volumetric Fog > Volume Size: Base size used to determine size of froxel buffer in the camera X-axis and Y-axis. The final size is scaled by the aspect ratio of the screen, so actual values may differ from what is set. Set a larger size for more detailed fog, set a smaller size for better performance.
Rendering > Environment > Volumetric Fog > Volume Depth: Number of slices to use along the depth of the froxel buffer for volumetric fog. A lower number will be more efficient but may result in artifacts appearing during camera movement.
Rendering > Environment > Volumetric Fog > Use Filter: Enables filtering of the volumetric fog effect prior to integration. This substantially blurs the fog which reduces fine details but also smooths out harsh edges and aliasing artifacts. Disable when more detail is required.
Using fog volumes for local volumetric fog¶
Sometimes, you want fog to be constrained to specific areas. Conversely, you may want to have global volumetric fog but fog should be excluded from certain areas. Both approaches can be followed using FogVolume nodes.
Here's a quick start guide to using FogVolumes:
Make sure Volumetric Fog is enabled in the Environment properties. If global volumetric fog is undesired, set its Density to
Create a FogVolume node.
Assign a new FogMaterial to the FogVolume node's Material property.
In the FogMaterial, set Density to a positive value to increase density within the FogVolume, or a negative value to subtract the density from global volumetric fog.
Configure the FogVolume's extents and shape as needed.
Thin fog volumes may appear to flicker when the camera moves or rotates. This can be alleviated by increasing the Rendering > Environment > Volumetric Fog > Volume Depth project setting (at a performance cost) or by decreasing Length in the Environment volumetric fog properties (at no performance cost, but at the cost of lower fog range). Alternatively, the FogVolume can be made thicker and use a lower density in the Material.
Extents: The size of the FogVolume when Shape is Ellipsoid, Cone, Cylinder or Box. If Shape is Cone or Cylinder, the cone/cylinder will be adjusted to fit within the extents. Non-uniform scaling of cone/cylinder shapes via the Extents property is not supported, but you can scale the FogVolume node instead.
Shape: The shape of the FogVolume. This can be set to Ellipsoid, Cone, Cylinder, Box or World (acts as global volumetric fog).
Material: The material used by the FogVolume. Can be either a built-in FogMaterial or a custom ShaderMaterial (Fog shaders).
After choosing New FogMaterial in the Material property, you can adjust the following properties in FogMaterial:
Density: The density of the FogVolume. Denser objects are more opaque, but may suffer from under-sampling artifacts that look like stripes. Negative values can be used to subtract fog from other FogVolumes or global volumetric fog.
Albedo: The single-scattering Color of the FogVolume. Internally, member albedo is converted into single-scattering, which is additively blended with other FogVolumes and global volumetric fog's Albedo.
Emission: The Color of the light emitted by the FogVolume. Emitted light will not cast light or shadows on other objects, but can be useful for modulating the Color of the FogVolume independently from light sources.
Height Falloff: The rate by which the height-based fog decreases in density as height increases in world space. A high falloff will result in a sharp transition, while a low falloff will result in a smoother transition. A value of
0.0results in uniform-density fog. The height threshold is determined by the height of the associated FogVolume.
Edge Fade: The hardness of the edges of the FogVolume. A higher value will result in softer edges, while a lower value will result in harder edges.
Density Texture: The 3D texture that is used to scale the member density of the FogVolume. This can be used to vary fog density within the FogVolume with any kind of static pattern. For animated effects, consider using a custom fog shader. You can import any image as a 3D texture by changing its import type in the Import dock.
Custom FogVolume shaders¶
This page only covers the built-in settings offered by FogMaterial. If you need to customize fog behavior within a FogVolume node (such as creating animated fog), FogVolume nodes' appearance can be customized using Fog shaders.