Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why are integer UV coordinates needed for fetching multisampled texture

when sampling a multisampled texture, we have to use integer coordinates, i.e

ivec2 Texcoord = ivec2(textureSize(texsampler) * In.Texcoord);
vec4 color = texelFetch(texsampler, Texcoord, i);  //i = sample, Texcoord is integer 

instead of

vec4 color = texture(texsampler, txcooord);  //txcoord is float between [0,1]

Why do we need exacty integer coordinates that map to every texel? Why cant my UV coordinates be float between 0.0 to 1.0. I am guessing this is related to the way a multisampled texture is stored in memory. But the whole idea is a little fuzzy to me.

I have seen a similar question here: Multisample texture sampling, but its not what I am looking for.

like image 383
viktorzeid Avatar asked Mar 14 '26 20:03

viktorzeid


1 Answers

What would be the point of using normalized values here? Filtering between texels is not allowed for multisample textures, as filtering doesn't make sense when a texel can have multiple values. Since you can only access specific texels, and specific samples within those texels, they figured there's no harm in forcing you to be specific about exactly which texel you want.

Could they have allowed normalized values? Sure. You can do that yourself like this:

vec4 textureMS(in sampler2DMS tex, in vec2 texCoord, in int sampleIx)
{
  ivec2 textureSize = textureSize(tex);
  ivec2 texelCoords = ivec2(textureSize * clamp(texCoord, 0.0, 1.0));
  return texelFetch(tex, texelCoords, sampleIx);
}

But that requires the implementation to provide the texture's size, which probably means passing it as an internal uniform or something. That just makes things take longer. Since you can do it yourself reasonably easily, they only provided the fast way. That way, people who can use the fast way don't accidentally get trapped by the slow way.

like image 121
Nicol Bolas Avatar answered Mar 16 '26 13:03

Nicol Bolas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!