我选择的GLFW_SAMPLES实际上做了什么? [英] What does my choice of GLFW_SAMPLES actually do?

查看:329
本文介绍了我选择的GLFW_SAMPLES实际上做了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

设置这个变量是做什么的?例如,如果我将它设置为4,那是什么意思?

我阅读了glfw.org上的描述(请参阅: GLFW Window Guide )下的Framebuffer相关提示部分。该手册说:GLFW_SAMPLES指定了用于多重采样的所需样本数量,零禁用多重采样,GLFW_DONT_CARE表示应用程序没有偏好。

我也读了一般的多重采样的描述(请看这里:多重采样由肖恩哈格里夫斯)。



我对于多重采样意味着什么:对图像进行大小调整和重新绘制时,用于重绘图像的点数应该足够接近,以便我们看到是图像的准确表示。数字示波器也会出现同样的想法---比如说你正在采样一个正弦信号。如果采样率恰好等于波的频率(f),示波器将显示一个恒定的电压,这与您希望看到的输入信号大不相同。为了避免这一点,奈奎斯特定理告诉我们,我们应该以至少2f的速率进行采样。所以我看到在计算机图形学中如何出现问题,但我不知道这个函数到底是什么

glfwWindowHint(GLFW_SAMPLES,4);


解决方案


设置这个变量是做什么的?例如,如果我将它设置为4,那意味着什么?


GLFW_SAMPLES 用于启用多重采样。因此 glfwWindowHint(GLFW_SAMPLES,4)是一种启用4x
<4 x MSAA意味着窗口缓冲区的每个像素都由4个子采样组成,这意味着每个像素由可以这么说。因此,尺寸为200x100像素的缓冲区实际上是800x400像素。如果您要创建一个额外的帧缓冲区,是屏幕的4倍。然后使用它作为纹理采样器,使用 GL_LINEAR 作为过滤器,将基本达到相同的结果。 请注意,这仅仅是4x MSAA的情况,因为 GL_LINEAR 只需要4个最接近相关像素的样本。



说到抗锯齿,那么使用MSAA是一个非常有效但昂贵的解决方案。如果你想要一个非常干净和好看的结果,那肯定是要走的路。通常会选择4x MSAA,因为在使用质量和性能之间有很好的平衡。

性能方面更便宜的选择是使用 FXAA 。这是作为后处理步骤完成的,通常是免费的。不同之处在于MSAA呈现更大的尺寸,下采样到想要的尺寸,而不会失去任何质量。 FXAA只是简单地对像素进行平均处理,基本上使图像模糊。 FXAA通常会给出一个非常好的结果。



另外,您的驱动程序很可能会在默认情况下启用它。但如果它不使用 glEnable(GL_MULTISAMPLE)






最后,如果你还没有,那么我强烈推荐阅读 LearnOpenGL的反锯齿教程。它对这一切给出了一个非常深入的解释。


What does setting this variable do? For instance, if I set it to 4, what does that mean?

I read a description on glfw.org (see here: GLFW Window Guide) under the "Framebuffer related hints" section. The manual says "GLFW_SAMPLES specifies the desired number of samples to use for multisampling. Zero disables multisampling. GLFW_DONT_CARE means the application has no preference."

I also read a description of multisampling in general (see here: Multisampling by Shawn Hargreaves).

I have a rough idea of what multisampling means: when resizing and redrawing an image, the number of points used to redraw the image should be close enough together that what we see is an accurate representation of the image. The same idea pops up with digital oscilloscopes---say you're sampling a sinusoidal signal. If the sampling rate just so happens to be exactly equal to the frequency (f) of the wave, the scope displays a constant voltage, which is much different than the input signal you're hoping to see. To avoid that, the Nyquist Theorem tells us that we should sample at a rate of at least 2f. So I see how a problem can arise in computer graphics, but I don't know what exactly the function

glfwWindowHint(GLFW_SAMPLES, 4); does.

解决方案

What does setting this variable do? For instance, if I set it to 4, what does that mean?

GLFW_SAMPLES is used to enable multisampling. So glfwWindowHint(GLFW_SAMPLES, 4) is a way to enable 4x MSAA in your application.

4x MSAA means that each pixel of the window's buffer consists of 4 subsamples, which means that each pixel consists of 4 pixels so to speak. Thus a buffer with the size of 200x100 pixels would actually be 800x400 pixels.


If you were to create an additional framebuffer that is 4 times bigger than the screen. Then using it as a texture sampler with GL_LINEAR as the filter, would basically achieve the same result. Note that this is only the case for 4x MSAA, as GL_LINEAR only takes 4 samples closest to the pixel in question.

When it comes to anti-aliasing, then using MSAA is a really effective but expensive solution. If you want a very clean and good looking result, then it's definitely the way to go. 4x MSAA is usually chosen as there's a good balance between quality and performance using it.

The cheaper alternative in terms of performance is to use FXAA. Which is done as a post-processing step and usually comes at no cost. The difference is that MSAA renders at a bigger size and downsamples to to the wanted size, not loosing any quality. Where as FXAA simply averages the pixels as is, basically bluring the image. FXAA usually gives a really decent result.

Also your driver will most likely enables it by default. But if it doesn't then use glEnable(GL_MULTISAMPLE).


Lastly if you haven't already, then I highly recommend reading LearnOpenGL's Anti-Aliasing tutorial. It gives a really in-depth explanation of all of this.

这篇关于我选择的GLFW_SAMPLES实际上做了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