Beispiel #1
0
    private void ProbeFinish()
    {
        EditorApplication.isPlaying = false;
        mset.SkyManager skmgr = mset.SkyManager.Get();
        foreach (mset.Sky sky in skmgr.SkiesToProbe)
        {
            if (sky.SpecularCube as Cubemap)
            {
                mset.CubeMipProcessor.CreateSubMips(sky.SpecularCube as Cubemap);
                mset.SHUtil.projectCube(ref sky.SH, sky.SpecularCube as Cubemap, 3, true);
                mset.SHUtil.convolve(ref sky.SH);
                sky.SH.copyToBuffer();
            }
            sky.Dirty = true;
        }
        proProbe           = null;
        freeProbe          = null;
        skmgr.SkiesToProbe = null;
        AssetDatabase.Refresh();

        skmgr.ShowSkybox = skmgr.ShowSkybox;
        skmgr.EditorUpdate(true);
        skmgr.ProbeExposures = Vector4.one;

        EditorUtility.ClearProgressBar();
        mset.SkyInspector.forceRefresh();

        if (DoneCallback != null)
        {
            DoneCallback();
        }
        DoneCallback = null;

        Close();
    }
Beispiel #2
0
    private bool TestCubeRTSupport()
    {
        mset.SkyManager mgr       = mset.SkyManager.Get();
        bool            useCubeRT = false;

        if (mgr && mgr.ProbeWithCubeRT)
        {
            //test for render texture and HDR support
            RenderTexture testRT = RenderTexture.GetTemporary(256, 256, 24, RenderTextureFormat.ARGBHalf);
            testRT.isCubemap    = true;
            testRT.useMipMap    = true;
            testRT.generateMips = true;
            if (!testRT.IsCreated() && !testRT.Create())
            {
                testRT              = RenderTexture.GetTemporary(256, 256, 24, RenderTextureFormat.ARGB32);
                testRT.isCubemap    = true;
                testRT.useMipMap    = true;
                testRT.generateMips = true;
            }
            useCubeRT = testRT.IsCreated() || testRT.Create();
            if (!useCubeRT)
            {
                Debug.LogWarning("RenderTextures don't seem to be supported, using ReadPixels capture instead.");
            }
                        #if UNITY_EDITOR_WIN
            if (!UnityEditor.PlayerSettings.useDirect3D11)
            {
                Debug.LogWarning("RenderTexture cubemaps require Direct3D 11 in Windows, using ReadPixels capture instead.");
                useCubeRT = false;
            }
                        #endif
            RenderTexture.ReleaseTemporary(testRT);
        }
        return(useCubeRT);
    }
Beispiel #3
0
    // Update is called once per frame
    void Update()
    {
        mset.SkyManager manager = mset.SkyManager.Get();
        if (manager && manager.GlobalSky)
        {
            mset.Sky globalSky = manager.GlobalSky;

            if (Input.GetKeyDown(KeyCode.S))
            {
                spinning = !spinning;
            }

            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(globalSky.CamExposure - targetExposure) > 0.01f)
            {
                globalSky.CamExposure = 0.95f * globalSky.CamExposure + 0.05f * targetExposure;
            }
            else
            {
                globalSky.CamExposure = targetExposure;
            }
        }
    }
Beispiel #4
0
 public void OnEnable()
 {
     mset.SkyManager mgr = target as mset.SkyManager;
     if (mgr.GlobalSky == null)
     {
         mgr.GlobalSky = GameObject.FindObjectOfType <mset.Sky>();
     }
     mgr.EditorUpdate(true);
 }
Beispiel #5
0
 void setSky(int index)
 {
     currentSky = index;
     mset.SkyManager manager = mset.SkyManager.Get();
     if (manager)
     {
         manager.BlendToGlobalSky(skies[currentSky], 1f);
     }
 }
Beispiel #6
0
 // Use this for initialization
 void Start()
 {
     baseRot = transform.localRotation;
     scale   = littleScale;
     manager = mset.SkyManager.Get();
     if (!manager)
     {
         Debug.LogError("Failed to find SkyManager in scene. You'll probably want one of those.");
     }
 }
Beispiel #7
0
 void FixedUpdate()
 {
     if (spinning)
     {
         mset.SkyManager manager = mset.SkyManager.Get();
         if (manager && manager.GlobalSky)
         {
             manager.GlobalSky.transform.Rotate(angularVel * Time.fixedDeltaTime);
         }
     }
 }
Beispiel #8
0
 public void Apply()
 {
     if (BindType == AnchorBindType.TargetSky)
     {
         //we don't want to check for null skies every frame for every object but for
         //targeted skies, we do a global sky backup here
         if (AnchorSky)
         {
             Blender.SnapToSky(AnchorSky);
         }
         else
         {
             Blender.SnapToSky(SkyManager.Get().GlobalSky);
         }
     }
     Blender.Apply(GetComponent <Renderer>(), materials);
 }
Beispiel #9
0
 public static void ProbeSkies(GameObject[] objects, mset.Sky[] skies, bool probeAll, bool probeIBL, System.Action doneCallback)
 {
     mset.SkyManager mgr = mset.SkyManager.Get();
     if (mgr)
     {
         Probeshop window = (Probeshop)EditorWindow.GetWindow(typeof(Probeshop), true);
         window.Show(true);
         window.minSize = window.maxSize = new Vector2(400, 200);
         Rect r = window.position;
         r.center            = new Vector2(Screen.currentResolution.width / 2, Screen.currentResolution.height / 2);
         window.position     = r;
         window.DoneCallback = doneCallback;
         mgr.ProbeSkies(objects, skies, probeAll, probeIBL);
     }
     else
     {
         EditorUtility.DisplayDialog("No Sky Manager found!", "Probing skies requires a SkyManager object in the scene. Add one through the GameObject menu.", "Ok");
         Debug.LogWarning("Probing requires a SkyManager object in the scene.");
     }
 }
Beispiel #10
0
    public static mset.SkyManager addSkyMan(string name)
    {
        if (mset.SkyManager.Get())
        {
            EditorUtility.DisplayDialog("Scene already contains Sky Manager", "Only one sky manager is necessary per scene. No new object created.", "Ok");
            return(null);
        }
        if (name.Length == 0)
        {
            name = "Sky Manager";
        }
        GameObject go = new GameObject(name);

        if (Camera.current)
        {
            go.transform.position = Camera.current.transform.position + Camera.current.transform.forward * 10f;
        }
        go.AddComponent <mset.SkyManager>();
        go.name = name;
        Selection.activeGameObject = go;
        mset.SkyManager man = go.GetComponent <mset.SkyManager>();
        mset.EditorUtil.RegisterCreatedObjectUndo(go, "Add Sky");
        return(man);
    }
