Sign in to follow this  
TechnoCore

Renderstates for smoke

Recommended Posts

TechnoCore    122
Im having troube comming up with the renderstates for smoke in my particle engine, using directx 9. All I can manage to get, is either dark and blocky smoke, or nicelooking alpha blended but additive light smoke. I want it to be dark, like when oil is burning. Can someone help me ? /TC :)

Share this post


Link to post
Share on other sites
Mezz    571
Hmm, something in the back of my brain says SRC_ALPHA, INV_SRC_ALPHA is what you want, but you will probably need to depth sort your smoke particles to make it work.

-Mezz

Share this post


Link to post
Share on other sites
SpreeTree    396
Try a subtractive blend, which should do the opposite of additive blending (the more particles you have, the blacker the patch of smoke). This might give you the effect your looking for, so you may as well give it a try.

I think subtractive is applied by using D3DBLEND_ZERO, D3DBLEND_INVSRCCOLOR, but I cant be sure as I am away from a code machine at the moment.

Spree

Share this post


Link to post
Share on other sites
TechnoCore    122
SpreeTree: Seems like its working! (D3DBLEND_ZERO, D3DBLEND_INVSRCCOLOR) get e nice dark smoke. Though they are popping out of existance... but i guess its just this particular effect that doesn't blend the particles towards 0 alfa.

Gotta try it some more.

Mezz: Sort particles? Oh lord... that will be painful.

thanks!
/T

Share this post


Link to post
Share on other sites
PouncingAnt    133
D3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_DESTCOLOR ); D3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);

(Using a greyscale bitmap that had a gradient of white -> black from the outside edge to the middle)

These are the states I used. I happened to have the source in front of me when I read the forum topic ;)

Yeah, I needed to do some ordering with it. Though I found that using D3DBLEND_ZERO as the source blend was a complete disaster. Hope this is of some help.

Also, if anyone could spare a few moments of thought: My method of using sprites goes completely to shambles if I try using fog ;) Any hints, anyone?

Share this post


Link to post
Share on other sites
TechnoCore    122
PouncingAnt:

I just tried this now:
m_textureStateCache->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ZERO );
m_textureStateCache->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCCOLOR );

with a texture gradient black->lightlight from outside to centre.
As far as i can see it works, (without sorting)

Im gonna look a bit more at it... maybe i will have problems somewhere...

thanks!
/T

Share this post


Link to post
Share on other sites
PouncingAnt    133
ah, so I'm using the wrong gradient with the wrong blending :) I'll try your technique right away!

EDIT: Yeap. Works like a dream.. However, my fog still doesnt like it. *resumes testing*

EDIT2: Thanks again for the correct blending technique! I can disable fog and make my sprites more invisible the further away they are. Shoulda thought of that instantly, really.

[Edited by - PouncingAnt on July 19, 2005 9:56:04 AM]

Share this post


Link to post
Share on other sites
ReaVeR-Andrey    199
In order to display transparent objects correctly they should be sorted: first to be drawn are those farther away from the viewer.
Imagine a situation: you're drawing a big transparent object nearby and a small object a bit further ( ar any situation where nearer object is transparent partially occludes farter object ). If you draw the big object first, it will fill the z-buffer with correct values. Then the second object will not be visible at all because of the z-buffer.

Share this post


Link to post
Share on other sites
TechnoCore    122
PouncingAnt: Glad it works !
ReaVeR-Andrey: Yes i finally saw that, but since my game is more or less top-down rts-style, it took me a while to see that.

Thanks all
// TC

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this