浏览代码

HDRenderPipeline: Plenty of correction and revert some code from previous draft

We need to have archetype like approach for light. I changed it to a
LightTypeExtent and re-introduced it.
/main
sebastienlagarde 7 年前
当前提交
e805946a
共有 3 个文件被更改,包括 181 次插入207 次删除
  1. 169
      ScriptableRenderPipeline/HDRenderPipeline/AdditionalData/HDAdditionalLightData.cs
  2. 102
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/Editor/HDLightEditor.cs
  3. 117
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs

169
ScriptableRenderPipeline/HDRenderPipeline/AdditionalData/HDAdditionalLightData.cs


namespace UnityEngine.Experimental.Rendering.HDPipeline
{
public enum LightShape
{
Directional = 0,
Point = 1,
Spot = 2,
Rectangle = 3,
Line = 4,
// Sphere = 5,
// Disc = 6,
}
// Deprecated / Obsolete - TODO: Remove once project have done the migration to the new LightEditor
public enum LightArchetype { Punctual, Area, Null }; // Null value have been added to detect that we have updated the light correctly.
// This enum extent the original LightType enum with new light type from HD
public enum LightTypeExtent
{
Punctual, // Fallback on LightShape type
Rectangle,
Line,
// Sphere,
// Disc,
};
public enum SpotLightShape { Cone, Pyramid, Box };

public class HDAdditionalLightData : MonoBehaviour, ISerializationCallbackReceiver
public class HDAdditionalLightData : MonoBehaviour
{
[Range(0.0f, 100.0f)]
[FormerlySerializedAs("m_innerSpotPercent")]

public bool affectDiffuse = true;
public bool affectSpecular = true;
// Caution m_lightShape need to be in sync with m_Type of original light component (i.e it need to drive the value). This is necessary for the GI to work correctly and this is handled by the HLightEditor
public LightShape m_LightShape; // To display this field in the UI this need to be public
// This setter/getter here can be use by C# code when creating procedural light.
public void SetLightshape(LightShape lightShape)
{
m_LightShape = lightShape;
Light light = gameObject.GetComponent<Light>();
switch (lightShape)
{
case LightShape.Directional:
light.type = LightType.Directional;
break;
case LightShape.Point:
light.type = LightType.Point;
break;
case LightShape.Spot:
light.type = LightType.Spot;
break;
case LightShape.Rectangle:
light.type = LightType.Area;
break;
case LightShape.Line:
light.type = LightType.Area;
break;
default:
light.type = LightType.Area;
break;
}
}
public LightShape GetLightShape()
{
return m_LightShape;
}
[FormerlySerializedAs("archetype")]
public LightTypeExtent lightTypeExtent = LightTypeExtent.Punctual;
// Only for Spotlight, should be hide for other light
public SpotLightShape spotLightShape = SpotLightShape.Cone;

// This is specific for the LightEditor GUI and not use at runtime
public bool useOldInspector = false;
public bool showAdditionalSettings = true;
// Deprecated / Obsolete - TODO: Remove once project have done the migration to the new LightEditor
private LightArchetype archetype = LightArchetype.Null;
// Deprecated / Obsolete - TODO: Remove once project have done the migration to the new LightEditor
public void OnBeforeSerialize()
{
}
// Deprecated / Obsolete - TODO: Remove once project have done the migration to the new LightEditor
public void OnAfterDeserialize()
{
if (archetype != LightArchetype.Null)
{
Light light = gameObject.GetComponent<Light>();
if (archetype == LightArchetype.Punctual)
{
switch (light.type)
{
case LightType.Spot:
m_LightShape = LightShape.Spot;
break;
case LightType.Directional:
m_LightShape = LightShape.Directional;
break;
case LightType.Point:
m_LightShape = LightShape.Point;
break;
}
}
else if (archetype == LightArchetype.Area)
{
switch (light.type)
{
case LightType.Spot:
m_LightShape = LightShape.Spot;
break;
case LightType.Directional:
m_LightShape = LightShape.Directional;
break;
case LightType.Point:
m_LightShape = LightShape.Point;
break;
}
}
UnityEditor.EditorUtility.SetDirty(this);
archetype = LightArchetype.Null;
}
}
public bool showAdditionalSettings = true; // TODO: Maybe we can remove if if we decide to always show additional settings
#if UNITY_EDITOR

gizmoColor.a = selected ? 1.0f : 0.3f; // Fade for the gizmo
Gizmos.color = Handles.color = gizmoColor;
switch (m_LightShape)
if (lightTypeExtent == LightTypeExtent.Punctual)
case LightShape.Directional:
EditorLightUtilities.DrawDirectionalLightGizmo(light);
break;
case LightShape.Point:
EditorLightUtilities.DrawPointlightGizmo(light, selected);
break;
case LightShape.Spot:
if(spotLightShape == SpotLightShape.Cone)
EditorLightUtilities.DrawSpotlightGizmo(light, selected);
if (spotLightShape == SpotLightShape.Pyramid)
EditorLightUtilities.DrawFrustumlightGizmo(light);
if (spotLightShape == SpotLightShape.Box) // TODO
EditorLightUtilities.DrawFrustumlightGizmo(light);
break;
case LightShape.Rectangle:
EditorLightUtilities.DrawArealightGizmo(light);
break;
case LightShape.Line:
EditorLightUtilities.DrawArealightGizmo(light);
break;
switch (light.type)
{
case LightType.Directional:
EditorLightUtilities.DrawDirectionalLightGizmo(light);
break;
case LightType.Point:
EditorLightUtilities.DrawPointlightGizmo(light, selected);
break;
case LightType.Spot:
if (spotLightShape == SpotLightShape.Cone)
EditorLightUtilities.DrawSpotlightGizmo(light, selected);
else if (spotLightShape == SpotLightShape.Pyramid)
EditorLightUtilities.DrawFrustumlightGizmo(light);
else if (spotLightShape == SpotLightShape.Box) // TODO
EditorLightUtilities.DrawFrustumlightGizmo(light);
break;
}
}
else
{
switch (lightTypeExtent)
{
case LightTypeExtent.Rectangle:
EditorLightUtilities.DrawArealightGizmo(light);
break;
case LightTypeExtent.Line:
EditorLightUtilities.DrawArealightGizmo(light);
break;
}
}
}