Beispiel #11
0
        public override void OnInspectorGUI()
        {
            GUI.changed = false;
            bool dirty    = false;              //flag for changed sky parameters
            bool dirtyRef = false;              //flag for changed sky cubemap references (causes SH recompute and preview refresh)

            mset.Sky           sky    = target as mset.Sky;
            mset.SkyApplicator app    = sky.gameObject.GetComponent <mset.SkyApplicator>();
            mset.SkyManager    skymgr = mset.SkyManager.Get();

            //sync GUI from sky
            camExposure     = sky.CamExposure;
            masterIntensity = sky.MasterIntensity;
            skyIntensity    = sky.SkyIntensity;
            diffIntensity   = sky.DiffIntensity;
            specIntensity   = sky.SpecIntensity;
            diffIntensityLM = sky.DiffIntensityLM;
            specIntensityLM = sky.SpecIntensityLM;

            //sync and sync from CubeGUIs
            refSIM.computeSH = (sky.CustomSH == null);

            dirtyRef |= skyToGUI(sky.SkyboxCube, sky.HDRSky, sky.SH, refSKY, sky.name, true);
            bool    prevHDR = sky.HDRSky;
            bool    currHDR = sky.HDRSky;
            Texture refCube = sky.SkyboxCube;

            dirtyRef |= GUIToSky(ref refCube, ref currHDR, null, refSKY);
            if (refCube != sky.SkyboxCube)
            {
                sky.SkyboxCube = refCube;
            }
            if (currHDR != prevHDR)
            {
                sky.HDRSky = currHDR;
            }

            dirtyRef |= skyToGUI(sky.SpecularCube, sky.HDRSpec, sky.SH, refSIM, sky.name, true);
            prevHDR   = sky.HDRSpec;
            currHDR   = sky.HDRSpec;
            refCube   = sky.SpecularCube;
            dirtyRef |= GUIToSky(ref refCube, ref currHDR, sky.SH, refSIM);
            if (refCube != sky.SpecularCube)
            {
                sky.SpecularCube = refCube;
            }
            if (currHDR != prevHDR)
            {
                sky.HDRSpec = currHDR;
            }

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

            string ashTip = "Accepts custom diffuse irradiance .asset files generated in other software (such as Knald Lys: www.knaldtech.com)\n\nWill override diffuse light generated from the specular cubemap.";

            EditorGUILayout.LabelField(new GUIContent("Custom Diffuse SH (Optional)", ashTip), GUILayout.Width(248));
            if (GUILayout.Button("None", GUILayout.Width(50), GUILayout.Height(14)))
            {
                sky.CustomSH     = null;
                refSIM.computeSH = true;
                refSIM.reloadReference();
            }
            EditorGUILayout.EndHorizontal();

            sky.CustomSH = EditorGUILayout.ObjectField(sky.CustomSH, typeof(mset.SHEncodingFile), false, GUILayout.Width(320)) as mset.SHEncodingFile;
            if (sky.CustomSH != null)
            {
                sky.SH.copyFrom(sky.CustomSH.SH);
                sky.SH.copyToBuffer();
            }
            refSIM.computeSH = (sky.CustomSH == null);

            GUIStyle buttonStyle = new GUIStyle("Button");

            buttonStyle.padding.top  = buttonStyle.padding.bottom = 0;
            buttonStyle.padding.left = buttonStyle.padding.right = 0;

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

            GUILayout.BeginHorizontal();
            //Global button
            if (skymgr != null)
            {
                bool alreadyGlobal = skymgr.GlobalSky == sky;
                EditorGUI.BeginDisabledGroup(alreadyGlobal);
                bool setAsGlobal = GUILayout.Button(new GUIContent("Make Global Sky", "Sets this sky as the global sky in the Sky Manager."), GUILayout.Width(120));
                if (setAsGlobal)
                {
                    skymgr.GlobalSky = sky;
                    SceneView.RepaintAll();
                }
                EditorGUI.EndDisabledGroup();
            }
            //Local Apply button
            EditorGUI.BeginDisabledGroup(app == null || !app.TriggerIsActive);
            string trigTip = "Applies this sky locally only to renderers contained within its Sky Applicator trigger volume.";

            if (app == null || !app.TriggerIsActive)
            {
                trigTip = "Requires Sky Applicator component with active trigger.";
            }

            if (GUILayout.Button(new GUIContent("Preview Apply", trigTip), GUILayout.Width(100)))
            {
                Renderer[] all = GameObject.FindObjectsOfType <Renderer>();
                foreach (Renderer r in all)
                {
                    app.ApplyInside(r);
                }
            }
            EditorGUI.EndDisabledGroup();
            GUILayout.EndHorizontal();

            //color detection is always on, but still required for LDR skies to function

            /*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 ) {
             *      mset.EditorUtil.RegisterUndo(sky, "Color-Space Detection Change");
             *      sky.AutoDetectColorSpace = detect;
             * }
             * bool prevLinear = sky.LinearSpace;
             */

            sky.AutoDetectColorSpace = true;
            if (sky.AutoDetectColorSpace)
            {
                detectColorSpace(ref sky);
            }


            /*
             * 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 ) {
             *              mset.EditorUtil.RegisterUndo(sky, "Color-Space Change");
             *              sky.LinearSpace = userLinearSpace;
             *      }
             * EditorGUI.EndDisabledGroup();
             * if( prevLinear != sky.LinearSpace ){
             * //	dirty = true;
             * }
             */

            sky.IsProbe = EditorGUILayout.Toggle(new GUIContent("Is Probe", "Enable if this sky has been rendered from within the scene. The \"Probe All Skies\" feature will only process skies marked as probes."), sky.IsProbe);

            bool prevProj = sky.HasDimensions;
            bool boxProj  = EditorGUILayout.Toggle(new GUIContent("Box Projected", "Assign box dimensions to this sky for parallaxed specular reflection."), sky.HasDimensions);

            if (boxProj != prevProj)
            {
                mset.EditorUtil.RegisterUndo(sky, "Box Projection Toggle");
                sky.HasDimensions = boxProj;
            }

            EditorGUILayout.BeginHorizontal();
            if (skymgr != null)
            {
                skymgr.ProbeOnlyStatic = EditorGUILayout.Toggle(new GUIContent("Probe Only Static Objects", ""), skymgr.ProbeOnlyStatic);
                EditorGUI.BeginDisabledGroup(true);
                EditorGUILayout.LabelField("(Global Setting)", GUILayout.Width(320));
                EditorGUI.EndDisabledGroup();
            }
            else
            {
                EditorGUI.BeginDisabledGroup(true);
                EditorGUILayout.Toggle(new GUIContent("Probe Only Static Objects", "Requires a Sky Manager object to be present in the scene."), false);
                EditorGUILayout.LabelField("(Missing Sky Manager in scene)", GUILayout.Width(320));
                EditorGUI.EndDisabledGroup();
            }
            EditorGUILayout.EndHorizontal();

            bool hasTrigger = app && app.TriggerIsActive;

            EditMode prevMode = editMode;

            EditorGUILayout.Space();
            Bounds dim = sky.Dimensions;

            dim.center     = EditorGUILayout.Vector3Field("Projector Center", dim.center);
            dim.size       = EditorGUILayout.Vector3Field("Projector Size", dim.size);
            sky.Dimensions = dim;

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

            GUIStyle style = new GUIStyle();

            style.richText = true;
            GUILayout.Label("<b>Viewport Edit Mode</b>", style);

            if (editIconListFull == null)
            {
                editIconListFull = new Texture2D[] {
                    Resources.Load <Texture2D>("editTrans"),
                    Resources.Load <Texture2D>("editProbe"),
                    Resources.Load <Texture2D>("editProjection"),
                    Resources.Load <Texture2D>("editTrigger")
                };

                editIconListAdd = new Texture2D[] {
                    editIconListFull[0],
                    editIconListFull[1],
                    Resources.Load <Texture2D>("addProjection"),
                    Resources.Load <Texture2D>("addTrigger")
                };

                editIconListProj = new Texture2D[] {
                    editIconListFull[0],
                    editIconListFull[1],
                    editIconListFull[2],
                    editIconListAdd[3]                     //no trigger
                };

                editIconListTrigger = new Texture2D[] {
                    editIconListFull[0],
                    editIconListFull[1],
                    editIconListAdd[2],                     //no projection
                    editIconListFull[3]
                };
            }

            int barWidth = 340;

            //reset edit mode if we've lost the tools we need for this sky configuration
            if (editMode == EditMode.PROJECTOR && !boxProj)
            {
                editMode = EditMode.TRANSFORM;
            }
            if (editMode == EditMode.TRIGGER && !hasTrigger)
            {
                editMode = EditMode.TRANSFORM;
            }

            if (hasTrigger && boxProj)
            {
                editMode = (EditMode)GUILayout.Toolbar((int)editMode, editIconListFull, GUILayout.Width(barWidth));
            }
            else if (boxProj)
            {
                editMode = (EditMode)GUILayout.Toolbar((int)editMode, editIconListProj, GUILayout.Width(barWidth));
            }
            else if (hasTrigger)
            {
                editMode = (EditMode)GUILayout.Toolbar((int)editMode, editIconListTrigger, GUILayout.Width(barWidth));
            }
            else
            {
                editMode = (EditMode)GUILayout.Toolbar((int)editMode, editIconListAdd, GUILayout.Width(barWidth));
            }

            if (!boxProj && editMode == EditMode.PROJECTOR)
            {
                boxProj           = true;
                sky.HasDimensions = true;
                editMode          = EditMode.PROJECTOR;
            }

            if (!hasTrigger && editMode == EditMode.TRIGGER)
            {
                hasTrigger = true;
                if (!app)
                {
                    app = sky.gameObject.AddComponent <mset.SkyApplicator>();
                }
                app.TriggerIsActive = true;
            }

            EditorGUILayout.BeginHorizontal(GUILayout.Width(barWidth));
            GUILayout.Label("Transform", GUILayout.Width(82));
            GUILayout.Label("Probe Origin", GUILayout.Width(82));
            if (boxProj)
            {
                GUILayout.Label("Projector", GUILayout.Width(86));
            }
            else
            {
                GUILayout.Label("Add Projector", GUILayout.Width(86));
            }
            if (hasTrigger)
            {
                GUILayout.Label("Trigger", GUILayout.Width(60));
            }
            else
            {
                GUILayout.Label("Add Trigger", GUILayout.Width(80));
            }
            EditorGUILayout.EndHorizontal();

            //edit mode has changed, sync or sync from stored bound centers
            if (prevMode != editMode)
            {
                projCenter = sky.transform.localToWorldMatrix.MultiplyPoint(sky.Dimensions.center);
                if (app)
                {
                    appCenter = sky.transform.localToWorldMatrix.MultiplyPoint(app.TriggerDimensions.center);
                }
                else
                {
                    appCenter = sky.transform.position;
                }
            }
            //turn on applicator resize handle drawing
            mset.SkyApplicatorInspector.triggerEdit = editMode == EditMode.TRIGGER;

            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)
            {
                mset.EditorUtil.RegisterUndo(sky, "Intensity Change");
                sky.MasterIntensity = masterIntensity;
            }

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

            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)
            {
                mset.EditorUtil.RegisterUndo(sky, "Intensity Change");
                sky.DiffIntensity = diffIntensity;
            }

            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)
            {
                mset.EditorUtil.RegisterUndo(sky, "Intensity Change");
                sky.SpecIntensity = specIntensity;
            }

            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)
            {
                mset.EditorUtil.RegisterUndo(sky, "Exposure Change");
                sky.CamExposure = camExposure;
            }

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

            EditorGUILayout.LabelField(new GUIContent("Lightmapped Diffuse Multiplier", "Multiplier on the diffuse intensity for lightmapped surfaces"));
            diffIntensityLM = EditorGUILayout.Slider(diffIntensityLM, 0f, 1f);
            if (sky.DiffIntensityLM != diffIntensityLM)
            {
                mset.EditorUtil.RegisterUndo(sky, "Multiplier Change");
                sky.DiffIntensityLM = diffIntensityLM;
            }

            EditorGUILayout.LabelField(new GUIContent("Lightmapped Specular Multiplier", "Multiplier on the specular intensity for lightmapped surfaces"));
            specIntensityLM = EditorGUILayout.Slider(specIntensityLM, 0f, 1f);
            if (sky.SpecIntensityLM != specIntensityLM)
            {
                mset.EditorUtil.RegisterUndo(sky, "Multiplier Change");
                sky.SpecIntensityLM = specIntensityLM;
            }

            dirty |= GUI.changed;

            if (forceDirty)
            {
                refSKY.reloadReference();
                refSIM.reloadReference();

                dirtyRef   = true;
                forceDirty = false;
                dirty      = true;
                Repaint();
            }

            //guess input path
            if (dirtyRef)
            {
                string inPath = refSKY.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     =
                        refSIM.inputPath = inPath;
                }
                else
                {
                    refSKY.inputPath     =
                        refSIM.inputPath = "";
                }
                dirty = true;
            }

            if (GUI.changed)
            {
                EditorUtility.SetDirty(target);
            }

            //reapply and repaint with manager
            mset.SkyManager mgr = mset.SkyManager.Get();

            if (!Application.isPlaying)
            {
                if (dirty || mgr && mgr.GlobalSky)
                {
                    sky.EditorUpdate();
                    if (mgr)
                    {
                        mgr.EditorUpdate(true);
                        SceneView.RepaintAll();
                    }
                }
            }
        }
Beispiel #12
0
        //	Vector3 dotPos;
        public void OnSceneGUI()
        {
            mset.Sky sky = target as mset.Sky;

            if (this.editMode == EditMode.TRIGGER)
            {
                return;
            }

            if (sky.HasDimensions)
            {
                Vector3 campos = Vector3.zero;
                if (Camera.current != null)
                {
                    campos = Camera.current.transform.position;
                }

                Vector3 skyScale = sky.transform.lossyScale;
                if (skyScale.x == 0)
                {
                    skyScale.x = 0.001f;
                }
                if (skyScale.y == 0)
                {
                    skyScale.y = 0.001f;
                }
                if (skyScale.z == 0)
                {
                    skyScale.z = 0.001f;
                }

                xscale = x2scale = sky.Dimensions.size.x * 0.5f * skyScale.x;
                yscale = y2scale = sky.Dimensions.size.y * 0.5f * skyScale.y;
                zscale = z2scale = sky.Dimensions.size.z * 0.5f * skyScale.z;

                if (this.editMode == EditMode.PROJECTOR)
                {
                    Handles.color = new Color(0.2f, 0.8f, 1f, 0.9f);
                    Vector3 dotpos;

                    Vector3 boxcenter = sky.transform.localToWorldMatrix.MultiplyPoint(sky.Dimensions.center);

                    dotpos = boxcenter + xscale * sky.transform.right;
                    dotpos = Handles.Slider(dotpos, sky.transform.right, (dotpos - campos).magnitude / 10.0f, Handles.ArrowHandleCap, 0.05f);
                    xscale = ((dotpos - boxcenter)).magnitude;

                    dotpos  = boxcenter + x2scale * -sky.transform.right;
                    dotpos  = Handles.Slider(dotpos, -sky.transform.right, (dotpos - campos).magnitude / 10.0f, Handles.ArrowHandleCap, 0.05f);
                    x2scale = ((dotpos - boxcenter)).magnitude;

                    dotpos = boxcenter + yscale * sky.transform.up;
                    dotpos = Handles.Slider(dotpos, sky.transform.up, (dotpos - campos).magnitude / 10.0f, Handles.ArrowHandleCap, 0.05f);
                    yscale = ((dotpos - boxcenter)).magnitude;

                    dotpos  = boxcenter + y2scale * -sky.transform.up;
                    dotpos  = Handles.Slider(dotpos, -sky.transform.up, (dotpos - campos).magnitude / 10.0f, Handles.ArrowHandleCap, 0.05f);
                    y2scale = ((dotpos - boxcenter)).magnitude;

                    dotpos = boxcenter + zscale * sky.transform.forward;
                    dotpos = Handles.Slider(dotpos, sky.transform.forward, (dotpos - campos).magnitude / 10.0f, Handles.ArrowHandleCap, 0.05f);
                    zscale = ((dotpos - boxcenter)).magnitude;

                    dotpos  = boxcenter + z2scale * -sky.transform.forward;
                    dotpos  = Handles.Slider(dotpos, -sky.transform.forward, (dotpos - campos).magnitude / 10.0f, Handles.ArrowHandleCap, 0.05f);
                    z2scale = ((dotpos - boxcenter)).magnitude;

                    float xposDiff = sky.Dimensions.size.x - (xscale / skyScale.x) * 2 - (sky.Dimensions.size.x - (x2scale / skyScale.x) * 2);
                    float yposDiff = sky.Dimensions.size.y - (yscale / skyScale.y) * 2 - (sky.Dimensions.size.y - (y2scale / skyScale.y) * 2);
                    float zposDiff = sky.Dimensions.size.z - (zscale / skyScale.z) * 2 - (sky.Dimensions.size.z - (z2scale / skyScale.z) * 2);

                    Bounds dim = sky.Dimensions;
                    dim.center += new Vector3(-xposDiff * 0.25f, -yposDiff * 0.25f, -zposDiff * 0.25f);
                    dim.size    = new Vector3((xscale + x2scale) / skyScale.x, (yscale + y2scale) / skyScale.y, (zscale + z2scale) / skyScale.z);

                    if (!dim.center.Equals(sky.Dimensions.center) || !dim.size.Equals(sky.Dimensions.size))
                    {
                        Undo.RecordObject(sky, "Sky Projection Resize");
                        sky.Dimensions = dim;
                        mset.SkyManager mgr = mset.SkyManager.Get();
                        if (mgr)
                        {
                            mgr.EditorUpdate(true);
                        }
                    }
                }
            }

            mset.SkyApplicator app = sky.gameObject.GetComponent <mset.SkyApplicator>();
            if (this.editMode == EditMode.PROBE)
            {
                //moving probe around, recompute local-space sky dimensions from world-space, cached centers
                Bounds dim = sky.Dimensions;
                dim.center = sky.transform.worldToLocalMatrix.MultiplyPoint(projCenter);

                if (dim.center != sky.Dimensions.center)
                {
                    if (app)
                    {
                        UnityEngine.Object[] undoList = { sky, app };
                        Undo.RecordObjects(undoList, "Probe Center Move");
                    }
                    else
                    {
                        Undo.RecordObject(sky, "Probe Center Move");
                    }
                }

                sky.Dimensions = dim;
                if (app)
                {
                    dim                   = app.TriggerDimensions;
                    dim.center            = sky.transform.worldToLocalMatrix.MultiplyPoint(appCenter);
                    app.TriggerDimensions = dim;
                }
            }
            else
            {
                //moving everything around, cache world-space centers of bounds
                projCenter = sky.transform.localToWorldMatrix.MultiplyPoint(sky.Dimensions.center);
                if (app)
                {
                    appCenter = sky.transform.localToWorldMatrix.MultiplyPoint(app.TriggerDimensions.center);
                }
                else
                {
                    appCenter = sky.transform.position;
                }
            }
        }
