Jump to content
  • Advertisement
Sign in to follow this  
Richard_OpenGL

DX9 StencilBuffer issue for multiple mirror reflection

This topic is 2288 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi All:

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);
}

[attachment=8234:1.jpg]
[attachment=8235:1.jpg]

It will be very thankful if anyone could help me about this problem.
Thanks a lot.

Richard

Share this post


Link to post
Share on other sites
Advertisement
I have also tried to draw all the mirror planes together in one stencilbuffer, but some of the unexpected stencilfail pix will be filled over on the other plane area.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!