diff --git a/mp/src/game/client/c_env_projectedtexture.cpp b/mp/src/game/client/c_env_projectedtexture.cpp index 76f5998f0..24b7a88e2 100644 --- a/mp/src/game/client/c_env_projectedtexture.cpp +++ b/mp/src/game/client/c_env_projectedtexture.cpp @@ -18,7 +18,7 @@ #include "tier0/memdbgon.h" static ConVar mat_slopescaledepthbias_shadowmap( "mat_slopescaledepthbias_shadowmap", "16", FCVAR_CHEAT ); -static ConVar mat_depthbias_shadowmap( "mat_depthbias_shadowmap", "0.0005", FCVAR_CHEAT ); +static ConVar mat_depthbias_shadowmap( "mat_depthbias_shadowmap", "0.00001", FCVAR_CHEAT ); //----------------------------------------------------------------------------- // Purpose: diff --git a/mp/src/game/client/clientshadowmgr.cpp b/mp/src/game/client/clientshadowmgr.cpp index 8c666c275..ec5fdfe95 100644 --- a/mp/src/game/client/clientshadowmgr.cpp +++ b/mp/src/game/client/clientshadowmgr.cpp @@ -1336,6 +1336,13 @@ void CClientShadowMgr::InitDepthTextureShadows() { VPROF_BUDGET( "CClientShadowMgr::InitDepthTextureShadows", VPROF_BUDGETGROUP_SHADOW_DEPTH_TEXTURING ); + // SAUL: start benchmark timer + CFastTimer timer; + timer.Start(); + + // SAUL: set m_nDepthTextureResolution to the depth resolution we want + m_nDepthTextureResolution = r_flashlightdepthres.GetInt(); + if( !m_bDepthTextureActive ) { m_bDepthTextureActive = true; @@ -1352,7 +1359,8 @@ void CClientShadowMgr::InitDepthTextureShadows() m_DummyColorTexture.InitRenderTargetTexture( r_flashlightdepthres.GetInt(), r_flashlightdepthres.GetInt(), RT_SIZE_OFFSCREEN, IMAGE_FORMAT_BGR565, MATERIAL_RT_DEPTH_SHARED, false, "_rt_ShadowDummy" ); m_DummyColorTexture.InitRenderTargetSurface( r_flashlightdepthres.GetInt(), r_flashlightdepthres.GetInt(), IMAGE_FORMAT_BGR565, true ); #else - m_DummyColorTexture.InitRenderTarget( r_flashlightdepthres.GetInt(), r_flashlightdepthres.GetInt(), RT_SIZE_OFFSCREEN, nullFormat, MATERIAL_RT_DEPTH_NONE, false, "_rt_ShadowDummy" ); + // SAUL: we want to create a render target of specific size, so use RT_SIZE_NO_CHANGE + m_DummyColorTexture.InitRenderTarget( m_nDepthTextureResolution, m_nDepthTextureResolution, RT_SIZE_NO_CHANGE, nullFormat, MATERIAL_RT_DEPTH_NONE, false, "_rt_ShadowDummy" ); #endif // Create some number of depth-stencil textures @@ -1372,9 +1380,13 @@ void CClientShadowMgr::InitDepthTextureShadows() depthTex.InitRenderTargetTexture( m_nDepthTextureResolution, m_nDepthTextureResolution, RT_SIZE_OFFSCREEN, dstFormat, MATERIAL_RT_DEPTH_NONE, false, strRTName ); depthTex.InitRenderTargetSurface( 1, 1, dstFormat, false ); #else - depthTex.InitRenderTarget( m_nDepthTextureResolution, m_nDepthTextureResolution, RT_SIZE_OFFSCREEN, dstFormat, MATERIAL_RT_DEPTH_NONE, false, strRTName ); + // SAUL: we want to create a *DEPTH TEXTURE* of specific size, so use RT_SIZE_NO_CHANGE and MATERIAL_RT_DEPTH_ONLY + depthTex.InitRenderTarget( m_nDepthTextureResolution, m_nDepthTextureResolution, RT_SIZE_NO_CHANGE, dstFormat, MATERIAL_RT_DEPTH_ONLY, false, strRTName ); #endif + // SAUL: ensure the depth texture size wasn't changed + Assert(depthTex->GetActualWidth() == m_nDepthTextureResolution); + if ( i == 0 ) { // Shadow may be resized during allocation (due to resolution constraints etc) @@ -1388,6 +1400,9 @@ void CClientShadowMgr::InitDepthTextureShadows() materials->EndRenderTargetAllocation(); } + + timer.End(); + DevMsg("InitDepthTextureShadows took %.2f msec\n", timer.GetDuration().GetMillisecondsF()); } void CClientShadowMgr::ShutdownDepthTextureShadows() diff --git a/mp/src/game/client/viewrender.cpp b/mp/src/game/client/viewrender.cpp index 67a8307cb..baa6cb61f 100644 --- a/mp/src/game/client/viewrender.cpp +++ b/mp/src/game/client/viewrender.cpp @@ -4983,6 +4983,10 @@ void CShadowDepthView::Draw() render->Push3DView( (*this), VIEW_CLEAR_DEPTH, m_pRenderTarget, GetFrustum() ); } + pRenderContext.GetFrom(materials); + pRenderContext->PushRenderTargetAndViewport(m_pRenderTarget, m_pDepthTexture, 0, 0, m_pDepthTexture->GetMappingWidth(), m_pDepthTexture->GetMappingWidth()); + pRenderContext.SafeRelease(); + SetupCurrentView( origin, angles, VIEW_SHADOW_DEPTH_TEXTURE ); MDLCACHE_CRITICAL_SECTION(); @@ -5027,6 +5031,7 @@ void CShadowDepthView::Draw() pRenderContext->CopyRenderTargetToTextureEx( m_pDepthTexture, -1, NULL, NULL ); } + pRenderContext->PopRenderTargetAndViewport(); render->PopView( GetFrustum() ); #if defined( _X360 ) diff --git a/sp/src/game/client/c_env_projectedtexture.cpp b/sp/src/game/client/c_env_projectedtexture.cpp index 76f5998f0..24b7a88e2 100644 --- a/sp/src/game/client/c_env_projectedtexture.cpp +++ b/sp/src/game/client/c_env_projectedtexture.cpp @@ -18,7 +18,7 @@ #include "tier0/memdbgon.h" static ConVar mat_slopescaledepthbias_shadowmap( "mat_slopescaledepthbias_shadowmap", "16", FCVAR_CHEAT ); -static ConVar mat_depthbias_shadowmap( "mat_depthbias_shadowmap", "0.0005", FCVAR_CHEAT ); +static ConVar mat_depthbias_shadowmap( "mat_depthbias_shadowmap", "0.00001", FCVAR_CHEAT ); //----------------------------------------------------------------------------- // Purpose: diff --git a/sp/src/game/client/clientshadowmgr.cpp b/sp/src/game/client/clientshadowmgr.cpp index b2f9baa95..188f1cadc 100644 --- a/sp/src/game/client/clientshadowmgr.cpp +++ b/sp/src/game/client/clientshadowmgr.cpp @@ -1336,6 +1336,13 @@ void CClientShadowMgr::InitDepthTextureShadows() { VPROF_BUDGET( "CClientShadowMgr::InitDepthTextureShadows", VPROF_BUDGETGROUP_SHADOW_DEPTH_TEXTURING ); + // SAUL: start benchmark timer + CFastTimer timer; + timer.Start(); + + // SAUL: set m_nDepthTextureResolution to the depth resolution we want + m_nDepthTextureResolution = r_flashlightdepthres.GetInt(); + if( !m_bDepthTextureActive ) { m_bDepthTextureActive = true; @@ -1352,7 +1359,8 @@ void CClientShadowMgr::InitDepthTextureShadows() m_DummyColorTexture.InitRenderTargetTexture( r_flashlightdepthres.GetInt(), r_flashlightdepthres.GetInt(), RT_SIZE_OFFSCREEN, IMAGE_FORMAT_BGR565, MATERIAL_RT_DEPTH_SHARED, false, "_rt_ShadowDummy" ); m_DummyColorTexture.InitRenderTargetSurface( r_flashlightdepthres.GetInt(), r_flashlightdepthres.GetInt(), IMAGE_FORMAT_BGR565, true ); #else - m_DummyColorTexture.InitRenderTarget( r_flashlightdepthres.GetInt(), r_flashlightdepthres.GetInt(), RT_SIZE_OFFSCREEN, nullFormat, MATERIAL_RT_DEPTH_NONE, false, "_rt_ShadowDummy" ); + // SAUL: we want to create a render target of specific size, so use RT_SIZE_NO_CHANGE + m_DummyColorTexture.InitRenderTarget( m_nDepthTextureResolution, m_nDepthTextureResolution, RT_SIZE_NO_CHANGE, nullFormat, MATERIAL_RT_DEPTH_NONE, false, "_rt_ShadowDummy" ); #endif // Create some number of depth-stencil textures @@ -1372,9 +1380,13 @@ void CClientShadowMgr::InitDepthTextureShadows() depthTex.InitRenderTargetTexture( m_nDepthTextureResolution, m_nDepthTextureResolution, RT_SIZE_OFFSCREEN, dstFormat, MATERIAL_RT_DEPTH_NONE, false, strRTName ); depthTex.InitRenderTargetSurface( 1, 1, dstFormat, false ); #else - depthTex.InitRenderTarget( m_nDepthTextureResolution, m_nDepthTextureResolution, RT_SIZE_OFFSCREEN, dstFormat, MATERIAL_RT_DEPTH_NONE, false, strRTName ); + // SAUL: we want to create a *DEPTH TEXTURE* of specific size, so use RT_SIZE_NO_CHANGE and MATERIAL_RT_DEPTH_ONLY + depthTex.InitRenderTarget( m_nDepthTextureResolution, m_nDepthTextureResolution, RT_SIZE_NO_CHANGE, dstFormat, MATERIAL_RT_DEPTH_ONLY, false, strRTName ); #endif + // SAUL: ensure the depth texture size wasn't changed + Assert(depthTex->GetActualWidth() == m_nDepthTextureResolution); + if ( i == 0 ) { // Shadow may be resized during allocation (due to resolution constraints etc) @@ -1388,6 +1400,9 @@ void CClientShadowMgr::InitDepthTextureShadows() materials->EndRenderTargetAllocation(); } + + timer.End(); + DevMsg("InitDepthTextureShadows took %.2f msec\n", timer.GetDuration().GetMillisecondsF()); } void CClientShadowMgr::ShutdownDepthTextureShadows() diff --git a/sp/src/game/client/viewrender.cpp b/sp/src/game/client/viewrender.cpp index a4fd0f8b9..981f925a4 100644 --- a/sp/src/game/client/viewrender.cpp +++ b/sp/src/game/client/viewrender.cpp @@ -4997,6 +4997,10 @@ void CShadowDepthView::Draw() render->Push3DView( (*this), VIEW_CLEAR_DEPTH, m_pRenderTarget, GetFrustum() ); } + pRenderContext.GetFrom(materials); + pRenderContext->PushRenderTargetAndViewport(m_pRenderTarget, m_pDepthTexture, 0, 0, m_pDepthTexture->GetMappingWidth(), m_pDepthTexture->GetMappingWidth()); + pRenderContext.SafeRelease(); + SetupCurrentView( origin, angles, VIEW_SHADOW_DEPTH_TEXTURE ); MDLCACHE_CRITICAL_SECTION(); @@ -5041,6 +5045,7 @@ void CShadowDepthView::Draw() pRenderContext->CopyRenderTargetToTextureEx( m_pDepthTexture, -1, NULL, NULL ); } + pRenderContext->PopRenderTargetAndViewport(); render->PopView( GetFrustum() ); #if defined( _X360 )