When drawing, you can always see the unsightly jagged edges. In particular, the edge of Sawtooth to the user's sense of the sudden, to computer graphics almost a "field" of research-anti-aliasing. Visual aesthetic optimization, as well as improved operating efficiency, both hands are hard. --zwqxin.com
This article is from Zwqxin (http://www.zwqxin.com/), reprint please specify
Original address: http://www.zwqxin.com/archives/opengl/antialiasing-multi-sample-1.html
Aliasing is due to the low screen resolution caused by the pseudo-items, presumably we also know what this means. Csdn a tall man asked, in the graphics card settings there is so-called "anti-aliasing" option, you can set the parameters of the overlay sampling, then in OpenGL also have the corresponding API can do the corresponding settings. I was just beginning to think that the so-called shader anti-aliasing is a full-screen PCF (percent progressive filtering) on the screens, and the OpenGL API has not seen anything that can receive parameters like overlay sampling, At best, the Glhint function can be used to alleviate the aliasing of dots by blending. But then someone replies to say NEHE46 class, I immediately "Awakening", to Oh, Nehe [good OpenGL Tutorial Collection] Indeed there is a class called what "full screen anti-aliasing", immediately find out in the computer to see-there really is.
The so-called sampling parameters, also can be said to be "smooth processing level", generally have 1x,2x,4x,8x,16x these values. In the [Image processing spatial domain Filter] article, talked about the image smoothing (blur), its essence is by a pixel as a neighborhood processing (domain plus average) to derive a new pixel value, the domain size is called the template parameter, is usually an odd number, so that the processing of pixels in the middle. And here the sampling parameters, at first glance is 2 of the n-th square such a number, but stealing that is actually so, but more suitable for the description only.
It is generally assumed that in real-time graphics, this pixel-level operation should be given to powerful shder. The shader is called the dithered samples, which is the PCF coefficient. Because of its programmable performance, the requirements for the graphics card are more resilient, in fact any x can be, not limited to 2 of the n-th side.
To be clear, take an example of the code snippet in the Orange Book about the Shadow map as the PCF chapter (Zwqxin also [Shadow Map Shadow Mapping Technology Ⅲ]):
Listing 13.7. Fragment shader for generating shadows, using four dithered samples uniform Sampler2dshadow shadowmap
;
Uniform float Epsilon;
uniform bool selfshadowed;
Uniform float Selfshadowedval;
Uniform float Nonselfshadowedval;
Varying vec3 Shadowcoord;
float illumination;
Float lookup (float x, float y)
{
Float depth = shadow2d (Shadowmap,
Shadowcoord + vec2 (x, y) * Epsilon). X;
return Depth! = 1.0? illumination:1.0;
}
void Main ()
{
//lighten up the self-shadows
illumination = selfshadowed? Selfshadowedval:nonselfshadowedval;
Use modulo to vary the sample pattern
vec2 o = mod (Floor (GL_FRAGCOORD.XY), 2.0);
float sum = 0.0;
Sum + = lookup (VEC2 ( -1.5, 1.5) + O);
Sum + = lookup (VEC2 (0.5, 1.5) + O);
Sum + = lookup (VEC2 ( -1.5, -0.5) + O);
Sum + = lookup (VEC2 (0.5, -0.5) + O);
Gl_fragcolor = VEC4 (sum * 0.25 * Gl_color.rgb, GL_COLOR.A);
}
You can think of this as a "full screen anti-aliasing" for shadow map-formed aliasing, or "full screen blur", "fullscreen smoothing" (for scenes covered by the Shadow Post). The parameter is 4X. Looking at the bottom lines, it does some of the actions of retrieving textures (shadow maps). Sum is a color counter that adds the values of the four texel around the texel where the pixel is currently processed, and divides the output by 4 to return to the [0,1] interval-a typical template filter operation. Of course there is a little bit of a trick (take a non-integer value and then offset the parity of the texture index by 0 or 1 texel), not much, but the general idea is this-this is the embryonic form of PCF. The color transition of a texture changes only at the edge, while the human eye is always sensitive to the edges, and the blurring at the edges is able to eliminate this sudden feeling.
Well, if this is 4X, then 5x,6x can do so. But 4X and 5X can you think of the difference between the two? Nothing but the latter more stir a texel, if the stir of the texel without the central Texel, you have to decide in which direction to add one. 6X, let alone ... So, the next "level" should be about the central Texel to extend a sheath outward, one more in each direction, that is, 8X .... By analogy, you can see that the "sampling parameters" of a more symmetrical and harmonious "sample parameter" are 2 of the n-th square.
On the other hand, the total can not be infinitely 32x,64x down, to know, each more a "level" of each pixel will have to do one more times the addition, the operation efficiency down, this does not count, the more important is that the whole texture has been dislocation superimposed n times, texture coating finally really blurred to a bloody, not humanoid (hello, It's not going to be--because smoothing is blurred, it's equivalent to the details of the place.
Concept here, go back to the beginning there. The PCF of the apparent Cary. I looked at my video card's Control Panel (NV9), which explained:
Smoothing can be set to help improve system performance or improve image quality.
If you want to display a three-dimensional animation effect and emphasize the smooth transformation of a scene, it's best to use performance settings.
If you want to display very fine and realistic three-dimensional objects as the primary purpose, it is best to use quality settings.
On the Manage 3D Settings page (Advanced view), you can set specific levels of smoothing.
The higher the value, the higher the corresponding smoothing level. For example, 16x is more than 2x in quality.
In the GeForce 8 series GPU, NVIDIA has introduced a new form of smoothing, called "overlay sampling," which affects 8x, 16x, and 16xQ smoothing settings. For more information, please refer to the Nvidia.com website for an introduction to Lumenex engine technology.
If you are not sure how to configure smoothing, use the "Application controlled" option. Your display will be adjusted to your application's requirements.
There are rough setup methods (quality-efficiency tradeoffs):
It is also possible to make a precise setting:
It is indeed possible to set it. So, since the video card provides such a feature, then the corresponding integration API is also very normal. However, after reading NEHE46 class, I know that OpenGL can implement this kind of setup by using an extension called "Multi sample". And also can't one step, need to set a lot of things. I am not sure if it has any special connection with PCF, so I would like to follow Nehe 46来 to realize it.
Please note the next article: Full screen anti-aliasing-Multiple sampling Ⅱ
This article is from Zwqxin (http://www.zwqxin.com/), reprint please specify
Original address: http://www.zwqxin.com/archives/opengl/antialiasing-multi-sample-1.html