diffuseTex

>> vertex <<

vec3 IN_position;
vec2 IN_texCoords;
vec3 IN_normal;
vec4 IN_tangent;
vec4 IN_weight;

uniform mat4 viewProjMatrix;
uniform vec4 spritesheetSize;

varying	vec4 OUT_position;
varying	vec2 OUT_texCoords;


void main()
{
	IN_position = ( gl_Vertex.xyz);
	IN_texCoords = vec2(gl_MultiTexCoord2.w, 0.0);
	IN_normal = gl_MultiTexCoord1.xyz;
	IN_tangent = gl_MultiTexCoord2.xyzw;
	IN_weight = gl_MultiTexCoord4.xyzw;

    vec2 is = spritesheetSize.xy;
    vec2 topLeft = IN_weight.xy / is;
    vec2 spriteSize = IN_normal.xy / is;

	vec2 pos2 = IN_weight.zw*0.5 - (vec2(IN_normal.z, IN_tangent.z) / IN_normal.xy);
	pos2 *= IN_normal.xy * IN_tangent.xy;


	mat2 rotmat;
	rotmat[0][0] = cos(IN_position.z);
	rotmat[1][0] = -sin(IN_position.z);
	rotmat[0][1] = sin(IN_position.z);
	rotmat[1][1] = cos(IN_position.z);

    vec4 pos4 = vec4(rotmat*pos2 + IN_position.xy, IN_texCoords.x, 1.0);
	pos4.xy = floor(pos4.xy+0.5);
	vec2 tc = IN_weight.zw * 0.5 + 0.5;

    OUT_texCoords = topLeft + tc * spriteSize;
	//pos4.y = -0.5*pos4.y;
	OUT_position = pos4;

	gl_Position = viewProjMatrix * OUT_position;
}

>> vertex-reflect <<

vec3 IN_position;
vec2 IN_texCoords;
vec3 IN_normal;
vec4 IN_tangent;
vec4 IN_weight;


uniform mat4 viewProjMatrix;
uniform vec4 spritesheetSize;
varying	vec4 OUT_position;
varying	vec2 OUT_texCoords;

#define NEW_REFLECTION 1

void main()
{
	IN_position = gl_Vertex.xyz;
	IN_texCoords = vec2(gl_MultiTexCoord2.w, 0.0);
	IN_normal = gl_MultiTexCoord1.xyz;
	IN_tangent = gl_MultiTexCoord2.xyzw;
	IN_weight = gl_MultiTexCoord4.xyzw;

    vec2 is = spritesheetSize.xy;
    vec2 topLeft = IN_weight.xy / is;
    vec2 spriteSize = IN_normal.xy / is;

	vec2 pos2 = IN_weight.zw*0.5 - (vec2(IN_normal.z, IN_tangent.z) / IN_normal.xy);
	pos2 *= IN_normal.xy * IN_tangent.xy;

	mat2 rotmat;
	rotmat[0][0] = cos(IN_position.z);
	rotmat[1][0] = -sin(IN_position.z);
	rotmat[0][1] = sin(IN_position.z);
	rotmat[1][1] = cos(IN_position.z);

    vec4 pos4 = vec4(rotmat*pos2 + IN_position.xy, IN_texCoords.x, 1.0);

	vec2 tc = IN_weight.zw * 0.5 + 0.5;

    OUT_texCoords = topLeft + tc * spriteSize;

	/// REFLECT
#if !NEW_REFLECTION
	pos4.y = -0.5*pos4.y;
#else
	pos4.y = -1.0*pos4.y;
#endif
	OUT_position = pos4;

	gl_Position = viewProjMatrix * OUT_position;
}

>> fragment <<
// #extension GL_EXT_gpu_shader4 : enable //Enabled for texelFetch

uniform sampler2D diffuseTex;


varying	vec4 OUT_position;
varying	vec2 OUT_texCoords;

uniform vec4 uniform_colors[8];


void main()
{
	vec4 diffuse = texture2D(diffuseTex, OUT_texCoords);
	int thecolind = int(diffuse.x * 8);
	vec4 outdiffuse = uniform_colors[thecolind];
	if (diffuse.rgb == vec3(0))
		discard;
	if (OUT_position.y > 0)
		discard;
	gl_FragColor = outdiffuse;
}

>> fragment-reflect <<
// #extension GL_EXT_gpu_shader4 : enable //Enabled for texelFetch

uniform sampler2D diffuseTex;


varying	vec4 OUT_position;
varying	vec2 OUT_texCoords;
uniform vec4 uniform_colors[8];


void main()
{
	vec4 diffuse = texture2D(diffuseTex, OUT_texCoords);
	int thecolind = int(diffuse.x * 8);
	vec4 outdiffuse = uniform_colors[thecolind];
	if (diffuse.rgb == vec3(0))
		discard;
	if (OUT_position.y < 0)
		discard;
	gl_FragColor = outdiffuse;
}

>> vertex/CG <<

struct input
{
float3 position 	: POSITION;
float3 normal	: TEXCOORD1;
float4 tangent	: TEXCOORD2;
float4 weight	: TEXCOORD4;
};

struct output
{
float4 position;
float4 gl_Position : POSITION;
float2 texCoords;
};

output main(input IN, uniform float4x4 viewProjMatrix, uniform float2 spritesheetSize)
{
float2 is = spritesheetSize.xy;
float2 topLeft = IN.weight.xy / is;
float2 spriteSize = IN.normal.xy / is;

float2 pos2 = IN.weight.zw*0.5 - (float2(IN.normal.z, IN.tangent.z) / IN.normal.xy);
pos2 *= IN.normal.xy * IN.tangent.xy;


float2x2 rotmat;
rotmat[0][0] = cos(IN.position.z);
rotmat[0][1] = -sin(IN.position.z);
rotmat[1][0] = sin(IN.position.z);
rotmat[1][1] = cos(IN.position.z);

float4 pos4 = float4(mul(rotmat,pos2) + IN.position.xy, IN.tangent.w, 1.0);
pos4.xy = floor(pos4.xy+0.5);
float2 tc = IN.weight.zw * 0.5 + 0.5;

output OUT;

OUT.texCoords = topLeft + tc * spriteSize;
OUT.position = pos4;

OUT.gl_Position = mul(viewProjMatrix, OUT.position);

return OUT;
}



>> fragment/CG <<

struct input
{
float4 position;
float4 gl_Position : POSITION;
float2 texCoords;
};

struct output
{
float4 color 	: COLOR;
};

output main(input IN, uniform sampler2D diffuseTex: TEXUNIT0,
uniform float4 uniform_colors[8]) : COLOR
{
output OUT;
float4 diffuse = tex2D( diffuseTex, IN.texCoords);
int thecolind = int(diffuse.x * 8);
	/*float4 outdiffuse = uniform_colors[thecolind];
	//float4 outdiffuse = diffuse;*/
	float4 outdiffuse = float4(0);
	if (thecolind == 0)
		outdiffuse = uniform_colors[0];
	if (thecolind == 1)
		outdiffuse = uniform_colors[1];
	if (thecolind == 2)
		outdiffuse = uniform_colors[2];
	if (thecolind == 3)
		outdiffuse = uniform_colors[3];
	if (thecolind == 4)
		outdiffuse = uniform_colors[4];
	if (thecolind == 5)
		outdiffuse = uniform_colors[5];
	if (thecolind == 6)
		outdiffuse = uniform_colors[6];
	if (thecolind == 7)
		outdiffuse = uniform_colors[7];
if (diffuse.r == 0 && diffuse.g == 0 && diffuse.b == 0)
discard;
if (IN.position.y > 0)
discard;
OUT.color = outdiffuse;
return OUT;
};

>> vertex-reflect/CG <<

struct input
{
float3 position 	: POSITION;
float3 normal	: TEXCOORD1;
float4 tangent	: TEXCOORD2;
float4 weight	: TEXCOORD4;
};

struct output
{
float4 position;
float4 gl_Position : POSITION;
float2 texCoords;
};

#define NEW_REFLECTION 1

output main(input IN, uniform float4x4 viewProjMatrix, uniform float2 spritesheetSize)
{
float2 is = spritesheetSize.xy;
float2 topLeft = IN.weight.xy / is;
float2 spriteSize = IN.normal.xy / is;

float2 pos2 = IN.weight.zw*0.5 - (float2(IN.normal.z, IN.tangent.z) / IN.normal.xy);
pos2 *= IN.normal.xy * IN.tangent.xy;


float2x2 rotmat;
rotmat[0][0] = cos(IN.position.z);
rotmat[0][1] = -sin(IN.position.z);
rotmat[1][0] = sin(IN.position.z);
rotmat[1][1] = cos(IN.position.z);

float4 pos4 = float4(mul(rotmat,pos2) + IN.position.xy, IN.tangent.w, 1.0);
pos4.xy = floor(pos4.xy+0.5);
float2 tc = IN.weight.zw * 0.5 + 0.5;

output OUT;

OUT.texCoords = topLeft + tc * spriteSize;

/// REFLECT
#if !NEW_REFLECTION
	pos4.y *= -0.5;
#else
	pos4.y *= -1.0;
#endif
OUT.position = pos4;

OUT.gl_Position = mul(viewProjMatrix, OUT.position);

return OUT;
}


>> fragment-reflect/CG <<

struct input
{
float4 position;
float4 gl_Position : POSITION;
float2 texCoords;
};

struct output
{
float4 color 	: COLOR;
};

output main(input IN, uniform sampler2D diffuseTex: TEXUNIT0,
uniform float4 uniform_colors[8]) : COLOR
{
if (IN.position.y < 0) discard;

float4 diffuse = tex2D( diffuseTex, IN.texCoords);
int thecolind = int(diffuse.x * 8);
output OUT;
OUT.color = float4(0);
if (thecolind == 0)
	discard;
else if (thecolind == 1)
	OUT.color = uniform_colors[1];
else if (thecolind == 2)
	OUT.color = uniform_colors[2];
else if (thecolind == 3)
	OUT.color = uniform_colors[3];
else if (thecolind == 4)
	OUT.color = uniform_colors[4];
else if (thecolind == 5)
	OUT.color = uniform_colors[5];
else if (thecolind == 6)
	OUT.color = uniform_colors[6];
else OUT.color = uniform_colors[7];

return OUT;
};
