HLSL tex2d border problem

Started by
1 comment, last by hardy_dev 15 years, 1 month ago
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(); } }
Advertisement
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

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

Thanks jollyjeffers,

I try with
AddressU = Clamp;
AddressV = Clamp;

problem is resolved, thanks very much. :)

This topic is closed to new replies.

Advertisement