internal void SetupRenderPipelinePreviewLight(Light light)
        {
            HDLightTypeAndShape hdLightTypeAndShape = (light.type == LightType.Point) ? HDLightTypeAndShape.Point : HDLightTypeAndShape.ConeSpot;

            HDAdditionalLightData hdLight = GameObjectExtension.AddHDLight(light.gameObject, hdLightTypeAndShape);

            hdLight.SetIntensity(20000f, LightUnit.Lumen);

            hdLight.affectDiffuse     = true;
            hdLight.affectSpecular    = false;
            hdLight.affectsVolumetric = false;
        }
 private void OnEnable()
 {
     //lightAnimations = GetComponents<LightEventAnimation>();
     if (gameObject.GetComponent <HDAdditionalLightData>())
     {
         additionalLightData = gameObject.GetComponent <HDAdditionalLightData>();
     }
     else if (gameObject.GetComponent <MaterialEmissionOverride>())
     {
         matBlockHandler = gameObject.GetComponent <MaterialEmissionOverride>();
     }
 }
 private void OnEnable()
 {
     lightAnimations = GetComponents <LightEventAnimation>();
     if (gameObject.GetComponent <HDAdditionalLightData>())
     {
         additionalLightData = gameObject.GetComponent <HDAdditionalLightData>();
     }
     else if (gameObject.GetComponent <MaterialEmissionDimmer>())
     {
         matEmissionDimmer = gameObject.GetComponent <MaterialEmissionDimmer>();
     }
 }
Beispiel #4
0
    public void SetUP( )
    {
        sunData = sun.gameObject.GetComponent <HDAdditionalLightData>();
        moduleList.Clear();
        moduleList.AddRange(GetComponents <DNModuleBase>());

        foreach (DNModuleBase module in moduleList)
        {
            module.SetUp();
        }

        NormalTimeCurve();
    }
Beispiel #5
0
        /// <summary>
        ///  Add a new HDRP Light to a GameObject
        /// </summary>
        /// <param name="gameObject">The GameObject on which the light is going to be added</param>
        /// <param name="lightTypeAndShape">The Type of the HDRP light to Add</param>
        /// <returns>The created HDRP Light component</returns>
        public static HDAdditionalLightData AddHDLight(this GameObject gameObject, HDLightTypeAndShape lightTypeAndShape)
        {
            var hdLight = gameObject.AddComponent <HDAdditionalLightData>();

            HDAdditionalLightData.InitDefaultHDAdditionalLightData(hdLight);

            // Reflector have been change to true by default in the UX, however to not break compatibility
            // with previous 2020.2 project that use light scripting we must keep reflector to false for scripted light
            hdLight.enableSpotReflector = false;
            hdLight.SetLightTypeAndShape(lightTypeAndShape);

            return(hdLight);
        }
Beispiel #6
0
    // -------------- Start ----------------
    void Start()
    {
        // Retrieve gameobjects / components
        thisTrans    = gameObject.transform;
        thisLight    = gameObject.GetComponent <Light>();
        thisLightHD  = gameObject.GetComponent <HDAdditionalLightData>();
        cam          = Camera.main;
        _eyetracking = conditionScript.EyeTracking;

        // Set initial variables
        mainTimer = mainBaseTimer;
        turnTime  = resetTurnTime;
    }
Beispiel #7
0
 void OnDestroy()
 {
     GameObject.Destroy(this.lightObject);
     this.lightObject         = null;
     this.skyDirectionalLight = null;
     this.hdLight             = null;
     this.timer        = null;
     this.dayFlare     = null;
     this.nightFlare   = null;
     this.volume       = null;
     this.pbsky        = null;
     this.clouds       = null;
     this.whiteBalance = null;
 }
Beispiel #8
0
        //[MenuItem("Internal/HDRP/Add \"Additional Light-shadow Data\" (if not present)")]
        static void AddAdditionalLightData()
        {
            var lights = UnityObject.FindObjectsOfType(typeof(Light)) as Light[];

            foreach (var light in lights)
            {
                // Do not add a component if there already is one.
                if (!light.TryGetComponent <HDAdditionalLightData>(out _))
                {
                    var hdLight = light.gameObject.AddComponent <HDAdditionalLightData>();
                    HDAdditionalLightData.InitDefaultHDAdditionalLightData(hdLight);
                }
            }
        }
        internal void SetupRenderPipelinePreviewLightIntensity(Light light, SerializedProperty useIESMaximumIntensityProp, SerializedProperty iesMaximumIntensityUnitProp, SerializedProperty iesMaximumIntensityProp)
        {
            HDAdditionalLightData hdLight = light.GetComponent <HDAdditionalLightData>();

            if (useIESMaximumIntensityProp.boolValue)
            {
                LightUnit lightUnit = (iesMaximumIntensityUnitProp.stringValue == "Lumens") ? LightUnit.Lumen : LightUnit.Candela;
                hdLight.SetIntensity(iesMaximumIntensityProp.floatValue, lightUnit);
            }
            else
            {
                hdLight.SetIntensity(20000f, LightUnit.Lumen);
            }
        }
