What is the best solution for passing last rendered frame to shader?

Hi, I am making a shader that compares the last frame to the current one. So, I need to keep the last frame in a buffer. I have tried setting the 2D texture parameter in the shader to a RenderImage in the manner below.

Shader "Compare"
{
    Properties
    {
        _MainTex ("_MainTex", 2D) = "white" {}
        _BufferTexture ("_BufferTexture", 2D) = "white" {}
....

And then in c# to change the textures

    void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        Graphics.Blit(buffer, destination, myShader);   //Goes to _MainTex

        Graphics.Blit(vp.targetTexture, buffer);        //buffer assigned to_BufferTexture in property window
    }

How do I blit to the texture in the shader?

Also, I tried with Texture2d in c# like so:

       RenderTexture.active = vp.targetTexture;
        _BufferTexture.ReadPixels(new Rect(0, 0, buffer.width, buffer.height), 0, 0);
        _BufferTexture.Apply();

Where I have a separate Texture2D assigned to the shader instead of a RenderTexture and then Read the rendertexture pixels into it. But this is way too slow and cumbersome it seams. Is there a better way?

I think that’s why there is custom render target:

Yeah, I looked t that, I turned on all the double buffering and then tried to access “_SelfTexture2D” but there was nothing in it. A working example would be good, but I could not find any.

I figured out a hackey way of doing it. I don’t use the _MainTex at all. Instead I use 2 separate sample2d’s. Here is the hack. But I would love an example of double buffering with CustomRenderTextures

    long lastframe = 0;
    void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        if (vp.frame != lastframe)
        {
            lastframe = vp.frame;
            Graphics.CopyTexture(_Buffer2Texture, _BufferTexture);
            Graphics.CopyTexture(vp.targetTexture, _Buffer2Texture);
        }
        Graphics.Blit(vp.targetTexture, destination, myShader);
    }
}