UniversalAdditionalLightData.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. using System;
  2. namespace UnityEngine.Rendering.Universal
  3. {
  4. /// <summary>Light Layers.</summary>
  5. [Flags]
  6. public enum LightLayerEnum
  7. {
  8. /// <summary>The light will no affect any object.</summary>
  9. Nothing = 0, // Custom name for "Nothing" option
  10. /// <summary>Light Layer 0.</summary>
  11. LightLayerDefault = 1 << 0,
  12. /// <summary>Light Layer 1.</summary>
  13. LightLayer1 = 1 << 1,
  14. /// <summary>Light Layer 2.</summary>
  15. LightLayer2 = 1 << 2,
  16. /// <summary>Light Layer 3.</summary>
  17. LightLayer3 = 1 << 3,
  18. /// <summary>Light Layer 4.</summary>
  19. LightLayer4 = 1 << 4,
  20. /// <summary>Light Layer 5.</summary>
  21. LightLayer5 = 1 << 5,
  22. /// <summary>Light Layer 6.</summary>
  23. LightLayer6 = 1 << 6,
  24. /// <summary>Light Layer 7.</summary>
  25. LightLayer7 = 1 << 7,
  26. /// <summary>Everything.</summary>
  27. Everything = 0xFF, // Custom name for "Everything" option
  28. }
  29. /// <summary>
  30. /// Contains extension methods for Light class.
  31. /// </summary>
  32. public static class LightExtensions
  33. {
  34. /// <summary>
  35. /// Universal Render Pipeline exposes additional light data in a separate component.
  36. /// This method returns the additional data component for the given light or create one if it doesn't exist yet.
  37. /// </summary>
  38. /// <param name="light"></param>
  39. /// <returns>The <c>UniversalAdditionalLightData</c> for this light.</returns>
  40. /// <see cref="UniversalAdditionalLightData"/>
  41. public static UniversalAdditionalLightData GetUniversalAdditionalLightData(this Light light)
  42. {
  43. var gameObject = light.gameObject;
  44. bool componentExists = gameObject.TryGetComponent<UniversalAdditionalLightData>(out var lightData);
  45. if (!componentExists)
  46. lightData = gameObject.AddComponent<UniversalAdditionalLightData>();
  47. return lightData;
  48. }
  49. }
  50. [DisallowMultipleComponent]
  51. [RequireComponent(typeof(Light))]
  52. [URPHelpURL("universal-additional-light-data")]
  53. public class UniversalAdditionalLightData : MonoBehaviour, IAdditionalData
  54. {
  55. // Version 0 means serialized data before the version field.
  56. [SerializeField] int m_Version = 1;
  57. internal int version
  58. {
  59. get => m_Version;
  60. }
  61. [Tooltip("Controls if light Shadow Bias parameters use pipeline settings.")]
  62. [SerializeField] bool m_UsePipelineSettings = true;
  63. public bool usePipelineSettings
  64. {
  65. get { return m_UsePipelineSettings; }
  66. set { m_UsePipelineSettings = value; }
  67. }
  68. public static readonly int AdditionalLightsShadowResolutionTierCustom = -1;
  69. public static readonly int AdditionalLightsShadowResolutionTierLow = 0;
  70. public static readonly int AdditionalLightsShadowResolutionTierMedium = 1;
  71. public static readonly int AdditionalLightsShadowResolutionTierHigh = 2;
  72. public static readonly int AdditionalLightsShadowDefaultResolutionTier = AdditionalLightsShadowResolutionTierHigh;
  73. public static readonly int AdditionalLightsShadowDefaultCustomResolution = 128;
  74. public static readonly int AdditionalLightsShadowMinimumResolution = 128;
  75. [Tooltip("Controls if light shadow resolution uses pipeline settings.")]
  76. [SerializeField] int m_AdditionalLightsShadowResolutionTier = AdditionalLightsShadowDefaultResolutionTier;
  77. public int additionalLightsShadowResolutionTier
  78. {
  79. get { return m_AdditionalLightsShadowResolutionTier; }
  80. }
  81. // The layer(s) this light belongs too.
  82. [SerializeField] LightLayerEnum m_LightLayerMask = LightLayerEnum.LightLayerDefault;
  83. public LightLayerEnum lightLayerMask
  84. {
  85. get { return m_LightLayerMask; }
  86. set { m_LightLayerMask = value; }
  87. }
  88. [SerializeField] bool m_CustomShadowLayers = false;
  89. // if enabled, shadowLayerMask use the same settings as lightLayerMask.
  90. public bool customShadowLayers
  91. {
  92. get { return m_CustomShadowLayers; }
  93. set { m_CustomShadowLayers = value; }
  94. }
  95. // The layer(s) used for shadow casting.
  96. [SerializeField] LightLayerEnum m_ShadowLayerMask = LightLayerEnum.LightLayerDefault;
  97. public LightLayerEnum shadowLayerMask
  98. {
  99. get { return m_ShadowLayerMask; }
  100. set { m_ShadowLayerMask = value; }
  101. }
  102. [Tooltip("Controls the size of the cookie mask currently assigned to the light.")]
  103. [SerializeField] Vector2 m_LightCookieSize = Vector2.one;
  104. public Vector2 lightCookieSize
  105. {
  106. get => m_LightCookieSize;
  107. set => m_LightCookieSize = value;
  108. }
  109. [Tooltip("Controls the offset of the cookie mask currently assigned to the light.")]
  110. [SerializeField] Vector2 m_LightCookieOffset = Vector2.zero;
  111. public Vector2 lightCookieOffset
  112. {
  113. get => m_LightCookieOffset;
  114. set => m_LightCookieOffset = value;
  115. }
  116. }
  117. }