Beispiel #10
0
        /// <summary>
        /// Gets or creates HD Light data
        /// </summary>
        /// <param name="light"></param>
        /// <returns></returns>
        public static HDAdditionalLightData GetHDLightData(Light light)
        {
            if (light == null)
            {
                return(null);
            }

            HDAdditionalLightData lightData = light.GetComponent <HDAdditionalLightData>();

            if (lightData == null)
            {
                lightData = light.gameObject.AddComponent <HDAdditionalLightData>();
            }

            return(lightData);
        }
Beispiel #11
0
 static void DrawGeneralAdvancedContent(SerializedHDLight serialized, Editor owner)
 {
     using (new EditorGUI.DisabledScope(!HDUtils.hdrpSettings.supportLightLayers))
     {
         var renderingLayerMask = serialized.serializedLightData.renderingLayerMask.intValue;
         var lightLayer = HDAdditionalLightData.RenderingLayerMaskToLightLayer(renderingLayerMask);
         EditorGUI.BeginChangeCheck();
         lightLayer = Convert.ToInt32(EditorGUILayout.EnumFlagsField(s_Styles.lightLayer, (LightLayerEnum)lightLayer));
         if (EditorGUI.EndChangeCheck())
         {
             // Overwrite only first byte
             lightLayer = HDAdditionalLightData.LightLayerToRenderingLayerMask(lightLayer, renderingLayerMask);
             serialized.serializedLightData.renderingLayerMask.intValue = lightLayer;
         }
     }
 }
        protected override void OnSceneGUI()
        {
            // Each handles manipulate only one light
            // Thus do not rely on serialized properties
            Light light = target as Light;
            HDAdditionalLightData additionalLightData = targetAdditionalData;

            if (additionalLightData.lightTypeExtent == LightTypeExtent.Punctual && (light.type == LightType.Directional || light.type == LightType.Point))
            {
                base.OnSceneGUI();
            }
            else
            {
                HDLightUI.DrawHandles(additionalLightData, this);
            }
        }
Beispiel #13
0
        protected override void OnSceneGUI()
        {
            m_SerializedHDLight.Update();


            HDAdditionalLightData src = (HDAdditionalLightData)m_SerializedHDLight.serializedLightDatas.targetObject;
            Light light = (Light)target;

            if (src.lightTypeExtent == LightTypeExtent.Punctual && (light.type == LightType.Directional || light.type == LightType.Point))
            {
                //use legacy handles
                base.OnSceneGUI();
                return;
            }

            HDLightUI.DrawHandles(m_SerializedHDLight, this);
        }
        /// <summary>
        /// Displays or hide an emissive mesh for the area light
        /// </summary>
        /// <param name="hdLight"></param>
        /// <param name="display"></param>
        public static void SetDisplayAreaLightEmissiveMesh(this HDAdditionalLightData hdLight, bool display)
        {
            if (hdLight.displayAreaLightEmissiveMesh == display)
            {
                return;
            }

            if (display)
            {
                // fix the local scale to match the emissive quad size
                hdLight.transform.localScale = new Vector3(hdLight.shapeWidth, hdLight.shapeHeight, HDAdditionalLightData.k_MinAreaWidth);
            }

            hdLight.displayAreaLightEmissiveMesh = display;

            hdLight.UpdateEmissiveMeshComponents();
        }
