Exemplo n.º 1
0
    void OnTriggerEnter(Collider other)
    {
        // Hit by light
        if (other.gameObject.GetComponent <LightUnit> ())
        {
            LightUnit lightUnit = other.gameObject.GetComponent <LightUnit> ();

            if (lightUnit.isNormal())
            {
                Vector3    inputVector = other.gameObject.GetComponent <Rigidbody> ().velocity;
                Color      inputColor  = other.gameObject.GetComponent <LightUnitColorManager> ().lightColor;
                GameObject newObject   = Instantiate(other.gameObject, transform.position, Quaternion.identity);
                newObject.GetComponent <Rigidbody> ().velocity = inputVector;
                Color outputColor = inputColor;

                outputColor.r = (filterColor.r == 0f) ? 0f : inputColor.r;
                outputColor.g = (filterColor.g == 0f) ? 0f : inputColor.g;
                outputColor.b = (filterColor.b == 0f) ? 0f : inputColor.b;

                newObject.GetComponent <LightUnitColorManager> ().lightColor = outputColor;

                lightUnit.kill();
            }
        }
    }
Exemplo n.º 2
0
        private void OnEnable()
        {
            if (needsIntensityUpdate_1_0)
            {
// Pragma to disable the warning got by using deprecated properties (areaIntensity, directionalIntensity, ...)
#pragma warning disable 0618
                switch (lightTypeExtent)
                {
                case LightTypeExtent.Punctual:
                    switch (m_Light.type)
                    {
                    case LightType.Directional:
                        lightUnit = LightUnit.Lux;
                        intensity = directionalIntensity;
                        break;

                    case LightType.Spot:
                    case LightType.Point:
                        lightUnit = LightUnit.Lumen;
                        intensity = punctualIntensity;
                        break;
                    }
                    break;

                case LightTypeExtent.Line:
                case LightTypeExtent.Rectangle:
                    lightUnit = LightUnit.Lumen;
                    intensity = areaIntensity;
                    break;
                }
#pragma warning restore 0618
            }
        }
        LightUnit LightIntensityUnitPopup(LightShape shape)
        {
            LightUnit selectedLightUnit;
            LightUnit oldLigthUnit = (LightUnit)m_AdditionalLightData.lightUnit.enumValueIndex;

            EditorGUI.BeginChangeCheck();
            switch (shape)
            {
            case LightShape.Directional:
                selectedLightUnit = (LightUnit)EditorGUILayout.EnumPopup((DirectionalLightUnit)m_AdditionalLightData.lightUnit.enumValueIndex);
                break;

            case LightShape.Point:
            case LightShape.Spot:
                selectedLightUnit = (LightUnit)EditorGUILayout.EnumPopup((PunctualLightUnit)m_AdditionalLightData.lightUnit.enumValueIndex);
                break;

            default:
                selectedLightUnit = (LightUnit)EditorGUILayout.EnumPopup((AreaLightUnit)m_AdditionalLightData.lightUnit.enumValueIndex);
                break;
            }
            if (EditorGUI.EndChangeCheck())
            {
                ConvertLightIntensity(oldLigthUnit, selectedLightUnit);
            }

            return(selectedLightUnit);
        }
Exemplo n.º 4
0
    void OnTriggerEnter(Collider other)
    {
        // Hit by light
        if (other.gameObject.GetComponent <LightUnit> ())
        {
            LightUnit lightUnit = other.gameObject.GetComponent <LightUnit> ();

            if (lightUnit.isNormal())
            {
                Vector3 normalVector = glass.transform.localRotation * Vector3.right;
                Vector3 inputVector  = other.gameObject.GetComponent <Rigidbody> ().velocity;
                // Debug.Log ("Normal = " + normalVector.ToString ());
                // Debug.Log ("Input = " + inputVector.ToString ());

                Quaternion normalQuaternion = Quaternion.FromToRotation(inputVector, normalVector);
                // Debug.Log ("Q = " + normalQuaternion.eulerAngles.ToString());
                Vector3 outputVector = -(normalQuaternion * (normalQuaternion * inputVector));
                // Debug.Log ("Output = " + outputVector.ToString ());

                if ((outputVector - inputVector).magnitude >= 1)
                {
                    GameObject newObject = Instantiate(other.gameObject, transform.position, Quaternion.identity);
                    newObject.GetComponent <Rigidbody> ().velocity = outputVector;
                }
                lightUnit.kill();
            }
        }
    }
Exemplo n.º 5
0
 public void RemoveLight(LightUnit light)
 {
     if (lights.Contains(light))
     {
         lights.Remove(light);
     }
 }
        static LightUnit LightIntensityUnitPopup(SerializedHDLight serialized, Editor owner)
        {
            LightShape shape = serialized.editorLightShape;
            LightUnit selectedLightUnit;
            LightUnit oldLigthUnit = (LightUnit)serialized.serializedLightData.lightUnit.enumValueIndex;

            EditorGUI.BeginChangeCheck();
            switch (shape)
            {
                case LightShape.Directional:
                    selectedLightUnit = (LightUnit)EditorGUILayout.EnumPopup((DirectionalLightUnit)serialized.serializedLightData.lightUnit.enumValueIndex);
                    break;
                case LightShape.Point:
                    selectedLightUnit = (LightUnit)EditorGUILayout.EnumPopup((PunctualLightUnit)serialized.serializedLightData.lightUnit.enumValueIndex);
                    break;
                case LightShape.Spot:
                    if ((SpotLightShape)serialized.serializedLightData.spotLightShape.enumValueIndex == SpotLightShape.Box)
                        selectedLightUnit = (LightUnit)EditorGUILayout.EnumPopup((DirectionalLightUnit)serialized.serializedLightData.lightUnit.enumValueIndex);
                    else
                        selectedLightUnit = (LightUnit)EditorGUILayout.EnumPopup((PunctualLightUnit)serialized.serializedLightData.lightUnit.enumValueIndex);
                    break;
                default:
                    selectedLightUnit = (LightUnit)EditorGUILayout.EnumPopup((AreaLightUnit)serialized.serializedLightData.lightUnit.enumValueIndex);
                    break;
            }
            if (EditorGUI.EndChangeCheck())
                ConvertLightIntensity(oldLigthUnit, selectedLightUnit, serialized, owner);

            return selectedLightUnit;
        }
        static void ConvertLightIntensity(LightUnit oldLightUnit, LightUnit newLightUnit, SerializedHDLight serialized, Editor owner)
        {
            float intensity = serialized.serializedLightData.intensity.floatValue;
            Light light = (Light)owner.target;

            // For punctual lights
            if ((LightTypeExtent)serialized.serializedLightData.lightTypeExtent.enumValueIndex == LightTypeExtent.Punctual)
            {
                // Lumen ->
                if (oldLightUnit == LightUnit.Lumen && newLightUnit == LightUnit.Candela)
                    intensity = LightUtils.ConvertPunctualLightLumenToCandela(light.type, intensity, light.intensity, serialized.serializedLightData.enableSpotReflector.boolValue);
                else if (oldLightUnit == LightUnit.Lumen && newLightUnit == LightUnit.Lux)
                    intensity = LightUtils.ConvertPunctualLightLumenToLux(light.type, intensity, light.intensity, serialized.serializedLightData.enableSpotReflector.boolValue,
                                                                            serialized.serializedLightData.luxAtDistance.floatValue);
                else if (oldLightUnit == LightUnit.Lumen && newLightUnit == LightUnit.Ev100)
                    intensity = LightUtils.ConvertPunctualLightLumenToEv(light.type, intensity, light.intensity, serialized.serializedLightData.enableSpotReflector.boolValue);
                // Candela ->
                else if (oldLightUnit == LightUnit.Candela && newLightUnit == LightUnit.Lumen)
                    intensity = LightUtils.ConvertPunctualLightCandelaToLumen(  light.type, (SpotLightShape)serialized.serializedLightData.spotLightShape.enumValueIndex, intensity, serialized.serializedLightData.enableSpotReflector.boolValue,
                                                                                light.spotAngle, serialized.serializedLightData.aspectRatio.floatValue);
                else if (oldLightUnit == LightUnit.Candela && newLightUnit == LightUnit.Lux)
                    intensity = LightUtils.ConvertCandelaToLux(intensity, serialized.serializedLightData.luxAtDistance.floatValue);
                else if (oldLightUnit == LightUnit.Candela && newLightUnit == LightUnit.Ev100)
                    intensity = LightUtils.ConvertCandelaToEv(intensity);
                // Lux ->
                else if (oldLightUnit == LightUnit.Lux && newLightUnit == LightUnit.Lumen)
                    intensity = LightUtils.ConvertPunctualLightLuxToLumen(light.type, (SpotLightShape)serialized.serializedLightData.spotLightShape.enumValueIndex, intensity, serialized.serializedLightData.enableSpotReflector.boolValue,
                                                                          light.spotAngle, serialized.serializedLightData.aspectRatio.floatValue, serialized.serializedLightData.luxAtDistance.floatValue);
                else if (oldLightUnit == LightUnit.Lux && newLightUnit == LightUnit.Candela)
                    intensity = LightUtils.ConvertLuxToCandela(intensity, serialized.serializedLightData.luxAtDistance.floatValue);
                else if (oldLightUnit == LightUnit.Lux && newLightUnit == LightUnit.Ev100)
                    intensity = LightUtils.ConvertLuxToEv(intensity, serialized.serializedLightData.luxAtDistance.floatValue);
                // EV100 ->
                else if (oldLightUnit == LightUnit.Ev100 && newLightUnit == LightUnit.Lumen)
                    intensity = LightUtils.ConvertPunctualLightEvToLumen(light.type, (SpotLightShape)serialized.serializedLightData.spotLightShape.enumValueIndex, intensity, serialized.serializedLightData.enableSpotReflector.boolValue,
                                                                            light.spotAngle, serialized.serializedLightData.aspectRatio.floatValue);
                else if (oldLightUnit == LightUnit.Ev100 && newLightUnit == LightUnit.Candela)
                    intensity = LightUtils.ConvertEvToCandela(intensity);
                else if (oldLightUnit == LightUnit.Ev100 && newLightUnit == LightUnit.Lux)
                    intensity = LightUtils.ConvertEvToLux(intensity, serialized.serializedLightData.luxAtDistance.floatValue);
            }
            else  // For area lights
            {               
                if (oldLightUnit == LightUnit.Lumen && newLightUnit == LightUnit.Luminance)
                    intensity = LightUtils.ConvertAreaLightLumenToLuminance((LightTypeExtent)serialized.serializedLightData.lightTypeExtent.enumValueIndex, intensity, serialized.serializedLightData.shapeWidth.floatValue, serialized.serializedLightData.shapeHeight.floatValue);
                if (oldLightUnit == LightUnit.Luminance && newLightUnit == LightUnit.Lumen)
                    intensity = LightUtils.ConvertAreaLightLuminanceToLumen((LightTypeExtent)serialized.serializedLightData.lightTypeExtent.enumValueIndex, intensity, serialized.serializedLightData.shapeWidth.floatValue, serialized.serializedLightData.shapeHeight.floatValue);
                if (oldLightUnit == LightUnit.Luminance && newLightUnit == LightUnit.Ev100)
                    intensity = LightUtils.ConvertLuminanceToEv(intensity);
                if (oldLightUnit == LightUnit.Ev100 && newLightUnit == LightUnit.Luminance)
                    intensity = LightUtils.ConvertEvToLuminance(intensity);
                if (oldLightUnit == LightUnit.Ev100 && newLightUnit == LightUnit.Lumen)
                    intensity = LightUtils.ConvertAreaLightEvToLumen((LightTypeExtent)serialized.serializedLightData.lightTypeExtent.enumValueIndex, intensity, serialized.serializedLightData.shapeWidth.floatValue, serialized.serializedLightData.shapeHeight.floatValue);
                if (oldLightUnit == LightUnit.Lumen && newLightUnit == LightUnit.Ev100)
                    intensity = LightUtils.ConvertAreaLightLumenToEv((LightTypeExtent)serialized.serializedLightData.lightTypeExtent.enumValueIndex, intensity, serialized.serializedLightData.shapeWidth.floatValue, serialized.serializedLightData.shapeHeight.floatValue);
            }

            serialized.serializedLightData.intensity.floatValue = intensity;
        }
