PDA

View Full Version : accumulation buffer - antialiasing



Floppy29
08-27-2012, 07:43 AM
hello together,

i use the accumulation buffer to get antialiasing for my scene.
but i feel like i doesnt work.

here is my code so far, for the antialiased part,


glClear(GL_ACCUM_BUFFER_BIT);
for(unsigned int i = 0; i < 10; i++) {
for(unsigned int j = 0; i < 10; i++) {
glClear(GL_DEPTH_BUFFER_BIT);
glTranslatef((i * 0.002f) - 0.002f, (j * 0.002f) - 0.002f, 0.0f);

glBindTexture(GL_TEXTURE_2D, space_box); // bind space box texture
glBegin(GL_QUADS);
glNormal3f(0.0f, 0.0f, 1.0f); // space box front; normal vector
glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.5f, -0.5f, 0.5f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.5f, -0.5f, 0.5f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.5f, 0.5f, 0.5f);
glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.5f, 0.5f, 0.5f);

/*glNormal3f(0.0f, 0.0f, -1.0f); // space box back; normal vector
glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.5f, -0.5f, -0.5f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.5f, 0.5f, -0.5f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.5f, 0.5f, -0.5f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.5f, -0.5f, -0.5f);

glNormal3f(0.0f, 1.0f, 0.0f); // space box top; normal vector
glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.5f, 0.5f, -0.5f);
glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.5f, 0.5f, -0.5f);
glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.5f, 0.5f, 0.5f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.5f, 0.5f, 0.5f);

glNormal3f(0.0f, -1.0f, 0.0f); // space box bottom; normal vector
glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.5f, -0.5f, 0.5f);
glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.5f, -0.5f, 0.5f);
glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.5f, -0.5f, -0.5f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.5f, -0.5f, -0.5f);

glNormal3f(1.0f, 0.0f, 0.0f); // space box right; normal vector
glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.5f, -0.5f, 0.5f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.5f, 0.5f, 0.5f);
glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.5f, 0.5f, -0.5f);
glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.5f, -0.5f, -0.5f);

glNormal3f(-1.0f, 0.0f, 0.0f); // space box left; normal vector
glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.5f, -0.5f, 0.5f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.5f, -0.5f, -0.5f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.5f, 0.5f, -0.5f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.5f, 0.5f, 0.5f);*/
glEnd();

glTranslatef(-((i * 0.002f) - 0.002f), -((j * 0.002f) - 0.002f), 0.0f);
glAccum(GL_ACCUM, 1.0f / 100);
}
}
glAccum(GL_RETURN, 1.0f);


how u can see, id draw one quad inside it.
and here a pic of how it looks like,
http://s1.directupload.net/file/d/2995/yg2m58l5_jpg.htm

i hope u can help me and tell me what i did wrong, thanks.

Rosario Leonardi
08-27-2012, 12:23 PM
How did you choose 0.002f? You should cover the whole pixel, not a 1/20th part of it.

Floppy29
08-28-2012, 01:50 AM
It were just a test - value. Id read I have to cover just a part of a pixel.

So, U mean.. it should work 100% with 0.04f?

Rosario Leonardi
08-28-2012, 02:12 PM
Ehm.. wait I was wrong. With +1 you are moving one unit away, so the whole screen in your case.. :D Not good.

You should cover a whole pixel in screen space, so the offset depend on viewport and distance.
I never tried cause it's an old technique but you should modify the W coordinate to achieve a correct result.

Also use better sampling, regular grid give other types of aliasing.

Bwt, with cheap video card with 1GiB of memory why don't you use supersampling? or better technique? Just go on video panel and enable FXAA.

Floppy29
08-29-2012, 02:23 AM
Ah ok, thanks ... it were just a test for me, actuall Im using msaa, GL_MULTISAMPLE.
Maybe I can use later for some blurring. :)

V-man
08-29-2012, 04:11 AM
Bwt, with cheap video card with 1GiB of memory why don't you use supersampling? or better technique? Just go on video panel and enable FXAA.

Or better yet, do it via GL
http://www.opengl.org/wiki/Multisampling