Beispiel #13
0
    public static void RefreshSkies()
    {
        mset.Sky[] skies = UnityEngine.Object.FindObjectsOfType(typeof(mset.Sky)) as mset.Sky[];

        mset.SkyManager mgr = mset.SkyManager.Get();
        mset.Sky        currSky;
        if (mgr)
        {
            currSky = mgr.GlobalSky;
        }
        else
        {
            currSky = null;
        }

        if (skies.Length > 0)
        {
            Debug.Log("Refreshing " + skies.Length + " skies");
            mset.EditorUtil.RegisterUndo(skies as UnityEngine.Object[], "Refresh Skies");
            for (int i = 0; i < skies.Length; ++i)
            {
                mset.Sky sky = skies[i];
                if (sky != null)
                {
                    //If this sky is an instance of a prefab, edit the prefab itself.
                    UnityEngine.Object po   = PrefabUtility.GetPrefabParent(sky);
                    mset.Sky           psky = null;
                    if (po && PrefabUtility.GetPrefabType(po) != PrefabType.None)
                    {
                        GameObject pgo = po as GameObject;
                        psky = po as mset.Sky;
                        if (pgo)
                        {
                            Debug.Log("Updating prefab GameObject: " + pgo.name);
                            psky = pgo.GetComponent <mset.Sky>();
                        }
                        else if (psky)
                        {
                            Debug.Log("Updating prefab Sky " + psky.name);
                        }
                        else
                        {
                            Debug.Log("No Sky found in prefab instance " + sky.name);
                        }
                    }

                    if (psky)
                    {
                        if (psky.SpecularCube)
                        {
                            psky.SpecularCube.filterMode = FilterMode.Trilinear;
                        }
                        mset.SkyInspector.detectColorSpace(ref psky);
                        mset.SkyInspector.generateSH(ref psky);
                        PrefabUtility.ResetToPrefabState(sky);
                    }
                    else
                    {
                        mset.SkyInspector.detectColorSpace(ref sky);
                        mset.SkyInspector.generateSH(ref sky);
                    }
                    sky.Apply();
                }
            }
            if (currSky)
            {
                currSky.Apply();
            }
        }
    }
Beispiel #14
0
        public override void OnInspectorGUI()
        {
            GUI.changed = false;

            mset.SkyManager skmgr = target as mset.SkyManager;
            mset.Sky        nusky = EditorGUILayout.ObjectField("Global Sky", skmgr.GlobalSky, typeof(mset.Sky), true) as mset.Sky;
            if (skmgr.GlobalSky != nusky)
            {
                //TODO: is this necessary?
                if (!Application.isPlaying && nusky != null)
                {
                    nusky.Apply();
                }
                if (nusky == null)
                {
                    RenderSettings.skybox = null;
                }
                skmgr.GlobalSky = nusky;
            }

            skmgr.ShowSkybox = GUILayout.Toggle(skmgr.ShowSkybox, new GUIContent("Show Skybox", "Toggles rendering the global sky's background image in both play and edit modes"));

            EditorGUILayout.Space();
            skmgr.ProjectionSupport = GUILayout.Toggle(skmgr.ProjectionSupport, new GUIContent("Box Projection Support", "Optimization for disabling all box projected cubemap distortion at the shader level"));
            skmgr.BlendingSupport   = GUILayout.Toggle(skmgr.BlendingSupport, new GUIContent("Blending Support", "Optimization for disabling blending transitions between skies at the shader level"));
            skmgr.LocalBlendTime    = EditorGUILayout.FloatField("Local Sky Blend Time", skmgr.LocalBlendTime);
            skmgr.GlobalBlendTime   = EditorGUILayout.FloatField("Global Sky Blend Time", skmgr.GlobalBlendTime);
            EditorGUILayout.Space();


            GUILayout.BeginHorizontal();
            skmgr.GameAutoApply = GUILayout.Toggle(skmgr.GameAutoApply, new GUIContent("Auto-Apply in Game", "If enabled for game mode, Sky Manager will keep and constantly update a list of dynamic renderers in the scene, applying local skies to them as they move around.\n\nRequired for dynamic sky binding and Sky Applicator triggers.\n\nNOTE: This feature causes material instances to be spawned at runtime and may hurt render batching."), GUILayout.Width(128));
            EditorGUI.BeginDisabledGroup(true);
            GUILayout.Label("(Creates material instances)");
            EditorGUI.EndDisabledGroup();
            GUILayout.EndHorizontal();

            skmgr.EditorAutoApply = GUILayout.Toggle(skmgr.EditorAutoApply, new GUIContent("Auto-Apply in Editor", "If enabled for edit mode, Sky Manager will apply local skies to renderers contained in their Sky Applicator trigger volumes.\n\nAffects editor viewport only."));
            skmgr.AutoMaterial    = GUILayout.Toggle(skmgr.AutoMaterial, new GUIContent("Dynamic Materials", "Periodically update the material caches in Sky Anchors. Enable if material lists of renderers are going to change at runtime (e.g. adding, removing, or replacing material references of renderers, property changes won't matter)."));

            //NOTE: The _ vars are stored in sky manager because they're part of the saved state. Pulling the list of layers from the bit mask instead of a full int array would sort the layer list every frame.
            skmgr._IgnoredLayerCount = EditorGUILayout.IntField("Ignored Layer Count", skmgr._IgnoredLayerCount);

            //if never allocated before, allocate ignoredLayers list here, it's only ever used here to display and configure the true hero: IgnoredLayerMask
            if (skmgr._IgnoredLayers == null)
            {
                skmgr._IgnoredLayers = new int[32];
            }

            skmgr.IgnoredLayerMask = 0;
            for (int i = 0; i < skmgr._IgnoredLayerCount; ++i)
            {
                skmgr._IgnoredLayers[i] = EditorGUILayout.LayerField(" ", skmgr._IgnoredLayers[i]);
                skmgr.IgnoredLayerMask |= 1 << skmgr._IgnoredLayers[i];
            }

            GUILayout.BeginHorizontal();
            if (GUILayout.Button(new GUIContent("Preview Auto-Apply", "Updates editor viewport to show an accurate representation of which renderers will be bound to which skies in the game.\n\nEditor Auto-Apply performs this every frame."), GUILayout.Width(140)))
            {
                skmgr.EditorUpdate(true);
                SceneView.RepaintAll();
            }
            GUILayout.EndHorizontal();


            EditorGUILayout.Space();

            string tipExponent = "Highest gloss exponent use in the specular mip chain when capturing probes. Other exponents in the chain are generated from this value.";

            skmgr.ProbeExponent = EditorGUILayout.IntField(new GUIContent("Probe Specular Exponent", tipExponent), skmgr.ProbeExponent);
            skmgr.ProbeExponent = Mathf.Max(1, skmgr.ProbeExponent);

            string staticTip = "If enabled, only GameObjects marked as \"Static\" will be rendered when capturing cubemaps.";

            skmgr.ProbeOnlyStatic = GUILayout.Toggle(skmgr.ProbeOnlyStatic, new GUIContent("Probe Only Static Objects", staticTip));

            string dx11Tip = "Uses HDR render-textures to capture sky probes faster and with better quality.\n\nRequires project to be in Direct3D 11 mode while capturing.";

            if (PlayerSettings.useDirect3D11)
            {
                skmgr.ProbeWithCubeRT = GUILayout.Toggle(skmgr.ProbeWithCubeRT, new GUIContent("Probe Using Render-to-Cubemap", dx11Tip));
            }
            else
            {
                EditorGUI.BeginDisabledGroup(true);
                GUILayout.Toggle(false, new GUIContent("Probe Using Render-to-Cubemap (Requires Direct3D11)", dx11Tip));
                EditorGUI.EndDisabledGroup();
            }

            string camTip = "Sky probing is performed using the settings and clipping planes of this camera. If field is empty, Main Camera is used.";

            skmgr.ProbeCamera = EditorGUILayout.ObjectField(new GUIContent("Probe with Camera", camTip), skmgr.ProbeCamera, typeof(Camera), true) as Camera;


            GUILayout.BeginHorizontal();
            if (GUILayout.Button(new GUIContent("Probe Skies (Direct)"), GUILayout.Width(140)))
            {
                bool probeNonProbes = false;
                bool probeIBL       = false;
                Probeshop.ProbeSkies(null, GameObject.FindObjectsOfType <mset.Sky>(), probeNonProbes, probeIBL, null);
            }
            if (GUILayout.Button("Probe Skies (Direct+IBL)", GUILayout.Width(170)))
            {
                bool probeNonProbes = false;
                bool probeIBL       = true;
                Probeshop.ProbeSkies(null, GameObject.FindObjectsOfType <mset.Sky>(), probeNonProbes, probeIBL, null);
            }
            GUILayout.EndHorizontal();

            if (GUI.changed)
            {
                skmgr.EditorUpdate(true);
                EditorUtility.SetDirty(target);
                SceneView.RepaintAll();
            }
        }
