using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[ExecuteInEditMode]
[AddComponentMenu("CameraGray")]
public class CameraGray : MonoBehaviour {
[Range(0, 1f)]
public float red = 0.299f;
[Range(0, 1f)]
public float green = 0.587f;
[Range(0, 1f)]
public float blue = 0.114f;
[Range(0, 1f)]
public float amount = 1.0f;
Shader shader;
Material material;
protected void OnRenderImage(RenderTexture src,RenderTexture des)
{
if (amount == 0f)
{
Graphics.Blit(src, des);
return;
}
material.SetVector("_Data",new Vector4(red,green,blue,amount));
Graphics.Blit(src, des,material);
}
protected void Start()
{
if(!SystemInfo.supportsImageEffects)
{
enabled = false;
return;
}
shader = Shader.Find("Custom/CameraGray");
if (!shader || !shader.isSupported)
{
enabled = false;
return;
}
material = new Material(shader);
}
}