Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

DX9 StencilBuffer issue for multiple mirror reflection


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Richard_OpenGL   Members   -  Reputation: 100

Like
0Likes
Like

Posted 14 April 2012 - 04:49 AM

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);
}
1.jpg
1.jpg

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

Richard

Ad:

#2 Richard_OpenGL   Members   -  Reputation: 100

Like
0Likes
Like

Posted 14 April 2012 - 05:02 AM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS