Jump to content
  • Advertisement
Sign in to follow this  

[mdx] Fading out meshes

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

Hi, I have several meshes that I'd like to have fade out (to transparent) in my managed direct 3d game. I can't seem to find out how to do this :) My draw function for my mesh class looks like this: public void Draw() { for (int i = 0; i < materials.Length; i++) { device.Material = materials; device.SetTexture(0, textures); mesh.DrawSubset(i); } } I'd like to have something like: Draw(float percentageTransparent) { // code... } Any ideas?

Share this post

Link to post
Share on other sites
i believe i once had a problem similar to this...
the thing is, directx mesh objects dont come with a colour variable in their vertex definition. this means you need to create a FVF with a value for colour and assign it to all loaded meshes.
now while this may seem like a fair bit of work just to get a colour tinge on your meshes, its worth it [wink].

first off you need to declare the FVF you're going to use:

or something to that effect. in case you're not familiar, D3DFVF_XYZ means the structure your vertices will use contains x, y and z values (positions...), D3DFVF_DIFFUSE is the one that specifies a colour value and D3DFVF_TEX1 gives room for 1 set of texture coordinates.

next you need a struct that will be used for each vertex's information:

typedef struct CUSTOMVERTEX {
float x, y, z;
DWORD colour;
float tu, tv;

this has variables corresponding to the FVF that was specified before (position, colour then texture coordinates).

so far so good, eh? now comes the tricky part - like i said before you need to tell every mesh object to use this format (D3DFVF_VERTEX) so that you can give colour to them.
im going to assume you use D3DXLoadMeshFromX or something similar to load meshes and to get their pointers.
here's how i went about applying this FVF:

LPD3DXMESH tempmesh = NULL;
LPD3DXMESH finalmesh = NULL;
LPDIRECT3DDEVICE9 pd3ddev; //initialised device


this takes the loaded mesh (tempmesh) and "clones" it but with the FVF supplied - D3DFVF_VERTEX - then it outputs a pointer to a new mesh (finalmesh).
now the mesh thats loaded will have a colour variable in its vertex definition. to use this you need to lock the vertex buffer for the mesh and manually change all colour values for each vertex:

colour = D3DCOLOR_ARGB(alpha,red,green,blue);


for (int i = 0; i < mesh->GetNumVertices(); ++i)
verts.colour = colour;


this assigns the value "colour" to all vertices in the mesh "mesh". now when you render your mesh it should be with the colour value that you specify. this means that if you have textures, the colour will be applied over the top; so for no colour change to be applied, make the "colour" value = ARGB(255,255,255,255) or white.
as for your question, if you want transparency in percentage youd do something like this:
colour = D3DCOLOR_ARGB(alpha/100.0*255,255,255,255);

where "alpha" is a value between 0 and 100 representing a percent of visibility (0% meaning totally transparent).

hope that all helps! [smile]

[Edited by - the_moo on May 23, 2006 8:40:30 PM]

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!