Beispiel #15
0
    public override void Init()
    {
        Transform hpHolo = transform.Find(string.Format("{0}/hp_hologram", C.Name));

        if (hpHolo != null)
        {
            GameObject holoPrefab = Resources.Load <GameObject>("cp_holo");
            GameObject holo       = Instantiate(holoPrefab, hpHolo);
            HoloRay = holo.GetComponent <LineRenderer>();
            Light   = holo.GetComponentInChildren <HDAdditionalLightData>();

            HoloWidthStart = HoloRay.startWidth;
            HoloWidthEnd   = HoloRay.endWidth;
            HoloAlpha      = HoloRay.material.GetColor("_UnlitColor").a;
            LightIntensity = Light.intensity;
        }

        AudioAmbient = gameObject.AddComponent <AudioSource>();
        AudioAmbient.spatialBlend = 1.0f;
        AudioAmbient.clip         = SoundLoader.LoadSound("com_blg_commandpost2");
        AudioAmbient.pitch        = 1.0f;
        AudioAmbient.volume       = 0.5f;
        AudioAmbient.rolloffMode  = AudioRolloffMode.Linear;
        AudioAmbient.minDistance  = 2.0f;
        AudioAmbient.maxDistance  = 30.0f;
        AudioAmbient.Play();

        AudioCapture = gameObject.AddComponent <AudioSource>();
        AudioCapture.spatialBlend = 1.0f;
        AudioCapture.loop         = true;
        AudioCapture.pitch        = 1.0f;
        AudioCapture.volume       = 0.8f;
        AudioCapture.rolloffMode  = AudioRolloffMode.Linear;
        AudioCapture.minDistance  = 2.0f;
        AudioCapture.maxDistance  = 30.0f;

        AudioAction = gameObject.AddComponent <AudioSource>();
        AudioAction.spatialBlend = 1.0f;
        AudioAction.loop         = false;
        AudioAction.pitch        = 1.1f;
        AudioAction.volume       = 0.5f;
        AudioAction.rolloffMode  = AudioRolloffMode.Linear;
        AudioAction.minDistance  = 2.0f;
        AudioAction.maxDistance  = 30.0f;
    }
        static void ResetLight(MenuCommand menuCommand)
        {
            GameObject go = ((Light)menuCommand.context).gameObject;

            Assert.IsNotNull(go);

            Light light = go.GetComponent <Light>();
            HDAdditionalLightData lightAdditionalData = go.GetComponent <HDAdditionalLightData>();

            Assert.IsNotNull(light);
            Assert.IsNotNull(lightAdditionalData);

            Undo.RecordObjects(new UnityEngine.Object[] { light, lightAdditionalData }, "Reset HD Light");
            light.Reset();
            // To avoid duplicating init code we copy default settings to Reset additional data
            // Note: we can't call this code inside the HDAdditionalLightData, thus why we don't wrap it in a Reset() function
            HDUtils.s_DefaultHDAdditionalLightData.CopyTo(lightAdditionalData);
        }
    void CreateSunlight()
    {
        if (sunlight == null)
        {
            sunlight = new GameObject("DirectionalLight");
            //Init defaults
            sunlightParameters = new SunlightParameters();
            sunlightParameters.lightParameters.type = LightType.Directional;
        }

        sunlight.transform.parent        = sunlightTimeofdayDummy.transform;
        sunlight.transform.localPosition = -Vector3.forward * gizmoSize;

        directionalLight    = sunlight.GetComponent <Light>() ?? sunlight.AddComponent <Light>();
        additionalLightData = sunlight.GetComponent <HDAdditionalLightData>() ?? sunlight.AddComponent <HDAdditionalLightData>();
        shadowData          = sunlight.GetComponent <AdditionalShadowData>() ?? sunlight.AddComponent <AdditionalShadowData>();

        directionalLight.type = LightType.Directional;
    }
Beispiel #18
0
        static void CreateLights(float[] floatParameters, string extraType)
        {
            GameObject newLightGo = new GameObject("custom " + extraType);
            var        newLight   = newLightGo.AddHDLight(HDLightTypeAndShape.ConeSpot);

            newLight.intensity = 10f;
            newLight.range     = 150f;
            newLight.color     = Color.white;
            newLight.EnableColorTemperature(true);
            switch (extraType)
            {
            case "spotlight":
                newLight.type = HDLightType.Spot;
                newLight.SetSpotAngle(floatParameters[10]);
                newLight.SetIntensity(floatParameters[6] * 1700);
                newLight.SetColor(new Color(floatParameters[7], floatParameters[8], floatParameters[9]), 5500f);
                newLightGo.transform.position = new Vector3(-floatParameters[0], floatParameters[2], -floatParameters[1]);
                newLightGo.transform.parent   = allLights.transform;
                Rotate(newLightGo, floatParameters);
                Debug.Log("Created Spotlight" + " x: " + newLightGo.transform.position.x + " y: " + newLightGo.transform.position.y + " z: " + newLightGo.transform.position.z);
                break;

            case "sunlight":
                newLightGo = GameObject.Find("sunlight");
                HDAdditionalLightData sunLight = newLightGo.GetComponent <HDAdditionalLightData>();
                sunLight.SetIntensity(floatParameters[6]);
                sunLight.SetColor(new Color(floatParameters[7], floatParameters[8], floatParameters[9]), 5500f);
                newLightGo.transform.position = new Vector3(-floatParameters[0], floatParameters[2], -floatParameters[1]);
                Rotate(newLightGo, floatParameters);
                Debug.Log("Created Sun" + " x: " + newLightGo.transform.position.x + " y: " + newLightGo.transform.position.y + " z: " + newLightGo.transform.position.z);
                break;

            case "pointlight":
                newLight.type = HDLightType.Point;
                newLight.SetIntensity(floatParameters[3] * 700);
                newLight.SetColor(new Color(floatParameters[4], floatParameters[5], floatParameters[6]), 5500f);
                newLightGo.transform.position = new Vector3(-floatParameters[0], floatParameters[2], -floatParameters[1]);
                newLightGo.transform.parent   = allLights.transform;
                Debug.Log("Created Pointlight" + " x: " + newLightGo.transform.position.x + " y: " + newLightGo.transform.position.y + " z: " + newLightGo.transform.position.z);
                break;
            }
        }
