浏览代码

Added an enum field to change the light intensity unit

/main
Antoine Lelievre 6 年前
当前提交
2828ae93
共有 3 个文件被更改,包括 146 次插入25 次删除
  1. 1
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/HDLightEditor.Styles.cs
  2. 83
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/HDLightEditor.cs
  3. 87
      com.unity.render-pipelines.high-definition/HDRP/Lighting/Light/HDAdditionalLightData.cs

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


public readonly GUIContent directionalIntensity = new GUIContent("Intensity (Lux)", "Illuminance of the directional light at ground level in lux.");
public readonly GUIContent punctualIntensity = new GUIContent("Intensity (Lumen)", "Luminous power of the light in lumen. Spotlight are considered as point light with barndoor so match intensity of a point light.");
public readonly GUIContent areaIntensity = new GUIContent("Intensity (Lumen)", "Luminous power of the light in lumen.");
public readonly GUIContent lightIntensity = new GUIContent("Intensity", "");
public readonly GUIContent maxSmoothness = new GUIContent("Max Smoothness", "Very low cost way of faking spherical area lighting. This will modify the roughness of the material lit. This is useful when the specular highlight is too small or too sharp.");
public readonly GUIContent affectDiffuse = new GUIContent("Affect Diffuse", "This will disable diffuse lighting for this light. Doesn't save performance, diffuse lighting is still computed.");

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


sealed class SerializedLightData
{
public SerializedProperty intensity;
public SerializedProperty directionalIntensity;
public SerializedProperty punctualIntensity;
public SerializedProperty areaIntensity;

public SerializedProperty maxSmoothness;
public SerializedProperty applyRangeAttenuation;
public SerializedProperty volumetricDimmer;
public SerializedProperty lightUnit;
// Editor stuff
public SerializedProperty useOldInspector;

//Disc,
}
enum LightUnits
{
Lumen,
Candela,
Lux,
Luminance,
}
enum DirectionalLightUnits
{
Lux = LightUnits.Lux,
}
enum AreaLightUnits
{
Lumen = LightUnits.Lumen,
Luminance = LightUnits.Luminance,
}
enum PunctualLightUnits
{
Lumen = LightUnits.Lumen,
Candela = LightUnits.Candela,
}
const float k_MinAreaWidth = 0.01f; // Provide a small size of 1cm for line light
// Used for UI only; the processing code must use LightTypeExtent and LightType

directionalIntensity = o.Find(x => x.directionalIntensity),
punctualIntensity = o.Find(x => x.punctualIntensity),
areaIntensity = o.Find(x => x.areaIntensity),
intensity = o.Find(x => x.editorLightIntensity),
lightUnit = o.Find(x => x.lightUnit),
fadeDistance = o.Find(x => x.fadeDistance),
affectDiffuse = o.Find(x => x.affectDiffuse),
affectSpecular = o.Find(x => x.affectSpecular),

showFeatures = o.Find(x => x.featuresFoldout),
showAdditionalSettings = o.Find(x => x.showAdditionalSettings)
};
// TODO: Review this once AdditionalShadowData is refactored
using (var o = new PropertyFetcher<AdditionalShadowData>(m_SerializedAdditionalShadowData))
m_AdditionalShadowData = new SerializedShadowData

// Caution: this function must match the one in HDAdditionalLightData.ConvertPhysicalLightIntensityToLightIntensity - any change need to be replicated
void UpdateLightIntensity()
{
//TOOD: TMP stuff, waiting for the emissive mesh to be merged
m_SerializedAdditionalLightData.ApplyModifiedProperties();
((Light)target).GetComponent<HDAdditionalLightData>().RefreshLightIntensity();
m_AdditionalLightData.directionalIntensity.floatValue = Mathf.Max(0, m_AdditionalLightData.directionalIntensity.floatValue);
/*m_AdditionalLightData.directionalIntensity.floatValue = Mathf.Max(0, m_AdditionalLightData.directionalIntensity.floatValue);
m_AdditionalLightData.punctualIntensity.floatValue = Mathf.Max(0, m_AdditionalLightData.punctualIntensity.floatValue);
m_AdditionalLightData.areaIntensity.floatValue = Mathf.Max(0, m_AdditionalLightData.areaIntensity.floatValue);

case LightShape.Line:
settings.intensity.floatValue = LightUtils.CalculateLineLightIntensity(m_AdditionalLightData.areaIntensity.floatValue, m_AdditionalLightData.shapeWidth.floatValue);
break;
}*/
}
LightUnits LightIntensityUnitPopup(LightShape shape)
{
switch (shape)
{
case LightShape.Directional:
return (LightUnits)EditorGUILayout.EnumPopup((DirectionalLightUnits)m_AdditionalLightData.lightUnit.intValue);
case LightShape.Point:
case LightShape.Spot:
return (LightUnits)EditorGUILayout.EnumPopup((PunctualLightUnits)m_AdditionalLightData.lightUnit.intValue);
default:
return (LightUnits)EditorGUILayout.EnumPopup((AreaLightUnits)m_AdditionalLightData.lightUnit.intValue);
}
}

