private void OnRenderImage(RenderTexture src, RenderTexture dest)
    {
        if (!RayMarchMat)
        {
            Graphics.Blit(src, dest);
            return;
        }

        //Matrix
        RayMarchMat.SetMatrix("_CamFrustum", CamFrustum(Cam));
        RayMarchMat.SetMatrix("_CamToWorld", Cam.cameraToWorldMatrix);


        RenderTexture.active = dest;
        RayMarchMat.SetTexture("_MainTex", src);

        RayMarchMat.SetTexture("_NoiseTex", noiseTex);

        RayMarchMat.SetFloat("_CloudSmooth", cloudSmooth);

        if (cloudRigi != null && cloudRigi.Length > 0)
        {
            RayMarchMat.SetVectorArray("_CloudRigi"
                                       , cloudRigi.Select(ts =>
            {
                if (ts == null)
                {
                    return(Vector4.zero);
                }

                var pos     = ts.position;
                var maxSize = Mathf.Max(ts.lossyScale.x, ts.lossyScale.y, ts.lossyScale.z);
                return(new Vector4(pos.x, pos.y, pos.z, maxSize));
            }).ToArray());
            RayMarchMat.SetInt("_CloudRigiNum", cloudRigi.Length);
        }
        else
        {
            RayMarchMat.SetInt("_CloudRigiNum", 0);
        }


        //压入当前的MVP
        GL.PushMatrix();

        //视野的锥型区域从(0,0,-1) to (1,1,100)
        GL.LoadOrtho();

        //激活pass 用于渲染
        RayMarchMat.SetPass(0);

        //压入一个面片当作模型
        GL.Begin(GL.QUADS);

        //BL
        //unit 是 texture 的编号
        GL.MultiTexCoord2(0, 0.0f, 0.0f);
        GL.Vertex3(0.0f, 0.0f, 3.0f); //z储存CamFrustum 的 row
        //BR
        GL.MultiTexCoord2(0, 1.0f, 0.0f);
        GL.Vertex3(1.0f, 0.0f, 2.0f);
        //TR
        GL.MultiTexCoord2(0, 1.0f, 1.0f);
        GL.Vertex3(1.0f, 1.0f, 1.0f);
        //TL
        GL.MultiTexCoord2(0, 0.0f, 1.0f);
        GL.Vertex3(0.0f, 1.0f, 0.0f);

        GL.End();

        //弹出改变MVP
        GL.PopMatrix();
    }
    private void OnRenderImage(RenderTexture src, RenderTexture dest)
    {
        if (!RayMarchMat)
        {
            Graphics.Blit(src, dest);
            return;
        }

        //Matrix
        RayMarchMat.SetMatrix("_CamFrustum", CamFrustum(Cam));
        RayMarchMat.SetMatrix("_CamToWorld", Cam.cameraToWorldMatrix);

        //Light
        if (directionalLight == null || directionalLight.type != LightType.Directional)
        {
            RayMarchMat.SetVector("_LightCol", Color.black);
            RayMarchMat.SetVector("_LightDir", Vector3.forward);
            RayMarchMat.SetFloat("_LightIntensity", 0);
        }
        else //(directionalLight.type == LightType.Directional)
        {
            RayMarchMat.SetColor("_LightCol", directionalLight.color);
            RayMarchMat.SetVector("_LightDir", directionalLight.transform.forward);
            RayMarchMat.SetFloat("_LightIntensity", directionalLight.intensity);
        }

        //Reflection
        if (reflectionProbe)
        {
            if (reflectionProbe.mode == ReflectionProbeMode.Baked)
            {
                RayMarchMat.SetTexture("_ReflectionCube"
                                       , reflectionProbe.bakedTexture);
            }
            else if (reflectionProbe.mode == ReflectionProbeMode.Custom)
            {
                RayMarchMat.SetTexture("_ReflectionCube"
                                       , reflectionProbe.customBakedTexture);
            }
            else if (reflectionProbe.mode == ReflectionProbeMode.Realtime)
            {
                RayMarchMat.SetTexture("_ReflectionCube"
                                       , reflectionProbe.realtimeTexture);
            }
        }
        else
        {
            RayMarchMat.SetTexture("_ReflectionCube"
                                   , Texture2D.blackTexture);
        }

        RayMarchMat.SetVector("_ReflectionData"
                              , new Vector3(
                                  _ReflectionCount, _ReflectionIntensity, _EnvRefIntensity
                                  ));

        //Shadow
        RayMarchMat.SetVector("_ShadowData"
                              , new Vector4(
                                  shadowDistance, shadowIntensity, softShadowPenumbra, softShadow ? 1f : 0f
                                  ));

        //AO
        RayMarchMat.SetVector("_AOData"
                              , new Vector3(
                                  aoStepSize, aoIterations, aoIntensity
                                  ));

        //Render Object
        RayMarchMat.SetFloat("_MaxDistance", maxDistance);
        RayMarchMat.SetFloat("_Accuracy", accuracy);
        RayMarchMat.SetFloat("_MaxIterations", maxIterations);

        //Sphere
        if (spheres != null && spheres.Length > 0)
        {
            RayMarchMat.SetVectorArray("_Spheres", spheres);
            RayMarchMat.SetInt("_SpheresNum", spheres.Length);
        }
        else
        {
            RayMarchMat.SetInt("_SpheresNum", 0);
        }

        if (spheresRigi != null && spheresRigi.Length > 0)
        {
            RayMarchMat.SetVectorArray("_SpheresRigi"
                                       , spheresRigi.Select(rigi =>
            {
                if (rigi == null)
                {
                    return(Vector4.zero);
                }

                var pos = rigi.transform.position;
                var col = rigi.GetComponent <SphereCollider>();
                return(new Vector4(pos.x, pos.y, pos.z, col == null ? 0f : col.radius));
            }).ToArray());
        }

        RayMarchMat.SetInt("_SpheresRigiNum", spheresRigi.Length);

        RayMarchMat.SetColor("_SpheresColor", spheresColor);
        RayMarchMat.SetFloat("_SphereSmooth", sphereSmooth);

        //Plane
        if (plane != null)
        {
            var position = plane.position;
            RayMarchMat.SetVector("_PlanePos"
                                  , new Vector4(position.x, position.y, position.z, 1.0f));
            RayMarchMat.SetVector("_PlaneUp", plane.up);
            RayMarchMat.SetVector("_PlaneColor", planeColor);
        }
        else
        {
            RayMarchMat.SetVector("_PlanePos", Vector4.zero);
        }

        RenderTexture.active = dest;
        RayMarchMat.SetTexture("_MainTex", src);

        //压入当前的MVP
        GL.PushMatrix();

        //视野的锥型区域从(0,0,-1) to (1,1,100)
        GL.LoadOrtho();

        //激活pass 用于渲染
        RayMarchMat.SetPass(0);

        //压入一个面片当作模型
        GL.Begin(GL.QUADS);

        //BL
        //unit 是 texture 的编号
        GL.MultiTexCoord2(0, 0.0f, 0.0f);
        GL.Vertex3(0.0f, 0.0f, 3.0f); //z储存CamFrustum 的 row
        //BR
        GL.MultiTexCoord2(0, 1.0f, 0.0f);
        GL.Vertex3(1.0f, 0.0f, 2.0f);
        //TR
        GL.MultiTexCoord2(0, 1.0f, 1.0f);
        GL.Vertex3(1.0f, 1.0f, 1.0f);
        //TL
        GL.MultiTexCoord2(0, 0.0f, 1.0f);
        GL.Vertex3(0.0f, 1.0f, 0.0f);

        GL.End();

        //弹出改变MVP
        GL.PopMatrix();
    }