97 lines
2.5 KiB
C#
97 lines
2.5 KiB
C#
using Thousandto.Launcher.ExternalLibs;
|
|
using UnityEngine;
|
|
|
|
namespace AmplifyBloom
|
|
{
|
|
//用于区分效果处理的脚本,需要挂在摄像机上
|
|
public class CheckAmpilfyBloom: MonoBehaviour
|
|
{
|
|
public AmplifyBloomBase BloomComponent;
|
|
|
|
public Shader AddTextureShader;
|
|
|
|
private RenderTexture _rt;
|
|
private Material _mat;
|
|
|
|
private void InitMaterial(int rtW, int rtH, RenderTextureFormat format)
|
|
{
|
|
if (_rt == null)
|
|
{
|
|
_rt = RenderTexture.GetTemporary(rtW, rtH, 16, format);
|
|
_rt.antiAliasing = 1;
|
|
_rt.name = "RenderTexture3";
|
|
}
|
|
if (_mat == null)
|
|
{
|
|
if(AddTextureShader == null) AddTextureShader = ShaderFactory.Find("Hidden/Ares/Amplify/AddTexture");
|
|
if (AddTextureShader != null)
|
|
{
|
|
_mat = new Material(AddTextureShader);
|
|
_mat.SetTexture("_EffectTex", _rt);
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError("没有找到Shader::Hidden/Ares/Amplify/AddTexture");
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
if (BloomComponent != null)
|
|
{
|
|
BloomComponent.gameObject.SetActive(true);
|
|
}
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
if (BloomComponent != null)
|
|
{
|
|
BloomComponent.TargetTexture = null;
|
|
BloomComponent.gameObject.SetActive(false);
|
|
}
|
|
|
|
if (_rt != null)
|
|
{
|
|
RenderTexture.ReleaseTemporary(_rt);
|
|
_rt = null;
|
|
}
|
|
|
|
if (_mat != null)
|
|
{
|
|
Destroy(_mat);
|
|
_mat = null;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
private void OnRenderImage(RenderTexture source, RenderTexture destination)
|
|
{
|
|
if (BloomComponent != null)
|
|
{
|
|
if (_rt == null)
|
|
{
|
|
InitMaterial(source.width, source.height, source.format);
|
|
}
|
|
|
|
if (_rt != null)
|
|
{
|
|
BloomComponent.TargetTexture = _rt;
|
|
}
|
|
|
|
if (_mat != null)
|
|
{
|
|
Graphics.Blit(source, destination, _mat);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Graphics.Blit(source, destination);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|