Exemplo n.º 8
0
        public void Setup(LightUnit unit, SerializedHDLight light, Editor owner)
        {
            m_Unit   = unit;
            m_Light  = light;
            m_Editor = owner;

            // Cache the spot reflector state as we will need to revert back to it after treating the slider as point light.
            m_SpotReflectorEnabled = light.enableSpotReflector.boolValue;
        }
Exemplo n.º 9
0
        void DrawPunctualLightUnitSlider(LightUnit lightUnit, SerializedProperty value, Rect rect, SerializedHDLight light, Editor owner)
        {
            k_PunctualLightUnitSlider.Setup(lightUnit, light, owner);

            float val = value.floatValue;

            k_PunctualLightUnitSlider.Draw(rect, value, ref val);
            if (val != value.floatValue)
            {
                value.floatValue = val;
            }
        }
Exemplo n.º 10
0
 public void Registerlight(LightUnit light)
 {
     if (!lights.Contains(light))
     {
         lights.Add(light);
         if (_isFastLightingMode)
         {
             light.lamp.shadows    = LightShadows.None;
             light.lamp.renderMode = LightRenderMode.ForceVertex;
         }
     }
 }
Exemplo n.º 11
0
 public void Draw(HDLightType type, LightUnit lightUnit, SerializedProperty value, Rect rect, SerializedHDLight light, Editor owner)
 {
     using (new EditorGUI.IndentLevelScope(-EditorGUI.indentLevel))
     {
         if (type == HDLightType.Directional)
         {
             DrawDirectionalUnitSlider(value, rect);
         }
         else
         {
             DrawPunctualLightUnitSlider(lightUnit, value, rect, light, owner);
         }
     }
 }
Exemplo n.º 12
0
        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);
            }
        }
        public void UpgradeLight()
        {
// Disable the warning generated by deprecated fields (areaIntensity, directionalIntensity, ...)
#pragma warning disable 618

            // If we are deserializing an old version, convert the light intensity to the new system
            if (needsIntensityUpdate_1_0)
            {
                switch (lightTypeExtent)
                {
                case LightTypeExtent.Punctual:
                    switch (m_Light.type)
                    {
                    case LightType.Directional:
                        lightUnit = LightUnit.Lux;
                        intensity = directionalIntensity;
                        break;

                    case LightType.Spot:
                    case LightType.Point:
                        lightUnit = LightUnit.Lumen;
                        intensity = punctualIntensity;
                        break;
                    }
                    break;

                case LightTypeExtent.Tube:
                case LightTypeExtent.Rectangle:
                    lightUnit = LightUnit.Lumen;
                    intensity = areaIntensity;
                    break;
                }
                needsIntensityUpdate_1_0 = false;
            }
            if (m_Version <= 2)
            {
                // ShadowNearPlane have been move to HDRP as default legacy unity clamp it to 0.1 and we need to be able to go below that
                shadowNearPlane = m_Light.shadowNearPlane;
            }
            if (m_Version <= 3)
            {
                m_Light.renderingLayerMask = LightLayerToRenderingLayerMask((int)lightLayers, m_Light.renderingLayerMask);
            }

            m_Version = currentVersion;
            version   = currentVersion;

#pragma warning restore 0618
        }
Exemplo n.º 14
0
        public void ApplySaveSettings(GameObject selectedObject, List <ISettingsSaveData> settings)
        {
            if (settings == null || !settings.Any())
            {
                return;
            }

            var lightSettings = settings.OfType <LightingSaveData>().ToList();

            if (!lightSettings.Any())
            {
                return;
            }

            var lightSetting = lightSettings.First();

            Enabled   = lightSetting.enabled;
            Intensity = lightSetting.intensity;
            Unit      = lightSetting.unit;
            Range     = lightSetting.range;
            Angle     = lightSetting.angle;
            Color     = lightSetting.color;

            var lights = selectedObject.GetComponentsInChildren <Light>(true);

            if (lights == null || !lights.Any())
            {
                return;
            }

            foreach (var light in lights)
            {
                var hdLight = light.GetComponent <HDAdditionalLightData>();

                light.enabled     = Enabled;
                hdLight.enabled   = Enabled;
                hdLight.lightUnit = Unit;
                hdLight.intensity = Intensity;
                hdLight.range     = Range;
                if (Angle != null)
                {
                    hdLight.SetSpotAngle(Angle.Value);
                }

                hdLight.color = new Color(Color.x, Color.y, Color.z);
            }
        }
Exemplo n.º 15
0
    void OnTriggerEnter(Collider other)
    {
        LightUnit lightUnit = other.gameObject.GetComponent <LightUnit> ();

        if (lightUnit && lightUnit.isNormal())
        {
            if (!penetrateLight)
            {
                lightUnit.kill();
            }
            if (openTime < 0.0f)
            {
                AudioSource.PlayClipAtPoint(hitSound, Camera.main.transform.position);
            }
            openTime = 1.0f;
        }
    }
Exemplo n.º 16
0
        static void DrawLightIntensityUnitPopup(SerializedHDLight serialized, Editor owner)
        {
            LightShape shape = serialized.editorLightShape;
            LightUnit  selectedLightUnit;
            LightUnit  oldLigthUnit = (LightUnit)serialized.serializedLightData.lightUnit.enumValueIndex;

            EditorGUI.showMixedValue = serialized.serializedLightData.lightUnit.hasMultipleDifferentValues;
            EditorGUI.BeginChangeCheck();
            switch (shape)
            {
            case LightShape.Directional:
                selectedLightUnit = (LightUnit)EditorGUILayout.EnumPopup((DirectionalLightUnit)serialized.serializedLightData.lightUnit.enumValueIndex);
                break;

            case LightShape.Point:
                selectedLightUnit = (LightUnit)EditorGUILayout.EnumPopup((PunctualLightUnit)serialized.serializedLightData.lightUnit.enumValueIndex);
                break;

            case LightShape.Spot:
                if ((SpotLightShape)serialized.serializedLightData.spotLightShape.enumValueIndex == SpotLightShape.Box)
                {
                    selectedLightUnit = (LightUnit)EditorGUILayout.EnumPopup((DirectionalLightUnit)serialized.serializedLightData.lightUnit.enumValueIndex);
                }
                else
                {
                    selectedLightUnit = (LightUnit)EditorGUILayout.EnumPopup((PunctualLightUnit)serialized.serializedLightData.lightUnit.enumValueIndex);
                }
                break;

            default:
                selectedLightUnit = (LightUnit)EditorGUILayout.EnumPopup((AreaLightUnit)serialized.serializedLightData.lightUnit.enumValueIndex);
                break;
            }

            EditorGUI.showMixedValue = false;

            if (EditorGUI.EndChangeCheck())
            {
                ConvertLightIntensity(oldLigthUnit, selectedLightUnit, serialized, owner);
                serialized.serializedLightData.lightUnit.enumValueIndex = (int)selectedLightUnit;
            }
        }
Exemplo n.º 17
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;
                }
            }
        }
        public void UpgradeLight()
        {
// Disable the warning generated by deprecated fields (areaIntensity, directionalIntensity, ...)
#pragma warning disable 0618

            // If we are deserializing an old version, convert the light intensity to the new system
            if (needsIntensityUpdate_1_0)
            {
                switch (lightTypeExtent)
                {
                case LightTypeExtent.Punctual:
                    switch (m_Light.type)
                    {
                    case LightType.Directional:
                        lightUnit = LightUnit.Lux;
                        intensity = directionalIntensity;
                        break;

                    case LightType.Spot:
                    case LightType.Point:
                        lightUnit = LightUnit.Lumen;
                        intensity = punctualIntensity;
                        break;
                    }
                    break;

                case LightTypeExtent.Line:
                case LightTypeExtent.Rectangle:
                    lightUnit = LightUnit.Lumen;
                    intensity = areaIntensity;
                    break;
                }
                needsIntensityUpdate_1_0 = false;
            }

            m_Version = currentVersion;
            version   = currentVersion;

#pragma warning restore 0618
        }
Exemplo n.º 19
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);
        }
Exemplo n.º 20
0
 public void Setup(LightUnit unit, SerializedHDLight light, Editor owner)
 {
     m_Unit   = unit;
     m_Light  = light;
     m_Editor = owner;
 }
Exemplo n.º 21
0
        internal static void ConvertLightIntensity(LightUnit oldLightUnit, LightUnit newLightUnit, HDAdditionalLightData hdLight, Light light)
        {
            float       intensity     = hdLight.intensity;
            float       luxAtDistance = hdLight.luxAtDistance;
            HDLightType lightType     = hdLight.ComputeLightType(light);

            // For punctual lights
            if (lightType != HDLightType.Area)
            {
                // Lumen ->
                if (oldLightUnit == LightUnit.Lumen && newLightUnit == LightUnit.Candela)
                {
                    intensity = LightUtils.ConvertPunctualLightLumenToCandela(lightType, intensity, light.intensity, hdLight.enableSpotReflector);
                }
                else if (oldLightUnit == LightUnit.Lumen && newLightUnit == LightUnit.Lux)
                {
                    intensity = LightUtils.ConvertPunctualLightLumenToLux(lightType, intensity, light.intensity, hdLight.enableSpotReflector, hdLight.luxAtDistance);
                }
                else if (oldLightUnit == LightUnit.Lumen && newLightUnit == LightUnit.Ev100)
                {
                    intensity = LightUtils.ConvertPunctualLightLumenToEv(lightType, intensity, light.intensity, hdLight.enableSpotReflector);
                }
                // Candela ->
                else if (oldLightUnit == LightUnit.Candela && newLightUnit == LightUnit.Lumen)
                {
                    intensity = LightUtils.ConvertPunctualLightCandelaToLumen(lightType, hdLight.spotLightShape, intensity, hdLight.enableSpotReflector, light.spotAngle, hdLight.aspectRatio);
                }
                else if (oldLightUnit == LightUnit.Candela && newLightUnit == LightUnit.Lux)
                {
                    intensity = LightUtils.ConvertCandelaToLux(intensity, hdLight.luxAtDistance);
                }
                else if (oldLightUnit == LightUnit.Candela && newLightUnit == LightUnit.Ev100)
                {
                    intensity = LightUtils.ConvertCandelaToEv(intensity);
                }
                // Lux ->
                else if (oldLightUnit == LightUnit.Lux && newLightUnit == LightUnit.Lumen)
                {
                    intensity = LightUtils.ConvertPunctualLightLuxToLumen(lightType, hdLight.spotLightShape, intensity, hdLight.enableSpotReflector,
                                                                          light.spotAngle, hdLight.aspectRatio, hdLight.luxAtDistance);
                }
                else if (oldLightUnit == LightUnit.Lux && newLightUnit == LightUnit.Candela)
                {
                    intensity = LightUtils.ConvertLuxToCandela(intensity, hdLight.luxAtDistance);
                }
                else if (oldLightUnit == LightUnit.Lux && newLightUnit == LightUnit.Ev100)
                {
                    intensity = LightUtils.ConvertLuxToEv(intensity, hdLight.luxAtDistance);
                }
                // EV100 ->
                else if (oldLightUnit == LightUnit.Ev100 && newLightUnit == LightUnit.Lumen)
                {
                    intensity = LightUtils.ConvertPunctualLightEvToLumen(lightType, hdLight.spotLightShape, intensity, hdLight.enableSpotReflector,
                                                                         light.spotAngle, hdLight.aspectRatio);
                }
                else if (oldLightUnit == LightUnit.Ev100 && newLightUnit == LightUnit.Candela)
                {
                    intensity = LightUtils.ConvertEvToCandela(intensity);
                }
                else if (oldLightUnit == LightUnit.Ev100 && newLightUnit == LightUnit.Lux)
                {
                    intensity = LightUtils.ConvertEvToLux(intensity, hdLight.luxAtDistance);
                }
            }
            else  // For area lights
            {
                if (oldLightUnit == LightUnit.Lumen && newLightUnit == LightUnit.Nits)
                {
                    intensity = LightUtils.ConvertAreaLightLumenToLuminance(hdLight.areaLightShape, intensity, hdLight.shapeWidth, hdLight.shapeHeight);
                }
                if (oldLightUnit == LightUnit.Nits && newLightUnit == LightUnit.Lumen)
                {
                    intensity = LightUtils.ConvertAreaLightLuminanceToLumen(hdLight.areaLightShape, intensity, hdLight.shapeWidth, hdLight.shapeHeight);
                }
                if (oldLightUnit == LightUnit.Nits && newLightUnit == LightUnit.Ev100)
                {
                    intensity = LightUtils.ConvertLuminanceToEv(intensity);
                }
                if (oldLightUnit == LightUnit.Ev100 && newLightUnit == LightUnit.Nits)
                {
                    intensity = LightUtils.ConvertEvToLuminance(intensity);
                }
                if (oldLightUnit == LightUnit.Ev100 && newLightUnit == LightUnit.Lumen)
                {
                    intensity = LightUtils.ConvertAreaLightEvToLumen(hdLight.areaLightShape, intensity, hdLight.shapeWidth, hdLight.shapeHeight);
                }
                if (oldLightUnit == LightUnit.Lumen && newLightUnit == LightUnit.Ev100)
                {
                    intensity = LightUtils.ConvertAreaLightLumenToEv(hdLight.areaLightShape, intensity, hdLight.shapeWidth, hdLight.shapeHeight);
                }
            }

            hdLight.intensity = intensity;
        }
