using UnityEngine;
using UnityEngine.Rendering.Universal;
///
/// Drifts the directional light's cookie so the caustic pattern it projects
/// onto the gravel, walls and fish wanders like light through a water surface.
///
[RequireComponent(typeof(Light))]
public class CausticsScroll : MonoBehaviour
{
public Vector2 drift = new Vector2(0.35f, 0.22f);
[Tooltip("Slow wobble added to the drift so it never looks like a conveyor belt.")]
public float wobble = 0.6f;
UniversalAdditionalLightData data;
Vector2 origin;
void Start()
{
data = GetComponent();
if (data != null) origin = data.lightCookieOffset;
}
void Update()
{
if (data == null) return;
float t = Time.time;
data.lightCookieOffset = origin + drift * t + new Vector2(Mathf.Sin(t * 0.37f), Mathf.Cos(t * 0.29f)) * wobble;
}
}