浏览代码

first draft

/main
sebastienlagarde 7 年前
当前提交
a4916499
共有 5 个文件被更改,包括 155 次插入5 次删除
  1. 8
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/HDLightEditor.Styles.cs
  2. 82
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/HDLightEditor.cs
  3. 7
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/HDAdditionalLightData.cs
  4. 52
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightUtils.cs
  5. 11
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightUtils.cs.meta

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


{
sealed class Styles
{
// Base
// Base (copy from LightEditor.cs)
public readonly GUIContent cookieSizeX = new GUIContent("Size X", "Controls the size of the cookie mask currently assigned to the light.");
public readonly GUIContent cookieSizeY = new GUIContent("Size Y", "Controls the size of the cookie mask currently assigned to the light.");
public readonly GUIContent shadowBias = new GUIContent("Bias", "Controls the distance at which the shadows will be pushed away from the light. Useful for avoiding false self-shadowing artifacts.");

public readonly GUIContent bakedShadowAngle = new GUIContent("Baked Shadow Angle", "Controls the amount of artificial softening applied to the edges of shadows cast by directional lights.");
public readonly GUIContent lightBounceIntensity = new GUIContent("Indirect Multiplier", "Controls the intensity of indirect light being contributed to the scene. A value of 0 will cause Realtime lights to be removed from realtime global illumination and Baked and Mixed lights to no longer emit indirect lighting. Has no effect when both Realtime and Baked Global Illumination are disabled.");
public readonly GUIContent indirectBounceShadowWarning = new GUIContent("Realtime indirect bounce shadowing is not supported for Spot and Point lights.");
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.");
public readonly GUIContent affectSpecular = new GUIContent("Affect Specular", "This will disable specular lighting for this light. Doesn't save performance, specular lighting is still computed.");

82
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
{
spotInnerPercent = o.Find(x => x.m_InnerSpotPercent),
directionalIntensity = o.Find(x => x.directionalIntensity),
punctualIntensity = o.Find(x => x.punctualIntensity),
areaIntensity = o.Find(x => x.areaIntensity),
displayBounceIntensity = o.Find(x => x.displayBounceIntensity),
lightDimmer = o.Find(x => x.lightDimmer),
fadeDistance = o.Find(x => x.fadeDistance),
affectDiffuse = o.Find(x => x.affectDiffuse),

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 ?)

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);
}
}
}

11
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightUtils.cs.meta


fileFormatVersion: 2
guid: 04acc467a6eef0b45b027f43ed25662b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存