Skip to main content
gamedev.net
🔒 Locked

DirectX Stencil Shadow Tutorial

Started by QuadMV Aug 14, 2006 at 12:30 AM 2 replies 4.5k views
Original Post
QuadMV
QuadMV
Can anyone point me to a quality tutorial using DirectX for creating shadows with the stencil buffer? I'm looking for something dumbed down which keeps it really simple and to the point. I hate tutorials that have 10 times more code than necessary to get the point across. If anyone knows of one I’d appreciate it. I like the NEHE samples, but I was looking for something in DirectX if it exists. Thanks
3DMUVE is an amateur game development team, and the designer and developer of a new gaming technology “MUVE” for the gaming industry.
sipickles
sipickles
Just be aware of the weakness of shadow volumes. They need meshes which extrude correctly, eg a high poly count torus, or a nice round teapot!

Otherwise, the software has to add extra polys at the shadow boundary and it all gets out of hand!!!

DX10 accommodates geometry shaders which help in this case. Roll on DX10!
QuadMV
QuadMV
Thanks,

It looks like they specifically create the stencil buffer as part of the device using:

    d3dpp.Windowed               = TRUE;    d3dpp.SwapEffect             = D3DSWAPEFFECT_DISCARD;    d3dpp.BackBufferFormat       = d3ddm.Format;    d3dpp.EnableAutoDepthStencil = TRUE;	d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;	d3dpp.Flags                  = D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL;    d3dpp.PresentationInterval   = D3DPRESENT_INTERVAL_IMMEDIATE;    g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hWnd,                          D3DCREATE_SOFTWARE_VERTEXPROCESSING,                          //D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE,                         &d3dpp, &g_pd3dDevice );


I'm using the MS DXUTIL framework, so I don't perform the CreateDevice directly. I just have the callback ftn which looks something like this below. Can anyone tell me how to set the stencil buffer using this configuration?

bool CALLBACK ModifyDeviceSettings( DXUTDeviceSettings* pDeviceSettings, const D3DCAPS9* pCaps, void* pUserContext ){    // If device doesn't support HW T&L or doesn't support 1.1 vertex shaders in HW     // then switch to SWVP.    if( (pCaps->DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) == 0 ||         pCaps->VertexShaderVersion < D3DVS_VERSION(1,1) )    {        pDeviceSettings->BehaviorFlags = D3DCREATE_SOFTWARE_VERTEXPROCESSING;    }	if( ( pCaps->StencilCaps & D3DSTENCILCAPS_TWOSIDED ) != 0 )		g_bTwoSidedStencilsAvailable = true;//    d3dpp.EnableAutoDepthStencil = TRUE;//	d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;    pDeviceSettings->BehaviorFlags |= D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL;	// Debugging vertex shaders requires either REF or software vertex processing     // and debugging pixel shaders requires REF.  #ifdef DEBUG_VS    if( pDeviceSettings->DeviceType != D3DDEVTYPE_REF )    {        pDeviceSettings->BehaviorFlags &= ~D3DCREATE_HARDWARE_VERTEXPROCESSING;        pDeviceSettings->BehaviorFlags &= ~D3DCREATE_PUREDEVICE;        pDeviceSettings->BehaviorFlags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING;    }#endif#ifdef DEBUG_PS    pDeviceSettings->DeviceType = D3DDEVTYPE_REF;#endif    // For the first device created if its a REF device, optionally display a warning dialog box    static bool s_bFirstTime = true;    if( s_bFirstTime )    {        s_bFirstTime = false;        if( pDeviceSettings->DeviceType == D3DDEVTYPE_REF )            DXUTDisplaySwitchingToREFWarning();    }    return true;}
3DMUVE is an amateur game development team, and the designer and developer of a new gaming technology “MUVE” for the gaming industry.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.