protected override void Render(Camera camera, float height, float minHeight, ref Texture2D tex)
        {
            RenderTexture src = RenderTexture.GetTemporary(4096, 4096, 24);

            camera.targetTexture = src;

            Shader.SetGlobalFloat("height", height);
            Shader.SetGlobalFloat("minheight", minHeight);
            camera.RenderWithShader(Shader.Find("Hidden/DepthMapRenderer"), "RenderType");

            Material blurMat = new Material(Shader.Find("Hidden/EdgeBlur"));

            blurMat.hideFlags = HideFlags.HideAndDontSave;
            blurMat.SetFloat("_Offset", offset);
            blurMat.SetFloat("_EdgeBeginWidth", edgeBeginWidth);
            blurMat.SetFloat("_Power", power);

            RenderTexture rt = RenderTexture.GetTemporary(src.width / 4, src.height / 4);

            Graphics.Blit(src, rt);
            for (int i = 0; i < iterations; i++)
            {
                RenderTexture rt2 = RenderTexture.GetTemporary(src.width / 4, src.height / 4);
                Graphics.Blit(rt, rt2, blurMat, 0);
                RenderTexture.ReleaseTemporary(rt);
                rt = rt2;
            }
            for (int i = 0; i < iterations; i++)
            {
                RenderTexture rt2 = RenderTexture.GetTemporary(src.width / 4, src.height / 4);
                Graphics.Blit(rt, rt2, blurMat, 1);
                RenderTexture.ReleaseTemporary(rt);
                rt = rt2;
            }

            blurMat.SetTexture("_Mix", rt);

            RenderTexture dst = RenderTexture.GetTemporary(src.width, src.height, src.depth);

            Graphics.Blit(src, dst, blurMat, 2);

            camera.targetTexture = null;

            RenderTexture.ReleaseTemporary(src);

            tex = UnlitWaterUtils.RenderTextureToTexture2D(dst);

            RenderTexture.ReleaseTemporary(dst);
        }
Exemple #2
0
        protected override void Render(Camera camera, float height, float minHeight, ref Texture2D tex)
        {
            RenderTexture rt = new RenderTexture(4096, 4096, 24);

            rt.hideFlags = HideFlags.HideAndDontSave;

            camera.targetTexture = rt;

            Shader.SetGlobalFloat("depth", maxDepth);
            Shader.SetGlobalFloat("power", depthPower);
            Shader.SetGlobalFloat("height", height);
            Shader.SetGlobalFloat("minheight", minHeight);
            camera.RenderWithShader(Shader.Find("Hidden/DepthMapRenderer"), "RenderType");

            tex = UnlitWaterUtils.RenderTextureToTexture2D(rt);

            camera.targetTexture = null;
            Object.DestroyImmediate(rt);
        }