SOLVED - Eliminating the depth buffer solved all problems.
I have two render textures that I would like to shade back and forth and back and forth using a GLSL shader.
I try to do this with a simple shader (this is the simplest one that shows my problem.)
Shader "Exerpiemnt/Simplest"
{
Properties
{
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader
{
Pass
{
GLSLPROGRAM
varying vec2 coords;
uniform sampler2D _MainTex;
#ifdef VERTEX
void main()
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
coords = vec2(gl_MultiTexCoord0);
}
#endif
#ifdef FRAGMENT
void main(void)
{
gl_FragColor = tex2D(_MainTex,coords);
}
#endif
ENDGLSL
}
}
FallBack off
}
Then I place a post-render script on the camera which normally takes in the scene view, and then when a boolean is set renders back and forth between the textures:
// Called by the camera to apply the image effect
void OnRenderImage (RenderTexture source, RenderTexture destination)
{
if ( recycle == false )
{
Graphics.Blit( source, Snapshot );
Graphics.Blit( Snapshot, destination );
useFirst = true;
}
else if ( useFirst )
{
Graphics.Blit( Snapshot, Snapshot2, material );
if ( showFirstOnly )
Graphics.Blit( Snapshot, destination );
else
Graphics.Blit( Snapshot2, destination );
useFirst = false;
}
else
{
Graphics.Blit( Snapshot2, Snapshot, material );
if ( showSecondOnly )
Graphics.Blit( Snapshot2, destination );
else
Graphics.Blit( Snapshot, destination );
useFirst = true;
}
}
If I do not use the material, (that is I do not use my shader), the images look crisp and clean and are fine.
When I do use the shader, they have some artifacts in them. These artifacts are in the same location every time the image is recycled (within the same editor play) but in different locations between plays. And the two render textures have different artifacts that are not shared between themselves (do not propogate to each other?)
My first question is, is this the best method to do iterative shading? or is there a better method than Graphics.Blit that I should use. Second, how do I get rid of these artifacts.
I would like to use the GLSL shaders for all kinds of calculations as well as image effects but can not afford to have it corrupt the data.