Beispiel #19
0
        public override void Start()
        {
            GetCookies();

            var camera = cameraController.mainCamera;

            light = gameObject.AddComponent <Light>();

            additionalLightData = gameObject.AddComponent <HDAdditionalLightData>();
            additionalLightData.volumetricDimmer = 0;

            light.type      = LightType.Spot;
            light.color     = LIGHT_COLOR;
            light.intensity = LIGHT_INTENSITY;
            light.range     = LIGHT_RANGE;
            light.spotAngle = LIGHT_ANGLE;
            light.cookie    = LIGHT_COOKIE == null ? null : Cookies[LIGHT_COOKIE];

            Logger.Log("Light started");
        }
Beispiel #20
0
        internal void SetupRenderPipelinePrefabLight(IESEngine engine, Light light, Texture ies)
        {
            HDLightTypeAndShape hdLightTypeAndShape = (light.type == LightType.Point) ? HDLightTypeAndShape.Point : HDLightTypeAndShape.ConeSpot;

            HDAdditionalLightData hdLight = GameObjectExtension.AddHDLight(light.gameObject, hdLightTypeAndShape);

            if (commonIESImporter.iesMetaData.UseIESMaximumIntensity)
            {
                LightUnit lightUnit = (commonIESImporter.iesMetaData.IESMaximumIntensityUnit == "Lumens") ? LightUnit.Lumen : LightUnit.Candela;
                hdLight.SetIntensity(commonIESImporter.iesMetaData.IESMaximumIntensity, lightUnit);
                if (light.type == LightType.Point)
                {
                    hdLight.IESPoint = ies;
                }
                else
                {
                    hdLight.IESSpot = ies;
                }
            }
        }
Beispiel #21
0
        private void Init()
        {
            if (lightData == null)
            {
                _lightObject = transform.GetComponentInChildren <Light>(true);
                lightData    = transform.GetComponentInChildren <HDAdditionalLightData>(true);

                // Init defaults
                lightData.shadowNearPlane = 0.01f;
                CastShadows = false;
                Color       = Color.white;
                switch (_lightObject.type)
                {
                case LightType.Directional:
                    Intensity    = 2f;
                    minIntensity = 0.0f;
                    maxIntensity = 10.0f;
                    break;

                case LightType.Point:
                    Intensity    = 50f;
                    minIntensity = 0.0f;
                    maxIntensity = 100.0f;
                    Range        = 10f;
                    minRange     = 0f;
                    maxRange     = 100f;
                    break;

                case LightType.Spot:
                    Intensity    = 50f;
                    minIntensity = 0.0f;
                    maxIntensity = 100.0f;
                    Range        = 2f;
                    minRange     = 0f;
                    maxRange     = 100f;
                    Sharpness    = 80f;
                    OuterAngle   = 100f;
                    break;
                }
            }
        }
