Texture Alpha Fade

Started by
10 comments, last by Buckeye 13 years, 4 months ago
Hi Guys, how to set a level of transparency gradually ?
as a smoke that will disappear at the end.
example:




Advertisement
Assuming you're using a shader and have parameters set as below, decrease the vertex color alpha over time.
AlphaBlendEnable = true;// alpha blendingSrcBlend     = SrcAlpha;DestBlend    = InvSrcAlpha; ZWriteEnable = false;

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Quote:Original post by Buckeye
Assuming you're using a shader and have parameters set as below, decrease the vertex color alpha over time.
AlphaBlendEnable = true;// alpha blendingSrcBlend     = SrcAlpha;DestBlend    = InvSrcAlpha; ZWriteEnable = false;


but how decrease the color of the vertex ?
For instance linear (pseuso code):
color.a = color.a * max(0, (1 - time / duration));
Where time is the particle's current lifetime (a variable) and duration is the time needed to fully fade out the particle (a constant).
Quote:Original post by unbird
For instance linear (pseuso code):
color.a = color.a * max(0, (1 - time / duration));
Where time is the particle's current lifetime (a variable) and duration is the time needed to fully fade out the particle (a constant).


but how i access the color of the vertex ?
(pseuso code):
   ID3DXMesh*  mesh;   loadXFile(&mesh, "xFile.x");   ........   //configure alpha   ........   g_pDevice->setTexture(0, text);   // how mesh->getColor ??   mesh->DrawSubset(0);


or

struct VERTEX{	enum { FVF = D3DFVF_XYZ | D3DFVF_TEX1 }; //D3DFVF_DIFFUSE 	float px, py, pz;	float tu, tv;};//create the vertexVERTEX vtxBillBoard[4] = { 	{ -1,  0, 0, 0, 1 },	{ -1,  4, 0, 0, 0 },	{  1,  0, 0, 1, 1 },	{  1,  4, 0, 1, 0 }};g_pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, vtxBillBoard, sizeof(VERTEX) );
Try something like this:

struct VERTEX{	enum { FVF = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1 };	float px, py, pz;        DWORD colour;	float tu, tv;};//create the vertexVERTEX vtxBillBoard[4] = { 	{ -1,  0, 0, 0, 0, 1 },	{ -1,  4, 0, 0, 0, 0 },	{  1,  0, 0, 0, 1, 1 },	{  1,  4, 0, 0, 1, 0 }};// Set random alpha value for all vertices// TODO: pick better alpha valuesfor(int i=0; i < 4 ; i++){  vtxBillBoard.colour = D3DCOLOR_ARGB(rand()%256, 0, 0, 0);}g_pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, vtxBillBoard, sizeof(VERTEX) );


You might also find http://msdn.microsoft.com/en-us/library/bb206332%28VS.85%29.aspx useful.
Quote:Original post by Adam_42
Try something like this:

*** Source Snippet Removed ***

You might also find http://msdn.microsoft.com/en-us/library/bb206332%28VS.85%29.aspx useful.


hi, thank, worked, but only changing the color and not the alpha:

for(int i=0; i < 4 ; i++)
{
vtxBillBoard.colour = D3DCOLOR_ARGB(100, rand()%256, rand()%256, rand()%256);
}
why ?
Quote:hi, thank, worked, but only changing the color and not the alpha:

for(int i=0; i < 4 ; i++)
{
vtxBillBoard.colour = D3DCOLOR_ARGB(100, rand()%256, rand()%256, rand()%256);
}
why ?


Look at your code: You're using ARGB and setting .a (alpha) parameter to 100. This means that alpha value will be constant.

Every frame, try changing .a parameter. Like one guy suggested:
for(int i=0; i < 4 ; i++){DWORD a = 255 * max (0, time / duration);vtxBillBoard.colour = D3DCOLOR_ARGB(a, rand()%256, rand()%256, rand()%256);}
There's no "hard", and "the impossible" takes just a little time.
Quote:Original post by programci_84
Quote:hi, thank, worked, but only changing the color and not the alpha:

for(int i=0; i < 4 ; i++)
{
vtxBillBoard.colour = D3DCOLOR_ARGB(100, rand()%256, rand()%256, rand()%256);
}
why ?


Look at your code: You're using ARGB and setting .a (alpha) parameter to 100. This means that alpha value will be constant.

Every frame, try changing .a parameter. Like one guy suggested:
*** Source Snippet Removed ***


sure, I understood, is working perfectly,
but if I change just the alpha does not work, I have to change the color too, regardless if I change the alpha value.
but how I do it in a mesh? (.x File)
Quote:is working perfectly, but if I change just the alpha does not work..

Then it's not doing what you asked about in your original post. The effects you posted pictures for are done by changing the alpha.

Are you trying to get an object that you are drawing to fade into the background?

Do you have alpha blending enabled? Do you have the source and destination blend factors set as mentioned above?

You should post your code for rendering the object.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

This topic is closed to new replies.

Advertisement