Exemplo n.º 22
0
        static void ConvertLightIntensity(LightUnit oldLightUnit, LightUnit newLightUnit, SerializedHDLight serialized, Editor owner)
        {
            float intensity = serialized.serializedLightData.intensity.floatValue;
            Light light     = (Light)owner.target;

            // For punctual lights
            if (oldLightUnit == LightUnit.Lumen && newLightUnit == LightUnit.Candela)
            {
                if (serialized.editorLightShape == LightShape.Spot && serialized.serializedLightData.enableSpotReflector.boolValue)
                {
                    // We have already calculate the correct value, just assign it
                    intensity = light.intensity;
                }
                else
                {
                    intensity = LightUtils.ConvertPointLightLumenToCandela(intensity);
                }
            }
            if (oldLightUnit == LightUnit.Candela && newLightUnit == LightUnit.Lumen)
            {
                if (serialized.editorLightShape == LightShape.Spot && serialized.serializedLightData.enableSpotReflector.boolValue)
                {
                    // We just need to multiply candela by solid angle in this case
                    if ((SpotLightShape)serialized.serializedLightData.spotLightShape.enumValueIndex == SpotLightShape.Cone)
                    {
                        intensity = LightUtils.ConvertSpotLightCandelaToLumen(intensity, light.spotAngle * Mathf.Deg2Rad, true);
                    }
                    else if ((SpotLightShape)serialized.serializedLightData.spotLightShape.enumValueIndex == SpotLightShape.Pyramid)
                    {
                        float angleA, angleB;
                        LightUtils.CalculateAnglesForPyramid(serialized.serializedLightData.aspectRatio.floatValue, light.spotAngle * Mathf.Deg2Rad, out angleA, out angleB);

                        intensity = LightUtils.ConvertFrustrumLightCandelaToLumen(intensity, angleA, angleB);
                    }
                    else // Box
                    {
                        intensity = LightUtils.ConvertPointLightCandelaToLumen(intensity);
                    }
                }
                else
                {
                    intensity = LightUtils.ConvertPointLightCandelaToLumen(intensity);
                }
            }

            // For area lights
            if (oldLightUnit == LightUnit.Lumen && newLightUnit == LightUnit.Luminance)
            {
                intensity = LightUtils.ConvertAreaLightLumenToLuminance((LightTypeExtent)serialized.serializedLightData.lightTypeExtent.enumValueIndex, intensity, serialized.serializedLightData.shapeWidth.floatValue, serialized.serializedLightData.shapeHeight.floatValue);
            }
            if (oldLightUnit == LightUnit.Luminance && newLightUnit == LightUnit.Lumen)
            {
                intensity = LightUtils.ConvertAreaLightLuminanceToLumen((LightTypeExtent)serialized.serializedLightData.lightTypeExtent.enumValueIndex, intensity, serialized.serializedLightData.shapeWidth.floatValue, serialized.serializedLightData.shapeHeight.floatValue);
            }
            if (oldLightUnit == LightUnit.Luminance && newLightUnit == LightUnit.Ev100)
            {
                intensity = LightUtils.ConvertLuminanceToEv(intensity);
            }
            if (oldLightUnit == LightUnit.Ev100 && newLightUnit == LightUnit.Luminance)
            {
                intensity = LightUtils.ConvertEvToLuminance(intensity);
            }
            if (oldLightUnit == LightUnit.Ev100 && newLightUnit == LightUnit.Lumen)
            {
                intensity = LightUtils.ConvertAreaLightEvToLumen((LightTypeExtent)serialized.serializedLightData.lightTypeExtent.enumValueIndex, intensity, serialized.serializedLightData.shapeWidth.floatValue, serialized.serializedLightData.shapeHeight.floatValue);
            }
            if (oldLightUnit == LightUnit.Lumen && newLightUnit == LightUnit.Ev100)
            {
                intensity = LightUtils.ConvertAreaLightLumenToEv((LightTypeExtent)serialized.serializedLightData.lightTypeExtent.enumValueIndex, intensity, serialized.serializedLightData.shapeWidth.floatValue, serialized.serializedLightData.shapeHeight.floatValue);
            }

            serialized.serializedLightData.intensity.floatValue = intensity;
        }
        void ConvertLightIntensity(LightUnit oldLightUnit, LightUnit newLightUnit)
        {
            float intensity = m_AdditionalLightData.intensity.floatValue;

            // For punctual lights
            if (oldLightUnit == LightUnit.Lumen && newLightUnit == LightUnit.Candela)
            {
                if (m_LightShape == LightShape.Spot && m_AdditionalLightData.enableSpotReflector.boolValue)
                {
                    // We have already calculate the correct value, just assign it
                    intensity = ((Light)target).intensity;
                }
                else
                {
                    intensity = LightUtils.ConvertPointLightLumenToCandela(intensity);
                }
            }
            if (oldLightUnit == LightUnit.Candela && newLightUnit == LightUnit.Lumen)
            {
                if (m_LightShape == LightShape.Spot && m_AdditionalLightData.enableSpotReflector.boolValue)
                {
                    // We just need to multiply candela by solid angle in this case
                    if ((SpotLightShape)m_AdditionalLightData.spotLightShape.enumValueIndex == SpotLightShape.Cone)
                    {
                        intensity = LightUtils.ConvertSpotLightCandelaToLumen(intensity, ((Light)target).spotAngle * Mathf.Deg2Rad, true);
                    }
                    else if ((SpotLightShape)m_AdditionalLightData.spotLightShape.enumValueIndex == SpotLightShape.Pyramid)
                    {
                        float angleA, angleB;
                        LightUtils.CalculateAnglesForPyramid(m_AdditionalLightData.aspectRatio.floatValue, ((Light)target).spotAngle * Mathf.Deg2Rad, out angleA, out angleB);

                        intensity = LightUtils.ConvertFrustrumLightCandelaToLumen(intensity, angleA, angleB);
                    }
                    else // Box
                    {
                        intensity = LightUtils.ConvertPointLightCandelaToLumen(intensity);
                    }
                }
                else
                {
                    intensity = LightUtils.ConvertPointLightCandelaToLumen(intensity);
                }
            }

            // For area lights
            if (oldLightUnit == LightUnit.Lumen && newLightUnit == LightUnit.Luminance)
            {
                if (m_LightShape == LightShape.Rectangle)
                {
                    intensity = LightUtils.ConvertRectLightLumenToLuminance(intensity, m_AdditionalLightData.shapeWidth.floatValue, m_AdditionalLightData.shapeHeight.floatValue);
                }
                else if (m_LightShape == LightShape.Line)
                {
                    intensity = LightUtils.CalculateLineLightLumenToLuminance(intensity, m_AdditionalLightData.shapeWidth.floatValue);
                }
            }
            if (oldLightUnit == LightUnit.Luminance && newLightUnit == LightUnit.Lumen)
            {
                if (m_LightShape == LightShape.Rectangle)
                {
                    intensity = LightUtils.ConvertRectLightLuminanceToLumen(intensity, m_AdditionalLightData.shapeWidth.floatValue, m_AdditionalLightData.shapeHeight.floatValue);
                }
                else if (m_LightShape == LightShape.Line)
                {
                    intensity = LightUtils.CalculateLineLightLuminanceToLumen(intensity, m_AdditionalLightData.shapeWidth.floatValue);
                }
            }

            m_AdditionalLightData.intensity.floatValue = intensity;
        }
Exemplo n.º 24
0
 void DrawPunctualLightUnitSlider(LightUnit lightUnit, SerializedProperty value, Rect rect, SerializedHDLight light, Editor owner)
 {
     k_PunctualLightUnitSlider.Setup(lightUnit, light, owner);
     k_PunctualLightUnitSlider.Draw(rect, value);
 }
