Scripting Support (C#)
advanced scriptingVolumetric Fog & Mist 3 · Scripting Support (C#)
All the classes are in the FluidFogAndMist namespace.
using FluidFogAndMist;
FluidFog (Fog Volume)
Changing Settings
The fog look is in fog.settings, a FluidFogSettings object. The fog volume sends the settings to the fog every frame, so a change shows in the next frame.
FluidFog fog = GetComponent<FluidFog>();
fog.settings.density = 2f;
fog.settings.albedo = new Color(0.9f, 0.95f, 1f);
fog.settings.windDirection = new Vector3(1f, 0f, 0.5f);
Shared profiles - With a profile assigned,
settings returns the settings of the profile, so a change reaches every fog volume that uses it, and in the editor it changes the profile asset. To change only one fog volume, call MakeProfileLocal() first.
FluidFogSettings own = fog.MakeProfileLocal();
own.height = 8f;
Members
| Member | Description |
|---|---|
FluidFogProfile profile | Profile that keeps the settings. With no profile, the fog volume uses its own settings. |
FluidFogSettings settings | Settings in use: the settings of the profile if one is assigned, otherwise the own settings of the fog volume. |
FluidFogSettings MakeProfileLocal() | Copies the settings of the profile into the fog volume and removes the profile. Returns the own settings. |
void LoadPreset(FluidFogProfile preset) | Copies the look of a profile into the own settings and removes the profile. The Terrain Fit settings stay. |
Bounds GetBounds() | Box of the fog volume in world space. |
static List<FluidFog> fluidFogs | Fog volumes enabled in the loaded scenes. |
bool enableNativeLights, nativeLightsMultiplier, nativeLightSteps, renderingLayerMask | Native lights options. |
bool cookie, castShadows, enableVoids | Cookie, Cast Shadows and Fog Voids options. |
bool enableFollow, Transform followTarget, FluidFogFollowMode followMode, Vector3 followOffset | Follow options. |
int sortingOrder | Drawing order of overlapping fog volumes. |
Terrain Fit
| Method | Description |
|---|---|
void PerformHeightmapCapture() | Captures the ground again. Call it after the terrain changes. |
float GetBaseAltitude(Vector3 position) | Altitude of the bottom of the fog layer at a position. After a capture, the new heights take a few frames to arrive. |
Fluid Simulation
| Member | Description |
|---|---|
bool enableFluidSimulation | Turns the fluid simulation on or off. |
Transform fluidTarget | Object at the center of the simulated area (Area Center). |
static void Blast(Vector3 position, float radius, float strength, float spin = 0, float verticalRadius = 0) | Blows the fog away from a point. strength is the speed in meters per second of the pushed fog, spin turns the fog around the center and verticalRadius is the vertical reach in meters (0 for the whole height of the fog). |
bool GetFluidFogAmount(Vector3 position, out float amount) | Gets the fog amount of the simulation at a position, from 0 (no fog) to 1 (full fog). The value is a few frames old. Returns false while there is no value. |
void SimulateFluid(float deltaTime) | Advances the simulation by the given seconds. Use it with fluidAutoSimulate off. |
void ResetFluidSimulation() | Puts the simulated fog back to rest at once. |
Fog of War
Enable enableFogOfWar on the fog volume first. Alpha 0 means no fog and 1 means full fog.
// clear a circle of 10 meters around the player in 1 second
fog.SetFogOfWarAlpha(player.position, 10f, 0f, 1f);
// clear the area of a collider
fog.SetFogOfWarAlpha(roomCollider, 0f);
// read the value at a position
float alpha = fog.GetFogOfWarAlpha(player.position);
// put all the fog back
fog.ResetFogOfWar();
| Method | Description |
|---|---|
SetFogOfWarAlpha(...) | Changes the fog of war inside a circle (position and radius), a Bounds, a Collider or the mesh of a GameObject. Options include the duration of the change, the border smoothness, a restore delay and duration, and the update method (FoWUpdateMethod.MainThread or BackgroundThread). |
ResetFogOfWarAlpha(...) | Sets the fog of war at once inside a circle, a Bounds, a Collider, a GameObject or a box. |
ResetFogOfWar(float alpha = 1) | Sets the whole map to one value. |
float GetFogOfWarAlpha(Vector3 worldPosition) | Gets the fog of war value at a position. |
Texture2D fogOfWarTexture | Mask texture of the fog of war. |
void ReloadFogOfWarTexture() | Reloads the map from the mask texture. |
void UpdateFogOfWar(bool forceUpload = false) | Sends the pending changes of the map to the fog. The fog volume calls it every frame. |
Other Components
| Class | Public fields |
|---|---|
FogPusher | radius, push, clear, fullClearSpeed, verticalRadius |
FogJet | areaSize, areaCenter, animateOffScreen, radius, speed, emission, gravity, turbulence, swirl, fogLifetime, color, density, groundEmission, groundSpread |
FogObstacle | No settings. The collider of the object gives its shape. |
FogVoid | roundness, falloff |
FluidFogManager
| Member | Description |
|---|---|
static FluidFogManager GetManagerIfExists() | Returns the manager in use, or null if the scene has no manager. With several managers, the main manager is used, otherwise the last one enabled. |
static PerformanceLevel currentPerformanceLevel | Performance level in use, or the default level if the scene has no manager. |
PerformanceLevel performanceLevel | High, Balanced, Low or Custom. |
int downscaling, minBufferHeight | Size of the fog rendering. |
bool temporal, temporalUpscale, float temporalBlend | Temporal options. |
bool transparentSupport | Draws the fog over compatible transparent objects. |
Was this page helpful?
Suggest an improvement
Help us improve this documentation page.