MaterialBlitFeature.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using UnityEngine;
  2. using UnityEngine.Rendering.Universal;
  3. namespace SicknessReduction.Visual.Rendering
  4. {
  5. public class MaterialBlitFeature : ScriptableRendererFeature
  6. {
  7. [System.Serializable]
  8. public class MyFeatureSettings
  9. {
  10. // we're free to put whatever we want here, public fields will be exposed in the inspector
  11. public bool IsEnabled = true;
  12. public RenderPassEvent WhenToInsert = RenderPassEvent.AfterRendering;
  13. public Material MaterialToBlit;
  14. }
  15. // MUST be named "settings" (lowercase) to be shown in the Render Features inspector
  16. public MyFeatureSettings settings = new MyFeatureSettings();
  17. RenderTargetHandle renderTextureHandle;
  18. MaterialBlitRenderPass myRenderPass;
  19. public override void Create()
  20. {
  21. myRenderPass = new MaterialBlitRenderPass(
  22. "Material Blit Render Pass",
  23. settings.WhenToInsert,
  24. settings.MaterialToBlit
  25. );
  26. }
  27. // called every frame once per camera
  28. public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
  29. {
  30. if (!settings.IsEnabled)
  31. {
  32. // we can do nothing this frame if we want
  33. return;
  34. }
  35. // Gather up and pass any extra information our pass will need.
  36. // In this case we're getting the camera's color buffer target
  37. var cameraColorTargetIdent = renderer.cameraColorTarget;
  38. myRenderPass.Setup(cameraColorTargetIdent);
  39. // Ask the renderer to add our pass.
  40. // Could queue up multiple passes and/or pick passes to use
  41. renderer.EnqueuePass(myRenderPass);
  42. }
  43. }
  44. }