-
Notifications
You must be signed in to change notification settings - Fork 13
/
Bloom.cs
36 lines (31 loc) · 1.24 KB
/
Bloom.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
using UnityEngine;
public class Bloom : MonoBehaviour
{
public Shader shader;
public int downSample = 2;
public int iteration = 5;
public float threshold = 0;
private void OnRenderImage(RenderTexture src, RenderTexture dest)
{
Material material = new Material(shader);
int width = src.width/downSample;
int height = src.height/downSample;
var brightArea = RenderTexture.GetTemporary(width, height, 0);
brightArea.filterMode = FilterMode.Bilinear;
material.SetFloat("threshold",threshold);
Graphics.Blit(src, brightArea, material, 0);
for (int i = 0; i < iteration; i++)
{
var temp = RenderTexture.GetTemporary(width, height, 0);
Graphics.Blit(brightArea, temp, material, 2);
RenderTexture.ReleaseTemporary(brightArea);
brightArea = temp;
temp = RenderTexture.GetTemporary(width, height, 0);
Graphics.Blit(brightArea, temp, material, 3);
RenderTexture.ReleaseTemporary(brightArea);
brightArea = temp;
}
material.SetTexture("_Bloom", brightArea);
Graphics.Blit(src, dest, material, 1);
}
}