-
Notifications
You must be signed in to change notification settings - Fork 223
/
CAS.cs
53 lines (48 loc) · 1.47 KB
/
CAS.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using UnityEngine;
// Add script to camera and assign Hidden/CAS shader
public class CAS : MonoBehaviour
{
[Header("Contrast Adaptive Sharpening post processing effect")]
public Shader ContrastAdaptiveSharpeningShader;
[Range(0.0f, 1.0f)] public float Amount = 0.2f;
[Range(0.0f, 5.0f)] public float Radius = 1.0f;
public bool InvertY = false;
private Material _Material;
void Start()
{
if (ContrastAdaptiveSharpeningShader == null) ContrastAdaptiveSharpeningShader = Shader.Find("Hidden/CAS");
_Material = new Material(ContrastAdaptiveSharpeningShader);
}
void Blit(RenderTexture source, RenderTexture destination, Material mat)
{
RenderTexture.active = destination;
mat.SetTexture("_MainTex", source);
GL.PushMatrix();
GL.LoadOrtho();
GL.invertCulling = true;
mat.SetPass(0);
GL.Begin(GL.QUADS);
GL.MultiTexCoord2(0, 0.0f, 0.0f);
GL.Vertex3(0.0f, 0.0f, 0.0f);
GL.MultiTexCoord2(0, 1.0f, 0.0f);
GL.Vertex3(1.0f, 0.0f, 0.0f);
GL.MultiTexCoord2(0, 1.0f, 1.0f);
GL.Vertex3(1.0f, 1.0f, 0.0f);
GL.MultiTexCoord2(0, 0.0f, 1.0f);
GL.Vertex3(0.0f, 1.0f, 0.0f);
GL.End();
GL.invertCulling = false;
GL.PopMatrix();
}
void OnRenderImage (RenderTexture source, RenderTexture destination)
{
_Material.SetFloat("_Amount", Amount);
_Material.SetFloat("_Radius", Radius);
_Material.SetFloat("_InvertY", System.Convert.ToSingle(InvertY));
Blit (source, destination, _Material);
}
void OnDestroy()
{
if (_Material != null) Destroy(_Material);
}
}