Exemplo n.º 1
0
        void Update()
        {
            // make sure the Holoplay is capturing depth
            holoplay.cam.depthTextureMode = DepthTextureMode.Depth;
            // passing shader vars
            Vector4 dofParams = new Vector4(start, dip, rise, end) * holoplay.size;

            dofParams = new Vector4(
                1.0f / (dofParams.x - dofParams.y),
                dofParams.y,
                dofParams.z,
                1.0f / (dofParams.w - dofParams.z)
                );
            boxBlurMat.SetVector("dofParams", dofParams);
            boxBlurMat.SetFloat("focalLength", holoplay.GetCamDistance());
            finalpassMat.SetInt("testFocus", testFocus ? 1 : 0);
            if (horizontalOnly)
            {
                Shader.EnableKeyword("_HORIZONTAL_ONLY");
            }
            else
            {
                Shader.DisableKeyword("_HORIZONTAL_ONLY");
            }
        }
Exemplo n.º 2
0
        public void DoDOF(RenderTexture src, RenderTexture srcDepth)
        {
            // // make sure the Holoplay is capturing depth
            // holoplay.cam.depthTextureMode = DepthTextureMode.Depth;
            // passing shader vars
            Vector4 dofParams = new Vector4(start, dip, rise, end) * holoplay.size;

            dofParams = new Vector4(
                1.0f / (dofParams.x - dofParams.y),
                dofParams.y,
                dofParams.z,
                1.0f / (dofParams.w - dofParams.z)
                );
            boxBlurMat.SetVector("dofParams", dofParams);
            boxBlurMat.SetFloat("focalLength", holoplay.GetCamDistance());
            finalpassMat.SetInt("testFocus", testFocus ? 1 : 0);
            if (horizontalOnly)
            {
                Shader.EnableKeyword("_HORIZONTAL_ONLY");
            }
            else
            {
                Shader.DisableKeyword("_HORIZONTAL_ONLY");
            }

            // make the temporary pass rendertextures
            var fullres = RenderTexture.GetTemporary(src.width, src.height, 0);
            // var fullresDest = RenderTexture.GetTemporary(src.width, src.height, 0);
            var blur1 = RenderTexture.GetTemporary(src.width / 2, src.height / 2, 0);
            var blur2 = RenderTexture.GetTemporary(src.width / 3, src.height / 3, 0);
            var blur3 = RenderTexture.GetTemporary(src.width / 4, src.height / 4, 0);

            Shader.SetGlobalVector("ProjParams", new Vector4(
                                       1f,
                                       holoplay.cam.nearClipPlane,
                                       holoplay.cam.farClipPlane,
                                       1f
                                       ));

            var tile = new Vector4(
                holoplay.quiltSettings.viewColumns,
                holoplay.quiltSettings.viewRows,
                holoplay.quiltSettings.numViews,
                holoplay.quiltSettings.viewColumns * holoplay.quiltSettings.viewRows
                );
            var viewPortion = new Vector4(
                holoplay.quiltSettings.viewPortionHorizontal,
                holoplay.quiltSettings.viewPortionVertical
                );

            boxBlurMat.SetVector("tile", tile);
            boxBlurMat.SetVector("viewPortion", viewPortion);
            finalpassMat.SetVector("tile", tile);
            finalpassMat.SetVector("viewPortion", viewPortion);

            // passes: start with depth
            passdepthMat.SetTexture("QuiltDepth", srcDepth);
            Graphics.Blit(src, fullres, passdepthMat);

            // blur 1
            boxBlurMat.SetInt("blurPassNum", 0);
            boxBlurMat.SetFloat("blurSize", blurSize * 2f);
            Graphics.Blit(fullres, blur1, boxBlurMat);

            // blur 2
            boxBlurMat.SetInt("blurPassNum", 1);
            boxBlurMat.SetFloat("blurSize", blurSize * 3f);
            Graphics.Blit(fullres, blur2, boxBlurMat);

            // blur 3
            boxBlurMat.SetInt("blurPassNum", 2);
            boxBlurMat.SetFloat("blurSize", blurSize * 4f);
            Graphics.Blit(fullres, blur3, boxBlurMat);

            // setting textures
            finalpassMat.SetTexture("blur1", blur1);
            finalpassMat.SetTexture("blur2", blur2);
            finalpassMat.SetTexture("blur3", blur3);

            // final blit for foreground
            // Graphics.Blit(fullres, src);
            Graphics.Blit(fullres, src, finalpassMat);

            // disposing of stuff
            RenderTexture.ReleaseTemporary(fullres);
            // RenderTexture.ReleaseTemporary(fullresDest);
            RenderTexture.ReleaseTemporary(blur1);
            RenderTexture.ReleaseTemporary(blur2);
            RenderTexture.ReleaseTemporary(blur3);
        }