-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathGaussianBlurImageEffect.cs
More file actions
36 lines (28 loc) · 966 Bytes
/
GaussianBlurImageEffect.cs
File metadata and controls
36 lines (28 loc) · 966 Bytes
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
using UnityEngine;
[RequireComponent(typeof(Camera)), ExecuteInEditMode, ImageEffectAllowedInSceneView]
public class GaussianBlurImageEffect : MonoBehaviour {
public Material material;
private int _Direction;
void Awake() {
_Direction = Shader.PropertyToID("_Direction");
}
void OnRenderImage(RenderTexture src, RenderTexture dest) {
var rt1 = RenderTexture.GetTemporary(src.width / 2, src.height / 2);
var rt2 = RenderTexture.GetTemporary(src.width / 2, src.height / 2);
var h = new Vector2(1, 0);
var v = new Vector2(0, 1);
// Scale Down
Graphics.Blit(src, rt1);
// Gaussian Blur
for (int i=0; i<3; i++) {
material.SetVector(_Direction, h);
Graphics.Blit(rt1, rt2, material);
material.SetVector(_Direction, v);
Graphics.Blit(rt2, rt1, material);
}
// Scale Up
Graphics.Blit(rt1, dest);
RenderTexture.ReleaseTemporary(rt2);
RenderTexture.ReleaseTemporary(rt1);
}
}