Beispiel #15
0
 // Use this for initialization
 void Start()
 {
     manager = mset.SkyManager.Get();
     manager.BlendToGlobalSky(skyList[currSky], blendTime);
     blendStamp = Time.time;
 }
Beispiel #16
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();
                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();
                    outSIM.drawGUI(); EditorGUILayout.Space();

                    EditorGUILayout.BeginHorizontal(); {
                        string newTip = "Create a new cubemap assets for each output slot and adds them to the project.";
                        if (GUILayout.Button(new GUIContent("New All ", newTip), GUILayout.Width(70), GUILayout.Height(18)))
                        {
                            outSKY.newCube();
                            outSIM.newCube();
                        }
                        string findTip = "Search project for all existing output cubemaps by input panorama name.";
                        if (GUILayout.Button(new GUIContent("Find All", findTip), GUILayout.Width(70), GUILayout.Height(18)))
                        {
                            outSKY.find();
                            outSIM.find();
                        }
                        string clearTip = "Deselect all target cubemaps from output slots.";
                        if (GUILayout.Button(new GUIContent("Clear All", clearTip), GUILayout.Width(80), GUILayout.Height(18)))
                        {
                            outSKY.clear();
                            outSIM.clear();
                        }
                        string reloadTip = "Reload all input and output slot textures and generate preview images for them.";
                        EditorGUI.BeginDisabledGroup(outSKY.fullPath.Length == 0 && outSIM.fullPath.Length == 0 && inSKY.fullPath.Length == 0);
                        {
                            if (GUILayout.Button(new GUIContent("Reload All", reloadTip), GUILayout.Width(85), GUILayout.Height(18)))
                            {
                                outSKY.reloadReference();
                                outSIM.reloadReference();
                                inSKY.reloadReference();
                            }
                        }
                        EditorGUI.EndDisabledGroup();
                    } EditorGUILayout.EndHorizontal();

                    EditorGUILayout.BeginHorizontal(); {
                        string   editLabel = "";
                        string   editTip   = "";
                        mset.Sky editSky   = null;

                        if (uiSelectedSky)
                        {
                            editSky   = uiSelectedSky;
                            editLabel = "Edit Selected";
                            editTip   = "Select cubemaps from the selected Sky as output targets.";
                        }
                        else
                        {
                            mset.SkyManager mgr = mset.SkyManager.Get();
                            if (mgr)
                            {
                                editSky = mgr.GlobalSky;
                            }
                            else
                            {
                                editSky = null;
                            }
                            editLabel = "Edit Global";
                            editTip   = "Select cubemaps from the current viewport Sky as output targets.";
                        }
                        EditorGUI.BeginDisabledGroup(editSky == null);
                        if (GUILayout.Button(new GUIContent(editLabel, editTip), GUILayout.Width(95), GUILayout.Height(32)))
                        {
                            if (editSky)
                            {
                                outSKY.HDR = editSky.HDRSky;
                                outSIM.HDR = editSky.HDRSpec;

                                if (editSky.SkyboxCube)
                                {
                                    outSKY.setReference(AssetDatabase.GetAssetPath(editSky.SkyboxCube), false, true);
                                }
                                else
                                {
                                    outSKY.clear();
                                }

                                if (editSky.SpecularCube)
                                {
                                    outSIM.setReference(AssetDatabase.GetAssetPath(editSky.SpecularCube), true, true);
                                }
                                else
                                {
                                    outSIM.clear();
                                }
                            }
                        }
                        EditorGUI.EndDisabledGroup();

                        string applyTip = "Change the selected Sky object to use Skyshop's current output cubemaps.";
                        EditorGUI.BeginDisabledGroup(uiSelectedSky == null);
                        if (GUILayout.Button(new GUIContent("Apply to Selected", applyTip), GUILayout.Width(120), GUILayout.Height(32)))
                        {
                            if (uiSelectedSky)
                            {
                                mset.EditorUtil.RegisterUndo(uiSelectedSky, "Apply to Selected Sky");
                                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;

                                SceneView.RepaintAll();
                            }
                        }
                        EditorGUI.EndDisabledGroup();

                        string addTip = "Create a new Sky object in the scene and assigns Skyshop's current output cubemaps to it.";
                        if (GUILayout.Button(new GUIContent("Add to Scene", addTip), GUILayout.Width(95), GUILayout.Height(32)))
                        {
                            mset.Sky skyScript = addSky(this.inSKY.skyName);
                            if (skyScript)
                            {
                                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.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)
                    {
                        mset.EditorUtil.RegisterUndo(this, "Change Exposure");
                        uiExposure = newExposure;
                    }

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

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

                        case mset.Quality.high:         uiConvoSize = 32; break;

                        case mset.Quality.medium:       uiConvoSize = 16; break;

                        case mset.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 tipMaxExponent  = "Highest gloss exponent use in the specular mip chain. Other exponents in the chain are generated from this value.";
            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)
                    {
                        mset.EditorUtil.RegisterUndo(this, "Change Convolution Size");
                        uiConvoSize    = newConvoSize;
                        uiConvoQuality = mset.Quality.custom;
                        switch (uiConvoSize)
                        {
                        case 8:  uiConvoQuality = mset.Quality.low; break;

                        case 16: uiConvoQuality = mset.Quality.medium; break;

                        case 32: uiConvoQuality = mset.Quality.high; break;

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

                    bool newMipChain = EditorGUILayout.Toggle(new GUIContent("Build Specular Mip Chain", "Specular Mip Chains -\n" + tipMipChain), uiMipChain);
                    if (newMipChain != uiMipChain)
                    {
                        mset.EditorUtil.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)
                        {
                            mset.EditorUtil.RegisterUndo(this, "Toggle Mip Chain Reflection");
                            uiReflectionInSIM = newRefInSIM;
                        }
                        int newExponent = EditorGUILayout.IntField(
                            new GUIContent("Max Specular Exponent", "Specular Exponent -\n" + tipMaxExponent),
                            uiExponent,
                            GUILayout.Width(300)
                            );
                        newExponent = Mathf.Max(1, newExponent);
                        if (newExponent != uiExponent)
                        {
                            mset.EditorUtil.RegisterUndo(this, "Change Specular Exponent");
                            uiExponent = newExponent;
                        }

                        EditorGUI.BeginDisabledGroup(true);
                        string mipString;
                        if (uiReflectionInSIM)
                        {
                            mipString = "mirror";
                        }
                        else
                        {
                            mipString = uiExponent.ToString();
                        }
                        for (int i = 1; i < 4; ++i)
                        {
                            if ((1 << i) < uiExponent)
                            {
                                mipString += ", ";
                                mipString += (uiExponent >> i);
                                if (i == 3)
                                {
                                    mipString += "...";
                                }
                            }
                        }
                        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)
                        {
                            mset.EditorUtil.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)
                    {
                        mset.EditorUtil.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;
                        uiExponent        = 512;
                    }
                    EditorGUILayout.Space();
                }
            } EditorGUILayout.EndVertical();

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

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

        EditorGUILayout.BeginHorizontal(); {
            bool   hasPro        = UnityEditorInternal.InternalEditorUtility.HasPro();
            string tipGPUCompute = "Generates skybox and specular cubemaps. Specular convolution is performed on the GPU for greater speed and quality.\n\nNote: a different convolution equation is used, results may vary from CPU compute.";
            if (hasPro == false)
            {
                tipGPUCompute = "Requires Unity Pro :-(\n\n" + tipGPUCompute;
            }

            bool playing = ps.isPlaying();
            //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 && outSIM.cube == null)
                {
                    valid = false;
                }
                EditorGUILayout.BeginVertical();
                EditorGUI.BeginDisabledGroup(!valid);
                generate = GUILayout.Button(playing ? "Cancel" : "Compute", GUILayout.Width(130), GUILayout.Height(50));
                if (playing)
                {
                    cancel = generate; generate = false;
                }
                EditorGUI.EndDisabledGroup();

                EditorGUI.BeginDisabledGroup(!valid || !hasPro || playing);
                generateGPU = GUILayout.Button(new GUIContent("GPU Compute", "GPU Compute -\n" + tipGPUCompute), GUILayout.Width(130), GUILayout.Height(50));
                EditorGUI.EndDisabledGroup();
                EditorGUILayout.EndVertical();

                if (!valid)
                {
                    EditorGUILayout.BeginVertical();
                    if (inSKY.input == null)
                    {
                        EditorGUILayout.HelpBox("Input Panorama is missing.", MessageType.Error);
                    }
                    if (outSKY.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     =
                    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;
            mset.EditorUtil.GUILayout.drawTexture(4, 0, previewWidth, previewHeight, "", uiConvoPreview, false);
        }

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

        if (generateGPU)
        {
            this.startConvoGPU();
            this.finishSKY();

            if (outSIM.cube)
            {
                Cubemap tempCube = this.outSKY.cube;
                if (tempCube == null)
                {
                    tempCube = new Cubemap(outSIM.cube.width, TextureFormat.ARGB32, false);
                    ps.IN.resampleToCube(ref tempCube, 0, outSIM.colorMode, true, uiExposure);
                    tempCube.Apply(false);
                    mset.AssetUtil.setLinear(new SerializedObject(tempCube), false);
                }

                mset.SkyProbe p = new mset.SkyProbe();
                p.maxExponent        = this.uiExponent;
                p.highestMipIsMirror = this.uiReflectionInSIM;
                p.generateMipChain   = this.uiMipChain;
                bool linear = UnityEditor.PlayerSettings.colorSpace == ColorSpace.Linear;
                p.convolve(this.outSIM.cube, tempCube, this.outSIM.HDR, this.outSKY.HDR, linear);
                outSIM.reloadReference();

                if (ps.buildMipChain)
                {
                    finishSIM();
                }
            }
            this.finishConvoGPU();
        }

        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)
            {
                mset.BeastConfig.DrawGUI();
                EditorGUILayout.Space();
            }
        } EditorGUILayout.EndVertical();


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

        //GUIUtility.ExitGUI();
    }
