Exemplo n.º 1
0
 //for the sake of the apply to selection buttons...
 private void OnSelectionChange()
 {
     BeastConfig.RefreshConfig();
     uiSelectedSky = null;
     if (Selection.activeGameObject)
     {
         uiSelectedSky = Selection.activeGameObject.GetComponent <Sky>();
     }
     if (Selection.GetFiltered(typeof(Light), SelectionMode.Deep).Length > 0)
     {
         repaintOften = true;
     }
     else
     {
         repaintOften = false;
     }
     this.Repaint();
 }
Exemplo n.º 2
0
    ///
    public void OnGUI()
    {
        GUILayout.BeginArea(new Rect(0, 0, position.width, position.height));
        uiScroll = EditorGUILayout.BeginScrollView(uiScroll, false, false, GUILayout.MinWidth(300), GUILayout.MaxWidth(position.width));

        float rightPad     = 23;
        float minWidth     = 315;
        float sectionWidth = position.width - rightPad;
        float logoSize     = 128;

        Rect logoRect = EditorGUILayout.BeginVertical(); {
            GUILayout.Space(32);
            drawSkyshopLogo(sectionWidth - logoSize, logoRect.y, logoSize);
        } EditorGUILayout.EndVertical();

        uiHideDuringCompute = false;        //EditorGUILayout.Toggle("Hide UI During Compute",uiHideDuringCompute);
        if (!uiHideDuringCompute || !ps.isPlaying())
        {
            // INPUT REF
            EditorGUILayout.BeginVertical(); {
                inSKY.previewWidth = Mathf.Max(328, (int)sectionWidth - 2);
                inSKY.drawGUI();
                outDIM.inputPath = outSIM.inputPath = outSKY.inputPath = inSKY.fullPath;
            } EditorGUILayout.EndVertical();

            // OUTPUT REF
            EditorGUILayout.BeginVertical("HelpBox", GUILayout.Width(sectionWidth), GUILayout.MinWidth(minWidth)); {
                uiRefOptions = EditorGUILayout.Foldout(uiRefOptions, "Output Cubemaps");
                if (uiRefOptions)
                {
                    outSKY.drawGUI(); EditorGUILayout.Space();
                    outDIM.drawGUI(); EditorGUILayout.Space();
                    outSIM.drawGUI(); EditorGUILayout.Space();

                    EditorGUILayout.BeginHorizontal(); {
                        //apply buttons
                        if (GUILayout.Button(new GUIContent("Edit Active", ""), GUILayout.Width(80), GUILayout.Height(32)))
                        {
                            Sky sky = Sky.activeSky;
                            //sky = uiSelectedSky;
                            if (sky)
                            {
                                outSKY.HDR = sky.hdrSky;
                                outDIM.HDR = sky.hdrDiff;
                                outSIM.HDR = sky.hdrSpec;
                                outSKY.setReference(AssetDatabase.GetAssetPath(sky.skyboxCube), false);
                                outDIM.setReference(AssetDatabase.GetAssetPath(sky.diffuseCube), false);
                                outSIM.setReference(AssetDatabase.GetAssetPath(sky.specularCube), true);
                            }
                        }
                        EditorGUI.BeginDisabledGroup(uiSelectedSky == null);
                        if (GUILayout.Button(new GUIContent("Apply to Selected", ""), GUILayout.Width(130), GUILayout.Height(32)))
                        {
                            if (uiSelectedSky)
                            {
                                Undo.RegisterSceneUndo("Apply to Selected Sky");
                                uiSelectedSky.diffuseCube     = outDIM.cube;
                                uiSelectedSky.specularCube    = outSIM.cube;
                                uiSelectedSky.skyboxCube      = outSKY.cube;
                                uiSelectedSky.masterIntensity = 1f;
                                uiSelectedSky.skyIntensity    = 1f;
                                uiSelectedSky.diffIntensity   = 1f;
                                uiSelectedSky.specIntensity   = 1f;
                                uiSelectedSky.hdrSky          = outSKY.HDR;
                                uiSelectedSky.hdrSpec         = outSIM.HDR;
                                uiSelectedSky.hdrDiff         = outDIM.HDR;
                                uiSelectedSky.Apply();                                 //Apply to Selected
                                SceneView.RepaintAll();
                            }
                        }
                        EditorGUI.EndDisabledGroup();
                        if (GUILayout.Button(new GUIContent("Add to Scene", ""), GUILayout.Width(100), GUILayout.Height(32)))
                        {
                            Sky skyScript = addSky();
                            if (skyScript)
                            {
                                skyScript.diffuseCube     = outDIM.cube;
                                skyScript.specularCube    = outSIM.cube;
                                skyScript.skyboxCube      = outSKY.cube;
                                skyScript.masterIntensity = 1f;
                                skyScript.skyIntensity    = 1f;
                                skyScript.diffIntensity   = 1f;
                                skyScript.specIntensity   = 1f;
                                skyScript.hdrSky          = outSKY.HDR;
                                skyScript.hdrSpec         = outSIM.HDR;
                                skyScript.hdrDiff         = outDIM.HDR;
                                skyScript.Apply();                                 //Add to Scene
                                SceneView.RepaintAll();
                            }
                        }
                    } EditorGUILayout.EndHorizontal();
                    EditorGUILayout.Space();
                }                // end if uiRefOptions
            } EditorGUILayout.EndVertical();

            // BASIC
            string tipExposure = "A multiplier on all the pixels in the Input Panorama during computation. Use for uniform brightness adjustment of results.";
            string tipQuality  = "Changes some advanced options to balance between image quality and computation speed.";

            EditorGUILayout.BeginVertical("HelpBox", GUILayout.Width(sectionWidth), GUILayout.MinWidth(minWidth)); {
                uiBasicOptions = EditorGUILayout.Foldout(uiBasicOptions, "Basic Options");
                if (uiBasicOptions)
                {
                    float newExposure = EditorGUILayout.FloatField(new GUIContent("Baked Exposure", "Baked Exposure -\n" + tipExposure), uiExposure, GUILayout.Width(300));
                    newExposure = Mathf.Max(0.0f, newExposure);
                    if (newExposure != uiExposure)
                    {
                        Undo.RegisterUndo(this, "Change Exposure");
                        uiExposure = newExposure;
                    }


                    Quality newQuality = (Quality)EditorGUILayout.EnumPopup(
                        new GUIContent("Quality", "Quality -\n" + tipQuality),
                        (Quality)uiConvoQuality,
                        GUILayout.Width(300)
                        );

                    if (newQuality != uiConvoQuality)
                    {
                        Undo.RegisterUndo(this, "Change Quality");
                        uiConvoQuality = newQuality;
                        switch (uiConvoQuality)
                        {
                        case Quality.ultra:     uiConvoSize = 64; break;

                        case Quality.high:              uiConvoSize = 32; break;

                        case Quality.medium:    uiConvoSize = 16; break;

                        case Quality.low:               uiConvoSize = 8; break;
                        }
                    }

                    /*
                     * uiCubeSize = (TexSize)EditorGUILayout.EnumPopup(
                     *      new GUIContent("Output Size (cube)","Output Size -\n"+tipCubeSize),
                     *      (CubeSize)uiCubeSize,
                     *      GUILayout.Width(300)
                     * );*/

                    EditorGUILayout.Space();
                }                // end if uiBasicOptions
            } EditorGUILayout.EndVertical();

            // PRO MOVES
            string tipConvoSize    = "Resolution the input panorama is downsampled to for convolution, must be power of 2.\n\nWarning: High resolutions can lead to VERY long computation times!";
            string tipMipChain     = "If enabled, different specular gloss exponents are computed and stored in each mipmap level of the Specular Output cube.\n\nThis must be enabled for Gloss Maps to function in Marmoset Shaders.";
            string tipExponent     = "Gloss exponent used in computing the Specular Output cubemap. Value must be a power of 2, lower values result in a blurrier cubemap. Only available when \"Build Mip Chains\" is disabled.";
            string tipExponents    = "Displays a list of the specular gloss exponents used in the various mip levels of the Specular Output cube.";
            string tipResponsiveUI = "Enable if Unity is too unresponsive during computation. Will slow overall computation time.";
            string tipReflection   = "Highest gloss level in the specular mip chain is a polished mirror reflection pulled from the input panorama itself.";

            EditorGUILayout.BeginVertical("HelpBox", GUILayout.Width(sectionWidth), GUILayout.MinWidth(minWidth));
            {
                uiAdvancedOptions = EditorGUILayout.Foldout(uiAdvancedOptions, "Advanced Options");
                if (uiAdvancedOptions)
                {
                    int newConvoSize = EditorGUILayout.IntField(
                        new GUIContent("Convolution Size", "Convolution Size -\n" + tipConvoSize),
                        uiConvoSize,
                        GUILayout.Width(300)
                        );

                    if (newConvoSize < 2)
                    {
                        newConvoSize = 2;
                    }
                    newConvoSize += newConvoSize % 2;

                    if (newConvoSize != uiConvoSize)
                    {
                        Undo.RegisterUndo(this, "Change Convolution Size");
                        uiConvoSize    = newConvoSize;
                        uiConvoQuality = Quality.custom;
                        switch (uiConvoSize)
                        {
                        case 8: uiConvoQuality = Quality.low; break;

                        case 16: uiConvoQuality = Quality.medium; break;

                        case 32: uiConvoQuality = Quality.high; break;

                        case 64: uiConvoQuality = Quality.ultra; break;
                        }
                        ;
                    }
                    EditorGUILayout.Space();
                    CubemapGUI.drawStaticGUI();

                    bool newMipChain = EditorGUILayout.Toggle(new GUIContent("Build Specular Mip Chain", "Specular Mip Chains -\n" + tipMipChain), uiMipChain);
                    if (newMipChain != uiMipChain)
                    {
                        Undo.RegisterUndo(this, "Toggle Specular Mip Chain");
                        uiMipChain = newMipChain;
                    }
                    if (uiMipChain)
                    {
                        bool newRefInSIM = EditorGUILayout.Toggle(new GUIContent("Highest Mip is Reflection", "Highest Mip is Reflection -\n" + tipReflection), uiReflectionInSIM);
                        if (newRefInSIM != uiReflectionInSIM)
                        {
                            Undo.RegisterUndo(this, "Toggle Mip Chain Reflection");
                            uiReflectionInSIM = newRefInSIM;
                        }
                        EditorGUI.BeginDisabledGroup(true);
                        string mipString;
                        if (uiReflectionInSIM)
                        {
                            mipString = "mirror, 128, 64, 32, 16...";
                        }
                        else
                        {
                            mipString = "256, 128, 64, 32, 16, 8...";
                        }
                        EditorGUILayout.TextField(new GUIContent("Specular Exponents", "Specular Exponents -\n" + tipExponents), mipString, GUILayout.Width(300));
                        EditorGUI.EndDisabledGroup();
                    }
                    else
                    {
                        EditorGUI.BeginDisabledGroup(true);
                        EditorGUILayout.Toggle(new GUIContent("Highest Mip is Reflection", "Highest Mip is Reflection -\n" + tipReflection), false);
                        EditorGUI.EndDisabledGroup();
                        int newExponent = EditorGUILayout.IntField(
                            new GUIContent("Specular Exponent", "Specular Exponent -\n" + tipExponent),
                            uiExponent,
                            GUILayout.Width(300)
                            );
                        newExponent = Mathf.Max(1, newExponent);
                        if (newExponent != uiExponent)
                        {
                            Undo.RegisterUndo(this, "Change Specular Exponent");
                            uiExponent = newExponent;
                        }
                    }
                    EditorGUILayout.Space();

                    //TODO: Will anyone ever want this? Marmoset shaders need gamma compression as does sRGB sampling.
                    uiGammaCompress = true;

                    /*
                     * uiGammaCompress = EditorGUILayout.Toggle(new GUIContent(
                     *      "Gamma-Compress RGBM",
                     *      "Gamma-Compress RGBM -\nIf enabled, a gamma of 1/2.2 is applied to HDR data before it is encoded as RGBM. This adds dynamic range but also shader complexity. Leave enabled for Marmoset shaders."),
                     *      uiGammaCompress);
                     */

                    uiResponsiveUI = stepsPerFrame <= 1024 * 16;
                    uiResponsiveUI = EditorGUILayout.Toggle(new GUIContent("Keep UI Responsive", "Keep UI Responsive -\n" + tipResponsiveUI), uiResponsiveUI);
                    ulong newStepsPerFrame = stepsPerFrame;
                    if (uiResponsiveUI)
                    {
                        newStepsPerFrame = 1024 * 16;
                    }
                    else
                    {
                        newStepsPerFrame = 1024 * 256;
                    }

                    if (newStepsPerFrame != stepsPerFrame)
                    {
                        Undo.RegisterUndo(this, "Toggle Responsive UI");
                        stepsPerFrame = newStepsPerFrame;
                    }
                    EditorGUILayout.Space();


                    if (GUILayout.Button("Reset to Default", GUILayout.Width(120)))
                    {
                        uiConvoSize       = Mathf.Min(uiConvoSize, 16);
                        uiMipChain        = true;
                        uiReflectionInSIM = true;
                        uiResponsiveUI    = false;
                        uiGammaCompress   = true;
                    }
                    EditorGUILayout.Space();
                }
            } EditorGUILayout.EndVertical();

            EditorGUILayout.Space();
            EditorGUILayout.Space();
        }

        //GENERATE
        bool generate = false;
        bool cancel   = false;

        EditorGUILayout.BeginHorizontal(); {
            if (ps.isPlaying())
            {
                cancel = GUILayout.Button("Abort", GUILayout.Width(130), GUILayout.Height(50));
            }
            else
            {
                bool valid = true;
                if (inSKY.input == null)
                {
                    valid = false;
                }
                if (outSKY.cube == null && outDIM.cube == null && outSIM.cube == null)
                {
                    valid = false;
                }
                EditorGUI.BeginDisabledGroup(!valid);
                generate = GUILayout.Button("Compute", GUILayout.Width(130), GUILayout.Height(50));
                EditorGUI.EndDisabledGroup();

                if (!valid)
                {
                    EditorGUILayout.BeginVertical();
                    if (inSKY.input == null)
                    {
                        EditorGUILayout.HelpBox("Input Panorama is missing.", MessageType.Error);
                    }
                    if (outSKY.cube == null && outDIM.cube == null && outSIM.cube == null)
                    {
                        EditorGUILayout.HelpBox("An Output Cubemap is needed.", MessageType.Error);
                    }
                    EditorGUILayout.EndVertical();
                }
            }
        } EditorGUILayout.EndHorizontal();
        if (cancel)
        {
            ps.pause();
            Repaint();

            inSKY.locked              =
                outSKY.locked         =
                    outDIM.locked     =
                        outSIM.locked = false;
            inSKY.updateBuffers();
        }

        progressRect       = GUILayoutUtility.GetRect(sectionWidth - 4, 16);
        progressRect.width = sectionWidth;
        progressRect.x     = 4;
        progressRect.y    += 2;

        //uiShowPreview = true;
        if (uiShowPreview)
        {
            EditorGUILayout.LabelField("Convolution Preview");
            float previewWidth  = position.width - rightPad;
            float previewHeight = previewWidth * 0.5f;
            Util.GUILayout.drawTexture(4, 0, previewWidth, previewHeight, "", uiConvoPreview, false);
        }

        if (generate)
        {
            startConvo();
            ps.repaintMetric.begin();
        }

        if (ps.isPlaying())
        {
            if (ps.curr == 0)
            {
                finishSKY();
            }
            if (ps.done())
            {
                ps.repaintMetric.end();
                finishConvo();
                Repaint();
                ps.pause();
            }
            else
            {
                ps.repaintMetric.end();
                //execute a subset of convolution steps, take a break to repaint the gui, then continue convolution
                stepConvo();
                EditorGUI.ProgressBar(progressRect, ps.progress(), "Convolution Progress " + Mathf.Floor(100f * ps.progress()) + "%");
                Repaint();
                ps.pendingRepaint = false;
                ps.repaintMetric.begin();
            }
        }

        if (ps.isPlaying() && !ps.done())
        {
            EditorGUI.ProgressBar(progressRect, ps.progress(), "Convolution Progress " + Mathf.Floor(100f * ps.progress()) + "%");
        }

        //DEBUG OPTIONS

        /*
         * EditorGUILayout.BeginVertical("HelpBox", GUILayout.Width(sectionWidth), GUILayout.MinWidth(minWidth)); {
         *      uiPerfReport = EditorGUILayout.Foldout(uiPerfReport,"Debug");
         *      if( uiPerfReport ) {
         *              uiShowPreview = EditorGUILayout.Toggle("Show Preview", uiShowPreview, GUILayout.Height(16));
         *              EditorGUILayout.Space();
         *
         *              string report = "Performance Report\n";
         *              report += ps.totalMetric.getString("Total",0);
         *              report += ps.initMetric.getString("Init",1);
         *              report += ps.blockMetric.getString("Coroutine Step",1);
         *              report += ps.passWriteMetric.getString("Cube Write",2);
         *              report += ps.repaintMetric.getString("Repaint", 1);
         *              report += ps.finishMetric.getString("Finalize", 1);
         *              EditorGUILayout.SelectableLabel(report, "HelpBox", GUILayout.Height(360));
         *              EditorGUILayout.Space();
         *              selectTest();
         *      }
         * }EditorGUILayout.EndVertical();
         */

        EditorGUILayout.BeginVertical("HelpBox", GUILayout.Width(sectionWidth), GUILayout.MinWidth(minWidth));
        {
            uiGIOptions = EditorGUILayout.Foldout(uiGIOptions, "Beast Global Illum Options");
            if (uiGIOptions)
            {
                BeastConfig.DrawGUI();
                EditorGUILayout.Space();
            }
        } EditorGUILayout.EndVertical();


        EditorGUILayout.EndScrollView();
        GUILayout.EndArea();

        //GUIUtility.ExitGUI();
    }
Exemplo n.º 3
0
 private void OnProjectChange()
 {
     BeastConfig.RefreshConfig();
     this.Repaint();
 }