views:

498

answers:

3

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

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?

A: 

You should enable multi-sampling through your application, not the nvidia control panel, if you want your rendering to always have it. That might even fix your issue.

As for the GL_TEXTURE_MAX_LEVEL setting being ignored when using the control panel multisampling, it sounds like a driver bug/feature. It's weird because this feature can be used to limit what you actually load in the texture (the so-called texture completeness criteria). What if you don't load the lowest mipmap levels at all ? What gets rendered ?

Edit: From the picture you're showing, it does not really look like it ignores the setting. For one thing, MAX_LEVEL=0 is different from MAX_LEVEL=6. Now, considering the noise in your textures, I don't even get why your MAX_LEVEL=6/MS off looks that clean. It should be noisy based on the MAX_LEVEL=16/MS off picture. At this point, I'd advise to put distinct solid colors in each mip level of your diffuse texture (and not rely on GL to build your mips), to see exactly which mip levels you're getting.

Bahbar
i generate the miplevels by gluBuild2DMipmaps() function. i can see it renders the miplevels that i dont want, because the color changes in the last miplevels because of blending of pixels.
well, try to load mipmaps manually instead, and don't load all of them. There is no way to tell gluBuild2DMipmaps to not load the levels, so don't use it to do the debugging. You don't even have to really load mipmaps. Just use GL_TEXTURE_MAX_LEVEL=0
Bahbar
when i use GL_TEXTURE_MAX_LEVEL=0, i still see ugly textures, now there is not only black pixels, but white/black pixels present, only at low angles though, but straight at top-down it looks normal. without multisampling the textures are rendered correctly.
How about some pictures ? "ugly" does not mean much.
Bahbar
updated the first post.
"I don't even get why your MAX_LEVEL=6/MS off looks that clean", because the tile textures are padded.
Hum, that does not explain it though. If it were that homogeneous at level 6, then it would stay homogeneous at smaller mips. Did you try loading solid color mips ?
Bahbar
nope, i dont see a reason to do that, it wont fix any problems
Well, too bad. I've got a couple theories that this test could help confirm/infirm. I guess I'll let you handle it with reasons you can see.
Bahbar
i tested now, it does follow the MAX_LEVEL, cant see other mip levels than that... :/ now you can tell your theories.
+1  A: 

Check also what have you set for the MIN_FILTER:

glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, ... );

Try the different settings ( a list is here ).

However, if you're dissatisfied with the results of gluBuild2DMipmaps I advise you to look at alternatives:

Especially the latter is highly customizable. And what was not mentioned, this extension is fired up by setting GL_GENERATE_MIPMAP to true. It is automatical so you don't need to do recalculation if data changes.

Kornel Kisielewicz
my min_filter is GL_LINEAR_MIPMAP_LINEAR as it should be. why GL_GENERATE_MIPMAP isnt enough for me? why use external libs for this? i cant see any difference between gluBuild2DMipmaps() and GL_GENERATE_MIPMAP, just the speed.
why did someone vote this up o.o? this is not the right answer...
A: 

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.

Bahbar
if i dont use texture atlas, i would have to bind over 200000 textures in sequence (1000-4000 unique). and that will make huge lag-fest for some cards (probably for any card). i cant use centroid sampling yet because i dont know anything about shaders yet, so i will just forget about this smooth polygon edges thing... unless there are other ways to smooth polygons?
Well, supersampling, rather than multisampling, would do the job. But its rendering cost usually makes it impractical (does 4x the pixel math).
Bahbar