Exemple #1
0
        public void ScriptingAPI_AddMemoryCubemap()
        {
            var path = BeginAssetTest();

            try
            {
                System.Exception exception = null;
                var importer = (CubemapArrayImporter)AssetImporter.GetAtPath(path);
                var texture  = new Cubemap(64, TextureFormat.RGB24, true);

                try
                {
                    importer.cubemaps = new Cubemap[] { texture };
                }
                catch (System.Exception e)
                {
                    exception = e;
                }
                finally
                {
                    Cubemap.DestroyImmediate(texture);
                }

                Assert.IsTrue(exception is System.NotSupportedException);
            }
            finally
            {
                EndAssetTest(path);
            }
        }
Exemple #2
0
        private void convolve_internal(Texture dstTex, Texture srcCube, bool dstRGBM, bool srcRGBM, bool linear, Camera cam, Material skyMat, Matrix4x4 matrix)
        {
            bool             prevHDR   = cam.hdr;
            CameraClearFlags prevFlags = cam.clearFlags;
            int prevMask = cam.cullingMask;

            cam.clearFlags  = CameraClearFlags.Skybox;
            cam.cullingMask = 0;
            cam.hdr         = !dstRGBM;     // might need HDR camera buffer when we're not rendering to RGBM encoded pixels

            skyMat.name   = "Internal Convolve Skybox";
            skyMat.shader = Shader.Find("Hidden/Marmoset/RGBM Convolve");

            //toggleKeywordPair("MARMO_LINEAR", "MARMO_GAMMA", linear);
            toggleKeywordPair("MARMO_RGBM_INPUT_ON", "MARMO_RGBM_INPUT_OFF", srcRGBM);
            toggleKeywordPair("MARMO_RGBM_OUTPUT_ON", "MARMO_RGBM_OUTPUT_OFF", dstRGBM);

            skyMat.SetMatrix("_SkyMatrix", matrix);
            skyMat.SetTexture("_CubeHDR", srcCube);
            bindRandomValueTable(skyMat, "_PhongRands", srcCube.width);

            Material prevSkyMat = UnityEngine.RenderSettings.skybox;

            UnityEngine.RenderSettings.skybox = skyMat;

            Cubemap       dstCube = dstTex as Cubemap;
            RenderTexture dstRT   = dstTex as RenderTexture;

            if (dstCube)
            {
                if (generateMipChain)
                {
                    int mipCount = mset.QPow.Log2i(dstCube.width) - 1;
                    int mip      = highestMipIsMirror ? 1 : 0;
                    for ( ; mip < mipCount; ++mip)
                    {
                        int   mipSize = 1 << (mipCount - mip);
                        float mipExp  = mset.QPow.clampedDownShift(this.maxExponent, highestMipIsMirror ? (mip - 1) : mip, 1);
                        skyMat.SetFloat("_SpecularExp", mipExp);
                        skyMat.SetFloat("_SpecularScale", this.convolutionScale);
                        Cubemap mipCube = new Cubemap(mipSize, dstCube.format, false);
                        cam.RenderToCubemap(mipCube);

                        for (int f = 0; f < 6; ++f)
                        {
                            CubemapFace face = (CubemapFace)f;
                            dstCube.SetPixels(mipCube.GetPixels(face), face, mip);
                        }
                        Cubemap.DestroyImmediate(mipCube);
                    }
                    dstCube.Apply(false);
                }
                else
                {
                    skyMat.SetFloat("_SpecularExp", this.maxExponent);
                    skyMat.SetFloat("_SpecularScale", this.convolutionScale);
                    cam.RenderToCubemap(dstCube);
                }
            }
            else if (dstRT)
            {
                skyMat.SetFloat("_SpecularExp", this.maxExponent);
                skyMat.SetFloat("_SpecularScale", this.convolutionScale);
                cam.RenderToCubemap(dstRT);
            }

            cam.clearFlags  = prevFlags;
            cam.cullingMask = prevMask;
            cam.hdr         = prevHDR;
            UnityEngine.RenderSettings.skybox = prevSkyMat;
        }