Texture2DMultisample: fetching samples in shader

Hi, I’m using Texture2DMultisample to perform full screen anti aliaising. Everything works perfectly but i have one question. What happens when i fetch more samples than i actually have in the buffer? Here’s the shader code that i use to resolve the msaa buffer.


#version 330
in vec2 texCoordIn;
uniform sampler2DMS color;
uniform int samples;
out vec4 fragColor;
float div= 1.0/samples;
void main()
{
 fragColor = vec4(0.0);
 ivec2 texcoord = ivec2(textureSize(color) * texCoordIn);
 for (int i=0;i<samples;i++)
 {
  fragColor += texelFetch(color, texcoord, i);
 }
 fragColor*= div;
}

Lets say i create a multi sampled buffer with only 4 samples but in my shader i set the number of samples to 16. It still works and i get 0 errors. Changing the number of samples in my shader from 4 to 16 even though my buffer only has 4 samples actually look somewhat smoother. What’s actually going on here? Where is it getting these extra samples from?

From NV_explicit_multisample (original multisample textures spec, I think):

Didn’t find mention of this anyplace else (ARB_texture_multisample or GL spec, but maybe I missed it). Nevertheless, the behavior is probably the same.

thanks dp, after playing around with it a bit it looks like the tex coordinates get offset to the next texel when the sample number is greater than the samples in the buffer.

And if sample number is “2 billion”, then…?

This is the sort of “undefined” behavior that has to become defined if ARB_robustness is ever to work.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.