glsl with anti-aliasing

Started by
4 comments, last by Yann L 13 years, 1 month ago
When use the shader, especially the frag to render scene, it draw pixel by pixel, how to apply anti-aliasing in a shader?
after reading the orange book, chapter 17, I got nothing understand...
what exactly does the fwidth function return?

Thanks in adav~
Advertisement
Look up multisampling glEnable(GL_MULTISAMPLE), you need to request a multi sample buffer at startup as you do for a depth/color buffer.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

Thanks
Do you mean if I just use the regular way to render the secen and do post operation in the shader, there is no way to do the antialiasing?
BTW, does the fwidth function have any relationship with the multisample?


Look up multisampling glEnable(GL_MULTISAMPLE), you need to request a multi sample buffer at startup as you do for a depth/color buffer.
http://www.opengl.org/wiki/Multisampling
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
Multisampling is done in the hardware, you don't do anything except enable it. Does not matter if you run a shader or not.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

I typed a long and detailed reply to this, only to have the new forums swallow it. Gah.

In short: I think the OP wants to anti-alias his (possibly procedural) shaders. Typical multisampling doesn't help here, as it will only invoke a shader once per pixel, regardless of coverage samples. You'll need to manually AA your shader using partial derivatives and/or estimate filter width over a sub-pixel area (ddx, ddy, fwidth, etc). fwidth returns the sum of the absolute partial derivatives in x and y of the specified varying at the current location.

There's also ARB_sample_shading, which more or less brute-forces this automatically, to some extend (if your HW supports it).

Both approaches will typically have a large impact on performance.

This topic is closed to new replies.

Advertisement