Exemplo n.º 25
0
 protected virtual LightingExplorerTableColumn[] GetHDLightColumns()
 {
     return(new[]
     {
         new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Name, HDStyles.Name, null, 200),                                               // 0: Name
         new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Checkbox, HDStyles.On, "m_Enabled", 25),                                       // 1: Enabled
         new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Enum, HDStyles.Type, "m_Type", 60),                                            // 2: Type
         new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Enum, HDStyles.Mode, "m_Lightmapping", 60),                                    // 3: Mixed mode
         new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Enum, HDStyles.Range, "m_Range", 60),                                          // 4: Range
         new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Checkbox, HDStyles.ColorTemperatureMode, "m_UseColorTemperature", 100),        // 5: Color Temperature Mode
         new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Color, HDStyles.Color, "m_Color", 60),                                         // 6: Color
         new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Float, HDStyles.ColorTemperature, "m_ColorTemperature", 100, (r, prop, dep) => // 7: Color Temperature
         {
             if (prop.serializedObject.FindProperty("m_UseColorTemperature").boolValue)
             {
                 prop = prop.serializedObject.FindProperty("m_ColorTemperature");
                 prop.floatValue = EditorGUI.FloatField(r, prop.floatValue);
             }
         }),
         new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Float, HDStyles.Intensity, "m_Intensity", 60, (r, prop, dep) =>                // 8: Intensity
         {
             Light light = prop.serializedObject.targetObject as Light;
             if (light == null)
             {
                 EditorGUI.LabelField(r, "null");
                 return;
             }
             float intensity = lightDataPairing[light].hdAdditionalLightData.intensity;
             EditorGUI.BeginChangeCheck();
             intensity = EditorGUI.FloatField(r, intensity);
             if (EditorGUI.EndChangeCheck())
             {
                 Undo.RecordObject(lightDataPairing[light].hdAdditionalLightData, "Changed light intensity");
                 lightDataPairing[light].hdAdditionalLightData.intensity = intensity;
             }
         }),
         new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Float, HDStyles.Unit, "m_Intensity", 60, (r, prop, dep) =>                // 9: Unit
         {
             Light light = prop.serializedObject.targetObject as Light;
             if (light == null)
             {
                 EditorGUI.LabelField(r, "null");
                 return;
             }
             LightUnit unit = lightDataPairing[light].hdAdditionalLightData.lightUnit;
             EditorGUI.BeginChangeCheck();
             unit = (LightUnit)EditorGUI.EnumPopup(r, unit);
             if (EditorGUI.EndChangeCheck())
             {
                 lightDataPairing[light].hdAdditionalLightData.lightUnit = unit;
             }
         }),
         new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Float, HDStyles.IndirectMultiplier, "m_BounceIntensity", 90),                  // 10: Indirect multiplier
         new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Checkbox, HDStyles.Shadows, "m_Shadows.m_Type", 60, (r, prop, dep) =>          // 11: Shadows
         {
             EditorGUI.BeginChangeCheck();
             bool shadows = EditorGUI.Toggle(r, prop.intValue != (int)LightShadows.None);
             if (EditorGUI.EndChangeCheck())
             {
                 prop.intValue = shadows ? (int)LightShadows.Soft : (int)LightShadows.None;
             }
         }),
         new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Checkbox, HDStyles.ContactShadows, "m_Shadows.m_Type", 100, (r, prop, dep) =>  // 12: Contact Shadows
         {
             Light light = prop.serializedObject.targetObject as Light;
             if (light == null)
             {
                 EditorGUI.LabelField(r, "null");
                 return;
             }
             bool contactShadows = lightDataPairing[light].additionalShadowData.contactShadows;
             EditorGUI.BeginChangeCheck();
             contactShadows = EditorGUI.Toggle(r, contactShadows);
             if (EditorGUI.EndChangeCheck())
             {
                 lightDataPairing[light].additionalShadowData.contactShadows = contactShadows;
             }
         }),
         new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Int, HDStyles.ShadowResolution, "m_Intensity", 60, (r, prop, dep) =>           // 13: Shadow resolution
         {
             Light light = prop.serializedObject.targetObject as Light;
             if (light == null)
             {
                 EditorGUI.LabelField(r, "null");
                 return;
             }
             int shadowResolution = lightDataPairing[light].additionalShadowData.shadowResolution;
             EditorGUI.BeginChangeCheck();
             shadowResolution = EditorGUI.IntField(r, shadowResolution);
             if (EditorGUI.EndChangeCheck())
             {
                 lightDataPairing[light].additionalShadowData.shadowResolution = shadowResolution;
             }
         }),
         new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Checkbox, HDStyles.AffectDiffuse, "m_Intensity", 90, (r, prop, dep) =>         // 14: Affect Diffuse
         {
             Light light = prop.serializedObject.targetObject as Light;
             if (light == null)
             {
                 EditorGUI.LabelField(r, "null");
                 return;
             }
             bool affectDiffuse = lightDataPairing[light].hdAdditionalLightData.affectDiffuse;
             EditorGUI.BeginChangeCheck();
             affectDiffuse = EditorGUI.Toggle(r, affectDiffuse);
             if (EditorGUI.EndChangeCheck())
             {
                 lightDataPairing[light].hdAdditionalLightData.affectDiffuse = affectDiffuse;
             }
         }),
         new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Checkbox, HDStyles.AffectSpecular, "m_Intensity", 90, (r, prop, dep) =>        // 15: Affect Specular
         {
             Light light = prop.serializedObject.targetObject as Light;
             if (light == null)
             {
                 EditorGUI.LabelField(r, "null");
                 return;
             }
             bool affectSpecular = lightDataPairing[light].hdAdditionalLightData.affectSpecular;
             EditorGUI.BeginChangeCheck();
             affectSpecular = EditorGUI.Toggle(r, affectSpecular);
             if (EditorGUI.EndChangeCheck())
             {
                 lightDataPairing[light].hdAdditionalLightData.affectSpecular = affectSpecular;
             }
         }),
         new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Custom, HDStyles.IsPrefab, "m_Intensity", 60, (r, prop, dep) =>                // 16: Prefab
         {
             Light light = prop.serializedObject.targetObject as Light;
             if (light == null)
             {
                 EditorGUI.LabelField(r, "null");
                 return;
             }
             bool isPrefab = lightDataPairing[light].isPrefab;
             if (isPrefab)
             {
                 EditorGUI.ObjectField(r, lightDataPairing[light].prefabRoot, typeof(GameObject), false);
             }
         }),
     });
 }
