} ;
public enum SpotLightShape { Cone , Pyramid , Box } ;
public enum LightUnit
{
Lumen ,
public const float currentVersion = 1.1f ;
[HideInInspector]
[FormerlySerializedAs("m_Version")]
public float version = currentVersion ;
// To be able to have correct default values for our lights and to also control the conversion of intensity from the light editor (so it is compatible with GI)
public const float k_DefaultDirectionalLightIntensity = Mathf . PI ; // In lux
public const float k_DefaultPunctualLightIntensity = 6 0 0.0f ; // In lumens
public const float k_DefaultAreaLightIntensity = 2 0 0.0f ; // In lumens
public float intensity
{
get { return displayLightIntensity ; }
public bool featuresFoldout = true ;
public bool showAdditionalSettings = false ;
public float displayLightIntensity ;
// Duplication of HDLightEditor.k_MinAreaWidth, maybe do something about that
const float k_MinAreaWidth = 0.01f ; // Provide a small size of 1cm for line light
return _light ;
}
}
void SetLightIntensity ( float intensity )
{
displayLightIntensity = intensity ;
}
else
m_Light . intensity = intensity ;
m_Light . SetLightDirty ( ) ; // Should be apply only to parameter that's affect GI, but make the code cleaner
}
{
case LightType . Directional :
m_Light . intensity = intensity ; // Alwas in lux
m_Light . intensity = intensity ; // Alway s in lux
break ;
case LightType . Point :
if ( lightUnit = = LightUnit . Candela )
break ;
case LightType . Spot :
if ( lightUnit = = LightUnit . Candela )
{
// When using candela, reflector don't have any effect. Our intensity is candela = lumens/steradian and the user
// provide desired value for an angle of 1 steradian.
else if ( enableSpotReflector )
}
else // lumen
if ( spotLightShape = = SpotLightShape . Cone )
if ( enableSpotReflector )
m_Light . intensity = LightUtils . ConvertSpotLightLumenToCandela ( intensity , m_Light . spotAngle * Mathf . Deg2Rad , true ) ;
}
else if ( spotLightShape = = SpotLightShape . Pyramid )
{
float angleA , angleB ;
LightUtils . CalculateAnglesForPyramid ( aspectRatio , m_Light . spotAngle ,
out angleA , out angleB ) ;
// If reflector is enabled all the lighting from the sphere is focus inside the solid angle of current shape
if ( spotLightShape = = SpotLightShape . Cone )
{
m_Light . intensity = LightUtils . ConvertSpotLightLumenToCandela ( intensity , m_Light . spotAngle * Mathf . Deg2Rad , true ) ;
}
else if ( spotLightShape = = SpotLightShape . Pyramid )
{
float angleA , angleB ;
LightUtils . CalculateAnglesForPyramid ( aspectRatio , m_Light . spotAngle * Mathf . Deg2Rad , out angleA , out angleB ) ;
m_Light . intensity = LightUtils . ConvertFrustrumLightLumenToCandela ( intensity , angleA , angleB ) ;
m_Light . intensity = LightUtils . ConvertFrustrumLightLumenToCandela ( intensity , angleA , angleB ) ;
}
else // Box shape, fallback to punctual light.
{
m_Light . intensity = LightUtils . ConvertPointLightLumenToCandela ( intensity ) ;
}
else // Box shape, fallback to punctual light.
else
// No reflector, angle act as occlusion of point light.
else // Reflector disabled, fallback to punctual light.
{
m_Light . intensity = LightUtils . ConvertPointLightLumenToCandela ( intensity ) ;
}
break ;
}
}
// Force to retre ive color light's m_UseColorTemperature because it's private
// Force to retrie ve color light's m_UseColorTemperature because it's private
bool useColorTemperature
public bool useColorTemperature
{
get
{
{
return IsAreaLight ( ( LightTypeExtent ) lightType . enumValueIndex ) ;
}
public void UpdateAreaLightEmissiveMesh ( )
{
MeshRenderer emissiveMeshRenderer = GetComponent < MeshRenderer > ( ) ;
// We don't have anything to do left if the dislay emissive mesh option is disabled
return ;
}
Vector3 lightSize ;
// Update light area size from GameObject transform scale if the transform have changed
else
lightSize = new Vector3 ( shapeWidth , shapeHeight , 0 ) ;
lightSize = Vector3 . Max ( Vector3 . one * k_MinAreaWidth , lightSize ) ;
m_Light . transform . localScale = lightSize ;
m_Light . areaSize = lightSize ;
case LightTypeExtent . Rectangle :
shapeWidth = lightSize . x ;
shapeHeight = lightSize . y ;
// If the light unit is in lumen, we need a convertion to get the good intensity value
if ( lightUnit = = LightUnit . Lumen )
{
if ( emissiveMeshRenderer . sharedMaterial = = null )
emissiveMeshRenderer . material = new Material ( Shader . Find ( "HDRenderPipeline/Unlit" ) ) ;
emissiveMeshRenderer . sharedMaterial . SetColor ( "_EmissiveColor" , m_Light . color . linear * areaLightIntensity * CorrelatedColorTemperatureToRGB ( m_Light . colorTemperature ) ) ;
emissiveMeshRenderer . sharedMaterial . SetColor ( "_EmissiveColor" , m_Light . color . linear * areaLightIntensity * LightUtils . CorrelatedColorTemperatureToRGB ( m_Light . colorTemperature ) ) ;
}
// Given a correlated color temperature (in Kelvin), estimate the RGB equivalent. Curve fit error is max 0.008.
Color CorrelatedColorTemperatureToRGB ( float temperature )
{
float r , g , b ;
// Temperature must fall between 1000 and 40000 degrees
// The fitting require to divide kelvin by 1000 (allow more precision)
float kelvin = Mathf . Clamp ( temperature , 1 0 0 0.0f , 4 0 0 0 0.0f ) / 1 0 0 0.0f ;
float kelvin2 = kelvin * kelvin ;
// Using 6570 as a pivot is an approximation, pivot point for red is around 6580 and for blue and green around 6560.
// Calculate each color in turn (Note, clamp is not really necessary as all value belongs to [0..1] but can help for extremum).
// Red
r = kelvin < 6.570f ? 1.0f : Mathf . Clamp ( ( 1.35651f + 0.216422f * kelvin + 0.000633715f * kelvin2 ) / ( - 3.24223f + 0.918711f * kelvin ) , 0.0f , 1.0f ) ;
// Green
g = kelvin < 6.570f ?
Mathf . Clamp ( ( - 3 9 9.809f + 4 1 4.271f * kelvin + 1 1 1.543f * kelvin2 ) / ( 2 7 7 9.24f + 1 6 4.143f * kelvin + 8 4.7356f * kelvin2 ) , 0.0f , 1.0f ) :
Mathf . Clamp ( ( 1 3 7 0.38f + 7 3 4.616f * kelvin + 0.689955f * kelvin2 ) / ( - 4 6 2 5.69f + 1 6 9 9.87f * kelvin ) , 0.0f , 1.0f ) ;
//Blue
b = kelvin > 6.570f ? 1.0f : Mathf . Clamp ( ( 3 4 8.963f - 5 2 3.53f * kelvin + 1 8 3.62f * kelvin2 ) / ( 2 8 4 8.82f - 2 1 4.52f * kelvin + 7 8.8614f * kelvin2 ) , 0.0f , 1.0f ) ;
return new Color ( r , g , b , 1.0f ) ;
}
#endif