浏览代码

Hdrp/fix/light gizmos and handles (#1905)

Hide legacy gizmo for all spot lights and introduce pyramid and box light handle.
(Cone spot light handle should be branched once validated in LW)
/hdrp-staging
JulienIgnace-Unity 6 年前
当前提交
195a1aa2
共有 5 个文件被更改,包括 403 次插入175 次删除
  1. 341
      com.unity.render-pipelines.core/CoreRP/Editor/Lighting/CoreLightEditorUtilities.cs
  2. 66
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/HDAdditionalLightDataEditor.cs
  3. 126
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/HDLightEditor.cs
  4. 34
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/HDLightEditorUtilities.cs
  5. 11
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/HDLightEditorUtilities.cs.meta

341
com.unity.render-pipelines.core/CoreRP/Editor/Lighting/CoreLightEditorUtilities.cs


{
public static class CoreLightEditorUtilities
{
static Vector2 SliderPlaneHandle(Vector3 origin, Vector3 axis1, Vector3 axis2, Vector2 position)
{
Vector3 pos = origin + position.x * axis1 + position.y * axis2;
float sizeHandle = HandleUtility.GetHandleSize(pos);
bool temp = GUI.changed;
GUI.changed = false;
pos = Handles.Slider2D(pos, Vector3.forward, axis1, axis2, sizeHandle * 0.03f, Handles.DotHandleCap, 0f);
if (GUI.changed)
{
position = new Vector2(Vector3.Dot(pos, axis1), Vector3.Dot(pos, axis2));
}
GUI.changed |= temp;
return position;
}
static float SliderLineHandle(Vector3 position, Vector3 direction, float value)
{
Vector3 pos = position + direction * value;
float sizeHandle = HandleUtility.GetHandleSize(pos);
bool temp = GUI.changed;
GUI.changed = false;
pos = Handles.Slider(pos, direction, sizeHandle * 0.03f, Handles.DotHandleCap, 0f);
if (GUI.changed)
{
value = Vector3.Dot(pos - position, direction);
}
GUI.changed |= temp;
return value;
}
static float SliderCircleHandle(Vector3 position, Vector3 normal, Vector3 zeroValueDirection, float angleValue, float radius)
{
zeroValueDirection.Normalize();
normal.Normalize();
Quaternion rot = Quaternion.AngleAxis(angleValue, normal);
Vector3 pos = position + rot * zeroValueDirection * radius;
float sizeHandle = HandleUtility.GetHandleSize(pos);
bool temp = GUI.changed;
GUI.changed = false;
Vector3 tangeant = Vector3.Cross(normal, (pos - position).normalized);
pos = Handles.Slider(pos, tangeant, sizeHandle * 0.03f, Handles.DotHandleCap, 0f);
if (GUI.changed)
{
Vector3 dir = (pos - position).normalized;
Vector3 cross = Vector3.Cross(zeroValueDirection, dir);
int sign = ((cross - normal).sqrMagnitude < (-cross - normal).sqrMagnitude) ? 1 : -1;
angleValue = Mathf.Acos(Vector3.Dot(zeroValueDirection, dir)) * Mathf.Rad2Deg * sign;
}
GUI.changed |= temp;
return angleValue;
}
public static Color GetLightHandleColor(Color wireframeColor)
{
Color color = wireframeColor;
color.a = Mathf.Clamp01(color.a * 2);
return (QualitySettings.activeColorSpace == ColorSpace.Linear) ? color.linear : color;
}
public static Color GetLightBehindObjectWireframeColor(Color wireframeColor)
{
Color color = wireframeColor;
color.a = 0.2f;
return (QualitySettings.activeColorSpace == ColorSpace.Linear) ? color.linear : color;
}
// Don't use Handles.Disc as it break the highlight of the gizmo axis, use our own draw disc function instead for gizmo
public static void DrawWireDisc(Quaternion q, Vector3 position, Vector3 axis, float radius)
{

Gizmos.DrawWireSphere(arealight.transform.position, arealight.range);
}
[Obsolete("Should use the legacy gizmo draw")]
public static void DrawPointlightGizmo(Light pointlight, bool selected)
{
if (pointlight.shadows != LightShadows.None && selected) Gizmos.DrawWireSphere(pointlight.transform.position, pointlight.shadowNearPlane);

// Same as Gizmo.DrawFrustum except that when aspect is below one, fov represent fovX instead of fovY
// Use to match our light frustum pyramid behavior
public static void DrawLightPyramidFrustum(Vector3 center, float fov, float maxRange, float minRange, float aspect)
public static void DrawPyramidFrustumWireframe(Vector4 aspectFovMaxRangeMinRange)
fov = Mathf.Deg2Rad * fov * 0.5f;
float tanfov = Mathf.Tan(fov);
float aspect = aspectFovMaxRangeMinRange.x;
float fov = aspectFovMaxRangeMinRange.y;
float maxRange = aspectFovMaxRangeMinRange.z;
float minRange = aspectFovMaxRangeMinRange.w;
float tanfov = Mathf.Tan(Mathf.Deg2Rad * fov * 0.5f);
float minXYFarEndSize = maxRange * tanfov;
Vector3 farEnd = new Vector3(0, 0, maxRange);
Vector3 endSizeX;
Vector3 endSizeY;

endSizeX = new Vector3(maxRange * tanfov * aspect, 0, 0);
endSizeY = new Vector3(0, maxRange * tanfov, 0);
endSizeX = new Vector3(minXYFarEndSize * aspect, 0, 0);
endSizeY = new Vector3(0, minXYFarEndSize, 0);
endSizeX = new Vector3(maxRange * tanfov, 0, 0);
endSizeY = new Vector3(0, maxRange * tanfov / aspect, 0);
endSizeX = new Vector3(minXYFarEndSize, 0, 0);
endSizeY = new Vector3(0, minXYFarEndSize / aspect, 0);
Vector3 s1, s2, s3, s4;
Vector3 s1 = Vector3.zero;
Vector3 s2 = Vector3.zero;
Vector3 s3 = Vector3.zero;
Vector3 s4 = Vector3.zero;
if (minRange <= 0.0f)
{
s1 = s2 = s3 = s4 = center;
}
else
if (minRange > 0.0f)
Vector3 nearEnd = new Vector3(0, 0, minRange);
float minXYStartSize = minRange * tanfov;
startSizeX = new Vector3(minRange * tanfov * aspect, 0, 0);
startSizeY = new Vector3(0, minRange * tanfov, 0);
startSizeX = new Vector3(minXYStartSize * aspect, 0, 0);
startSizeY = new Vector3(0, minXYStartSize, 0);
startSizeY = new Vector3(minRange * tanfov / aspect, 0, 0);
startSizeX = new Vector3(0, minRange * tanfov, 0);
startSizeX = new Vector3(minXYStartSize, 0, 0);
startSizeY = new Vector3(0, minXYStartSize / aspect, 0);
Vector3 startPoint = center;
s1 = startPoint + startSizeX + startSizeY;
s2 = startPoint - startSizeX + startSizeY;
s3 = startPoint - startSizeX - startSizeY;
s4 = startPoint + startSizeX - startSizeY;
Gizmos.DrawLine(s1, s2);
Gizmos.DrawLine(s2, s3);
Gizmos.DrawLine(s3, s4);
Gizmos.DrawLine(s4, s1);
Vector3 startPoint = nearEnd;
s1 = startPoint + startSizeX + startSizeY;
s2 = startPoint - startSizeX + startSizeY;
s3 = startPoint - startSizeX - startSizeY;
s4 = startPoint + startSizeX - startSizeY;
Handles.DrawLine(s1, s2);
Handles.DrawLine(s2, s3);
Handles.DrawLine(s3, s4);
Handles.DrawLine(s4, s1);
Gizmos.DrawLine(e1, e2);
Gizmos.DrawLine(e2, e3);
Gizmos.DrawLine(e3, e4);
Gizmos.DrawLine(e4, e1);
Handles.DrawLine(s1, e1);
Handles.DrawLine(s2, e2);
Handles.DrawLine(s3, e3);
Handles.DrawLine(s4, e4);
Gizmos.DrawLine(s1, e1);
Gizmos.DrawLine(s2, e2);
Gizmos.DrawLine(s3, e3);
Gizmos.DrawLine(s4, e4);
Handles.DrawLine(e1, e2);
Handles.DrawLine(e2, e3);
Handles.DrawLine(e3, e4);
Handles.DrawLine(e4, e1);
public static void DrawLightOrthoFrustum(Vector3 center, float width, float height, float maxRange, float minRange)
public static Vector4 DrawPyramidFrustumHandle(Vector4 aspectFovMaxRangeMinRange, bool useNearPlane, float minAspect = 0.05f, float maxAspect = 20f, float minFov = 1f)
float aspect = aspectFovMaxRangeMinRange.x;
float fov = aspectFovMaxRangeMinRange.y;
float maxRange = aspectFovMaxRangeMinRange.z;
float minRange = aspectFovMaxRangeMinRange.w;
float tanfov = Mathf.Tan(Mathf.Deg2Rad * fov * 0.5f);
float minXYFarEndSize = maxRange * tanfov;
Vector3 endSizeX = new Vector3(width, 0, 0);
Vector3 endSizeY = new Vector3(0, height, 0);
Vector3 endSizeX;
Vector3 endSizeY;
Vector3 s1, s2, s3, s4;
Vector3 e1 = farEnd + endSizeX + endSizeY;
Vector3 e2 = farEnd - endSizeX + endSizeY;
Vector3 e3 = farEnd - endSizeX - endSizeY;
Vector3 e4 = farEnd + endSizeX - endSizeY;
if (minRange <= 0.0f)
if (aspect >= 1.0f)
s1 = s2 = s3 = s4 = center;
endSizeX = new Vector3(minXYFarEndSize * aspect, 0, 0);
endSizeY = new Vector3(0, minXYFarEndSize, 0);
Vector3 startSizeX = new Vector3(width, 0, 0);
Vector3 startSizeY = new Vector3(0, height, 0);
endSizeX = new Vector3(minXYFarEndSize, 0, 0);
endSizeY = new Vector3(0, minXYFarEndSize / aspect, 0);
}
Vector3[] e = new Vector3[]
{
farEnd + endSizeX + endSizeY,
farEnd - endSizeX + endSizeY,
farEnd - endSizeX - endSizeY,
farEnd + endSizeX - endSizeY
};
if (useNearPlane)
{
minRange = SliderLineHandle(Vector3.zero, Vector3.forward, minRange);
}
Vector3 startPoint = center;
s1 = startPoint + startSizeX + startSizeY;
s2 = startPoint - startSizeX + startSizeY;
s3 = startPoint - startSizeX - startSizeY;
s4 = startPoint + startSizeX - startSizeY;
Gizmos.DrawLine(s1, s2);
Gizmos.DrawLine(s2, s3);
Gizmos.DrawLine(s3, s4);
Gizmos.DrawLine(s4, s1);
maxRange = SliderLineHandle(Vector3.zero, Vector3.forward, maxRange);
//find the righttop corner in screen
Vector2[] screenPositions = new Vector2[]
{
Camera.current.WorldToScreenPoint(Handles.matrix * e[0]),
Camera.current.WorldToScreenPoint(Handles.matrix * e[1]),
Camera.current.WorldToScreenPoint(Handles.matrix * e[2]),
Camera.current.WorldToScreenPoint(Handles.matrix * e[3])
};
float maxWeight = float.MinValue;
int maxIndex = 0;
Vector2 support = new Vector2(Camera.current.pixelWidth, Camera.current.pixelHeight);
Vector2 supportOrtho = new Vector2(support.y, -support.x);
for (int i = 0; i < 4; ++i)
{
float weight = Vector3.Dot(screenPositions[i], support) - 0.5f * Mathf.Abs(Vector3.Dot(screenPositions[i], supportOrtho));
if (weight > maxWeight)
{
maxWeight = weight;
maxIndex = i;
}
Gizmos.DrawLine(e1, e2);
Gizmos.DrawLine(e2, e3);
Gizmos.DrawLine(e3, e4);
Gizmos.DrawLine(e4, e1);
Vector2 send = e[maxIndex];
EditorGUI.BeginChangeCheck();
Vector2 received = SliderPlaneHandle(farEnd, Vector3.right, Vector3.up, send);
if (EditorGUI.EndChangeCheck())
{
bool fixedFov = Event.current.control && !Event.current.shift;
bool fixedAspect = Event.current.shift && !Event.current.control;
Gizmos.DrawLine(s1, e1);
Gizmos.DrawLine(s2, e2);
Gizmos.DrawLine(s3, e3);
Gizmos.DrawLine(s4, e4);
//work on positive quadrant
int xSign = send.x < 0f ? -1 : 1;
int ySign = send.y < 0f ? -1 : 1;
Vector2 corrected = new Vector2(received.x * xSign, received.y * ySign);
//fixed aspect correction
if (fixedAspect)
{
corrected.x = corrected.y * aspect;
}
//remove aspect deadzone
if (corrected.x > maxAspect * corrected.y)
{
corrected.y = corrected.x * minAspect;
}
if (corrected.x < minAspect * corrected.y)
{
corrected.x = corrected.y / maxAspect;
}
//remove fov deadzone
float deadThresholdFoV = Mathf.Tan(Mathf.Deg2Rad * minFov * 0.5f) * maxRange;
corrected.x = Mathf.Max(corrected.x, deadThresholdFoV);
corrected.y = Mathf.Max(corrected.y, deadThresholdFoV, Mathf.Epsilon * 100); //prevent any division by zero
if (!fixedAspect)
{
aspect = corrected.x / corrected.y;
}
float min = Mathf.Min(corrected.x, corrected.y);
if (!fixedFov && maxRange > Mathf.Epsilon * 100)
{
fov = Mathf.Atan(min / maxRange) * 2f * Mathf.Rad2Deg;
}
}
return new Vector4(aspect, fov, maxRange, minRange);
public static void DrawOrthoFrustumWireframe(Vector4 widthHeightMaxRangeMinRange)
{
float halfWidth = widthHeightMaxRangeMinRange.x * 0.5f;
float halfHeight = widthHeightMaxRangeMinRange.y * 0.5f;
float maxRange = widthHeightMaxRangeMinRange.z;
float minRange = widthHeightMaxRangeMinRange.w;
Vector3 sizeX = new Vector3(halfWidth, 0, 0);
Vector3 sizeY = new Vector3(0, halfHeight, 0);
Vector3 nearEnd = new Vector3(0, 0, minRange);
Vector3 farEnd = new Vector3(0, 0, maxRange);
Vector3 s1 = nearEnd + sizeX + sizeY;
Vector3 s2 = nearEnd - sizeX + sizeY;
Vector3 s3 = nearEnd - sizeX - sizeY;
Vector3 s4 = nearEnd + sizeX - sizeY;
Vector3 e1 = farEnd + sizeX + sizeY;
Vector3 e2 = farEnd - sizeX + sizeY;
Vector3 e3 = farEnd - sizeX - sizeY;
Vector3 e4 = farEnd + sizeX - sizeY;
Handles.DrawLine(s1, s2);
Handles.DrawLine(s2, s3);
Handles.DrawLine(s3, s4);
Handles.DrawLine(s4, s1);
Handles.DrawLine(e1, e2);
Handles.DrawLine(e2, e3);
Handles.DrawLine(e3, e4);
Handles.DrawLine(e4, e1);
Handles.DrawLine(s1, e1);
Handles.DrawLine(s2, e2);
Handles.DrawLine(s3, e3);
Handles.DrawLine(s4, e4);
}
public static Vector4 DrawOrthoFrustumHandle(Vector4 widthHeightMaxRangeMinRange, bool useNearHandle)
{
float halfWidth = widthHeightMaxRangeMinRange.x * 0.5f;
float halfHeight = widthHeightMaxRangeMinRange.y * 0.5f;
float maxRange = widthHeightMaxRangeMinRange.z;
float minRange = widthHeightMaxRangeMinRange.w;
Vector3 farEnd = new Vector3(0, 0, maxRange);
if (useNearHandle)
{
minRange = SliderLineHandle(Vector3.zero, Vector3.forward, minRange);
}
maxRange = SliderLineHandle(Vector3.zero, Vector3.forward, maxRange);
EditorGUI.BeginChangeCheck();
halfWidth = SliderLineHandle(farEnd, Vector3.right, halfWidth);
halfWidth = SliderLineHandle(farEnd, Vector3.left, halfWidth);
if (EditorGUI.EndChangeCheck())
{
halfWidth = Mathf.Max(0f, halfWidth);
}
EditorGUI.BeginChangeCheck();
halfHeight = SliderLineHandle(farEnd, Vector3.up, halfHeight);
halfHeight = SliderLineHandle(farEnd, Vector3.down, halfHeight);
if (EditorGUI.EndChangeCheck())
{
halfHeight = Mathf.Max(0f, halfHeight);
}
return new Vector4(halfWidth * 2f, halfHeight * 2f, maxRange, minRange);
}
[Obsolete("Should use the legacy gizmo draw")]
public static void DrawDirectionalLightGizmo(Light directionalLight)
{
var gizmoSize = 0.2f;

66
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/HDAdditionalLightDataEditor.cs


{
}
}
public class HDAdditionalLightDataGizmoDrawer
{
[DrawGizmo(GizmoType.Selected | GizmoType.Active)]
static void DrawGizmoForHDAdditionalLightData(HDAdditionalLightData src, GizmoType gizmoType)
{
bool selected = (gizmoType & GizmoType.Selected) != 0;
var light = src.gameObject.GetComponent<Light>();
var gizmoColor = light.color;
gizmoColor.a = selected ? 1.0f : 0.3f; // Fade for the gizmo
Gizmos.color = Handles.color = gizmoColor;
if (src.lightTypeExtent == LightTypeExtent.Punctual)
{
switch (light.type)
{
case LightType.Directional:
CoreLightEditorUtilities.DrawDirectionalLightGizmo(light);
break;
case LightType.Point:
CoreLightEditorUtilities.DrawPointlightGizmo(light, selected);
break;
case LightType.Spot:
if (src.spotLightShape == SpotLightShape.Cone)
CoreLightEditorUtilities.DrawSpotlightGizmo(light, src.GetInnerSpotPercent01(), selected);
else if (src.spotLightShape == SpotLightShape.Pyramid)
HDLightEditorUtilities.DrawFrustumlightGizmo(light);
else if (src.spotLightShape == SpotLightShape.Box)
HDLightEditorUtilities.DrawFrustumlightGizmo(light);
break;
}
}
else
{
switch (src.lightTypeExtent)
{
case LightTypeExtent.Rectangle:
CoreLightEditorUtilities.DrawArealightGizmo(light);
break;
case LightTypeExtent.Line:
CoreLightEditorUtilities.DrawArealightGizmo(light);
break;
}
}
if (selected)
{
// Trace a ray down to better locate the light location
Ray ray = new Ray(src.gameObject.transform.position, Vector3.down);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
Handles.color = Color.green;
Handles.zTest = UnityEngine.Rendering.CompareFunction.LessEqual;
Handles.DrawLine(src.gameObject.transform.position, hit.point);
Handles.DrawWireDisc(hit.point, hit.normal, 0.5f);
Handles.color = Color.red;
Handles.zTest = UnityEngine.Rendering.CompareFunction.Greater;
Handles.DrawLine(src.gameObject.transform.position, hit.point);
Handles.DrawWireDisc(hit.point, hit.normal, 0.5f);
}
}
}
}
}

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


UpdateAreaLightEmissiveMeshComponents();
}
protected override void OnSceneGUI()
{
m_SerializedAdditionalLightData.Update();
HDAdditionalLightData src = (HDAdditionalLightData)m_SerializedAdditionalLightData.targetObject;
Light light = (Light)target;
Color wireframeColorAbove = light.enabled ? LightEditor.kGizmoLight : LightEditor.kGizmoDisabledLight;
Color handleColorAbove = CoreLightEditorUtilities.GetLightHandleColor(wireframeColorAbove);
Color wireframeColorBehind = CoreLightEditorUtilities.GetLightBehindObjectWireframeColor(wireframeColorAbove);
Color handleColorBehind = CoreLightEditorUtilities.GetLightHandleColor(wireframeColorBehind);
switch (src.lightTypeExtent)
{
case LightTypeExtent.Punctual:
switch (light.type)
{
case LightType.Directional:
case LightType.Point:
base.OnSceneGUI(); //use legacy handles
break;
case LightType.Spot:
switch (src.spotLightShape)
{
case SpotLightShape.Cone:
CoreLightEditorUtilities.DrawSpotlightGizmo(light, src.GetInnerSpotPercent01(), true);
break;
case SpotLightShape.Pyramid:
using (new Handles.DrawingScope(Matrix4x4.TRS(light.transform.position, light.transform.rotation, Vector3.one)))
{
Vector4 aspectFovMaxRangeMinRange = new Vector4(src.aspectRatio, light.spotAngle, light.range);
Handles.zTest = UnityEngine.Rendering.CompareFunction.Greater;
Handles.color = wireframeColorBehind;
CoreLightEditorUtilities.DrawPyramidFrustumWireframe(aspectFovMaxRangeMinRange);
Handles.zTest = UnityEngine.Rendering.CompareFunction.LessEqual;
Handles.color = wireframeColorAbove;
CoreLightEditorUtilities.DrawPyramidFrustumWireframe(aspectFovMaxRangeMinRange);
EditorGUI.BeginChangeCheck();
Handles.zTest = UnityEngine.Rendering.CompareFunction.Greater;
Handles.color = handleColorBehind;
aspectFovMaxRangeMinRange = CoreLightEditorUtilities.DrawPyramidFrustumHandle(aspectFovMaxRangeMinRange, false);
Handles.zTest = UnityEngine.Rendering.CompareFunction.LessEqual;
Handles.color = handleColorAbove;
aspectFovMaxRangeMinRange = CoreLightEditorUtilities.DrawPyramidFrustumHandle(aspectFovMaxRangeMinRange, false);
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObjects(new UnityEngine.Object[] { target, src }, "Adjust Pyramid Spot Light");
src.aspectRatio = aspectFovMaxRangeMinRange.x;
light.spotAngle = aspectFovMaxRangeMinRange.y;
light.range = aspectFovMaxRangeMinRange.z;
}
// Handles.color reseted at end of scope
}
break;
case SpotLightShape.Box:
using (new Handles.DrawingScope(Matrix4x4.TRS(light.transform.position, light.transform.rotation, Vector3.one)))
{
Vector4 widthHeightMaxRangeMinRange = new Vector4(src.shapeWidth, src.shapeHeight, light.range);
Handles.zTest = UnityEngine.Rendering.CompareFunction.Greater;
Handles.color = wireframeColorBehind;
CoreLightEditorUtilities.DrawOrthoFrustumWireframe(widthHeightMaxRangeMinRange);
Handles.zTest = UnityEngine.Rendering.CompareFunction.LessEqual;
Handles.color = wireframeColorAbove;
CoreLightEditorUtilities.DrawOrthoFrustumWireframe(widthHeightMaxRangeMinRange);
EditorGUI.BeginChangeCheck();
Handles.zTest = UnityEngine.Rendering.CompareFunction.Greater;
Handles.color = handleColorBehind;
widthHeightMaxRangeMinRange = CoreLightEditorUtilities.DrawOrthoFrustumHandle(widthHeightMaxRangeMinRange, false);
Handles.zTest = UnityEngine.Rendering.CompareFunction.LessEqual;
Handles.color = handleColorAbove;
widthHeightMaxRangeMinRange = CoreLightEditorUtilities.DrawOrthoFrustumHandle(widthHeightMaxRangeMinRange, false);
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObjects(new UnityEngine.Object[] { target, src }, "Adjust Box Spot Light");
src.shapeWidth = widthHeightMaxRangeMinRange.x;
src.shapeHeight = widthHeightMaxRangeMinRange.y;
light.range = widthHeightMaxRangeMinRange.z;
}
// Handles.color reseted at end of scope
}
break;
}
break;
}
break;
}
}
void DrawFoldout(SerializedProperty foldoutProperty, string title, Action func)
{
CoreEditorUtils.DrawSplitter();

break;
}
}
}
[DrawGizmo(GizmoType.Selected | GizmoType.Active)]
static void DrawGizmoForHDAdditionalLightData(HDAdditionalLightData src, GizmoType gizmoType)
{
bool selected = (gizmoType & GizmoType.Selected) != 0;
var light = src.gameObject.GetComponent<Light>();
Color previousColor = Gizmos.color;
Gizmos.color = light.enabled ? LightEditor.kGizmoLight : LightEditor.kGizmoDisabledLight;
if (selected)
{
// Trace a ray down to better locate the light location
Ray ray = new Ray(src.gameObject.transform.position, Vector3.down);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
Handles.zTest = UnityEngine.Rendering.CompareFunction.LessEqual;
using (new Handles.DrawingScope(Color.green))
{
Handles.DrawLine(src.gameObject.transform.position, hit.point);
Handles.DrawWireDisc(hit.point, hit.normal, 0.5f);
}
Handles.zTest = UnityEngine.Rendering.CompareFunction.Greater;
using (new Handles.DrawingScope(Color.red))
{
Handles.DrawLine(src.gameObject.transform.position, hit.point);
Handles.DrawWireDisc(hit.point, hit.normal, 0.5f);
}
}
}
Gizmos.color = previousColor;
}
}
}

