skip to Main Content

Scripting Support (C#)

Accessing global fog properties

All properties shown in the inspector can be set or modified at runtime using scripting.

First you need to get a reference to the main script which can be done easily using:

using VolumetricFogAndMist;

VolumetricFog fog = VolumetricFog.instance;

Then, you can set any property like the fog color or wind speed/direction:

fog.color = new Color(1,0,0);
fog.speed = 0.5f;
fog.windDirection = Vector3.right;

Although you can set any property using this way, you can also assign a whole profile:

fog.profile = myprofile; // my profile is a VolumetricFogProfile scriptableobject

List of useful runtime Volumetric Fog properties

Unless specified, all properties can return or set a value. For example, fog.profile will return the currently assigned profile while fog.profile = … will assign a new profile and apply its settings immediately.

Please note that the VolumetricFog script exposes many more properties which usually are set either in the inspector or through a profile. Here’s a reduced list of most frequent used properties at runtime.

Property name Type Description
preset FOG_PRESET Gets or sets a legacy factory preset (ie: WindyMist, SeaClouds, etc.)
profile VolumetricForProfile Gets or sets a fog profile with predefined settings. See “Profiles” in Special Section of this document for more details.
useFogVolumes bool Specifies if fog volumes can be detected and used. Fog Volumes are special areas where a custom profile can be applied producing a smooth transition. Check “Fog Volumes” section for more details.
sun GameObject Gets or sets the gameobject used as Sun. This is usually the directional light.
distance float Start distance of the fog in meters.
distanceFallOff float (0-5) Controls the gradient transition between camera and the starting distance.
height float Height of the fog.
heightFallOff float (0-1) Controls the gradient vertical transition.
baselineHeight float Specifies the altitude in meters at which the fog starts.
baselineRelativeToCamera bool If true, the baselineHeight is relative to the camera Y coordinate. Otherwise the baselineHeight is relative to 0 altitude.
density float (0-1.25) The fog density.
alpha float (0-1.05) Transparency of the fog.
color Color Albedo color of the fog.
specularColor Color Specular color of the fog.
copySunColor bool If Sun color and intensity should be used. If false, the lightColor and lightIntensity properties are used instead.
lightColor Color The color of the directional light.
lightIntensity float The intensity or brightness of the directional light.
speed float (0-1) Speed of the wind animation.
windDirection Vector3 Normalized direction of the wind animation (only X & Z axis are used).
useRealTime bool If the wind animation timing should use realtime clock or not. If true, any change in speed will be smoother.
turbulence float (0-10) Turbulence amount. 0 = disables this effect.
skyColor Color The color of the sky haze effect.
skyHaze float The altitude of the sky haze effect (0 = disables it completely).
character GameObject The character or gameobject to be followed by the fog void.
fogVoidPosition Vector3 The position of the fog void if not following a gameobject (character property is null).
fogVoidTopology FOG_VOID_TOPOLOGY If the fog void is spherical or boxed.
fogVoidRadius float Radius of the fog void.
fogVoidDepth float Depth of the fog void (if boxed).
fogVoidHeight float Height of the fog void (if boxed).
fogAreaCenter GameObject The character or gameobject to be followed by this fog area.
fogAreaFollowMode FOG_AREA_FOLLOW_MODE If the fog area follows in 3D or 2D (X/Z plane only).
fogAreaPosition Vector3 The position of the fog area if not following a gameobject (fogAreaCenter is null).
fogAreaTopology FOG_AREA_TOPOLOGY If the fog area is spherical or boxed.
fogAreaRadius float Radius of the fog area.
fogAreaDepth float Depth of the fog area (if boxed).
fogAreaHeight float Height of the fog area (if boxed).
Downsampling int 1 = no downsampling (native screen resolution). Increasing downsampling improves performance at quality expense.
sunShadows bool If directional light shadows should be used.

Fog of War methods

The following fog of war methods are available:


General reset function which removes any previous change to fog of war transparency.


Restores fog immediately at a given position with radius or bounds.


Changes the transparency of the fog in an area. This method is overloaded and can accept different paremeters and options:

  • Accepts a world position and a radius, or a bounds, or a world position and size, a collider, a gameobject, …

  • Desired alpha and specify if this value replaces the existing transparency or if it blends with it (blendAlpha parameter).

  • The duration of the transition (pass 0 to set the alpha immediately).

  • The smoothness/harshness of the border (by default it uses the global setting in Fog Of War section which is 1f).

  • The restore delay and duration (by default it uses the global settings in Fog Of War section). Pass 0 to restore delay to make the change permanent.

float GetFogOfWarAlpha(Vector3 worldPosition)

Returns the transparency (0-1) of the fog of war at the given world position.

Texture2D fogOfWarTexture

Sets/returns the currently assigned fog of war texture which stores the transparency values.

Color32[] fogOfWarTextureData

Sets/returns the contents of the fog of war texture.

Back To Top