
As of version 2.0, we’ve introduced a comprehensive animation system that makes it incredibly easy to create dynamic, engaging lighting effects. The VolumetricLightAnimation
component provides built-in support for pulsing, color cycling, and flickering effects with minimal setup required.
Quick Start
Adding Animation to a Light
1. Select a GameObject
with a VolumetricLight
component
2. Add the VolumetricLightAnimation
component
3. Enable “Enable Animations” in the inspector
4. Configure your desired effects using the intuitive interface
Writing your own animation presets / components
You can also extend our system to write your own preset animations, i.e. to add them repeatedly to different objects.
Basic Usage
using Sparrow.VolumetricLight;
using UnityEngine;
public class BasicAnimationExample : MonoBehaviour
{
[SerializeField] VolumetricLightAnimation m_Animation = default;
void Start()
{
// Enable all animation types
m_Animation.enableAnimations = true;
m_Animation.enablePulsing = true;
m_Animation.enableColorCycling = true;
m_Animation.enableFlickering = true;
}
}
Animation Types
Pulsing Effects
Create dynamic intensity variations with three different patterns:
// Sine wave pulsing - smooth and organic
m_Animation.enablePulsing = true;
m_Animation.pulsingPattern = VolumetricLightAnimation.PulsingPattern.Sine;
m_Animation.pulsingSpeed = 1.5f;
m_Animation.pulsingIntensity = 0.5f;
// Square wave strobing - sharp on/off effect
m_Animation.pulsingPattern = VolumetricLightAnimation.PulsingPattern.Square;
m_Animation.pulsingSpeed = 2f;
m_Animation.pulsingIntensity = 0.8f;
// Random noise pulsing - unpredictable and organic
m_Animation.pulsingPattern = VolumetricLightAnimation.PulsingPattern.Random;
m_Animation.pulsingSpeed = 1f;
m_Animation.pulsingIntensity = 0.3f;
Available Patterns:
Sine
: Smooth, wave-like pulsingSquare
: Sharp on/off strobingRandom
: Noise-based, unpredictable pulsing
Color Cycling
Smoothly transition between colors using predefined palettes or custom color arrays:
// Using predefined palettes
m_Animation.enableColorCycling = true;
m_Animation.colorPalette = VolumetricLightAnimation.ColorPalette.Fire;
m_Animation.colorSpeed = 0.8f;
m_Animation.colorSmoothness = 1.2f;
// Using custom colors
Color[] customColors = { Color.red, Color.blue, Color.green, Color.yellow };
m_Animation.SetCustomPalette(customColors);
m_Animation.colorPalette = VolumetricLightAnimation.ColorPalette.Custom;
Predefined Palettes:
Fire
: Red to yellow gradientIce
: Blue to white gradientNeon
: Bright, saturated colorsSunset
: Warm orange tonesOcean
: Blue to cyan gradientForest
: Green gradientCustom
: Use your own color array
Flickering Effects
Create realistic candle/fire-like flickering with noise-based intensity variation:
m_Animation.enableFlickering = true;
m_Animation.flickerIntensity = 0.6f;
m_Animation.flickerSpeed = 3f;
m_Animation.flickerRandomness = 0.7f;
m_Animation.minFlickerIntensity = 0.2f;
Advanced Features
Time Synchronization
Use time offsets to create synchronized or wave-like effects across multiple lights:
// Create a wave effect across multiple lights
public class WaveEffect : MonoBehaviour
{
[SerializeField] VolumetricLightAnimation[] m_Lights = default;
void Start()
{
for (int i = 0; i < m_Lights.Length; i++)
{
m_Lights[i].timeOffset = i * 0.5f; // Stagger each light by 0.5 seconds
}
}
}
Runtime Control
Dynamically enable/disable animation types at runtime:
public class DynamicControl : MonoBehaviour
{
[SerializeField] VolumetricLightAnimation m_Animation = default;
void Update()
{
// Toggle pulsing based on distance to player
float distance = Vector3.Distance(transform.position, Camera.main.transform.position);
m_Animation.SetAnimationEnabled(
VolumetricLightAnimation.AnimationType.Pulsing,
distance < 10f
);
}
}
Preset Effects
The system includes several built-in presets for common effects:
public class PresetExample : MonoBehaviour
{
[SerializeField] VolumetricLightAnimation m_Animation = default;
void Start()
{
// Apply fire effect preset
ApplyFirePreset();
}
void ApplyFirePreset()
{
m_Animation.enableAnimations = true;
m_Animation.enablePulsing = true;
m_Animation.pulsingPattern = VolumetricLightAnimation.PulsingPattern.Random;
m_Animation.pulsingSpeed = 2f;
m_Animation.pulsingIntensity = 0.3f;
m_Animation.enableColorCycling = true;
m_Animation.colorPalette = VolumetricLightAnimation.ColorPalette.Fire;
m_Animation.colorSpeed = 1.5f;
m_Animation.enableFlickering = true;
m_Animation.flickerIntensity = 0.4f;
m_Animation.flickerSpeed = 3f;
}
}
Performance Considerations
The animation system is optimized for performance:
- Only processes when
enableAnimations
is true - Uses efficient noise functions for flickering
- Minimal impact on frame rate
- Automatically disables when not needed
// Disable animations when not visible for performance
public class PerformanceOptimized : MonoBehaviour
{
[SerializeField] VolumetricLightAnimation m_Animation = default;
[SerializeField] Camera m_Camera = default;
void Update()
{
// Only animate when light is visible
bool isVisible = GeometryUtility.TestPlanesAABB(
GeometryUtility.CalculateFrustumPlanes(m_Camera),
GetComponent<Renderer>().bounds
);
m_Animation.enableAnimations = isVisible;
}
}
Common Use Cases
Campfire Effect
// Realistic campfire with random pulsing, fire colors, and flickering
m_Animation.enableAnimations = true;
m_Animation.enablePulsing = true;
m_Animation.pulsingPattern = VolumetricLightAnimation.PulsingPattern.Random;
m_Animation.pulsingSpeed = 1.5f;
m_Animation.pulsingIntensity = 0.4f;
m_Animation.enableColorCycling = true;
m_Animation.colorPalette = VolumetricLightAnimation.ColorPalette.Fire;
m_Animation.enableFlickering = true;
m_Animation.flickerIntensity = 0.6f;
Neon Sign Effect
// Bright, strobing neon sign
m_Animation.enableAnimations = true;
m_Animation.enablePulsing = true;
m_Animation.pulsingPattern = VolumetricLightAnimation.PulsingPattern.Square;
m_Animation.pulsingSpeed = 2f;
m_Animation.pulsingIntensity = 0.8f;
m_Animation.enableColorCycling = true;
m_Animation.colorPalette = VolumetricLightAnimation.ColorPalette.Neon;
m_Animation.colorSpeed = 1.5f;
Candle Effect
// Subtle, realistic candle flickering
m_Animation.enableAnimations = true;
m_Animation.enableColorCycling = true;
m_Animation.colorPalette = VolumetricLightAnimation.ColorPalette.Fire;
m_Animation.colorSpeed = 0.3f;
m_Animation.enableFlickering = true;
m_Animation.flickerIntensity = 0.5f;
m_Animation.flickerSpeed = 4f;
m_Animation.flickerRandomness = 0.8f;
API Reference
Properties
enableAnimations
: Master toggle for all animationsenablePulsing
: Enable/disable pulsing effectsenableColorCycling
: Enable/disable color cyclingenableFlickering
: Enable/disable flickering effects
Methods
SetAnimationEnabled(AnimationType, bool)
: Enable/disable specific animation typesSetCustomPalette(Color[])
: Set a custom color paletteResetToOriginal()
: Reset light to original state
Enums
PulsingPattern
: Sine, Square, RandomColorPalette
: Fire, Ice, Neon, Sunset, Ocean, Forest, CustomAnimationType
: Pulsing, ColorCycling, Flickering
This animation system provides a powerful and intuitive way to bring your volumetric lights to life with minimal code and maximum visual impact!