Jump to content
  • Advertisement
Sign in to follow this  
Dolf

OpenGL Accumelation buffer

This topic is 3957 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys, I have been teaching myself some OpenGL lately and I have a nice little textured model on my screen. Now I'd like some anti aliasing. I found out there are multiple ways and probably the best (correct me if I am wrong) way is MSAA through that extension. But as an excersice I tried doing it with the accumulation buffer. I really wonder what is going on with that, because it does not seem to work at all. Even if I do something stupid like
//I use double buffer
glClear(GL_ACCUM_BUFFER_BIT);
glReadBuffer(GL_BACK);
glDrawBuffer(GL_BACK);
glAccum(GL_LOAD,1);
glClear(GL_COLOR_BUFFER_BIT);
glAccum(GL_RETURN,0.5f);//picture should be half the brightness, right?


Anyway, so I decided it must be me and I ripped some code from the official opengl guide, and that didnt work. Then I ripped some from some shady website and it didn't work either (listed below).
glClear(GL_ACCUM_BUFFER_BIT);
for(int i=0; i<4; i++)
{
    glPushMatrix();
    glRotated(i * 10., 0, 1, 0);
    //Here I draw
    glPopMatrix();

    glAccum(GL_ACCUM, 0.25);
}

glAccum(GL_RETURN, 1.0);



Now there must be something that I am missing because the OpenGL guide said nothing about this not being implemented on all hardware or something. I also read that it's slow, so should I use it at all? Or is all functionality better to be done with extensions or shaders? Cheers, thanks for the help. Dolf

Share this post


Link to post
Share on other sites
Advertisement
Generally the technique is quite slow, I use this technique for softer shadow edges for a project I'm doing and its about 4 times slower (generally depends on how many steps you take) with good results.

I can't see anything wrong, but your doing a rotate which seems a bit weird to me.

I translate my object a few epilson in each direction then call
glAccum(GL_ACCUM, 1.0f / (steps * steps +1))

and then after I call glAccum(GL_RETURN), I don't believe I use GL_LOAD at all.

I had a good tutorial on Accumulation Buffer or screen space blurring somewhere.
I'll have a look..

neutrinohunter

Share this post


Link to post
Share on other sites
cheers,

the rotate isn't my code, I just ripped it off of a website to see if anything would work.

because I dont get any results from the accumulation buffer.

Share this post


Link to post
Share on other sites
It wouldn't be this site that I was about to refer you to was it? ;)
http://www.cse.msu.edu/~cse872/tutorial5.html

This is code from my shadowing demo, you should be able to remove the unneeded bits and generally hack the code for a solution which will suit your needs

glClear(GL_ACCUM_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

int noOfLights = scene->getLightManager()->getNumberOfLightsUsed();

//Set up Blending
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

//for each light get the position and set up planar
//projection matrix
for(int i = 0; i < noOfLights; i++) {

JVector3D lightPos = scene->getLightManager()->getLight(i)->getPosition();

GLfloat shadMatrix[] = {
lightPos.y, 0.0, 0.0, 0.0,
-lightPos.x, 0.0, -lightPos.z, -1.0,
0.0, 0.0, lightPos.y, 0.0,
0.0, 0.0, 0.0, lightPos.y };

GLfloat dx, dz, step;
dx = -0.1f;
dz = -0.1f;
step = 0.1f;
int numSteps = 2 * -dx / step;
GLuint value = 4;


for (int i = 0; i< numSteps; i++) {
dz+=step;

for (int j = 0; j< numSteps; j++){


dx+=step;
glClear(GL_DEPTH_BUFFER_BIT| GL_STENCIL_BUFFER_BIT);

// Turn off writing to the Color Buffer and Depth Buffer
// We want to draw to the Stencil Buffer only
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
glDepthMask(GL_FALSE);

// Enable the Stencil Buffer
glEnable(GL_STENCIL_TEST);

// Set 1 into the stencil buffer
glStencilFunc(GL_ALWAYS, 1, 0xFFFFFFFF);
glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);

// Turn off writing to the Color Buffer and Depth Buffer
// We want to draw to the Stencil Buffer only
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
glDepthMask(GL_FALSE);

scene->renderInternalProperties();

// Turn on Color Buffer and Depth Buffer
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glDepthMask(GL_TRUE);

// Only write to the Stencil Buffer where 1 is set
glStencilFunc(GL_EQUAL, 1, 0xFFFFFFFF);
// Keep the content of the Stencil Buffer
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);

scene->renderInternalProperties();

glPolygonOffset(bias, offset);
glEnable(GL_POLYGON_OFFSET_FILL);

glDisable(GL_LIGHTING);
glPushMatrix();
glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
glMultMatrixf(shadMatrix);
glTranslatef(dx, 0, dz);
//disable lighting and render shadows

scene->getModelManager()->render(true);
glPopMatrix();
glDisable(GL_STENCIL_TEST);
glDisable(GL_BLEND);
glDisable(GL_POLYGON_OFFSET_FILL);
glEnable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST);

scene->getModelManager()->render();
glAccum(GL_ACCUM, 1.0f/ (numSteps * numSteps +1));

}
} //end sampling
}
//glDisable(GL_BLEND);

glAccum(GL_RETURN, 1.0f);



neutrinohunter

Share this post


Link to post
Share on other sites
I can copy the lines from the tutorial and put them in my program, and I dont see any difference.

I also looked at your example, I dont think it worked here.

Either I'm massively missing out on a major issue (like forgetting a glEnable) or it just doesn't work on this graphics card.

Anyone has any thoughts about this?

Share this post


Link to post
Share on other sites
Whats the graphics card? Running Windows/Linux?

I am pretty sure that the accumulation buffer is pretty standard on GC's but someone else may have a better idea.

Edit: Didn't say whether you were using GLUT or Windows or what not, but you have to specify in either case whether you want to use the Accumulation Buffer. For glut you need a call:

glutInit(GL_ACCUM) or add the GL_ACCUM to the list of arguments to that function, for Windows I think you need to change your values to your PIXELFORMATDESCRIPTOR.

neutrinohunter

Share this post


Link to post
Share on other sites
Hey,

Windows XP with a ATI mobility Radeon X1400.
Not using glut, I create a window myself I enable OpenGL.

I do not know anything about pixeldescriptor settings. I made no changes to the pixeldescriptor I found on a website with the tutorial that explained how to set OpenGL up.

(please tell me what to change because the official opengl guide didnt mention it I believe).

Could u maybe paste your pixeldescriptor ?

Cheers mate, thanks for the help.

Edit: When I look at the #define 's in wingdi.h (got there trough a "go to definition" on the PFD_SUPPORT_OPENGL) I can't see anythign that would enable the accumulation buffer. But I'm obviously wrong :)

Edit 2: Found "cAccumBits" and color bits in the PixelFormatDescriptor struct. I'll try that next time.

Share this post


Link to post
Share on other sites
Yeah awesome great thanks.

It works, I had to specify some bits for the accumulation buffer.

I think the accumulation buffer tutorials should all mention that.

Anyway it works now :)

Now I'll make some nice FSAA and Soft Shadows!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!