• Advertisement
Sign in to follow this  

[Assimp DX] Loss of Ambient Color (the alpha channel)

Recommended Posts

Upon importing models from assimp to DX9,

I always loose the ambient alpha channel.

Here is the code of assimp which is responsible for importing the materials

if (scene->HasMaterials())
    {
        for (int m = 0; m < scene->mNumMaterials; m++)
        {
            materials newMat;
            aiMaterial* mat = scene->mMaterials[m];
            D3DMATERIAL9 l_mat;
            CComPtr<IDirect3DTexture9> newTexture;
            aiColor4D diffuse_col, ambient_col, specular_col, emissive_col;
            aiGetMaterialColor(mat,AI_MATKEY_COLOR_DIFFUSE,&diffuse_col);
            aiGetMaterialColor(mat,AI_MATKEY_COLOR_AMBIENT,&ambient_col);
            aiGetMaterialColor(mat,AI_MATKEY_COLOR_SPECULAR, &specular_col);
            aiGetMaterialColor(mat,AI_MATKEY_COLOR_EMISSIVE, &emissive_col);
            // TODO: Get Specular Power
            l_mat.Diffuse = Assimp_Col_To_DX(diffuse_col);
            l_mat.Ambient = Assimp_Col_To_DX(ambient_col);
            l_mat.Emissive = Assimp_Col_To_DX(emissive_col);
            l_mat.Specular = Assimp_Col_To_DX(specular_col);
            l_mat.Power = 0.5f;
            
            float shininess;
            float strength;
            unsigned int max = 1;
            aiReturn ret1, ret2;
            ret1 = aiGetMaterialFloatArray(mat, AI_MATKEY_SHININESS, &shininess, &max);
            if(ret1 == AI_SUCCESS) {
                max = 1;
                ret2 = aiGetMaterialFloatArray(mat, AI_MATKEY_SHININESS_STRENGTH, &strength, &max);
                if(ret2 == AI_SUCCESS)
                    l_mat.Power = shininess * strength;
                else
                    l_mat.Power = shininess;
            }
            else {
                //glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 0.0f);
                //set_float4(c, 0.0f, 0.0f, 0.0f, 0.0f);
                //glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, c);
                l_mat.Power = 0.0f;
            }

            for(int i=0;i<mat->GetTextureCount(aiTextureType_DIFFUSE);i++)
            {
                aiString str;
                mat->GetTexture(aiTextureType_DIFFUSE,i,&str);
                textureData tmp;
                newTexture=loadTexture(str.C_Str());
                tmp.type=0;
                newMat.textures.push_back(newTexture);
                
            }

            newMat.material = l_mat;

            m_mats.insert(std::make_pair(m, newMat));
        }
    }
D3DXCOLOR Assimp_Col_To_DX(const aiColor4D& l_col)
{
    D3DXCOLOR newColor;
    newColor.r = l_col.r;
    newColor.g = l_col.g;
    newColor.b = l_col.b;
    newColor.a = l_col.a;
    return newColor;
}

And here is the result I got from DX9... The models looks blacky.

Import thru D3DXLoadMeshHierarchyFromX

Name: Body01
mat#: 0
Diffuse= r:0.717647 0.615686 0.533333 1
Ambient= r:0 0 0 1
Specular=r:0 0 0 1
Emissive=r:0 0 0 1
Power: 10
mat#: 1
Diffuse= r:0.105882 0.333333 0.545098 1
Ambient= r:0 0 0 1
Specular=r:0 0 0 1
Emissive=r:0 0 0 1
Power: 10
mat#: 2
Diffuse= r:0.580392 0.517647 0.419608 1
Ambient= r:0 0 0 1
Specular=r:0 0 0 1
Emissive=r:0 0 0 1
Power: 10

Importing thru assimp, notice the ambient alpha has been changed from 1 to 0

Name:
mat#: 0
Diffuse= r:0.717647 0.615686 0.533333 1
Ambient= r:0 0 0 0
Specular=r:0 0 0 1
Emissive=r:0 0 0 1
Power: 10
Name:
mat#: 0
Diffuse= r:0.105882 0.333333 0.545098 1
Ambient= r:0 0 0 0
Specular=r:0 0 0 1
Emissive=r:0 0 0 1
Power: 10
Name:
mat#: 0
Diffuse= r:0.580392 0.517647 0.419608 1
Ambient= r:0 0 0 0
Specular=r:0 0 0 1
Emissive=r:0 0 0 1
Power: 10

Why is this happening...

I don't think I've changed the materials anywhere else.

Does anyone have a clue?

Thanks

Jack

Edited by lucky6969b

Share this post


Link to post
Share on other sites
Advertisement

Maybe Assimp just fails to load the ambient color, have you checked if those calls to aiGetMaterialColor return AI_SUCCESS?

Share this post


Link to post
Share on other sites

I don't know. But I found out that the X file format (D3DX) has no ambient color channel.....

So probably assimp just make one up for me.

Thanks

Jack

Share this post


Link to post
Share on other sites

The documentation says that it doesn't modify the passed variable if the color isn't found, so you can just put up your own default values for the colors before trying to get them.

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  

  • Advertisement