Advertisement
443eb9

Untitled

Aug 22nd, 2023
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.Rendering;
  3. using UnityEngine.Rendering.Universal;
  4.  
  5. public class PosterizeRenderPassFeature : ScriptableRendererFeature
  6. {
  7. class CustomRenderPass : ScriptableRenderPass
  8. {
  9. private Material _material;
  10. private RTHandle _tempHandle, _sourceHandle;
  11.  
  12. public CustomRenderPass(Material material)
  13. {
  14. _material = material;
  15. }
  16.  
  17. public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
  18. {
  19. _sourceHandle = renderingData.cameraData.renderer.cameraColorTargetHandle;
  20. }
  21.  
  22. public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
  23. {
  24. if (_material == null)
  25. return;
  26.  
  27. CommandBuffer cmd = CommandBufferPool.Get();
  28. var descriptor = renderingData.cameraData.cameraTargetDescriptor;
  29. descriptor.depthBufferBits = 0;
  30. RenderingUtils.ReAllocateIfNeeded(ref _tempHandle, descriptor, FilterMode.Bilinear);
  31.  
  32. Blit(cmd, _sourceHandle, _tempHandle, _material);
  33. Blit(cmd, _tempHandle, _sourceHandle);
  34.  
  35. context.ExecuteCommandBuffer(cmd);
  36. CommandBufferPool.Release(cmd);
  37. }
  38. }
  39.  
  40. private CustomRenderPass _pass;
  41. public Material material;
  42.  
  43. public override void Create()
  44. {
  45. _pass = new CustomRenderPass(material)
  46. {
  47. renderPassEvent = RenderPassEvent.AfterRenderingOpaques
  48. };
  49. }
  50.  
  51. public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
  52. {
  53. renderer.EnqueuePass(_pass);
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement