Skip to main content
gamedev.net
🔒 Locked

Particles

Started by dpadam450 Sep 20, 2006 at 1:24 AM 5 replies 1k views
Original Post
dpadam450
dpadam450
I am currently drawing particles as quads with a mask texture, and then the actual texture over it. The only problem is that this way I have to disable the depth test. What way should I do it? glDisable(GL_DEPTH_TEST); glEnable(GL_BLEND); glBlendFunc(GL_DST_COLOR, GL_ZERO); glBindTexture(GL_TEXTURE_2D, texture[8]); //Draw the mask here glBlendFunc(GL_ONE, GL_ONE); glBindTexture(GL_TEXTURE_2D, texture[9]); //Draw the actual particle here
NBA2K, Madden, Maneater, Killing Floor, Sims 
zedzeek
zedzeek
forget about masks theyre so 1980/90s
normally the method u use is stick the 'how much of the pixel u want to show through' info in the alpha channel of the texture and enable alphatest or blending.
much faster/flexible/easier
Morpheus011
Morpheus011
usually we want to disable depth tests when rendering particles. If we have to depth test every particle the performance of the system will take a fairly significant hit, especially for larger particle systems, this is why in many games you can see certain effects through the terrain/buildings/etc.

zedzeek is absolutely right though, in general the texture you are using for the particle should contain the mask itself, then we simply have to set the blending mode appropriately and we get the desired effect.

enable blending first by calling glEnable(GL_BLEND); then set the blending operation with a call to glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); This is the most common usage of the blend func and will work very well for particle textures with a black background used as the baked in mask.
dpadam450
dpadam450
Actually I modified my code and it works fine. I was draw 20 squares and the problem with drawing was that there would be a slight z-fight. But no particle in general will have the same rotation and position (meaning more than a row of pixels shouldnt be fighting for a z value. So I'm actually fine with my code now. Should have just changed the values in the first place so that they dont overlap so much.

What it looks like.


[Edited by - dpadam450 on September 20, 2006 10:55:55 PM]
NBA2K, Madden, Maneater, Killing Floor, Sims 
Morpheus011
Morpheus011
if you disable depth testing, z-fighting becomes irrelevant :)
dpadam450
dpadam450
Must not have copied the "//" with the Disable() :)
NBA2K, Madden, Maneater, Killing Floor, Sims 

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.