Exemplo n.º 26
0
        protected virtual LightingExplorerTableColumn[] GetHDLightColumns()
        {
            return(new[]
            {
                new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Name, HDStyles.Name, null, 200),                                               // 0: Name
                new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Checkbox, HDStyles.On, "m_Enabled", 25),                                       // 1: Enabled
                new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Enum, HDStyles.Type, "m_Type", 60),                                            // 2: Type
                new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Enum, HDStyles.Mode, "m_Lightmapping", 60),                                    // 3: Mixed mode
                new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Enum, HDStyles.Range, "m_Range", 60),                                          // 4: Range
                new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Checkbox, HDStyles.ColorTemperatureMode, "m_UseColorTemperature", 100),        // 5: Color Temperature Mode
                new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Color, HDStyles.Color, "m_Color", 60),                                         // 6: Color
                new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Float, HDStyles.ColorTemperature, "m_ColorTemperature", 100, (r, prop, dep) => // 7: Color Temperature
                {
                    if (prop.serializedObject.FindProperty("m_UseColorTemperature").boolValue)
                    {
                        prop = prop.serializedObject.FindProperty("m_ColorTemperature");
                        prop.floatValue = EditorGUI.FloatField(r, prop.floatValue);
                    }
                }),
                new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Float, HDStyles.Intensity, "m_Intensity", 60, (r, prop, dep) =>                // 8: Intensity
                {
                    Light light = prop.serializedObject.targetObject as Light;
                    if (light == null || lightDataPairing[light].hdAdditionalLightData == null)
                    {
                        EditorGUI.LabelField(r, "null");
                        return;
                    }
                    float intensity = lightDataPairing[light].hdAdditionalLightData.intensity;
                    EditorGUI.BeginChangeCheck();
                    intensity = EditorGUI.FloatField(r, intensity);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(lightDataPairing[light].hdAdditionalLightData, "Changed light intensity");
                        lightDataPairing[light].hdAdditionalLightData.intensity = intensity;
                    }
                }),
                new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Float, HDStyles.Unit, "m_Intensity", 60, (r, prop, dep) =>                // 9: Unit
                {
                    Light light = prop.serializedObject.targetObject as Light;
                    if (light == null || lightDataPairing[light].hdAdditionalLightData == null)
                    {
                        EditorGUI.LabelField(r, "null");
                        return;
                    }
                    LightUnit unit = lightDataPairing[light].hdAdditionalLightData.lightUnit;
                    EditorGUI.BeginChangeCheck();
                    unit = (LightUnit)EditorGUI.EnumPopup(r, unit);
                    if (EditorGUI.EndChangeCheck())
                    {
                        lightDataPairing[light].hdAdditionalLightData.lightUnit = unit;
                    }
                }),
                new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Float, HDStyles.IndirectMultiplier, "m_BounceIntensity", 90),                  // 10: Indirect multiplier
                new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Checkbox, HDStyles.Shadows, "m_Shadows.m_Type", 60, (r, prop, dep) =>          // 11: Shadows
                {
                    EditorGUI.BeginChangeCheck();
                    bool shadows = EditorGUI.Toggle(r, prop.intValue != (int)LightShadows.None);
                    if (EditorGUI.EndChangeCheck())
                    {
                        prop.intValue = shadows ? (int)LightShadows.Soft : (int)LightShadows.None;
                    }
                }),
                new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Checkbox, HDStyles.ContactShadows, "m_Shadows.m_Type", 100, (r, prop, dep) =>  // 12: Contact Shadows
                {
                    Light light = prop.serializedObject.targetObject as Light;
                    if (light == null || lightDataPairing[light].hdAdditionalLightData == null)
                    {
                        EditorGUI.LabelField(r, "null");
                        return;
                    }
                    bool contactShadows = lightDataPairing[light].hdAdditionalLightData.contactShadows;
                    EditorGUI.BeginChangeCheck();
                    contactShadows = EditorGUI.Toggle(r, contactShadows);
                    if (EditorGUI.EndChangeCheck())
                    {
                        lightDataPairing[light].hdAdditionalLightData.contactShadows = contactShadows;
                    }
                }),
                new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Checkbox, HDStyles.UseShadowQualitySettings, "m_Intensity", 60, (r, prop, dep) =>           // 13: Use Custom Shadow Res
                {
                    Light light = prop.serializedObject.targetObject as Light;
                    if (light == null || lightDataPairing[light].hdAdditionalLightData == null)
                    {
                        EditorGUI.LabelField(r, "null");
                        return;
                    }
                    bool useQualitySettings = lightDataPairing[light].hdAdditionalLightData.useShadowQualitySettings;
                    EditorGUI.BeginChangeCheck();
                    useQualitySettings = EditorGUI.Toggle(r, useQualitySettings);
                    if (EditorGUI.EndChangeCheck())
                    {
                        lightDataPairing[light].hdAdditionalLightData.useShadowQualitySettings = useQualitySettings;
                    }
                }),
                new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Enum, HDStyles.ShadowResolutionTier, "m_Intensity", 60, (r, prop, dep) =>           // 14: Shadow tiers
                {
                    Light light = prop.serializedObject.targetObject as Light;
                    if (light == null || lightDataPairing[light].hdAdditionalLightData == null)
                    {
                        EditorGUI.LabelField(r, "null");
                        return;
                    }
                    ShadowResolutionTier resTier = lightDataPairing[light].hdAdditionalLightData.shadowResolutionTier;
                    EditorGUI.BeginChangeCheck();
                    resTier = (ShadowResolutionTier)EditorGUI.EnumPopup(r, resTier);
                    if (EditorGUI.EndChangeCheck())
                    {
                        lightDataPairing[light].hdAdditionalLightData.shadowResolutionTier = resTier;
                    }
                }),

                new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Int, HDStyles.CustomShadowResolution, "m_Intensity", 60, (r, prop, dep) =>           // 15: Custom Shadow resolution
                {
                    Light light = prop.serializedObject.targetObject as Light;
                    if (light == null || lightDataPairing[light].hdAdditionalLightData == null)
                    {
                        EditorGUI.LabelField(r, "null");
                        return;
                    }
                    int customResolution = lightDataPairing[light].hdAdditionalLightData.customResolution;
                    EditorGUI.BeginChangeCheck();
                    customResolution = EditorGUI.IntField(r, customResolution);
                    if (EditorGUI.EndChangeCheck())
                    {
                        lightDataPairing[light].hdAdditionalLightData.customResolution = customResolution;
                    }
                }),
                new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Checkbox, HDStyles.AffectDiffuse, "m_Intensity", 90, (r, prop, dep) =>         // 16: Affect Diffuse
                {
                    Light light = prop.serializedObject.targetObject as Light;
                    if (light == null || lightDataPairing[light].hdAdditionalLightData == null)
                    {
                        EditorGUI.LabelField(r, "null");
                        return;
                    }
                    bool affectDiffuse = lightDataPairing[light].hdAdditionalLightData.affectDiffuse;
                    EditorGUI.BeginChangeCheck();
                    affectDiffuse = EditorGUI.Toggle(r, affectDiffuse);
                    if (EditorGUI.EndChangeCheck())
                    {
                        lightDataPairing[light].hdAdditionalLightData.affectDiffuse = affectDiffuse;
                    }
                }),
                new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Checkbox, HDStyles.AffectSpecular, "m_Intensity", 90, (r, prop, dep) =>        // 17: Affect Specular
                {
                    Light light = prop.serializedObject.targetObject as Light;
                    if (light == null || lightDataPairing[light].hdAdditionalLightData == null)
                    {
                        EditorGUI.LabelField(r, "null");
                        return;
                    }
                    bool affectSpecular = lightDataPairing[light].hdAdditionalLightData.affectSpecular;
                    EditorGUI.BeginChangeCheck();
                    affectSpecular = EditorGUI.Toggle(r, affectSpecular);
                    if (EditorGUI.EndChangeCheck())
                    {
                        lightDataPairing[light].hdAdditionalLightData.affectSpecular = affectSpecular;
                    }
                }),
                new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Float, HDStyles.FadeDistance, "m_Intensity", 60, (r, prop, dep) =>                // 18: Fade Distance
                {
                    Light light = prop.serializedObject.targetObject as Light;
                    if (light == null || lightDataPairing[light].hdAdditionalLightData == null)
                    {
                        EditorGUI.LabelField(r, "null");
                        return;
                    }
                    float fadeDistance = lightDataPairing[light].hdAdditionalLightData.fadeDistance;
                    EditorGUI.BeginChangeCheck();
                    fadeDistance = EditorGUI.FloatField(r, fadeDistance);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(lightDataPairing[light].hdAdditionalLightData, "Changed light fade distance");
                        lightDataPairing[light].hdAdditionalLightData.fadeDistance = fadeDistance;
                    }
                }),
                new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Float, HDStyles.ShadowFadeDistance, "m_Intensity", 60, (r, prop, dep) =>           // 19: Shadow Fade Distance
                {
                    Light light = prop.serializedObject.targetObject as Light;
                    if (light == null || lightDataPairing[light].hdAdditionalLightData == null)
                    {
                        EditorGUI.LabelField(r, "null");
                        return;
                    }
                    float shadowFadeDistance = lightDataPairing[light].hdAdditionalLightData.shadowFadeDistance;
                    EditorGUI.BeginChangeCheck();
                    shadowFadeDistance = EditorGUI.FloatField(r, shadowFadeDistance);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(lightDataPairing[light].hdAdditionalLightData, "Changed light shadow fade distance");
                        lightDataPairing[light].hdAdditionalLightData.shadowFadeDistance = shadowFadeDistance;
                    }
                }),
                new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Custom, HDStyles.LightLayer, "m_RenderingLayerMask", 80, (r, prop, dep) =>     // 20: Light Layer
                {
                    using (new EditorGUI.DisabledScope(!(GraphicsSettings.renderPipelineAsset as HDRenderPipelineAsset).currentPlatformRenderPipelineSettings.supportLightLayers))
                    {
                        HDEditorUtils.LightLayerMaskPropertyDrawer(r, prop);
                    }
                }),
                new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Custom, HDStyles.IsPrefab, "m_Intensity", 60, (r, prop, dep) =>                // 21: Prefab
                {
                    Light light = prop.serializedObject.targetObject as Light;
                    if (light == null)
                    {
                        EditorGUI.LabelField(r, "null");
                        return;
                    }
                    bool isPrefab = lightDataPairing[light].isPrefab;
                    if (isPrefab)
                    {
                        EditorGUI.ObjectField(r, lightDataPairing[light].prefabRoot, typeof(GameObject), false);
                    }
                }),
            });
        }
