Scripting Support (C#)
advanced scriptingGlobal Snow & Rain 3 · Scripting Support (C#)
Control Global Snow at runtime with the classes of the GlobalSnowEffect namespace. The component on the camera is available through GlobalSnow.instance.
using GlobalSnowEffect;
GlobalSnow snow = GlobalSnow.instance;
snow.snowAmount = 0.8f;
snow.rainAmount = 0.5f;
snow.UpdateMaterialProperties();
Most properties apply at once when you set them. Call UpdateMaterialProperties() after changing several values. Ranges and defaults below match the inspector.
GlobalSnow
MonoBehaviour on the camera that manages the snow, the weather, the marks, the frost and the rain. Access it with GlobalSnow.instance.
General
static GlobalSnow instance read-only
The active Global Snow component. It looks on the main camera first, then on the other cameras.
Camera snowCamera read-only
The camera that has the Global Snow component.
GlobalSnowProfile profile
Gets or sets a profile. Setting a profile applies its settings.
GlobalSnowProfile transitionTarget read-only
Profile that a running TransitionTo() blends into, or null when none runs.
GameObject sun
Directional light used for the snow lighting. If empty, the first directional light in the scene is used.
bool showSnowInSceneView
Renders the snow in the Scene View. Default true.
bool addSnowToGrass
Add Snow To Terrain Grass: uses a grass shader with snow for the grass painted on Unity terrains. For grass and plants placed as objects, use vegetationLayerMask. Set it in the Editor, since changing it from a script in a build has no effect. Default false.
bool addSnowToForwardOpaques
Adds snow to opaque objects whose shader draws only in the forward pass, such as some tree leaves, with an extra pass after them. The leaves use vegetationSlopeThreshold. Default false.
float forwardSnowIntensity
Intensity of Add Snow To Forward Opaques: how much the snow covers the surfaces drawn only in the forward pass. Lower values let the leaves show through the snow. Range 0 to 1, default 0.85.
Weather
float temperature
Air temperature in °C. It decides what falls (snow, wet snow, snow and rain mixed, or rain), the frost, the camera frost and the puddle ice. It does not melt the snow on the ground. Setting it applies the precipitation, like SetPrecipitation(). Range -20 to 10, default -5.
float precipitationIntensity
How much falls: 0 none, 1 light, 2 medium, 3 heavy, 4 storm, 5 extreme. Setting it applies the precipitation, like SetPrecipitation(). Default 2.
string precipitationName read-only
Name of what falls now, for example "Heavy Snow", "Light Snow + Rain" or "Rain Storm".
float snowAmount
Snow slider. From 0 to 1 the snow fades in, from 1 to 2 it grows thicker. Default 1.
bool snowfall
Turns the snowfall on or off. Default true.
float snowfallIntensity
Density of the falling flakes. Range 0.001 to 4, default 0.1.
float snowdustIntensity
Amount of snow dust puffs. Range 0 to 1, 0 hides the dust. Default 0.
float rainAmount
Rain slider: falling rain plus wet surfaces. Range 0 to 1, default 0.
float puddleAmount
Puddles slider: still water, independent from the rain. Range 0 to 1, default 0.
float puddleIce
How frozen the puddles are, from 0 water to 1 still ice. Temperature sets it. Range 0 to 1, default 0.
float frost
Frost slider: hoarfrost on the ground and walls. Range 0 to 1, default 0.
bool cameraFrost
Turns the camera frost on or off. Default true.
float cameraFrostIntensity
Intensity of the camera frost. SetPrecipitation() sets it from the temperature, so it is 0 when there is no frost. Range 0.001 to 1.5, default 0.35.
PerformanceLevel performanceLevel
Performance Level: Best, Medium, Fastest or Custom. It can change at runtime, for example from the graphics menu of a game. Best, Medium and Fastest limit snowQuality, contactMeshDetail, coverageResolution and terrainMarksTextureSize, lowering them only when they are higher than the level allows. Medium and Fastest also turn rainDetailHalfResolution on, and Fastest draws half the snowflakes and turns off Snow Accumulation, Running Drops and Splashes. Medium and Fastest also turn off the Deep Marks Shadow. Those settings keep their own values, and scripts can change them at runtime under any level. Custom uses them as they are. Default Best.
GlobalSnow.PerformanceLevelValues performanceValues read-only
Values in use: the settings limited by the Performance Level, or the settings as they are with Custom. Fields: snowQuality, meshDetail, coverageResolution, rainDetailHalfResolution, terrainMarksTextureSize, flakeShare (share of the snowflakes drawn), and allowSnowLayer, allowRainDetail and allowRainSplashes (false at Fastest), and allowDeepMarksShadow (false at Medium and Fastest).
Coverage
LayerMask layerMask
Layers that can receive snow, for objects and terrains. Nothing gives no snow anywhere. Default: all layers.
int defaultExclusionLayer
Layer used internally for exclusions. Use a layer that no object uses. Default 27.
float exclusionBias
Depth bias for excluded objects. Default 0.99.
bool exclusionDoubleSided
Exclusion for double sided objects.
bool exclusionUseFastMaskShader
Uses the fast mask shader for exclusions. Default true.
float exclusionDefaultCutOff
Alpha cut off for excluded objects. 0 uses the alpha clip of the object materials when they have one. Range 0 to 1, default 0.
float minimumAltitude
Snow level in world units. Default -100.
float altitudeBlending
Altitude Range: height in meters above the minimum altitude where the snow appears in growing patches. Its effect fades to 0 as Snow goes from 1.5 to 2. Minimum 0, default 0.
bool useZenithalCoverage
Uses the top-down capture to keep snow, rain and puddles off covered surfaces. Default true.
LayerMask zenithalMask
Layers that take part in the top-down capture. Default: all layers.
SnowCoverageUpdateMethod coverageUpdateMethod
When the coverage is captured again: EveryFrame, Discrete (after the camera moves coverageUpdateDistance), Manual (call UpdateSnowCoverage()) or Disabled. Default Discrete.
float coverageUpdateDistance
Meters the camera must move before a Discrete coverage capture. Minimum 1, default 50.
ZenithalCoverageCullMode zenithalCoverageCullMode
Normal or BothFaces. Both Faces also captures the back faces of single sided roofs. Default Normal.
float coverageMargin
Margin: meters the snow stays out from walls and other covers, up to two coverage texels (1 m at Best with coverageExtension 1). Raise it when thin walls let snow into rooms. Range 0 to 1, default 0.
float minimumAltitudeVegetationOffset
Height offset added to the minimum altitude for terrain grass. Default 0.
float grassCoverage
Share of each grass blade buried in snow, from the base. Range 0 to 1, default 0.35.
LayerMask vegetationLayerMask
Vegetation Layers: layers of grass and plants placed as objects with their own shader. They get snow with vegetationSlopeThreshold and a snowy base up to vegetationSnowHeight over the ground, and they do not hide the ground from the snow. Default: nothing.
float vegetationSlopeThreshold
Slope Threshold of the plants on the Vegetation Layers. The leaves of addSnowToForwardOpaques use the same value. Lower values put snow on more upright leaves. Range 0 to 1, default 0.3.
float vegetationSnowHeight
Snow Height: height in meters of the snowy base of the plants on the Vegetation Layers over the ground. Minimum 0, default 0.15.
int coverageExtension
Size of the coverage area: 1 = 512 m up to 4 = 4096 m. Default 1.
int coverageResolution
Quality: 1 = 512 up to 4 = 4096 pixels. With a coverageExtension above 1, a value of 1 is raised to 2. Performance Level can limit it. Default 2.
Coverage Mask
bool coverageMask
Turns on the coverage mask.
Texture2D coverageMaskTexture
Mask texture, red channel. 0 = no snow, 255 = full snow.
Vector3 coverageMaskWorldSize
World size covered by the mask. Default (2000, 0, 2000).
Vector3 coverageMaskWorldCenter
World position of the mask center.
bool coverageMaskFillOutside
Fills the area outside the mask with snow. Default true.
int maskTextureResolution
Size of a mask texture created by the mask methods or the Mask Editor when none is assigned, from 256 to 8192. Default 1024.
Snow Appearance
SnowQuality snowQuality
Complexity: FlatShading, NormalMapping or ReliefMapping. Performance Level can limit it. Default ReliefMapping.
float reliefAmount
Relief depth with Relief Mapping. Range 0.05 to 0.3, default 0.2, a relief of about 3 cm.
Texture2D reliefTex, reliefNormalsTex
Relief Height (red channel) and Relief Normals of Relief Mapping. Empty uses the built-in scanned snow. Call UpdateSnowTexturePropertiesNow() after changing them.
float reliefTexSize
Mapping Scale: world size in meters of one tile of the relief textures. Default 1.
float snowShade
Shading of the snow relief and marks toward the sun. Range 0 to 3, default 1.
float glitterStrength
Sparkle intensity. 0 turns it off and values above 1 make it brighter. Default 0.75.
float glitterDensity
How many dots sparkle: lower values leave fewer and values above 1 make each dot flash more often. Range 0 to 3, default 1.
float glitterDistance
Distance in meters where the glitter fades out. Minimum 1, default 100.
bool snowLayer
Snow Accumulation on or off. Default true.
float snowLayerThickness
Thickness of the snow accumulation in meters. 0 means no accumulation. Range 0 to 0.3, default 0.15.
List<ReceiverItemData> snowLayerReceivers
Receivers of the snow accumulation. Each entry has a gameObject, an optional overrideThickness with its thickness (0 to 0.3 m, default 0.15) and an optional overrideSlope with its slopeThreshold (0 to 1, default 0.7). Call RefreshReceivers() after you change the list or the layer of a receiver in Play mode.
float contactMeshDetail
Mesh Detail: how fine the snow accumulation mesh is on terrains, everywhere. 0 keeps the terrain mesh, 0.5 gives triangles of about 20 pixels near the camera and 1 about 4 pixels. Higher values cost more GPU time. Performance Level can limit it. Range 0 to 1, default 0.5.
bool snowLayerMeshDebug
Show Mesh: tints the snow accumulation in green and draws the real edges of its triangles on terrains in dark green, to check Mesh Detail.
bool snowLayerFillNearCamera
Fill Near Camera: keeps the snow accumulation from being cut near a very low camera over a terrain. Default false.
bool unitySSAOAfterSnow
Unity SSAO After Snow: runs the Unity Screen Space Ambient Occlusion after the snow accumulation, so it does not darken the ground under the snow. Set it to false to keep the Unity order. Default true.
static void RefreshReceivers()
Call it after you move, add or remove receivers, or change the layer of a receiver, in Play mode, so the snow accumulation and its edges follow. ReceiversChanged() still works but is obsolete.
bool snowLayerActive read-only
True when Snow Accumulation is on, the Performance Level is not Fastest, its Thickness is above 0 and the Receivers list has at least one object. It does not check Play mode or whether the component is enabled.
float slopeThreshold
Steepest slope where snow can stay. Range 0 to 1, default 0.7. See also slopeSharpness and slopeNoise (default 0.5 each).
float snowDepthSlopeCutoff
Deep Snow Cutoff: with Snow above 1, the steepest slope the extra snow fills. Range 0 to 1, default 0.45.
float altitudeScatter
Scatter: share of the ground left bare in patches. Its effect fades to 0 as Snow goes from 1.5 to 2. Range 0 to 1, default 0.
float scatterEdgeSoftness
Width of the accumulation slope at the edges of the bare patches of Scatter. Range 0.1 to 1, default 0.6.
float scatterScale
Size in meters of the patches of Scatter. Range 1 to 32, default 16.
Color snowTint
Snow color tint.
float smoothness
Snow smoothness. Range 0 to 1, default 0.3.
float snowExposure
Brightness of the snow. Range 0 to 2, default 1.
float minimumGIAmbient
Lowest ambient light on the snow. Range 0 to 1, default 0.2.
float maximumGIAmbient
Highest ambient light on the snow. Range 0 to 4, default 0.5.
Texture2D snowNormalsTex
Normals Texture: normal map of the snow with Normal Mapping. Call UpdateSnowTexturePropertiesNow() after changing it.
float snowNormalsStrength
Normals Strength: strength of the normal map, and of the relief normals with Relief Mapping. Range 0 to 2, default 1.
float noiseTexScale
Normals Scale: tiling of the normals texture. Default 0.1.
Deep Marks
bool contactMarks
Turns on Deep Marks. They need the snow accumulation and draw nothing without it. Default false.
bool contactActive read-only
True when Deep Marks are working: enabled, with snowLayerActive true and Snow above 0, in Play mode and with the component enabled. The marks are cleared when Snow or the Thickness reaches 0.
float contactSoftness
Softness in meters. Range 0 to 0.03, default 0.03.
float contactRim
Snow pushed up along the edges. Range 0 to 2, default 1.48.
float contactRimWidth
Rim Width in meters. Range 0.05 to 0.2, default 0.0848.
float contactRimNoise
Irregularity of the rim. Range 0 to 1, default 0.205.
float contactRimNoiseScale
Rim Noise Scale in meters. Range 0.005 to 0.2, default 0.0282.
bool deepMarksShadow
Shadow of the walls of the marks on the direct light. It works with Performance Level Best and Custom. Default true.
Footprints
bool footprints
Turns on footprints, for characters with feet and for the first person steps.
Texture2D footprintsSoleTexture
Sole texture stamped at each footprint. If empty, the bundled sole is used.
int footprintsDuration
Seconds before footprints fade out. Range 1 to 240, default 60.
float footprintsScale
World meters covered by each footprint. Range 0.04 to 1, default 1.
float footprintsObscurance
Darkening of the footprints. Range 0.05 to 0.5, default 0.1.
Collision Marks
bool terrainMarks
Turns on Collision Marks. MarkAt() and MarkTrail() need it to draw on the snow when Deep Marks are not working or the point is more than 34 m from the camera.
float terrainMarksDefaultSize
Default mark size. Range 0 to 1, default 0.25.
float terrainMarksWidthMultiplier
Widens the collision marks. Minimum 0.1, default 1.
float terrainMarksDigDepth
Visual depth of a mark in meters. Minimum 0.01, default 0.15.
DecalTextureResolution terrainMarksTextureSize
Extents: _512, _1024, _2048, _4096 or _8192. A change applies at once. Performance Level can limit it. Default _2048.
float terrainMarksViewDistance
Maximum render distance of the marks. It works up to terrainMarksTextureSize / 16 meters. Range 0 to 1024, default 200.
float terrainMarksStepMaxDistance
Max Step between two frames for a continuous trail. Default 20.
float terrainMarksRoofMinDistance
Minimum distance from a mark to a roof above. Default 0.5.
float terrainMarksRotationThreshold
Rotation in degrees that triggers a new mark for contacts reported with CollisionStay() for objects without Global Snow Interaction. Default 3.
Marks Common Options
int terrainMarksDuration
Seconds that Deep Marks and Collision Marks take to fill back in. Range 1 to 240, default 180.
bool terrainMarksImpactFX
Turns on the Impact FX snow bursts. Default true.
float terrainMarksImpactFXIntensity
Strength of the Impact FX particles. Range 0 to 2, default 1.
float terrainMarksImpactFXDistance
Impact FX Distance: impacts farther than this from the camera, in meters, throw no snow particles. Contact ripples use the same distance. Range 5 to 200, default 30.
float marksCompaction
Extra smoothness of the pressed snow, and how much snow detail the Deep Marks lose. Range 0 to 1, default 0.25.
bool marksDirtEnabled
Dirt Reveal. Default true. Related fields: marksDirtFloor (meters, default 0.02), marksDirtBlend (default 1), marksDirtColor, marksDirtAlbedoTex, marksDirtNormalTex, marksDirtHeightTex, marksDirtTiling (default 2), marksDirtNormalStrength (default 1) and marksDirtSmoothness (default 0.2).
Snowfall
float snowfallSpeed
Fall speed in meters per second. Range 0.1 to 3, default 1.
float snowfallWeight
Resistance to wind and flutter. Range 1 to 10, default 1.
float snowfallDistance
Emission Distance: size of the flake volume. Range 10 to 200, default 100.
bool snowfallUseIllumination
Flakes catch light from the sun direction.
float snowfallFlakeSize
Base flake size in meters. Range 0.001 to 0.1, default 0.06.
float snowfallBrightness
Flake color multiplier. Range 0.5 to 3, default 1.
float snowfallCrispness
Smaller, more solid flakes. Range 0 to 1, default 0.
bool snowfallWhiteoutEnabled
Turns the whiteout on or off. When false, there is no haze at any precipitation intensity. Default true.
float snowfallWhiteout
Distance haze to white. Range 0 to 1, default 0.
float snowfallMeltingFlakes
Melting Flakes: snowflakes that fall on water stay there for a short time and melt. Range 0 to 1, 0 turns it off. Default 1.
int snowfallRenderQueue
Render queue of the snowflakes and the snow dust. They always draw after the whiteout. Range 2501 to 5000, default 3000.
bool snowfallWhiteoutUseFog
Applies the whiteout to objects in the transparent queue through the URP linear fog. Default true.
int snowfallWhiteoutRenderQueue
Render queue of the whiteout. It covers the transparent objects with a lower render queue. Range 2501 to 5000, default 2990.
float snowfallFlutter
Sideways drift of the flakes. Range 0 to 1, default 0.35.
float snowfallStreaks
Motion streaks. Range 0 to 1, default 0.5.
Snow Dust
float snowdustVerticalOffset
Lift of the puffs in meters. Range -5 to 5, default 0.
float snowdustSize
Puff Size in meters. Range 0.05 to 20, default 1.5.
float snowdustThickness
Max Height of the puff centers. Range 0.02 to 15, default 0.1.
float snowdustRange
Width of the dust volume in meters. Range 40 to 120, default 80.
float snowdustCoverBlur
Shelter Blur in meters. Range 2 to 20, default 8.
float snowdustCoverFade
Shelter Fade in meters. Range 1 to 20, default 6.
float snowdustSoftIntersection
Fade distance near solid geometry. Range 0.01 to 5, default 1.
Wind
WindSource windSource
Manual or WindZone. Default Manual.
WindZone windZone
WindZone read by the WindZone source.
float windZoneSpeedScale
Meters per second per unit of WindZone Main strength. Range 0.1 to 20, default 5.
float windSpeed
Manual wind speed in meters per second. Range 0 to 20, default 0.
float windDirection
Manual direction the wind blows toward, in degrees (0 = +X, 90 = +Z). Range 0 to 360, default 0.
float windGustiness
Strength of the gusts on snowfall, snow dust and rain. The gusts also turn the snowfall wind, up to 15 degrees at 1 and up to 90 degrees at 2. Range 0 to 2, default 0.6.
float currentWindSpeed read-only
Wind speed in meters per second currently used by snowfall, snow dust and rain.
float currentWindDirection read-only
Direction the wind blows toward, in degrees (0 = +X, 90 = +Z).
Vector2 currentWindVector read-only
Horizontal wind vector (X and Z) in meters per second.
Frost
LayerMask frostLayerMask
Layers that can get frost. Objects on other layers keep their snow but get no frost. Default: all layers.
float frostWallHeight
How high the frost climbs walls, in meters. 20 means no limit. Range 0.1 to 20, default 1.5.
float frostScale
Patch Scale. Range 0.05 to 2, default 0.35.
float frostNoiseOpacity
Noise Opacity: how much frost the noise removes between the patches on walls. 0 gives continuous frost. Range 0 to 1, default 0.7.
Texture2D frostIceColorTex, frostIceRoughnessTex
Veins and Roughness textures of Frost and Ice. Empty slots use the bundled textures.
float frostTiling
Ice detail repeats per meter of Frost and Ice. Range 0.02 to 2, default 0.25.
float cameraFrostSpread
Shape of the frost edge: low values let the frost reach the center of the screen sooner. Range 1 to 5, default 1.2.
float cameraFrostDistortion
How much the frost refracts the view behind it. Range 0 to 1, default 0.25.
Color cameraFrostTintColor
Tint of the camera frost. Default white.
Rain & Wetness
float wetness
Snow Wetness: minimum wet look of the snow. Range 0 to 1, default 0.
float rainSpeedMultiplier
Rain fall speed multiplier. Range 0.5 to 1.5, default 1.
float rainStreakLength
Rain streak length multiplier. Range 0.5 to 1.5, default 1.
float rainContrast
Visibility of the falling drops. Range 0 to 1, default 1.
int rainRenderQueue
Render queue of the rain. A transparent object with a higher render queue draws over the rain. Range 2501 to 5000, default 2988.
float cameraRain
Camera Rain: drops on the camera lens, scaled by Rain. Only on the camera with Global Snow, never in the Scene View. 0 turns it off. Range 0 to 1, default 0.
float cameraRainDropSize
Size of the drops on the lens. Range 0.5 to 2, default 1.
float cameraRainDistortion
How much the lens drops bend the view behind them. Range 0 to 1, default 0.5.
float rainWallWetness
Wall Wetness: how wet walls and steep surfaces are on their own, rain or not. Rain adds to it. Range 0 to 1, default 0.
bool rainDetail
Running Drops. Default true.
float rainDetailSteepCatch
On Walls. Range 0 to 1, default 0.35.
bool rainDetailHalfResolution
Draws the running drops at half resolution. Performance Level Medium and Fastest turn it on. Default false.
float rainDetailContrast
Contrast of the running drops. Range 0 to 1, default 1.
float puddleScale
Scale of the procedural puddle pattern. Range 0.1 to 8, default 1.
float puddleMaxSlope
Max Slope: the steepest ground, in degrees, that holds still water. Range 0 to 20, default 3.
float puddleSmoothness
Smoothness of the puddle water. Lower values give shorter, wider and softer reflections. Range 0.3 to 1, default 0.95.
Color deepWaterTint
Color of the water that collects in deep marks, footprints and furrows in the snow. Alpha sets how much it darkens the snow below. Default (0.735, 0.798, 0.828, 0.8).
float contactRipples
Strength of the contact ripples on the puddles. Range 0 to 2, default 1.
float rainRipples
Strength of the rain rings on the puddles. Range 0 to 2, default 1.
float rainSplashes
Size of the splashes that rain drops throw within 12 m of the camera, wherever they hit. It does not change how many there are. 0 turns them off. Range 0 to 2, default 1.
Texture2D rainPuddleMask
Optional puddle mask (red channel). Null uses procedural patches.
float rainPuddleMaskWorldSize
World meters covered by the puddle mask. Minimum 1, default 512.
Vector2 rainPuddleMaskCenter
World X and Z position of the puddle mask center.
bool lightning
Turns the lightning on or off. Strikes only fall while it rains, and only in Play mode. Default false.
float lightningFrequency
Rate: lightning strikes per minute, on average. Range 0.5 to 30, default 2.
bool lightningFlash
Flash: each strike lights the scene and the sky. Off keeps only the thunder. Default true.
LightningType lightningType
Types: the types of flash that the strikes use, Strike, Flicker and Glow. You can combine them, for example LightningType.Strike | LightningType.Glow, and each strike uses one of them at random. With no type (0), the strikes do not flash and only the thunder remains. Default Strike.
float lightningBrightness
Brightness: the light that a near strike adds to the Sun, in the same units as the Sun intensity. Range 0 to 4, default 1.
Vector2 lightningDistance
Storm Distance: the nearest (x) and the farthest (y) strike, in km. Range 0.5 to 5, default (0.5, 2).
Compare and Debug Views
bool compareMode
Split view without Global Snow on one side.
bool compareSameSide
Both sides show the same view, rendered by a copy of the game camera.
float comparePanning
Shifts the view along the split. Range 0 to 0.5, default 0.25.
float compareLineAngle
Angle of the split line in radians, from -PI to PI. Default 1.4.
float compareLineWidth
Thickness of the split line as a fraction of the screen. Range 0.0001 to 0.05, default 0.002.
bool snowLayerDebug
Show Receivers: tints in green the surfaces that carry the snow accumulation, to check which objects the Receivers reach.
Events
OnUpdatePropertiesEvent OnUpdateProperties()
Called when the snow properties are updated.
GlobalSnow.instance.OnUpdateProperties = () => {
Debug.Log("Snow properties changed");
};
OnUpdateCoverageEvent OnBeforeUpdateCoverage()
Called before the coverage is captured again.
OnUpdateCoverageEvent OnPostUpdateCoverage()
Called after the coverage has been captured.
OnMarkEvent OnMark(Vector3 start, Vector3 end, float radius, float depth)
Called for each mark made by MarkAt(), MarkTrail() and MarkPath() (start and end are the same for MarkAt()). Save the calls to replay the marks later, for example when a saved game is loaded.
GlobalSnow.instance.OnMark = (start, end, radius, depth) => {
savedMarks.Add(new SavedMark { start = start, end = end, radius = radius, depth = depth });
};
OnThunderEvent OnThunder(float closeness)
Called when the thunder of a lightning strike reaches the camera, with the delay of its distance already applied. closeness is 1 for a strike at 0.5 km and 0 for a strike at 5 km. See Thunder Sounds.
Methods
void UpdateMaterialProperties()
Queues an update of all the properties. In Play mode it runs in the next LateUpdate of Global Snow, so a call from Update applies in the same frame. In Edit mode it runs at once.
void UpdateMaterialPropertiesNow()
Updates all the properties at once.
void UpdateSnowTexturePropertiesNow()
Applies the snow textures. Call it after changing snowNormalsTex.
void SetPrecipitation(float temperature, float intensity)
Sets what falls from the air temperature in °C and the intensity from 0 to 5, with the same result as the Temperature and Intensity sliders. It writes Snowfall and Snow Dust with the look of the flakes and the puffs, Rain with its speed, Camera Rain, Camera Frost (cameraFrostIntensity), Frost and puddleIce, and with the Manual wind source also the wind speed and gustiness. It is cheap enough to call every frame. To keep your own values, set them right after the call.
void TransitionTo(GlobalSnowProfile target, float duration)
Blends the current settings into the settings of the profile over the duration in seconds. Without a duration or outside Play mode they apply at once. A new call starts from the settings at that moment. The profile is not assigned as the profile of Global Snow. Use GlobalSnowProfile.FromCurrent() to make a profile with the current settings and change a few of them.
void UpdateSnowCoverage()
Captures the coverage again in the next LateUpdate of Global Snow. Use it with the Manual update method. It has no effect with the Disabled update method.
void RefreshExcludedObjects(bool performFullSceneScan = false)
Refreshes the list of excluded objects. Pass true to scan the whole scene.
void ResetRainDrops()
Clears the running drop history. Call it after a camera cut, a change of projection or any jump that makes the previous frame meaningless.
void ShiftOrigin(Vector3 offset)
Keeps the snow and the rain in place after a floating origin shift. Pass the same offset you added to every transform of the scene, and call it right after that, in the same frame: from Update, or from a LateUpdate that runs before the one of Global Snow. It keeps in place the rain, the puddle mask, the Coverage Mask, Minimum Altitude (it follows the vertical offset), the snowflakes, the puddle ripples and the tracking of characters and moving objects, so nothing draws a trail or plays a footstep across the jump. It also captures the coverage and the Snow Accumulation of the receivers again, and the other cameras catch up one per frame. The Deep Marks, the Footprints and the Collision Marks are erased, since they cannot follow the shift.
float GetSnowAmountAt(Vector3 position)
Snow amount at the position, 0 to 1, at once. The first call for a spot returns an estimate (0 under cover or below the minimum altitude, the coverage mask value inside the mask, 1 otherwise; it uses a physics ray, so the ground needs a collider) and queues a GPU read of its 1 m cell. When the read arrives, a few frames later, calls return the exact amount the snow renders for 1.5 s. After that, the next call reads the cell again and returns the estimate until the new read arrives.
Awaitable<SnowAndWater> GetSnowAndWaterAtPositionAsync(Vector3 position)
Snow, still water and frozen water at the position as the snow renders them, 0 to 1 each, in the snow, water and ice fields of SnowAndWater. ice is the water times the ice that the puddles show, so it also follows Frost and is 0 with Frost 0 even when Puddle Ice is above 0. Use it to play steps on ice over frozen puddles; the demo footsteps do it from an ice of 0.25. The read runs on the GPU and arrives a few frames later; a 1 m cell read in the last 1.5 s answers at once. Use it for the exact value, for example before playing a splash or a crunch.
Marks, Footprints & Impact Methods
These methods mark the snow and also ripple the puddles when Puddles and Contact Ripples are above 0, in Play mode.
void MarkAt(Vector3 position)
Marks the ground at the position with the Default Size, on the snow and on the puddles. With Deep Marks working it digs a round mark into the snow accumulation, within 34 m of the camera; otherwise it leaves a Collision Mark, which needs Collision Marks enabled.
void MarkAt(Vector3 position, float radius)
Same as above with a custom radius. A radius of 0 or less uses the Default Size.
void MarkAt(Vector3 position, float radius, float depth)
Same as above with a deep mark depth in meters, limited to the Snow Accumulation Thickness. 0 uses Dig Depth. Collision Marks ignore it.
void MarkTrail(Vector3 start, Vector3 end, float radius)
Marks the ground along a segment, on the snow and on the puddles. Use it for custom movers like sleds or vehicles. With Deep Marks working it digs a trench that follows the slope, within 34 m of the camera; otherwise it leaves Collision Marks, which need Collision Marks enabled.
void MarkTrail(Vector3 start, Vector3 end, float radius, float depth)
Same as above with a deep mark depth in meters. 0 uses Dig Depth.
void MarkPath(IReadOnlyList<Vector3> points, float radius, float depth = 0)
Marks the ground along a list of points, one MarkTrail() per segment. Use it to replay a saved trail when a game is loaded.
void EmitImpactFX(Vector3 position, Vector3 velocity, float radius)
Emits the impact effects of an object moving on the ground: a snow burst and a ripple on the puddles. The snow burst needs Impact FX on, Snow above 0.5, Snow Wetness and Rain at 0, and a speed of at least 0.2 m/s that is also above 3 m/s, in Play mode, above the minimum altitude, in view of the camera within terrainMarksImpactFXDistance, over snow and not still water. The ripple needs a speed above 0.2 m/s. Nothing happens when the velocity is close to zero.
void FootprintAt(Vector3 position, Vector3 moveDir)
Draws one sole footprint at the position, oriented along moveDir. Each call alternates the left and right foot. Needs Footprints enabled.
void FootPlantAt(Vector3 position, Vector3 moveDir, FootSide side)
Draws a single sole footprint of the given foot (FootSide.Left or FootSide.Right) at the exact position, oriented along moveDir. Left and right feet keep independent footprints. Needs Footprints enabled.
void CollisionStay(GameObject go, Collision collision, Vector3 contactPoint)
Reports a contact of an object with the snow and leaves collision marks along its path. Pass the moving object and the collision it receives, where only contacts below the object count, or the moving object, null as collision and the contact point. Objects with Global Snow Interaction do this on their own.
void CollisionStop(GameObject go)
Reports that the object no longer touches the snow.
void AddContactSource(GameObject source, bool plow = false, float sinkDepthMeters = 0.1f)
Adds an object whose renderers dig Deep Marks wherever they rest on or move over the snow, and ripple the puddles they touch. sinkDepthMeters is the depth it sinks into the accumulation in meters, up to its Thickness. Pass plow true for objects that push the snow away, like blades: they clear the whole snow accumulation where they pass within 5 cm of the ground. The object is kept while Deep Marks are off, and it marks again when they turn on.
void RemoveContactSource(GameObject source)
Removes an object added with AddContactSource().
Coverage Mask Methods
A value of 0 removes snow and 255 adds full snow. If no mask texture is assigned, these methods create one with maskTextureResolution and turn on the coverage mask. Changes are sent to the GPU automatically.
void MaskPaint(Vector3 pos, byte value, float brushWidth, float brushOpacity = 1f, float brushFuzziness = 0f, MaskPaintMethod paintMethod = MaskPaintMethod.BackgroundThread)
Paints the mask around a world position. brushWidth is the radius in world units. Only the part of the brush inside the mask area is painted. paintMethod can be MainThread, BackgroundThread (used in Play mode) or GPU.
void MaskClear(byte value = 255)
Fills the whole mask with a value. The default 255 gives full snow.
void MaskFillArea(GameObject go, byte value, float opacity = 1f, float border = 0f)
Fills the mask over the shape of the object. The GameObject needs a MeshRenderer and a MeshFilter with a triangle mesh. border widens the shape in meters.
void MaskFillArea(MeshRenderer meshRenderer, byte value, float opacity = 1f, float border = 0f, bool useBackgroundThread = true)
Fills the mask over the shape of a Mesh Renderer.
void MaskFillArea(Bounds bounds, byte value, float opacity = 1f, float fallOff = 0)
Fills the mask inside the given bounds, with an optional fall off at the borders.
void SubmitCoverageMaskTextureChanges()
Sends the pending mask changes to the GPU at once.
Static Methods
static string GetPrecipitationName(float temperature, float intensity)
Name of a precipitation from its air temperature in °C and its intensity, for example "Heavy Snow" or "Rain Storm". It returns "None" when the intensity is 0.
static GlobalSnow.PerformanceLevelValues GetPerformanceLevelValues(PerformanceLevel level, int coverageExtension)
Highest values a Performance Level allows for a coverageExtension, with the same fields as performanceValues. Custom returns the Best values.
static GlobalSnow.PerformanceLevelValues LimitToPerformanceLevel(GlobalSnow.PerformanceLevelValues settings, PerformanceLevel level, int coverageExtension)
The values you pass, limited by a Performance Level for a coverageExtension, as performanceValues does with the current settings. Custom returns them as they are.
GlobalSnowInteraction
Component on a character, vehicle or any object that sets how it interacts with the snow: sink depth, impact FX, ripples, collision marks and footprints. It registers the object for Deep Marks, handles wheel colliders and listens to the collisions of the object, so it marks any ground, roof or object below it with nothing needed on the surface. Contacts with other moving rigidbodies leave no marks and throw no snow. On a physics object, add it to the GameObject that has the Rigidbody. A disabled component leaves the object out of every mark, footprint, snow burst and ripple.
bool interact
Interact: the object leaves marks and throws snow and water when it touches the snow or the puddles. A moving object with Interact on keeps the snow on the ground below it, also with Block Snow/Rain and Precise. True for a component added in the editor, false for one added by script with AddComponent.
float sinkDepthMeters
Depth in meters the object sinks into the snow accumulation, up to its Thickness. Range 0.02 to 0.3, default 0.1.
bool plowMode
Clears the whole snow accumulation under the parts of the object within 5 cm of the ground, for vehicles and blades. The ground keeps its snow coverage. It does not change the width of the marks. Default false.
bool impactFX
Snow burst particles when the object hits the snow, and water drops from its wheels in puddles. Default true.
float impactFXIntensity
Amount of snow particles and water drops this object throws on each impact. 2 and 3 throw two and three times more powder, chunks and drops. Range 0 to 3, default 1.
bool impactFXPowder
The object throws snow powder when it hits the snow. Default on.
float impactFXPowderStartSpeed
Speed in meters per second where this object starts to throw powder. The amount grows gradually and reaches its maximum 7 m/s above this speed. Use it on objects that move fast, such as vehicles. Feet are not affected. Range 0 to 40, default 3.
bool impactFXChunks
The object throws snow chunks when it hits the snow. Default on.
float impactFXChunksStartSpeed
Speed in meters per second where this object starts to throw chunks. The amount grows gradually and reaches its maximum 12 m/s above this speed. Use it on objects that move fast, such as vehicles. Feet are not affected. Range 0 to 40, default 8.
float impactFXChunksSize
Size of the snow chunks this object throws, also with its feet. 1 is the default size. Range 0 to 1, default 1.
bool waterSplashes
Water drops thrown by the wheels of the object in puddles. They need impactFX. Default true.
bool ripples
Ripples on the puddles the object touches. Wheels leave no ripples. Default true.
bool overrideMarkSize
Uses markSize instead of the size measured from the object. Default false.
float markSize
Radius in meters of the Collision Marks of this object, multiplied by terrainMarksWidthMultiplier. It applies when overrideMarkSize is true. Default 0.25.
float collisionDistanceThreshold
How far the object must move before it leaves a new collision mark, in meters. Default 0.3.
bool separateStamps
One round stamp per collision instead of a trail, with no snow particles.
float stepMaxDistance
Maximum length of a trail segment. 0 leaves marks only at the contact points. Default 20.
float rotationThreshold
Rotation in degrees that triggers a new mark. Default 3.
bool leaveFootprints
Draws the sole footprint at each foot plant. It needs Footprints on, and the feet leave Deep Marks instead while Deep Marks work. Default true.
Texture2D soleTexture
Sole of this character. Null uses the Footprints texture of Global Snow.
Transform[] feet
Bones that move with each foot. Even entries are left feet, odd entries are right feet.
bool DetectFeet()
Detects the feet: the foot bones of a humanoid Animator, else up to 8 bones named foot, paw or hoof, skipping IK helpers, in left and right order. Returns false when none are found.
void ResetTracking()
Clears the tracking of the feet, for example after teleporting the character.
bool hasFeet read-only
True when the component tracks at least one foot.
OnFootPlantEvent OnFootPlant(Vector3 position, FootSide side)
Called each time a foot lands, with the contact point and the foot side. Use it to play footstep sounds. It needs Interact on, feet and Global Snow enabled, and Play mode, and it is called whatever the footprint, impact FX and ripple settings are.
GetComponent<GlobalSnowInteraction>().OnFootPlant = (position, side) => {
// play a footstep sound at position
};
GlobalSnowFirstPersonInteraction
Leaves the steps of a first person player on the snow and the puddles. Add it to the camera or to the object with the Character Controller. See Global Snow First Person Interaction.
FirstPersonMarks marks
What the feet dig when Deep Marks is on: Footprints, TwoFeetFurrows or Plow. Default Footprints.
float plowWidth
Width in meters of the bottom of the plow trail. Range 0.2 to 2, default 0.5.
float sinkDepthMeters
Depth in meters of the footprints and the furrows. Range 0.02 to 0.3, default 0.1.
float wallSlope
Slope in degrees of the walls of the marks, 90 for vertical walls. Range 30 to 90, default 60.
float trailStep
Distance in meters the furrows and the plow trail grow at a time. Range 0.01 to 0.5, default 0.1.
bool ripples
Ripples on the puddles the feet touch. Default true.
Texture2D soleTexture
Footprint texture of the feet. Empty uses the Footprints texture of Global Snow.
float stepLength
Distance in meters between two steps. Range 0.3 to 2, default 0.7.
float groundDistance
Maximum height in meters of the object over the ground to count as walking. Default 2.
OnFootPlantEvent OnFootPlant(Vector3 position, FootSide side)
Called at each step with the ground point of the foot and its side, in Play mode. Use it to play footstep sounds.
GetComponent<GlobalSnowFirstPersonInteraction>().OnFootPlant = (position, side) => {
// play a footstep sound at position
};
GlobalSnowInteraction Coverage
Per object exclusion, in the Coverage section of GlobalSnowInteraction. After changing these fields at runtime, call GlobalSnow.instance.RefreshExcludedObjects(). After changing blockSnow, also call UpdateSnowCoverage() so the coverage is captured again.
bool receiveSnow
Off by default, so the object and its children get no snow. Turn it on to give them snow, also when their layer is excluded.
bool blockSnow
Block Snow/Rain: the object keeps snow and rain off the surfaces below it.
bool blockSnowPrecise
Precise: with Block Snow/Rain on, a fine capture from above keeps snow and rain from falling under or inside the object, in a 128 m area around the camera. Only mesh and skinned mesh renderers count. The rain also follows the shape of the object: drops hit its real top and throw small droplets, and the still and flowing water follow its surface. It costs a capture of the precise objects near the camera. Default false.
bool includeTransparents
Include Transparents: the transparent parts of the object, such as car windows, get rain drops, hit rings and running drops within 30 m of the camera. It needs Block Snow/Rain and Precise on, and Running Drops on. It costs one more draw of those parts per camera while it rains. Default false.
bool useFastMaskShader
Uses the fast mask shader for the exclusion. Default true.
float exclusionCutOff
Alpha cut off for the exclusion. 0 uses the alpha clip of the object materials when they have one. Range 0 to 1, default 0.
GlobalSnowProfile
ScriptableObject that stores snow and rain settings. Create one with Create > Global Snow Profile or with the Create button of the inspector. Its fields have the same names as the properties of GlobalSnow, such as performanceLevel, coverageMargin, vegetationLayerMask, vegetationSlopeThreshold and vegetationSnowHeight. To change the Performance Level of a profile, set its performanceLevel.
void ApplyTo(GlobalSnow snow)
Applies the profile settings to a Global Snow component.
void CopyFrom(GlobalSnow snow)
Stores the current settings of a Global Snow component in the profile.
void SetPrecipitation(float temperature, float intensity)
Writes what falls into the profile, with the same values as GlobalSnow.SetPrecipitation(). Then call ApplyTo() or pass the profile to TransitionTo().
static GlobalSnowProfile FromCurrent(GlobalSnow gs)
New profile with the current settings of Global Snow, or with the settings a running TransitionTo() blends into. Change a few of them and pass it to TransitionTo().
static void Lerp(GlobalSnow gs, GlobalSnowProfile profile1, GlobalSnowProfile profile2, float t)
Blends two profiles and applies the result. t goes from 0 to 1. Snowfall, Running Drops, Camera Frost, Snow Accumulation and the whiteout fade in and out. Lightning and its Flash stay on during the blend when one of the profiles has them on. Other toggles and textures switch at 0.5.
GlobalSnowProfile.Lerp(GlobalSnow.instance, autumnProfile, winterProfile, t);
GlobalSnowRenderFeature
LayerMask camerasLayerMask
Layers of the cameras that render Global Snow. Default: all layers.
Code Examples
Basic Runtime Control
using UnityEngine;
using GlobalSnowEffect;
public class SnowController : MonoBehaviour {
void Start() {
GlobalSnow snow = GlobalSnow.instance;
snow.snowAmount = 0.5f;
snow.snowTint = Color.white;
snow.smoothness = 0.7f;
// a lower Complexity applies under any Performance Level
snow.snowQuality = SnowQuality.NormalMapping;
snow.UpdateMaterialProperties();
}
}
Weather Changes
using UnityEngine;
using GlobalSnowEffect;
public class WeatherController : MonoBehaviour {
public void StartBlizzard() {
GlobalSnow snow = GlobalSnow.instance;
// -8 °C, storm intensity
snow.SetPrecipitation(temperature: -8f, intensity: 4f);
// own values after the call
snow.cameraFrost = true;
snow.cameraFrostIntensity = 0.8f;
}
public void StartRainStorm() {
GlobalSnow snow = GlobalSnow.instance;
// +8 °C, storm intensity
snow.SetPrecipitation(temperature: 8f, intensity: 4f);
snow.puddleAmount = 0.7f;
snow.windDirection = 45f;
}
}
Thunder Sounds
using UnityEngine;
using GlobalSnowEffect;
public class ThunderSounds : MonoBehaviour {
public AudioSource thunderSource;
// volume of the thunder of the farthest strikes
public float farVolume = 0.2f;
GlobalSnow snow;
void OnEnable() {
snow = GlobalSnow.instance;
if (snow != null) snow.OnThunder += PlayThunder;
}
void OnDisable() {
if (snow != null) snow.OnThunder -= PlayThunder;
}
// louder for near strikes
void PlayThunder(float closeness) {
thunderSource.volume = Mathf.Lerp(farVolume, 1f, closeness);
thunderSource.Play();
}
}
Season Transitions with Profiles
using UnityEngine;
using GlobalSnowEffect;
public class SeasonSystem : MonoBehaviour {
public GlobalSnowProfile winterProfile;
public float transitionDuration = 5f;
// blend from the current settings into winter
public void StartWinter() {
GlobalSnow.instance.TransitionTo(winterProfile, transitionDuration);
}
// current settings with a snow storm
public void StartSnowStorm() {
GlobalSnowProfile storm = GlobalSnowProfile.FromCurrent(GlobalSnow.instance);
storm.SetPrecipitation(temperature: -8f, intensity: 4f);
GlobalSnow.instance.TransitionTo(storm, transitionDuration);
}
}
Query Snow at a Position
using UnityEngine;
using GlobalSnowEffect;
public class SnowDetector : MonoBehaviour {
void Update() {
// at once: an estimate first, the exact value once the cell has been read
float amount = GlobalSnow.instance.GetSnowAmountAt(transform.position);
if (amount > 0.5f) {
// play snow footstep sounds or slow the player down
}
}
// exact snow, still water and ice, a few frames later
async void CheckGround() {
SnowAndWater sw = await GlobalSnow.instance.GetSnowAndWaterAtPositionAsync(transform.position);
if (sw.ice >= 0.25f) {
// play a step on ice
} else if (sw.water > 0.5f) {
// play a splash
}
}
}
Marks From a Custom Mover
using UnityEngine;
using GlobalSnowEffect;
// sled that marks the snow and ripples the puddles
public class SledMarks : MonoBehaviour {
public float radius = 0.3f;
Vector3 lastPosition;
float lastTime;
void Start() {
lastPosition = transform.position;
lastTime = Time.time;
}
void Update() {
GlobalSnow snow = GlobalSnow.instance;
if (snow == null) return;
Vector3 position = transform.position;
Vector3 travel = position - lastPosition;
if (travel.sqrMagnitude < 0.0025f) return;
Vector3 velocity = travel / Mathf.Max(Time.time - lastTime, 0.001f);
// trench with Deep Marks near the camera, else Collision Marks
snow.MarkTrail(lastPosition, position, radius);
// snow burst and ripple at the current position
snow.EmitImpactFX(position, velocity, radius);
lastPosition = position;
lastTime = Time.time;
}
}
Deep Marks From Any Object
using UnityEngine;
using GlobalSnowEffect;
// digs Deep Marks wherever this object rests on the snow
public class DeepMarkSource : MonoBehaviour {
public bool plow;
[Range(0f, 0.3f)] public float sinkDepthMeters = 0.1f;
void OnEnable() {
GlobalSnow snow = GlobalSnow.instance;
if (snow != null) snow.AddContactSource(gameObject, plow, sinkDepthMeters);
}
void OnDisable() {
GlobalSnow snow = GlobalSnow.instance;
if (snow != null) snow.RemoveContactSource(gameObject);
}
}
Coverage Mask - Clear Snow Under Buildings
using UnityEngine;
using GlobalSnowEffect;
public class BuildingExclusion : MonoBehaviour {
// needs a MeshRenderer and a MeshFilter
public GameObject building;
void Start() {
GlobalSnow snow = GlobalSnow.instance;
snow.coverageMask = true;
snow.MaskFillArea(building, value: 0, opacity: 1f, border: 2f);
}
}
Floating Origin and Camera Cuts
using UnityEngine;
using GlobalSnowEffect;
public class FloatingOriginHelper : MonoBehaviour {
// call right after moving every object of the scene by offset
public void OnWorldShifted(Vector3 offset) {
GlobalSnow.instance.ShiftOrigin(offset);
}
// call after a camera cut
public void OnCameraCut() {
GlobalSnow.instance.ResetRainDrops();
}
}
Suggest an improvement
Help us improve this documentation page.