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?