Hi,
When I enable alpha channel, some opaque objects gone missing
m_pDevice->SetRenderState (D3DRS_ALPHABLENDENABLE, true);
m_pDevice->SetRenderState (D3DRS_ZENABLE, true);
when I turn off the depth buffer, everything appears in the scene
but transparency was lost.
I have optimized the mesh with Optimize( ATTRSORT....
And using an attribute table, The materials buffer should be correct, otherwise the main object won't appear
when I disable z-buffer.
Any thoughts.. (Post pics later)
Thanks
Jack
Alpha blending has no effect on z buffer. So if a transparent face is in front of something solid but is drawn before it in the rendering, the solid object wont be drawn. Is this maybe your problem? When I've written rendering code before that uses alpha transparency, I've done the rendering in 2 passes, first of all the solid stuff then the transparent.
Hi,
When I enable alpha channel, some opaque objects gone missing
m_pDevice->SetRenderState (D3DRS_ALPHABLENDENABLE, true);
m_pDevice->SetRenderState (D3DRS_ZENABLE, true);
when I turn off the depth buffer, everything appears in the scene
but transparency was lost.
I have optimized the mesh with Optimize( ATTRSORT....
And using an attribute table, The materials buffer should be correct, otherwise the main object won't appear
when I disable z-buffer.
Any thoughts.. (Post pics later)
Thanks
Jack
These opaque objects disappearing don't happen to have alpha component in their texture or perhaps the material values contain zero alpha values?
- basically you should turn on alpha blending just for objects requiring it. So "global" alpha blend enable for every object isn't good approach.
- also, keep in mind that alpha transparency is draw order dependent procedure.
I took a quick look in your code and I got impression that you are mixing fixed function pipeline stuff and effect stuff. Are you using vertex/pixel shaders?
My knowledge of the old SetRenderState functions start to get rusty, but "[font=CourierNew, monospace][size=2]D3DCMP_FORCE_DWORD" flag is definetely wrong. You seem to use it in several occasions. It is a enum for the compilers. [/font][font=CourierNew, monospace][size=2]However, it shouldn't have significance here or anywhere. [/font]
[font=CourierNew, monospace][size=2]
[/font]
[font=CourierNew, monospace][size=2]
[/font]
[font=CourierNew, monospace][size=2][color=#1C2837][font=arial, verdana, tahoma, sans-serif][color=#000000]m_pDevice[color=#666600]->[color=#660066]SetRenderState[color=#666600]([color=#000000] D3DRS_DIFFUSEMATERIALSOURCE[color=#666600],[color=#000000] D3DMCS_MATERIAL [color=#666600]);[/font][/font]
[font=CourierNew, monospace][size=2]
[/font]
[font=CourierNew, monospace][size=2]The above line doesn't have meaning unless you set [/font]D3DRS_COLORVERTEX to true.
[font="'Segoe UI"]As you said, it is a mess. Especially if you mix effect files and shaders with ffp processing. Can you show more code perhaps? Show some shaders?[/font]
[font="'Segoe UI"]
[/font]
[font="'Segoe UI"]Cheers![/font]
// Get the texture color.
float4 texColor = tex2D(TexS, tex0);
// Combine the color from lighting with the texture color.
//float3 color = (ambient + diffuse)*texColor.rgb + spec;
// float3 color = (ambient + diffuse) + spec;
float3 color = (ambient + diffuse);
// if (texColor != 0) {
// color = gMtrl.diffuse*texColor.rgb;
// }
// Sum all the terms together and copy over the diffuse alpha.
// float3 outcolor = color.rgb * 0.5f;
//return float4(color, gMtrl.diffuse.a*texColor.a);
return float4(color, gMtrl.diffuse.a);
}
technique PhongDirLtTexTech
{
pass P0
{
// Specify the vertex and pixel shader associated with this pass.
vertexShader = compile vs_2_0 PhongDirLtTexVS();
pixelShader = compile ps_2_0 PhongDirLtTexPS();
}
}
Here are the pics. I enable and disable z-buffering in these 2 trials
http://img220.imageshack.us/i/beforeh.png/
http://img217.imageshack.us/i/afteruo.png/
Thanks
Jack
I took another quick look to your code and the lines below are "no no" when using vertex/pixel shaders, although they shouldn't matter
[color=#1C2837][size=2][color=#000000]m_pDevice[color=#666600]->[color=#660066]SetRenderState[color=#666600]([color=#000000]D3DRS_LIGHTING[color=#666600],[color=#000000] [color=#000088]true[color=#666600]);[color=#000000]
m_pDevice[color=#666600]->[color=#660066]LightEnable[color=#666600]([color=#000000]DIRECTIONAL[color=#666600],[color=#000000] [color=#000088]true[color=#666600]);
Also, you are setting sampler states in your code and you also define a sampler in the shader code.
I'd get rid most of the SetRenderStates and move what's necessary to your fx-file.
What you can test is to manually set the alpha value in your shader output and then try the alphablending.
I don't see you setting your gMtrl value anywhere in the code.
Hi,
Thanks for your help first. Really appreciate it
I actually set gMtrl inside the render method
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));
.....
I am not sure how to set individual pixels to alpha (is that what you meant?) to the mesh
because the mesh is a large chunk by itself. Could you please give me more hints on that?
Thanks
Jack