// Smearless Projected MovieTextures: VideoProjector/Additive Falloff v1.01
// Author: Noisecrime
// Date:   14.06.10

// INFO:
// Designed for use with Projected movieTextures to avoid the 'smearing' due to clamping.
// Based on builtin shader 'ShadowProjection.shader' - 'FX/Projector Multiply'

// ADDITIVE FALLOFF MODE:
// Projects the video using additive blend image onto surfaces.
// Falloff supported so you can avoid reverse projection and with tweaking avoid projecting onto other faces.

// METHOD:
// Uses a plain white texture (clamped) with black edge pixels in alpha to mask out video clamp issue.

// USAGE:
// Make sure you mask texture is rgba (RGBA 16 format for best results) with white alpha, but with a black edge/border. 
// Try to avoid using mip-maps, Set filter to 'point' this prevents artifacts around the edges at accute view angles.
// If you must use mip-maps, make sure you enable 'Border mipmaps' and set Aniso Level high.
// Set mask texture to use clamp wrapmode.
// Ensure the mask texture is 1:1 pixel size to movie texture to avoid scaling black border.


Shader "ncp/FX/VideoProjector/Additive with Falloff v1.01" 
{
	Properties 
	{
		_MovieTexture ("MovieTexture", 2D) = "" { TexGen ObjectLinear }
		_MaskTex ("Mask Clamp", 2D) = "" { TexGen ObjectLinear }
		_FalloffTex ("FallOff", 2D) = "" { TexGen ObjectLinear }
	}
	
	Subshader 
	{
		Tags { "RenderType"="Transparent" }
		Pass 
		{
			ZWrite off
			AlphaTest Greater 0							// Optional: though might improve performance.
			AlphaToMask True							// Optional: when using FSAA, alpha-tested objects can smoother outlines. Not Tested
			Fog { Color (1, 1, 1) }
			ColorMask RGB								// would RGBA be more efficient?
			Blend SrcAlpha One 
			
			SetTexture [_MovieTexture]
			{
				combine texture  , One - texture
				Matrix [_Projector]
			}
			
			SetTexture [_MaskTex]
			{
				//combine previous * texture,  texture  // Optional: allows use of texture color.
				
				ConstantColor (1,1,1,0)
				combine previous *constant,  texture
				Matrix [_Projector]
			}
			
			SetTexture [_FalloffTex]
			{
				constantColor (0,0,0,0)
				combine previous lerp (texture) constant
				Matrix [_ProjectorClip]
			}
		}
	}
}



//SrcAlpha OneMinusSrcAlpha     //One One

// combine texture, ONE - texture
// constantColor (0,0,0,0)
// combine previous lerp (texture) constant
// combine texture lerp (texture) previous
// combine previous * texture//, previous * texture 

/*
Subshader {
      Pass {
         ZWrite off
         Fog { Color (1, 1, 1) }
         ColorMask RGBA
         Blend One OneMinusSrcAlpha

         SetTexture [_MaskTex] 
		{
		combine texture,  texture
            Matrix [_Projector] //[_ProjectorClip]
        	 }

         SetTexture [_MovieTexture] 
		{
            combine previous * texture, texture
            Matrix [_Projector]
         	}
     	}

*/