TransparentSettingsPass.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. namespace UnityEngine.Rendering.Universal
  2. {
  3. /// <summary>
  4. /// Applies relevant settings before rendering transparent objects
  5. /// </summary>
  6. internal class TransparentSettingsPass : ScriptableRenderPass
  7. {
  8. bool m_shouldReceiveShadows;
  9. const string m_ProfilerTag = "Transparent Settings Pass";
  10. private static readonly ProfilingSampler m_ProfilingSampler = new ProfilingSampler(m_ProfilerTag);
  11. public TransparentSettingsPass(RenderPassEvent evt, bool shadowReceiveSupported)
  12. {
  13. base.profilingSampler = new ProfilingSampler(nameof(TransparentSettingsPass));
  14. renderPassEvent = evt;
  15. m_shouldReceiveShadows = shadowReceiveSupported;
  16. }
  17. public bool Setup(ref RenderingData renderingData)
  18. {
  19. // Currently we only need to enqueue this pass when the user
  20. // doesn't want transparent objects to receive shadows
  21. return !m_shouldReceiveShadows;
  22. }
  23. public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
  24. {
  25. // Get a command buffer...
  26. CommandBuffer cmd = CommandBufferPool.Get();
  27. using (new ProfilingScope(cmd, m_ProfilingSampler))
  28. {
  29. // Toggle light shadows enabled based on the renderer setting set in the constructor
  30. CoreUtils.SetKeyword(cmd, ShaderKeywordStrings.MainLightShadows, m_shouldReceiveShadows);
  31. CoreUtils.SetKeyword(cmd, ShaderKeywordStrings.MainLightShadowCascades, m_shouldReceiveShadows);
  32. CoreUtils.SetKeyword(cmd, ShaderKeywordStrings.AdditionalLightShadows, m_shouldReceiveShadows);
  33. }
  34. // Execute and release the command buffer...
  35. context.ExecuteCommandBuffer(cmd);
  36. CommandBufferPool.Release(cmd);
  37. }
  38. }
  39. }