Volumetric Lights 2 (Built-in) · Scripting Support (C#)
This page covers the Built-in Render Pipeline version. See also the URP version.
The main scripting class is VolumetricLight (namespace VolumetricLights). This MonoBehavior attaches to any GameObject with a Light component. Settings can optionally be stored in a VolumetricLightProfile ScriptableObject for sharing across multiple lights.
Use profile to assign a shared profile and set profileSync = true to keep settings synchronized. Changes to the profile automatically update all lights referencing it. Without a profile, modify fields directly on the component.
void SetBounds(Bounds bounds)Sets the custom bounds for the volumetric light in world space. If boundsInLocalSpace is enabled, the bounds center is adjusted relative to the light position.
event PropertiesChangedEvent OnPropertiesChanged(VolumetricLight volumetricLight)Instance event fired when the volumetric light properties are updated. Subscribe to react to property changes.
static List<VolumetricLight> volumetricLightsStatic list of all active VolumetricLight instances in the scene. Lights are added on enable and removed on disable.
void PropertiesChangedEvent(VolumetricLight volumetricLight)void UpdateMaterialProperties()Schedules an update of the volumetric light material properties. Call this after modifying light settings at runtime.
A ScriptableObject containing the same settings fields as VolumetricLight. Create via Unity menu Assets > Create > Volumetric Light Profile. Assign to one or more lights and set profileSync = true to share settings.
void ApplyTo(VolumetricLight vl)Copies all profile settings to the specified VolumetricLight instance and calls UpdateMaterialProperties().
void LoadFrom(VolumetricLight vl)Copies all settings from the specified VolumetricLight instance into this profile.
using UnityEngine;
using VolumetricLights;
public class LightController : MonoBehaviour {
VolumetricLight vl;
void Start() {
vl = GetComponent<VolumetricLight>();
vl.density = 0.5f;
vl.mediumAlbedo = new Color(1f, 0.9f, 0.8f);
vl.brightness = 1.5f;
vl.noiseStrength = 0.8f;
vl.windDirection = new Vector3(0.05f, 0.01f, 0);
vl.UpdateMaterialProperties();
}
}
VolumetricLight vl = GetComponent<VolumetricLight>();
vl.enableShadows = true;
vl.shadowIntensity = 0.8f;
vl.shadowBakeInterval = ShadowBakeInterval.EveryFrame;
vl.shadowResolution = ShadowResolution._512;
vl.ScheduleShadowCapture();
vl.UpdateMaterialProperties();
VolumetricLight vl = GetComponent<VolumetricLight>();
vl.enableDustParticles = true;
vl.dustBrightness = 0.8f;
vl.dustMinSize = 0.005f;
vl.dustMaxSize = 0.03f;
vl.dustWindSpeed = 1.5f;
vl.UpdateMaterialProperties();
VolumetricLight vl = GetComponent<VolumetricLight>();
vl.autoToggle = true;
vl.distanceStartDimming = 50f;
vl.distanceDeactivation = 80f;
vl.autoToggleCheckInterval = 0.5f;
public VolumetricLightProfile torchProfile;
public VolumetricLightProfile lanternProfile;
void SetupTorch(VolumetricLight vl) {
torchProfile.ApplyTo(vl);
}
void SaveCurrentSettings(VolumetricLight vl) {
lanternProfile.LoadFrom(vl);
}
foreach (VolumetricLight vl in VolumetricLight.volumetricLights) {
vl.brightness *= 0.5f;
vl.UpdateMaterialProperties();
}Help us improve this documentation page.