102
ScriptableRenderPipeline/HDRenderPipeline/Lighting/Editor/HDLightEditor.cs


SerializedProperty m_FadeDistance;
SerializedProperty m_AffectDiffuse;
SerializedProperty m_AffectSpecular;
SerializedProperty m_LightShape;
SerializedProperty m_LightTypeExtent;
SerializedProperty m_SpotLightShape;
SerializedProperty m_ShapeLength;
SerializedProperty m_ShapeWidth;

SerializedProperty m_ShadowCascadeBorders;
SerializedProperty m_ShadowResolution;
// This enum below is LightType enum + LightTypeExtent enum
public enum LightShape
{
Spot = 0,
Directional = 1,
Point = 2,
//Area = 3, <= offline type of Unity not dispay in our case but reuse for GI of our area light
Rectangle = 4,
Line = 5,
// Sphere = 6,
// Disc = 7,
}
// LightShape is use for displaying UI only. The processing code must use LightTypeExtent and LightType
LightShape m_LightShape;
private Light light { get { return target as Light; } }
// Note: There is no Lightmapping enum, the code C# side must use int

public readonly GUIContent CookieWarning = EditorGUIUtility.TextContent("Cookie textures for spot lights should be set to clamp, not repeat, to avoid artifacts.");
public readonly GUIContent DisabledLightWarning = EditorGUIUtility.TextContent("Lighting has been disabled in at least one Scene view. Any changes applied to lights in the Scene will not be updated in these views until Lighting has been enabled again.");
*/
public static string lightShapeText = "LightShape";
public static readonly string[] lightShapeNames = Enum.GetNames(typeof(LightShape));
}
static Styles s_Styles;

m_FadeDistance = additionalDataSerializedObject.FindProperty("fadeDistance");
m_AffectDiffuse = additionalDataSerializedObject.FindProperty("affectDiffuse");
m_AffectSpecular = additionalDataSerializedObject.FindProperty("affectSpecular");
m_LightShape = additionalDataSerializedObject.FindProperty("m_LightShape");
m_LightTypeExtent = additionalDataSerializedObject.FindProperty("lightTypeExtent");
m_SpotLightShape = additionalDataSerializedObject.FindProperty("spotLightShape");
m_ShapeLength = additionalDataSerializedObject.FindProperty("shapeLength");
m_ShapeWidth = additionalDataSerializedObject.FindProperty("shapeWidth");

