Sign in to follow this  
hardy_dev

HLSL tex2d border problem

Recommended Posts

hi,all, just a strange problem in HLSL, float4 alpha = tex2D(WipeAlphaCueSampler,float2(0,0)); //it should return the first column data of texture, but it return a grey value. float4 alpha = tex2D(WipeAlphaCueSampler,float2(0.000001,0)); //here it can return the first column data so any answer with that? I use GF 9600GT。 and I try ps_3_0 , ps_2_0 , both same problem. //below is the code ====================================================== texture WipeAlphaCue; sampler WipeAlphaCueSampler = sampler_state { Texture = <WipeAlphaCue>; MipFilter = LINEAR; MinFilter = LINEAR; MagFilter = LINEAR; }; float4 wipePS(WipeVertexOutput IN) : COLOR { float4 alpha = tex2D(WipeAlphaCueSampler,float2(0.0000001,0)); return alpha; } technique RenderScene { pass p0 { PixelShader = compile ps_2_0 wipePS(); } }

Share this post


Link to post
Share on other sites
I suspect you're getting caught in the pixel addressing issue.

Under D3D9 the centre of the pixel is at 0.5,0.5 - thus a UV of 0,0 is actually above-left from the top-left pixel. If you have wrapping enabled then it'll actually sample from all 4 corners of the texture!

Have a look at the "Directly Mapping Texels to Pixels" article in the SDK, it should provide valuable insight. In short, offsetting by 1/2 a pixel in the U and V directions should get you what you want. Otherwise you need to go for point sampling (might actually be better if you're using lookup textures) or different clamping/wrapping modes.


hth
Jack

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this