• Advertisement
Sign in to follow this  

Basic Shadow Mapping Depth Stencil Question

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

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.




    // 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
    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;
    //create shader resource view desc
    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 );
    //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 );
    //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 );



Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement