コード例 #1
0
 void OnMouseDown()
 {
     if (targetSky)
     {
         targetSky.Apply();
     }
 }
コード例 #2
0
    // Update is called once per frame
    void Update()
    {
        if (firstFrame)
        {
            firstFrame = false;
            if (Sky.activeSky)
            {
                targetExposure            = Sky.activeSky.camExposure;
                Sky.activeSky.camExposure = -1f;
            }
        }
        if (Input.GetKeyDown(KeyCode.S))
        {
            spinning = !spinning;
        }
        if (Input.GetKeyDown(KeyCode.B))
        {
            if (sky)
            {
                sky.showSkybox = !sky.showSkybox;
                sky.Apply();
            }
        }

        if (Input.GetKeyDown(KeyCode.Equals) || Input.GetKeyDown(KeyCode.KeypadEquals))
        {
            targetExposure = Mathf.Min(targetExposure + 0.2f, 2f);
        }
        if (Input.GetKeyDown(KeyCode.Minus) || Input.GetKeyDown(KeyCode.KeypadMinus))
        {
            targetExposure = Mathf.Max(0.05f, targetExposure - 0.2f);
        }
        if (Mathf.Abs(Sky.activeSky.camExposure - targetExposure) > 0.01f)
        {
            Sky.activeSky.camExposure = 0.85f * Sky.activeSky.camExposure + 0.15f * targetExposure;
            Sky.activeSky.Apply();
        }
        else
        {
            Sky.activeSky.camExposure = targetExposure;
        }
    }
コード例 #3
0
    public override void OnInspectorGUI()
    {
        bool dirty = false;
        Sky  sky   = target as Sky;

        //sync GUI from sky
        camExposure     = sky.camExposure;
        masterIntensity = sky.masterIntensity;
        skyIntensity    = sky.skyIntensity;
        diffIntensity   = sky.diffIntensity;
        specIntensity   = sky.specIntensity;

        //sync and sync from CubeGUIs
        dirty |= updateCube(ref sky.skyboxCube, ref sky.hdrSky, refSKY);
        dirty |= updateCube(ref sky.diffuseCube, ref sky.hdrDiff, refDIM);
        dirty |= updateCube(ref sky.specularCube, ref sky.hdrSpec, refSIM);

        bool showSkybox = EditorGUILayout.Toggle(new GUIContent("Show Skybox", "Toggles rendering the background image"), sky.showSkybox);

        if (showSkybox != sky.showSkybox)
        {
            Undo.RegisterUndo(sky, "Skybox Toggle");
            sky.showSkybox = showSkybox;
            // if we're toggling skyboxes off, clear the render settings material
            if (!sky.showSkybox)
            {
                RenderSettings.skybox = null;
            }
            dirty = true;
        }

        bool detect = EditorGUILayout.Toggle(new GUIContent("Auto-Detect Color Space", "If enabled, attempts to detect the project's gamma correction setting and enables/disables the Linear Space option accordingly"), sky.autoDetectColorSpace);

        if (detect != sky.autoDetectColorSpace)
        {
            Undo.RegisterUndo(sky, "Color-Space Detection Change");
            sky.autoDetectColorSpace = detect;
        }

        bool prevLinear = sky.linearSpace;

        if (sky.autoDetectColorSpace)
        {
            sky.linearSpace = PlayerSettings.colorSpace == ColorSpace.Linear;
        }
        EditorGUI.BeginDisabledGroup(sky.autoDetectColorSpace);
        bool userLinearSpace = EditorGUILayout.Toggle(new GUIContent("Linear Space", "Enable if gamma correction is enabled for this project (Edit -> Project Settings -> Player -> Color Space: Linear)"), sky.linearSpace);

        if (userLinearSpace != sky.linearSpace)
        {
            Undo.RegisterUndo(sky, "Color-Space Change");
            sky.linearSpace = userLinearSpace;
        }
        EditorGUI.EndDisabledGroup();
        if (prevLinear != sky.linearSpace)
        {
            dirty = true;
        }

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

        //sync sky from GUI
        EditorGUILayout.LabelField(new GUIContent("Master Intensity", "Multiplier on the Sky, Diffuse, and Specular cube intensities"));
        masterIntensity = EditorGUILayout.Slider(masterIntensity, 0f, 10f);
        if (sky.masterIntensity != masterIntensity)
        {
            Undo.RegisterUndo(sky, "Intensity Change");
            sky.masterIntensity = masterIntensity;
            dirty = true;
        }

        EditorGUILayout.LabelField(new GUIContent("Skybox Intensity", "Brightness of the skybox"));
        skyIntensity = EditorGUILayout.Slider(skyIntensity, 0f, 10f);
        if (sky.skyIntensity != skyIntensity)
        {
            Undo.RegisterUndo(sky, "Intensity Change");
            sky.skyIntensity = skyIntensity;
            dirty            = true;
        }

        EditorGUILayout.LabelField(new GUIContent("Diffuse Intensity", "Multiplier on the diffuse light put out by this sky"));
        diffIntensity = EditorGUILayout.Slider(diffIntensity, 0f, 10f);
        if (sky.diffIntensity != diffIntensity)
        {
            Undo.RegisterUndo(sky, "Intensity Change");
            sky.diffIntensity = diffIntensity;
            dirty             = true;
        }

        EditorGUILayout.LabelField(new GUIContent("Specular Intensity", "Multiplier on the specular light put out by this sky"));
        specIntensity = EditorGUILayout.Slider(specIntensity, 0f, 10f);
        if (sky.specIntensity != specIntensity)
        {
            Undo.RegisterUndo(sky, "Intensity Change");
            sky.specIntensity = specIntensity;
            dirty             = true;
        }

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

        EditorGUILayout.LabelField(new GUIContent("Camera Exposure", "Multiplier on all light coming into the camera, including IBL, direct light, and glow maps"));
        camExposure = EditorGUILayout.Slider(camExposure, 0f, 10f);
        if (sky.camExposure != camExposure)
        {
            Undo.RegisterUndo(sky, "Exposure Change");
            sky.camExposure = camExposure;
            dirty           = true;
        }

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

        dirty |= GUI.changed;

        if (forceDirty)
        {
            forceDirty = false;
            dirty      = true;
        }

        //guess input path
        if (dirty)
        {
            string inPath = refSKY.fullPath;
            if (inPath.Length == 0)
            {
                inPath = refDIM.fullPath;
            }
            if (inPath.Length == 0)
            {
                inPath = refSIM.fullPath;
            }
            if (inPath.Length > 0)
            {
                int uscore = inPath.LastIndexOf("_");
                if (uscore > -1)
                {
                    inPath = inPath.Substring(0, uscore);
                }
                else
                {
                    inPath = Path.GetDirectoryName(inPath) + "/" + Path.GetFileNameWithoutExtension(inPath);
                }
                refSKY.inputPath         =
                    refDIM.inputPath     =
                        refSIM.inputPath = inPath;
            }
            else
            {
                refSKY.inputPath         =
                    refDIM.inputPath     =
                        refSIM.inputPath = "";
            }
        }

        //if the active sky is not whats selected, see whats up with that and try rebinding (catches re-activating disabled skies)
        if (Sky.activeSky != sky)
        {
            dirty = true;
        }

        if (!Application.isPlaying)
        {
            //if any of the cubemaps have changed, refresh the viewport
            if (dirty)
            {
                sky.Apply();                 //SkyInspector dirty
                SceneView.RepaintAll();
            }
            else
            {
                sky.ApplySkyTransform();
            }
        }
    }
コード例 #4
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();
    }