volume shadow
Hi everyone
It is the first time I try to make volume shadow and I have some problem with stencil.
Here is the code of directx sample that I got
// Set renderstates (disable z-buffering, enable stencil,and
// turn on alphablending)
g_pd3dDevice->SetRenderState( D3DRS_ZENABLE, FALSE );
g_pd3dDevice->SetRenderState( D3DRS_STENCILENABLE, TRUE );
g_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
// set reference value
g_pd3dDevice->SetRenderState( D3DRS_STENCILREF, 0x1 );
// Don't change the value of pixel
g_pd3dDevice->SetRenderState( D3DRS_STENCILPASS, D3DSTENCILOP_KEEP );
// Comparision
g_pd3dDevice->SetRenderState( D3DRS_STENCILFUNC, D3DCMP_LESSEQUAL );
// Draw a big, gray square
g_pd3dDevice->SetFVF( cc_shadowvertex::FVF );
g_pd3dDevice->SetStreamSource( 0, g_pBigSquareVB, 0, sizeof(shadowvertex));
g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );
It means that all the pixel where stencil val >= reference value (1) will be overwrite by the gray square.
The problem is when I change the reference value the square allways is drawn. So it means the function to compare current pixel with reference is not work. I don't have any experience about stencil so I'm not be confidence.
Or I have to put some comment to initialize stencil when I create the device? Anyone can help me ?
Thanks
To what kind of values have you changed the reference val?
The result will be the same for any arbitrary value in range of <1,2^N+1), where N is stencil bits . If you switch to zero, you will get shadow where's light and vice versa.
The result will be the same for any arbitrary value in range of <1,2^N+1), where N is stencil bits . If you switch to zero, you will get shadow where's light and vice versa.
Quote:Original post by snowintherain
Or I have to put some comment to initialize stencil when I create the device?
Make sure you have EnableAutoDepthStencil set to TRUE and AutoDepthStencilFormat set to D3DFMT_D24S8 in your D3DPRESENT_PARAMETERS struct.
Thanks for your help I change the D3DPRESENT_PARAMETERS to
d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
Now the function to compare working.
If I set this value
m_pd3dDevice->SetRenderState( D3DRS_STENCILREF, 0x1 );
m_pd3dDevice->SetRenderState( D3DRS_STENCILFUNC, D3DCMP_LESSEQUAL );
The shadowed area appear in the screen
I change it to
m_pd3dDevice->SetRenderState( D3DRS_STENCILREF, 0x0 );
All the screen is gray
m_pd3dDevice->SetRenderState( D3DRS_STENCILREF, 0x2 );
no dark area in it.
But what is the meaning of D3DFMT_D24S8?
d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
Now the function to compare working.
If I set this value
m_pd3dDevice->SetRenderState( D3DRS_STENCILREF, 0x1 );
m_pd3dDevice->SetRenderState( D3DRS_STENCILFUNC, D3DCMP_LESSEQUAL );
The shadowed area appear in the screen
I change it to
m_pd3dDevice->SetRenderState( D3DRS_STENCILREF, 0x0 );
All the screen is gray
m_pd3dDevice->SetRenderState( D3DRS_STENCILREF, 0x2 );
no dark area in it.
But what is the meaning of D3DFMT_D24S8?
Quote:Original post by snowintherain
But what is the meaning of D3DFMT_D24S8?
It allocates a depth-stencil buffer with 24 bits depth (Z-buffer) and 8 bits stencil. As you propably know, shadow volumes need stencil buffer to work.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement