1
0

BokehFeature.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using UnityEngine;
  2. using UnityEngine.Rendering.Universal;
  3. namespace SicknessReduction.Visual.Rendering
  4. {
  5. public class BokehFeature : ScriptableRendererFeature
  6. {
  7. [System.Serializable]
  8. public class BokehFeatureSettings
  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 float maxCoc;
  14. public float focusDistance;
  15. public Material fragMaterial;
  16. }
  17. // MUST be named "settings" (lowercase) to be shown in the Render Features inspector
  18. public BokehFeatureSettings settings = new BokehFeatureSettings();
  19. RenderTargetHandle renderTextureHandle;
  20. BokehRenderPass myRenderPass;
  21. public override void Create()
  22. {
  23. myRenderPass = new BokehRenderPass(
  24. "Bokeh Render Pass",
  25. settings
  26. );
  27. }
  28. // called every frame once per camera
  29. public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
  30. {
  31. if (!settings.IsEnabled)
  32. {
  33. // we can do nothing this frame if we want
  34. return;
  35. }
  36. // Gather up and pass any extra information our pass will need.
  37. // In this case we're getting the camera's color buffer target
  38. var cameraColorTargetIdent = renderer.cameraColorTarget;
  39. myRenderPass.Setup(renderingData.cameraData.cameraTargetDescriptor, cameraColorTargetIdent);
  40. // Ask the renderer to add our pass.
  41. // Could queue up multiple passes and/or pick passes to use
  42. renderer.EnqueuePass(myRenderPass);
  43. }
  44. }
  45. }