<jittershader name="map">
	<description>
	charmap-style color lookup
	</description>
	
	<param name="mapdim" type="float" default="256.">
		<description>size of color map</description>
	</param>
	<param name="amt" type="float" default="1.">
		<description>mix amount</description>
	</param>
	<param name="interp" type="int" default="0" />
	<param name="tex0" type="int" default="0" />
	<param name="tex1" type="int" default="1" />
	<language name="glsl" version="1.0">
		<bind param="mapdim" program="fp" /> 
		<bind param="amt" program="fp" /> 
		<bind param="interp" program="fp" />
		<bind param="tex0" program="fp" />
		<bind param="tex1" program="fp" />	
		<program name="vp" type="vertex" source="sh.passthru.xform.vp.glsl" />
		<program name="fp" type="fragment">
<![CDATA[

// Andrew Benson - andrewb@cycling74.com
//Copyright 2006 - Cycling '74
//fragment shader for charmap-style Color LUT


//setup for 2 texture
varying vec2 texcoord0;
varying vec2 texcoord1;
uniform sampler2DRect tex0;
uniform sampler2DRect tex1;

//wipe state
uniform int interp;
uniform float mapdim;
uniform float amt;

void main()
{   

	vec4 a = texture2DRect(tex0, texcoord0);
	vec4 set = mix(floor(a*mapdim),a*mapdim,float(interp));//multiply color value for LUT range
	float rout = float (texture2DRect(tex1, vec2(set.r,0.)).r);//look up red
	float gout = float (texture2DRect(tex1, vec2(set.g,0.)).g);//look up green
	float bout = float (texture2DRect(tex1, vec2(set.b,0.)).b);//look up blue
	vec4 mapped = vec4 (rout,gout,bout,a.a);
		
	// output texture
	gl_FragColor = mix(a,mapped,amt);
}
]]>
		</program>
	</language>
</jittershader>
