HRESULT CGraphics::DrawShadow()
{
d3dDevice->SetRenderState( D3DRS_ZENABLE, FALSE );
d3dDevice->SetRenderState( D3DRS_STENCILENABLE, TRUE );
d3dDevice->SetRenderState( D3DRS_FOGENABLE, FALSE );
d3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
d3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
d3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
d3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
d3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
d3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
d3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
d3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );
d3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
// Only write where stencil val >= 1 (count indicates # of shadows that
// overlap that pixel)
d3dDevice->SetRenderState( D3DRS_STENCILREF, 0x1 );
d3dDevice->SetRenderState( D3DRS_STENCILFUNC, D3DCMP_LESSEQUAL );
d3dDevice->SetRenderState( D3DRS_STENCILPASS, D3DSTENCILOP_KEEP );
// Draw a big square
d3dDevice->SetFVF( SHADOWVERTEX::FVF );
d3dDevice->SetStreamSource( 0, bigSquareVB, 0, sizeof(SHADOWVERTEX) );
d3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );
// Restore render states
d3dDevice->SetRenderState( D3DRS_ZENABLE, TRUE );
d3dDevice->SetRenderState( D3DRS_STENCILENABLE, FALSE );
d3dDevice->SetRenderState( D3DRS_FOGENABLE, TRUE );
d3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
return S_OK;
}
I think it's probably a renderstate somewhere, but I can't seem to find it. Any help would be greatly appreciated.
[edited by - circlesoft on October 10, 2003 3:46:51 PM]
Stencil Buffer Turns Everything Black
I'm using the same approach as the SDK Stencil Buffer sample to create realtime shadows. When I render the vertex buffer, however, all the objects that should have materials and textures just turn to black. Whenever I bypass the function that does this, everything is fine (no shadows are rendered though, of course). Here is the code:
Have you remembered to clear the stencil buffer in your Clear() call, and if so, what to?
--
Simon O''Connor
3D Game Programmer &
Microsoft DirectX MVP
--
Simon O''Connor
3D Game Programmer &
Microsoft DirectX MVP
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement