Нет описания
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. /// <summary>
  12. /// Class <c>Renderer2DData</c> contains resources for a <c>Renderer2D</c>.
  13. /// </summary>
  14. [Serializable, ReloadGroup, ExcludeFromPreset]
  15. [MovedFrom(true, "UnityEngine.Experimental.Rendering.Universal", "Unity.RenderPipelines.Universal.Runtime")]
  16. [HelpURL("https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@latest/index.html?subfolder=/manual/2DRendererData-overview.html")]
  17. public partial class Renderer2DData : ScriptableRendererData
  18. {
  19. internal enum Renderer2DDefaultMaterialType
  20. {
  21. Lit,
  22. Unlit,
  23. Custom
  24. }
  25. [SerializeField]
  26. TransparencySortMode m_TransparencySortMode = TransparencySortMode.Default;
  27. [SerializeField]
  28. Vector3 m_TransparencySortAxis = Vector3.up;
  29. [SerializeField]
  30. float m_HDREmulationScale = 1;
  31. [SerializeField, Range(0.01f, 1.0f)]
  32. float m_LightRenderTextureScale = 0.5f;
  33. [SerializeField, FormerlySerializedAs("m_LightOperations")]
  34. Light2DBlendStyle[] m_LightBlendStyles = null;
  35. [SerializeField]
  36. bool m_UseDepthStencilBuffer = true;
  37. [SerializeField]
  38. bool m_UseCameraSortingLayersTexture = false;
  39. [SerializeField]
  40. int m_CameraSortingLayersTextureBound = 0;
  41. [SerializeField]
  42. Downsampling m_CameraSortingLayerDownsamplingMethod = Downsampling.None;
  43. [SerializeField]
  44. uint m_MaxLightRenderTextureCount = 16;
  45. [SerializeField]
  46. uint m_MaxShadowRenderTextureCount = 1;
  47. [SerializeField]
  48. PostProcessData m_PostProcessData = null;
  49. /// <summary>
  50. /// HDR Emulation Scale allows platforms to use HDR lighting by compressing the number of expressible colors in exchange for extra intensity range.
  51. /// Scale describes this extra intensity range. Increasing this value too high may cause undesirable banding to occur.
  52. /// </summary>
  53. public float hdrEmulationScale => m_HDREmulationScale;
  54. internal float lightRenderTextureScale => m_LightRenderTextureScale;
  55. /// <summary>
  56. /// Returns a list Light2DBlendStyle
  57. /// </summary>
  58. public Light2DBlendStyle[] lightBlendStyles => m_LightBlendStyles;
  59. internal bool useDepthStencilBuffer => m_UseDepthStencilBuffer;
  60. internal PostProcessData postProcessData { get => m_PostProcessData; set { m_PostProcessData = value; } }
  61. internal TransparencySortMode transparencySortMode => m_TransparencySortMode;
  62. internal Vector3 transparencySortAxis => m_TransparencySortAxis;
  63. internal uint lightRenderTextureMemoryBudget => m_MaxLightRenderTextureCount;
  64. internal uint shadowRenderTextureMemoryBudget => m_MaxShadowRenderTextureCount;
  65. internal bool useCameraSortingLayerTexture => m_UseCameraSortingLayersTexture;
  66. internal int cameraSortingLayerTextureBound => m_CameraSortingLayersTextureBound;
  67. internal Downsampling cameraSortingLayerDownsamplingMethod => m_CameraSortingLayerDownsamplingMethod;
  68. /// <summary>
  69. /// Creates the instance of the Renderer2D.
  70. /// </summary>
  71. /// <returns>The instance of Renderer2D</returns>
  72. protected override ScriptableRenderer Create()
  73. {
  74. #if UNITY_EDITOR
  75. if (!Application.isPlaying)
  76. {
  77. ReloadAllNullProperties();
  78. }
  79. #endif
  80. return new Renderer2D(this);
  81. }
  82. internal void Dispose()
  83. {
  84. for (var i = 0; i < m_LightBlendStyles.Length; ++i)
  85. m_LightBlendStyles[i].renderTargetHandle?.Release();
  86. foreach(var mat in lightMaterials)
  87. CoreUtils.Destroy(mat.Value);
  88. lightMaterials.Clear();
  89. CoreUtils.Destroy(spriteSelfShadowMaterial);
  90. CoreUtils.Destroy(spriteUnshadowMaterial);
  91. CoreUtils.Destroy(geometrySelfShadowMaterial);
  92. CoreUtils.Destroy(geometryUnshadowMaterial);
  93. CoreUtils.Destroy(projectedShadowMaterial);
  94. CoreUtils.Destroy(projectedUnshadowMaterial);
  95. }
  96. /// <summary>
  97. /// OnEnable implementation.
  98. /// </summary>
  99. protected override void OnEnable()
  100. {
  101. base.OnEnable();
  102. for (var i = 0; i < m_LightBlendStyles.Length; ++i)
  103. {
  104. m_LightBlendStyles[i].renderTargetHandleId = Shader.PropertyToID($"_ShapeLightTexture{i}");
  105. m_LightBlendStyles[i].renderTargetHandle = RTHandles.Alloc(m_LightBlendStyles[i].renderTargetHandleId, $"_ShapeLightTexture{i}");
  106. }
  107. geometrySelfShadowMaterial = null;
  108. geometryUnshadowMaterial = null;
  109. spriteSelfShadowMaterial = null;
  110. spriteUnshadowMaterial = null;
  111. projectedShadowMaterial = null;
  112. projectedUnshadowMaterial = null;
  113. }
  114. // transient data
  115. internal Dictionary<uint, Material> lightMaterials { get; } = new Dictionary<uint, Material>();
  116. internal Material spriteSelfShadowMaterial { get; set; }
  117. internal Material spriteUnshadowMaterial { get; set; }
  118. internal Material geometrySelfShadowMaterial { get; set; }
  119. internal Material geometryUnshadowMaterial { get; set; }
  120. internal Material projectedShadowMaterial { get; set; }
  121. internal Material projectedUnshadowMaterial { get; set; }
  122. internal RTHandle normalsRenderTarget;
  123. internal RTHandle cameraSortingLayerRenderTarget;
  124. // this shouldn've been in RenderingData along with other cull results
  125. internal ILight2DCullResult lightCullResult { get; set; }
  126. }
  127. }