EditorGUI.BeginChangeCheck();
switch (m_LightShape)
EditorGUILayout.BeginHorizontal();
EditorGUILayout.PropertyField(m_AdditionalLightData.intensity, s_Styles.lightIntensity);
m_AdditionalLightData.lightUnit.intValue = (int)LightIntensityUnitPopup(m_LightShape);
EditorGUILayout.EndHorizontal();
// Only display reflector option if it make sense
if (m_LightShape == LightShape.Spot)
case LightShape.Directional:
EditorGUILayout.PropertyField(m_AdditionalLightData.directionalIntensity, s_Styles.directionalIntensity);
break;
case LightShape.Point:
case LightShape.Spot:
EditorGUILayout.PropertyField(m_AdditionalLightData.punctualIntensity, s_Styles.punctualIntensity);
// Only display reflector option if it make sense
if (m_LightShape == LightShape.Spot)
{
var spotLightShape = (SpotLightShape)m_AdditionalLightData.spotLightShape.enumValueIndex;
if (spotLightShape == SpotLightShape.Cone || spotLightShape == SpotLightShape.Pyramid)
EditorGUILayout.PropertyField(m_AdditionalLightData.enableSpotReflector, s_Styles.enableSpotReflector);
}
break;
case LightShape.Rectangle:
case LightShape.Line:
EditorGUILayout.PropertyField(m_AdditionalLightData.areaIntensity, s_Styles.areaIntensity);
break;
var spotLightShape = (SpotLightShape)m_AdditionalLightData.spotLightShape.enumValueIndex;
if (spotLightShape == SpotLightShape.Cone || spotLightShape == SpotLightShape.Pyramid)
EditorGUILayout.PropertyField(m_AdditionalLightData.enableSpotReflector, s_Styles.enableSpotReflector);
}
if (EditorGUI.EndChangeCheck())

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


public float directionalIntensity = Mathf.PI; // In Lux
public float punctualIntensity = 600.0f; // Light default to 600 lumen, i.e ~48 candela
public float areaIntensity = 200.0f; // Light default to 200 lumen to better match point light
public float intensity
{
get { return m_Light.intensity; }
set { GetLightIntensity(value); }
}
// Only for Spotlight, should be hide for other light
public bool enableSpotReflector = false;

[Range(0.0f, 1.0f)]
public float volumetricDimmer = 1.0f;
// Used internally to convert any light unit input into light intensity
public int lightUnit;
// Not used for directional lights.
public float fadeDistance = 10000.0f;

public bool useOldInspector = false;
public bool featuresFoldout = true;
public bool showAdditionalSettings = false;
public float editorLightIntensity;
// Runtime datas used to compute light intensity
Light _light;
Light m_Light
{
get
{
if (_light == null)
_light = GetComponent<Light>();
return _light;
}
}
void GetLightIntensity(float value)
{
switch (lightTypeExtent)
{
case LightTypeExtent.Punctual:
GetLightIntensityPunctual(value);
break;
case LightTypeExtent.Line:
m_Light.intensity = LightUtils.CalculateLineLightIntensity(value, shapeWidth);
break;
case LightTypeExtent.Rectangle:
m_Light.intensity = LightUtils.ConvertRectLightIntensity(value, shapeWidth, shapeHeight);
break ;
}
}
void GetLightIntensityPunctual(float value)
{
switch (m_Light.type)
{
case LightType.Directional:
m_Light.intensity = directionalIntensity;
break;
case LightType.Point:
m_Light.intensity = LightUtils.ConvertPointLightIntensity(value);
break;
case LightType.Spot:
if (enableSpotReflector)
{
if (spotLightShape == SpotLightShape.Cone)
{
m_Light.intensity = LightUtils.ConvertSpotLightIntensity(value, m_Light.spotAngle * Mathf.Deg2Rad, true);
}
else if (spotLightShape == SpotLightShape.Pyramid)
{
float angleA, angleB;
LightUtils.CalculateAnglesForPyramid(aspectRatio, m_Light.spotAngle,
out angleA, out angleB);
m_Light.intensity = LightUtils.ConvertFrustrumLightIntensity(value, angleA, angleB);
}
else // Box shape, fallback to punctual light.
{
m_Light.intensity = LightUtils.ConvertPointLightIntensity(value);
}
}
else // Reflector disabled, fallback to punctual light.
{
m_Light.intensity = LightUtils.ConvertPointLightIntensity(value);
}
break;
}
}
#if UNITY_EDITOR

DrawGizmos(true);
}
public void RefreshLightIntensity()
{
// The editor can only access editorLightIntensity (because of SerializedProperties) so we update the intensity to get the real value
intensity = editorLightIntensity;
}
var light = gameObject.GetComponent<Light>();
var light = m_Light;
if (lightTypeExtent == LightTypeExtent.Punctual)
{

// At first init we need to initialize correctly the default value
lightData.ConvertPhysicalLightIntensityToLightIntensity();
// TODO: Initialize the light intensity in function of the light type
}
}
}
正在加载...
取消
保存