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;
        }
        protected override void OnSceneGUI()
        {
            if (!(GraphicsSettings.currentRenderPipeline is UniversalRenderPipelineAsset))
            {
                return;
            }

            if (!(target is Light light) || light == null)
            {
                return;
            }

            switch (light.type)
            {
            case LightType.Spot:
                using (new Handles.DrawingScope(Matrix4x4.TRS(light.transform.position, light.transform.rotation, Vector3.one)))
                {
                    CoreLightEditorUtilities.DrawSpotLightGizmo(light);
                }
                break;

            case LightType.Point:
                using (new Handles.DrawingScope(Matrix4x4.TRS(light.transform.position, Quaternion.identity, Vector3.one)))
                {
                    CoreLightEditorUtilities.DrawPointLightGizmo(light);
                }
                break;

            case LightType.Rectangle:
                using (new Handles.DrawingScope(Matrix4x4.TRS(light.transform.position, light.transform.rotation, Vector3.one)))
                {
                    CoreLightEditorUtilities.DrawRectangleLightGizmo(light);
                }
                break;

            case LightType.Disc:
                using (new Handles.DrawingScope(Matrix4x4.TRS(light.transform.position, light.transform.rotation, Vector3.one)))
                {
                    CoreLightEditorUtilities.DrawDiscLightGizmo(light);
                }
                break;

            case LightType.Directional:
                using (new Handles.DrawingScope(Matrix4x4.TRS(light.transform.position, light.transform.rotation, Vector3.one)))
                {
                    CoreLightEditorUtilities.DrawDirectionalLightGizmo(light);
                }
                break;

            default:
                base.OnSceneGUI();
                break;
            }
        }
示例#3
0
        public static void DrawHandles(HDAdditionalLightData additionalData, Editor owner)
        {
            Light light = additionalData.legacyLight;

            Color wireframeColorAbove  = (owner as HDLightEditor).legacyLightColor;
            Color handleColorAbove     = CoreLightEditorUtilities.GetLightHandleColor(wireframeColorAbove);
            Color wireframeColorBehind = CoreLightEditorUtilities.GetLightBehindObjectWireframeColor(wireframeColorAbove);
            Color handleColorBehind    = CoreLightEditorUtilities.GetLightHandleColor(wireframeColorBehind);

            switch (additionalData.lightTypeExtent)
            {
            case LightTypeExtent.Punctual:
                switch (light.type)
                {
                case LightType.Directional:
                case LightType.Point:
                    //use legacy handles for those cases:
                    //See HDLightEditor
                    break;

                case LightType.Spot:
                    switch (additionalData.spotLightShape)
                    {
                    case SpotLightShape.Cone:
                        using (new Handles.DrawingScope(Matrix4x4.TRS(light.transform.position, light.transform.rotation, Vector3.one)))
                        {
                            Vector3 outterAngleInnerAngleRange = new Vector3(light.spotAngle, light.spotAngle * additionalData.GetInnerSpotPercent01(), light.range);
                            Handles.zTest = UnityEngine.Rendering.CompareFunction.Greater;
                            Handles.color = wireframeColorBehind;
                            CoreLightEditorUtilities.DrawSpotlightWireframe(outterAngleInnerAngleRange, additionalData.shadowNearPlane);
                            Handles.zTest = UnityEngine.Rendering.CompareFunction.LessEqual;
                            Handles.color = wireframeColorAbove;
                            CoreLightEditorUtilities.DrawSpotlightWireframe(outterAngleInnerAngleRange, additionalData.shadowNearPlane);
                            EditorGUI.BeginChangeCheck();
                            Handles.zTest = UnityEngine.Rendering.CompareFunction.Greater;
                            Handles.color = handleColorBehind;
                            outterAngleInnerAngleRange = CoreLightEditorUtilities.DrawSpotlightHandle(outterAngleInnerAngleRange);
                            Handles.zTest = UnityEngine.Rendering.CompareFunction.LessEqual;
                            Handles.color = handleColorAbove;
                            outterAngleInnerAngleRange = CoreLightEditorUtilities.DrawSpotlightHandle(outterAngleInnerAngleRange);
                            if (EditorGUI.EndChangeCheck())
                            {
                                Undo.RecordObjects(new UnityEngine.Object[] { light, additionalData }, "Adjust Cone Spot Light");
                                additionalData.m_InnerSpotPercent = 100f * outterAngleInnerAngleRange.y / outterAngleInnerAngleRange.x;
                                light.spotAngle = outterAngleInnerAngleRange.x;
                                light.range     = outterAngleInnerAngleRange.z;
                            }

                            // Handles.color reseted at end of scope
                        }
                        break;

                    case SpotLightShape.Pyramid:
                        using (new Handles.DrawingScope(Matrix4x4.TRS(light.transform.position, light.transform.rotation, Vector3.one)))
                        {
                            Vector4 aspectFovMaxRangeMinRange = new Vector4(additionalData.aspectRatio, light.spotAngle, light.range);
                            Handles.zTest = UnityEngine.Rendering.CompareFunction.Greater;
                            Handles.color = wireframeColorBehind;
                            CoreLightEditorUtilities.DrawPyramidFrustumWireframe(aspectFovMaxRangeMinRange, additionalData.shadowNearPlane);
                            Handles.zTest = UnityEngine.Rendering.CompareFunction.LessEqual;
                            Handles.color = wireframeColorAbove;
                            CoreLightEditorUtilities.DrawPyramidFrustumWireframe(aspectFovMaxRangeMinRange, additionalData.shadowNearPlane);
                            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[] { light, additionalData }, "Adjust Pyramid Spot Light");
                                additionalData.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(additionalData.shapeWidth, additionalData.shapeHeight, light.range);
                            Handles.zTest = UnityEngine.Rendering.CompareFunction.Greater;
                            Handles.color = wireframeColorBehind;
                            CoreLightEditorUtilities.DrawOrthoFrustumWireframe(widthHeightMaxRangeMinRange, additionalData.shadowNearPlane);
                            Handles.zTest = UnityEngine.Rendering.CompareFunction.LessEqual;
                            Handles.color = wireframeColorAbove;
                            CoreLightEditorUtilities.DrawOrthoFrustumWireframe(widthHeightMaxRangeMinRange, additionalData.shadowNearPlane);
                            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[] { light, additionalData }, "Adjust Box Spot Light");
                                additionalData.shapeWidth  = widthHeightMaxRangeMinRange.x;
                                additionalData.shapeHeight = widthHeightMaxRangeMinRange.y;
                                light.range = widthHeightMaxRangeMinRange.z;
                            }

                            // Handles.color reseted at end of scope
                        }
                        break;
                    }
                    break;
                }
                break;

            case LightTypeExtent.Rectangle:
            case LightTypeExtent.Tube:
                bool withYAxis = additionalData.lightTypeExtent == LightTypeExtent.Rectangle;
                using (new Handles.DrawingScope(Matrix4x4.TRS(light.transform.position, light.transform.rotation, Vector3.one)))
                {
                    Vector2 widthHeight = new Vector4(additionalData.shapeWidth, withYAxis ? additionalData.shapeHeight : 0f);
                    float   range       = light.range;
                    EditorGUI.BeginChangeCheck();
                    Handles.zTest = UnityEngine.Rendering.CompareFunction.Greater;
                    Handles.color = wireframeColorBehind;
                    CoreLightEditorUtilities.DrawAreaLightWireframe(widthHeight);
                    range         = Handles.RadiusHandle(Quaternion.identity, Vector3.zero, range); //also draw handles
                    Handles.zTest = UnityEngine.Rendering.CompareFunction.LessEqual;
                    Handles.color = wireframeColorAbove;
                    CoreLightEditorUtilities.DrawAreaLightWireframe(widthHeight);
                    range         = Handles.RadiusHandle(Quaternion.identity, Vector3.zero, range); //also draw handles
                    Handles.zTest = UnityEngine.Rendering.CompareFunction.Greater;
                    Handles.color = handleColorBehind;
                    widthHeight   = CoreLightEditorUtilities.DrawAreaLightHandle(widthHeight, withYAxis);
                    Handles.zTest = UnityEngine.Rendering.CompareFunction.LessEqual;
                    Handles.color = handleColorAbove;
                    widthHeight   = CoreLightEditorUtilities.DrawAreaLightHandle(widthHeight, withYAxis);
                    widthHeight   = Vector2.Max(Vector2.one * k_MinLightSize, widthHeight);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObjects(new UnityEngine.Object[] { light, additionalData }, withYAxis ? "Adjust Area Rectangle Light" : "Adjust Area Tube Light");
                        additionalData.shapeWidth = widthHeight.x;
                        if (withYAxis)
                        {
                            additionalData.shapeHeight = widthHeight.y;
                        }
                        light.range = range;
                    }

                    // Handles.color reseted at end of scope
                }
                break;
            }
        }
