SKYPRO_Renderer.cs 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using UnityEngine;
  2. using UnityEngine.Rendering;
  3. using UnityEngine.Rendering.Universal;
  4. public class SKYPRO_Renderer : ScriptableRendererFeature
  5. {
  6. class CustomRenderPass : ScriptableRenderPass
  7. {
  8. public RenderTargetIdentifier source;
  9. private Material _material;
  10. private RenderTargetHandle tempRenderTarget;
  11. public CustomRenderPass(Material mat)
  12. {
  13. _material = mat;
  14. tempRenderTarget.Init("_TemporaryColourTexture");
  15. }
  16. // This method is called before executing the render pass.
  17. // It can be used to configure render targets and their clear state. Also to create temporary render target textures.
  18. // When empty this render pass will render to the active camera render target.
  19. // You should never call CommandBuffer.SetRenderTarget. Instead call <c>ConfigureTarget</c> and <c>ConfigureClear</c>.
  20. // The render pipeline will ensure target setup and clearing happens in an performance manner.
  21. public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
  22. {
  23. }
  24. // Here you can implement the rendering logic.
  25. // Use <c>ScriptableRenderContext</c> to issue drawing commands or execute command buffers
  26. // https://docs.unity3d.com/ScriptReference/Rendering.ScriptableRenderContext.html
  27. // You don't have to call ScriptableRenderContext.submit, the render pipeline will call it at specific points in the pipeline.
  28. public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
  29. {
  30. CommandBuffer commandBuffer = CommandBufferPool.Get();
  31. commandBuffer.GetTemporaryRT(tempRenderTarget.id, renderingData.cameraData.cameraTargetDescriptor);
  32. Blit(commandBuffer, source, tempRenderTarget.Identifier(), _material);
  33. Blit(commandBuffer, tempRenderTarget.Identifier(), source);
  34. context.ExecuteCommandBuffer(commandBuffer);
  35. CommandBufferPool.Release(commandBuffer);
  36. }
  37. /// Cleanup any allocated resources that were created during the execution of this render pass.
  38. public override void FrameCleanup(CommandBuffer cmd)
  39. {
  40. }
  41. }
  42. [System.Serializable]
  43. public class _Settings
  44. {
  45. public Material material = null;
  46. }
  47. public _Settings settings = new _Settings();
  48. CustomRenderPass m_ScriptablePass;
  49. public override void Create()
  50. {
  51. m_ScriptablePass = new CustomRenderPass(settings.material);
  52. // Configures where the render pass should be injected.
  53. //m_ScriptablePass.renderPassEvent = RenderPassEvent.BeforeRenderingOpaques;
  54. //m_ScriptablePass.renderPassEvent = RenderPassEvent.AfterRenderingOpaques;
  55. //m_ScriptablePass.renderPassEvent = RenderPassEvent.BeforeRenderingSkybox;
  56. //m_ScriptablePass.renderPassEvent = RenderPassEvent.AfterRenderingSkybox;
  57. //m_ScriptablePass.renderPassEvent = RenderPassEvent.BeforeRenderingTransparents;
  58. m_ScriptablePass.renderPassEvent = RenderPassEvent.AfterRenderingTransparents;
  59. //m_ScriptablePass.renderPassEvent = RenderPassEvent.BeforeRenderingPostProcessing;
  60. //m_ScriptablePass.renderPassEvent = RenderPassEvent.AfterRenderingPostProcessing;
  61. }
  62. // Here you can inject one or multiple render passes in the renderer.
  63. // This method is called when setting up the renderer once per-camera.
  64. public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
  65. {
  66. m_ScriptablePass.source = renderer.cameraColorTarget;
  67. renderer.EnqueuePass(m_ScriptablePass);
  68. }
  69. }