Renderer2DData.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine.Scripting.APIUpdating;
  4. using UnityEngine.Serialization;
  5. #if UNITY_EDITOR
  6. using UnityEditor;
  7. using UnityEditor.ProjectWindowCallback;
  8. #endif
  9. namespace UnityEngine.Rendering.Universal
  10. {
  11. [Serializable, ReloadGroup, ExcludeFromPreset]
  12. [MovedFrom("UnityEngine.Experimental.Rendering.Universal")]
  13. [HelpURL("https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@latest/index.html?subfolder=/manual/2DRendererData_overview.html")]
  14. public partial class Renderer2DData : ScriptableRendererData
  15. {
  16. internal enum Renderer2DDefaultMaterialType
  17. {
  18. Lit,
  19. Unlit,
  20. Custom
  21. }
  22. [SerializeField]
  23. TransparencySortMode m_TransparencySortMode = TransparencySortMode.Default;
  24. [SerializeField]
  25. Vector3 m_TransparencySortAxis = Vector3.up;
  26. [SerializeField]
  27. float m_HDREmulationScale = 1;
  28. [SerializeField, Range(0.01f, 1.0f)]
  29. float m_LightRenderTextureScale = 0.5f;
  30. [SerializeField, FormerlySerializedAs("m_LightOperations")]
  31. Light2DBlendStyle[] m_LightBlendStyles = null;
  32. [SerializeField]
  33. bool m_UseDepthStencilBuffer = true;
  34. [SerializeField]
  35. bool m_UseCameraSortingLayersTexture = false;
  36. [SerializeField]
  37. int m_CameraSortingLayersTextureBound = 0;
  38. [SerializeField]
  39. Downsampling m_CameraSortingLayerDownsamplingMethod = Downsampling.None;
  40. [SerializeField]
  41. uint m_MaxLightRenderTextureCount = 16;
  42. [SerializeField]
  43. uint m_MaxShadowRenderTextureCount = 1;
  44. [SerializeField, Reload("Shaders/2D/Light2D-Shape.shader")]
  45. Shader m_ShapeLightShader = null;
  46. [SerializeField, Reload("Shaders/2D/Light2D-Shape-Volumetric.shader")]
  47. Shader m_ShapeLightVolumeShader = null;
  48. [SerializeField, Reload("Shaders/2D/Light2D-Point.shader")]
  49. Shader m_PointLightShader = null;
  50. [SerializeField, Reload("Shaders/2D/Light2D-Point-Volumetric.shader")]
  51. Shader m_PointLightVolumeShader = null;
  52. [SerializeField, Reload("Shaders/Utils/Blit.shader")]
  53. Shader m_BlitShader = null;
  54. [SerializeField, Reload("Shaders/Utils/Sampling.shader")]
  55. Shader m_SamplingShader = null;
  56. [SerializeField, Reload("Shaders/2D/Shadow2D-Projected.shader")]
  57. Shader m_ProjectedShadowShader = null;
  58. [SerializeField, Reload("Shaders/2D/Shadow2D-Shadow-Sprite.shader")]
  59. Shader m_SpriteShadowShader = null;
  60. [SerializeField, Reload("Shaders/2D/Shadow2D-Unshadow-Sprite.shader")]
  61. Shader m_SpriteUnshadowShader = null;
  62. [SerializeField, Reload("Shaders/2D/Shadow2D-Unshadow-Geometry.shader")]
  63. Shader m_GeometryUnshadowShader = null;
  64. [SerializeField, Reload("Shaders/Utils/FallbackError.shader")]
  65. Shader m_FallbackErrorShader;
  66. [SerializeField]
  67. PostProcessData m_PostProcessData = null;
  68. [SerializeField, Reload("Runtime/2D/Data/Textures/FalloffLookupTexture.png")]
  69. [HideInInspector]
  70. private Texture2D m_FallOffLookup = null;
  71. /// <summary>
  72. /// HDR Emulation Scale allows platforms to use HDR lighting by compressing the number of expressible colors in exchange for extra intensity range.
  73. /// Scale describes this extra intensity range. Increasing this value too high may cause undesirable banding to occur.
  74. /// </summary>
  75. public float hdrEmulationScale => m_HDREmulationScale;
  76. internal float lightRenderTextureScale => m_LightRenderTextureScale;
  77. /// <summary>
  78. /// Returns a list Light2DBlendStyle
  79. /// </summary>
  80. public Light2DBlendStyle[] lightBlendStyles => m_LightBlendStyles;
  81. internal bool useDepthStencilBuffer => m_UseDepthStencilBuffer;
  82. internal Texture2D fallOffLookup => m_FallOffLookup;
  83. internal Shader shapeLightShader => m_ShapeLightShader;
  84. internal Shader shapeLightVolumeShader => m_ShapeLightVolumeShader;
  85. internal Shader pointLightShader => m_PointLightShader;
  86. internal Shader pointLightVolumeShader => m_PointLightVolumeShader;
  87. internal Shader blitShader => m_BlitShader;
  88. internal Shader samplingShader => m_SamplingShader;
  89. internal PostProcessData postProcessData { get => m_PostProcessData; set { m_PostProcessData = value; } }
  90. internal Shader spriteShadowShader => m_SpriteShadowShader;
  91. internal Shader spriteUnshadowShader => m_SpriteUnshadowShader;
  92. internal Shader geometryUnshadowShader => m_GeometryUnshadowShader;
  93. internal Shader projectedShadowShader => m_ProjectedShadowShader;
  94. internal TransparencySortMode transparencySortMode => m_TransparencySortMode;
  95. internal Vector3 transparencySortAxis => m_TransparencySortAxis;
  96. internal uint lightRenderTextureMemoryBudget => m_MaxLightRenderTextureCount;
  97. internal uint shadowRenderTextureMemoryBudget => m_MaxShadowRenderTextureCount;
  98. internal bool useCameraSortingLayerTexture => m_UseCameraSortingLayersTexture;
  99. internal int cameraSortingLayerTextureBound => m_CameraSortingLayersTextureBound;
  100. internal Downsampling cameraSortingLayerDownsamplingMethod => m_CameraSortingLayerDownsamplingMethod;
  101. protected override ScriptableRenderer Create()
  102. {
  103. #if UNITY_EDITOR
  104. if (!Application.isPlaying)
  105. {
  106. ReloadAllNullProperties();
  107. }
  108. #endif
  109. return new Renderer2D(this);
  110. }
  111. protected override void OnEnable()
  112. {
  113. base.OnEnable();
  114. for (var i = 0; i < m_LightBlendStyles.Length; ++i)
  115. {
  116. m_LightBlendStyles[i].renderTargetHandle.Init($"_ShapeLightTexture{i}");
  117. }
  118. normalsRenderTarget.Init("_NormalMap");
  119. shadowsRenderTarget.Init("_ShadowTex");
  120. spriteSelfShadowMaterial = null;
  121. spriteUnshadowMaterial = null;
  122. projectedShadowMaterial = null;
  123. stencilOnlyShadowMaterial = null;
  124. }
  125. // transient data
  126. internal Dictionary<uint, Material> lightMaterials { get; } = new Dictionary<uint, Material>();
  127. internal Material[] spriteSelfShadowMaterial { get; set; }
  128. internal Material[] spriteUnshadowMaterial { get; set; }
  129. internal Material[] geometryUnshadowMaterial { get; set; }
  130. internal Material[] projectedShadowMaterial { get; set; }
  131. internal Material[] stencilOnlyShadowMaterial { get; set; }
  132. internal bool isNormalsRenderTargetValid { get; set; }
  133. internal float normalsRenderTargetScale { get; set; }
  134. internal RenderTargetHandle normalsRenderTarget;
  135. internal RenderTargetHandle shadowsRenderTarget;
  136. internal RenderTargetHandle cameraSortingLayerRenderTarget;
  137. // this shouldn've been in RenderingData along with other cull results
  138. internal ILight2DCullResult lightCullResult { get; set; }
  139. }
  140. }