Should I modify the viewport's size as the shadow map'size when I render scene into a shadow map?
| void RenderTexture::EnableRendering(void) |
| { |
| // Store original values |
| // |
| GetApp()->GetDevice()->GetViewport(&m_OldViewport); |
| GetApp()->GetDevice()->GetRenderTarget(0,&m_pOldRenderTarget); |
| GetApp()->GetDevice()->GetDepthStencilSurface(&m_pOldDSSurface); |
| |
| // Set new values |
| // |
| GetApp()->GetDevice()->SetViewport(&m_Viewport); |
| GetApp()->GetDevice()->SetRenderTarget(0,m_pSurface); |
| GetApp()->GetDevice()->SetDepthStencilSurface(m_pDSSurface); |
| } |
| |
| // Enable rendering to shadowmap |
| // |
| _ShadowMapTexture.EnableRendering(); |
| |
| |
| // Clear the shadowmap |
| // |
| GetApp()->GetDevice()->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 0xFFFFFFFF, 1.0f, 0); |
| |
| |
| // Set up shaders |
| // |
| // To hide artifacts, only render back faces of the scene |
| // |
| _pEffect->SetTechnique("RenderShadowMap"); |
| |
| |
| // Render the scene to the shadowmap |
| // |
| RenderScene(_mLightView,_mLightProj); |
| |
| |
| // Go back to normal rendering |
| // |
| _ShadowMapTexture.DisableRendering(); |