49 lines
1.1 KiB
C#
49 lines
1.1 KiB
C#
using UnityEngine;
|
|
|
|
[AddComponentMenu("Image Effects/Frost")]
|
|
[ExecuteInEditMode]
|
|
public class FrostEffect : MonoBehaviour
|
|
{
|
|
public float FrostAmount = 0.5f;
|
|
|
|
public float EdgeSharpness = 1f;
|
|
|
|
public float minFrost;
|
|
|
|
public float maxFrost = 1f;
|
|
|
|
public float seethroughness = 0.2f;
|
|
|
|
public float distortion = 0.1f;
|
|
|
|
public Texture2D Frost;
|
|
|
|
public Texture2D FrostNormals;
|
|
|
|
public Shader Shader;
|
|
|
|
private Material material;
|
|
|
|
private void Awake()
|
|
{
|
|
material = new Material(Shader);
|
|
material.SetTexture("_BlendTex", Frost);
|
|
material.SetTexture("_BumpMap", FrostNormals);
|
|
}
|
|
|
|
private void OnRenderImage(RenderTexture source, RenderTexture destination)
|
|
{
|
|
if (!Application.isPlaying)
|
|
{
|
|
material.SetTexture("_BlendTex", Frost);
|
|
material.SetTexture("_BumpMap", FrostNormals);
|
|
EdgeSharpness = Mathf.Max(1f, EdgeSharpness);
|
|
}
|
|
material.SetFloat("_BlendAmount", Mathf.Clamp01(Mathf.Clamp01(FrostAmount) * (maxFrost - minFrost) + minFrost));
|
|
material.SetFloat("_EdgeSharpness", EdgeSharpness);
|
|
material.SetFloat("_SeeThroughness", seethroughness);
|
|
material.SetFloat("_Distortion", distortion);
|
|
Graphics.Blit(source, destination, material);
|
|
}
|
|
}
|