m_ShadowResolution = shadowDataSerializedObject.FindProperty("shadowResolution");
}
void ResolveLightShape()
{
if (m_LightTypeExtent.enumValueIndex == (int)LightTypeExtent.Punctual)
{
switch ((LightType)m_Type.enumValueIndex)
{
case LightType.Directional:
m_LightShape = LightShape.Directional;
break;
case LightType.Point:
m_LightShape = LightShape.Point;
break;
case LightType.Spot:
m_LightShape = LightShape.Spot;
break;
}
}
else
{
switch ((LightTypeExtent)m_LightTypeExtent.enumValueIndex)
{
case LightTypeExtent.Rectangle:
m_LightShape = LightShape.Rectangle;
break;
case LightTypeExtent.Line:
m_LightShape = LightShape.Line;
break;
}
}
}
EditorGUILayout.PropertyField(m_LightShape);
m_LightShape = (LightShape)EditorGUILayout.Popup(Styles.lightShapeText, (int)m_LightShape, Styles.lightShapeNames);
switch ((LightShape)m_LightShape.enumValueIndex)
switch (m_LightShape)
{
case LightShape.Directional:
m_Type.enumValueIndex = (int)LightType.Directional;

case LightShape.Rectangle:
m_Type.enumValueIndex = (int)LightType.Area;
m_LightTypeExtent.enumValueIndex = (int)LightTypeExtent.Rectangle;
EditorGUILayout.PropertyField(m_ShapeLength);
EditorGUILayout.PropertyField(m_ShapeWidth);
m_AreaSizeX.floatValue = m_ShapeLength.floatValue;

case LightShape.Line:
m_Type.enumValueIndex = (int)LightType.Area;
m_LightTypeExtent.enumValueIndex = (int)LightTypeExtent.Line;
EditorGUILayout.PropertyField(m_ShapeLength);
m_ShapeWidth.floatValue = 0;
// Fake line with a small rectangle in vanilla unity for GI

m_ShapeLength.floatValue = m_CookieSize.floatValue;
m_ShapeWidth.floatValue = m_CookieSize.floatValue;
}
EditorGUILayout.PropertyField(m_ApplyRangeAttenuation);
// Do not display option for shadow if we are fully bake
if (m_Lightmapping.enumValueIndex != (int)LightMappingType.Static)
{
EditorGUILayout.PropertyField(m_ShadowsType);
}
}
void ShadowsGUI()

