public SerializedProperty maxSmoothness ;
public SerializedProperty applyRangeAttenuation ;
public SerializedProperty volumetricDimmer ;
public SerializedProperty show EmissiveMesh;
public SerializedProperty displayAreaLight EmissiveMesh;
// Editor stuff
public SerializedProperty useOldInspector ;
LightShape m_LightShape ;
HDAdditionalLightData [ ] m_AdditionalLightDatas ;
AdditionalShadowData [ ] m_AdditionalShao dowDatas ;
AdditionalShadowData [ ] m_AdditionalShadowDatas ;
Vector3 m_OldLightSize ;
bool m_UpdateEmissiveMesh ;
Vector3 m_OldArea LightSize ;
bool m_UpdateAreaLight EmissiveMesh ;
protected override void OnEnable ( )
{
m_AdditionalLightDatas = CoreEditorUtils . GetAdditionalData < HDAdditionalLightData > ( targets , HDAdditionalLightData . InitDefaultHDAdditionalLightData ) ;
m_AdditionalShao dowDatas = CoreEditorUtils . GetAdditionalData < AdditionalShadowData > ( targets , HDAdditionalShadowData . InitDefaultHDAdditionalShadowData ) ;
m_AdditionalShadowDatas = CoreEditorUtils . GetAdditionalData < AdditionalShadowData > ( targets , HDAdditionalShadowData . InitDefaultHDAdditionalShadowData ) ;
m_SerializedAdditionalShadowData = new SerializedObject ( m_AdditionalShao dowDatas ) ;
m_SerializedAdditionalShadowData = new SerializedObject ( m_AdditionalShadowDatas ) ;
using ( var o = new PropertyFetcher < HDAdditionalLightData > ( m_SerializedAdditionalLightData ) )
m_AdditionalLightData = new SerializedLightData
spotInnerPercent = o . Find ( x = > x . m_InnerSpotPercent ) ,
lightDimmer = o . Find ( x = > x . lightDimmer ) ,
volumetricDimmer = o . Find ( x = > x . volumetricDimmer ) ,
show EmissiveMesh = o . Find ( x = > x . show EmissiveMesh) ,
displayAreaLight EmissiveMesh = o . Find ( x = > x . displayAreaLight EmissiveMesh) ,
fadeDistance = o . Find ( x = > x . fadeDistance ) ,
affectDiffuse = o . Find ( x = > x . affectDiffuse ) ,
affectSpecular = o . Find ( x = > x . affectSpecular ) ,
CoreEditorUtils . DrawSplitter ( ) ;
EditorGUILayout . Space ( ) ;
UpdateEmissiveMeshSize ( ) ;
UpdateAreaLight EmissiveMeshSize ( ) ;
if ( m_UpdateEmissiveMesh )
UpdateEmissiveMesh ( ) ;
if ( m_UpdateAreaLight EmissiveMesh )
UpdateAreaLight EmissiveMesh ( ) ;
}
void DrawFoldout ( SerializedProperty foldoutProperty , string title , Action func )
if ( EditorGUI . EndChangeCheck ( ) )
{
UpdateLightIntensity ( ) ;
m_UpdateEmissiveMesh = true ;
m_UpdateAreaLight EmissiveMesh = true ;
( ( Light ) target ) . SetLightDirty ( ) ; // Should be apply only to parameter that's affect GI, but make the code cleaner
}
}
return shape = = LightShape . Rectangle | | shape = = LightShape . Line ;
}
void UpdateEmissiveMesh ( )
void UpdateAreaLight EmissiveMesh ( )
{
foreach ( var lightData in m_AdditionalLightDatas )
{
Light light = lightGameObject . GetComponent < Light > ( ) ;
bool show EmissiveMesh = IsAreaLightShape ( m_LightShape ) & & m_LightShape ! = LightShape . Line & & m_AdditionalLightData . show EmissiveMesh. boolValue ;
bool displayAreaLight EmissiveMesh = IsAreaLightShape ( m_LightShape ) & & m_LightShape ! = LightShape . Line & & m_AdditionalLightData . displayAreaLight EmissiveMesh. boolValue ;
if ( show EmissiveMesh)
if ( displayAreaLight EmissiveMesh)
{
if ( emissiveMeshRenderer = = null )
emissiveMeshRenderer = lightGameObject . AddComponent < MeshRenderer > ( ) ;
continue ;
}
float areaLightIntensity = 0 ;
float areaLightIntensity = 0.0f ;
// Update Mesh emissive value
switch ( m_LightShape )
lightGameObject . transform . localScale = new Vector3 ( lightData . shapeWidth , lightData . shapeHeight , 0 ) ;
// Do the same conversion as for light intensity
light . intensity ,
m_AdditionalLightData . areaIntensity . floatValue ,
lightData . shapeWidth ,
lightData . shapeHeight ) ;
break ;
emissiveMeshRenderer . material = new Material ( Shader . Find ( "HDRenderPipeline/Unlit" ) ) ;
emissiveMeshRenderer . sharedMaterial . SetColor ( "_UnlitColor" , Color . black ) ;
emissiveMeshRenderer . sharedMaterial . SetColor ( "_EmissiveColor" , light . color * areaLightIntensity ) ;
// Note that we must use the light in linear RGB
emissiveMeshRenderer . sharedMaterial . SetColor ( "_EmissiveColor" , light . color . linear * areaLightIntensity ) ;
void UpdateEmissiveMeshSize ( )
void UpdateAreaLightEmissiveMeshSize ( )
{
// Early exit if the light type is not an area
if ( ! IsAreaLightShape ( m_LightShape ) | | target = = null | | targets . Length > 1 )
lightSize = Vector3 . Max ( Vector3 . one * k_MinAreaWidth , lightSize ) ;
if ( lightSize = = m_OldLightSize )
if ( lightSize = = m_OldArea LightSize )
return ;
switch ( m_LightShape )
}
UpdateLightIntensity ( ) ;
m_UpdateEmissiveMesh = true ;
m_UpdateAreaLight EmissiveMesh = true ;
m_OldLightSize = lightSize ;
m_OldArea LightSize = lightSize ;
}
// Caution: this function must match the one in HDAdditionalLightData.ConvertPhysicalLightIntensityToLightIntensity - any change need to be replicated
EditorGUI . BeginChangeCheck ( ) ;
settings . DrawColor ( ) ;
if ( EditorGUI . EndChangeCheck ( ) )
m_UpdateEmissiveMesh = true ;
m_UpdateAreaLight EmissiveMesh = true ;
EditorGUI . BeginChangeCheck ( ) ;
if ( EditorGUI . EndChangeCheck ( ) )
{
UpdateLightIntensity ( ) ;
m_UpdateEmissiveMesh = true ;
m_UpdateAreaLight EmissiveMesh = true ;
}
settings . DrawBounceIntensity ( ) ;
EditorGUI . indentLevel - - ;
}
}
// Emissive mesh for area light only
if ( IsAreaLightShape ( m_LightShape ) )
{
EditorGUI . BeginChangeCheck ( ) ;
EditorGUILayout . PropertyField ( m_AdditionalLightData . showEmissiveMesh , s_Styles . showEmissiveMesh ) ;
if ( EditorGUI . EndChangeCheck ( ) )
m_UpdateEmissiveMesh = true ;
}
if ( m_AdditionalLightData . showAdditionalSettings . boolValue )
{
EditorGUILayout . PropertyField ( m_AdditionalLightData . volumetricDimmer , s_Styles . volumetricDimmer ) ;
if ( m_LightShape ! = LightShape . Directional )
EditorGUILayout . PropertyField ( m_AdditionalLightData . applyRangeAttenuation , s_Styles . applyRangeAttenuation ) ;
// Emissive mesh for area light only
if ( IsAreaLightShape ( m_LightShape ) )
{
EditorGUI . BeginChangeCheck ( ) ;
EditorGUILayout . PropertyField ( m_AdditionalLightData . displayAreaLightEmissiveMesh , s_Styles . displayAreaLightEmissiveMesh ) ;
if ( EditorGUI . EndChangeCheck ( ) )
m_UpdateAreaLightEmissiveMesh = true ;
}
EditorGUI . indentLevel - - ;
}