|
|
|
|
|
|
using System; |
|
|
|
using System.Linq; |
|
|
|
using UnityEngine; |
|
|
|
using UnityEngine.Assertions; |
|
|
|
using UnityEngine.Experimental.Rendering; |
|
|
|
|
|
|
CoreEditorUtils.DrawSplitter(); |
|
|
|
EditorGUILayout.Space(); |
|
|
|
|
|
|
|
UpdateEmissiveMeshSize(); |
|
|
|
|
|
|
|
m_SerializedAdditionalShadowData.ApplyModifiedProperties(); |
|
|
|
m_SerializedAdditionalLightData.ApplyModifiedProperties(); |
|
|
|
settings.ApplyModifiedProperties(); |
|
|
|
|
|
|
|
|
|
|
if (EditorGUI.EndChangeCheck()) |
|
|
|
{ |
|
|
|
UpdateEmissiveMesh(); |
|
|
|
UpdateEmissiveMesh(); |
|
|
|
bool IsAreaLightShape(LightShape shape) |
|
|
|
{ |
|
|
|
return shape == LightShape.Rectangle || shape == LightShape.Line; |
|
|
|
} |
|
|
|
|
|
|
|
Debug.Log("heavy operation"); |
|
|
|
bool showEmissiveMesh = IsAreaLightShape(m_LightShape) && m_LightShape != LightShape.Line && m_AdditionalLightData.showEmissiveMesh.boolValue; |
|
|
|
|
|
|
|
if (lightData.showEmissiveMesh) |
|
|
|
if (showEmissiveMesh) |
|
|
|
{ |
|
|
|
if (emissiveMeshRenderer == null) |
|
|
|
emissiveMeshRenderer = lightGameObject.AddComponent<MeshRenderer>(); |
|
|
|
|
|
|
DestroyImmediate(emissiveMeshRenderer); |
|
|
|
if (emissiveMeshFilter != null) |
|
|
|
DestroyImmediate(emissiveMeshFilter); |
|
|
|
|
|
|
|
// Skip to the next light
|
|
|
|
continue; |
|
|
|
if (lightData.showEmissiveMesh) |
|
|
|
float areaLightIntensity = 0; |
|
|
|
|
|
|
|
// Update Mesh emissive value
|
|
|
|
switch (m_LightShape) |
|
|
|
// Update Mesh emissive value
|
|
|
|
case LightShape.Rectangle: |
|
|
|
emissiveMeshFilter.mesh = AssetDatabase.LoadAssetAtPath< Mesh >(HDEditorUtils.GetHDRenderPipelinePath() + "RenderPipelineResources/Quad.FBX"); |
|
|
|
lightGameObject.transform.localScale = new Vector3(m_AdditionalLightData.shapeWidth.floatValue, m_AdditionalLightData.shapeHeight.floatValue, 0); |
|
|
|
areaLightIntensity = LightUtils.ConvertRectLightIntensity( |
|
|
|
settings.intensity.floatValue, |
|
|
|
m_AdditionalLightData.shapeWidth.floatValue, |
|
|
|
m_AdditionalLightData.shapeHeight.floatValue); |
|
|
|
break; |
|
|
|
default: |
|
|
|
break; |
|
|
|
|
|
|
|
if (emissiveMeshRenderer.sharedMaterial == null) |
|
|
|
emissiveMeshRenderer.material = new Material(Shader.Find("HDRenderPipeline/Unlit")); |
|
|
|
|
|
|
|
emissiveMeshRenderer.sharedMaterial.SetColor("_UnlitColor", Color.black); |
|
|
|
emissiveMeshRenderer.sharedMaterial.SetColor("_EmissiveColor", settings.color.colorValue * areaLightIntensity); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// This function updates the area light size when the local scale of the gameobject changes
|
|
|
|
void UpdateEmissiveMeshSize() |
|
|
|
{ |
|
|
|
// Early exit if the light type is not an area
|
|
|
|
if (!IsAreaLightShape(m_LightShape) || target == null) |
|
|
|
return ; |
|
|
|
|
|
|
|
Vector3 lightSize = ((Light)target).transform.localScale; |
|
|
|
lightSize = Vector3.Max(Vector3.one * k_MinAreaWidth, lightSize); |
|
|
|
|
|
|
|
switch (m_LightShape) |
|
|
|
{ |
|
|
|
case LightShape.Rectangle: |
|
|
|
m_AdditionalLightData.shapeWidth.floatValue = lightSize.x; |
|
|
|
m_AdditionalLightData.shapeHeight.floatValue = lightSize.y; |
|
|
|
break; |
|
|
|
default: |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void DrawLightSettings() |
|
|
|
{ |
|
|
|
EditorGUI.BeginChangeCheck(); |
|
|
|
if (EditorGUI.EndChangeCheck()) |
|
|
|
UpdateEmissiveMesh(); |
|
|
|
|
|
|
|
EditorGUI.BeginChangeCheck(); |
|
|
|
|
|
|
|
|
|
|
if (EditorGUI.EndChangeCheck()) |
|
|
|
{ |
|
|
|
UpdateLightIntensity(); |
|
|
|
UpdateEmissiveMesh(); |
|
|
|
} |
|
|
|
|
|
|
|
settings.DrawBounceIntensity(); |
|
|
|
|
|
|
EditorGUI.BeginChangeCheck(); // For GI we need to detect any change on additional data and call SetLightDirty
|
|
|
|
|
|
|
|
// No cookie with area light (maybe in future textured area light ?)
|
|
|
|
if (m_LightShape != LightShape.Rectangle && m_LightShape != LightShape.Line) |
|
|
|
if (!IsAreaLightShape(m_LightShape)) |
|
|
|
{ |
|
|
|
settings.DrawCookie(); |
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Emissive mesh for area light only
|
|
|
|
if (m_LightShape == LightShape.Rectangle) |
|
|
|
if (IsAreaLightShape(m_LightShape)) |
|
|
|
{ |
|
|
|
EditorGUI.BeginChangeCheck(); |
|
|
|
EditorGUILayout.PropertyField(m_AdditionalLightData.showEmissiveMesh); |
|
|
|