Setting amount of blend in d3d

Started by
6 comments, last by MatuX 23 years ago
Is there a way of setting the amount of blending used in d3d? I mean, like making an animation of an object that goes from invisible to fully visible, and at the same time it blends all the time with the background. Dunno if I explained myself correctly... Thanks
Advertisement
I''ve never used d3d, but normally, when you want to do something like that, you use the fourth color component: the alpha channel, which is basically how transparent a color is. Alpha is usually described between 0.0 and 1.0, where 1.0 is fully opaque. To simulate an object materializing from thin air, you can start with an alpha value of 0.0 and gradually add values until you get to 1.0.
G''day!

The basic blending bit:
// enable alpha blending
lpdevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
// set the source to the texture''s alpha channel
lpdevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
// set the destination to 1- that.
lpdevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);

Then if your object is textured:
Set your ALPHAOP to MODULATE, ALPHAARG1 to D3DTA_TEXTURE and ALPHAARG2 to D3DTA_DIFFUSE . Then to fade it out change the alpha component of each vertex to the desired level.

If not textured, set ALPHAOP to SELECTARG1 and ALPHAARG1 to DIFFUSE and leave ARG2 blank.


Stay Casual,

Ken
Drunken Hyena
Stay Casual,KenDrunken Hyena
You may also want to take a look at setting your D3DTSS_COLOROP to D3DTOP_BLENDFACTORALPHA and then modifying the D3DRS_TEXTUREFACTOR render state. I think this will allow you to fade an object without actually touching the vertex or texture data.

...Syzygy
Thanks guys, I will test it at once
Drunken:

I cannot find any alpha component on the D3DVertex thingy...

Syzygy:

Setting D3DTSS_COLOROP to D3DTOP_BLENDFACTORALPHA completely messes up all my scene..

Thanks for the help though, guys

BTW, did I mention I''m using DX7?
Hmmm, I''m not sure what exactly is happening to completely mess up your scene -- I''d have to see the code to figure anything out for sure. One thought, though: You want to make sure that you only modify the TextureStageStates and RenderStates when you render the one object that you want to fade. If you leave them set for the rendering of all of your objects then they will all be blended.

Hope this helps.
...Syzygy
G''day!

quote:Original post by MatuX
Drunken:

I cannot find any alpha component on the D3DVertex thingy...


It''s part of the diffuse colour. When you set your colour you give it a DWORD laid out like: 0xAARRGGBB

quote:
Syzygy:

Setting D3DTSS_COLOROP to D3DTOP_BLENDFACTORALPHA completely messes up all my scene..


I know (in theory) that the texture factor is supposed to be a better/faster way to go, but I''ve never played with it myself so I didn''t recommend it. I prefer to have some clue what I''m talking about on occasion.

I should have a look at it though, can be handy.


Stay Casual,

Ken
Drunken Hyena
Stay Casual,KenDrunken Hyena

This topic is closed to new replies.

Advertisement