Archived

This topic is now archived and is closed to further replies.

mictian

particles and depth testing???

Recommended Posts

hail, in my particle system ( as well as in others i have studied ) depth testing is disabled to allow all particles to render and blend properly... i want to render particles but i want them to be occluded by objects in the foreground, how can i accomplish this?

Share this post


Link to post
Share on other sites
when you render your room/terrain take the particle system as an entire entity. Then drawing from the back forward. When you reach your particle system, render it with depth test disabled, then continue drawing objects closer.

the simplist way to do this is to do a distance check on objects in your scene (quite CPU expensive).

it would help if i knew what rendering technique you''re using and what you are rendering. BSP, Portal, ? and Terrain, Indoors, ?

Share this post


Link to post
Share on other sites
Hello,

a really good way is to disable z writes when rendering the particles. This way the particles are occluded by near objects, because of depth test, but they don't occlude farther objects, because the z values aren't stored.

Ciao, Thorris.

EDIT: correctness

[edited by - Thorris on August 14, 2003 5:50:43 AM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster


The suggestion above will work. Generally you will want to render your opaque objects first with z-testing and z-writing on. Then you can turn off z-writing and render your transparent elements from a depth sorted list.

Share this post


Link to post
Share on other sites
yup, wat the AP said is a proper way to do it. Remember, disabling depth-testing and disabling depth-writing are two different thing. Just in case (to be safe), here''s a brief rundown.

Depth-testing, i''m sure u know, is all about z-buffer usage. Without that, the z-buffer is completely disabled. Thus all objects will be displayed in order of rendering, irrespective of their position in the virtual scene.

Depth-writing is the current state of the z-buffer. By default it is enabled and thats how objects in front write over previous values IF the data in the z-buffer contains more ''distant'' objects. By disabling z-writing, any new objects will still be tested for depth accuracy and wont be drawn in the color buffer if they fail. But if they succeed, rendering will occur BUT these new objects will not update the existing state of the z-buffer.

Share this post


Link to post
Share on other sites
The OpenGL command to enable/disable depth writing glDepthMask(true/false). Also remember: If you use additive blending like glBlendFunc(GL_SRC_ALPHA, GL_ONE) you do not need to sort your particles back to front. With all the other blending equations you will need to sort the particles.

Sander Maréchal
[Lone Wolves Game Development][RoboBlast][Articles][GD Emporium][Webdesign][E-mail]


GSACP: GameDev Society Against Crap Posting
To join: Put these lines in your signature and don''t post crap!

Share this post


Link to post
Share on other sites
thankyou all for your responses.

i have obtained the desired effect by a simple bubble sort to order all particles for back->front rendering. i render them last after other objects and with depth testing turned on, so as to allow other objects in the scene to occlude them, depth writing is also turned on, but due to the order of rendering it makes no difference.

i also do use additive blending as you mentioned, but sorting is in this case necessary as i left depth testing on

Share this post


Link to post
Share on other sites
i would also me much obliged if you could tell me what fps you get from running my demo which is here:

http://people.umass.edu/rwhall/particle_demo.exe

( it is from the same workspace as an earlier demo, and i forgot to remove the check for the cubemapping extension, so if you have an old gpu it might give you an error about that )

i got 80fps on my 2.4ghz p4, but my friend on his athlon 1.2 got only 20 ( same GPU ), so i am wondering whether i need to optimize way more ( there is _plenty_ to be done...did i mention i bubble sorted heheheh ) also there is no occluder in this demo as i removed the metaballs, so the sort is not really necessary

Share this post


Link to post
Share on other sites
why would I test your demo for performance, when you say it''s not done yet? How about finishing your demo, and THEN let people test it?

Share this post


Link to post
Share on other sites
yeah thats true i suppose...just wondering how bad this section actually is though, i got a few of my friends to do it and they reported 40-50 on some old school-ish pentiums so i guess i am happy

Share this post


Link to post
Share on other sites
If you use depthmasking you can make it a lot faster. Bubblesort will slow you down, especially if the number of particles increases. Just:

- render scene
- enable depthmask
- render particles
- disable depthmask
- swap buffers

Sander Maréchal
[Lone Wolves Game Development][RoboBlast][Articles][GD Emporium][Webdesign][E-mail]


GSACP: GameDev Society Against Crap Posting
To join: Put these lines in your signature and don''t post crap!

Share this post


Link to post
Share on other sites