PDA

View Full Version : Parallel-planes within semi-transparent volume



strorph
03-08-2012, 11:36 PM
Hi all,

I've been racking my head over this problem. I'm drawing a volume mesh with a semi-transparency, and I get an odd effect at a certain angle when the volume is rotated: parallel planes are visible within the volume mesh. To add, the semi-transparency isn't entirely consistent at different angles. The attached screen may better describe the issue. Of note, this effect does not show up when there is no transparency (i.e. when the surface is opaque).

http://i.imgur.com/6Byoe.jpg

Here's the relevant source code:

glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);

glEnable(GL_DEPTH_TEST);
glEnable(GL_NORMALIZE);
glShadeModel(GL_SMOOTH);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

// draw mesh
glDepthMask(GL_FALSE);
glPushMatrix();
mc->draw();
glPopMatrix();
glDepthMask(GL_TRUE);

glDisable(GL_NORMALIZE);
glDisable(GL_BLEND);
glDisable(GL_COLOR_MATERIAL);
glDisable(GL_LIGHTING);
glDisable(GL_DEPTH_TEST);

Thanks for any advice!
s.

ZbuffeR
03-09-2012, 12:28 AM
Depth testing does not work with blending.

The classic way is to change the planes in order to keep them roughly facing the camera, and back to front. With 4 possible orientations it should be ok.

strorph
03-09-2012, 09:32 AM
Thanks for the quick reply ZbuffeR.
How would I go about controlling/changing the orientation of these planes? The ones showing up in my volume just 'appear' upon rotation (oriented in the xy-plane).

ZbuffeR
03-09-2012, 02:49 PM
Ah sorry I completely misread your post ; I imagined that you were doing volume rendering, using a stack of parallel planes, like this :
http://paulbourke.net/miscellaneous/glvol/

You are rendering a simple shell, no actual volume right ?
You pic actually looks like like severe z-fighting, can be caused by lack of depth buffer precision.
A few typical causes :
- having near and far planes too far away with a perspective projection (show your related code). Worst being near plane at 0 distance... Try to pack more tightly around the actual near and far values you really need.
- not having a depth buffer in the first place. Check how you create the GL window, verify you ask for and get a depth buffer with 24 bits of precision

strorph
03-09-2012, 05:37 PM
Yeah you're right, I'm drawing a shell basically -- I realize I was unclear.

I'm investigating whether it's z-fighting that's the issue, but I also wanted to mention that as the resolution of the mesh is improved (the vertex spacing are decreased), the distance between these 'parallel planes' is decreased proportionally.

As per your suggestions, I squeezed the near and far planes without much success, and I do have a depth buffer active.

These planes within the shell are perpendicular to the initial camera position (camera is on z-axis, planes are in xy), and will only appear when I have rotated such that I parallel (or close to parallel) to the xy-plane.

ZbuffeR
03-10-2012, 01:57 AM
Well what I said earlier still holds : depth testing does not work with blending. In your case with a convex object it is easier, but you have to render front faces only:

glEnable(GL_CULL_FACE); /// to avoid drawing back faces.

strorph
03-10-2012, 02:11 PM
Awesome. Enabling culling seems to have resolved the issue.
Thanks!