Hiya guys 'n gals.
I need some help with my below multi-tex shader, please.

As you can see from the code, I use the "MagFilter=NONE;" sampler state
to prevent the shader 'extrapolating' the texture co-ordinates when a pixel
is 'somewhere between' pixels in the blend map.
This give me nice SHARP edges based on my EXTREMELY low-resolution blend-map.

But, if I just use the usual "MagFilter=LINEAR;" or the like, then the
edges overlap TOO MUCH with neighbouring pixels.


But, I would LIKE to find a happy "medium" programmatically.


So, IF the texture co-ords were in 'whole numbers'... say 0->128
I could just truncate off a controlled portion of the decimal places with
the trusty old "integer()" function, BUT, as you know, the co-ordinate
system for textures is in the range 0.0->1.0, so I dont know where to begin...

Hopefully it can happen in the vertex-shader portion, as Im already short of
available calculation 'slots' in the pixel shader as is...


Im not looking for a "fix it for me" job here, because I want and need to
fully understand what Im doing, because this shader is a work-in-progress
as a proof-of-concept for something larger...


Thanks a heap guys...


Click to reveal..
Code:
//-----------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------
//
float4  vecSkill1;	//	from material skills	::	vecSkill1.x = texture-scaling multiplier
//
//-----------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------
//
// Engine Variables
float4x4 matWorldViewProj, matWorld;
float4 vecFog, vecViewPos, vecSunColor, vecLight;	float3 vecSunDir;
float4 vecLightPos[8], vecLightColor[8];
//
// Textures
Texture entSkin1;
Texture roof_shader_D_bmap;
Texture roof_shader_R_bmap;
Texture roof_shader_G_bmap;
Texture roof_shader_B_bmap;
//
// Samplers
sampler blendmap=sampler_state	{	Texture=<entSkin1>;	MagFilter=NONE;	};
sampler map_D = sampler_state		{	Texture=<roof_shader_D_bmap>;				};
sampler map_R = sampler_state		{	Texture=<roof_shader_R_bmap>;				};	
sampler map_G = sampler_state		{	Texture=<roof_shader_G_bmap>;				};
sampler map_B = sampler_state		{	Texture=<roof_shader_B_bmap>;				};
//
//-----------------------------------------------------------------------------------------
//
// Vertex Shader
void multitex_VS(float4 Pos  :POSITION,	float4 Norm:NORMAL,	float2 Tex:TEXCOORD0,
				out  float4 _Pos :POSITION,	out float2 _Tex:TEXCOORD1,	
				out  float2 _Norm:TEXCOORD2,	out float3 _View:TEXCOORD3						)
{
	// transform or direct-pipe vertex data
	_Pos  = mul(Pos, matWorldViewProj);		_View = mul(Pos, matWorld);		
	_Tex=Tex * vecSkill1.x;						_Norm=Norm;
}
//
//-----------------------------------------------------------------------------------------
//
// Per-Pixel Shader
float4 multitex_PS(	float4 Pos :POSITION,	float2 Tex :TEXCOORD1,	
							float2 Norm:TEXCOORD2,	float3 View:TEXCOORD3	): COLOR
{	
	// extract blending data
	float4 BlendColor = tex2D(blendmap, Tex/vecSkill1.x);
	// "blend" the textures together
	float4 Color = 	  tex2D(map_D, 	Tex);
	Color = lerp(Color, tex2D(map_R, 	Tex), BlendColor.r);
	Color = lerp(Color, tex2D(map_G, 	Tex), BlendColor.g);
	Color = lerp(Color, tex2D(map_B, 	Tex), BlendColor.b);
	//
	// calculate the diffuse 'sunlight' levels
	float4 Lights, Diffuse = (vecLight+saturate(dot(-vecSunDir, Norm))*vecSunColor);
	//
	// append the diffuse 'dynamic-light' levels
	for(int i = 0; i < 3; i++)		// need try to squeeze out 4 dynamic lights
	{	Lights.xyz = vecLightPos[i]-View;
		Lights.a = saturate(1.0f - length(Lights.xyz/vecLightPos[i].w));
		Diffuse += saturate(dot(normalize(Lights.xyz), Norm))*vecLightColor[i]*Lights.a;
	}
	//	
	return float4((Color*Diffuse).rgb, BlendColor.a);
}
//
//-----------------------------------------------------------------------------------------
//
// Render Pass
technique multitex
{
	pass one
	{
		VertexShader = compile vs_1_1 multitex_VS();
		PixelShader  = compile ps_1_1 multitex_PS();
	}
}
//
//-----------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------




"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial