Lighting/HDRLightAnimator.cs
using Sandbox;
[Title( "HDR Light Animator" )]
public sealed class HDRLightAnimator : Component
{
[Property] public Curve Curve { get; set; } = new Curve( new Curve.Frame( 0.0f, 0.5f ), new Curve.Frame( 1.0f, 1.0f ) );
[Property, Range(0,1)] public float Speed { get; set; } = 1.0f;
Light light;
float time;
float seedRand;
Color cachedLightColor = Color.White;
protected override void OnEnabled()
{
light = Components.Get<Light>( FindMode.EverythingInSelf );
cachedLightColor = light?.LightColor ?? Color.White;
seedRand = Random.Shared.Float( 0, 1000 );
}
protected override void OnUpdate()
{
time = MathF.Sin( Speed * MathF.PI * (Time.Now + seedRand) ).Remap( -1, 1, 0, 1 );
light.LightColor = cachedLightColor * Curve.Evaluate( time );
}
}