Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

circlesoft

Stencil Buffer Turns Everything Black

This topic is 5398 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

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:
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]

Share this post


Link to post
Share on other sites
Advertisement

  • 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!