Beispiel #22
0
        private static void UpdateUnityHdData(HDAdditionalLightData unityHdData, AdditionalShadowData unityShadowData, HDLightData hdData)
        {
            unityHdData.lightTypeExtent       = hdData.lightTypeExtent;
            unityHdData.lightDimmer           = hdData.lightDimmer;
            unityHdData.fadeDistance          = hdData.fadeDistance;
            unityHdData.affectDiffuse         = hdData.affectDiffuse;
            unityHdData.affectSpecular        = hdData.affectSpecular;
            unityHdData.shapeWidth            = hdData.shapeWidth;
            unityHdData.shapeHeight           = hdData.shapeHeight;
            unityHdData.aspectRatio           = hdData.aspectRatio;
            unityHdData.shapeRadius           = hdData.shapeRadius;
            unityHdData.maxSmoothness         = hdData.maxSmoothness;
            unityHdData.applyRangeAttenuation = hdData.applyRangeAttenuation;

            // Spot light specific
            // NOTE: Can't add branch here, because HD light doesn't itself know whether it's a spot. That's stored in Unity.Light.
            unityHdData.enableSpotReflector = hdData.enableSpotReflector;
            unityHdData.m_InnerSpotPercent  = hdData.innerSpotPercent;
            unityHdData.spotLightShape      = hdData.spotLightShape;

            // Intensity is a property. It setups lots of things and assumes data is already set. Must be called last!
            unityHdData.intensity = hdData.intensity;

            // HDShadowData
            unityShadowData.shadowResolution       = hdData.shadowResolution;
            unityShadowData.shadowDimmer           = hdData.shadowDimmer;
            unityShadowData.volumetricShadowDimmer = hdData.volumetricShadowDimmer;
            unityShadowData.shadowFadeDistance     = hdData.shadowFadeDistance;
            unityShadowData.contactShadows         = hdData.contactShadows;
            unityShadowData.viewBiasMin            = hdData.viewBiasMin;
            unityShadowData.viewBiasMax            = hdData.viewBiasMax;
            unityShadowData.viewBiasScale          = hdData.viewBiasScale;
            unityShadowData.normalBiasMin          = hdData.normalBiasMin;
            unityShadowData.normalBiasMax          = hdData.normalBiasMax;
            unityShadowData.normalBiasScale        = hdData.normalBiasScale;
            unityShadowData.sampleBiasScale        = hdData.sampleBiasScale;
            unityShadowData.edgeLeakFixup          = hdData.edgeLeakFixup;
            unityShadowData.edgeToleranceNormal    = hdData.edgeToleranceNormal;
            unityShadowData.edgeTolerance          = hdData.edgeTolerance;
        }
    void OnValidate()
    {
        if (targetLight == null)
        {
            targetLight = GetComponent <Light>();
        }
        if (targetLight == null)
        {
            return;
        }
        if (hdLightData == null)
        {
            hdLightData = GetComponent <HDAdditionalLightData>();
        }
        if (hdLightData == null)
        {
            return;
        }

        if (mode == Mode.Distance)
        {
            float t = targetRadius / distance;
            angle = Mathf.Atan(t) * Mathf.Rad2Deg * 2f;
        }
        else
        {
            float t = Mathf.Tan(Mathf.Deg2Rad * angle * 0.5f);
            distance = targetRadius / t;
        }

        float sphereRadius = targetRadius / Mathf.Sin(Mathf.Deg2Rad * angle * 0.5f);

        targetLight.spotAngle   = angle;
        targetLight.range       = sphereRadius + additionalRange;
        transform.localPosition = -sphereRadius * Vector3.forward;

        hdLightData.intensity = referenceIntensity * Mathf.Pow(sphereRadius / referenceDistance, 2f);
    }
Beispiel #24
0
        /// <summary>
        /// Describe how to create an Prefab for the current SRP, have to be reimplemented for each SRP.
        /// </summary>
        /// <param name="ctx">Context used from the asset importer</param>
        /// <param name="iesFileName">Filename of the current IES file</param>
        /// <param name="useIESMaximumIntensity">True if uses the internal Intensity from the file</param>
        /// <param name="iesMaximumIntensityUnit">The string of the units described by the intensity</param>
        /// <param name="iesMaximumIntensity">Intensity</param>
        /// <param name="light">Light used for the prefab</param>
        /// <param name="ies">Texture used for the prefab</param>
        /// <returns></returns>
        static public void CreateRenderPipelinePrefabLight(AssetImportContext ctx, string iesFileName, bool useIESMaximumIntensity, string iesMaximumIntensityUnit, float iesMaximumIntensity, Light light, Texture ies)
        {
            HDLightTypeAndShape hdLightTypeAndShape = (light.type == LightType.Point) ? HDLightTypeAndShape.Point : HDLightTypeAndShape.ConeSpot;

            HDAdditionalLightData hdLight = GameObjectExtension.AddHDLight(light.gameObject, hdLightTypeAndShape);

            if (useIESMaximumIntensity)
            {
                LightUnit lightUnit = (iesMaximumIntensityUnit == "Lumens") ? LightUnit.Lumen : LightUnit.Candela;
                hdLight.SetIntensity(iesMaximumIntensity, lightUnit);
                if (light.type == LightType.Point)
                {
                    hdLight.IESPoint = ies;
                }
                else
                {
                    hdLight.IESSpot = ies;
                }
            }

            // The light object will be automatically converted into a prefab.
            ctx.AddObjectToAsset(iesFileName + "-HDRP", light.gameObject);
        }
Beispiel #25
0
        /// <summary>Provide a specific property drawer for LightLayer (without label)</summary>
        /// <param name="rect">The rect where to draw</param>
        /// <param name="property">The SerializedProperty (representing an int that should be displayed as a LightLayer)</param>
        public static void LightLayerMaskPropertyDrawer(Rect rect, SerializedProperty property)
        {
            var renderingLayerMask = property.intValue;
            int lightLayer;

            if (property.hasMultipleDifferentValues)
            {
                EditorGUI.showMixedValue = true;
                lightLayer = 0;
            }
            else
            {
                lightLayer = HDAdditionalLightData.RenderingLayerMaskToLightLayer(renderingLayerMask);
            }
            EditorGUI.BeginChangeCheck();
            lightLayer = System.Convert.ToInt32(EditorGUI.EnumFlagsField(rect, (LightLayerEnum)lightLayer));
            if (EditorGUI.EndChangeCheck())
            {
                lightLayer        = HDAdditionalLightData.LightLayerToRenderingLayerMask(lightLayer, renderingLayerMask);
                property.intValue = lightLayer;
            }
            EditorGUI.showMixedValue = false;
        }
