/*
   Copyright (C) 2007 guest(r) - guest.r@gmail.com

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License
   as published by the Free Software Foundation; either version 2
   of the License, or (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

*/

/*
   This nice shader reads the brightness values of "pixels" and returns an image
   with only a single color used - to produce the "monochrome" effect, otherwise seen on now very obsolete types of displays.

   The final numbers of colors can be set to produce a final reduced color look while still emulating an "advanced" gfx. chipset.
*/

/* COMPATIBILITY 
   - HLSL compilers
   - Cg   compilers
   - FX11 compilers
*/

#pragma parameter MCGREEN_COLOR "McGreen Color" 256.0 0.0 256.0 1.0
#ifdef PARAMETER_UNIFORM
uniform float MCGREEN_COLOR;
#else
#define MCGREEN_COLOR 256.0
#endif

#include "../compat_includes.inc"
uniform COMPAT_Texture2D(decal) : TEXUNIT0;
uniform float4x4 modelViewProj;

struct out_vertex
{
	float4 position : COMPAT_POS;
	float2 texCoord : TEXCOORD0;
#ifndef HLSL_4
	float4 Color    : COLOR;
#endif
};

out_vertex main_vertex(COMPAT_IN_VERTEX)
{
	out_vertex OUT;
#ifdef HLSL_4
	float4 position = VIN.position;
	float2 texCoord = VIN.texCoord;
#else
	OUT.Color = color;
#endif
	OUT.position = mul(modelViewProj, position);
	OUT.texCoord = texCoord;
	
	return OUT;
}

float4 main_fragment(COMPAT_IN_FRAGMENT) : COMPAT_Output
{
	float3 ink = float3(0.32, 0.50, 0.0);  
	float3 c11 = COMPAT_Sample(decal, VOUT.texCoord).xyz;
	float lct = floor(MCGREEN_COLOR * length(c11)) / MCGREEN_COLOR;

	return float4(lct*ink,1);
}
COMPAT_END