OpenGL:启用多重采样会在高缩放级别绘制混乱的多边形边缘

发布于 2024-08-17 11:18:29 字数 739 浏览 4 评论 0原文

当我使用以下代码时:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 6);

然后启用多重采样,我注意到我的程序不再关心最大 mip 级别。

编辑:它也会渲染最后的 miplevels,这就是问题,我不希望它们被渲染。

编辑3: 我测试并确认它根本不会忘记 mip 限制,因此它确实遵循我的 GL_TEXTURE_MAX_LEVEL 设置。 ...所以问题与mipmap无关,我猜...

编辑2:截图,这是世界地图缩小了很多,并使用低角度使效果显示为最糟糕的方式,也地图下方有渲染的水平面,因此不可能从地图纹理以外的任何地方获取黑色像素:

替代文本 http://img511.imageshack.us/img511/6635/multisamplingtexturelim.png

Edit4: 所有这些图片应该看起来像右上角的图片(只是更平滑)边缘取决于多重采样)。但显然我的代码中有一些严重的错误。我必须使用 mipmap,mipmap 不是问题,它们工作得很好。

我做错了什么,或者我该如何解决这个问题?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

晚风撩人 2024-08-24 11:18:29

好的。所以问题毕竟不是 TEXTURE_MAX_LEVEL 。有趣的是,一个简单的测试就帮助解决了这个问题。

我有两种关于 LOD 被不同选择的理论,这两种理论似乎都被纯色测试所推翻。

接下来讨论第三种理论。如果我正确理解你的场景,你有一个使用纹理图集的模型,我们观察到的是,一些应该从图集的特定项目中获取的多边形实际上是从不同的项目中获取的。是这样吗?

这可以通过多重采样片段通常在像素中间采样的事实来解释。即使该中心不在生成样本的三角形内部。有关说明,请参阅此页面的底部。

解决这个问题的常用方法称为质心采样(此页面有很好的插图问题也)。它强制采样将采样点带回三角形内。

现在是坏消息:我不知道有什么方法可以在可编程管道之外打开质心过滤,并且您没有使用它。您认为您想要切换以访问该功能吗?

编辑添加:

此外,不使用纹理图集也是解决此问题的一种方法。它如此明显的原因是因为您开始使用“三角外”采样模式从图集的另一部分获取数据。

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.

另请检查您为 MIN_FILTER 设置的内容:

glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, ... );

尝试不同的设置(列表为 此处)。

但是,如果您对 gluBuild2DMipmaps 的结果不满意,我建议您查看替代方案:

尤其是后者是高度可定制的。没有提到的是,这个扩展是通过将 GL_GENERATE_MIPMAP 设置为 true 来启动的。它是自动的,因此如果数据发生变化,您无需重新计算。

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.

人疚 2024-08-24 11:18:29

您应该通过您的应用程序(而不是nvidia 控制面板,如果您希望渲染始终拥有它。这甚至可能解决你的问题。

至于使用控制面板多重采样时忽略 GL_TEXTURE_MAX_LEVEL 设置,这听起来像是驱动程序错误/功能。这很奇怪,因为此功能可用于限制您在纹理中实际加载的内容(所谓的纹理完整性标准)。如果您根本不加载最低的 mipmap 级别怎么办?渲染什么?

编辑:从您显示的图片来看,它看起来并没有真正忽略该设置。一方面,MAX_LEVEL=0 与 MAX_LEVEL=6 不同。现在,考虑到纹理中的噪点,我什至不明白为什么你的 MAX_LEVEL=6/MS 关闭看起来那么干净。根据 MA​​X_LEVEL=16/MS 关闭图片,它应该有噪声。此时,我建议在漫反射纹理的每个 mip 级别中放置不同的纯色(而不是依赖 GL 来构建 mip),以准确查看您获得的 mip 级别。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文