[color=#1C2837][size=2][color=#000000]float4 [color=#660066]PhongDirLtTexPS[color=#666600]([color=#000000]float3 normalW [color=#666600]:[color=#000000] TEXCOORD0[color=#666600],[color=#000000] float3 toEyeW [color=#666600]:[color=#000000] TEXCOORD1[color=#666600],[color=#000000] float2 tex0 [color=#666600]:[color=#000000] TEXCOORD2[color=#666600])[color=#000000] [color=#666600]:[color=#000000] COLOR
[color=#666600]{[color=#000000]
[color=#000000] ....
[color=#000088]return[color=#000000] float4[color=#666600]([color=#000000]color[color=#666600],[color=#000000] gMtrl[color=#666600].[color=#000000]diffuse[color=#666600].[color=#000000]a[color=#666600]);[color=#000000] [color=#880000]// 1.0f[color=#000000]
[color=#666600]}[color=#000000]
Your pixel shader outputs individual fragments. In your shader code, the alpha is coming from "[color=#1C2837][font=CourierNew, monospace][size=2][color=#000000]gMtrl[color=#666600].[color=#000000]diffuse[color=#666600].[color=#000000]a", which you seem to assume to be 1.0 (?).[/font]
[color=#1C2837][font=CourierNew, monospace][size=2][color=#000000]
[/font]
[color=#1C2837][font=CourierNew, monospace][size=2][color=#000000]Basically, if you put 1.0f instead of "[/font][color=#1C2837][font=CourierNew, monospace][size=2][color=#000000]gMtrl[color=#666600].[color=#000000]diffuse[color=#666600].[color=#000000]a" you are saying that all pixels are fully opaque. So no object should go missing when alphablending is enabled.[/font]
Cheers!
Alpha Channel makes opaque objects disappear
Hmmm..... At first blush, the 1.0 doesn't mean anything.. I just commented out the original code.... According to the debugger, the materials were actually correct, as you see in the pictures
Sorry for the misleading comment.....
Thanks very much
Jack
Sorry for the misleading comment.....
Thanks very much
Jack
[color=#1C2837][size=2]"- also, keep in mind that alpha transparency is draw order dependent procedure. "
[color=#1C2837][size=2]
[color=#1C2837][size=2]Sorry I didn't notice your pictures.
[color=#1C2837][size=2]
[color=#1C2837][size=2]- How about trying to draw the opaque meshes first
[color=#1C2837][size=2]- and the draw the alpha blended meshes
[color=#1C2837][size=2]
[color=#1C2837][size=2]Cheers!
[color=#1C2837][size=2]
[color=#1C2837][size=2]Sorry I didn't notice your pictures.
[color=#1C2837][size=2]
[color=#1C2837][size=2]- How about trying to draw the opaque meshes first
[color=#1C2837][size=2]- and the draw the alpha blended meshes
[color=#1C2837][size=2]
[color=#1C2837][size=2]Cheers!
Yes, I get your point. That's also the problem I have. As the mesh (the main object) is opaque in some parts, and some of them are transparent.
I am not sure how to display them apart.
Thanks... have fun
Jack
I am not sure how to display them apart.
Thanks... have fun
Jack
Hi,
Do you have one big mesh or lots of different meshes?
If you have one big mesh, try to draw first the opaque parts. Something like " if (mtrl.[font=CourierNew, monospace][size=2]ambient.a == 1.0f)Render()"[/font]
After that, draw it again with a different rule " if (mtrl.[font=CourierNew, monospace][size=2]ambient.a < 1.0f)Render()"[/font]
Without seeing your drawing code I can't give more precise hint.
Cheers!
Do you have one big mesh or lots of different meshes?
If you have one big mesh, try to draw first the opaque parts. Something like " if (mtrl.[font=CourierNew, monospace][size=2]ambient.a == 1.0f)Render()"[/font]
After that, draw it again with a different rule " if (mtrl.[font=CourierNew, monospace][size=2]ambient.a < 1.0f)Render()"[/font]
Without seeing your drawing code I can't give more precise hint.
Cheers!
The warehouse is one big mesh, some parts of it has alpha value less than 1.0, others objects include the trucks and the counter balances and the pallets in yellow
Here is how I load the mesh
Here is how I render the static objects
Thanks
Jack
Here is how I load the mesh
void CMesh::LoadMesh(TCHAR *filename....)
{
D3DXLoadMeshFromX(filename, D3DXMESH_SYSTEMMEM, pDevice,
&adjBuffer, &mtrlBuffer, NULL, &numMtrls, &meshSys);
D3DVERTEXELEMENT9 elems[MAX_FVF_DECL_SIZE];
meshSys->GetDeclaration(elems);
bool hasNormals = false;
D3DVERTEXELEMENT9 term = D3DDECL_END();
for(int i = 0; i < MAX_FVF_DECL_SIZE; ++i)
{
// Did we reach D3DDECL_END() {0xFF,0,D3DDECLTYPE_UNUSED, 0,0,0}?
if(elems.Stream == 0xff )
break;
if( elems.Type == D3DDECLTYPE_FLOAT3 &&
elems.Usage == D3DDECLUSAGE_NORMAL &&
elems.UsageIndex == 0 )
{
hasNormals = true;
break;
}
}
// Step 3: Change vertex format to VertexPNT.
D3DVERTEXELEMENT9 elements[64];
UINT numElements = 0;
VertexPNT::Decl->GetDeclaration(elements, &numElements);
ID3DXMesh* temp = 0;
meshSys->CloneMesh(D3DXMESH_SYSTEMMEM | D3DXMESH_32BIT,
elements, pDevice, &temp);
ReleaseCOM(meshSys);
meshSys = temp;
// Step 4: If the mesh did not have normals, generate them.
if( hasNormals == false)
D3DXComputeNormals(meshSys, 0);
// Step 5: Optimize the mesh.
meshSys->Optimize(D3DXMESH_MANAGED |
D3DXMESHOPT_COMPACT | D3DXMESHOPT_ATTRSORT | D3DXMESHOPT_VERTEXCACHE,
(DWORD*)adjBuffer->GetBufferPointer(), 0, 0, 0, &mMesh);
ReleaseCOM(meshSys); // Done w/ system mesh.
ReleaseCOM(adjBuffer); // Done with buffer.
// Step 6: Extract the materials and load the textures.
attTable = new D3DXATTRIBUTERANGE[numMtrls];
mMesh->GetAttributeTable(attTable, &m_cAttributes);
if( mtrlBuffer != 0 && numMtrls != 0 )
{
D3DXMATERIAL* d3dxmtrls = (D3DXMATERIAL*)mtrlBuffer->GetBufferPointer();
for(DWORD i = 0; i < numMtrls; ++i)
{
// Save the ith material. Note that the MatD3D property does not have an ambient
// value set when its loaded, so just set it to the diffuse value.
Mtrl m;
m.ambient = d3dxmtrls.MatD3D.Diffuse; //Diffuse;
m.diffuse = d3dxmtrls.MatD3D.Diffuse;
m.spec = d3dxmtrls.MatD3D.Specular;
m.specPower = d3dxmtrls.MatD3D.Power;
mMtrl.push_back( m );
// Check if the ith material has an associative texture
if( d3dxmtrls.pTextureFilename != 0 )
{
// Yes, load the texture for the ith subset
IDirect3DTexture9* tex = 0;
char* texFN = d3dxmtrls.pTextureFilename;
D3DXCreateTextureFromFile(pDevice, texFN, &tex);
// Save the loaded texture
mTex.push_back( tex );
}
else
{
// No texture for the ith subset
mTex.push_back( 0 );
}
}
}
ReleaseCOM(mtrlBuffer); // done w/ buffer
}
Here is how I render the static objects
void CStaticObject::RenderStaticMesh()
{
mFX->SetMatrix(mhWVP, &(m_matWorld*g_View*g_Proj));
D3DXMATRIX worldInvTrans;
D3DXMatrixInverse(&worldInvTrans, 0, &m_matWorld);
D3DXMatrixTranspose(&worldInvTrans, &worldInvTrans);
mFX->SetMatrix(mhWorldInvTrans, &worldInvTrans);
mFX->SetMatrix(mhWorld, &m_matWorld);
mFX->SetTechnique(mhTech);
UINT numPasses = 0;
mFX->Begin(&numPasses,0);
mFX->BeginPass(0);
for (int j = 0; j < m_pMesh->m_cAttributes; ++j)
{
int mtrlIndex = m_pMesh->attTable[j].AttribId;
Mtrl m = m_pMesh->GetMaterial()[mtrlIndex];
mFX->SetValue(mhMtrl, &m, sizeof(Mtrl));
if (m_pMesh->GetTexture()[j] != 0)
{
mFX->SetTexture(mhTex, m_pMesh->GetTexture()[j]);
}
else
{
;
}
mFX->CommitChanges();
m_pMesh->GetMesh()->DrawSubset(j);
}
mFX->EndPass();
mFX->End();
}
Thanks
Jack
Yes, I get your point. That's also the problem I have. As the mesh (the main object) is opaque in some parts, and some of them are transparent.
I am not sure how to display them apart.
Thanks... have fun
Jack
It will be different subsets then, each subset has a different material, so the transparent subsets and opaque subsets will be separated.
That means that you'll have to for example go from rendering mesh by mesh (while for each mesh you iterate all its subsets) to some sort of a render queue where each entry is a subset of some mesh. You will be also able to sort the queue by materials (by shaders, textures, whatever) which could improve your performance a bit as you can minimise your shader and texture changes. When rendering mesh by mesh you're basically just sorting by a world transform.
I think the StateManager DirectX SDK sample has quite nice "engine" that does that.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement