These days I got a trouble when I use stencilbuffer to make the plane reflection (more than one mirror).
The depth of stencil was cleared after the render of first mirror, but it was hard for me to fix.
My Code:
for(set<CObject3D*>::iterator it=m_SetMirrors.begin();it!=m_SetMirrors.end();it++)
{ pd3dDevice->SetDepthStencilSurface(pDSOld);
pd3dDevice->SetRenderState(D3DRS_STENCILENABLE, TRUE);
pd3dDevice->SetRenderState(D3DRS_STENCILREF, dwRef); // prevent the stencilfail of mirror a draw to mirror b area
pd3dDevice->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_ALWAYS);
pd3dDevice->SetRenderState(D3DRS_STENCILMASK, 0xffffffff);
pd3dDevice->SetRenderState(D3DRS_STENCILWRITEMASK, 0xffffffff);
pd3dDevice->SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP);
pd3dDevice->SetRenderState(D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP);
pd3dDevice->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_REPLACE);
//pd3dDevice->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
//pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
//pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ZERO);
//pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
(*it)->RenderOneStage(pd3dDevice, m_pAmbientStage, fTime, fElapsedTime); // draw mirror to the stencil buffer
//pd3dDevice->SetRenderState(D3DRS_ZWRITEENABLE, TRUE);
pd3dDevice->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_EQUAL);
pd3dDevice->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_KEEP);
//pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_DESTCOLOR);
//pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ZERO);
V(pd3dDevice->Clear(0, NULL, D3DCLEAR_ZBUFFER, 0, 1.0f, 0L)); // clear the Zbuffer
m_flagMirror = true;
D3DXMatrixReflect(&m_MatReflect, &(*it)->m_plane);
m_ReflectAlpha = (*it)->m_Reflectivity;
StagesPerLight(pd3dDevice,fTime,fElapsedTime,NULL,(*it)); // draw the reflected objects
m_flagMirror = false;
dwRef<<=1;
pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
pd3dDevice->SetRenderState(D3DRS_STENCILENABLE, FALSE);
}
It will be very thankful if anyone could help me about this problem.
Thanks a lot.
Richard






