Depth Testing Problem

Started by
2 comments, last by plates 22 years, 3 months ago
if (planet[loop].atmos_phere != 0) { glEnable(GL_BLEND); glDisable(GL_DEPTH_TEST); glBindTexture(GL_TEXTURE_2D, bmptexture[planet[loop].atmos_texid]); DrawSphere(planet[loop].radius + 0.05f, 32, 32); glEnable(GL_DEPTH_TEST); glDisable(GL_BLEND); } The bit of code is used to draw a sphere surrounding another sphere (For an atmosphere on a planet), then map a texture to it, - The problem is the planet sphere is depth tested correctly, but the atmosphere sphere isn''t, and consequently the atmosphere sphere shows up behind the planets (specifically the sun) as it rotates around it. I''ve tried every order of DEPTH TESTING statements, but I can''t seem to get it right - the ones above seem, in my mind anyway, logically correct. If someone could point out what exactly I am doing wrong, would be fantastic. Many Thanks Plates.
Advertisement
you can''t disable depth_test. once you do all pixels will be drawn no matter if they are behind something or not. While drawing transparent areas you should do like this:
1.draw all non-transparent areas
2.sort the transparent triangles from back to front
3.draw them according to this order with z-write turned off. (but depth testing turned on!)

good luck

PS.the back to front sorting is neccessary for achieving good quality images, but you can try to skip it, because you''re scene is a special case and it might look good even without this sort


With best regards,
Mirek Czerwiñski
http://kris.top.pl/~kherin/
With best regards, Mirek Czerwiñski
I don't know much OpenGL, but it's the same with all graphics API's. It is impossible to use a depth buffer to correctly render translucent objects, such as your atmosphere. The only correct solution that works in all cases, is to manually sort your translucent polygons in order of depth, and then render from furthest to nearest.

However, there's one better solution in the case of your atmosphere, taking advantage of the fact that your rendering a sphere shape. You can first disable he depth buffer. Then render all the polygons facing away from the camera using culling (I assume OpenGL can do this for you, like DirectX?). Then render the polygons facing towards the camera, again using culling. Voila! A perfect sphere! If you're rendering many spheres inside each other as in your atmosphere, then render from outside to inside first, change the culling mode, and then from inside to outside.

Edited by - bazee on January 1, 2002 6:07:17 PM
Right, erm , I still don''t understand totally what you mean, I''ve posted my Code & exe on http://www.sigmat.demon.co.uk/planets.zip - You need to read the readme.txt first before you run it tho. Anyway, as you will see when Uranus goes behind the sun, atmosphere is still rendered. Any help (code specific espeically) as always greatly appearicted.

Plates.

This topic is closed to new replies.

Advertisement