Gamestudio Links
Zorro Links
Newest Posts
What are you working on?
by rayp. 10/15/25 20:44
Help!
by VoroneTZ. 10/14/25 05:04
Zorro 2.70
by jcl. 10/13/25 09:01
ZorroGPT
by TipmyPip. 10/12/25 13:58
Sam Foster Sound | Experienced Game Composer for Hire
by titanicpiano14. 10/11/25 18:45
Reality Check results on my strategy
by dBc. 10/11/25 06:15
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
1 registered members (AndrewAMD), 7,782 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
joenxxx, Jota, krishna, DrissB, James168
19170 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Shader Guru's please apply. Advanced help needed. #402882
06/11/12 13:58
06/11/12 13:58
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline OP
Expert
EvilSOB  Offline OP
Expert

Joined: Feb 2008
Posts: 3,232
Australia
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
Re: Shader Guru's please apply. Advanced help needed. [Re: EvilSOB] #402886
06/11/12 15:35
06/11/12 15:35
Joined: Oct 2005
Posts: 4,771
Bay City, MI
lostclimate Offline
Expert
lostclimate  Offline
Expert

Joined: Oct 2005
Posts: 4,771
Bay City, MI
hmmm. I think if your using shader model 2 or higher you can have values over 1 so I wonder if you multiplied you return by something like 128, clipped the excess and then re-divided it if you'd accomplish what you need with a decent speed?

Re: Shader Guru's please apply. Advanced help needed. [Re: lostclimate] #402911
06/11/12 19:29
06/11/12 19:29
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline OP
Expert
EvilSOB  Offline OP
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Sorry Dude...

After an hour hacking with your idea, it still doesnt pan out, and I dont know why.

Any ideas? Example code? My brain hurts...


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Shader Guru's please apply. Advanced help needed. [Re: EvilSOB] #403163
06/15/12 15:46
06/15/12 15:46
Joined: Oct 2005
Posts: 4,771
Bay City, MI
lostclimate Offline
Expert
lostclimate  Offline
Expert

Joined: Oct 2005
Posts: 4,771
Bay City, MI
it was all theory. Don't really have any example code and I'm at work right now frown

Re: Shader Guru's please apply. Advanced help needed. [Re: lostclimate] #403544
06/21/12 19:54
06/21/12 19:54
Joined: Dec 2003
Posts: 1,097
Maryland, USA
Steempipe Offline
Serious User
Steempipe  Offline
Serious User

Joined: Dec 2003
Posts: 1,097
Maryland, USA
Hi, Please show a screen of the example of the problem, and an example of what you ideally want to do. Thanks.


Moderated by  Blink, Hummel, Superku 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1