// Smearless Projected MovieTextures: VideoProjector/Multiply 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'

// MULTIPLY MODE:
// Projects the video using Multiply to draw image onto surfaces.
// Does not use falloff so yoou get reverse projection and projection extends on back faces of object.

// 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.

// Notes:
// Mulitply uses constant color so actual colour of texture map may be irrelevant.


Shader "ncp/FX/VideoProjector/Multiply v1.01" 
{
	Properties
	{
		_MovieTexture ("MovieTexture", 2D) = "" { TexGen ObjectLinear }
		_MaskTex ("Mask Clamp", 2D) = "" { TexGen ObjectLinear }
	}
	
	Subshader 
	{
		Tags { "RenderType"="Transparent" }
		Pass
		{
			ZWrite off
			AlphaTest Greater 0							// Required
			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 DstColor Zero  
			
			SetTexture [_MovieTexture]
			{
				combine texture, texture
				Matrix [_Projector]
         	}
			
			SetTexture [_MaskTex]
			{
				constantColor (1,1,1,0)
				combine previous *constant,  texture
				Matrix [_Projector]
			}
         
     	}
	}
}