Jump to content
  • Advertisement
Sign in to follow this  
Garra

Direct3D Transparency

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

I'm working on a project using Direct3D. I have a array of objects declared as ghost G[20]. What i'm trying to accomplish is make it so the 20 object fade in and out. The function i'm using to do this is below, however right now it's set up so if the alpha is 0.3 then change it to 0 for testing purposes. tarGhost is the ghost i want to change transparency on, index is the index of the ghost. I need the index because i have a array of 20 materials called ghostMat, this is declared in the private section of my class.


void ghost::fadeGhost(ghost tarGhost, int index)
{
if (tarGhost.ghostMat[index].Diffuse.a == 0.3f)
{
tarGhost.ghostMat[index].Diffuse.a = 0.0f;
}

//if (tarGhost.ghostMat[index].Diffuse.a <= 0)
//{
// tarGhost.ghostMat[index].Diffuse.a = 0;
//}
}



in my main game loop i call the function like so:

for (int i = 0; i < 20; i++)
{
G.moveGhost();
G.draw(device, i);

//===============================
G.fadeGhost(G, i);
//===============================

}




The program acts as if the comparison is never made, so the transparency never changes and is always set to 0.3f (which is the initial value for the alpha).

Share this post


Link to post
Share on other sites
Advertisement
Alternately, try something like:

if( diffuse.a <= 0.3f ) ...

As Molle85 implies, a == comparison between floats or doubles is asking for trouble. Remember, those float values are converted to and compared as binary numbers. Decimal numbers such as 0.3 can't be converted exactly to binary.

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!