Sign in to follow this  
Garra

Direct3D Transparency

Recommended Posts

Garra    103
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[i].moveGhost();
G[i].draw(device, i);

//===============================
G[i].fadeGhost(G[i], 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
Buckeye    10747
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this