|
|
I try to modify the Parallel-Splits Shadow Maps for using render-target-texure to save the result. Because I want to use the deferred shading for rendering the scene. But when I use render-target-texture, some objects in the scene will be culled. I guess this problem produced from the nested and many times rendering in render-target-texture. I paste the pseudo code about the rendering in my code as below:
- RenderTexture ResultTexture;
- RenderTexture _ShadowMapTexture;
- void RednerScene()
- {
- ResultTexture.EnableRendering();
- D3Device->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DXCOLOR(0.5f,0.5f,0.5f,0.5f), 1.0f, 0);
- ResultTexture.DisableRendering();
- for(int iSplit=0;iSplit<_iNumSplits;iSplit++)
- {
- float fNear=_pSplitDistances[iSplit];
- float fFar=_pSplitDistances[iSplit+1];
- CalculateFrustumCorners(pCorners,_vCameraSource,_vCameraTarget, _vCameraUpVector, fNear, fFar, _fCameraFOV, fCameraAspect,fScale);
- CalculateLightForFrustum(pCorners);
- _ShadowMapTexture.EnableRendering();
- D3Device->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 0xFFFFFFFF, 1.0f, 0);
- _pEffect->SetTechnique("RenderShadowMap");
- RenderScene(_mLightView,_mLightProj);
- _ShadowMapTexture.DisableRendering();
- D3DVIEWPORT9 CameraViewport;
- D3Device->GetViewport(&CameraViewport);
- CameraViewport.MinZ=iSplit/(float)_iNumSplits;
- CameraViewport.MaxZ=(iSplit+1)/(float)_iNumSplits;
- D3Device->SetViewport(&CameraViewport);
- CalculateViewProj ( _mCameraView, _mCameraProj, _vCameraSource, _vCameraTarget, _vCameraUpVector, _fCameraFOV, fNear, fFar, fCameraAspect);
- _pEffect->SetTechnique("Shadowed_org");
- D3Device->SetTexture(0,_ShadowMapTexture.GetColorTexture());
- g_ResultTexture.EnableRendering();
- RenderScene(_mCameraView, _mCameraProj);
- g_ResultTexture.DisableRendering();
- RenderResultTextureToQuad();
- }
- }
- 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);
- }
- void RenderTexture::DisableRendering(void)
- {
- // Restore old depth stencil
- //
- GetApp()->GetDevice()->SetDepthStencilSurface(m_pOldDSSurface);
- // releasing is necessary due to reference counting
- if(m_pOldDSSurface!=NULL)
- {
- m_pOldDSSurface->Release();
- m_pOldDSSurface=NULL;
- }
- // Restore old render target
- //
- GetApp()->GetDevice()->SetRenderTarget(0,m_pOldRenderTarget);
- // releasing is necessary due to reference counting
- if(m_pOldRenderTarget!=NULL)
- {
- m_pOldRenderTarget->Release();
- m_pOldRenderTarget=NULL;
- }
- // Restore old viewport
- //
- GetApp()->GetDevice()->SetViewport(&m_OldViewport);
- }
复制代码
PS:Here is my complete source code
F3:not use render-target-texture
F4:use render-target-texture
PSSM_F3.jpg is the result without using redner-target-texture(original)
PSSM_F4.jpg is the result with using redner-target-texture
Hope somebodies are interested this problem will see the code and solve this problem! |
|