//varying vec2 texCoord;
varying vec4 vpos;
uniform sampler2D colorMap;
uniform sampler2D dramaMap;
uniform float tlx;
uniform float tly;
uniform float drx;
uniform float dry;
uniform float boxscalex;
uniform float boxscaley;
uniform float gradientselect;
varying vec4 flatvpos;
varying vec4 boxpos;
uniform float testvalue;
/*
void main (void)
{
	gl_FragColor = texture2D(colorMap, texCoord);
}
*/

void main (void)
{
///gradientselect*=testvalue;
//vec2 nutexcoord;
//	nutexcoord=texCoord;
//	nutexcoord.x=1.0-nutexcoord.x;

	//float x=(vpos.x-tlx)/(drx-tlx); float y=(vpos.y-tly)/(dry-tly);
	//float x=(flatvpos.x-tlx)/(drx-tlx); float y=(flatvpos.y-tly)/(dry-tly);
	//float x=(boxpos.x-tlx)/(drx-tlx); float y=(boxpos.y-tly)/(dry-tly);


	//tlx=(gl_ModelViewMatrix * vec4(tlx,0,0,1)).x;
	//tly=(gl_ModelViewMatrix * vec4(0,tly,0,1)).y;
	//drx=(gl_ModelViewMatrix * vec4(drx,0,0,1)).x;
	//dry=(gl_ModelViewMatrix * vec4(0,dry,0,1)).y;
	//tlx=(gl_ModelViewProjectionMatrix* vec4(tlx,0,0,1)).x;
	//tly=(gl_ModelViewProjectionMatrix* vec4(0,tly,0,1)).y;
	//boxscalex=(gl_ModelViewProjectionMatrix* vec4(boxscalex,0,0,1)).x;
	//boxscaley=(gl_ModelViewProjectionMatrix* vec4(0,boxscaley,0,1)).y;
	//drx=(gl_ModelViewProjectionMatrix* vec4(drx,0,0,1)).x;
	//dry=(gl_ModelViewProjectionMatrix* vec4(0,dry,0,1)).y;
	boxscalex=drx-tlx;
	boxscaley=dry-tly;

	float x=(boxpos.x-tlx)/boxscalex; float y=(boxpos.y-tly)/boxscaley;
	//float x=(flatvpos.x-tlx)/boxscalex*testvalue; float y=(flatvpos.y-tly)/boxscaley*testvalue;
	vec2 texCoord=vec2(x,y);
	vec4 col1=texture2D(dramaMap, clamp(texCoord,2.0/256.0,254.0/256.0));
	vec4 col2=texture2D(colorMap, clamp(vec2(1.0-col1.r,gradientselect),2.0/256.0,254.0/256.0));
	gl_FragColor = col2;
	//gl_FragColor = texture2D(colorMap, texCoord)*vColor;
	//gl_FragColor = texture2D(colorMap, nutexcoord);
}
