hlsl Gather vs Sample, SM5.0

Started by
0 comments, last by Aqua Costa 12 years, 2 months ago
Hi,

I have a simple pixel shader like below. the result looks wrong if I use "texture2d.Gather". But, if I use "texture2d.Sample", the result is correct. the shader resource is RGB8_UNORM, my questions are

1. Gather and Sample should both return float4 in this case, right?

2. I searched the archive, some posts suggest that Gather will return the values of 4 texels. Since TemplateType is float4 here, the return value should be float4. where does "4 texels" come into picture?

3. based on the document, both Gather and Sample should return un-filtered values at one specific texture, correct?

Thank you for helps.



Texture2D<float4> texture2d;
sampler samplerState;

struct PSIn { float2 texcoord : TEXCOORD; };
struct PSOut{ float4 color : SV_Target; };

PSOut main( in PSIn input )
{
PSOut output;

output.color = texture2d.Gather(samplerState, input.texcoord, int2(0,0) );
// output.color = texture2d.Sample(samplerState, input.texcoord);

return output;
}
Advertisement
1.
-Sample returns a float4 containing the RGBA of the sampled texture.
-Gather returns a float4 in which each component contains the Red channel of the 4 texels that are used to perform bilinear filtering. So if you want to get the value in the Green channel you can you use GatherGreen() (and also GatherBlue() and GatherAlpha() ).

2.
-So like I said before the return float4 is float4(Red of texel 1, Red of texel 2, Red of texel 3, Red of texel 4).

3.
-Incorrect. Both Sample and Gather return values sampled using whatever filtering method you set in the sampler state used in those functions.

This topic is closed to new replies.

Advertisement