Beispiel #17
0
    public void Update()
    {
        //NOTE: mouse coordinates have a bottom-left origin, camera top-left
        inputBounds.x      = GetComponent <Camera>().pixelWidth *paramInputBounds.x;
        inputBounds.y      = GetComponent <Camera>().pixelHeight *paramInputBounds.y;
        inputBounds.width  = GetComponent <Camera>().pixelWidth *paramInputBounds.width;
        inputBounds.height = GetComponent <Camera>().pixelHeight *paramInputBounds.height;

        if (target && inputBounds.Contains(Input.mousePosition))
        {
            float dx = Input.GetAxis("Mouse X");
            float dy = Input.GetAxis("Mouse Y");
                        #if UNITY_IPHONE || UNITY_ANDROID
            if (Input.multiTouchEnabled)
            {
                if (Input.touchCount > 0)
                {
                    //touch-down detection. kekeke.
                    if (!firstTouch)
                    {
                        dx += Input.GetTouch(0).deltaPosition.x * 0.01f;
                        dy += Input.GetTouch(0).deltaPosition.y * 0.01f;
                    }
                    firstTouch = false;
                }
                else
                {
                    firstTouch = true;
                }
            }
                        #endif
            bool click1    = Input.GetMouseButton(0) || Input.touchCount == 1;
            bool click2    = Input.GetMouseButton(1) || Input.touchCount == 2;
            bool click3    = Input.GetMouseButton(2) || Input.touchCount == 3;
            bool click4    = Input.touchCount >= 4;
            bool rotInput  = click1;
            bool skyInput  = click4 || click1 && (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift));
            bool panInput  = click3 || click1 && (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl));
            bool zoomInput = click2;

            if (skyInput)
            {
                dx = dx * thetaSpeed * 0.02f;
                mset.SkyManager manager = mset.SkyManager.Get();
                if (manager && manager.GlobalSky)
                {
                    manager.GlobalSky.transform.Rotate(new Vector3(0, dx, 0));
                }
            }
            else if (panInput)
            {
                dx            = dx * moveSpeed * 0.005f * targetDist;
                dy            = dy * moveSpeed * 0.005f * targetDist;
                targetLookAt -= transform.up * dy + transform.right * dx;
                if (useMoveBounds)
                {
                    targetLookAt.x = Mathf.Clamp(targetLookAt.x, -moveBounds, moveBounds);
                    targetLookAt.y = Mathf.Clamp(targetLookAt.y, -moveBounds, moveBounds);
                    targetLookAt.z = Mathf.Clamp(targetLookAt.z, -moveBounds, moveBounds);
                }
            }
            else if (zoomInput)
            {
                dy          = dy * zoomSpeed * 0.005f * targetDist;
                targetDist += dy;
                targetDist  = Mathf.Max(0.1f, targetDist);
            }
            else if (rotInput)
            {
                dx        = dx * thetaSpeed * 0.02f;
                dy        = dy * phiSpeed * 0.02f;
                euler.x  += dx;
                euler.y  -= dy;
                euler.y   = ClampAngle(euler.y, phiBoundMin, phiBoundMax);
                targetRot = Quaternion.Euler(euler.y, euler.x, 0);
            }

            targetDist -= Input.GetAxis("Mouse ScrollWheel") * zoomSpeed * 0.5f;
            targetDist  = Mathf.Max(0.1f, targetDist);
        }
    }
