TileDepthRangePass.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System;
  2. namespace UnityEngine.Rendering.Universal.Internal
  3. {
  4. /// <summary>
  5. /// Calculate min and max depth per screen tile for tiled-based deferred shading.
  6. /// </summary>
  7. internal class TileDepthRangePass : ScriptableRenderPass
  8. {
  9. DeferredLights m_DeferredLights;
  10. int m_PassIndex = 0;
  11. public TileDepthRangePass(RenderPassEvent evt, DeferredLights deferredLights, int passIndex)
  12. {
  13. base.profilingSampler = new ProfilingSampler(nameof(TileDepthRangePass));
  14. base.renderPassEvent = evt;
  15. m_DeferredLights = deferredLights;
  16. m_PassIndex = passIndex;
  17. }
  18. public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
  19. {
  20. RenderTargetHandle outputTex;
  21. RenderTextureDescriptor desc;
  22. if (m_PassIndex == 0 && m_DeferredLights.HasTileDepthRangeExtraPass())
  23. {
  24. int alignment = 1 << DeferredConfig.kTileDepthInfoIntermediateLevel;
  25. int depthInfoWidth = (m_DeferredLights.RenderWidth + alignment - 1) >> DeferredConfig.kTileDepthInfoIntermediateLevel;
  26. int depthInfoHeight = (m_DeferredLights.RenderHeight + alignment - 1) >> DeferredConfig.kTileDepthInfoIntermediateLevel;
  27. outputTex = m_DeferredLights.DepthInfoTexture;
  28. desc = new RenderTextureDescriptor(depthInfoWidth, depthInfoHeight, UnityEngine.Experimental.Rendering.GraphicsFormat.R32_UInt, 0);
  29. }
  30. else
  31. {
  32. int tileDepthRangeWidth = m_DeferredLights.GetTiler(0).TileXCount;
  33. int tileDepthRangeHeight = m_DeferredLights.GetTiler(0).TileYCount;
  34. outputTex = m_DeferredLights.TileDepthInfoTexture;
  35. desc = new RenderTextureDescriptor(tileDepthRangeWidth, tileDepthRangeHeight, UnityEngine.Experimental.Rendering.GraphicsFormat.R32_UInt, 0);
  36. }
  37. cmd.GetTemporaryRT(outputTex.id, desc, FilterMode.Point);
  38. base.ConfigureTarget(outputTex.Identifier());
  39. }
  40. /// <inheritdoc/>
  41. public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
  42. {
  43. if (m_PassIndex == 0)
  44. m_DeferredLights.ExecuteTileDepthInfoPass(context, ref renderingData);
  45. else
  46. m_DeferredLights.ExecuteDownsampleBitmaskPass(context, ref renderingData);
  47. }
  48. /// <inheritdoc/>
  49. public override void OnCameraCleanup(CommandBuffer cmd)
  50. {
  51. if (cmd == null)
  52. throw new ArgumentNullException("cmd");
  53. cmd.ReleaseTemporaryRT(m_DeferredLights.TileDepthInfoTexture.id);
  54. m_DeferredLights.TileDepthInfoTexture = RenderTargetHandle.CameraTarget;
  55. }
  56. }
  57. }