using System;
namespace UnityEngine.Rendering.Universal
{
/// Light Layers.
[Flags]
public enum LightLayerEnum
{
/// The light will no affect any object.
Nothing = 0, // Custom name for "Nothing" option
/// Light Layer 0.
LightLayerDefault = 1 << 0,
/// Light Layer 1.
LightLayer1 = 1 << 1,
/// Light Layer 2.
LightLayer2 = 1 << 2,
/// Light Layer 3.
LightLayer3 = 1 << 3,
/// Light Layer 4.
LightLayer4 = 1 << 4,
/// Light Layer 5.
LightLayer5 = 1 << 5,
/// Light Layer 6.
LightLayer6 = 1 << 6,
/// Light Layer 7.
LightLayer7 = 1 << 7,
/// Everything.
Everything = 0xFF, // Custom name for "Everything" option
}
///
/// Contains extension methods for Light class.
///
public static class LightExtensions
{
///
/// Universal Render Pipeline exposes additional light data in a separate component.
/// This method returns the additional data component for the given light or create one if it doesn't exist yet.
///
///
/// The UniversalAdditionalLightData for this light.
///
public static UniversalAdditionalLightData GetUniversalAdditionalLightData(this Light light)
{
var gameObject = light.gameObject;
bool componentExists = gameObject.TryGetComponent(out var lightData);
if (!componentExists)
lightData = gameObject.AddComponent();
return lightData;
}
}
[DisallowMultipleComponent]
[RequireComponent(typeof(Light))]
[URPHelpURL("universal-additional-light-data")]
public class UniversalAdditionalLightData : MonoBehaviour, IAdditionalData
{
// Version 0 means serialized data before the version field.
[SerializeField] int m_Version = 1;
internal int version
{
get => m_Version;
}
[Tooltip("Controls if light Shadow Bias parameters use pipeline settings.")]
[SerializeField] bool m_UsePipelineSettings = true;
public bool usePipelineSettings
{
get { return m_UsePipelineSettings; }
set { m_UsePipelineSettings = value; }
}
public static readonly int AdditionalLightsShadowResolutionTierCustom = -1;
public static readonly int AdditionalLightsShadowResolutionTierLow = 0;
public static readonly int AdditionalLightsShadowResolutionTierMedium = 1;
public static readonly int AdditionalLightsShadowResolutionTierHigh = 2;
public static readonly int AdditionalLightsShadowDefaultResolutionTier = AdditionalLightsShadowResolutionTierHigh;
public static readonly int AdditionalLightsShadowDefaultCustomResolution = 128;
public static readonly int AdditionalLightsShadowMinimumResolution = 128;
[Tooltip("Controls if light shadow resolution uses pipeline settings.")]
[SerializeField] int m_AdditionalLightsShadowResolutionTier = AdditionalLightsShadowDefaultResolutionTier;
public int additionalLightsShadowResolutionTier
{
get { return m_AdditionalLightsShadowResolutionTier; }
}
// The layer(s) this light belongs too.
[SerializeField] LightLayerEnum m_LightLayerMask = LightLayerEnum.LightLayerDefault;
public LightLayerEnum lightLayerMask
{
get { return m_LightLayerMask; }
set { m_LightLayerMask = value; }
}
[SerializeField] bool m_CustomShadowLayers = false;
// if enabled, shadowLayerMask use the same settings as lightLayerMask.
public bool customShadowLayers
{
get { return m_CustomShadowLayers; }
set { m_CustomShadowLayers = value; }
}
// The layer(s) used for shadow casting.
[SerializeField] LightLayerEnum m_ShadowLayerMask = LightLayerEnum.LightLayerDefault;
public LightLayerEnum shadowLayerMask
{
get { return m_ShadowLayerMask; }
set { m_ShadowLayerMask = value; }
}
[Tooltip("Controls the size of the cookie mask currently assigned to the light.")]
[SerializeField] Vector2 m_LightCookieSize = Vector2.one;
public Vector2 lightCookieSize
{
get => m_LightCookieSize;
set => m_LightCookieSize = value;
}
[Tooltip("Controls the offset of the cookie mask currently assigned to the light.")]
[SerializeField] Vector2 m_LightCookieOffset = Vector2.zero;
public Vector2 lightCookieOffset
{
get => m_LightCookieOffset;
set => m_LightCookieOffset = value;
}
float m_Intensity;
///
/// Get/Set the intensity of the light using the current light unit.
///
public float intensity
{
get => m_Intensity;
set
{
if (m_Intensity == value)
return;
m_Intensity = Mathf.Clamp(value, 0, float.MaxValue);
// UpdateLightIntensity();
}
}
public bool useVolumetric = true;
[Range(0.0f, 16.0f), SerializeField]
float m_VolumetricDimmer = 1.0f;
///
/// Get/Set the light dimmer / multiplier on volumetric effects, between 0 and 16.
///
public float volumetricDimmer
{
get => useVolumetric ? m_VolumetricDimmer : 0.0f;
set
{
if (m_VolumetricDimmer == value)
return;
m_VolumetricDimmer = Mathf.Clamp(value, 0.0f, 16.0f);
//if (lightEntity.valid)
// HDLightRenderDatabase.instance.EditLightDataAsRef(lightEntity).volumetricDimmer = m_VolumetricDimmer;
}
}
}
}