Jump to content

  • Log In with Google      Sign In   
  • Create Account


hlsl Gather vs Sample, SM5.0


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 zero_t98   Members   -  Reputation: 130

Like
0Likes
Like

Posted 08 February 2012 - 04:21 PM

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;
}

Sponsor:

#2 TiagoCosta   Crossbones+   -  Reputation: 1912

Like
0Likes
Like

Posted 08 February 2012 - 05:22 PM

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.
Tiago Costa
Aqua Engine - my DirectX 11 game "engine" - In development




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS