游戏开发论坛

 找回密码
 立即注册
搜索
查看: 1811|回复: 0

Render render-target-texture nested and many times

[复制链接]

414

主题

611

帖子

621

积分

高级会员

Rank: 4

积分
621
发表于 2009-2-10 20:25:00 | 显示全部楼层 |阅读模式
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:


  1. RenderTexture ResultTexture;
  2. RenderTexture _ShadowMapTexture;

  3. void RednerScene()
  4. {
  5.         ResultTexture.EnableRendering();
  6.         D3Device->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DXCOLOR(0.5f,0.5f,0.5f,0.5f), 1.0f, 0);
  7.         ResultTexture.DisableRendering();

  8.         for(int iSplit=0;iSplit<_iNumSplits;iSplit++)
  9.         {
  10.                 float fNear=_pSplitDistances[iSplit];
  11.                 float fFar=_pSplitDistances[iSplit+1];

  12.                 CalculateFrustumCorners(pCorners,_vCameraSource,_vCameraTarget, _vCameraUpVector, fNear, fFar, _fCameraFOV, fCameraAspect,fScale);
  13.                 CalculateLightForFrustum(pCorners);

  14.                 _ShadowMapTexture.EnableRendering();
  15.                 D3Device->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 0xFFFFFFFF, 1.0f, 0);

  16.                 _pEffect->SetTechnique("RenderShadowMap");
  17.                 RenderScene(_mLightView,_mLightProj);
  18.                 _ShadowMapTexture.DisableRendering();

  19.                 D3DVIEWPORT9 CameraViewport;
  20.                 D3Device->GetViewport(&CameraViewport);
  21.                 CameraViewport.MinZ=iSplit/(float)_iNumSplits;
  22.                 CameraViewport.MaxZ=(iSplit+1)/(float)_iNumSplits;
  23.                 D3Device->SetViewport(&CameraViewport);

  24.                 CalculateViewProj ( _mCameraView, _mCameraProj, _vCameraSource, _vCameraTarget, _vCameraUpVector, _fCameraFOV, fNear, fFar, fCameraAspect);

  25.                 _pEffect->SetTechnique("Shadowed_org");

  26.                 D3Device->SetTexture(0,_ShadowMapTexture.GetColorTexture());

  27.                 g_ResultTexture.EnableRendering();
  28.                 RenderScene(_mCameraView, _mCameraProj);
  29.                 g_ResultTexture.DisableRendering();

  30.                 RenderResultTextureToQuad();
  31.         }
  32. }

  33. void RenderTexture::EnableRendering(void)
  34. {
  35.         // Store original values
  36.         //
  37.         GetApp()->GetDevice()->GetViewport(&m_OldViewport);
  38.         GetApp()->GetDevice()->GetRenderTarget(0,&m_pOldRenderTarget);
  39.         GetApp()->GetDevice()->GetDepthStencilSurface(&m_pOldDSSurface);

  40.         // Set new values
  41.         //
  42.         GetApp()->GetDevice()->SetViewport(&m_Viewport);
  43.         GetApp()->GetDevice()->SetRenderTarget(0,m_pSurface);
  44.         GetApp()->GetDevice()->SetDepthStencilSurface(m_pDSSurface);
  45. }

  46. void RenderTexture::DisableRendering(void)
  47. {
  48.         // Restore old depth stencil
  49.         //
  50.         GetApp()->GetDevice()->SetDepthStencilSurface(m_pOldDSSurface);

  51.         // releasing is necessary due to reference counting
  52.         if(m_pOldDSSurface!=NULL)
  53.         {
  54.                 m_pOldDSSurface->Release();
  55.                 m_pOldDSSurface=NULL;
  56.         }

  57.         // Restore old render target
  58.         //
  59.         GetApp()->GetDevice()->SetRenderTarget(0,m_pOldRenderTarget);

  60.         // releasing is necessary due to reference counting
  61.         if(m_pOldRenderTarget!=NULL)
  62.         {
  63.                 m_pOldRenderTarget->Release();
  64.                 m_pOldRenderTarget=NULL;
  65.         }

  66.         // Restore old viewport
  67.         //
  68.         GetApp()->GetDevice()->SetViewport(&m_OldViewport);
  69. }
复制代码


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!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2026-1-20 08:43

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表