Пример #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();
    }
Пример #2
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();
                }
            }
        }
    }
Пример #3
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();
    }
Пример #4
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();
                }
            }
        }
    }