Jump to content
  • Advertisement
Sign in to follow this  
asafpolt

alpha blending

This topic is 4808 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, i'm trying to write a particle engine for my game. I read that I will need billboarding and alpha-blending to achieve this. I already learned and implemented billboarding using ID3DXSprite interface and its billboarding flag. I noticed that there is another flag that is related somehow to alpha-blending. I also noticed that ID3DXSprite::Draw() takes a color parameter that has something todo with alpha-blending. I believe that there is a way to config the sprite to work with alpha-blending, the thing is I'm not realy sure what alpha blending is... I already read the SDK documentation I could find on the subject, so if anyone knows a good tutorial on alpha blending or can help me with the sprite configuration it would be highly appreciated. Thanks, Asaf Polturak, Israel.

Share this post


Link to post
Share on other sites
Advertisement
Well to answer your question, alpha blending is how opaque an object is. This is usually determined by how light or dark the alpha channel of a texture is. Try getting a texture with an alpha channel and applying it like this:

Device->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
Device->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
Device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
Device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
Device->SetRenderState(D3DRS_ALPHABLENDENABLE, true);

Device->SetTexture(0, YourTextureHere);
(render your object here)

Device->SetRenderState(D3DRS_ALPHABLENDENABLE, false);

That is how you would get an object to have see through parts based on the alpha channel of the texture. However, if you are looking to make a particle engine, you should really use point sprites. There is a good tutorial about them here:

http://www.codesampler.com/dx9src/dx9src_6.htm
here:
http://www.codesampler.com/dx9src/dx9src_7.htm#dx9_particle_system
and here:
http://www.two-kings.de/tutorials/dxgraphics/dxgraphics17.html

-Chris

Share this post


Link to post
Share on other sites
thanks chris, all of this 3 links seem useful.

but just in case I decide to stick with my sprites and not move to point sprites, It would still be helpful if someone will direct me to a relevant place

Share this post


Link to post
Share on other sites
Here are a few more links about ID3DXSprite for you.

http://www.gamedev.net/reference/articles/article1608.asp
http://triplebuffer.devmaster.net/tutorials/stepping3.php

and a thread on the topic here:
http://www.gamedev.net/community/forums/topic.asp?topic_id=318190

-Chris

Share this post


Link to post
Share on other sites
Hey I managed to have some opacity to my sprite, but it wasn't what I expected:

I used the alpha-blending flag in the sprite->begin() method.
in the draw method's color parameter I used D3DCOLOR_RGBA(256,256,256,128).

What I saw was a see-through billboard that didn't resemble the initial texture at all. what am I doing wrong?

Share this post


Link to post
Share on other sites
Hi there asafpolt,
How are you doing?

The Problem
Parameters passed to D3DCOLOR_ARGB() is incorrect

The Solution
This may effect your final result or it may not but just as a side note. The D3DCOLOR_ARGB() macro takes parameters in the range of 0 - 255. You are specifying 256 which is out of bounds ;)

Hope this helps you in the future buddy ;)
Take care.

Share this post


Link to post
Share on other sites
I'm not sure what is exactly your problem, because it's little hard to tell without seeing a screenshot... but anyway, I'll try to help: [smile]

You may want to use additive blending instead of the normal blending mode which is set with the alpha blending flag. To do this, add these lines before sprite drawing code:


device->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
device->SetRenderState(D3DRS_SOURCEBLEND, D3DBLEND_ONE);
device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);


Then draw your sprites without the alpha blending flag.

This method is often used with particle systems, because it makes particles "brighten" each other when they overlap. It looks a lot better than the default blending mode.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!