Beispiel #18
0
    private void ProbeUpdate()
    {
        mset.SkyManager skmgr = mset.SkyManager.Get();
        if (UnityEditor.EditorApplication.isPlaying && skmgr.SkiesToProbe != null)
        {
            if (firstFrame)
            {
                if (skmgr.ProbeOnlyStatic)
                {
                    //hide dynamics
                    Renderer[] rends = GameObject.FindObjectsOfType <Renderer>();
                    foreach (Renderer rend in rends)
                    {
                        if (!rend.gameObject.isStatic)
                        {
                            rend.gameObject.SetActive(false);
                        }
                    }
                }
                firstFrame = false;
            }

            if (useCubeRT)
            {
                if (proProbe == null)
                {
                    proProbe = new mset.SkyProbe();
                }

                //Run the whole loop in place and finish
                bool success = true;
                int  i       = 0;
                foreach (mset.Sky targetSky in skmgr.SkiesToProbe)
                {
                    i++;
                    SetProgress((float)i / (float)skmgr.SkiesToProbe.Length);

                    //NOTE: we don't allocate new cubemaps at this stage. That's on you, buddy.
                    Cubemap targetCube = targetSky.SpecularCube as Cubemap;
                    if (targetCube == null)
                    {
                        continue;
                    }

                    Transform at = targetSky.transform;
                    proProbe.maxExponent = skmgr.ProbeExponent;
                    proProbe.exposures   = skmgr.ProbeExposures;
                    bool linear = UnityEditor.PlayerSettings.colorSpace == ColorSpace.Linear;

                    bool k = proProbe.capture(targetCube, at.position, at.rotation, targetSky.HDRSpec, linear, true);
                    if (!k)
                    {
                        Debug.LogWarning("Failed to capture with RenderTextures, falling back to ReadPixels.");
                        useCubeRT = false;
                        success   = false;
                        break;
                    }
                }
                if (success)
                {
                    CueProbeFinish();
                }
            }

            if (!useCubeRT)
            {
                //Create a game object and let the update loop run until DoneCallback gets called
                if (freeProbe == null)
                {
                    GameObject go = new GameObject();
                    go.name = "FreeProbe Object";
                    go.AddComponent <Camera>();
                    freeProbe = go.AddComponent <mset.FreeProbe>();
                    skmgr.GameApplySkies(true);
                    Shader.SetGlobalVector("_UniformOcclusion", skmgr.ProbeExposures);
                    freeProbe.linear      = UnityEditor.PlayerSettings.colorSpace == ColorSpace.Linear;
                    freeProbe.maxExponent = skmgr.ProbeExponent;
                    freeProbe.exposures   = skmgr.ProbeExposures;
                    freeProbe.QueueSkies(skmgr.SkiesToProbe);
                    freeProbe.ProgressCallback = this.SetProgress;
                    freeProbe.DoneCallback     = this.CueProbeFinish;
                    freeProbe.RunQueue();
                }
            }
        }
    }