You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.5 KiB
62 lines
1.5 KiB
|
6 years ago
|
using UnityEngine;
|
||
|
|
|
||
|
|
namespace UC
|
||
|
|
{
|
||
|
|
[ExecuteInEditMode]
|
||
|
|
[RequireComponent(typeof(Camera))]
|
||
|
|
[AddComponentMenu("Image Effects/Fade")]
|
||
|
|
public class ScreenSpaceFade : MonoBehaviour
|
||
|
|
{
|
||
|
|
public Color color;
|
||
|
|
[Range(0.0f, 1.0f)]
|
||
|
|
public float amount = 0f;
|
||
|
|
|
||
|
|
[SerializeField]
|
||
|
|
private Shader m_Shader;
|
||
|
|
public Shader shader
|
||
|
|
{
|
||
|
|
get
|
||
|
|
{
|
||
|
|
if (m_Shader == null)
|
||
|
|
m_Shader = Shader.Find("Hidden/ScreenSpaceFade");
|
||
|
|
|
||
|
|
return m_Shader;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
private Material m_Material;
|
||
|
|
public Material material
|
||
|
|
{
|
||
|
|
get
|
||
|
|
{
|
||
|
|
if (m_Material == null)
|
||
|
|
m_Material = ImageEffectHelper.CheckShaderAndCreateMaterial(shader);
|
||
|
|
|
||
|
|
return m_Material;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
private void OnEnable()
|
||
|
|
{
|
||
|
|
if (!ImageEffectHelper.IsSupported(shader, true, false, this))
|
||
|
|
enabled = false;
|
||
|
|
GetComponent<Camera>().depthTextureMode = DepthTextureMode.DepthNormals;
|
||
|
|
}
|
||
|
|
|
||
|
|
private void OnDisable()
|
||
|
|
{
|
||
|
|
if (m_Material != null)
|
||
|
|
DestroyImmediate(m_Material);
|
||
|
|
|
||
|
|
m_Material = null;
|
||
|
|
}
|
||
|
|
|
||
|
|
private void OnRenderImage(RenderTexture source, RenderTexture destination)
|
||
|
|
{
|
||
|
|
material.SetColor("blend_color", color);
|
||
|
|
material.SetFloat("amount", amount);
|
||
|
|
Graphics.Blit(source, destination, material);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|