Пример #1
0
            public override void OnGUI(Rect rect)
            {
                GUILayout.BeginVertical();
                {
                    GUILayout.Label(styles.sEnvironment, EditorStyles.miniLabel);
                    EditorGUI.BeginChangeCheck();
                    float angleOffset = EditorGUILayout.Slider(styles.sAngleOffset, m_CubemapInfo.angleOffset % 360.0f, -360.0f, 360.0f);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(m_LookDevView.envLibrary, "Changed environment settings");
                        m_CubemapInfo.angleOffset      = angleOffset;
                        m_LookDevView.envLibrary.dirty = true;
                        m_LookDevView.Repaint();
                    }

                    if (GUILayout.Button(styles.sResetEnv, EditorStyles.toolbarButton))
                    {
                        Undo.RecordObject(m_LookDevView.envLibrary, "Changed environment settings");
                        m_CubemapInfo.ResetEnvInfos();
                        m_LookDevView.envLibrary.dirty = true;
                        m_LookDevView.Repaint();
                    }

                    using (new EditorGUI.DisabledScope(!m_LookDevView.config.enableShadowCubemap))
                    {
                        DrawSeparator();
                        GUILayout.Label(styles.sShadows, EditorStyles.miniLabel);

                        EditorGUI.BeginChangeCheck();
                        float shadowIntensity = EditorGUILayout.Slider(styles.sShadowIntensity, m_CubemapInfo.shadowInfo.shadowIntensity, 0.0f, 5.0f);
                        Color shadowColor     = EditorGUILayout.ColorField(styles.sShadowColor, m_CubemapInfo.shadowInfo.shadowColor);
                        if (EditorGUI.EndChangeCheck())
                        {
                            Undo.RecordObject(m_LookDevView.envLibrary, "Changed shadow settings");
                            m_CubemapInfo.shadowInfo.shadowIntensity = shadowIntensity;
                            m_CubemapInfo.shadowInfo.shadowColor     = shadowColor;
                            m_LookDevView.envLibrary.dirty           = true;
                            m_LookDevView.Repaint();
                        }

                        if (GUILayout.Button(styles.sBrightest, EditorStyles.toolbarButton))
                        {
                            Undo.RecordObject(m_LookDevView.envLibrary, "Changed shadow settings");
                            LookDevResources.UpdateShadowInfoWithBrightestSpot(m_CubemapInfo);
                            m_LookDevView.envLibrary.dirty = true;
                            m_LookDevView.Repaint();
                        }

                        if (GUILayout.Button(styles.sResetShadow, EditorStyles.toolbarButton))
                        {
                            Undo.RecordObject(m_LookDevView.envLibrary, "Changed shadow settings");
                            m_CubemapInfo.SetCubemapShadowInfo(m_CubemapInfo);
                            m_LookDevView.envLibrary.dirty = true;
                            m_LookDevView.Repaint();
                        }
                    }
                }
                GUILayout.EndVertical();
            }
        public void InsertHDRI(Cubemap cubemap, int insertionIndex)
        {
            Undo.RecordObject(this.m_LookDevView.envLibrary, "Insert HDRI");
            Undo.RecordObject(this.m_LookDevView.config, "Insert HDRI");
            Cubemap cubemap0 = null;
            Cubemap cubemap1 = null;

            if (cubemap == LookDevResources.m_DefaultHDRI)
            {
                cubemap0 = LookDevResources.m_DefaultHDRI;
                cubemap1 = LookDevResources.m_DefaultHDRI;
            }
            else
            {
                cubemap0 = this.m_HDRIList[this.m_LookDevView.config.lookDevContexts[0].currentHDRIIndex].cubemap;
                cubemap1 = this.m_HDRIList[this.m_LookDevView.config.lookDevContexts[1].currentHDRIIndex].cubemap;
            }
            int num = this.m_HDRIList.FindIndex((CubemapInfo x) => x.cubemap == cubemap);

            if (num == -1)
            {
                this.m_Dirty = true;
                CubemapInfo cubemapInfo = null;
                for (int i = 0; i < this.m_HDRIList.Count; i++)
                {
                    if (this.m_HDRIList[i].cubemapShadowInfo.cubemap == cubemap)
                    {
                        cubemapInfo = this.m_HDRIList[i].cubemapShadowInfo;
                        cubemapInfo.SetCubemapShadowInfo(cubemapInfo);
                        break;
                    }
                }
                if (cubemapInfo == null)
                {
                    cubemapInfo         = new CubemapInfo();
                    cubemapInfo.cubemap = cubemap;
                    cubemapInfo.ambientProbe.Clear();
                    cubemapInfo.alreadyComputed = false;
                    cubemapInfo.SetCubemapShadowInfo(cubemapInfo);
                }
                int count = this.m_HDRIList.Count;
                this.m_HDRIList.Insert((insertionIndex != -1) ? insertionIndex : count, cubemapInfo);
                if (cubemapInfo.cubemap != LookDevResources.m_DefaultHDRI)
                {
                    LookDevResources.UpdateShadowInfoWithBrightestSpot(cubemapInfo);
                }
            }
            if (num != insertionIndex && num != -1 && insertionIndex != -1)
            {
                CubemapInfo item = this.m_HDRIList[num];
                this.m_HDRIList.RemoveAt(num);
                this.m_HDRIList.Insert((num <= insertionIndex) ? (insertionIndex - 1) : insertionIndex, item);
            }
            this.m_LookDevView.config.lookDevContexts[0].UpdateProperty(LookDevProperty.HDRI, this.m_HDRIList.FindIndex((CubemapInfo x) => x.cubemap == cubemap0));
            this.m_LookDevView.config.lookDevContexts[1].UpdateProperty(LookDevProperty.HDRI, this.m_HDRIList.FindIndex((CubemapInfo x) => x.cubemap == cubemap1));
            this.m_LookDevView.Repaint();
        }
            public override void OnGUI(Rect rect)
            {
                GUILayout.BeginVertical(new GUILayoutOption[0]);
                GUILayout.Label(styles.sEnvironment, EditorStyles.miniLabel, new GUILayoutOption[0]);
                EditorGUI.BeginChangeCheck();
                float num = EditorGUILayout.Slider(styles.sAngleOffset, this.m_CubemapInfo.angleOffset % 360f, -360f, 360f, new GUILayoutOption[0]);

                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(this.m_LookDevView.envLibrary, "Changed environment settings");
                    this.m_CubemapInfo.angleOffset      = num;
                    this.m_LookDevView.envLibrary.dirty = true;
                    this.m_LookDevView.Repaint();
                }
                if (GUILayout.Button(styles.sResetEnv, EditorStyles.toolbarButton, new GUILayoutOption[0]))
                {
                    Undo.RecordObject(this.m_LookDevView.envLibrary, "Changed environment settings");
                    this.m_CubemapInfo.ResetEnvInfos();
                    this.m_LookDevView.envLibrary.dirty = true;
                    this.m_LookDevView.Repaint();
                }
                using (new EditorGUI.DisabledScope(!this.m_LookDevView.config.enableShadowCubemap))
                {
                    this.DrawSeparator();
                    GUILayout.Label(styles.sShadows, EditorStyles.miniLabel, new GUILayoutOption[0]);
                    EditorGUI.BeginChangeCheck();
                    float num2  = EditorGUILayout.Slider(styles.sShadowIntensity, this.m_CubemapInfo.shadowInfo.shadowIntensity, 0f, 5f, new GUILayoutOption[0]);
                    Color color = EditorGUILayout.ColorField(styles.sShadowColor, this.m_CubemapInfo.shadowInfo.shadowColor, new GUILayoutOption[0]);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(this.m_LookDevView.envLibrary, "Changed shadow settings");
                        this.m_CubemapInfo.shadowInfo.shadowIntensity = num2;
                        this.m_CubemapInfo.shadowInfo.shadowColor     = color;
                        this.m_LookDevView.envLibrary.dirty           = true;
                        this.m_LookDevView.Repaint();
                    }
                    if (GUILayout.Button(styles.sBrightest, EditorStyles.toolbarButton, new GUILayoutOption[0]))
                    {
                        Undo.RecordObject(this.m_LookDevView.envLibrary, "Changed shadow settings");
                        LookDevResources.UpdateShadowInfoWithBrightestSpot(this.m_CubemapInfo);
                        this.m_LookDevView.envLibrary.dirty = true;
                        this.m_LookDevView.Repaint();
                    }
                    if (GUILayout.Button(styles.sResetShadow, EditorStyles.toolbarButton, new GUILayoutOption[0]))
                    {
                        Undo.RecordObject(this.m_LookDevView.envLibrary, "Changed shadow settings");
                        this.m_CubemapInfo.SetCubemapShadowInfo(this.m_CubemapInfo);
                        this.m_LookDevView.envLibrary.dirty = true;
                        this.m_LookDevView.Repaint();
                    }
                }
                GUILayout.EndVertical();
            }
Пример #4
0
        // If insertionIndex is -1 it mean we insert at the end of the list
        public void InsertHDRI(Cubemap cubemap, int insertionIndex)
        {
            Undo.RecordObject(m_LookDevView.envLibrary, "Insert HDRI");
            Undo.RecordObject(m_LookDevView.config, "Insert HDRI");

            // Handle cubemap index remapping for both context. Simply do it brute force in all cases.
            // Save the cubemap info before any modification to m_HDRIList.
            // Also if we are inserting m_DefaultHDRI, it mean we have an empty m_HDRIList
            Cubemap cubemap0 = null;
            Cubemap cubemap1 = null;

            if (cubemap == LookDevResources.m_DefaultHDRI)
            {
                cubemap0 = LookDevResources.m_DefaultHDRI;
                cubemap1 = LookDevResources.m_DefaultHDRI;
            }
            else
            {
                cubemap0 = m_HDRIList[m_LookDevView.config.lookDevContexts[0].currentHDRIIndex].cubemap;
                cubemap1 = m_HDRIList[m_LookDevView.config.lookDevContexts[1].currentHDRIIndex].cubemap;
            }

            // Check if the cubemap already exist
            int iIndex = m_HDRIList.FindIndex(x => x.cubemap == cubemap);

            // Create cubemap if it doesn't exist
            if (iIndex == -1)
            {
                m_Dirty = true;

                CubemapInfo newInfo = null;

                // Check if the cubemap exist but as a shadow cubemap only
                // in this case we don't recreate the CubemapInfo, but we still insert it as a new one.
                for (int i = 0; i < m_HDRIList.Count; ++i)
                {
                    if (m_HDRIList[i].cubemapShadowInfo.cubemap == cubemap)
                    {
                        newInfo = m_HDRIList[i].cubemapShadowInfo;
                        // Prevent recursion with shadow cubemap info
                        newInfo.SetCubemapShadowInfo(newInfo);
                        break;
                    }
                }

                if (newInfo == null)
                {
                    newInfo         = new CubemapInfo();
                    newInfo.cubemap = cubemap;
                    newInfo.ambientProbe.Clear();
                    newInfo.alreadyComputed = false;
                    newInfo.SetCubemapShadowInfo(newInfo); // By default we use the same cubemap for the version without sun.
                }

                int newCubemapIndex = m_HDRIList.Count;
                // Add the cubemap to the specified location or last if no location provide
                m_HDRIList.Insert(insertionIndex == -1 ? newCubemapIndex : insertionIndex, newInfo);

                // When inserting the default HDRI the first time, the lookdev env is not yet ready.
                // But as we default the latlong light position of ShadowInfo to brightest location of default HDRI this is not a problem to not call the function.
                if (newInfo.cubemap != LookDevResources.m_DefaultHDRI)
                {
                    LookDevResources.UpdateShadowInfoWithBrightestSpot(newInfo);
                }
            }

            // If we haven't inserted at end of the list, if it is not a new cubemap and if we do not insert at the same place, we need to shift current cubemap position in the list
            if (iIndex != insertionIndex && iIndex != -1 && insertionIndex != -1)
            {
                // Get cubemap info before modifying m_LookDevSetup.m_HDRIList;
                CubemapInfo infos = m_HDRIList[iIndex];

                m_HDRIList.RemoveAt(iIndex);
                // If we insert after the removed cubemap we need to increase the index
                m_HDRIList.Insert(iIndex > insertionIndex ? insertionIndex : insertionIndex - 1, infos);
            }

            m_LookDevView.config.lookDevContexts[0].UpdateProperty(LookDevProperty.HDRI, m_HDRIList.FindIndex(x => x.cubemap == cubemap0));
            m_LookDevView.config.lookDevContexts[1].UpdateProperty(LookDevProperty.HDRI, m_HDRIList.FindIndex(x => x.cubemap == cubemap1));

            m_LookDevView.Repaint();
        }