Basic Shadow Mapping Depth Stencil Question

Started by
-1 comments, last by Gribbles 11 years, 2 months ago

After Spending about 3 days trying to get shadow mapping to work I'm having some trouble getting the shadow mapped passed in to the shaders.

First I initialize the depth stencil and the resource view, then i draw ( I believe ) to the depth stencil. The problem that I am finding is that the depth stencil never has any data associated with it.

Pix shows no data in the resource view or the depth stencil, I am unable to save an image of the depth stencil to a file (I am from the non shadow depth stencil ). I am able to call DrawSceneShadow() and see a result I want though.

Any help is appreciated thank you.

Initialize

// Create depth stencil texture
D3D10_TEXTURE2D_DESC descDepth;
descDepth.Width = width;
descDepth.Height = height;
descDepth.MipLevels = 1;
descDepth.ArraySize = 1;
descDepth.Format = DXGI_FORMAT_R32_TYPELESS;
descDepth.SampleDesc.Count = 1;
descDepth.SampleDesc.Quality = 0;
descDepth.Usage = D3D10_USAGE_DEFAULT;
descDepth.BindFlags = D3D10_BIND_DEPTH_STENCIL;
descDepth.CPUAccessFlags = 0;
descDepth.MiscFlags = 0;
hr = g_pd3dDevice->CreateTexture2D( &descDepth, NULL, &g_pDepthStencil );
// Create the depth stencil view
D3D10_DEPTH_STENCIL_VIEW_DESC descDSV;
descDSV.Format = DXGI_FORMAT_D32_FLOAT;
descDSV.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D;
descDSV.Texture2D.MipSlice = 0;
hr = g_pd3dDevice->CreateDepthStencilView( g_pDepthStencil, &descDSV, &g_pDepthStencilView );
/////////////////////////////
//Shadow Mapping
//create shadow map texture desc
descDepth.Width = width;
descDepth.Height = height;
descDepth.Format = DXGI_FORMAT_R32_TYPELESS;
descDepth.BindFlags = D3D10_BIND_DEPTH_STENCIL | D3D10_BIND_SHADER_RESOURCE;
//create shader resource view desc
D3D10_SHADER_RESOURCE_VIEW_DESC srvDesc;
srvDesc.Format = DXGI_FORMAT_R32_FLOAT;
srvDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
srvDesc.Texture2D.MipLevels = descDepth.MipLevels;
srvDesc.Texture2D.MostDetailedMip = 0;
Render Scene
//Create shadow map
//***************************************************************************
//set render targets
//set render targets and viewport
g_pd3dDevice->OMSetRenderTargets(0, 0, pShadowMapDepthView);
g_pd3dDevice->ClearDepthStencilView( pShadowMapDepthView, D3D10_CLEAR_DEPTH, 1.0f, 0 );
moveCam( lightPos.x, lightPos.y, lightPos.z );
DrawSceneShadow();
//Render final scene
//***************************************************************************
//set render targets
g_pd3dDevice->OMSetRenderTargets(1, &g_pRenderTargetView, g_pDepthStencilView);
g_pd3dDevice->RSSetViewports(1, &vp);
g_pd3dDevice->ClearRenderTargetView( g_pRenderTargetView, D3DXCOLOR(0.6f,0.6f,0.6f,0) );
g_pd3dDevice->ClearDepthStencilView( g_pDepthStencilView, D3D10_CLEAR_DEPTH, 1.0f, 0 );
//bind shadow map texture
g_pEffect->GetVariableByName("shadowMap")->AsShaderResource()->SetResource( pShadowMapSRView );
ScreenGrab();
resetCam();
lightMatrix();
DrawScene();
//unbind shadow map as SRV and call apply on scene rendering technique
g_pEffect->GetVariableByName("shadowMap")->AsShaderResource()->SetResource( 0 );
g_pRenderShadowMapTechnique->GetPassByIndex(0)->Apply( 0 );

This topic is closed to new replies.

Advertisement