Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.Rendering;
- using UnityEngine.Rendering.Universal;
- public class PosterizeRenderPassFeature : ScriptableRendererFeature
- {
- class CustomRenderPass : ScriptableRenderPass
- {
- private Material _material;
- private RTHandle _tempHandle, _sourceHandle;
- private const string TempTex = "_TempTex";
- private readonly int _tempTexID = Shader.PropertyToID(TempTex);
- public CustomRenderPass(Material material)
- {
- _material = material;
- }
- public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
- {
- _sourceHandle = renderingData.cameraData.renderer.cameraColorTargetHandle;
- _tempHandle = RTHandles.Alloc(new RenderTargetIdentifier(TempTex), name: TempTex);
- }
- public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
- {
- if (_material == null)
- return;
- CommandBuffer cmd = CommandBufferPool.Get();
- var descriptor = renderingData.cameraData.cameraTargetDescriptor;
- descriptor.depthBufferBits = 0;
- cmd.GetTemporaryRT(_tempTexID, descriptor, FilterMode.Bilinear);
- Blit(cmd,_sourceHandle,_tempHandle,_material);
- Blit(cmd,_tempHandle,_sourceHandle);
- context.ExecuteCommandBuffer(cmd);
- CommandBufferPool.Release(cmd);
- }
- public override void OnCameraCleanup(CommandBuffer cmd)
- {
- _tempHandle.Release();
- }
- }
- private CustomRenderPass _pass;
- public Material material;
- public override void Create()
- {
- _pass = new CustomRenderPass(material)
- {
- renderPassEvent = RenderPassEvent.AfterRenderingOpaques
- };
- }
- public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
- {
- renderer.EnqueuePass(_pass);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement