Stencil Buffer Turns Everything Black

Started by
1 comment, last by circlesoft 20 years, 6 months ago
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]
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
Advertisement
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 | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

Thanks for the reply. I found the problem in:

d3dDevice->SetRenderState( D3DRS_FOGENABLE, TRUE ); 


And I don''t use fog



Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )

This topic is closed to new replies.

Advertisement