void AdditionalSettingsGUI()
{
EditorGUILayout.LabelField(new GUIContent("General"), EditorStyles.boldLabel);
EditorGUILayout.PropertyField(m_CullingMask);
// Currently culling mask is not working with HD
// EditorGUILayout.LabelField(new GUIContent("General"), EditorStyles.boldLabel);
// EditorGUILayout.PropertyField(m_CullingMask);
EditorGUILayout.LabelField(new GUIContent("Light"), EditorStyles.boldLabel);
EditorGUILayout.PropertyField(m_AffectDiffuse);

EditorGUILayout.PropertyField(m_ApplyRangeAttenuation);
if (m_ShadowsType.enumValueIndex != (int)LightShadows.None && m_Lightmapping.enumValueIndex != (int)LightMappingType.Static)
{

additionalDataSerializedObject.Update();
shadowDataSerializedObject.Update();
ResolveLightShape();
var additionalData = light.GetComponent<HDAdditionalLightData>();
var shadowData = light.GetComponent<AdditionalShadowData>();

ApplyAdditionalComponentsVisibility(true);
// Allow to display the arrow for reduce/expanfd correctly
EditorGUI.indentLevel = 1;
// EditorGUI.indentLevel++;
// EditorGUILayout.LabelField(new GUIContent("Light features"), EditorStyles.boldLabel);
// EditorLightUtilities.DrawSplitter();
// m_affectDiffuse.isExpanded = EditorLightUtilities.DrawHeaderFoldout("Light features", m_AffectDiffuse.isExpanded);
EditorGUI.indentLevel++;
EditorGUILayout.LabelField(new GUIContent("Light features"), EditorStyles.boldLabel);
// Do not display option for shadow if we are fully bake
if (m_Lightmapping.enumValueIndex != (int)LightMappingType.Static)
{
if (EditorGUILayout.Toggle(new GUIContent("Enable Shadow"), m_ShadowsType.enumValueIndex != 0))
m_ShadowsType.enumValueIndex = (int)LightShadows.Hard;
else
m_ShadowsType.enumValueIndex = (int)LightShadows.None;
}
// if (m_AffectDiffuse.isExpanded)
// {
// EditorGUILayout.PropertyField(m_AffectDiffuse, new GUIContent("Diffuse"), GUILayout.MaxWidth(EditorGUIUtility.labelWidth + 30));
// var AffectDiffuseRect = GUILayoutUtility.GetLastRect();
// var AffectSpecularRect = new Rect(EditorGUIUtility.labelWidth + 30, AffectDiffuseRect.y, EditorGUIUtility.labelWidth + 30, AffectDiffuseRect.height);
// EditorGUI.PropertyField(AffectSpecularRect, m_AffectSpecular, new GUIContent("Specular"));
//}
EditorGUI.indentLevel--;
// Allow to display the arrow for reduce/expand correctly
EditorGUI.indentLevel = 1;
// LightShape
EditorGUI.indentLevel--;

117
ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs


GPUShadowType shadowType = GPUShadowType.Unknown;
switch (ald.GetLightShape())
switch (ald.lightTypeExtent)
case LightShape.Directional:
case LightShape.Spot:
case LightShape.Point:
case LightTypeExtent.Punctual:
shadowType = ShadowRegistry.ShadowLightType(l);
break;

GPULightType gpuLightType = GPULightType.Point;
LightVolumeType lightVolumeType = LightVolumeType.Count;
switch (additionalData.GetLightShape())
{
case LightShape.Point:
if (punctualLightcount >= k_MaxPunctualLightsOnScreen)
continue;
if (additionalData.lightTypeExtent == LightTypeExtent.Punctual)
{
gpuLightType = GPULightType.Point;
lightVolumeType = LightVolumeType.Sphere;
break;
case LightShape.Spot:
if (punctualLightcount >= k_MaxPunctualLightsOnScreen)
continue;
lightCategory = LightCategory.Punctual;
switch (additionalData.spotLightShape)
switch (light.lightType)
case SpotLightShape.Cone:
gpuLightType = GPULightType.Spot;
lightVolumeType = LightVolumeType.Cone;
case LightType.Spot:
if (punctualLightcount >= k_MaxPunctualLightsOnScreen)
continue;
switch (additionalData.spotLightShape)
{
case SpotLightShape.Cone:
gpuLightType = GPULightType.Spot;
lightVolumeType = LightVolumeType.Cone;
break;
case SpotLightShape.Pyramid:
gpuLightType = GPULightType.ProjectorPyramid;
lightVolumeType = LightVolumeType.Cone;
break;
case SpotLightShape.Box:
gpuLightType = GPULightType.ProjectorBox;
lightVolumeType = LightVolumeType.Box;
break;
default:
Debug.Assert(false, "Encountered an unknown SpotLightShape.");
break;
}
case SpotLightShape.Pyramid:
gpuLightType = GPULightType.ProjectorPyramid;
lightVolumeType = LightVolumeType.Cone;
case LightType.Directional:
if (directionalLightcount >= k_MaxDirectionalLightsOnScreen)
continue;
gpuLightType = GPULightType.Directional;
// No need to add volume, always visible
lightVolumeType = LightVolumeType.Count; // Count is none
case SpotLightShape.Box:
gpuLightType = GPULightType.ProjectorBox;
lightVolumeType = LightVolumeType.Box;
case LightType.Point:
if (punctualLightcount >= k_MaxPunctualLightsOnScreen)
continue;
gpuLightType = GPULightType.Point;
lightVolumeType = LightVolumeType.Sphere;
Debug.Assert(false, "Encountered an unknown SpotLightShape.");
Debug.Assert(false, "Encountered an unknown LightType.");
break;
}
else
{
lightCategory = LightCategory.Area;
case LightShape.Directional:
if (directionalLightcount >= k_MaxDirectionalLightsOnScreen)
continue;
lightCategory = LightCategory.Punctual;
gpuLightType = GPULightType.Directional;
// No need to add volume, always visible
lightVolumeType = LightVolumeType.Count; // Count is none
break;
switch (additionalData.lightTypeExtent)
{
case LightTypeExtent.Rectangle:
if (areaLightCount >= k_MaxAreaLightsOnScreen)
continue;
gpuLightType = GPULightType.Rectangle;
lightVolumeType = LightVolumeType.Box;
break;
case LightShape.Rectangle:
if (areaLightCount >= k_MaxAreaLightsOnScreen)
continue;
lightCategory = LightCategory.Area;
gpuLightType = GPULightType.Rectangle;
lightVolumeType = LightVolumeType.Box;
break;
case LightTypeExtent.Line:
if (areaLightCount >= k_MaxAreaLightsOnScreen)
continue;
gpuLightType = GPULightType.Line;
lightVolumeType = LightVolumeType.Box;
break;
case LightShape.Line:
if (areaLightCount >= k_MaxAreaLightsOnScreen)
continue;
lightCategory = LightCategory.Area;
gpuLightType = GPULightType.Line;
lightVolumeType = LightVolumeType.Box;
break;
default:
Debug.Assert(false, "Encountered an unknown LightType.");
break;
default:
Debug.Assert(false, "Encountered an unknown LightType.");
break;
}
}
uint shadow = m_ShadowIndices.ContainsKey(lightIndex) ? 1u : 0;

正在加载...
取消
保存