using UnityEngine; namespace _02.Scripts { [ExecuteInEditMode] public class SpeedLines : MonoBehaviour { [SerializeField] private Shader shader; [SerializeField] private Texture texture; [SerializeField] private Color color = new(1,1,1,0.1f); [Range(0,1)] [SerializeField] private float width = 0.4f; [Range(0, 1)] [SerializeField] private float length = 0.42f; [Range(0, 100)] [SerializeField] private float lengthSpeed = 17; [Range(0, 1)] [SerializeField] private float density = 0.75f; private Material material; private static readonly int Color = Shader.PropertyToID("_Color"); private static readonly int Width = Shader.PropertyToID("_Width"); private static readonly int Length = Shader.PropertyToID("_Length"); private static readonly int LengthSpeed = Shader.PropertyToID("_LengthSpeed"); private static readonly int Density = Shader.PropertyToID("_Density"); private static readonly int Fbm = Shader.PropertyToID("_FBM"); private void Awake() { if (material) return; material = new Material(shader); material.SetTexture(Fbm, texture); } private void LateUpdate() { material.SetColor(Color, color); material.SetFloat(Width, width); material.SetFloat(Length, length); material.SetFloat(LengthSpeed, lengthSpeed); material.SetFloat(Density, density); } public void OnRenderObject() { material.SetPass(0); GL.PushMatrix(); GL.LoadOrtho(); GL.Begin(GL.QUADS); GL.TexCoord(new Vector3(0, 0, 0)); GL.Vertex3(0, 0, 0); GL.TexCoord(new Vector3(0, 1, 0)); GL.Vertex3(0, 1, 0); GL.TexCoord(new Vector3(1, 1, 0)); GL.Vertex3(1, 1, 0); GL.TexCoord(new Vector3(1, 0, 0)); GL.Vertex3(1, 0, 0); GL.End(); GL.PopMatrix(); } } }