34
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/HDLightEditorUtilities.cs


using System;
using System.Reflection;
using UnityEditor;
using UnityEngine;
using UnityEngine.Experimental.Rendering.HDPipeline;
namespace UnityEditor.Experimental.Rendering.HDPipeline
{
public static class HDLightEditorUtilities
{
public static void DrawFrustumlightGizmo(Light frustumlight)
{
var additionalLightData = frustumlight.GetComponent<HDAdditionalLightData>();
if (additionalLightData == null)
return;
Matrix4x4 matrix = new Matrix4x4(frustumlight.transform.right, frustumlight.transform.up, frustumlight.transform.forward, frustumlight.transform.position);
Gizmos.matrix = matrix;
if (additionalLightData.spotLightShape == SpotLightShape.Pyramid)
{
CoreLightEditorUtilities.DrawLightPyramidFrustum(Vector3.zero, frustumlight.spotAngle, frustumlight.range, 0.0f, additionalLightData.aspectRatio);
}
else // Ortho frustum
{
//DrawLightOrthoFrustum(Vector3.zero, additionalLightData.shapeWidth, additionalLightData.shapeHeight, frustumlight.range, 0.0f);
Vector3 frustumCenter = new Vector3(0.0f, 0.0f, 0.5f * frustumlight.range);
Vector3 frustumsize = new Vector3(additionalLightData.shapeWidth, additionalLightData.shapeHeight, frustumlight.range);
Gizmos.DrawWireCube(frustumCenter, frustumsize);
}
Gizmos.matrix = Matrix4x4.identity;
}
}
}

11
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/HDLightEditorUtilities.cs.meta


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