Beispiel #26
0
        internal static void SetTypeFromLegacy(this HDAdditionalLightData lightData, LightType legacyLightType)
        {
            switch (legacyLightType)
            {
            case LightType.Directional: {
                lightData.type = HDLightType.Directional;
                break;
            }

            case LightType.Spot: {
                lightData.type = HDLightType.Spot;
                break;
            }

            case LightType.Point: {
                lightData.type = HDLightType.Point;
                break;
            }

            case LightType.Disc: {
                lightData.type           = HDLightType.Area;
                lightData.areaLightShape = AreaLightShape.Disc;
                break;
            }

            case LightType.Area: {
                lightData.type           = HDLightType.Area;
                lightData.areaLightShape = AreaLightShape.Rectangle;
                break;
            }

            default: {
                Debug.LogWarning($"[MeshSync] Unsupported legacy light type: {legacyLightType}");
                break;
            };
            }
        }
        public void Start()
        {
            GetCookies();

            light = gameObject.AddComponent <Light>();

            additionalLightData = gameObject.AddComponent <HDAdditionalLightData>();
            //additionalLightData.intensity = 100;
            additionalLightData.lightUnit = LightUnit.Ev100;
            //additionalLightData.lightDimmer = 0;
            additionalLightData.volumetricDimmer = 0;

            light.type = LightType.Spot;

            light.color = LIGHT_COLOR;
            additionalLightData.intensity = LIGHT_INTENSITY;
            //light.intensity = LIGHT_INTENSITY;
            light.intensity = LIGHT_INTENSITY;
            light.range     = LIGHT_RANGE;
            light.spotAngle = LIGHT_ANGLE;
            light.cookie    = LIGHT_COOKIE == null ? null : Cookies[LIGHT_COOKIE];

            Main.Logger.Log("Light started");
        }
Beispiel #28
0
        static void DrawGizmoForHDAdditionalLightData(HDAdditionalLightData src, GizmoType gizmoType)
        {
            if (!(UnityEngine.Rendering.GraphicsSettings.currentRenderPipeline is HDRenderPipelineAsset))
            {
                return;
            }

            if (src.type != HDLightType.Directional)
            {
                // 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);
                    }
                }

                if ((ShaderConfig.s_BarnDoor == 1) && (src.type == HDLightType.Area && src.barnDoorAngle < 89.0f))
                {
                    // Convert the angle to randians
                    float angle = src.barnDoorAngle * Mathf.PI / 180.0f;

                    // Compute the depth of the pyramid
                    float depth = src.barnDoorLength * Mathf.Cos(angle);

                    // Evaluate the half dimensions of the rectangular area light
                    float halfWidth  = src.shapeWidth * 0.5f;
                    float halfHeight = src.shapeHeight * 0.5f;

                    // Evaluate the dimensions of the extended area light
                    float extendedWidth  = Mathf.Tan(angle) * depth + halfWidth;
                    float extendedHeight = Mathf.Tan(angle) * depth + halfHeight;

                    // Compute all the points of the pyramid
                    Vector3 pos00 = src.transform.position + halfWidth * src.transform.right + halfHeight * src.transform.up;
                    Vector3 pos10 = src.transform.position - halfWidth * src.transform.right + halfHeight * src.transform.up;
                    Vector3 pos20 = src.transform.position - halfWidth * src.transform.right - halfHeight * src.transform.up;
                    Vector3 pos30 = src.transform.position + halfWidth * src.transform.right - halfHeight * src.transform.up;
                    Vector3 pos01 = src.transform.position + src.transform.forward * depth + src.transform.right * extendedWidth + src.transform.up * extendedHeight;
                    Vector3 pos11 = src.transform.position + src.transform.forward * depth - src.transform.right * extendedWidth + src.transform.up * extendedHeight;
                    Vector3 pos21 = src.transform.position + src.transform.forward * depth - src.transform.right * extendedWidth - src.transform.up * extendedHeight;
                    Vector3 pos31 = src.transform.position + src.transform.forward * depth + src.transform.right * extendedWidth - src.transform.up * extendedHeight;

                    // Draw the pyramid
                    Debug.DrawLine(pos00, pos01, Color.yellow);
                    Debug.DrawLine(pos10, pos11, Color.yellow);
                    Debug.DrawLine(pos20, pos21, Color.yellow);
                    Debug.DrawLine(pos30, pos31, Color.yellow);
                    Debug.DrawLine(pos01, pos11, Color.yellow);
                    Debug.DrawLine(pos11, pos21, Color.yellow);
                    Debug.DrawLine(pos21, pos31, Color.yellow);
                    Debug.DrawLine(pos31, pos01, Color.yellow);
                }
            }
        }
