PDA

View Full Version : Bug with multipass to overcome z-fighting. solved



Oldschool
03-30-2008, 02:23 AM
Greetings, I've recently been working on a space-scene, and figured the solution to my z-fighting problems would be solved nicely with multipassing.
However, I have some weird bugs.

As it is now, I render the stuff furthest away first, reset the znear/zfar, and then render closer stuff, in 3 passes.

I have two problems I'm not sure why are happening, and how to fix.

1: Objects rendered in later pass (Which are closer) are visually appearing behind objects in the distance.
(I figured that was because I did not clear the z-buffer, but the problem remains even after I do (or, try))

2: When an object is hitting the z-near, the parts of the object too close, is not rendered, so it looks like the planet is "cut" up a piece.
For some reason, the closest part of the planet is not rendered when a later pass, which should include the "missing" piece is run.

Even if I try to have the closer planes "overlap" slightly too, the bug remains.


glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60, (windowSizeW / windowSizeH), 90000000, 1000000000000);
glMatrixMode(GL_MODELVIEW);
sceneroot.render();
glClearDepth(1.0);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60, (windowSizeW / windowSizeH), 9000, 100000000);
glMatrixMode(GL_MODELVIEW);
sceneroot.render();
glClearDepth(1.0);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60, (windowSizeW / windowSizeH), .1, 10000);
glMatrixMode(GL_MODELVIEW);
sceneroot.render();


I dont have a nice place to put a screenshot at the moment, but I'll try to find one if that would be helpful.

Thanks in advance for any help/suggestions for what might fix it.

--Edit--
Figured out what was wrong.
For those with a similar problem in the future, my problem was that "glClearDepth(1.0);" did not behave as I thought.
The solution was to use "glClear(GL_DEPTH_BUFFER_BIT);" instead.