Jump to content
  • Advertisement
Sign in to follow this  

hlsl Gather vs Sample, SM5.0

This topic is 2807 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


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;

Share this post

Link to post
Share on other sites
-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() ).

-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).

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

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!