Jump to content
  • Advertisement
Sign in to follow this  
Fibonacci One

Bizarre TexCoords error in hlsl

This topic is 4054 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey everyone, I'm working on what I assumed would be some fairly simple code to perform a gaussian blur. To keep the source code I'm giving you as small as possible let's say I'm working on a 3x3 gaussian blur. I'm calculating three sets of texture coordinates in the vertex shader then when I pass them to the pixel shader the only texture coordinates that work correctly are the first ones defined in my structure. For example, if I were to draw the texture coords to the red and green channels in the code below LowTexCoords would work but CenterTexCoords would be black. The only set of texture coordnates that don't give me a black screen are the ones sent to TexCoord0. Any ideas what I'm doing wrong?
texture2D Image;

sampler2D nearestSampler = sampler_state
{
	Texture = <Image>;
	AddressU = Clamp;
	AddressV = Clamp;
	MipFilter = Point;
	MinFilter = Point;
	MagFilter = Point;
};

/********************************************************
				3x3 Gaussian Filter
********************************************************/

struct VSOutputBlur3
{
	float4 Position : Position;
	float2 LowTexCoords : TexCoord0;
	float2 CenterTexCoords : TexCoord1;
	float2 HighTexCoords : TexCoord2;
};

VSOutputBlur3 VSGaussianBlur3X(	float4 Position : Position,
				float2 TexCoords : TexCoord0)
{
	VSOutputBlur3 Output;
	Output.Position = Position;
	
	Output.LowTexCoords = float2(TexCoords.x - TexelSize, TexCoords.y);
	Output.CenterTexCoords = TexCoords;
	Output.HighTexCoords = float2(TexCoords.x + TexelSize, TexCoords.y);
	
	return Output;
}

VSOutputBlur3 VSGaussianBlur3Y(	float4 Position : Position,
			        float2 TexCoords : TexCoord0)
{
	VSOutputBlur3 Output;
	Output.Position = Position;
	
	Output.LowTexCoords = float2(TexCoords.x, TexCoords.y - TexelSize);
	Output.CenterTexCoords = TexCoords;
	Output.HighTexCoords = float2(TexCoords.x, TexCoords.y + TexelSize);
	
	return Output;
}

float4 PSGaussianBlur3( VSOutputBlur3 Input ) : Color
{
	float4 TapLow = tex2D(nearestSampler, Input.LowTexCoords) * Blur3[0];
	float4 TapCenter = tex2D(nearestSampler, Input.CenterTexCoords) * Blur3[1];
	float4 TapHigh = tex2D(nearestSampler, Input.HighTexCoords) * Blur3[2];
	
	return (TapLow + TapCenter + TapHigh);
}

technique GuassianBlur3x3
{
	pass p0
	{
		VertexShader = compile vs_2_0 VSGaussianBlur3X();
		PixelShader = compile ps_2_0 PSGaussianBlur3();
	}
	pass p1
	{
		VertexShader = compile vs_2_0 VSGaussianBlur3Y();
		PixelShader = compile ps_2_0 PSGaussianBlur3();
	}
}


[Edited by - Fibonacci One on May 14, 2007 1:27:50 PM]

Share this post


Link to post
Share on other sites
Advertisement
Does your hardware support the point filtering of mip-maps that your sampler is asking for? Check the device caps

Does it support point filtering of mip-maps with the back buffer/render target format you're using? IDirect3D9::CheckDeviceFormat with D3DUSAGE_QUERY_FILTER to see.

Same with the minification and magnification filters.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!