Exemplo n.º 27
0
        public void AddOptions(GameObject SelectedObject, ObjectEditUI ObjectEdit)
        {
            var lights = SelectedObject.GetComponentsInChildren <Light>(true);

            if (lights != null && lights.Any())
            {
                var light     = lights.First();
                var hdrpLight = light.GetComponent <HDAdditionalLightData>();

                var lightExpandable = ObjectEdit.AddLightSettings();

                var expandable = lightExpandable.GetComponent <LightSettingsExpandable>();

                Enabled = light.enabled;

                expandable.EnabledToggle.Toggle.onValueChanged.AddListener((isOn) =>
                {
                    Enabled = isOn;
                    foreach (var lightToEdit in lights)
                    {
                        lightToEdit.GetComponent <HDAdditionalLightData>().enabled = isOn;
                        lightToEdit.enabled = isOn;
                    }
                });

                #region Intensity slider
                hdrpLight.lightUnit = LightUnit.Ev100;
                float currentIntensity = Mathf.Clamp(hdrpLight.intensity, ev100Min, ev100Max);
                float sliderValue      = ((currentIntensity - ev100Min) / (ev100Max - ev100Min)) * numSteps;
                Intensity = sliderValue;
                Unit      = LightUnit.Ev100;
                expandable.IntensitySlider.Slider.value = sliderValue;

                float labelText = ev100Min + ((sliderValue / numSteps) * (ev100Max - ev100Min));
                expandable.IntensitySlider.Value.SetText(labelText.ToString("N"));

                expandable.IntensitySlider.Slider.onValueChanged.AddListener((intensity) =>
                {
                    foreach (var lightToEdit in lights)
                    {
                        var hdrpLightToEdit = lightToEdit.GetComponent <HDAdditionalLightData>();

                        float newIntensity = ev100Min + ((intensity / numSteps) * (ev100Max - ev100Min));

                        expandable.IntensitySlider.Value.SetText(newIntensity.ToString("N"));
                        Intensity = newIntensity;
                        Unit      = LightUnit.Ev100;
                        hdrpLightToEdit.SetIntensity(newIntensity, LightUnit.Ev100);
                    }
                });
                #endregion

                #region Range slider
                float currentRange = Mathf.Clamp(hdrpLight.range, rangeMin, rangeMax);
                Range = currentRange;
                float rangeSliderValue = ((currentRange - rangeMin) / (rangeMax - rangeMin)) * numRangeSteps;
                expandable.RangeSlider.Slider.value = rangeSliderValue;
                expandable.RangeSlider.Value.SetText(rangeSliderValue.ToString("N"));

                expandable.RangeSlider.Slider.onValueChanged.AddListener((range) =>
                {
                    foreach (var lightToEdit in lights)
                    {
                        float newRange = rangeMin + ((range / numRangeSteps) * (rangeMax - rangeMin));
                        Range          = newRange;
                        expandable.RangeSlider.Value.SetText(newRange.ToString("N"));

                        lightToEdit.GetComponent <HDAdditionalLightData>().SetRange(newRange);
                    }
                });
                #endregion

                #region Angle slider
                if (hdrpLight.type != HDLightType.Spot)
                {
                    Angle = null;
                    expandable.AngleSlider.Slider.interactable = false;
                }
                else
                {
                    float spotAngle = Mathf.Clamp(light.spotAngle, angleMin, angleMax);
                    Angle = spotAngle;
                    float angleSliderValue = ((spotAngle - angleMin) / (angleMax - angleMin)) * numAngleSteps;
                    expandable.AngleSlider.Slider.value = angleSliderValue;
                    expandable.AngleSlider.Value.SetText($"{(int)angleSliderValue}°");

                    expandable.AngleSlider.Slider.onValueChanged.AddListener((angle) =>
                    {
                        foreach (var lightToEdit in lights)
                        {
                            float newSpotAngle    = angleMin + (((angle - angleMin) / numAngleSteps) * (angleMax - angleMin));
                            lightToEdit.spotAngle = newSpotAngle;
                            Angle = newSpotAngle;
                            expandable.AngleSlider.Value.SetText($"{(int)newSpotAngle}°");
                        }
                    });
                }
                #endregion

                #region Color sliders
                Color = new Vector3(hdrpLight.color.r, hdrpLight.color.g, hdrpLight.color.b);

                expandable.ColorSliders.XSlider.Slider.value = hdrpLight.color.r;
                expandable.ColorSliders.XSlider.Value.SetText(hdrpLight.color.r.ToString("N"));

                expandable.ColorSliders.YSlider.Slider.value = hdrpLight.color.g;
                expandable.ColorSliders.YSlider.Value.SetText(hdrpLight.color.g.ToString("N"));

                expandable.ColorSliders.ZSlider.Slider.value = hdrpLight.color.b;
                expandable.ColorSliders.ZSlider.Value.SetText(hdrpLight.color.b.ToString("N"));

                expandable.ColorSliders.onValueChanged += (color) =>
                {
                    Color = color;
                    foreach (var lightToEdit in lights)
                    {
                        lightToEdit.GetComponent <HDAdditionalLightData>().color = new Color(color.x, color.y, color.z);

                        expandable.ColorSliders.XSlider.Value.SetText(color.x.ToString("N"));
                        expandable.ColorSliders.YSlider.Value.SetText(color.y.ToString("N"));
                        expandable.ColorSliders.ZSlider.Value.SetText(color.z.ToString("N"));
                    }
                };
                #endregion
            }
        }
Exemplo n.º 28
0
        protected virtual LightingExplorerTableColumn[] GetHDLightColumns()
        {
            return(new[]
            {
                new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Name, HDStyles.Name, null, 200),                                               // 0: Name
                new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Checkbox, HDStyles.On, "m_Enabled", 25),                                       // 1: Enabled
                new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Enum, HDStyles.Type, "m_Type", 60),                                            // 2: Type
                new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Enum, HDStyles.Mode, "m_Lightmapping", 60),                                    // 3: Mixed mode
                new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Enum, HDStyles.Range, "m_Range", 60),                                          // 4: Range
                new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Checkbox, HDStyles.ColorTemperatureMode, "m_UseColorTemperature", 100),        // 5: Color Temperature Mode
                new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Color, HDStyles.Color, "m_Color", 60),                                         // 6: Color
                new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Float, HDStyles.ColorTemperature, "m_ColorTemperature", 100, (r, prop, dep) => // 7: Color Temperature
                {
                    if (prop.serializedObject.FindProperty("m_UseColorTemperature").boolValue)
                    {
                        prop = prop.serializedObject.FindProperty("m_ColorTemperature");
                        prop.floatValue = EditorGUI.FloatField(r, prop.floatValue);
                    }
                }),
                new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Float, HDStyles.Intensity, "m_Intensity", 60, (r, prop, dep) =>                // 8: Intensity
                {
                    Light light = prop.serializedObject.targetObject as Light;
                    if (light == null || lightDataPairing[light].hdAdditionalLightData == null)
                    {
                        EditorGUI.LabelField(r, "null");
                        return;
                    }
                    float intensity = lightDataPairing[light].hdAdditionalLightData.intensity;
                    EditorGUI.BeginChangeCheck();
                    intensity = EditorGUI.FloatField(r, intensity);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(lightDataPairing[light].hdAdditionalLightData, "Changed light intensity");
                        lightDataPairing[light].hdAdditionalLightData.intensity = intensity;
                    }
                }),
                new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Float, HDStyles.Unit, "m_Intensity", 60, (r, prop, dep) =>                // 9: Unit
                {
                    Light light = prop.serializedObject.targetObject as Light;
                    if (light == null || lightDataPairing[light].hdAdditionalLightData == null)
                    {
                        EditorGUI.LabelField(r, "null");
                        return;
                    }
                    LightUnit unit = lightDataPairing[light].hdAdditionalLightData.lightUnit;
                    EditorGUI.BeginChangeCheck();
                    unit = (LightUnit)EditorGUI.EnumPopup(r, unit);
                    if (EditorGUI.EndChangeCheck())
                    {
                        lightDataPairing[light].hdAdditionalLightData.lightUnit = unit;
                    }
                }),
                new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Float, HDStyles.IndirectMultiplier, "m_BounceIntensity", 90),                  // 10: Indirect multiplier
                new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Checkbox, HDStyles.Shadows, "m_Shadows.m_Type", 60, (r, prop, dep) =>          // 11: Shadows
                {
                    EditorGUI.BeginChangeCheck();
                    bool shadows = EditorGUI.Toggle(r, prop.intValue != (int)LightShadows.None);
                    if (EditorGUI.EndChangeCheck())
                    {
                        prop.intValue = shadows ? (int)LightShadows.Soft : (int)LightShadows.None;
                    }
                }),
                new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Custom, HDStyles.ContactShadowsSource, "m_Shadows.m_Type", 100, (r, prop, dep) =>  // 12: Contact Shadows
                {
                    Light light = prop.serializedObject.targetObject as Light;
                    if (light == null || lightDataPairing[light].hdAdditionalLightData == null)
                    {
                        EditorGUI.LabelField(r, "null");
                        return;
                    }

                    var value = lightDataPairing[light].hdAdditionalLightData.useContactShadow;
                    EditorGUI.BeginChangeCheck();
                    var(level, useOverride) = SerializedScalableSettingValueUI.LevelFieldGUI(r, GUIContent.none, value.level,
                                                                                             value.useOverride);
                    if (EditorGUI.EndChangeCheck())
                    {
                        value.level = level;
                        value.useOverride = useOverride;
                    }
                }),
                new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Checkbox, HDStyles.ContactShadowsValue, "m_Shadows.m_Type", 100, (r, prop, dep) =>  // 12: Contact Shadows
                {
                    Light light = prop.serializedObject.targetObject as Light;
                    if (light == null || lightDataPairing[light].hdAdditionalLightData == null)
                    {
                        EditorGUI.LabelField(r, "null");
                        return;
                    }

                    var value = lightDataPairing[light].hdAdditionalLightData.useContactShadow;
                    if (value.useOverride)
                    {
                        value.@override = EditorGUI.Toggle(r, value.@override);
                    }
                    else
                    {
                        var hdrp = GraphicsSettings.currentRenderPipeline as HDRenderPipelineAsset;
                        var defaultValue = HDAdditionalLightData.ScalableSettings.UseContactShadow(hdrp);
                        var enabled = GUI.enabled;
                        GUI.enabled = false;
                        EditorGUI.Toggle(r, defaultValue[value.level]);
                        GUI.enabled = enabled;
                    }
                }),
                new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Enum, HDStyles.ShadowResolutionSource, "m_Intensity", 60, (r, prop, dep) =>           // 14: Shadow Resolution Source
                {
                    Light light = prop.serializedObject.targetObject as Light;
                    if (light == null || lightDataPairing[light].hdAdditionalLightData == null)
                    {
                        EditorGUI.LabelField(r, "null");
                        return;
                    }
                    var shadowResolution = lightDataPairing[light].hdAdditionalLightData.shadowResolution;
                    EditorGUI.BeginChangeCheck();
                    var(level, useOverride) = SerializedShadowResolutionSettingValueUI.LevelFieldGUI(r, shadowResolution.level, shadowResolution.useOverride);
                    if (EditorGUI.EndChangeCheck())
                    {
                        shadowResolution.level = level;
                        shadowResolution.useOverride = useOverride;
                    }
                }),
                new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Int, HDStyles.ShadowResolutionValue, "m_Intensity", 60, (r, prop, dep) =>           // 15: Shadow resolution value
                {
                    var hdrp = GraphicsSettings.currentRenderPipeline as HDRenderPipelineAsset;
                    Light light = prop.serializedObject.targetObject as Light;
                    if (light == null || lightDataPairing[light].hdAdditionalLightData == null || hdrp == null)
                    {
                        EditorGUI.LabelField(r, "null");
                        return;
                    }
                    var shadowResolution = lightDataPairing[light].hdAdditionalLightData.shadowResolution;
                    if (shadowResolution.useOverride)
                    {
                        shadowResolution.@override = EditorGUI.IntField(r, shadowResolution.@override);
                    }
                    else
                    {
                        var lightShape = SerializedHDLight.ResolveLightShape(lightDataPairing[light].hdAdditionalLightData.lightTypeExtent, light.type);
                        var defaultValue = HDLightUI.ScalableSettings.ShadowResolution(lightShape, hdrp);
                        EditorGUI.LabelField(r, defaultValue[shadowResolution.level].ToString());
                    }
                }),
                new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Checkbox, HDStyles.AffectDiffuse, "m_Intensity", 90, (r, prop, dep) =>         // 16: Affect Diffuse
                {
                    Light light = prop.serializedObject.targetObject as Light;
                    if (light == null || lightDataPairing[light].hdAdditionalLightData == null)
                    {
                        EditorGUI.LabelField(r, "null");
                        return;
                    }
                    bool affectDiffuse = lightDataPairing[light].hdAdditionalLightData.affectDiffuse;
                    EditorGUI.BeginChangeCheck();
                    affectDiffuse = EditorGUI.Toggle(r, affectDiffuse);
                    if (EditorGUI.EndChangeCheck())
                    {
                        lightDataPairing[light].hdAdditionalLightData.affectDiffuse = affectDiffuse;
                    }
                }),
                new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Checkbox, HDStyles.AffectSpecular, "m_Intensity", 90, (r, prop, dep) =>        // 17: Affect Specular
                {
                    Light light = prop.serializedObject.targetObject as Light;
                    if (light == null || lightDataPairing[light].hdAdditionalLightData == null)
                    {
                        EditorGUI.LabelField(r, "null");
                        return;
                    }
                    bool affectSpecular = lightDataPairing[light].hdAdditionalLightData.affectSpecular;
                    EditorGUI.BeginChangeCheck();
                    affectSpecular = EditorGUI.Toggle(r, affectSpecular);
                    if (EditorGUI.EndChangeCheck())
                    {
                        lightDataPairing[light].hdAdditionalLightData.affectSpecular = affectSpecular;
                    }
                }),
                new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Float, HDStyles.FadeDistance, "m_Intensity", 60, (r, prop, dep) =>                // 18: Fade Distance
                {
                    Light light = prop.serializedObject.targetObject as Light;
                    if (light == null || lightDataPairing[light].hdAdditionalLightData == null)
                    {
                        EditorGUI.LabelField(r, "null");
                        return;
                    }
                    float fadeDistance = lightDataPairing[light].hdAdditionalLightData.fadeDistance;
                    EditorGUI.BeginChangeCheck();
                    fadeDistance = EditorGUI.FloatField(r, fadeDistance);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(lightDataPairing[light].hdAdditionalLightData, "Changed light fade distance");
                        lightDataPairing[light].hdAdditionalLightData.fadeDistance = fadeDistance;
                    }
                }),
                new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Float, HDStyles.ShadowFadeDistance, "m_Intensity", 60, (r, prop, dep) =>           // 19: Shadow Fade Distance
                {
                    Light light = prop.serializedObject.targetObject as Light;
                    if (light == null || lightDataPairing[light].hdAdditionalLightData == null)
                    {
                        EditorGUI.LabelField(r, "null");
                        return;
                    }
                    float shadowFadeDistance = lightDataPairing[light].hdAdditionalLightData.shadowFadeDistance;
                    EditorGUI.BeginChangeCheck();
                    shadowFadeDistance = EditorGUI.FloatField(r, shadowFadeDistance);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(lightDataPairing[light].hdAdditionalLightData, "Changed light shadow fade distance");
                        lightDataPairing[light].hdAdditionalLightData.shadowFadeDistance = shadowFadeDistance;
                    }
                }),
                new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Custom, HDStyles.LightLayer, "m_RenderingLayerMask", 80, (r, prop, dep) =>     // 20: Light Layer
                {
                    using (new EditorGUI.DisabledScope(!(GraphicsSettings.renderPipelineAsset as HDRenderPipelineAsset).currentPlatformRenderPipelineSettings.supportLightLayers))
                    {
                        HDEditorUtils.LightLayerMaskPropertyDrawer(r, prop);
                    }
                }),
                new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Custom, HDStyles.IsPrefab, "m_Intensity", 60, (r, prop, dep) =>                // 21: Prefab
                {
                    Light light = prop.serializedObject.targetObject as Light;
                    if (light == null)
                    {
                        EditorGUI.LabelField(r, "null");
                        return;
                    }
                    bool isPrefab = lightDataPairing[light].isPrefab;
                    if (isPrefab)
                    {
                        EditorGUI.ObjectField(r, lightDataPairing[light].prefabRoot, typeof(GameObject), false);
                    }
                }),
            });
        }