• ### Popular Now

• 13
• 10
• 27
• 9
• 9

This topic is 2665 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi Guys, how to set a level of transparency gradually ?
as a smoke that will disappear at the end.
example:

##### Share on other sites
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;

##### Share on other sites
Quote:
 Original post by BuckeyeAssuming 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 ?

##### 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 on other sites
Quote:
 Original post by unbirdFor 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) );

##### 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 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.

##### Share on other sites
Quote:
 Original post by Adam_42Try 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 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 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 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.