I'd like to use a render target as an input texture to a shader, this shader being used to render into said render target.
What I'm mostly interested to know is if I do that, when I read pixels from the RT (tex2D(blahblah);) will those retrieved pixels be of the untouched original RT before any rendering, or will they be modified as pixels get rendered into the RT?
OK, I tested it and I can answer this ages-old question:
Yes, it's possible to do something like this:
RenderTexture oldRT = RenderTexture.active;
RenderTexture.active = RT;
GL.PushMatrix( );
Material mat = myMat;
mat.SetTexture( "_MainTex", RT );
for( int i = 0 ; i < mat.passCount ; i++ )
{
mat.SetPass( i );
DrawQuad( rect, new Rect( 0.0f, 0.0f, 1.0f, 1.0f ) ); //some rectangle, with texture coords...
}
GL.PopMatrix( );
RenderTexture.active = oldRT;
which uses the target texture as a normal texture in the shader.
If it works for me, it might be because my hardware (GTX260) is capable of getting data from stuff it's rendering too, I don't know.
But that definitely works.
I think I can also answer my second question, since I can see some bleeding from my blur shader: when I read from my render texture, it reads things that were already rendered for previous pixels.
In other words: I'm definitely reading what I'm writing into by doing that.
And I for one am happy of this. There are so many crazy things that can be done with this fact. Many will consider it horrible hack, I don't mind :)
But I still need to use an intermediate render texture for my blur, because of all the bleeding :p