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.
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
Replaces the URP terrain grass shader with a shader that supports snow.
Weather
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: standing water, independent from the rain. 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. Range 0.001 to 1.5, default 0.35.
Coverage
LayerMask layerMask
Layers that can receive snow. Objects on the Default layer are never excluded by this mask. 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. Range 0 to 1.
float minimumAltitude
Snow level in world units. Default -10.
float altitudeBlending
Altitude Range: height in meters above the minimum altitude where the snow appears in growing patches. 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 50 meters), Manual (call UpdateSnowCoverage()) or Disabled. Default Discrete.
ZenithalCoverageCullMode zenithalCoverageCullMode
Normal or BothFaces. Both Faces also captures the back faces of single sided roofs. Default Normal.
float groundCoverage
Lets snow get under opaque objects: it fills in under the lowest covers and comes in patches under higher ones. Range 0 to 0.5, default 0.
float coverageScatter
Coverage Scatter: width in meters of the snow scattered in patches outward from what covers the ground. 0 gives a clean edge. Range 0 to 8, default 0.
float minimumAltitudeVegetationOffset
Height offset added to the minimum altitude for terrain grass. Default 0.
float grassCoverage
Amount of snow on grass. Range 0 to 1, default 0.75.
int coverageExtension
Size of the coverage area: 1 = 512 m up to 4 = 4096 m. Default 1.
int coverageResolution
Coverage Quality: 1 = 512 up to 4 = 4096 pixels. Default 1.
bool showCoverageGizmo
Shows the coverage area in the Scene View.
bool coverageDepthDebug
Shows the coverage depth texture in the inspector.
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 MaskPaint() or the Mask Editor when none is assigned. Default 1024.
bool maskEditorEnabled
Mask Editor brush settings: maskEditorEnabled, maskBrushMode (MaskTextureBrushMode.AddSnow or RemoveSnow, default RemoveSnow), maskBrushWidth (radius in world units, default 20), maskBrushFuzziness (default 0.5) and maskBrushOpacity (default 0.25).
Snow Appearance
SnowQuality snowQuality
Complexity: FlatShading, NormalMapping or ReliefMapping. Default ReliefMapping.
float reliefAmount
Relief intensity with Relief Mapping. Range 0.05 to 0.3, default 0.3.
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. Default 0.75.
float snowLayerThickness
Thickness of the snow layer in meters. 0 means no layer. Range 0 to 0.3, default 0.15.
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. Range 0 to 1, default 0.
float scatterEdgeSoftness
Width of the layer slope at the edges of the bare patches of Scatter, Coverage Scatter and Ground Coverage. Range 0.1 to 1, default 0.25.
float scatterScale
Size in meters of the patches of Scatter, Coverage Scatter and Ground Coverage. Range 1 to 32, default 16.
Color snowTint
Snow color tint.
float smoothness
Snow smoothness. Range 0 to 1, default 0.9.
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, noiseTex
Normal and noise textures of the snow. Call UpdateSnowTexturePropertiesNow() after changing them.
float snowNormalsStrength
Normal map strength. Range 0 to 2, default 1.
float noiseTexScale
Tiling of the noise texture. Default 0.1.
Deep Marks
bool contactMarks
Turns on Deep Marks.
bool contactActive read-only
True when Deep Marks are working: enabled, with a snow layer Thickness above 0, in Play mode and with the component enabled.
float contactSoftness
Softness in meters. Range 0 to 0.03, default 0.012.
float contactRim
Snow pushed up along the edges. Range 0 to 2, default 0.5.
float contactRimNoise
Irregularity of the rim. Range 0 to 1, default 0.35.
float contactShadow
Shadow of the walls of the marks. 0 skips it. The quality presets set it. Range 0 to 1, default 0.3.
Footprints
bool footprints
Turns on footprints.
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.
GroundCheck groundCheck
First person footprint mode: None, CharacterController or RayCast. Default RayCast.
CharacterController characterController
Character Controller used by the CharacterController mode.
Transform footprintsOrigin
Ray Origin of the RayCast mode. If empty, the camera is used.
float groundDistance
Maximum distance from the ray origin to the ground. Default 1.
Collision Marks
bool terrainMarks
Turns on Collision Marks. Needed by MarkAt() and MarkTrail() to draw on the snow.
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. Default _2048.
float terrainMarksViewDistance
Maximum render distance of the marks. Range 0 to 1024, default 200.
bool terrainMarksAutoFPS
FPS Marks: adds marks when the camera moves.
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 marksCompaction
Extra smoothness of the pressed snow. 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.01 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.
float snowfallWhiteout
Distance haze to white. Range 0 to 1, default 0.
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.
float snowfallWaves
Density Waves. 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). Default 0.
float windGustiness
Strength of the gusts. Range 0 to 1, 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
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.
Texture2D frostIceColorTex, frostIceRoughnessTex
Ice color and roughness textures. Empty slots use the bundled textures.
float frostTiling
Ice detail repeats per meter. Range 0.02 to 2, default 0.25.
float frostGlaze
Darkening under the ice. Range 0 to 1, default 0.5.
float frostReflectivity
Strength of the ice reflections. Range 0.5 to 2, default 1.
float frostVeins
Whiteness of rims, cracks and specks. Range 0 to 2, default 0.5.
float frostSmoothness
Glossiness of the ice plates. Range 0 to 1, default 0.95.
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.
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
Wall Drops. Range 0 to 1, default 0.35.
bool rainDetailHalfResolution
Draws the running drops at half resolution.
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 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.
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.
Tools & Debug
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.
int rainDebugView
0 = None, 1 = Impact Rings, 2 = Running Drops Receiver.
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.
Static Flags
static bool needUpdateSnowCoverage
Set to true to capture the coverage again on the next frame.
static bool needFootprintBlit
Set to true to refresh the footprint texture on the next frame.
static bool needRebuildCommandBuffer
Set to true to rebuild the exclusion commands on the next frame.
Methods
void UpdateMaterialProperties()
Queues an update of all the properties. In Play mode it runs on the next frame, in Edit mode at once.
void UpdateMaterialPropertiesNow()
Updates all the properties at once.
void UpdateSnowAppearancePropertiesNow()
Updates only the shader values of the appearance settings.
void UpdateSnowTexturePropertiesNow()
Applies the snow textures. Call it after changing snowNormalsTex or noiseTex.
void UpdateSnowfallProperties()
Applies the snowfall settings.
void UpdateSnowdustProperties()
Applies the snow dust settings.
void UpdateWindProperties()
Applies the wind to snowfall, snow dust and rain.
void UpdateFrostData()
Applies the frost settings.
void UpdateRainPropertiesNow()
Applies the rain settings only.
void ApplySnowPreset(GlobalSnow.SnowPreset preset)
Applies a snowfall preset: SoftSnowfall, LightSnow, Moderate, HeavySnow or Blizzard. It sets the snowfall, the snow dust and the wind speed.
void UpdateSnowCoverage()
Captures the coverage again on the next frame. Use it with the Manual 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 ShiftRainFieldOrigin(Vector3 worldDelta)
Keeps the rain anchored to the world across a floating origin shift. Pass the same offset you added to every transform of the scene. It also moves the puddle mask center.
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. Calls in the next 1.5 s return the exact amount the snow renders.
Awaitable<SnowAndWater> GetSnowAndWaterAtPositionAsync(Vector3 position)
Snow and standing water at the position as the snow renders them, 0 to 1 each, in the snow and water fields of SnowAndWater. 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. The snow mark 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 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. The snow mark needs Collision Marks enabled.
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 and Snow above 0.5, in Play mode, in view of the camera within 30 m, over snow and not standing water. 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.
void CollisionStay(GameObject go, Collision collision, Vector3 contactPoint)
Reports a contact of an object with the snow and leaves collision marks along its path. Global Snow Interaction calls it from the collisions of its object: go is the moving object, the collision is seen from it, and only contacts below the object count. To report a contact by hand, pass the moving object, null as collision and the contact point.
void CollisionStop(GameObject go)
Reports that the object no longer touches the snow.
void AddContactSource(GameObject source, bool plow = false, float sinkDepth = 0.65f)
Adds an object whose renderers dig Deep Marks wherever they rest on or move over the snow, and ripple the puddles they touch. sinkDepth is the share of the layer it sinks into: 1 reaches the ground. Pass plow true for objects that push the snow away, like blades: their marks are as wide as the object and reach 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. 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.
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 void IgnoreGameObject(GlobalSnowIgnoreCoverage obj)
Adds an object to the exclusion list. The component calls it when it is enabled.
static void UseGameObject(GlobalSnowIgnoreCoverage obj)
Removes an object from the exclusion list. The component calls it when it is disabled.
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. 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.
float sinkDepth
Share of the snow layer the object sinks into. 1 reaches the ground. Range 0 to 1, default 0.65.
bool plowMode
Marks as wide as the bounds of the object that reach the ground, for vehicles and blades. Default false.
bool impactFX
Snow burst particles when the object hits the snow. Default true.
bool ripples
Ripples on the puddles the object touches. Default true.
float markSize
Collision Marks size for this collider. Default 0.25.
float collisionDistanceThreshold
Distance between collisions. Default 0.1.
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. 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. Returns false when none are found.
void ResetTracking()
Clears the tracking of the feet, for example after teleporting the character.
GlobalSnowIgnoreCoverage
Per object exclusion. After changing its fields at runtime, call GlobalSnow.instance.RefreshExcludedObjects().
bool receiveSnow
The object and its children receive snow even if their layer is excluded.
bool blockSnow
The object keeps snow off the surfaces below it.
bool useFastMaskShader
Uses the fast mask shader for the exclusion. Default true.
float exclusionCutOff
Alpha cut off for the exclusion. Range 0 to 1.
GlobalSnowProfile
ScriptableObject that stores snow and rain settings. Create one with Create > Global Snow Profile or with the Create button of the inspector.
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.
static void Lerp(GlobalSnow gs, GlobalSnowProfile profile1, GlobalSnowProfile profile2, float t)
Blends two profiles and applies the result. t goes from 0 to 1. 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;
snow.snowQuality = SnowQuality.NormalMapping;
snow.UpdateMaterialProperties();
}
}
Weather Changes
using UnityEngine;
using GlobalSnowEffect;
public class WeatherController : MonoBehaviour {
public void StartBlizzard() {
GlobalSnow snow = GlobalSnow.instance;
snow.ApplySnowPreset(GlobalSnow.SnowPreset.Blizzard);
snow.cameraFrost = true;
snow.cameraFrostIntensity = 0.8f;
}
public void StartRainStorm() {
GlobalSnow snow = GlobalSnow.instance;
snow.snowfall = false;
snow.snowdustIntensity = 0f;
snow.rainAmount = 0.8f;
snow.puddleAmount = 0.7f;
// manual wind source
snow.windSpeed = 6f;
snow.windDirection = 45f;
}
}
Season Transitions with Profiles
using UnityEngine;
using GlobalSnowEffect;
public class SeasonSystem : MonoBehaviour {
public GlobalSnowProfile autumnProfile;
public GlobalSnowProfile winterProfile;
public float transitionDuration = 5f;
float t;
void Update() {
t += Time.deltaTime / transitionDuration;
GlobalSnowProfile.Lerp(GlobalSnow.instance,
autumnProfile, winterProfile, Mathf.Clamp01(t));
}
}
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 and standing water, a few frames later
async void CheckGround() {
SnowAndWater sw = await GlobalSnow.instance.GetSnowAndWaterAtPositionAsync(transform.position);
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);
// trail on the snow, needs 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, 1f)] public float sinkDepth = 0.65f;
void OnEnable() {
GlobalSnow snow = GlobalSnow.instance;
if (snow != null) snow.AddContactSource(gameObject, plow, sinkDepth);
}
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
public GameObject building;
void Start() {
GlobalSnow snow = GlobalSnow.instance;
snow.coverageMask = true;
snow.MaskFillArea(building, 0, 1f, 2f);
}
}
Floating Origin and Camera Cuts
using UnityEngine;
using GlobalSnowEffect;
public class RainOriginHelper : MonoBehaviour {
// call after moving every object of the scene by offset
public void OnWorldShifted(Vector3 offset) {
GlobalSnow.instance.ShiftRainFieldOrigin(offset);
}
// call after a camera cut
public void OnCameraCut() {
GlobalSnow.instance.ResetRainDrops();
}
}
Suggest an improvement
Help us improve this documentation page.