Search code examples
c++openglmultisampling

OpenGL: Enabling multisampling draws messed up edges for polygons at high zoom levels


When im using this following code:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 6);

and then i enable multisampling, i notice that my program no longer cares about the max mip level.

Edit: It renders the last miplevels as well, that is the problem, i dont want them being rendered.

Edit3: I tested and confirmed that it doesnt forget mip limits at all, so it does follow my GL_TEXTURE_MAX_LEVEL setting. ...So the problem isnt mipmap related, i guess...

Edit2: Screenshots, this is the world map zoomed out a lot and using low angle to make the effect shown the worst possible way, also there is rendered water plane under the map, so theres no possibility to take black pixels from anywhere else than map textures:

alt text http://img511.imageshack.us/img511/6635/multisamplingtexturelim.png

Edit4: All those pics should look like the top right corner pic (just smoother edges depending on multisampling). But apparently theres something horribly wrong in my code. I have to use mipmaps, the mipmaps arent the problem, they work perfectly.

What im doing wrong, or how can i fix this?


Solution

  • Ok. So the problem was not TEXTURE_MAX_LEVEL after all. Funny how a simple test helped figure that out.

    I had 2 theories that were about the LOD being picked differently, and both of those seem to be disproved by the solid color test.

    Onto a third theory then. If I understand correctly your scene, you have a model that's using a texture atlas, and what we're observing is that some polygons that should fetch from a specific item of the atlas actually fetch from a different one. Is that right ?

    This can be explained by the fact that a multisampled fragment usually get sampled at the middle of the pixel. Even when that center is not inside the triangle that generated the sample. See the bottom of this page for an illustration.

    The usual way to get around that is called centroid sampling (this page has nice illustrations of the issue too). It forces the sampling to bring back the sampling point inside the triangle.

    Now the bad news: I'm not aware of any way to turn on centroid filtering outside of the programmable pipeline, and you're not using it. Do you think you want to switch to get access to that feature ?

    Edit to add:

    Also, not using texture atlases would be a way to work around this. The reason it is so visible is because you start fetching from another part of the atlas with the "out-of-triangle" sampling pattern.