ForwardRendererData.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #if UNITY_EDITOR
  2. using UnityEditor;
  3. using UnityEditor.ProjectWindowCallback;
  4. #endif
  5. using System;
  6. using UnityEngine.Scripting.APIUpdating;
  7. namespace UnityEngine.Rendering.Universal
  8. {
  9. [Serializable, ReloadGroup, ExcludeFromPreset]
  10. [MovedFrom("UnityEngine.Rendering.LWRP")]
  11. public class ForwardRendererData : ScriptableRendererData
  12. {
  13. #if UNITY_EDITOR
  14. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1812")]
  15. internal class CreateForwardRendererAsset : EndNameEditAction
  16. {
  17. public override void Action(int instanceId, string pathName, string resourceFile)
  18. {
  19. var instance = CreateInstance<ForwardRendererData>();
  20. AssetDatabase.CreateAsset(instance, pathName);
  21. ResourceReloader.ReloadAllNullIn(instance, UniversalRenderPipelineAsset.packagePath);
  22. Selection.activeObject = instance;
  23. }
  24. }
  25. [MenuItem("Assets/Create/Rendering/Universal Render Pipeline/Forward Renderer", priority = CoreUtils.assetCreateMenuPriority2)]
  26. static void CreateForwardRendererData()
  27. {
  28. ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, CreateInstance<CreateForwardRendererAsset>(), "CustomForwardRendererData.asset", null, null);
  29. }
  30. #endif
  31. [Serializable, ReloadGroup]
  32. public sealed class ShaderResources
  33. {
  34. [Reload("Shaders/Utils/Blit.shader")]
  35. public Shader blitPS;
  36. [Reload("Shaders/Utils/CopyDepth.shader")]
  37. public Shader copyDepthPS;
  38. [Reload("Shaders/Utils/ScreenSpaceShadows.shader")]
  39. public Shader screenSpaceShadowPS;
  40. [Reload("Shaders/Utils/Sampling.shader")]
  41. public Shader samplingPS;
  42. [Reload("Shaders/Utils/FallbackError.shader")]
  43. public Shader fallbackErrorPS;
  44. }
  45. [Reload("Runtime/Data/PostProcessData.asset")]
  46. public PostProcessData postProcessData = null;
  47. public ShaderResources shaders = null;
  48. [SerializeField] LayerMask m_OpaqueLayerMask = -1;
  49. [SerializeField] LayerMask m_TransparentLayerMask = -1;
  50. [SerializeField] StencilStateData m_DefaultStencilState = new StencilStateData();
  51. [SerializeField] bool m_ShadowTransparentReceive = true;
  52. protected override ScriptableRenderer Create()
  53. {
  54. #if UNITY_EDITOR
  55. if (!Application.isPlaying)
  56. {
  57. ResourceReloader.TryReloadAllNullIn(this, UniversalRenderPipelineAsset.packagePath);
  58. ResourceReloader.TryReloadAllNullIn(postProcessData, UniversalRenderPipelineAsset.packagePath);
  59. }
  60. #endif
  61. return new ForwardRenderer(this);
  62. }
  63. /// <summary>
  64. /// Use this to configure how to filter opaque objects.
  65. /// </summary>
  66. public LayerMask opaqueLayerMask
  67. {
  68. get => m_OpaqueLayerMask;
  69. set
  70. {
  71. SetDirty();
  72. m_OpaqueLayerMask = value;
  73. }
  74. }
  75. /// <summary>
  76. /// Use this to configure how to filter transparent objects.
  77. /// </summary>
  78. public LayerMask transparentLayerMask
  79. {
  80. get => m_TransparentLayerMask;
  81. set
  82. {
  83. SetDirty();
  84. m_TransparentLayerMask = value;
  85. }
  86. }
  87. public StencilStateData defaultStencilState
  88. {
  89. get => m_DefaultStencilState;
  90. set
  91. {
  92. SetDirty();
  93. m_DefaultStencilState = value;
  94. }
  95. }
  96. /// <summary>
  97. /// True if transparent objects receive shadows.
  98. /// </summary>
  99. public bool shadowTransparentReceive
  100. {
  101. get => m_ShadowTransparentReceive;
  102. set
  103. {
  104. SetDirty();
  105. m_ShadowTransparentReceive = value;
  106. }
  107. }
  108. protected override void OnEnable()
  109. {
  110. base.OnEnable();
  111. // Upon asset creation, OnEnable is called and `shaders` reference is not yet initialized
  112. // We need to call the OnEnable for data migration when updating from old versions of UniversalRP that
  113. // serialized resources in a different format. Early returning here when OnEnable is called
  114. // upon asset creation is fine because we guarantee new assets get created with all resources initialized.
  115. if (shaders == null)
  116. return;
  117. #if UNITY_EDITOR
  118. ResourceReloader.TryReloadAllNullIn(this, UniversalRenderPipelineAsset.packagePath);
  119. ResourceReloader.TryReloadAllNullIn(postProcessData, UniversalRenderPipelineAsset.packagePath);
  120. #endif
  121. }
  122. }
  123. }