PDA

View Full Version : Texture2DMultisample: fetching samples in shader.



sgsrules
01-28-2011, 07:53 PM
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?

Dark Photon
01-29-2011, 06:32 PM
From NV_explicit_multisample (original multisample textures spec, I think):


If the sample number is greater than or equal to the value of SAMPLES for the render buffer associated with the renderbuffer texture, the results are undefined.

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.

sgsrules
01-29-2011, 10:03 PM
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.

arekkusu
01-30-2011, 10:51 AM
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.