C#代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Bloom : MonoBehaviour {
//全屏泛光
public Material mat;
public int downscale;//分辨率
public int sampleScale = 1;//高斯模糊半径
public Color colorHold = Color.gray;//颜色阙值,提取高光点
public Color bloomColor = Color.white;//高光颜色
[Range(0.0f, 1.0f)]
public float bloomFactor = 0.5f;//高光权重值
private void OnRenderImage(RenderTexture source, RenderTexture destination)
{
RenderTexture temp1 = RenderTexture.GetTemporary(source.width >> downscale, source.height >> downscale, 0, source.format);
RenderTexture temp2 = RenderTexture.GetTemporary(source.width >> downscale, source.height >> downscale, 0, source.format);
Graphics.Blit(source, temp1);
mat.SetVector("_colorHold", colorHold);
Graphics.Blit(temp1, temp2, mat, 0);
mat.SetVector("_offset", new Vector4(0, sampleScale, 0, 0));
Graphics.Blit(temp2, temp1, mat, 1);
mat.SetVector("_offset", new Vector4(sampleScale, 0, 0, 0));
Graphics.Blit(temp1, temp2, mat, 1);
mat.SetTexture("_BlurTex", temp2);
mat.SetVector("_bloomColor", bloomColor);
mat.SetFloat("_bloomFactor", bloomFactor);
Graphics.Blit(source, destination