浏览代码

re-introduce physical light elment remove previously

/main
Sebastien Lagarde 7 年前
当前提交
761db059
共有 4 个文件被更改,包括 141 次插入4 次删除
  1. 3
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/HDLightEditor.Styles.cs
  2. 83
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/HDLightEditor.cs
  3. 7
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/HDAdditionalLightData.cs
  4. 52
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightUtils.cs

3
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/HDLightEditor.Styles.cs


public readonly GUIContent indirectBounceShadowWarning = new GUIContent("Realtime indirect bounce shadowing is not supported for Spot and Point lights.");
// Additional light data
public readonly GUIContent directionalIntensity = new GUIContent("Intensity (Lux)", "");
public readonly GUIContent punctualIntensity = new GUIContent("Intensity (Lumen)", "");
public readonly GUIContent areaIntensity = new GUIContent("Intensity (Lumen)", "");
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
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/HDLightEditor.cs


{
sealed class SerializedLightData
{
public SerializedProperty directionalIntensity;
public SerializedProperty punctualIntensity;
public SerializedProperty areaIntensity;
public SerializedProperty displayBounceIntensity;
public SerializedProperty spotInnerPercent;
public SerializedProperty lightDimmer;
public SerializedProperty fadeDistance;

//Disc,
}
const float k_LineWidth = 0.01f; // Provide a small size of 1cm for line light
// Used for UI only; the processing code must use LightTypeExtent and LightType
LightShape m_LightShape;

using (var o = new PropertyFetcher<HDAdditionalLightData>(m_SerializedAdditionalLightData))
m_AdditionalLightData = new SerializedLightData
{
directionalIntensity = o.Find(x => x.directionalIntensity),
punctualIntensity = o.Find(x => x.punctualIntensity),
areaIntensity = o.Find(x => x.areaIntensity),
displayBounceIntensity = o.Find(x => x.displayBounceIntensity),
spotInnerPercent = o.Find(x => x.m_InnerSpotPercent),
lightDimmer = o.Find(x => x.lightDimmer),
fadeDistance = o.Find(x => x.fadeDistance),

EditorGUILayout.PropertyField(m_AdditionalLightData.shapeWidth, s_Styles.shapeWidthLine);
// Fake line with a small rectangle in vanilla unity for GI
settings.areaSizeX.floatValue = m_AdditionalLightData.shapeWidth.floatValue;
settings.areaSizeY.floatValue = 0.01f;
settings.areaSizeY.floatValue = k_LineWidth;
settings.shadowsType.enumValueIndex = (int)LightShadows.None;
break;

void DrawLightSettings()
{
settings.DrawColor();
settings.DrawIntensity();
settings.DrawBounceIntensity();
EditorGUI.BeginChangeCheck();
switch (m_LightShape)
{
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);
break;
case LightShape.Rectangle:
case LightShape.Line:
EditorGUILayout.PropertyField(m_AdditionalLightData.areaIntensity, s_Styles.areaIntensity);
break;
}
if (EditorGUI.EndChangeCheck())
{
switch (m_LightShape)
{
case LightShape.Directional:
settings.intensity.floatValue = m_AdditionalLightData.directionalIntensity.floatValue;
break;
case LightShape.Point:
settings.intensity.floatValue = LightUtils.ConvertPointLightIntensity(m_AdditionalLightData.punctualIntensity.floatValue);
break;
case LightShape.Spot:
settings.intensity.floatValue = LightUtils.ConvertSpotLightIntensity(m_AdditionalLightData.punctualIntensity.floatValue, settings.spotAngle.floatValue, false);
break;
case LightShape.Rectangle:
settings.intensity.floatValue = LightUtils.ConvertRectLightIntensity(m_AdditionalLightData.punctualIntensity.floatValue, m_AdditionalLightData.shapeWidth.floatValue, m_AdditionalLightData.shapeHeight.floatValue);
break;
case LightShape.Line:
settings.intensity.floatValue = LightUtils.calculateLineLightArea(m_AdditionalLightData.punctualIntensity.floatValue, k_LineWidth, m_AdditionalLightData.shapeWidth.floatValue);
break;
}
}
EditorGUI.BeginChangeCheck();
{
EditorGUILayout.PropertyField(m_AdditionalLightData.displayBounceIntensity, s_Styles.lightBounceIntensity);
// No indirect shadow support for anything but directional
if (m_LightShape != LightShape.Directional &&
settings.shadowsType.enumValueIndex != (int)LightShadows.None &&
settings.isRealtime && m_AdditionalLightData.displayBounceIntensity.floatValue > 0.0f &&
!settings.lightType.hasMultipleDifferentValues)
{
EditorGUILayout.HelpBox(s_Styles.indirectBounceShadowWarning.text, MessageType.Info);
}
}
if (EditorGUI.EndChangeCheck())
{
// Lightmapper don't divide correctly by PI when calculating bounce of analytic light (Lambert is rho / PI but lightmapper only do rho),
// so we need to handle the divide ourselves through this workaround (only for analytical light)
settings.bounceIntensity.floatValue = m_AdditionalLightData.displayBounceIntensity.floatValue / Mathf.PI;
}
settings.DrawLightmapping();
// No cookie with area light (maybe in future textured area light ?)

EditorGUILayout.Slider(m_AdditionalShadowData.cascadeRatios.GetArrayElementAtIndex(i), 0f, 1f, s_Styles.shadowCascadeRatios[i]);
EditorGUI.indentLevel--;
if(!m_AdditionalShadowData.enableContactShadows.hasMultipleDifferentValues && m_AdditionalShadowData.enableContactShadows.boolValue)
if (!m_AdditionalShadowData.enableContactShadows.hasMultipleDifferentValues && m_AdditionalShadowData.enableContactShadows.boolValue)
{
EditorGUILayout.Space();
EditorGUILayout.LabelField(s_Styles.contactShadow, EditorStyles.boldLabel);

7
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/HDAdditionalLightData.cs


float m_Version = 1.0f;
#pragma warning restore 414
// To be able to have correct default values for our lights and to also control the conversion of intensity from the light editor (so it is compatible with GI)
// we add intensity (for each type of light we want to manage).
public float directionalIntensity = 10000.0f; // Sun Light default to 10000 lux
public float punctualIntensity = 600.0f; // Light default to 600 lumens, i.e ~48 candela
public float areaIntensity = 600.0f; // Light default to 600 lumens
public float displayBounceIntensity = 1.0f; // override bound intensity of built-in unity to take into account the PI shift observe in GI (as GI don't divide by PI)
[Range(0.0f, 100.0f)]
public float m_InnerSpotPercent = 0.0f; // To display this field in the UI this need to be public

52
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightUtils.cs


using System;
using System.Collections.Generic;
using System.Linq;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{
public class LightUtils
{
// Physical light unit helper
// All light unit are in lumen (Luminous power)
// Punctual light (point, spot) are convert to candela (cd = lumens / steradian)
// Area light are convert to luminance (cd/(m^2*steradian)) with the following formulation: Luminous Power / (Area * PI * steradian)
// Ref: Moving Frostbite to PBR
public static float ConvertPointLightIntensity(float intensity)
{
return intensity / (4.0f * Mathf.PI);
}
// angle is the full angle, not the half angle in radiant
public static float ConvertSpotLightIntensity(float intensity, float angle, bool exact)
{
return exact ? intensity / (2.0f * (1.0f - Mathf.Cos(angle / 2.0f)) * Mathf.PI) : intensity / Mathf.PI;
}
// angleA and angleB are the full opening angle, not half angle
public static float ConvertFrustrumLightIntensity(float intensity, float angleA, float angleB)
{
return intensity / (4.0f * Mathf.Asin(Mathf.Sin(angleA / 2.0f) * Mathf.Sin(angleB / 2.0f)));
}
public static float ConvertSphereLightIntensity(float intensity, float sphereRadius)
{
return intensity / (4.0f * Mathf.PI * sphereRadius * sphereRadius * Mathf.PI * Mathf.PI);
}
public static float ConvertDiscLightIntensity(float intensity, float discRadius)
{
return intensity / (discRadius * discRadius * Mathf.PI * Mathf.PI);
}
public static float ConvertRectLightIntensity(float intensity, float width, float height)
{
return intensity / (width * height * Mathf.PI);
}
public static float calculateLineLightArea(float intensity, float lineRadius, float lineWidth)
{
return intensity / (2.0f * Mathf.PI * lineRadius * lineWidth * Mathf.PI);
}
}
}
正在加载...
取消
保存