#if UNITY_EDITOR using UnityEditor; #endif using UnityEngine.Serialization; namespace UnityEngine.Experimental.Rendering.HDPipeline { // 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 }; //@TODO: We should continuously move these values // into the engine when we can see them being generally useful [RequireComponent(typeof(Light))] public class HDAdditionalLightData : MonoBehaviour { [Range(0.0f, 100.0f)] [FormerlySerializedAs("m_innerSpotPercent")] public float m_InnerSpotPercent = 0.0f; // To display this field in the UI this need to be public public float GetInnerSpotPercent01() { return Mathf.Clamp(m_InnerSpotPercent, 0.0f, 100.0f) / 100.0f; } [Range(0.0f, 1.0f)] public float lightDimmer = 1.0f; // Not used for directional lights. public float fadeDistance = 10000.0f; public bool affectDiffuse = true; public bool affectSpecular = true; [FormerlySerializedAs("archetype")] public LightTypeExtent lightTypeExtent = LightTypeExtent.Punctual; // Only for Spotlight, should be hide for other light public SpotLightShape spotLightShape = SpotLightShape.Cone; // Only for Rectangle/Line/projector lights [Range(0.0f, 20.0f)] [FormerlySerializedAs("lightLength")] public float shapeLength = 0.5f; // Only for Rectangle/projector lights [Range(0.0f, 20.0f)] [FormerlySerializedAs("lightWidth")] public float shapeWidth = 0.5f; // Only for Sphere/Disc public float shapeRadius = 0.0f; // Only for Spot/Point - use to cheaply fake specular spherical area light [Range(0.0f, 1.0f)] public float maxSmoothness = 1.0f; // If true, we apply the smooth attenuation factor on the range attenuation to get 0 value, else the attenuation is just inverse square and never reach 0 public bool applyRangeAttenuation = true; // This is specific for the LightEditor GUI and not use at runtime public bool useOldInspector = false; public bool featuresFoldout = true; public bool showAdditionalSettings = true; // TODO: Maybe we can remove if if we decide to always show additional settings #if UNITY_EDITOR private void DrawGizmos(bool selected) { var light = gameObject.GetComponent(); var gizmoColor = light.color; gizmoColor.a = selected ? 1.0f : 0.3f; // Fade for the gizmo Gizmos.color = Handles.color = gizmoColor; if (lightTypeExtent == LightTypeExtent.Punctual) { 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; } } if (selected) { DrawVerticalRay(); } } // Trace a ray down to better locate the light location private void DrawVerticalRay() { Ray ray = new Ray(transform.position, Vector3.down); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { Handles.color = Color.green; Handles.zTest = UnityEngine.Rendering.CompareFunction.LessEqual; Handles.DrawLine(transform.position, hit.point); Handles.DrawWireDisc(hit.point, hit.normal, 0.5f); Handles.color = Color.red; Handles.zTest = UnityEngine.Rendering.CompareFunction.Greater; Handles.DrawLine(transform.position, hit.point); Handles.DrawWireDisc(hit.point, hit.normal, 0.5f); } } private void OnDrawGizmos() { // DrawGizmos(false); } private void OnDrawGizmosSelected() { DrawGizmos(true); } #endif } }