revival/game/Assets/Scripts/Rendering/BlendPass.cs

48 lines
1.6 KiB
C#
Raw Normal View History

2021-04-24 03:06:03 +02:00
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
public class BlendPass : ScriptableRenderPass
{
2021-04-26 00:44:43 +02:00
private GlitchFeature.Settings _settings;
2021-04-24 03:06:03 +02:00
private RenderTargetIdentifier _src;
private RenderTargetIdentifier _dest;
2021-04-26 00:44:43 +02:00
private int _temporaryRTID = Shader.PropertyToID("_TempRT");
private RenderTargetIdentifier _temp;
2021-04-24 03:06:03 +02:00
2021-04-26 00:44:43 +02:00
public BlendPass(GlitchFeature.Settings settings)
2021-04-24 03:06:03 +02:00
{
2021-04-26 00:44:43 +02:00
_settings = settings;
_src = new RenderTargetIdentifier(_settings.stencilTex);
_dest = new RenderTargetIdentifier(_settings.blendTex);
_temp = new RenderTargetIdentifier(_temporaryRTID);
2021-04-24 03:06:03 +02:00
}
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
var cmd = CommandBufferPool.Get();
2021-04-26 00:44:43 +02:00
cmd.GetTemporaryRT(_temporaryRTID, _settings.blendTex.descriptor);
2021-04-24 03:06:03 +02:00
// set properties on material
2021-04-26 00:44:43 +02:00
var blend = _settings.blendMat;
blend.SetFloat("_Sample", _settings.sample * Time.deltaTime);
blend.SetTexture("_BlendTex", _settings.blendTex);
2021-04-25 01:59:37 +02:00
// blend.SetFloat("_DeltaTime", Time.deltaTime);
2021-04-24 03:06:03 +02:00
2021-04-25 01:59:37 +02:00
// blend.SetTexture("_GlitchTex", Settings.glitchTex);
// blend.SetTexture("_BlendTex", Settings.blendTex);
2021-04-24 03:06:03 +02:00
2021-04-26 00:44:43 +02:00
cmd.Blit(_src,_temporaryRTID,blend);
cmd.Blit(_temporaryRTID, _dest);
2021-04-24 03:06:03 +02:00
context.ExecuteCommandBuffer(cmd);
}
public override void FrameCleanup(CommandBuffer cmd)
{
2021-04-26 00:44:43 +02:00
cmd.ReleaseTemporaryRT(_temporaryRTID);
2021-04-24 03:06:03 +02:00
}
}