Jump to content
  • Advertisement
Sign in to follow this  
andrew_ww

Applying Alpha to existing material

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

Hello, I'm trying to follow a tutorial on alpha (blending) and I'm having trouble applying the techniques to my own project. The trouble is the example creates a new material which is then applied to the object. My project uses an x file which already has a material applied to it. Can this existing material be modified within directx ? This is the code that is drawing the x fie object: for(int i = 0; i < Mtrls.size(); i++) { Device->SetMaterial( &Mtrls ); Device->SetTexture(0, Textures); Mesh->DrawSubset(i); } and this is code that is from the tutorial: TeapotMtrl = d3d::RED_MTRL; TeapotMtrl.Diffuse.a = 0.5f; // set alpha to 50% opacity Code that draws it: Device->SetMaterial(&TeapotMtrl); Is what I'm trying to do actually possible? Should I create a new material which has no color then run the SetMaterial() function twice? Thanks again.

Share this post


Link to post
Share on other sites
Advertisement
Quote:

Original post by andrew_ww
Can this existing material be modified within directx?


Sure, why not? For example, to modify the first material of the mesh you would write:
Mtrls[0].Diffuse.a = 0.5f;
Of course, you'll probably want to do this for all the mesh's materials.

Share this post


Link to post
Share on other sites
Unless all the materials are the same in the mesh, you want to call SetMaterial() before each DrawSubset() call (same thing goes for textures). How you set the material values is up to you.

Note that if you're using the pipeline to draw, i believe you need to set the ambient.a as well as the diffuse.a for transparency to work (and of course have the render states etc. set up right).

Also note that your transparent subsets are gonna be rendered in the order they appear in the .x file unless you manually sort them back to front (which will result in incorrect ordered alpha blending in some cases).

-programmer_tom

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!