Pergunta

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.

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top