浏览代码

Fix issue with light intensity not matching area emissive mesh intensity + some renaming

/main
Sebastien Lagarde 7 年前
当前提交
75993083
共有 3 个文件被更改,包括 38 次插入34 次删除
  1. 2
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/HDLightEditor.Styles.cs
  2. 67
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/HDLightEditor.cs
  3. 3
      com.unity.render-pipelines.high-definition/HDRP/Lighting/Light/HDAdditionalLightData.cs

2
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/HDLightEditor.Styles.cs


public readonly GUIContent shapeWidthBox = new GUIContent("Size X", "");
public readonly GUIContent shapeHeightBox = new GUIContent("Size Y", "");
public readonly GUIContent applyRangeAttenuation = new GUIContent("Apply Range Attenuation", "Allows disabling range attenuation. This is useful indoor (like a room) to avoid having to setup a large range for a light to get correct inverse square attenuation that may leak out of the indoor");
public readonly GUIContent showEmissiveMesh = new GUIContent("Show Emissive Mesh", "Generate an emissive mesh using the size, color and intensity of the light");
public readonly GUIContent displayAreaLightEmissiveMesh = new GUIContent("Display Emissive Mesh", "Generate an emissive mesh using the size, color and intensity of the area light");
public readonly GUIContent shape = new GUIContent("Type", "Specifies the current type of light. Possible types are Directional, Spot, Point, Rectangle and Line lights.");
public readonly GUIContent[] shapeNames;

67
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/HDLightEditor.cs


public SerializedProperty maxSmoothness;
public SerializedProperty applyRangeAttenuation;
public SerializedProperty volumetricDimmer;
public SerializedProperty showEmissiveMesh;
public SerializedProperty displayAreaLightEmissiveMesh;
// Editor stuff
public SerializedProperty useOldInspector;

LightShape m_LightShape;
HDAdditionalLightData[] m_AdditionalLightDatas;
AdditionalShadowData[] m_AdditionalShaodowDatas;
AdditionalShadowData[] m_AdditionalShadowDatas;
Vector3 m_OldLightSize;
bool m_UpdateEmissiveMesh;
Vector3 m_OldAreaLightSize;
bool m_UpdateAreaLightEmissiveMesh;
protected override void OnEnable()
{

m_AdditionalLightDatas = CoreEditorUtils.GetAdditionalData<HDAdditionalLightData>(targets, HDAdditionalLightData.InitDefaultHDAdditionalLightData);
m_AdditionalShaodowDatas = CoreEditorUtils.GetAdditionalData<AdditionalShadowData>(targets, HDAdditionalShadowData.InitDefaultHDAdditionalShadowData);
m_AdditionalShadowDatas = CoreEditorUtils.GetAdditionalData<AdditionalShadowData>(targets, HDAdditionalShadowData.InitDefaultHDAdditionalShadowData);
m_SerializedAdditionalShadowData = new SerializedObject(m_AdditionalShaodowDatas);
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),
showEmissiveMesh = o.Find(x => x.showEmissiveMesh),
displayAreaLightEmissiveMesh = o.Find(x => x.displayAreaLightEmissiveMesh),
fadeDistance = o.Find(x => x.fadeDistance),
affectDiffuse = o.Find(x => x.affectDiffuse),
affectSpecular = o.Find(x => x.affectSpecular),

CoreEditorUtils.DrawSplitter();
EditorGUILayout.Space();
UpdateEmissiveMeshSize();
UpdateAreaLightEmissiveMeshSize();
if (m_UpdateEmissiveMesh)
UpdateEmissiveMesh();
if (m_UpdateAreaLightEmissiveMesh)
UpdateAreaLightEmissiveMesh();
}
void DrawFoldout(SerializedProperty foldoutProperty, string title, Action func)

if (EditorGUI.EndChangeCheck())
{
UpdateLightIntensity();
m_UpdateEmissiveMesh = true;
m_UpdateAreaLightEmissiveMesh = 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 UpdateAreaLightEmissiveMesh()
{
foreach (var lightData in m_AdditionalLightDatas)
{

Light light = lightGameObject.GetComponent<Light>();
bool showEmissiveMesh = IsAreaLightShape(m_LightShape) && m_LightShape != LightShape.Line && m_AdditionalLightData.showEmissiveMesh.boolValue;
bool displayAreaLightEmissiveMesh = IsAreaLightShape(m_LightShape) && m_LightShape != LightShape.Line && m_AdditionalLightData.displayAreaLightEmissiveMesh.boolValue;
if (showEmissiveMesh)
if (displayAreaLightEmissiveMesh)
{
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_OldAreaLightSize)
return ;
switch (m_LightShape)

}
UpdateLightIntensity();
m_UpdateEmissiveMesh = true;
m_UpdateAreaLightEmissiveMesh = true;
m_OldLightSize = lightSize;
m_OldAreaLightSize = 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_UpdateAreaLightEmissiveMesh = true;
EditorGUI.BeginChangeCheck();

if (EditorGUI.EndChangeCheck())
{
UpdateLightIntensity();
m_UpdateEmissiveMesh = true;
m_UpdateAreaLightEmissiveMesh = 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--;
}

3
com.unity.render-pipelines.high-definition/HDRP/Lighting/Light/HDAdditionalLightData.cs


public bool featuresFoldout = true;
public bool showAdditionalSettings = false;
public bool showEmissiveMesh = false;
// When true, a mesh will be display to represent the area light (Can only be change in editor, component is added in Editor)
public bool displayAreaLightEmissiveMesh = false;
#if UNITY_EDITOR

正在加载...
取消
保存