Archived

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

Alpha blending question...(DX8)

This topic is 6003 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

I am having a bit of trouble understanding alpha blending. I understand what it does, but I cant figure out how to do it. I have a texture that is faded from black to white, and I want to make the black transparent. I also don''t want to use additive alpha blending, just regular blending (so when I have several blended objects over eachother it doesn''t turn white). How would this be done?

Share this post


Link to post
Share on other sites
Check out drunkenhyenas tutorials at
http://www.drunkenhyena.com/docs/d3d8/dhGrayScale.phtml

this one explaines how to turn a greyscale image to an alpha channel.

And use modulate instead of adding for alphas.

Possibility

Share this post


Link to post
Share on other sites
I am afraid thats not quite what I am looking for. I just want to take a standard image (eg - bitmap, jpg, etc) and blend away the black without having to read through each pixel of the image (something like the pointsprite demo on the SDK). I know this is possible, I just don''t know the render states and texture stage states.

Share this post


Link to post
Share on other sites
Sorry, I think you will have to examine each pixel in the image no matter what...however, this (not to sure what your talking about...)maight beable to be done through hardware...not sure. but you will always need to find the value of the pixel before doing an operation on it or skipping over it otherwise tyou won''t get the results you''re lokking for.

Share this post


Link to post
Share on other sites
I know it can be done with the right renderstates/texture stage states. I know this can be done because I have done it before with pointsprites. I tried to copy the exact renderstates/texture stage states but it didn't work (go ahead, call me dumb). When I figure it out I will be sure to post how to do it up here.

I would also like to figure out how to specify an amount to blend by instead of using the alpha part of the vertex color. That is quite possible, isn't it?

To err is human. To really foul things up requires a computer.

Edited by - Moe on June 29, 2001 12:16:40 AM

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
can''t ya just use color keying? you just want to make black (0,0,0) transparent, right?

Share this post


Link to post
Share on other sites
No, I am not just trying to colorkey. I am trying to blend the darker colors so they are more transparent. Take a look at the Poinsprites sample in the SDK. The bitmap it loads in is faded from black to the orange color in the middle, and the black is blended out so there is no sharp edge between the orange and background.

Share this post


Link to post
Share on other sites
I think you can achieve what you want by setting

SetTextureStageState 0, D3DTSS_SRCBLEND, D3DBLEND_SRCCOLOR
SetTextureStageState 0, D3DTSS_DESTBLEND, D3DBLEND_INVSRCCOLOR

Basically, that tells DX to take the color''s intensity as the alpha.

Share this post


Link to post
Share on other sites
I think thats what I am after, but is it possible to do it without having an alpha value in the souce image, or do I need to load that texture in as a file type that has and alpha value?

Share this post


Link to post
Share on other sites
What file formats are there that include alpha information? I mean ones that can be loaded by the d3d8x library?

Edited by - zennehoy on July 2, 2001 1:29:09 PM

Share this post


Link to post
Share on other sites
quote:
Original post by Moe
No, I am not just trying to colorkey. I am trying to blend the darker colors so they are more transparent. Take a look at the Poinsprites sample in the SDK. The bitmap it loads in is faded from black to the orange color in the middle, and the black is blended out so there is no sharp edge between the orange and background.


The pointsprites demo in the SDK uses:
g_d3d_device->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_ONE);
g_d3d_device->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_ONE);



Stay Casual,

Ken
Drunken Hyena

Share this post


Link to post
Share on other sites
Yes, but that uses additive alpha blending, doesn''t it? I want to do the same thing except make it so that they don''t go so bright when they cross eachother, like rocket smoke from Q3A.

Share this post


Link to post
Share on other sites
When you load the data into your semi-transparent texture, you need to set each pixel''s alpha value, whether it''s built into the original file or a seperate alpha mask file. You could just use a greyscale bitmap perhaps for the alpha.

Then set your renderstates (D3DRS_ALPHABLENDENABLE, D3DRS_SRCBLEND, and D3DRS_DESTBLEND) to what you desire (may require a bit of trial and error) and away you go.

Share this post


Link to post
Share on other sites