TransparentSettingsPass.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. public TransparentSettingsPass(RenderPassEvent evt, bool shadowReceiveSupported)
  11. {
  12. renderPassEvent = evt;
  13. m_shouldReceiveShadows = shadowReceiveSupported;
  14. }
  15. public bool Setup(ref RenderingData renderingData)
  16. {
  17. // Currently we only need to enqueue this pass when the user
  18. // doesn't want transparent objects to receive shadows
  19. return !m_shouldReceiveShadows;
  20. }
  21. public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
  22. {
  23. // Get a command buffer...
  24. CommandBuffer cmd = CommandBufferPool.Get(m_ProfilerTag);
  25. // Toggle light shadows enabled based on the renderer setting set in the constructor
  26. CoreUtils.SetKeyword(cmd, ShaderKeywordStrings.MainLightShadows, m_shouldReceiveShadows);
  27. CoreUtils.SetKeyword(cmd, ShaderKeywordStrings.MainLightShadowCascades, m_shouldReceiveShadows);
  28. CoreUtils.SetKeyword(cmd, ShaderKeywordStrings.AdditionalLightShadows, m_shouldReceiveShadows);
  29. // Execute and release the command buffer...
  30. context.ExecuteCommandBuffer(cmd);
  31. CommandBufferPool.Release(cmd);
  32. }
  33. }
  34. }