D3D Alpha Blending

Started by
7 comments, last by Freeride Designs 23 years, 10 months ago
Right, I''ve got alpha blending working in D3D, and I use the D3D_BLENDONE on destAlpha and srcAlpha flags to set the type of alpha blending, but I want to be able to change the amount of blending between the src and dest. eg. I want the dest to only blend with 25% of the src. So how do I change the alpha value? Thanks for any help
----------------
Black Edge Games
----------------
Advertisement
I change the emissive.a (alpha) component of the material in use. But the texture may have a alpha channel and you can joy with this.


-eng3d.softhome.net-
-----------------------------------------------"Cuando se es peon, la unica salida es la revolución"
In addition to the blending functions set with:

m_pD3DDev->SetRenderState(D3DRENDERSTATE_SRCBLEND, ?);
m_pD3DDev->SetRenderState(D3DRENDERSTATE_DESTBLEND, ?);

you also need to set how the alpha is computed for the rendered polygon. And that is done with:

m_pD3DDev->SetTextureStageState(0, D3DTSS_ALPHAOP, ?);
m_pD3DDev->SetTextureStageState(0, D3DTSS_ALPHAARG1, ?);
m_pD3DDev->SetTextureStageState(0, D3DTSS_ALPHAARG2, ?);

I suggest you read up on those functions in the docs. There you''ll find numerous of ways to do the alpha computation you want.

- WitchLord

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Thanks witchlord, I''ve got it now.
I don''t know what this forum would do without you helping everybody
----------------
Black Edge Games
----------------
It would probably do alright, it just might take a little longer before the right answers come.

- WitchLord

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

I''ve got a question that doesn''t seem to far off topic, so here goes... Let''s say I have a texture that I want to have some percent of alpha blending like Freeride Designs was looking for, but I also want a color to be totally clear. I am talking about something similar to DirectDraw''s color keys. How is this accomplished? I think I read somewhere that something called Alpha Testing is used. Is this on the right track?

Thanks,
->Briar LoDeran
quote:Original post by BriarLoDeran

I''ve got a question that doesn''t seem to far off topic, so here goes... Let''s say I have a texture that I want to have some percent of alpha blending like Freeride Designs was looking for, but I also want a color to be totally clear. I am talking about something similar to DirectDraw''s color keys. How is this accomplished? I think I read somewhere that something called Alpha Testing is used. Is this on the right track?

Thanks,
->Briar LoDeran


When you load the texture, load it using 1555 or 5551 format if possible. Then set the color you don''t want to have an alpha of 0. Set the texture state to include D3DTOP_MODULATE, and use the diffuse alpha to change the other alpha. If you need some more help (I understand this is confusing, as it took me awhile to understand, plus I just can''t explain things that well), I have some code if you want.

Nytegard:

Yeah, that is a little confusing... . I would appreciate it if you would elaborate a little more.

->Briar LoDeran
Sorry if the following code doesn't print out correctly.

It's late, and I've been struggling trying to get some other stuff done, so my brain is kind of dead right now.

First, don't use the bitmap loader (loadbitmap() or something like that. Haven't used it in awhile).

Load the bitmap into the direct draw structure yourself.

For that, there are plenty of tutorials here and on the web.
Actually, load the bitmap into an array or something similar where you insert the alpha value every 4th byte.
(A zero if you want the pixel to be clear, or a one if you want it to show)

Set the format to 1555 or 5551. A way to do this is to set the masks, although this will cause problems in the future. But for the time being, don't worry about it.
(A correct way will be to enumerate the 1555 texture format and select that).

ddpixel->dwRGBAlphaBitMask=0x8000;
ddpixel->dwRBitMask=0x7c00;
ddpixel->dwGBitMask=0x03e0;
ddpixel->dwBBitMask=0x001f;
ddpixel->dwFlags/=DDPF_ALPHAPIXELS;

Then load the array into the directdraw surface.

When you initialize directdraw, include:

/*Multiplies the two alpha arguments*/
d3dDevice->SetTextureStageState
(0,D3DTSS_ALPHAOP,D3DTOP_MODULATE);
/*sets the first alpha argument as the texture alpha, aka the 1 bit to determine whether the pixel is clear or shows*/
d3dDevice->SetTextureStageState(0,D3DTSS_ALPHAARG1,D3DTA_TEXTURE);
/*sets the second argument as diffuse alpha*/
d3dDevice->SetTextureStageState(0,D3DTSS_ALPHAARG2,D3DTA_DIFFUSE);
/*Sets the alpha value that will not be drawn. Usually best to include this, and always set the value above 0x01 because of precision.*/
d3dDevice->SetRenderState(D3DRENDERSTATE_ALPHAREF,0x08);
d3dDevice->SetRenderState(D3DRENDERSTATE_ALPHAFUNC,D3DCMP_GREATEREQUAL);

Now, set the materials alpha

mtrl.diffuse.a = 0.4f;

When you draw the texture, remember to include:

d3dDevice->SetRenderState(D3DRENDERSTATE_ALPHATESTENABLE, TRUE);
d3dDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE,TRUE);

(Also, remember to turn these false when you don't need them).

If you still need help, I think I have a simple program that uses what you are looking for here.

Edited by - Nytegard on May 29, 2000 5:33:49 PM

This topic is closed to new replies.

Advertisement