Files
2026-02-21 16:45:37 +08:00

52 lines
1.2 KiB
C#

using UnityEngine;
[AddComponentMenu("Image Effects/Rain/ShowerEffect")]
[ExecuteInEditMode]
public class ShowerEffect : MonoBehaviour
{
private Material mat;
public Shader shader;
public Texture2D NormalMap;
[Range(0.01f, 1.5f)]
public float alpha = 0.03f;
[Range(0.05f, 2f)]
public float intensity = 1f;
[Range(0.05f, 2f)]
public float scrollSpeed = 0.5f;
private float scrollPos;
private void Awake()
{
if (!shader)
{
shader = Resources.Load("ShowerEffectShader", typeof(Shader)) as Shader;
}
if (!NormalMap)
{
NormalMap = Resources.Load("NormShower", typeof(Texture2D)) as Texture2D;
}
mat = new Material(shader);
mat.SetTexture("_NormalTex", NormalMap);
}
public void Update()
{
scrollPos += Time.deltaTime * scrollSpeed;
}
private void OnRenderImage(RenderTexture source, RenderTexture destination)
{
mat.SetTexture("_NormalTex", NormalMap);
mat.SetFloat("_Intensity", intensity);
mat.SetFloat("_Alpha", alpha);
mat.SetVector("_OffsetScale", new Vector4(0f, scrollPos, (float)Screen.width / (float)NormalMap.width, (float)Screen.height / (float)NormalMap.height));
Graphics.Blit(source, destination, mat);
}
}