Beispiel #29
0
        public static void DrawHandles(HDAdditionalLightData additionalData, Editor owner)
        {
            Light light           = additionalData.legacyLight;
            float shadowNearPlane = light.shadows != LightShadows.None ? additionalData.shadowNearPlane : 0.0f;

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

            switch (additionalData.type)
            {
            case HDLightType.Directional:
            case HDLightType.Point:
                //use legacy handles for those cases:
                //See HDLightEditor
                break;

            case HDLightType.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.innerSpotPercent01, light.range);
                        Handles.zTest = UnityEngine.Rendering.CompareFunction.Greater;
                        Handles.color = wireframeColorBehind;
                        DrawSpotlightWireframe(outterAngleInnerAngleRange, shadowNearPlane);
                        Handles.zTest = UnityEngine.Rendering.CompareFunction.LessEqual;
                        Handles.color = wireframeColorAbove;
                        DrawSpotlightWireframe(outterAngleInnerAngleRange, shadowNearPlane);
                        EditorGUI.BeginChangeCheck();
                        Handles.zTest = UnityEngine.Rendering.CompareFunction.Greater;
                        Handles.color = handleColorBehind;
                        outterAngleInnerAngleRange = DrawSpotlightHandle(outterAngleInnerAngleRange);
                        Handles.zTest = UnityEngine.Rendering.CompareFunction.LessEqual;
                        Handles.color = handleColorAbove;
                        outterAngleInnerAngleRange = DrawSpotlightHandle(outterAngleInnerAngleRange);
                        if (EditorGUI.EndChangeCheck())
                        {
                            Undo.RecordObjects(new UnityEngine.Object[] { light, additionalData }, "Adjust Cone Spot Light");
                            additionalData.innerSpotPercent = 100f * outterAngleInnerAngleRange.y / Mathf.Max(0.1f, 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;
                        DrawSpherePortionWireframe(aspectFovMaxRangeMinRange, shadowNearPlane);
                        Handles.zTest = UnityEngine.Rendering.CompareFunction.LessEqual;
                        Handles.color = wireframeColorAbove;
                        DrawSpherePortionWireframe(aspectFovMaxRangeMinRange, shadowNearPlane);
                        EditorGUI.BeginChangeCheck();
                        Handles.zTest             = UnityEngine.Rendering.CompareFunction.Greater;
                        Handles.color             = handleColorBehind;
                        aspectFovMaxRangeMinRange = DrawSpherePortionHandle(aspectFovMaxRangeMinRange, false);
                        Handles.zTest             = UnityEngine.Rendering.CompareFunction.LessEqual;
                        Handles.color             = handleColorAbove;
                        aspectFovMaxRangeMinRange = DrawSpherePortionHandle(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;
                        DrawOrthoFrustumWireframe(widthHeightMaxRangeMinRange, shadowNearPlane);
                        Handles.zTest = UnityEngine.Rendering.CompareFunction.LessEqual;
                        Handles.color = wireframeColorAbove;
                        DrawOrthoFrustumWireframe(widthHeightMaxRangeMinRange, shadowNearPlane);
                        EditorGUI.BeginChangeCheck();
                        Handles.zTest = UnityEngine.Rendering.CompareFunction.Greater;
                        Handles.color = handleColorBehind;
                        widthHeightMaxRangeMinRange = DrawOrthoFrustumHandle(widthHeightMaxRangeMinRange, false);
                        Handles.zTest = UnityEngine.Rendering.CompareFunction.LessEqual;
                        Handles.color = handleColorAbove;
                        widthHeightMaxRangeMinRange = 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;

            case HDLightType.Area:
                switch (additionalData.areaLightShape)
                {
                case AreaLightShape.Rectangle:
                case AreaLightShape.Tube:
                    bool withYAxis = additionalData.areaLightShape == AreaLightShape.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;
                        DrawAreaLightWireframe(widthHeight);
                        range         = Handles.RadiusHandle(Quaternion.identity, Vector3.zero, range); //also draw handles
                        Handles.zTest = UnityEngine.Rendering.CompareFunction.LessEqual;
                        Handles.color = wireframeColorAbove;
                        DrawAreaLightWireframe(widthHeight);
                        range         = Handles.RadiusHandle(Quaternion.identity, Vector3.zero, range); //also draw handles
                        Handles.zTest = UnityEngine.Rendering.CompareFunction.Greater;
                        Handles.color = handleColorBehind;
                        widthHeight   = DrawAreaLightHandle(widthHeight, withYAxis);
                        Handles.zTest = UnityEngine.Rendering.CompareFunction.LessEqual;
                        Handles.color = handleColorAbove;
                        widthHeight   = 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;

                case AreaLightShape.Disc:
                    //use legacy handles for this case
                    break;
                }
                break;
            }
        }
        static void DrawEmissionContent(SerializedHDLight serialized, Editor owner)
        {
            if (GraphicsSettings.lightsUseLinearIntensity && GraphicsSettings.lightsUseColorTemperature)
            {
                EditorGUILayout.PropertyField(serialized.settings.useColorTemperature, s_Styles.useColorTemperature);
                if (serialized.settings.useColorTemperature.boolValue)
                {
                    EditorGUI.indentLevel += 1;
                    EditorGUILayout.PropertyField(serialized.settings.color, s_Styles.colorFilter);
                    SliderWithTexture(s_Styles.colorTemperature, serialized.settings.colorTemperature, serialized.settings);
                    EditorGUI.indentLevel -= 1;
                }
                else
                    EditorGUILayout.PropertyField(serialized.settings.color, s_Styles.color);
            }
            else
                EditorGUILayout.PropertyField(serialized.settings.color, s_Styles.color);

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PropertyField(serialized.serializedLightData.intensity, s_Styles.lightIntensity);
            serialized.serializedLightData.lightUnit.enumValueIndex = (int)LightIntensityUnitPopup(serialized, owner);
            EditorGUILayout.EndHorizontal();
            if (EditorGUI.EndChangeCheck())
            {
                serialized.serializedLightData.intensity.floatValue = Mathf.Max(serialized.serializedLightData.intensity.floatValue, 0.0f);
            }

            if (serialized.editorLightShape != LightShape.Directional && serialized.serializedLightData.lightUnit.enumValueIndex == (int)PunctualLightUnit.Lux)
            {
                // Box are local directional light and shouldn't display the Lux At widget. It use only lux
                if (!(serialized.editorLightShape == LightShape.Spot && ((SpotLightShape)serialized.serializedLightData.spotLightShape.enumValueIndex == SpotLightShape.Box)))
                {
                    EditorGUI.indentLevel++;
                    EditorGUI.BeginChangeCheck();
                    EditorGUILayout.PropertyField(serialized.serializedLightData.luxAtDistance, s_Styles.luxAtDistance);
                    if (EditorGUI.EndChangeCheck())
                    {
                        serialized.serializedLightData.luxAtDistance.floatValue = Mathf.Max(serialized.serializedLightData.luxAtDistance.floatValue, 0.01f);
                    }
                    EditorGUI.indentLevel--;
                }
            }

            if (serialized.editorLightShape == LightShape.Spot)
            {
                var spotLightShape = (SpotLightShape)serialized.serializedLightData.spotLightShape.enumValueIndex;
                if (spotLightShape == SpotLightShape.Cone || spotLightShape == SpotLightShape.Pyramid)
                {
                    // Display reflector only in advance mode
                    if (serialized.serializedLightData.lightUnit.enumValueIndex == (int)PunctualLightUnit.Lumen && GetAdvanced(Advanceable.Emission, serialized, owner))
                    {
                        EditorGUI.indentLevel++;
                        EditorGUILayout.PropertyField(serialized.serializedLightData.enableSpotReflector, s_Styles.enableSpotReflector);
                        EditorGUI.indentLevel--;
                    }
                }
            }

            if (serialized.editorLightShape != LightShape.Directional)
            {
                EditorGUI.BeginChangeCheck();
                serialized.settings.DrawRange(false);
                if (EditorGUI.EndChangeCheck())
                {
                    // For GI we need to detect any change on additional data and call SetLightDirty + For intensity we need to detect light shape change
                    serialized.needUpdateAreaLightEmissiveMeshComponents = true;
                    ((Light)owner.target).SetLightDirty(); // Should be apply only to parameter that's affect GI, but make the code cleaner
                }
            }

            serialized.settings.DrawBounceIntensity();

            EditorGUI.BeginChangeCheck(); // For GI we need to detect any change on additional data and call SetLightDirty

            // No cookie with area light (maybe in future textured area light ?)
            if (!HDAdditionalLightData.IsAreaLight(serialized.serializedLightData.lightTypeExtent))
            {
                serialized.settings.DrawCookie();

                // When directional light use a cookie, it can control the size
                if (serialized.settings.cookie != null && serialized.editorLightShape == LightShape.Directional)
                {
                    EditorGUI.indentLevel++;
                    EditorGUILayout.PropertyField(serialized.serializedLightData.shapeWidth, s_Styles.cookieSizeX);
                    EditorGUILayout.PropertyField(serialized.serializedLightData.shapeHeight, s_Styles.cookieSizeY);
                    EditorGUI.indentLevel--;
                }
            }

            if (EditorGUI.EndChangeCheck())
            {
                serialized.needUpdateAreaLightEmissiveMeshComponents = true;
                ((Light)owner.target).SetLightDirty(); // Should be apply only to parameter that's affect GI, but make the code cleaner
            }
        }