示例#4
0
        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:
                        using (new Handles.DrawingScope(Matrix4x4.TRS(light.transform.position, light.transform.rotation, Vector3.one)))
                        {
                            Vector3 outterAngleInnerAngleRange = new Vector3(light.spotAngle, light.spotAngle * src.GetInnerSpotPercent01(), light.range);
                            Handles.zTest = UnityEngine.Rendering.CompareFunction.Greater;
                            Handles.color = wireframeColorBehind;
                            CoreLightEditorUtilities.DrawSpotlightWireframe(outterAngleInnerAngleRange, light.shadowNearPlane);
                            Handles.zTest = UnityEngine.Rendering.CompareFunction.LessEqual;
                            Handles.color = wireframeColorAbove;
                            CoreLightEditorUtilities.DrawSpotlightWireframe(outterAngleInnerAngleRange, light.shadowNearPlane);
                            EditorGUI.BeginChangeCheck();
                            Handles.zTest = UnityEngine.Rendering.CompareFunction.Greater;
                            Handles.color = handleColorBehind;
                            outterAngleInnerAngleRange = CoreLightEditorUtilities.DrawSpotlightHandle(outterAngleInnerAngleRange);
                            Handles.zTest = UnityEngine.Rendering.CompareFunction.LessEqual;
                            Handles.color = handleColorAbove;
                            outterAngleInnerAngleRange = CoreLightEditorUtilities.DrawSpotlightHandle(outterAngleInnerAngleRange);
                            if (EditorGUI.EndChangeCheck())
                            {
                                Undo.RecordObjects(new UnityEngine.Object[] { target, src }, "Adjust Cone Spot Light");
                                src.m_InnerSpotPercent = 100f * outterAngleInnerAngleRange.y / outterAngleInnerAngleRange.x;
                                light.spotAngle        = outterAngleInnerAngleRange.x;
                                light.range            = outterAngleInnerAngleRange.z;
                            }

                            // Handles.color reseted at end of scope
                        }
                        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;
            }
        }
示例#5
0
        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);
                }
            }
        }