Artifacts when iterative shading

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.

I attempted to do the same thing with a CG shader as well, and have a similar issue:

Shader "Exerpiemnt/SimplestCG"
{
	Properties {
		_MainTex ("Base (RGB)", 2D) = "white" {}
	}
	SubShader {
		Tags { "RenderType"="Opaque" }
		LOD 2048
		
		Pass {
			CGPROGRAM
				#pragma vertex vert
				#pragma fragment frag
				#include "UnityCG.cginc"
			
				struct v2f {
					float4 pos : SV_POSITION;
					float2 uv_MainTex : TEXCOORD0;
				};
			
				float4 _MainTex_ST;
			
				v2f vert(appdata_base v) {
					v2f o;
					o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
					o.uv_MainTex = TRANSFORM_TEX(v.texcoord, _MainTex);
					return o;
				}
			
				sampler2D _MainTex;
			
				float4 frag(v2f IN) : COLOR {
					half4 c = tex2D (_MainTex, IN.uv_MainTex);
					return c;
				}
			ENDCG
		}
	}
	FallBack off
}

I have still not been able to figure out why these are here, and how to get rid of them. Or, in other words to guarantee complete rendering if a render texture without corruption…

Again, this is important because I want to iteratively render.

It looks to me as if one or more of your buffers has preexisting garbage that is just never overwritten.
Do your snapshot rendertextures have depth buffers? If so, you should probably get rid of those or add a
ZTest Always
to your subshader or pass

In my Watersimulation, I create completely new RenderTextures for each iteration. I haven’t noticed any big problems with overhead, especially in heavier simulations, and it helps prevent odd artifacts (in early tests, I got creepy ghost text appearing on the result, and odd mirrored data). Make sure you clean up the textures when you no longer need them as input (Release and DestroyImmediate) so you don’t run out of memory ^^.

Thank you both so much! The depth-buffer was the problem. Eliminating it has cleared up the weird artifacts.

I also appreciate the advice of creating a new one from scratch and will take that route if I should have any more problems.

John