浏览代码

Merge pull request #1797 from Unity-Technologies/EvIntensityForLights

Ev intensity for lights
/main
GitHub 6 年前
当前提交
e9c0c3ef
共有 4 个文件被更改,包括 71 次插入24 次删除
  1. 1
      com.unity.render-pipelines.high-definition/CHANGELOG.md
  2. 23
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/HDLightEditor.cs
  3. 21
      com.unity.render-pipelines.high-definition/HDRP/Lighting/Light/HDAdditionalLightData.cs
  4. 50
      com.unity.render-pipelines.high-definition/HDRP/Lighting/LightUtils.cs

1
com.unity.render-pipelines.high-definition/CHANGELOG.md


- Added an option to disable light by type in the debug menu
- Added gradient sky
- Split EmissiveColor and bakeDiffuseLighting in forward avoiding the emissiveColor to be affect by SSAO
- Added EV 100 intensity unit for area lights
### Fixed
- Fixed an issue with PreIntegratedFGD texture being sometimes destroyed and not regenerated causing rendering to break

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


{
Lumen = LightUnit.Lumen,
Luminance = LightUnit.Luminance,
Ev100 = LightUnit.Ev100,
}
enum PunctualLightUnit

// For area lights
if (oldLightUnit == LightUnit.Lumen && newLightUnit == LightUnit.Luminance)
{
if (m_LightShape == LightShape.Rectangle)
intensity = LightUtils.ConvertRectLightLumenToLuminance(intensity, m_AdditionalLightData.shapeWidth.floatValue, m_AdditionalLightData.shapeHeight.floatValue);
else if (m_LightShape == LightShape.Line)
intensity = LightUtils.CalculateLineLightLumenToLuminance(intensity, m_AdditionalLightData.shapeWidth.floatValue);
}
intensity = LightUtils.ConvertAreaLightLumenToLuminance((LightTypeExtent)m_AdditionalLightData.lightTypeExtent.enumValueIndex, intensity, m_AdditionalLightData.shapeWidth.floatValue, m_AdditionalLightData.shapeHeight.floatValue);
{
if (m_LightShape == LightShape.Rectangle)
intensity = LightUtils.ConvertRectLightLuminanceToLumen(intensity, m_AdditionalLightData.shapeWidth.floatValue, m_AdditionalLightData.shapeHeight.floatValue);
else if (m_LightShape == LightShape.Line)
intensity = LightUtils.CalculateLineLightLuminanceToLumen(intensity, m_AdditionalLightData.shapeWidth.floatValue);
}
intensity = LightUtils.ConvertAreaLightLuminanceToLumen((LightTypeExtent)m_AdditionalLightData.lightTypeExtent.enumValueIndex, intensity, m_AdditionalLightData.shapeWidth.floatValue, m_AdditionalLightData.shapeHeight.floatValue);
if (oldLightUnit == LightUnit.Luminance && newLightUnit == LightUnit.Ev100)
intensity = LightUtils.ConvertLuminanceToEv(intensity);
if (oldLightUnit == LightUnit.Ev100 && newLightUnit == LightUnit.Luminance)
intensity = LightUtils.ConvertEvToLuminance(intensity);
if (oldLightUnit == LightUnit.Ev100 && newLightUnit == LightUnit.Lumen)
intensity = LightUtils.ConvertAreaLightEvToLumen((LightTypeExtent)m_AdditionalLightData.lightTypeExtent.enumValueIndex, intensity, m_AdditionalLightData.shapeWidth.floatValue, m_AdditionalLightData.shapeHeight.floatValue);
if (oldLightUnit == LightUnit.Lumen && newLightUnit == LightUnit.Ev100)
intensity = LightUtils.ConvertAreaLightLumenToEv((LightTypeExtent)m_AdditionalLightData.lightTypeExtent.enumValueIndex, intensity, m_AdditionalLightData.shapeWidth.floatValue, m_AdditionalLightData.shapeHeight.floatValue);
m_AdditionalLightData.intensity.floatValue = intensity;
}

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


Candela,
Lux,
Luminance,
Ev100,
}
// Light layering

if (lightUnit == LightUnit.Lumen)
{
switch (lightTypeExtent)
{
case LightTypeExtent.Punctual:
SetLightIntensityPunctual(intensity);
break;
case LightTypeExtent.Line:
m_Light.intensity = LightUtils.CalculateLineLightLumenToLuminance(intensity, shapeWidth);
break;
case LightTypeExtent.Rectangle:
m_Light.intensity = LightUtils.ConvertRectLightLumenToLuminance(intensity, shapeWidth, shapeHeight);
break;
}
if (lightTypeExtent == LightTypeExtent.Punctual)
SetLightIntensityPunctual(intensity);
else
m_Light.intensity = LightUtils.ConvertAreaLightLumenToLuminance(lightTypeExtent, intensity, shapeWidth, shapeHeight);
}
else if (lightUnit == LightUnit.Ev100)
{
m_Light.intensity = LightUtils.ConvertEvToLuminance(intensity);
}
else
m_Light.intensity = intensity;

50
com.unity.render-pipelines.high-definition/HDRP/Lighting/LightUtils.cs


return intensity * ((width * height) * Mathf.PI);
}
public static float ConvertEvToLuminance(float ev)
{
return Mathf.Pow(2, ev - 3);
}
public static float ConvertLuminanceToEv(float luminance)
{
const float k = 12.5f;
return (float)Math.Log((luminance * 100f) / k, 2);
}
public static float ConvertAreaLightLumenToLuminance(LightTypeExtent areaLightType, float lumen, float width, float height = 0)
{
switch (areaLightType)
{
case LightTypeExtent.Line:
return LightUtils.CalculateLineLightLumenToLuminance(lumen, width);
case LightTypeExtent.Rectangle:
return LightUtils.ConvertRectLightLumenToLuminance(lumen, width, height);
}
return lumen;
}
public static float ConvertAreaLightLuminanceToLumen(LightTypeExtent areaLightType, float luminance, float width, float height = 0)
{
switch (areaLightType)
{
case LightTypeExtent.Line:
return LightUtils.CalculateLineLightLuminanceToLumen(luminance, width);
case LightTypeExtent.Rectangle:
return LightUtils.ConvertRectLightLuminanceToLumen(luminance, width, height);
}
return luminance;
}
public static float ConvertAreaLightLumenToEv(LightTypeExtent areaLightType, float lumen, float width, float height)
{
float luminance = ConvertAreaLightLumenToLuminance(areaLightType, lumen, width, height);
return ConvertLuminanceToEv(luminance);
}
public static float ConvertAreaLightEvToLumen(LightTypeExtent areaLightType, float ev, float width, float height)
{
float luminance = ConvertEvToLuminance(ev);
return ConvertAreaLightLuminanceToLumen(areaLightType, luminance, width, height);
}
// convert intensity (lumen) to nits
public static float CalculateLineLightLumenToLuminance(float intensity, float lineWidth)
{

正在加载...
取消
保存