Jump to content
  • Advertisement
Sign in to follow this  
renanrosa

Texture Alpha Fade

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

Advertisement
Assuming you're using a shader and have parameters set as below, decrease the vertex color alpha over time.

AlphaBlendEnable = true;
// alpha blending
SrcBlend = SrcAlpha;
DestBlend = InvSrcAlpha;
ZWriteEnable = false;

Share this post


Link to post
Share on other sites
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 blending
SrcBlend = SrcAlpha;
DestBlend = InvSrcAlpha;
ZWriteEnable = false;


but how decrease the color of the vertex ?

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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 vertex
VERTEX 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) );


Share this post


Link to post
Share on other sites
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 vertex
VERTEX 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 values
for(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.

Share this post


Link to post
Share on other sites
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 ?

Share this post


Link to post
Share on other sites
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);
}

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
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.

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!