MaterialBlitFeature.cs 1.8 KB

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