From 01a86e2b3d8c51f62a94f2b6c48f4deeca6503e2 Mon Sep 17 00:00:00 2001 From: Robert Beckebans Date: Thu, 10 Mar 2022 20:20:48 +0100 Subject: [PATCH] Fixed flash light shadow maps --- neo/renderer/RenderBackend.cpp | 34 +++++++++++++------ .../builtin/lighting/interactionSM.ps.hlsl | 3 +- neo/sys/win32/win_wndproc.cpp | 2 +- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/neo/renderer/RenderBackend.cpp b/neo/renderer/RenderBackend.cpp index e21edc08..306b81b6 100644 --- a/neo/renderer/RenderBackend.cpp +++ b/neo/renderer/RenderBackend.cpp @@ -3118,6 +3118,13 @@ void idRenderBackend::ShadowMapPass( const drawSurf_t* drawSurfs, const viewLigh idRenderMatrix lightProjectionRenderMatrix; idRenderMatrix lightViewRenderMatrix; + // Calculate alternate matrix that maps to [0, 1] UV space instead of [-1, 1] clip space + ALIGNTYPE16 const idRenderMatrix matClipToUvzw( + 0.5f, 0.0f, 0.0f, 0.5f, + 0.0f, -0.5f, 0.0f, 0.5f, + 0.0f, 0.0f, 1.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f + ); if( vLight->parallel && side >= 0 ) { @@ -3275,6 +3282,12 @@ void idRenderBackend::ShadowMapPass( const drawSurf_t* drawSurfs, const viewLigh shadowV[side] = lightViewRenderMatrix; shadowP[side] = lightProjectionRenderMatrix; + +#if 0 //defined( USE_NVRHI ) + idRenderMatrix shadowToClip; + idRenderMatrix::Multiply( renderMatrix_windowSpaceToClipSpace, lightProjectionRenderMatrix, shadowToClip ); + idRenderMatrix::Multiply( matClipToUvzw, shadowToClip, shadowP[side] ); +#endif } else if( vLight->pointLight && side >= 0 ) { @@ -3386,7 +3399,7 @@ void idRenderBackend::ShadowMapPass( const drawSurf_t* drawSurfs, const viewLigh lightProjectionMatrix[1 * 4 + 2] = 0.0f; lightProjectionMatrix[2 * 4 + 2] = -0.999f; // adjust value to prevent imprecision issues -#if 0 //defined( USE_NVRHI ) +#if defined( USE_NVRHI ) // the D3D clip space Z is in range [0,1] instead of [-1,1] lightProjectionMatrix[3 * 4 + 2] = -zNear; #else @@ -3402,9 +3415,16 @@ void idRenderBackend::ShadowMapPass( const drawSurf_t* drawSurfs, const viewLigh shadowV[side] = lightViewRenderMatrix; shadowP[side] = lightProjectionRenderMatrix; + +#if 0 //defined( USE_NVRHI ) + idRenderMatrix shadowToClip; + idRenderMatrix::Multiply( renderMatrix_windowSpaceToClipSpace, lightProjectionRenderMatrix, shadowToClip ); + idRenderMatrix::Multiply( matClipToUvzw, shadowToClip, shadowP[side] ); +#endif } else { + // spot light lightViewRenderMatrix.Identity(); lightProjectionRenderMatrix = vLight->baseLightProject; @@ -3412,15 +3432,9 @@ void idRenderBackend::ShadowMapPass( const drawSurf_t* drawSurfs, const viewLigh shadowP[0] = lightProjectionRenderMatrix; #if defined( USE_NVRHI ) - // Calculate alternate matrix that maps to [0, 1] UV space instead of [-1, 1] clip space - ALIGNTYPE16 const idRenderMatrix matClipToUvzw( - 0.5f, 0.0f, 0.0f, 0.5f, - 0.0f, -0.5f, 0.0f, 0.5f, - 0.0f, 0.0f, 1.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 1.0f - ); - - idRenderMatrix::Multiply( matClipToUvzw, lightProjectionRenderMatrix, shadowP[0] ); + idRenderMatrix shadowToClip; + idRenderMatrix::Multiply( renderMatrix_windowSpaceToClipSpace, lightProjectionRenderMatrix, shadowToClip ); + idRenderMatrix::Multiply( matClipToUvzw, shadowToClip, shadowP[0] ); #endif } diff --git a/neo/shaders/builtin/lighting/interactionSM.ps.hlsl b/neo/shaders/builtin/lighting/interactionSM.ps.hlsl index 53a005c7..28181078 100644 --- a/neo/shaders/builtin/lighting/interactionSM.ps.hlsl +++ b/neo/shaders/builtin/lighting/interactionSM.ps.hlsl @@ -212,7 +212,6 @@ void main( PS_IN fragment, out PS_OUT result ) float4 modelPosition = float4( fragment.texcoord7.xyz, 1.0 ); - float4 shadowTexcoord; shadowTexcoord.x = dot4( modelPosition, shadowMatrixX ); shadowTexcoord.y = dot4( modelPosition, shadowMatrixY ); @@ -399,7 +398,7 @@ void main( PS_IN fragment, out PS_OUT result ) uvzShadow.z = shadowTexcoord.w; float shadow = t_ShadowMapArray.SampleCmpLevelZero( samp2, uvzShadow, shadowTexcoord.z ); -#if 1 +#if 0 if( shadowIndex == 0 ) { result.color = float4( 1.0, 0.0, 0.0, 1.0 ); diff --git a/neo/sys/win32/win_wndproc.cpp b/neo/sys/win32/win_wndproc.cpp index 60f966c1..f77c28a5 100644 --- a/neo/sys/win32/win_wndproc.cpp +++ b/neo/sys/win32/win_wndproc.cpp @@ -179,7 +179,7 @@ LONG WINAPI MainWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) switch( uMsg ) { case WM_WINDOWPOSCHANGED: - if( renderSystem->IsInitialized() && win32.hDC != NULL ) + if( renderSystem->IsInitialized() )//&& win32.hDC != NULL ) { RECT rect; if( ::GetClientRect( win32.hWnd, &rect ) )