Scripting Support (C#)
advanced scriptingVolumetric Fog & Mist 2 (URP) · Scripting Support (C#)
The main scripting class is VolumetricFog (namespace VolumetricFogAndMist2). This MonoBehavior is attached to each fog volume GameObject. Fog appearance settings are stored in a VolumetricFogProfile ScriptableObject.
Use fog.profile to access the shared profile (changes affect all volumes sharing it). Use fog.settings to get an instanced copy that only affects this volume — similar to Unity’s sharedMaterial vs material.
VolumetricFog
Profile & Settings
VolumetricFogProfile profileThe shared fog profile asset. Changes affect all fog volumes that reference this profile.
VolumetricFogProfile settings propertyReturns an instanced copy of the profile. Changes only affect this fog volume. Analogous to Unity’s material vs sharedMaterial.
Material material read-onlyReturns the fog material used by this volume.
Lighting
bool enableNativeLightsSupports Unity native lights including point and spot lights. Default: false.
float nativeLightsMultiplierMultiplier to native lights intensity. Default: 1.
float nativeLightFallOffNative lights distance attenuation falloff. Range 0–1. Default: 1.
bool enablePointLightsEnable fast point lights (faster than native lights but cannot be combined with them). Default: false.
bool enableAPVSupports Adaptive Probe Volumes (Unity 2023.1+). Default: false.
float apvIntensityMultiplierMultiplier to APV intensity. Default: 1.
bool enableVoidsEnable fog voids (subtractive volumes that remove fog). Default: false.
Follow & Fade
bool enableFollowMakes this fog volume follow another object automatically. Default: false.
Transform followTargetThe target transform to follow.
VolumetricFogFollowMode followModeFollow mode: FullXYZ or RestrictToXZPlane. Default: RestrictToXZPlane.
bool followIncludeDistantFogAlso move distant fog when following the target. Default: false.
Vector3 followOffsetOffset from the follow target position.
bool enableFadeFades fog in/out when the reference controller enters or exits the fog volume. Default: false.
bool fadeIncludeDistantFogAlso fades distant fog along with this volume. Default: false.
float fadeDistanceFog blending starts within this fade distance from any volume border. Default: 1.
bool fadeOutFog disappears when the controller enters the volume (instead of appearing). Default: false.
Transform fadeControllerThe controller (player or camera) used to check for volume entry. Defaults to main camera if not set.
Sub-Volumes & Update
bool enableSubVolumesEnable sub-volume blending. When the controller enters a sub-volume, the fog profile blends to the sub-volume’s profile. Default: false.
List<VolumetricFogSubVolume> subVolumesList of allowed sub-volumes. If empty, any sub-volume in the scene can affect this fog volume.
bool enableUpdateModeOptionsCustomize how this fog volume data is updated and animated. Default: false.
VolumetricFogUpdateMode updateModeWhen to update fog data: WhenFogVolumeIsVisible or WhenCameraIsInsideArea. Default: WhenFogVolumeIsVisible.
Camera updateModeCameraCamera used to compute visibility. Uses main camera if not set.
Bounds updateModeBoundsBounds for WhenCameraIsInsideArea mode. Default: center (0,0,0), size (100,100,100).
bool showBoundaryShows the fog volume boundary in the Game View. Default: false.
Fog of War Properties
bool enableFogOfWarEnable fog of war feature. Default: false.
Vector3 fogOfWarCenterWorld-space center of the fog of war coverage area.
bool fogOfWarIsLocalWhether the fog of war center is relative to the transform position. Default: false.
Vector3 anchoredFogOfWarCenter read-onlyReturns the world-space fog of war center, offset by the transform position if fogOfWarIsLocal is true.
Vector3 fogOfWarSizeWorld-space size of the fog of war coverage area. Default: (1024, 0, 1024).
bool fogOfWarShowCoverageShow fog of war coverage gizmo in the Scene View. Default: false.
int fogOfWarTextureWidthWidth of the fog of war texture. Range 32–2048. Default: 256.
int fogOfWarTextureHeightHeight of the fog of war texture. Range 32–2048. Use 0 to match width.
float fogOfWarRestoreDelayDelay in seconds before cleared fog starts restoring. Set to 0 to keep cleared areas permanent. Range 0–100.
float fogOfWarRestoreDurationDuration in seconds of the fog restore transition. Range 0–25. Default: 2.
float fogOfWarSmoothnessBorder smoothness of cleared fog areas. Range 0–1. Default: 1.
bool fogOfWarBlurApply blur to the fog of war texture for smoother edges. Default: false.
Texture2D fogOfWarTexture propertyGets or sets the fog of war texture. Setting this reloads the texture data.
Color32[] fogOfWarTextureData propertyGets or sets the raw fog of war color buffer. The alpha channel controls fog opacity: 0 = fully cleared, 255 = full fog. Useful for saving/loading fog of war state.
Fog of War Methods
void SetFogOfWarAlpha(Vector3 worldPosition, float radius, float fogNewAlpha, float duration = 0)Changes fog of war opacity at a world position within a circular radius. Set fogNewAlpha to 0 to clear fog, 1 to restore.
void SetFogOfWarAlpha(Vector3 worldPosition, float radius, float fogNewAlpha, float duration, float smoothness)Same as above with an additional smoothness parameter for the cleared area border.
void SetFogOfWarAlpha(Vector3 worldPosition, float radius, float fogNewAlpha, float duration, float smoothness, FoWUpdateMethod updateMethod, bool blendAlpha = true)Circular fog of war with explicit update method (main thread or background thread) and blend mode.
void SetFogOfWarAlpha(Vector3 worldPosition, float radius, float fogNewAlpha, bool blendAlpha, float duration, float smoothness, float restoreDelay, float restoreDuration, float restoreToAlphaValue = 1f, FoWUpdateMethod updateMethod = FoWUpdateMethod.BackgroundThread)Full circular fog of war with all options including auto-restore after a delay.
void SetFogOfWarAlpha(Bounds bounds, float fogNewAlpha, float duration = 0)Changes fog of war opacity within a rectangular bounds area.
void SetFogOfWarAlpha(Bounds bounds, float fogNewAlpha, float duration, float smoothness)Bounds-based fog of war with smoothness control.
void SetFogOfWarAlpha(Bounds bounds, float fogNewAlpha, bool blendAlpha, float duration)Bounds-based fog of war with blend mode control.
void SetFogOfWarAlpha(Bounds bounds, float fogNewAlpha, bool blendAlpha, float duration, float smoothness, float restoreDelay, float restoreDuration, float restoreToAlpha = 1f, FoWUpdateMethod updateMethod = FoWUpdateMethod.BackgroundThread)Full bounds-based fog of war with all options including auto-restore.
void SetFogOfWarAlpha(Collider collider, float fogNewAlpha)Changes fog of war opacity within a convex collider shape.
void SetFogOfWarAlpha(Collider collider, float fogNewAlpha, bool blendAlpha = false, float duration = 0, float smoothness = 0, float restoreDelay = 0, float restoreDuration = 2, float restoreToAlpha = 1f)Collider-based fog of war with all options.
void SetFogOfWarAlpha(GameObject go, float fogNewAlpha)Changes fog of war opacity within a mesh shape defined by a GameObject.
void SetFogOfWarAlpha(GameObject go, float fogNewAlpha, float duration = 0, float restoreDelay = 0, float restoreDuration = 2, float restoreToAlpha = 1f, FoWUpdateMethod updateMethod = FoWUpdateMethod.BackgroundThread)Mesh-based fog of war with restore and threading options.
void SetFogOfWarAlpha(GameObject go, Vector3[] positions, float fogNewAlpha, float duration = 0, float restoreDelay = 0, float restoreDuration = 2, float restoreToAlpha = 1f, FoWUpdateMethod updateMethod = FoWUpdateMethod.BackgroundThread) newBatched: stamps a mesh shape at multiple positions in a single call, applying the same alpha to all. Ideal for tile-based fog of war (hex grids, strategy maps).
void SetFogOfWarAlpha(GameObject go, Vector3[] positions, float[] fogNewAlphas, float duration = 0, float restoreDelay = 0, float restoreDuration = 2, float restoreToAlpha = 1f, FoWUpdateMethod updateMethod = FoWUpdateMethod.BackgroundThread) newBatched: stamps a mesh shape at multiple positions with per-position alpha values.
void ResetFogOfWar(float alpha = 1f)Resets the entire fog of war texture to the given opacity.
void ResetFogOfWarAlpha(Vector3 worldPosition, float radius, float alpha = 1f)Restores fog of war at a circular area.
void ResetFogOfWarAlpha(Bounds bounds, float alpha = 1f)Restores fog of war within a rectangular bounds.
void ResetFogOfWarAlpha(Collider collider, float alpha = 1f)Restores fog of war within a collider shape.
void ResetFogOfWarAlpha(GameObject go, float alpha = 1f)Restores fog of war within a mesh shape.
void ResetFogOfWarAlpha(Vector3 position, Vector3 size, float alpha = 1f)Restores fog of war at a position with a given size.
void ResetFogOfWarAlpha(Vector3 position, float extentsX, float extentsZ, float alpha = 1f)Restores fog of war at a position with given X/Z extents.
float GetFogOfWarAlpha(Vector3 worldPosition)Returns the current fog of war alpha at a world position (0 = cleared, 1 = full fog).
void ReloadFogOfWarTexture()Reloads the current contents of the fog of war texture and uploads it to the GPU.
void UpdateFogOfWar(bool forceUpload = false)Updates fog of war transitions (restore timers) and uploads texture changes to the GPU.
Methods
void UpdateMaterialProperties()Schedules a material properties update at end of frame. Call after modifying profile fields at runtime.
void UpdateMaterialProperties(bool forceTerrainCaptureUpdate)Schedules a material properties update, optionally forcing a terrain capture refresh.
void UpdateMaterialPropertiesNow(bool skipTerrainCapture = false, bool forceTerrainCaptureUpdate = false)Forces an immediate material properties update instead of deferring to end of frame.
void PerformHeightmapCapture()Updates the terrain heightmap capture for this fog volume. Call after terrain modifications when using terrain fit.
Bounds GetBounds()Returns the world-space bounds of the fog volume.
void SetBounds(Bounds bounds)Sets the position and scale of the fog volume from the given bounds.
void RegisterFogMat(Material fogMat)Registers an additional material to receive fog shader properties. Useful for custom shaders that need to sample the fog.
void UnregisterFogMat(Material fogMat)Unregisters a material from receiving fog shader properties.
Static Members
static List<VolumetricFog> volumetricFogs read-onlyStatic list of all active VolumetricFog instances in the scene.
static void FindAlphaClippingObjects()Refreshes the list of renderers used for the depth pre-pass alpha clipping. Call after creating new transparent objects at runtime.
static void AddAlphaClippingObject(Renderer renderer)Adds a specific renderer to the alpha clipping depth pre-pass.
static void RemoveAlphaClippingObject(Renderer renderer)Removes a specific renderer from the alpha clipping depth pre-pass.
Events
event OnUpdateMaterialPropertiesEvent OnUpdateMaterialProperties(VolumetricFog fogVolume)Fired when the fog volume’s material properties are updated.
Delegate: void OnUpdateMaterialPropertiesEvent(VolumetricFog fogVolume)
VolumetricFogProfile
Rendering
int raymarchQualityNumber of raymarching samples. Higher values are more accurate but slower. Range 1–16. Default: 6.
float raymarchNearSteppingIncreases samples at short distances for better near-camera detail. Range 0–50. Default: 8.
float raymarchMinStepMinimum step size for raymarching. Default: 0.1.
float jitteringJittering amount to reduce banding artifacts. Default: 0.5.
float ditheringDithering amount. Range 0–2. Default: 1.
int renderQueueRender queue for the fog material. Default: 3100.
int sortingLayerIDOptional sorting layer ID. Default: 0.
int sortingOrderOptional sorting order within the sorting layer. Default: 0.
Density & Noise
float densityOverall fog density. Default: 1.
bool constantDensityDo not use any noise — produces uniform fog. Default: false.
Texture2D noiseTextureMain noise texture used for fog density variation.
float noiseStrengthNoise strength. Range 0–3. Default: 1.
float noiseScaleNoise scale (world-space size of the noise pattern). Default: 15.
float noiseFinalMultiplierFinal multiplier applied to the noise result. Default: 1.
bool useDetailNoiseEnable detail noise for finer density variation. Default: false.
Texture3D detailTexture3D texture used for detail noise.
float detailScaleDetail noise scale. Default: 0.35.
float detailStrengthDetail noise strength. Range 0–1. Default: 0.5.
float detailOffsetDetail noise offset. Default: -0.5.
Geometry
VolumetricFogShape shapeVolume shape: Box, Sphere, or Custom. Default: Box.
float borderBorder fade (soft edges). Range 0–1. Default: 0.05.
float scaleNoiseWithHeightScales noise with volume height. Range 0–1. Default: 0.
bool customHeightIgnores volume height and uses a custom height from the profile. Default: false.
float heightCustom height value (used when customHeight is true). Default: 0.
float verticalOffsetVertical offset for the fog density within the volume. Default: 0.
float distanceMinimum distance from camera for fog to appear. Default: 0.
float distanceFallOffDistance fall-off. Range 0–1. Default: 0.93.
float maxDistanceMaximum distance from camera. Default: 10000.
float maxDistanceFallOffFall-off at max distance. Range 0–1. Default: 0.
Mesh customMeshCustom mesh used when shape is set to Custom.
Terrain Fit
bool terrainFitFits fog altitude to the terrain heightmap. Default: false.
HeightmapCaptureResolution terrainFitResolutionResolution of the heightmap capture: _64, _128, _256, _512, or _1024. Default: _128.
LayerMask terrainLayerMaskWhich objects are included in the heightmap capture. Default: Everything.
float terrainFogHeightHeight of fog above the terrain surface. Default: 25.
float terrainFogMinAltitudeMinimum altitude for terrain-fitted fog. Default: 0.
float terrainFogMaxAltitudeMaximum altitude for terrain-fitted fog. Default: 150.
Colors
Color albedoFog base color. Default: light gray.
float brightnessOverall brightness multiplier. Default: 1.
float deepObscuranceDarkens fog in thicker/deeper areas. Range 0–2. Default: 1.
Color specularColorSpecular highlight color. Default: (1, 1, 0.8).
float specularThresholdSpecular threshold. Range 0–1. Default: 0.637.
float specularIntensitySpecular intensity. Range 0–1. Default: 0.428.
bool enableDepthGradientEnable depth-based color gradient. Default: false.
Gradient depthGradientDepth gradient (HDR, linear interpolation).
float depthGradientMaxDistanceMaximum distance for the depth gradient. Default: 1000.
bool enableHeightGradientEnable height-based color gradient. Default: false.
Gradient heightGradientHeight gradient (HDR, linear interpolation).
Animation
float turbulenceTurbulence speed. Default: 0.73.
Vector3 windDirectionWind direction and speed. Default: (0.02, 0, 0).
bool useCustomDetailNoiseWindDirectionUse a separate wind direction for detail noise. Default: false.
Vector3 detailNoiseWindDirectionWind direction for detail noise. Default: (0.02, 0, 0).
Directional Light
bool dayNightCycleSyncs fog lighting with the Sun/Moon from the Volumetric Fog Manager. Default: true.
Vector3 sunDirectionCustom sun direction (used when dayNightCycle is disabled). Default: Vector3.up.
Color sunColorCustom sun color (used when dayNightCycle is disabled).
float sunIntensityCustom sun intensity. Default: 1.
float ambientLightMultiplierInfluence of ambient light on fog. Default: 0.
DiffusionModel lightDiffusionModelLight diffusion model: Simple, Smooth, or Strong. Default: Simple.
float lightDiffusionPowerLight diffusion power. Range 1–256. Default: 32.
float lightDiffusionIntensityLight diffusion intensity. Default: 0.4.
float lightDiffusionNearDepthAttenNear depth attenuation for light diffusion. Default: 0.
bool receiveShadowsEnable shadow reception from the directional light. Default: false.
float shadowIntensityShadow intensity. Range 0–1. Default: 0.5.
float shadowCancellationRemoves fog in shadowed areas. Range 0–1. Default: 0.
float shadowMaxDistanceMaximum distance for shadow rendering. Default: 250.
bool cookieUses the directional light’s cookie texture on the fog. Default: false.
Distant Fog
bool distantFogEnables exponential distant fog for horizon/sky coverage. Default: false.
bool distantFogShowInEditModeShow distant fog in edit mode. Default: true.
float distantFogStartDistanceStart distance for distant fog. Default: 1000.
float distantFogDistanceDensityDistance density. Default: 0.5.
float distantFogMaxHeightMaximum height. Default: 4000.
float distantFogHeightDensityHeight density. Default: 0.5.
Color distantFogColorDistant fog color. Default: dark gray.
float distantFogDiffusionIntensityLight diffusion intensity for distant fog. Default: 0.4.
int distantFogRenderQueueRender queue. Default: 2999.
float distantFogBaseAltitudeBase altitude. Default: 0.
bool distantFogSymmetricalSymmetrical distant fog. Default: false.
bool distantFogTransparencySupportEnables transparency support via depth peeling. Default: false.
bool distantFogNoiseEnables noise for distant fog. Default: false.
Texture3D distantFogNoiseTextureNoise texture for distant fog.
float distantFogDistanceNoiseScaleNoise scale. Default: 0.1.
float distantFogDistanceNoiseStrengthNoise strength. Range 0–1. Default: 0.5.
float distantFogDistanceNoiseMaxDistanceMax distance for noise fade out. Default: 250.
Vector3 distantFogNoiseWindDirectionWind direction for distant fog noise. Default: (0.002, 0.002, 0).
Methods & Events
void ValidateSettings()Validates and clamps all profile settings to their valid ranges.
void Lerp(VolumetricFogProfile p1, VolumetricFogProfile p2, float t)Interpolates all profile settings between two profiles by factor t (0–1). Useful for smooth transitions between fog configurations.
event OnSettingsChanged onSettingsChanged()Fired when profile settings are modified.
Delegate: void OnSettingsChanged()
Code Examples
Runtime Fog Modification
using UnityEngine;
using VolumetricFogAndMist2;
public class FogController : MonoBehaviour {
VolumetricFog fog;
void Start() {
fog = GetComponent<VolumetricFog>();
// Modify instanced profile (only this volume)
fog.settings.density = 2f;
fog.settings.albedo = new Color(0.5f, 0.6f, 0.7f);
fog.settings.windDirection = new Vector3(0.05f, 0, 0);
fog.UpdateMaterialProperties();
}
void Update() {
// Animate density over time
fog.settings.density = 1f + Mathf.Sin(Time.time) * 0.5f;
fog.UpdateMaterialProperties();
}
}
Follow Target Setup
VolumetricFog fog = GetComponent<VolumetricFog>();
fog.enableFollow = true;
fog.followTarget = player.transform;
fog.followMode = VolumetricFogFollowMode.RestrictToXZPlane;
fog.followOffset = new Vector3(0, -2, 0);
Fog of War
VolumetricFog fog = GetComponent<VolumetricFog>();
// Clear fog at player position (circular)
fog.SetFogOfWarAlpha(player.position, radius: 15f, fogNewAlpha: 0f);
// Clear fog within bounds (rectangular)
fog.SetFogOfWarAlpha(new Bounds(center, size), fogNewAlpha: 0f);
// Clear fog matching a collider shape
fog.SetFogOfWarAlpha(areaCollider, fogNewAlpha: 0f);
// Clear with auto-restore after 5 seconds
fog.SetFogOfWarAlpha(player.position, 10f, fogNewAlpha: 0f,
blendAlpha: true, duration: 0.5f, smoothness: 1f,
restoreDelay: 5f, restoreDuration: 3f);
// Query fog opacity at a position
float alpha = fog.GetFogOfWarAlpha(targetPosition);
// Reset all fog of war
fog.ResetFogOfWar();
Batched Fog of War (Hex Grids / Tile Maps)
VolumetricFog fog = GetComponent<VolumetricFog>();
// A mesh representing a single tile shape (e.g. hexagon)
public GameObject tileMeshPrefab;
// Reveal multiple tiles at once with the same alpha
Vector3[] tileCenters = new Vector3[] {
new Vector3(10, 0, 20),
new Vector3(12, 0, 22),
new Vector3(14, 0, 20)
};
fog.SetFogOfWarAlpha(tileMeshPrefab, tileCenters, fogNewAlpha: 0f);
// Per-tile alpha values (e.g. partial visibility)
float[] alphas = new float[] { 0f, 0.3f, 0f };
fog.SetFogOfWarAlpha(tileMeshPrefab, tileCenters, alphas, duration: 0.5f);
Profile Interpolation
public VolumetricFogProfile daytimeProfile;
public VolumetricFogProfile nightProfile;
void UpdateFogForTimeOfDay(float t) {
VolumetricFog fog = GetComponent<VolumetricFog>();
fog.settings.Lerp(daytimeProfile, nightProfile, t);
fog.UpdateMaterialProperties();
}
Saving & Loading Fog of War State
VolumetricFog fog = GetComponent<VolumetricFog>();
// Save state
Color32[] savedState = fog.fogOfWarTextureData;
// Load state
fog.fogOfWarTextureData = savedState;Suggest an improvement
Help us improve this documentation page.