From ace8829cda21f3ae761cd6e0fb6f5d74308fa681 Mon Sep 17 00:00:00 2001 From: Stephen Saunders Date: Wed, 25 Jan 2023 12:27:32 -0500 Subject: [PATCH 01/12] Fix ImGui include path handling to be consistent with other external libs --- neo/CMakeLists.txt | 1 + neo/imgui/BFGimgui.h | 2 +- neo/renderer/GuiModel.cpp | 2 +- neo/renderer/Image_intrinsic.cpp | 2 +- neo/renderer/NVRHI/RenderBackend_NVRHI.cpp | 2 +- neo/renderer/RenderSystem_init.cpp | 2 +- neo/tools/imgui/util/Imgui_IdWidgets.cpp | 2 +- neo/ui/DeviceContext.cpp | 2 +- 8 files changed, 8 insertions(+), 7 deletions(-) diff --git a/neo/CMakeLists.txt b/neo/CMakeLists.txt index 0e56f792..f9c7b6d3 100644 --- a/neo/CMakeLists.txt +++ b/neo/CMakeLists.txt @@ -348,6 +348,7 @@ else (JPEG_FOUND) set(JPEG_LIBRARY "" ) endif (JPEG_FOUND) +include_directories("libs/imgui") macro(SET_OPTION option value) set(${option} ${value} CACHE "" INTERNAL FORCE) diff --git a/neo/imgui/BFGimgui.h b/neo/imgui/BFGimgui.h index d6d3d20e..d1f0724f 100644 --- a/neo/imgui/BFGimgui.h +++ b/neo/imgui/BFGimgui.h @@ -2,7 +2,7 @@ #ifndef NEO_IMGUI_BFGIMGUI_H_ #define NEO_IMGUI_BFGIMGUI_H_ -#include "libs/imgui/imgui.h" +#include "imgui.h" #include "../idlib/math/Vector.h" diff --git a/neo/renderer/GuiModel.cpp b/neo/renderer/GuiModel.cpp index 08744f1b..877ba868 100644 --- a/neo/renderer/GuiModel.cpp +++ b/neo/renderer/GuiModel.cpp @@ -32,7 +32,7 @@ If you have questions concerning this license or the applicable additional terms #pragma hdrstop #include "RenderCommon.h" -#include "libs/imgui/imgui.h" +#include "imgui.h" const float idGuiModel::STEREO_DEPTH_NEAR = 0.0f; const float idGuiModel::STEREO_DEPTH_MID = 0.5f; diff --git a/neo/renderer/Image_intrinsic.cpp b/neo/renderer/Image_intrinsic.cpp index b0efc408..3ac87991 100644 --- a/neo/renderer/Image_intrinsic.cpp +++ b/neo/renderer/Image_intrinsic.cpp @@ -31,7 +31,7 @@ If you have questions concerning this license or the applicable additional terms #include "precompiled.h" #pragma hdrstop -#include "libs/imgui/imgui.h" +#include "imgui.h" #include "RenderCommon.h" #include "SMAA/AreaTex.h" diff --git a/neo/renderer/NVRHI/RenderBackend_NVRHI.cpp b/neo/renderer/NVRHI/RenderBackend_NVRHI.cpp index 1b19436a..ac2b982d 100644 --- a/neo/renderer/NVRHI/RenderBackend_NVRHI.cpp +++ b/neo/renderer/NVRHI/RenderBackend_NVRHI.cpp @@ -35,7 +35,7 @@ If you have questions concerning this license or the applicable additional terms #include "../RenderCommon.h" #include "../RenderBackend.h" #include "../../framework/Common_local.h" -#include "../../imgui/imgui.h" +#include "imgui.h" #include "../ImmediateMode.h" #include "nvrhi/utils.h" diff --git a/neo/renderer/RenderSystem_init.cpp b/neo/renderer/RenderSystem_init.cpp index 6053a57b..660eda8a 100644 --- a/neo/renderer/RenderSystem_init.cpp +++ b/neo/renderer/RenderSystem_init.cpp @@ -32,7 +32,7 @@ If you have questions concerning this license or the applicable additional terms #include "precompiled.h" #pragma hdrstop -#include "libs/imgui/imgui.h" +#include "imgui.h" #include "RenderCommon.h" diff --git a/neo/tools/imgui/util/Imgui_IdWidgets.cpp b/neo/tools/imgui/util/Imgui_IdWidgets.cpp index a4d2d9e4..36f30729 100644 --- a/neo/tools/imgui/util/Imgui_IdWidgets.cpp +++ b/neo/tools/imgui/util/Imgui_IdWidgets.cpp @@ -30,7 +30,7 @@ If you have questions concerning this license or the applicable additional terms #include "precompiled.h" #pragma hdrstop -#include "../imgui/imgui.h" +#include "imgui.h" #include "Imgui_IdWidgets.h" diff --git a/neo/ui/DeviceContext.cpp b/neo/ui/DeviceContext.cpp index cf4d2c53..ac4b2ef3 100644 --- a/neo/ui/DeviceContext.cpp +++ b/neo/ui/DeviceContext.cpp @@ -31,7 +31,7 @@ If you have questions concerning this license or the applicable additional terms #include "DeviceContext.h" -#include "libs/imgui/imgui.h" +#include "imgui.h" #include "../renderer/RenderCommon.h" extern idCVar in_useJoystick; From 0c7f8be44e783bec93e1f0d591f0740441c63e12 Mon Sep 17 00:00:00 2001 From: Stephen Saunders Date: Wed, 25 Jan 2023 12:42:42 -0500 Subject: [PATCH 02/12] Restore rm_precomp_header custom target for makefile / ninja command line builds --- neo/CMakeLists.txt | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/neo/CMakeLists.txt b/neo/CMakeLists.txt index f9c7b6d3..e1d81c01 100644 --- a/neo/CMakeLists.txt +++ b/neo/CMakeLists.txt @@ -1817,13 +1817,24 @@ else() set(remove_command "rm") endif() - # make sure precompiled header is deleted after executable is compiled - add_custom_command(TARGET RBDoom3BFG POST_BUILD - COMMAND ${remove_command} "idlib/precompiled.h.gch" - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMENT "remove idlib/precompiled.h.gch" - ) - endif() + # delete precompiled header file after executable is compiled: command line build case + if(CMAKE_GENERATOR MATCHES "Makefiles" OR CMAKE_GENERATOR MATCHES "Ninja") + add_custom_target(rm_precomp_header ALL + COMMAND ${remove_command} "idlib/precompiled.h.gch" + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMENT "remove idlib/precompiled.h.gch" + ) + add_dependencies(rm_precomp_header RBDoom3BFG) + + # delete precompiled header file after executable is compiled: IDE build case (e.g. Xcode) + else() + add_custom_command(TARGET RBDoom3BFG POST_BUILD + COMMAND ${remove_command} "idlib/precompiled.h.gch" + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMENT "remove idlib/precompiled.h.gch" + ) + endif() + endif() if(NOT WIN32) if(NOT APPLE) From 8fe25bf9876f3f360e05febbab168aaa93ad786b Mon Sep 17 00:00:00 2001 From: Stephen Saunders Date: Wed, 25 Jan 2023 14:23:14 -0500 Subject: [PATCH 03/12] Fix legacy SSAO for NVRHI Vulkan and enable SSAO compute shader alternative --- neo/renderer/Image_intrinsic.cpp | 4 +- neo/renderer/NVRHI/RenderBackend_NVRHI.cpp | 12 ----- neo/renderer/Passes/SsaoPass.cpp | 13 +++-- neo/renderer/Passes/SsaoPass.h | 4 +- neo/renderer/RenderBackend.cpp | 48 ++++++++++++++----- .../builtin/SSAO/AmbientOcclusion_AO.ps.hlsl | 8 ++-- neo/shaders/builtin/SSAO/ssao_blur.cs.hlsl | 12 +++-- neo/shaders/builtin/SSAO/ssao_compute.cs.hlsl | 3 ++ .../builtin/SSAO/ssao_deinterleave.cs.hlsl | 3 ++ neo/shaders/builtin/mipmapgen.cs.hlsl | 4 +- 10 files changed, 67 insertions(+), 44 deletions(-) diff --git a/neo/renderer/Image_intrinsic.cpp b/neo/renderer/Image_intrinsic.cpp index 3ac87991..6b0266fe 100644 --- a/neo/renderer/Image_intrinsic.cpp +++ b/neo/renderer/Image_intrinsic.cpp @@ -1101,8 +1101,8 @@ void idImageManager::CreateIntrinsicImages() gbufferNormalsRoughnessImage = ImageFromFunction( "_currentNormals", R_GeometryBufferImage_ResNative ); - ambientOcclusionImage[0] = ImageFromFunction( "_ao0", R_SMAAImage_ResNative ); - ambientOcclusionImage[1] = ImageFromFunction( "_ao1", R_SMAAImage_ResNative ); + ambientOcclusionImage[0] = ImageFromFunction( "_ao0", R_AmbientOcclusionImage_ResNative ); + ambientOcclusionImage[1] = ImageFromFunction( "_ao1", R_AmbientOcclusionImage_ResNative ); hierarchicalZbufferImage = ImageFromFunction( "_cszBuffer", R_HierarchicalZBufferImage_ResNative ); diff --git a/neo/renderer/NVRHI/RenderBackend_NVRHI.cpp b/neo/renderer/NVRHI/RenderBackend_NVRHI.cpp index ac2b982d..a70e5980 100644 --- a/neo/renderer/NVRHI/RenderBackend_NVRHI.cpp +++ b/neo/renderer/NVRHI/RenderBackend_NVRHI.cpp @@ -249,12 +249,6 @@ void idRenderBackend::Init() currentJointOffset = 0; prevBindingLayoutType = -1; - // RB: FIXME but for now disable it to avoid validation errors - if( deviceManager->GetGraphicsAPI() == nvrhi::GraphicsAPI::VULKAN ) - { - r_useSSAO.SetBool( false ); - } - deviceManager->GetDevice()->waitForIdle(); deviceManager->GetDevice()->runGarbageCollection(); } @@ -1858,12 +1852,6 @@ void idRenderBackend::CheckCVars() r_antiAliasing.ClearModified(); } #endif - - // RB: FIXME but for now disable it to avoid validation errors - if( deviceManager->GetGraphicsAPI() == nvrhi::GraphicsAPI::VULKAN ) - { - r_useSSAO.SetBool( false ); - } } /* diff --git a/neo/renderer/Passes/SsaoPass.cpp b/neo/renderer/Passes/SsaoPass.cpp index d02b747f..7dbbd00f 100644 --- a/neo/renderer/Passes/SsaoPass.cpp +++ b/neo/renderer/Passes/SsaoPass.cpp @@ -34,6 +34,9 @@ If you have questions concerning this license or the applicable additional terms struct SsaoConstants { + idVec2i viewportOrigin; + idVec2i viewportSize; + idVec2 clipToView; idVec2 invQuantizedGbufferSize; @@ -224,7 +227,7 @@ void SsaoPass::CreateBindingSet( void SsaoPass::Render( nvrhi::ICommandList* commandList, const SsaoParameters& params, - viewDef_t* viewDef, + const viewDef_t* viewDef, int bindingSetIndex ) { assert( m_Deinterleave.BindingSets[bindingSetIndex] ); @@ -241,17 +244,19 @@ void SsaoPass::Render( quarterResExtent.maxY = ( quarterResExtent.maxY + 3 ) / 4; SsaoConstants ssaoConstants = {}; + ssaoConstants.viewportOrigin = idVec2i( viewDef->viewport.x1, viewDef->viewport.y1 ); + ssaoConstants.viewportSize = idVec2i( viewDef->viewport.GetWidth(), viewDef->viewport.GetHeight() ); ssaoConstants.clipToView = idVec2( viewDef->projectionMatrix[2 * 4 + 3] / viewDef->projectionMatrix[0 * 4 + 0], - viewDef->projectionMatrix[2 * 4 + 3] / viewDef->projectionMatrix[0 * 4 + 1] ); + viewDef->projectionMatrix[2 * 4 + 3] / viewDef->projectionMatrix[1 * 4 + 1] ); ssaoConstants.invQuantizedGbufferSize = 1.f / m_QuantizedGbufferTextureSize; ssaoConstants.quantizedViewportOrigin = idVec2i( quarterResExtent.minX, quarterResExtent.minY ) * 4; ssaoConstants.amount = params.amount; ssaoConstants.invBackgroundViewDepth = ( params.backgroundViewDepth > 0.f ) ? 1.f / params.backgroundViewDepth : 0.f; ssaoConstants.radiusWorld = params.radiusWorld; ssaoConstants.surfaceBias = params.surfaceBias; - ssaoConstants.powerExponent = params.powerExponent; ssaoConstants.radiusToScreen = 0.5f * viewDef->viewport.GetHeight() * abs( viewDef->projectionMatrix[1 * 4 + 1] ); + ssaoConstants.powerExponent = params.powerExponent; commandList->writeBuffer( m_ConstantBuffer, &ssaoConstants, sizeof( ssaoConstants ) ); uint32_t dispatchWidth = ( quarterResExtent.width() + 7 ) / 8; @@ -277,4 +282,4 @@ void SsaoPass::Render( commandList->dispatch( dispatchWidth, dispatchHeight, 1 ); commandList->endMarker(); -} \ No newline at end of file +} diff --git a/neo/renderer/Passes/SsaoPass.h b/neo/renderer/Passes/SsaoPass.h index edbbcd2c..902e21af 100644 --- a/neo/renderer/Passes/SsaoPass.h +++ b/neo/renderer/Passes/SsaoPass.h @@ -93,8 +93,8 @@ public: void Render( nvrhi::ICommandList* commandList, const SsaoParameters& params, - viewDef_t* viewDef, + const viewDef_t* viewDef, int bindingSetIndex = 0 ); }; -#endif \ No newline at end of file +#endif diff --git a/neo/renderer/RenderBackend.cpp b/neo/renderer/RenderBackend.cpp index 50070c44..320b6d77 100644 --- a/neo/renderer/RenderBackend.cpp +++ b/neo/renderer/RenderBackend.cpp @@ -5878,7 +5878,7 @@ void idRenderBackend::DrawScreenSpaceAmbientOcclusion( const viewDef_t* _viewDef } // FIXME: the hierarchical depth buffer does not work with the MSAA depth texture source - if( r_useSSAO.GetInteger() <= 0 || r_useSSAO.GetInteger() > 1 || R_GetMSAASamples() > 1 ) + if( !r_useSSAO.GetBool() || R_GetMSAASamples() > 1 ) { return; } @@ -5908,7 +5908,6 @@ void idRenderBackend::DrawScreenSpaceAmbientOcclusion( const viewDef_t* _viewDef #if defined( USE_NVRHI ) commandList->clearTextureFloat( globalImages->hierarchicalZbufferImage->GetTextureHandle(), nvrhi::AllSubresources, nvrhi::Color( 1.f ) ); commandList->clearTextureFloat( globalImages->ambientOcclusionImage[0]->GetTextureHandle(), nvrhi::AllSubresources, nvrhi::Color( 1.f ) ); - commandList->clearTextureFloat( globalImages->ambientOcclusionImage[1]->GetTextureHandle(), nvrhi::AllSubresources, nvrhi::Color( 1.f ) ); #endif // build hierarchical depth buffer @@ -6147,6 +6146,10 @@ void idRenderBackend::DrawScreenSpaceAmbientOcclusion( const viewDef_t* _viewDef if( r_ssaoFiltering.GetBool() ) { float jitterTexScale[4]; + +#if defined( USE_NVRHI ) + commandList->clearTextureFloat( globalImages->ambientOcclusionImage[1]->GetTextureHandle(), nvrhi::AllSubresources, nvrhi::Color( 1.f ) ); +#endif // AO blur X globalFramebuffers.ambientOcclusionFBO[1]->Bind(); @@ -6241,7 +6244,7 @@ void idRenderBackend::DrawScreenSpaceAmbientOcclusion2( const viewDef_t* _viewDe return; } - if( r_useSSAO.GetInteger() <= 0 || r_useSSAO.GetInteger() < 2 ) + if( !r_useSSAO.GetBool() ) { return; } @@ -6257,7 +6260,24 @@ void idRenderBackend::DrawScreenSpaceAmbientOcclusion2( const viewDef_t* _viewDe return; } - //GL_CheckErrors(); + renderLog.OpenMainBlock( MRB_SSAO_PASS ); + renderLog.OpenBlock( "Render_NewSSAO", colorBlue ); + + commandList->clearTextureFloat( globalImages->ambientOcclusionImage[0]->GetTextureHandle(), nvrhi::AllSubresources, nvrhi::Color( 1.f ) ); + + SsaoParameters ssaoParams; + // SRS - these are the defaults, but explicitly listed here for testing and possible adjustment + ssaoParams.amount = 2.f; + ssaoParams.backgroundViewDepth = 100.f; + ssaoParams.radiusWorld = 0.5f; + ssaoParams.surfaceBias = .1f; + ssaoParams.powerExponent = 2.f; + ssaoParams.enableBlur = true; + ssaoParams.blurSharpness = 16.f; + ssaoPass->Render( commandList, ssaoParams, _viewDef, 0 ); + + renderLog.CloseBlock(); + renderLog.CloseMainBlock(); #endif } @@ -6600,14 +6620,7 @@ void idRenderBackend::ExecuteBackEndCommands( const emptyCommand_t* cmds ) delete hiZGenPass; } - if( deviceManager->GetGraphicsAPI() == nvrhi::GraphicsAPI::VULKAN ) - { - hiZGenPass = NULL; - } - else - { - hiZGenPass = new MipMapGenPass( deviceManager->GetDevice(), globalImages->hierarchicalZbufferImage->GetTextureHandle() ); - } + hiZGenPass = new MipMapGenPass( deviceManager->GetDevice(), globalImages->hierarchicalZbufferImage->GetTextureHandle() ); } @@ -6854,7 +6867,16 @@ void idRenderBackend::DrawViewInternal( const viewDef_t* _viewDef, const int ste //------------------------------------------------- // build hierarchical depth buffer and SSAO render target //------------------------------------------------- - DrawScreenSpaceAmbientOcclusion( _viewDef, false ); +#if defined( USE_NVRHI ) + if( r_useNewSsaoPass.GetBool() ) + { + DrawScreenSpaceAmbientOcclusion2( _viewDef, false ); + } + else +#endif + { + DrawScreenSpaceAmbientOcclusion( _viewDef, false ); + } //------------------------------------------------- // render static lighting and consider SSAO results diff --git a/neo/shaders/builtin/SSAO/AmbientOcclusion_AO.ps.hlsl b/neo/shaders/builtin/SSAO/AmbientOcclusion_AO.ps.hlsl index ea847563..5d6afbf3 100644 --- a/neo/shaders/builtin/SSAO/AmbientOcclusion_AO.ps.hlsl +++ b/neo/shaders/builtin/SSAO/AmbientOcclusion_AO.ps.hlsl @@ -93,11 +93,11 @@ static const float projScale = 500.0; #define VALUE_TYPE float -Texture2D t_NormalRoughness : register( t0 VK_DESCRIPTOR_SET( 1 ) ); -Texture2D t_ViewDepth : register( t1 VK_DESCRIPTOR_SET( 1 ) ); -Texture2D t_BlueNoise : register( t2 VK_DESCRIPTOR_SET( 1 ) ); +Texture2D t_NormalRoughness : register( t0 VK_DESCRIPTOR_SET( 0 ) ); +Texture2D t_ViewDepth : register( t1 VK_DESCRIPTOR_SET( 0 ) ); +Texture2D t_BlueNoise : register( t2 VK_DESCRIPTOR_SET( 0 ) ); -SamplerState blueNoiseSampler : register( s0 VK_DESCRIPTOR_SET( 2 ) ); +SamplerState blueNoiseSampler : register( s0 VK_DESCRIPTOR_SET( 1 ) ); #define CS_Z_buffer t_ViewDepth diff --git a/neo/shaders/builtin/SSAO/ssao_blur.cs.hlsl b/neo/shaders/builtin/SSAO/ssao_blur.cs.hlsl index e7e9d42c..09c096bf 100644 --- a/neo/shaders/builtin/SSAO/ssao_blur.cs.hlsl +++ b/neo/shaders/builtin/SSAO/ssao_blur.cs.hlsl @@ -26,6 +26,9 @@ struct SsaoConstants { + int2 viewportOrigin; + int2 viewportSize; + float2 clipToView; float2 invQuantizedGbufferSize; @@ -168,10 +171,9 @@ void main( uint2 groupId : SV_GroupID, uint2 threadId : SV_GroupThreadID, uint2 #endif int2 storePos = int2( globalId.xy ) + g_Ssao.quantizedViewportOrigin; - float2 storePosF = float2( storePos ); - //if (all(storePosF >= g_Ssao.view.viewportOrigin.xy) && all(storePosF < g_Ssao.view.viewportOrigin.xy + g_Ssao.view.viewportSize.xy)) - //{ - // u_RenderTarget[storePos] = totalOcclusion; - //} + if (all(storePos >= g_Ssao.viewportOrigin.xy) && all(storePos < g_Ssao.viewportOrigin.xy + g_Ssao.viewportSize.xy)) + { + u_RenderTarget[storePos] = totalOcclusion; + } } diff --git a/neo/shaders/builtin/SSAO/ssao_compute.cs.hlsl b/neo/shaders/builtin/SSAO/ssao_compute.cs.hlsl index 902ad610..12a880f4 100644 --- a/neo/shaders/builtin/SSAO/ssao_compute.cs.hlsl +++ b/neo/shaders/builtin/SSAO/ssao_compute.cs.hlsl @@ -26,6 +26,9 @@ struct SsaoConstants { + int2 viewportOrigin; + int2 viewportSize; + float2 clipToView; float2 invQuantizedGbufferSize; diff --git a/neo/shaders/builtin/SSAO/ssao_deinterleave.cs.hlsl b/neo/shaders/builtin/SSAO/ssao_deinterleave.cs.hlsl index 695c90a2..371fdf95 100644 --- a/neo/shaders/builtin/SSAO/ssao_deinterleave.cs.hlsl +++ b/neo/shaders/builtin/SSAO/ssao_deinterleave.cs.hlsl @@ -26,6 +26,9 @@ struct SsaoConstants { + int2 viewportOrigin; + int2 viewportSize; + float2 clipToView; float2 invQuantizedGbufferSize; diff --git a/neo/shaders/builtin/mipmapgen.cs.hlsl b/neo/shaders/builtin/mipmapgen.cs.hlsl index 145db1e2..715eb0ab 100644 --- a/neo/shaders/builtin/mipmapgen.cs.hlsl +++ b/neo/shaders/builtin/mipmapgen.cs.hlsl @@ -83,7 +83,7 @@ cbuffer c_MipMapgen : register( b0 ) MipmmapGenConstants g_MipMapGen; }; -RWTexture2D u_output[NUM_LODS] : register( u0 ); +RWTexture2D u_output[] : register( u0 ); Texture2D t_input : register( t0 ); // *INDENT-ON* @@ -138,4 +138,4 @@ groupshared VALUE_TYPE s_ReductionData[GROUP_SIZE][GROUP_SIZE]; GroupMemoryBarrierWithGroupSync(); } -} \ No newline at end of file +} From a466a7a4ad5c600d7af98f46b4cd62a7b7b79067 Mon Sep 17 00:00:00 2001 From: Stephen Saunders Date: Wed, 25 Jan 2023 21:08:25 -0500 Subject: [PATCH 04/12] Restore bounded array in mipmapgen.cs.hlsl for DXIL UAV binding --- neo/shaders/builtin/mipmapgen.cs.hlsl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/neo/shaders/builtin/mipmapgen.cs.hlsl b/neo/shaders/builtin/mipmapgen.cs.hlsl index 715eb0ab..5266a9cb 100644 --- a/neo/shaders/builtin/mipmapgen.cs.hlsl +++ b/neo/shaders/builtin/mipmapgen.cs.hlsl @@ -83,7 +83,11 @@ cbuffer c_MipMapgen : register( b0 ) MipmmapGenConstants g_MipMapGen; }; +#ifdef __spirv__ // use unbounded array size for proper SPIR-V descriptor binding RWTexture2D u_output[] : register( u0 ); +#else // use bounded array for DXIL -flegacy-resource-reservation flag +RWTexture2D u_output[NUM_LODS] : register( u0 ); +#endif Texture2D t_input : register( t0 ); // *INDENT-ON* From 866244ffdd6a643e964ff9e02aced848eacbf88b Mon Sep 17 00:00:00 2001 From: Stephen Saunders Date: Sun, 29 Jan 2023 02:01:15 -0500 Subject: [PATCH 05/12] Fix AmbientOcclusion_blur.ps.hlsl shader for legacy r_ssaoFiltering option --- neo/shaders/builtin/SSAO/AmbientOcclusion_blur.ps.hlsl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/neo/shaders/builtin/SSAO/AmbientOcclusion_blur.ps.hlsl b/neo/shaders/builtin/SSAO/AmbientOcclusion_blur.ps.hlsl index b178d296..335c85a7 100644 --- a/neo/shaders/builtin/SSAO/AmbientOcclusion_blur.ps.hlsl +++ b/neo/shaders/builtin/SSAO/AmbientOcclusion_blur.ps.hlsl @@ -22,9 +22,9 @@ // *INDENT-OFF* #define VALUE_TYPE float -Texture2D t_NormalRoughness : register( t0 VK_DESCRIPTOR_SET( 1 ) ); -Texture2D t_ViewDepth : register( t1 VK_DESCRIPTOR_SET( 1 ) ); -Texture2D t_Ao : register( t2 VK_DESCRIPTOR_SET( 1 ) ); +Texture2D t_NormalRoughness : register( t0 VK_DESCRIPTOR_SET( 0 ) ); +Texture2D t_ViewDepth : register( t1 VK_DESCRIPTOR_SET( 0 ) ); +Texture2D t_Ao : register( t2 VK_DESCRIPTOR_SET( 0 ) ); #define normal_buffer t_NormalRoughness #define cszBuffer t_ViewDepth @@ -103,7 +103,7 @@ float3 sampleNormal( Texture2D normalBuffer, int2 ssC, int mipLevel ) /** Used for preventing AO computation on the sky (at infinite depth) and defining the CS Z to bilateral depth key scaling. This need not match the real far plane but should not be much more than it.*/ -const float FAR_PLANE_Z = -16000.0; +static const float FAR_PLANE_Z = -16000.0; float CSZToKey( float z ) { From 6d83ad0f8d20ccd4de71a6f26f7358e4549d20b2 Mon Sep 17 00:00:00 2001 From: Stephen Saunders Date: Sun, 29 Jan 2023 23:38:40 -0500 Subject: [PATCH 06/12] Include modelMatrix in new SSAO compute shader constant buffer --- neo/renderer/Passes/SsaoPass.cpp | 14 ++++++++--- neo/shaders/builtin/SSAO/ssao_blur.cs.hlsl | 12 ++++++--- neo/shaders/builtin/SSAO/ssao_compute.cs.hlsl | 25 +++++++++++-------- .../builtin/SSAO/ssao_deinterleave.cs.hlsl | 17 ++++++++----- 4 files changed, 45 insertions(+), 23 deletions(-) diff --git a/neo/renderer/Passes/SsaoPass.cpp b/neo/renderer/Passes/SsaoPass.cpp index 7dbbd00f..b3878054 100644 --- a/neo/renderer/Passes/SsaoPass.cpp +++ b/neo/renderer/Passes/SsaoPass.cpp @@ -34,8 +34,13 @@ If you have questions concerning this license or the applicable additional terms struct SsaoConstants { - idVec2i viewportOrigin; - idVec2i viewportSize; + idVec2 viewportOrigin; + idVec2 viewportSize; + + idVec4 modelMatrixX; + idVec4 modelMatrixY; + idVec4 modelMatrixZ; + idVec4 modelMatrixW; idVec2 clipToView; idVec2 invQuantizedGbufferSize; @@ -244,8 +249,9 @@ void SsaoPass::Render( quarterResExtent.maxY = ( quarterResExtent.maxY + 3 ) / 4; SsaoConstants ssaoConstants = {}; - ssaoConstants.viewportOrigin = idVec2i( viewDef->viewport.x1, viewDef->viewport.y1 ); - ssaoConstants.viewportSize = idVec2i( viewDef->viewport.GetWidth(), viewDef->viewport.GetHeight() ); + ssaoConstants.viewportOrigin = idVec2( viewDef->viewport.x1, viewDef->viewport.y1 ); + ssaoConstants.viewportSize = idVec2( viewDef->viewport.GetWidth(), viewDef->viewport.GetHeight() ); + idRenderMatrix::CopyMatrix( *( idRenderMatrix* )viewDef->worldSpace.modelMatrix, ssaoConstants.modelMatrixX, ssaoConstants.modelMatrixY, ssaoConstants.modelMatrixZ, ssaoConstants.modelMatrixW ); ssaoConstants.clipToView = idVec2( viewDef->projectionMatrix[2 * 4 + 3] / viewDef->projectionMatrix[0 * 4 + 0], viewDef->projectionMatrix[2 * 4 + 3] / viewDef->projectionMatrix[1 * 4 + 1] ); diff --git a/neo/shaders/builtin/SSAO/ssao_blur.cs.hlsl b/neo/shaders/builtin/SSAO/ssao_blur.cs.hlsl index 09c096bf..e3837d07 100644 --- a/neo/shaders/builtin/SSAO/ssao_blur.cs.hlsl +++ b/neo/shaders/builtin/SSAO/ssao_blur.cs.hlsl @@ -26,8 +26,13 @@ struct SsaoConstants { - int2 viewportOrigin; - int2 viewportSize; + float2 viewportOrigin; + float2 viewportSize; + + float4 modelMatrixX; + float4 modelMatrixY; + float4 modelMatrixZ; + float4 modelMatrixW; float2 clipToView; float2 invQuantizedGbufferSize; @@ -171,8 +176,9 @@ void main( uint2 groupId : SV_GroupID, uint2 threadId : SV_GroupThreadID, uint2 #endif int2 storePos = int2( globalId.xy ) + g_Ssao.quantizedViewportOrigin; + float2 storePosF = float2( storePos ); - if (all(storePos >= g_Ssao.viewportOrigin.xy) && all(storePos < g_Ssao.viewportOrigin.xy + g_Ssao.viewportSize.xy)) + if (all(storePosF >= g_Ssao.viewportOrigin.xy) && all(storePosF < g_Ssao.viewportOrigin.xy + g_Ssao.viewportSize.xy)) { u_RenderTarget[storePos] = totalOcclusion; } diff --git a/neo/shaders/builtin/SSAO/ssao_compute.cs.hlsl b/neo/shaders/builtin/SSAO/ssao_compute.cs.hlsl index 12a880f4..faa2d346 100644 --- a/neo/shaders/builtin/SSAO/ssao_compute.cs.hlsl +++ b/neo/shaders/builtin/SSAO/ssao_compute.cs.hlsl @@ -26,8 +26,13 @@ struct SsaoConstants { - int2 viewportOrigin; - int2 viewportSize; + float2 viewportOrigin; + float2 viewportSize; + + float4 modelMatrixX; + float4 modelMatrixY; + float4 modelMatrixZ; + float4 modelMatrixW; float2 clipToView; float2 invQuantizedGbufferSize; @@ -172,8 +177,8 @@ float ComputeAO( float3 V, float3 N, float InvR2 ) float2 WindowToClip( float2 windowPos ) { - float2 clipToWindowScale = float2( 0.5f * rpWindowCoord.z, -0.5f * rpWindowCoord.w ); - float2 clipToWindowBias = rpViewOrigin.xy + rpWindowCoord.zw * 0.5f; + float2 clipToWindowScale = float2( 0.5f * g_Ssao.viewportSize.x, -0.5f * g_Ssao.viewportSize.y ); + float2 clipToWindowBias = g_Ssao.viewportOrigin.xy + g_Ssao.viewportSize.xy * 0.5f; float2 windowToClipScale = 1.f / clipToWindowScale; float2 windowToClipBias = -clipToWindowBias * windowToClipScale; @@ -204,9 +209,9 @@ void main( uint3 globalId : SV_DispatchThreadID ) // View to clip space. float3 pN; - pN.x = dot4( float4( pixelNormal, 0 ), rpModelMatrixX ); - pN.y = dot4( float4( pixelNormal, 0 ), rpModelMatrixY ); - pN.z = dot4( float4( pixelNormal, 0 ), rpModelMatrixZ ); + pN.x = dot4( float4( pixelNormal, 0 ), g_Ssao.modelMatrixX ); + pN.y = dot4( float4( pixelNormal, 0 ), g_Ssao.modelMatrixY ); + pN.z = dot4( float4( pixelNormal, 0 ), g_Ssao.modelMatrixZ ); pixelNormal = normalize( pN ); @@ -272,9 +277,9 @@ void main( uint3 globalId : SV_DispatchThreadID ) if( directionalLength > 0 ) { float3 worldSpaceResult; - worldSpaceResult.x = dot4( float4( normalize( result.xyz ), 0 ), rpModelMatrixX ); - worldSpaceResult.y = dot4( float4( normalize( result.xyz ), 0 ), rpModelMatrixY ); - worldSpaceResult.z = dot4( float4( normalize( result.xyz ), 0 ), rpModelMatrixZ ); + worldSpaceResult.x = dot4( float4( normalize( result.xyz ), 0 ), g_Ssao.modelMatrixX ); + worldSpaceResult.y = dot4( float4( normalize( result.xyz ), 0 ), g_Ssao.modelMatrixY ); + worldSpaceResult.z = dot4( float4( normalize( result.xyz ), 0 ), g_Ssao.modelMatrixZ ); result.xyz = worldSpaceResult.xyz * directionalLength; } diff --git a/neo/shaders/builtin/SSAO/ssao_deinterleave.cs.hlsl b/neo/shaders/builtin/SSAO/ssao_deinterleave.cs.hlsl index 371fdf95..4a6dd8f9 100644 --- a/neo/shaders/builtin/SSAO/ssao_deinterleave.cs.hlsl +++ b/neo/shaders/builtin/SSAO/ssao_deinterleave.cs.hlsl @@ -26,8 +26,13 @@ struct SsaoConstants { - int2 viewportOrigin; - int2 viewportSize; + float2 viewportOrigin; + float2 viewportSize; + + float4 modelMatrixX; + float4 modelMatrixY; + float4 modelMatrixZ; + float4 modelMatrixW; float2 clipToView; float2 invQuantizedGbufferSize; @@ -72,10 +77,10 @@ void main( uint3 globalId : SV_DispatchThreadID ) #else float4 clipPos = float4( 0, 0, depth, 1 ); float4 viewPos; - viewPos.x = dot4( clipPos, rpModelMatrixX ); - viewPos.y = dot4( clipPos, rpModelMatrixY ); - viewPos.z = dot4( clipPos, rpModelMatrixZ ); - viewPos.w = dot4( clipPos, rpModelMatrixW ); + viewPos.x = dot4( clipPos, g_Ssao.modelMatrixX ); + viewPos.y = dot4( clipPos, g_Ssao.modelMatrixY ); + viewPos.z = dot4( clipPos, g_Ssao.modelMatrixZ ); + viewPos.w = dot4( clipPos, g_Ssao.modelMatrixW ); float linearDepth = viewPos.z / viewPos.w; #endif From c7ad3f2801bbb09bdd677c4c6829a10eed5a130b Mon Sep 17 00:00:00 2001 From: Stephen Saunders Date: Mon, 30 Jan 2023 16:00:51 -0500 Subject: [PATCH 07/12] Add required render matrices to SsaoConstants and init them for render pass --- neo/renderer/Passes/SsaoPass.cpp | 17 +++++++++----- neo/renderer/RenderBackend.cpp | 3 ++- neo/shaders/builtin/SSAO/ssao_blur.cs.hlsl | 7 +++--- neo/shaders/builtin/SSAO/ssao_compute.cs.hlsl | 22 +++++-------------- .../builtin/SSAO/ssao_deinterleave.cs.hlsl | 14 ++++-------- 5 files changed, 25 insertions(+), 38 deletions(-) diff --git a/neo/renderer/Passes/SsaoPass.cpp b/neo/renderer/Passes/SsaoPass.cpp index b3878054..64ab246e 100644 --- a/neo/renderer/Passes/SsaoPass.cpp +++ b/neo/renderer/Passes/SsaoPass.cpp @@ -36,11 +36,10 @@ struct SsaoConstants { idVec2 viewportOrigin; idVec2 viewportSize; - - idVec4 modelMatrixX; - idVec4 modelMatrixY; - idVec4 modelMatrixZ; - idVec4 modelMatrixW; + + idRenderMatrix matClipToView; + idRenderMatrix matWorldToView; + idRenderMatrix matViewToWorld; idVec2 clipToView; idVec2 invQuantizedGbufferSize; @@ -251,7 +250,13 @@ void SsaoPass::Render( SsaoConstants ssaoConstants = {}; ssaoConstants.viewportOrigin = idVec2( viewDef->viewport.x1, viewDef->viewport.y1 ); ssaoConstants.viewportSize = idVec2( viewDef->viewport.GetWidth(), viewDef->viewport.GetHeight() ); - idRenderMatrix::CopyMatrix( *( idRenderMatrix* )viewDef->worldSpace.modelMatrix, ssaoConstants.modelMatrixX, ssaoConstants.modelMatrixY, ssaoConstants.modelMatrixZ, ssaoConstants.modelMatrixW ); + + // SRS - FIXME: These transformations need to be verified + ssaoConstants.matClipToView = viewDef->unprojectionToCameraRenderMatrix; + ssaoConstants.matViewToWorld = viewDef->unprojectionToWorldRenderMatrix; + idRenderMatrix::Inverse( ssaoConstants.matViewToWorld, ssaoConstants.matWorldToView ); + // SRS end + ssaoConstants.clipToView = idVec2( viewDef->projectionMatrix[2 * 4 + 3] / viewDef->projectionMatrix[0 * 4 + 0], viewDef->projectionMatrix[2 * 4 + 3] / viewDef->projectionMatrix[1 * 4 + 1] ); diff --git a/neo/renderer/RenderBackend.cpp b/neo/renderer/RenderBackend.cpp index 320b6d77..ce0aacfb 100644 --- a/neo/renderer/RenderBackend.cpp +++ b/neo/renderer/RenderBackend.cpp @@ -6241,7 +6241,8 @@ void idRenderBackend::DrawScreenSpaceAmbientOcclusion2( const viewDef_t* _viewDe if( !_viewDef->viewEntitys || _viewDef->is2Dgui ) { // 3D views only - return; + // FIXME: Disable for now until flickering problem is solved + //return; } if( !r_useSSAO.GetBool() ) diff --git a/neo/shaders/builtin/SSAO/ssao_blur.cs.hlsl b/neo/shaders/builtin/SSAO/ssao_blur.cs.hlsl index e3837d07..ed92dfa8 100644 --- a/neo/shaders/builtin/SSAO/ssao_blur.cs.hlsl +++ b/neo/shaders/builtin/SSAO/ssao_blur.cs.hlsl @@ -29,10 +29,9 @@ struct SsaoConstants float2 viewportOrigin; float2 viewportSize; - float4 modelMatrixX; - float4 modelMatrixY; - float4 modelMatrixZ; - float4 modelMatrixW; + float4x4 matClipToView; + float4x4 matWorldToView; + float4x4 matViewToWorld; float2 clipToView; float2 invQuantizedGbufferSize; diff --git a/neo/shaders/builtin/SSAO/ssao_compute.cs.hlsl b/neo/shaders/builtin/SSAO/ssao_compute.cs.hlsl index faa2d346..2fab661c 100644 --- a/neo/shaders/builtin/SSAO/ssao_compute.cs.hlsl +++ b/neo/shaders/builtin/SSAO/ssao_compute.cs.hlsl @@ -29,10 +29,9 @@ struct SsaoConstants float2 viewportOrigin; float2 viewportSize; - float4 modelMatrixX; - float4 modelMatrixY; - float4 modelMatrixZ; - float4 modelMatrixW; + float4x4 matClipToView; + float4x4 matWorldToView; + float4x4 matViewToWorld; float2 clipToView; float2 invQuantizedGbufferSize; @@ -207,13 +206,7 @@ void main( uint3 globalId : SV_DispatchThreadID ) float3 pixelNormal = t_Normals[pixelPos].xyz; #endif - // View to clip space. - float3 pN; - pN.x = dot4( float4( pixelNormal, 0 ), g_Ssao.modelMatrixX ); - pN.y = dot4( float4( pixelNormal, 0 ), g_Ssao.modelMatrixY ); - pN.z = dot4( float4( pixelNormal, 0 ), g_Ssao.modelMatrixZ ); - - pixelNormal = normalize( pN ); + pixelNormal = normalize(mul(float4(pixelNormal, 0), g_Ssao.matWorldToView).xyz); float2 pixelClipPos = WindowToClip( pixelPos ); float3 pixelViewPos = ViewDepthToViewPos( pixelClipPos.xy, pixelViewDepth ); @@ -276,12 +269,7 @@ void main( uint3 globalId : SV_DispatchThreadID ) float directionalLength = length( result.xyz ); if( directionalLength > 0 ) { - float3 worldSpaceResult; - worldSpaceResult.x = dot4( float4( normalize( result.xyz ), 0 ), g_Ssao.modelMatrixX ); - worldSpaceResult.y = dot4( float4( normalize( result.xyz ), 0 ), g_Ssao.modelMatrixY ); - worldSpaceResult.z = dot4( float4( normalize( result.xyz ), 0 ), g_Ssao.modelMatrixZ ); - - result.xyz = worldSpaceResult.xyz * directionalLength; + result.xyz = mul(float4(normalize(result.xyz), 0), g_Ssao.matViewToWorld).xyz * directionalLength; } #endif diff --git a/neo/shaders/builtin/SSAO/ssao_deinterleave.cs.hlsl b/neo/shaders/builtin/SSAO/ssao_deinterleave.cs.hlsl index 4a6dd8f9..3921f1de 100644 --- a/neo/shaders/builtin/SSAO/ssao_deinterleave.cs.hlsl +++ b/neo/shaders/builtin/SSAO/ssao_deinterleave.cs.hlsl @@ -29,10 +29,9 @@ struct SsaoConstants float2 viewportOrigin; float2 viewportSize; - float4 modelMatrixX; - float4 modelMatrixY; - float4 modelMatrixZ; - float4 modelMatrixW; + float4x4 matClipToView; + float4x4 matWorldToView; + float4x4 matViewToWorld; float2 clipToView; float2 invQuantizedGbufferSize; @@ -76,12 +75,7 @@ void main( uint3 globalId : SV_DispatchThreadID ) float linearDepth = depth; #else float4 clipPos = float4( 0, 0, depth, 1 ); - float4 viewPos; - viewPos.x = dot4( clipPos, g_Ssao.modelMatrixX ); - viewPos.y = dot4( clipPos, g_Ssao.modelMatrixY ); - viewPos.z = dot4( clipPos, g_Ssao.modelMatrixZ ); - viewPos.w = dot4( clipPos, g_Ssao.modelMatrixW ); - + float4 viewPos = mul(clipPos, g_Ssao.matClipToView); float linearDepth = viewPos.z / viewPos.w; #endif From 0f869604c9c478bb986b3c5ddc8c4874f3e565f3 Mon Sep 17 00:00:00 2001 From: Stephen Saunders Date: Fri, 3 Feb 2023 17:20:25 -0500 Subject: [PATCH 08/12] Run new ssao pass on 3d + 2d overlay views to avoid flickering, skip for 2d-only views --- neo/renderer/RenderBackend.cpp | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/neo/renderer/RenderBackend.cpp b/neo/renderer/RenderBackend.cpp index ce0aacfb..e99eae6a 100644 --- a/neo/renderer/RenderBackend.cpp +++ b/neo/renderer/RenderBackend.cpp @@ -58,6 +58,8 @@ idCVar r_useLightStencilSelect( "r_useLightStencilSelect", "0", CVAR_RENDERER | extern idCVar stereoRender_swapEyes; +// SRS - flag indicating whether we are drawing a 3d view vs. a 2d-only view (e.g. menu or pda) +bool drawView3D; /* ================ @@ -6238,11 +6240,11 @@ NVRHI SSAO using compute shaders. */ void idRenderBackend::DrawScreenSpaceAmbientOcclusion2( const viewDef_t* _viewDef, bool downModulateScreen ) { - if( !_viewDef->viewEntitys || _viewDef->is2Dgui ) + // SRS - run ssao pass on 3d + 2d overlay views to avoid flickering, skip for 2d-only views (menu & pda) + if( ( !_viewDef->viewEntitys || _viewDef->is2Dgui ) && !drawView3D ) { // 3D views only - // FIXME: Disable for now until flickering problem is solved - //return; + return; } if( !r_useSSAO.GetBool() ) @@ -6266,15 +6268,7 @@ void idRenderBackend::DrawScreenSpaceAmbientOcclusion2( const viewDef_t* _viewDe commandList->clearTextureFloat( globalImages->ambientOcclusionImage[0]->GetTextureHandle(), nvrhi::AllSubresources, nvrhi::Color( 1.f ) ); - SsaoParameters ssaoParams; - // SRS - these are the defaults, but explicitly listed here for testing and possible adjustment - ssaoParams.amount = 2.f; - ssaoParams.backgroundViewDepth = 100.f; - ssaoParams.radiusWorld = 0.5f; - ssaoParams.surfaceBias = .1f; - ssaoParams.powerExponent = 2.f; - ssaoParams.enableBlur = true; - ssaoParams.blurSharpness = 16.f; + SsaoParameters ssaoParams = {}; ssaoPass->Render( commandList, ssaoParams, _viewDef, 0 ); renderLog.CloseBlock(); @@ -6655,7 +6649,7 @@ void idRenderBackend::ExecuteBackEndCommands( const emptyCommand_t* cmds ) // SRS - Save glConfig.timerQueryAvailable state so it can be disabled for RC_DRAW_VIEW_GUI then restored after it is finished const bool timerQueryAvailable = glConfig.timerQueryAvailable; - bool drawView3D_timestamps = false; + drawView3D = false; for( ; cmds != NULL; cmds = ( const emptyCommand_t* )cmds->next ) { @@ -6665,7 +6659,7 @@ void idRenderBackend::ExecuteBackEndCommands( const emptyCommand_t* cmds ) break; case RC_DRAW_VIEW_GUI: - if( drawView3D_timestamps ) + if( drawView3D ) { // SRS - Capture separate timestamps for overlay GUI rendering when RC_DRAW_VIEW_3D timestamps are active renderLog.OpenMainBlock( MRB_DRAW_GUI ); @@ -6688,7 +6682,7 @@ void idRenderBackend::ExecuteBackEndCommands( const emptyCommand_t* cmds ) break; case RC_DRAW_VIEW_3D: - drawView3D_timestamps = true; + drawView3D = true; DrawView( cmds, 0 ); c_draw3d++; break; From 050c766f9dc319d170e4a381538b7170692b7c35 Mon Sep 17 00:00:00 2001 From: Stephen Saunders Date: Sat, 4 Feb 2023 01:08:46 -0500 Subject: [PATCH 09/12] Optimization: Skip ssao compute step for 2d gui overlay views --- neo/renderer/Passes/SsaoPass.cpp | 40 ++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/neo/renderer/Passes/SsaoPass.cpp b/neo/renderer/Passes/SsaoPass.cpp index 64ab246e..8e9145e1 100644 --- a/neo/renderer/Passes/SsaoPass.cpp +++ b/neo/renderer/Passes/SsaoPass.cpp @@ -269,28 +269,32 @@ void SsaoPass::Render( ssaoConstants.radiusToScreen = 0.5f * viewDef->viewport.GetHeight() * abs( viewDef->projectionMatrix[1 * 4 + 1] ); ssaoConstants.powerExponent = params.powerExponent; commandList->writeBuffer( m_ConstantBuffer, &ssaoConstants, sizeof( ssaoConstants ) ); + + // SRS - after writing constant buffer, compute ssao for 3d views only + if( viewDef->viewEntitys && !viewDef->is2Dgui ) + { + uint32_t dispatchWidth = ( quarterResExtent.width() + 7 ) / 8; + uint32_t dispatchHeight = ( quarterResExtent.height() + 7 ) / 8; - uint32_t dispatchWidth = ( quarterResExtent.width() + 7 ) / 8; - uint32_t dispatchHeight = ( quarterResExtent.height() + 7 ) / 8; + nvrhi::ComputeState state; + state.pipeline = m_Deinterleave.Pipeline; + state.bindings = { m_Deinterleave.BindingSets[bindingSetIndex] }; + commandList->setComputeState( state ); + commandList->dispatch( dispatchWidth, dispatchHeight, 1 ); - nvrhi::ComputeState state; - state.pipeline = m_Deinterleave.Pipeline; - state.bindings = { m_Deinterleave.BindingSets[bindingSetIndex] }; - commandList->setComputeState( state ); - commandList->dispatch( dispatchWidth, dispatchHeight, 1 ); + state.pipeline = m_Compute.Pipeline; + state.bindings = { m_Compute.BindingSets[bindingSetIndex] }; + commandList->setComputeState( state ); + commandList->dispatch( dispatchWidth, dispatchHeight, 16 ); - state.pipeline = m_Compute.Pipeline; - state.bindings = { m_Compute.BindingSets[bindingSetIndex] }; - commandList->setComputeState( state ); - commandList->dispatch( dispatchWidth, dispatchHeight, 16 ); + dispatchWidth = ( viewExtent.width() + 15 ) / 16; + dispatchHeight = ( viewExtent.height() + 15 ) / 16; - dispatchWidth = ( viewExtent.width() + 15 ) / 16; - dispatchHeight = ( viewExtent.height() + 15 ) / 16; - - state.pipeline = m_Blur.Pipeline; - state.bindings = { m_Blur.BindingSets[bindingSetIndex] }; - commandList->setComputeState( state ); - commandList->dispatch( dispatchWidth, dispatchHeight, 1 ); + state.pipeline = m_Blur.Pipeline; + state.bindings = { m_Blur.BindingSets[bindingSetIndex] }; + commandList->setComputeState( state ); + commandList->dispatch( dispatchWidth, dispatchHeight, 1 ); + } commandList->endMarker(); } From 846cf265fbd7fc93408bbdb8ade7e53251c723cd Mon Sep 17 00:00:00 2001 From: Robert Beckebans Date: Tue, 7 Feb 2023 15:06:40 +0100 Subject: [PATCH 10/12] Added code for debugging Donut's SSAO pass --- neo/renderer/GLMatrix.cpp | 7 +- neo/renderer/NVRHI/RenderBackend_NVRHI.cpp | 4 - neo/renderer/Passes/SsaoPass.cpp | 129 +++++++++--------- neo/renderer/Passes/SsaoPass.h | 47 +++---- neo/renderer/RenderBackend.cpp | 16 +-- .../builtin/SSAO/AmbientOcclusion_AO.ps.hlsl | 3 +- neo/shaders/builtin/SSAO/ssao_blur.cs.hlsl | 2 +- neo/shaders/builtin/SSAO/ssao_compute.cs.hlsl | 6 +- .../builtin/SSAO/ssao_deinterleave.cs.hlsl | 3 +- .../DeepGBufferRadiosity_radiosity.ps.hlsl | 3 - neo/shaders/global_inc.hlsl | 76 +---------- 11 files changed, 106 insertions(+), 190 deletions(-) diff --git a/neo/renderer/GLMatrix.cpp b/neo/renderer/GLMatrix.cpp index a23d4341..899a00d2 100644 --- a/neo/renderer/GLMatrix.cpp +++ b/neo/renderer/GLMatrix.cpp @@ -4,6 +4,7 @@ Doom 3 BFG Edition GPL Source Code Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. Copyright (C) 2014 Robert Beckebans +Copyright (C) 2022 Stephen Pridham This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code"). @@ -537,13 +538,7 @@ void R_SetupProjectionMatrix( viewDef_t* viewDef, bool doJitter ) projectionMatrix[3 * 4 + 0] = 0.0f; projectionMatrix[0 * 4 + 1] = 0.0f; - - // RB: Y axis now points down the screen -#if defined(USE_VULKAN) - projectionMatrix[1 * 4 + 1] = -2.0f * zNear / height; -#else projectionMatrix[1 * 4 + 1] = 2.0f * zNear / height; -#endif projectionMatrix[2 * 4 + 1] = yoffset; projectionMatrix[3 * 4 + 1] = 0.0f; diff --git a/neo/renderer/NVRHI/RenderBackend_NVRHI.cpp b/neo/renderer/NVRHI/RenderBackend_NVRHI.cpp index a70e5980..49c1bbad 100644 --- a/neo/renderer/NVRHI/RenderBackend_NVRHI.cpp +++ b/neo/renderer/NVRHI/RenderBackend_NVRHI.cpp @@ -1749,10 +1749,6 @@ void idRenderBackend::GL_Clear( bool color, bool depth, bool stencil, byte stenc if( depth || stencil ) { nvrhi::utils::ClearDepthStencilAttachment( commandList, framebuffer, 1.0f, stencilValue ); - - //nvrhi::ITexture* depthTexture = ( nvrhi::ITexture* )( globalImages->currentDepthImage->GetTextureID() ); - //const nvrhi::FormatInfo& depthFormatInfo = nvrhi::getFormatInfo( depthTexture->getDesc().format ); - //commandList->clearDepthStencilTexture( depthTexture, nvrhi::AllSubresources, depth, 1.f, depthFormatInfo.hasStencil, stencilValue ); } } diff --git a/neo/renderer/Passes/SsaoPass.cpp b/neo/renderer/Passes/SsaoPass.cpp index 8e9145e1..5ec20170 100644 --- a/neo/renderer/Passes/SsaoPass.cpp +++ b/neo/renderer/Passes/SsaoPass.cpp @@ -1,29 +1,23 @@ /* -=========================================================================== - -Doom 3 BFG Edition GPL Source Code -Copyright (C) 2022 Stephen Pridham - -This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code"). - -Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Doom 3 BFG Edition Source Code. If not, see . - -In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below. - -If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. - -=========================================================================== +* Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +* DEALINGS IN THE SOFTWARE. */ #include #pragma hdrstop @@ -32,11 +26,19 @@ If you have questions concerning this license or the applicable additional terms #include "SsaoPass.h" + +static idCVar r_ssaoBackgroundViewDepth( "r_ssaoBackgroundViewDepth", "100", CVAR_RENDERER | CVAR_FLOAT, "" ); +static idCVar r_ssaoRadiusWorld( "r_ssaoRadiusWorld", "0.5", CVAR_RENDERER | CVAR_FLOAT, "" ); +static idCVar r_ssaoSurfaceBias( "r_ssaoSurfaceBias", "0.1", CVAR_RENDERER | CVAR_FLOAT, "" ); +static idCVar r_ssaoPowerExponent( "r_ssaoSurfaceBias", "2", CVAR_RENDERER | CVAR_FLOAT, "" ); +static idCVar r_ssaoBlurSharpness( "r_ssaoBlurSharpness", "16", CVAR_RENDERER | CVAR_FLOAT, "" ); +static idCVar r_ssaoAmount( "r_ssaoAmount", "2", CVAR_RENDERER | CVAR_FLOAT, "" ); + struct SsaoConstants { idVec2 viewportOrigin; idVec2 viewportSize; - + idRenderMatrix matClipToView; idRenderMatrix matWorldToView; idRenderMatrix matViewToWorld; @@ -230,7 +232,6 @@ void SsaoPass::CreateBindingSet( void SsaoPass::Render( nvrhi::ICommandList* commandList, - const SsaoParameters& params, const viewDef_t* viewDef, int bindingSetIndex ) { @@ -238,41 +239,45 @@ void SsaoPass::Render( assert( m_Compute.BindingSets[bindingSetIndex] ); assert( m_Blur.BindingSets[bindingSetIndex] ); - commandList->beginMarker( "SSAO" ); - - nvrhi::Rect viewExtent( viewDef->viewport.x1, viewDef->viewport.x2, viewDef->viewport.y1, viewDef->viewport.y2 ); - nvrhi::Rect quarterResExtent = viewExtent; - quarterResExtent.minX /= 4; - quarterResExtent.minY /= 4; - quarterResExtent.maxX = ( quarterResExtent.maxX + 3 ) / 4; - quarterResExtent.maxY = ( quarterResExtent.maxY + 3 ) / 4; - - SsaoConstants ssaoConstants = {}; - ssaoConstants.viewportOrigin = idVec2( viewDef->viewport.x1, viewDef->viewport.y1 ); - ssaoConstants.viewportSize = idVec2( viewDef->viewport.GetWidth(), viewDef->viewport.GetHeight() ); - - // SRS - FIXME: These transformations need to be verified - ssaoConstants.matClipToView = viewDef->unprojectionToCameraRenderMatrix; - ssaoConstants.matViewToWorld = viewDef->unprojectionToWorldRenderMatrix; - idRenderMatrix::Inverse( ssaoConstants.matViewToWorld, ssaoConstants.matWorldToView ); - // SRS end - - ssaoConstants.clipToView = idVec2( - viewDef->projectionMatrix[2 * 4 + 3] / viewDef->projectionMatrix[0 * 4 + 0], - viewDef->projectionMatrix[2 * 4 + 3] / viewDef->projectionMatrix[1 * 4 + 1] ); - ssaoConstants.invQuantizedGbufferSize = 1.f / m_QuantizedGbufferTextureSize; - ssaoConstants.quantizedViewportOrigin = idVec2i( quarterResExtent.minX, quarterResExtent.minY ) * 4; - ssaoConstants.amount = params.amount; - ssaoConstants.invBackgroundViewDepth = ( params.backgroundViewDepth > 0.f ) ? 1.f / params.backgroundViewDepth : 0.f; - ssaoConstants.radiusWorld = params.radiusWorld; - ssaoConstants.surfaceBias = params.surfaceBias; - ssaoConstants.radiusToScreen = 0.5f * viewDef->viewport.GetHeight() * abs( viewDef->projectionMatrix[1 * 4 + 1] ); - ssaoConstants.powerExponent = params.powerExponent; - commandList->writeBuffer( m_ConstantBuffer, &ssaoConstants, sizeof( ssaoConstants ) ); - - // SRS - after writing constant buffer, compute ssao for 3d views only - if( viewDef->viewEntitys && !viewDef->is2Dgui ) { + nvrhi::Rect viewExtent( viewDef->viewport.x1, viewDef->viewport.x2, viewDef->viewport.y1, viewDef->viewport.y2 ); + nvrhi::Rect quarterResExtent = viewExtent; + quarterResExtent.minX /= 4; + quarterResExtent.minY /= 4; + quarterResExtent.maxX = ( quarterResExtent.maxX + 3 ) / 4; + quarterResExtent.maxY = ( quarterResExtent.maxY + 3 ) / 4; + + SsaoConstants ssaoConstants = {}; + ssaoConstants.viewportOrigin = idVec2( viewDef->viewport.x1, viewDef->viewport.y1 ); + ssaoConstants.viewportSize = idVec2( viewDef->viewport.GetWidth(), viewDef->viewport.GetHeight() ); + + ssaoConstants.matClipToView = viewDef->unprojectionToCameraRenderMatrix; + + // SRS - FIXME: These transformations need to be verified + + // RB: TODO: only need for DIRECTIONAL_OCCLUSION + //ssaoConstants.matViewToWorld = viewDef->worldSpace; + //idRenderMatrix::Inverse( ssaoConstants.matViewToWorld, ssaoConstants.matWorldToView ); + // SRS end + + float projectionMatrix[16]; + + //R_MatrixTranspose( viewDef->projectionMatrix, projectionMatrix ); + memcpy( projectionMatrix, viewDef->projectionMatrix, 16 * 4 ); + + ssaoConstants.clipToView = idVec2( + projectionMatrix[2 * 4 + 3] / projectionMatrix[0 * 4 + 0], + projectionMatrix[2 * 4 + 3] / projectionMatrix[1 * 4 + 1] ); + ssaoConstants.invQuantizedGbufferSize = 1.f / m_QuantizedGbufferTextureSize; + ssaoConstants.quantizedViewportOrigin = idVec2i( quarterResExtent.minX, quarterResExtent.minY ) * 4; + ssaoConstants.amount = r_ssaoAmount.GetFloat(); + ssaoConstants.invBackgroundViewDepth = ( r_ssaoBackgroundViewDepth.GetFloat() > 0.f ) ? 1.f / r_ssaoBackgroundViewDepth.GetFloat() : 0.f; + ssaoConstants.radiusWorld = r_ssaoRadiusWorld.GetFloat(); + ssaoConstants.surfaceBias = r_ssaoSurfaceBias.GetFloat(); + ssaoConstants.powerExponent = r_ssaoPowerExponent.GetFloat(); + ssaoConstants.radiusToScreen = 0.5f * viewDef->viewport.GetHeight() * abs( viewDef->projectionMatrix[1 * 4 + 1] ); + commandList->writeBuffer( m_ConstantBuffer, &ssaoConstants, sizeof( ssaoConstants ) ); + uint32_t dispatchWidth = ( quarterResExtent.width() + 7 ) / 8; uint32_t dispatchHeight = ( quarterResExtent.height() + 7 ) / 8; @@ -295,6 +300,4 @@ void SsaoPass::Render( commandList->setComputeState( state ); commandList->dispatch( dispatchWidth, dispatchHeight, 1 ); } - - commandList->endMarker(); } diff --git a/neo/renderer/Passes/SsaoPass.h b/neo/renderer/Passes/SsaoPass.h index 902e21af..a8725018 100644 --- a/neo/renderer/Passes/SsaoPass.h +++ b/neo/renderer/Passes/SsaoPass.h @@ -1,33 +1,28 @@ /* -=========================================================================== - -Doom 3 BFG Edition GPL Source Code -Copyright (C) 2022 Stephen Pridham - -This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code"). - -Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Doom 3 BFG Edition Source Code. If not, see . - -In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below. - -If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. - -=========================================================================== +* Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +* DEALINGS IN THE SOFTWARE. */ #ifndef RENDERER_PASSES_SSAOPASS_H_ #define RENDERER_PASSES_SSAOPASS_H_ +/* struct SsaoParameters { float amount = 2.f; @@ -38,6 +33,7 @@ struct SsaoParameters bool enableBlur = true; float blurSharpness = 16.f; }; +*/ class SsaoPass { @@ -92,7 +88,6 @@ public: void Render( nvrhi::ICommandList* commandList, - const SsaoParameters& params, const viewDef_t* viewDef, int bindingSetIndex = 0 ); }; diff --git a/neo/renderer/RenderBackend.cpp b/neo/renderer/RenderBackend.cpp index e99eae6a..a0c90c34 100644 --- a/neo/renderer/RenderBackend.cpp +++ b/neo/renderer/RenderBackend.cpp @@ -6148,7 +6148,7 @@ void idRenderBackend::DrawScreenSpaceAmbientOcclusion( const viewDef_t* _viewDef if( r_ssaoFiltering.GetBool() ) { float jitterTexScale[4]; - + #if defined( USE_NVRHI ) commandList->clearTextureFloat( globalImages->ambientOcclusionImage[1]->GetTextureHandle(), nvrhi::AllSubresources, nvrhi::Color( 1.f ) ); #endif @@ -6240,15 +6240,14 @@ NVRHI SSAO using compute shaders. */ void idRenderBackend::DrawScreenSpaceAmbientOcclusion2( const viewDef_t* _viewDef, bool downModulateScreen ) { - // SRS - run ssao pass on 3d + 2d overlay views to avoid flickering, skip for 2d-only views (menu & pda) - if( ( !_viewDef->viewEntitys || _viewDef->is2Dgui ) && !drawView3D ) + if( !r_useSSAO.GetBool() ) { - // 3D views only return; } - if( !r_useSSAO.GetBool() ) + if( !_viewDef->viewEntitys || _viewDef->is2Dgui ) { + // 3D views only return; } @@ -6264,12 +6263,11 @@ void idRenderBackend::DrawScreenSpaceAmbientOcclusion2( const viewDef_t* _viewDe } renderLog.OpenMainBlock( MRB_SSAO_PASS ); - renderLog.OpenBlock( "Render_NewSSAO", colorBlue ); + renderLog.OpenBlock( "Render_SSAO2", colorBlue ); commandList->clearTextureFloat( globalImages->ambientOcclusionImage[0]->GetTextureHandle(), nvrhi::AllSubresources, nvrhi::Color( 1.f ) ); - - SsaoParameters ssaoParams = {}; - ssaoPass->Render( commandList, ssaoParams, _viewDef, 0 ); + + ssaoPass->Render( commandList, _viewDef, 0 ); renderLog.CloseBlock(); renderLog.CloseMainBlock(); diff --git a/neo/shaders/builtin/SSAO/AmbientOcclusion_AO.ps.hlsl b/neo/shaders/builtin/SSAO/AmbientOcclusion_AO.ps.hlsl index 5d6afbf3..0617fb8f 100644 --- a/neo/shaders/builtin/SSAO/AmbientOcclusion_AO.ps.hlsl +++ b/neo/shaders/builtin/SSAO/AmbientOcclusion_AO.ps.hlsl @@ -57,8 +57,7 @@ #define MIN_MIP_LEVEL 0 -static const float DOOM_TO_METERS = 0.0254; // doom to meters -static const float METERS_TO_DOOM = ( 1.0 / DOOM_TO_METERS ); // meters to doom + /** Used for preventing AO computation on the sky (at infinite depth) and defining the CS Z to bilateral depth key scaling. This need not match the real far plane but should not be much more than it.*/ diff --git a/neo/shaders/builtin/SSAO/ssao_blur.cs.hlsl b/neo/shaders/builtin/SSAO/ssao_blur.cs.hlsl index ed92dfa8..8ba3c435 100644 --- a/neo/shaders/builtin/SSAO/ssao_blur.cs.hlsl +++ b/neo/shaders/builtin/SSAO/ssao_blur.cs.hlsl @@ -177,7 +177,7 @@ void main( uint2 groupId : SV_GroupID, uint2 threadId : SV_GroupThreadID, uint2 int2 storePos = int2( globalId.xy ) + g_Ssao.quantizedViewportOrigin; float2 storePosF = float2( storePos ); - if (all(storePosF >= g_Ssao.viewportOrigin.xy) && all(storePosF < g_Ssao.viewportOrigin.xy + g_Ssao.viewportSize.xy)) + if( all( storePosF >= g_Ssao.viewportOrigin.xy ) && all( storePosF < g_Ssao.viewportOrigin.xy + g_Ssao.viewportSize.xy ) ) { u_RenderTarget[storePos] = totalOcclusion; } diff --git a/neo/shaders/builtin/SSAO/ssao_compute.cs.hlsl b/neo/shaders/builtin/SSAO/ssao_compute.cs.hlsl index 2fab661c..12a1bdc7 100644 --- a/neo/shaders/builtin/SSAO/ssao_compute.cs.hlsl +++ b/neo/shaders/builtin/SSAO/ssao_compute.cs.hlsl @@ -182,6 +182,7 @@ float2 WindowToClip( float2 windowPos ) float2 windowToClipScale = 1.f / clipToWindowScale; float2 windowToClipBias = -clipToWindowBias * windowToClipScale; + // TODO add pixelOffset for TAA return windowPos.xy * windowToClipScale + windowToClipBias; } @@ -206,7 +207,8 @@ void main( uint3 globalId : SV_DispatchThreadID ) float3 pixelNormal = t_Normals[pixelPos].xyz; #endif - pixelNormal = normalize(mul(float4(pixelNormal, 0), g_Ssao.matWorldToView).xyz); + // RB: pixelNormal is already in view space + //pixelNormal = normalize( mul( float4( pixelNormal, 0 ), g_Ssao.matWorldToView ).xyz ); float2 pixelClipPos = WindowToClip( pixelPos ); float3 pixelViewPos = ViewDepthToViewPos( pixelClipPos.xy, pixelViewDepth ); @@ -269,7 +271,7 @@ void main( uint3 globalId : SV_DispatchThreadID ) float directionalLength = length( result.xyz ); if( directionalLength > 0 ) { - result.xyz = mul(float4(normalize(result.xyz), 0), g_Ssao.matViewToWorld).xyz * directionalLength; + result.xyz = mul( float4( normalize( result.xyz ), 0 ), g_Ssao.matViewToWorld ).xyz * directionalLength; } #endif diff --git a/neo/shaders/builtin/SSAO/ssao_deinterleave.cs.hlsl b/neo/shaders/builtin/SSAO/ssao_deinterleave.cs.hlsl index 3921f1de..e0b6331c 100644 --- a/neo/shaders/builtin/SSAO/ssao_deinterleave.cs.hlsl +++ b/neo/shaders/builtin/SSAO/ssao_deinterleave.cs.hlsl @@ -75,7 +75,8 @@ void main( uint3 globalId : SV_DispatchThreadID ) float linearDepth = depth; #else float4 clipPos = float4( 0, 0, depth, 1 ); - float4 viewPos = mul(clipPos, g_Ssao.matClipToView); + //float4 clipPos = float4( 0, 0, depth * 2.0 - 1.0, 1 ); + float4 viewPos = mul( clipPos, g_Ssao.matClipToView ); float linearDepth = viewPos.z / viewPos.w; #endif diff --git a/neo/shaders/builtin/SSGI/DeepGBufferRadiosity_radiosity.ps.hlsl b/neo/shaders/builtin/SSGI/DeepGBufferRadiosity_radiosity.ps.hlsl index 178d5c1d..4986c5f9 100644 --- a/neo/shaders/builtin/SSGI/DeepGBufferRadiosity_radiosity.ps.hlsl +++ b/neo/shaders/builtin/SSGI/DeepGBufferRadiosity_radiosity.ps.hlsl @@ -43,9 +43,6 @@ #define MIN_MIP_LEVEL 0 -static const float DOOM_TO_METERS = 0.0254; // doom to meters -static const float METERS_TO_DOOM = ( 1.0 / DOOM_TO_METERS ); // meters to doom - /** Used for preventing AO computation on the sky (at infinite depth) and defining the CS Z to bilateral depth key scaling. This need not match the real far plane but should not be much more than it.*/ static const float FAR_PLANE_Z = -4000.0; diff --git a/neo/shaders/global_inc.hlsl b/neo/shaders/global_inc.hlsl index 7c5a829a..ca4cf161 100644 --- a/neo/shaders/global_inc.hlsl +++ b/neo/shaders/global_inc.hlsl @@ -165,6 +165,9 @@ static float dot4( float2 a, float4 b ) // RB: the golden ratio is useful to animate Blue noise #define c_goldenRatioConjugate 0.61803398875 +static const float DOOM_TO_METERS = 0.0254; // doom to meters +static const float METERS_TO_DOOM = ( 1.0 / DOOM_TO_METERS ); // meters to doom + // ---------------------- // sRGB <-> Linear RGB Color Conversion // ---------------------- @@ -495,77 +498,4 @@ float3 Hash33( float3 p3 ) return frac( ( p3.xxy + p3.yxx ) * p3.zyx ); } -/* -static float3 DitherRGB( float3 color, float2 uvSeed, float quantSteps ) -{ - // uniform noise - //float3 noise = Hash33( float3( uvSeed, rpJitterTexOffset.w ) ); - - //float3 noise = float3( InterleavedGradientNoise( uvSeed ) ); - float3 noise = _float3( InterleavedGradientNoiseAnim( uvSeed, rpJitterTexOffset.w ) ); - - // triangular noise [-0.5;1.5[ - -#if 1 - noise.x = RemapNoiseTriErp( noise.x ); - noise = noise * 2.0 - 0.5; -#endif - - noise = _float3( noise.x ); - - // quantize/truncate color and dither the result - //float scale = exp2( float( TARGET_BITS ) ) - 1.0; - - // lets assume 2^3 bits = 8 - //float scale = 7.0; - //const float quantSteps = 8.0; - float scale = quantSteps - 1.0; - - // apply dither - color += noise / ( quantSteps ); - - color = floor( color * scale ) / scale; - - //float3 color = c + whiteNoise / 255.0; - - return color; -} -*/ - -/* -static float3 DitherChromaticBlueNoise( float3 color, float2 n, SamplerState blueTex ) -{ - // uniform noise - //float3 noise = Hash33( float3( n, rpJitterTexOffset.w ) ); - - //float3 noise = float3( InterleavedGradientNoise( n ) ); - //float3 noise = float3( InterleavedGradientNoiseAnim( n, rpJitterTexOffset.w ) ); - - // uv is screen position / sizeof blue noise image - float2 uv = n.xy * rpJitterTexOffset.xy; - float3 noise = tex2D( blueTex, uv ).rgb; - - // rpJitterTexOffset.w is frameTime % 64 - noise = frac( noise + c_goldenRatioConjugate * rpJitterTexOffset.w ); - - // triangular noise [-0.5;1.5[ - noise.x = RemapNoiseTriErp( noise.x ); - noise = noise * 2.0 - 0.5; - - //noise = float3( noise.x ); - - // quantize/truncate color and dither the result - //float scale = exp2( float( TARGET_BITS ) ) - 1.0; - - // lets assume 2^3 bits = 8 - float quantSteps = 255.0; - - //float3 color = floor( c * scale + noise ) / scale; - - color = floor( 0.5 + color * quantSteps - 0.5 + noise ) * ( 1.0 / ( quantSteps - 1.0 ) ); - - return color; -} -*/ - #define SMAA_RT_METRICS float4(1.0 / 1280.0, 1.0 / 720.0, 1280.0, 720.0) \ No newline at end of file From 1d1ad26adfbdb80db74c13d5fd1a9feb9374d15e Mon Sep 17 00:00:00 2001 From: Robert Beckebans Date: Tue, 7 Feb 2023 21:07:29 +0100 Subject: [PATCH 11/12] More SSAO experiments --- neo/renderer/GLMatrix.cpp | 78 ++++++++++++------- neo/renderer/Passes/SsaoPass.cpp | 2 +- .../builtin/SSAO/ssao_deinterleave.cs.hlsl | 14 +++- neo/shaders/builtin/gbuffer.ps.hlsl | 2 +- 4 files changed, 65 insertions(+), 31 deletions(-) diff --git a/neo/renderer/GLMatrix.cpp b/neo/renderer/GLMatrix.cpp index 899a00d2..444b2602 100644 --- a/neo/renderer/GLMatrix.cpp +++ b/neo/renderer/GLMatrix.cpp @@ -495,6 +495,19 @@ void R_SetupProjectionMatrix( viewDef_t* viewDef, bool doJitter ) // const float zNear = ( viewDef->renderView.cramZNear ) ? ( r_znear.GetFloat() * 0.25f ) : r_znear.GetFloat(); + const int viewWidth = viewDef->viewport.x2 - viewDef->viewport.x1 + 1; + const int viewHeight = viewDef->viewport.y2 - viewDef->viewport.y1 + 1; + + // TODO integrate jitterx += viewDef->renderView.stereoScreenSeparation; + + // this mimics the logic in the Donut Feature Demo + const float xoffset = -2.0f * jitterx / ( 1.0f * viewWidth ); + const float yoffset = -2.0f * jittery / ( 1.0f * viewHeight ); + + float* projectionMatrix = doJitter ? viewDef->projectionMatrix : viewDef->unjitteredProjectionMatrix; + +#if 1 + float ymax = zNear * tan( viewDef->renderView.fov_y * idMath::PI / 360.0f ); float ymin = -ymax; @@ -504,34 +517,6 @@ void R_SetupProjectionMatrix( viewDef_t* viewDef, bool doJitter ) const float width = xmax - xmin; const float height = ymax - ymin; - const int viewWidth = viewDef->viewport.x2 - viewDef->viewport.x1 + 1; - const int viewHeight = viewDef->viewport.y2 - viewDef->viewport.y1 + 1; - -#if 0 - jitterx = jitterx * width / viewWidth; - jitterx += r_centerX.GetFloat(); - jitterx += viewDef->renderView.stereoScreenSeparation; - xmin += jitterx * width; - xmax += jitterx * width; - const float xoffset = ( xmax + xmin ) / width; // 0 without jitter - - jittery = jittery * height / viewHeight; - jittery += r_centerY.GetFloat(); - ymin += jittery * height; - ymax += jittery * height; - const float yoffset = ( ymax + ymin ) / height; - -#else - // this mimics the logic in the Donut / Feature Demo - const float xoffset = -2.0f * jitterx / ( 1.0f * viewWidth ); - const float yoffset = -2.0f * jittery / ( 1.0f * viewHeight ); -#endif - - // RB: IMPORTANT - the projectionMatrix has a few changes to make it work with Vulkan - // for a detailed explanation see https://matthewwellings.com/blog/the-new-vulkan-coordinate-system/ - - float* projectionMatrix = doJitter ? viewDef->projectionMatrix : viewDef->unjitteredProjectionMatrix; - projectionMatrix[0 * 4 + 0] = 2.0f * zNear / width; projectionMatrix[1 * 4 + 0] = 0.0f; projectionMatrix[2 * 4 + 0] = xoffset; @@ -558,6 +543,43 @@ void R_SetupProjectionMatrix( viewDef_t* viewDef, bool doJitter ) projectionMatrix[2 * 4 + 3] = -1.0f; projectionMatrix[3 * 4 + 3] = 0.0f; +#else + + // alternative Z for better precision in the distance + + float aspect = viewDef->renderView.fov_x / viewDef->renderView.fov_y; + + float yScale = 1.0f / ( tanf( 0.5f * DEG2RAD( viewDef->renderView.fov_y ) ) ); + float xScale = yScale / aspect; + + const float epsilon = 1.9073486328125e-6F; // 2^-19; + const float zFar = 160000; + + //float k = zFar / ( zFar - zNear ); + float k = 1.0f - epsilon; + + projectionMatrix[0 * 4 + 0] = xScale; + projectionMatrix[1 * 4 + 0] = 0.0f; + projectionMatrix[2 * 4 + 0] = xoffset; + projectionMatrix[3 * 4 + 0] = 0.0f; + + projectionMatrix[0 * 4 + 1] = 0.0f; + projectionMatrix[1 * 4 + 1] = yScale; + projectionMatrix[2 * 4 + 1] = yoffset; + projectionMatrix[3 * 4 + 1] = 0.0f; + + projectionMatrix[0 * 4 + 2] = 0.0f; + projectionMatrix[1 * 4 + 2] = 0.0f; + projectionMatrix[2 * 4 + 2] = -k; + projectionMatrix[3 * 4 + 2] = -k * zNear; + + projectionMatrix[0 * 4 + 3] = 0.0f; + projectionMatrix[1 * 4 + 3] = 0.0f; + projectionMatrix[2 * 4 + 3] = -1.0f; + projectionMatrix[3 * 4 + 3] = 0.0f; + +#endif + if( viewDef->renderView.flipProjection ) { projectionMatrix[1 * 4 + 1] = -projectionMatrix[1 * 4 + 1]; diff --git a/neo/renderer/Passes/SsaoPass.cpp b/neo/renderer/Passes/SsaoPass.cpp index 5ec20170..a1a85430 100644 --- a/neo/renderer/Passes/SsaoPass.cpp +++ b/neo/renderer/Passes/SsaoPass.cpp @@ -30,7 +30,7 @@ static idCVar r_ssaoBackgroundViewDepth( "r_ssaoBackgroundViewDepth", "100", CVAR_RENDERER | CVAR_FLOAT, "" ); static idCVar r_ssaoRadiusWorld( "r_ssaoRadiusWorld", "0.5", CVAR_RENDERER | CVAR_FLOAT, "" ); static idCVar r_ssaoSurfaceBias( "r_ssaoSurfaceBias", "0.1", CVAR_RENDERER | CVAR_FLOAT, "" ); -static idCVar r_ssaoPowerExponent( "r_ssaoSurfaceBias", "2", CVAR_RENDERER | CVAR_FLOAT, "" ); +static idCVar r_ssaoPowerExponent( "r_ssaoPowerExponent", "2", CVAR_RENDERER | CVAR_FLOAT, "" ); static idCVar r_ssaoBlurSharpness( "r_ssaoBlurSharpness", "16", CVAR_RENDERER | CVAR_FLOAT, "" ); static idCVar r_ssaoAmount( "r_ssaoAmount", "2", CVAR_RENDERER | CVAR_FLOAT, "" ); diff --git a/neo/shaders/builtin/SSAO/ssao_deinterleave.cs.hlsl b/neo/shaders/builtin/SSAO/ssao_deinterleave.cs.hlsl index e0b6331c..444f71fa 100644 --- a/neo/shaders/builtin/SSAO/ssao_deinterleave.cs.hlsl +++ b/neo/shaders/builtin/SSAO/ssao_deinterleave.cs.hlsl @@ -74,10 +74,22 @@ void main( uint3 globalId : SV_DispatchThreadID ) #if LINEAR_DEPTH float linearDepth = depth; #else - float4 clipPos = float4( 0, 0, depth, 1 ); + //float4 clipPos = float4( 0, 0, depth, 1 ); //float4 clipPos = float4( 0, 0, depth * 2.0 - 1.0, 1 ); + + // adjust depth + depth = depth * 2.0 - 1.0; + float4 clipPos = float4( 0, 0, depth, 1 ); + float4 viewPos = mul( clipPos, g_Ssao.matClipToView ); float linearDepth = viewPos.z / viewPos.w; + + // HACK: adjust linear depth to fit into [0 .. 16000] range + linearDepth += 0.35; + linearDepth = saturate( linearDepth ); + //linearDepth = 1.0 - linearDepth; // reverse depth + //linearDepth *= 4000; // zFar + //linearDepth *= DOOM_TO_METERS; #endif depths[y * 4 + x] = linearDepth; diff --git a/neo/shaders/builtin/gbuffer.ps.hlsl b/neo/shaders/builtin/gbuffer.ps.hlsl index 806bf961..efdd4dc1 100644 --- a/neo/shaders/builtin/gbuffer.ps.hlsl +++ b/neo/shaders/builtin/gbuffer.ps.hlsl @@ -66,7 +66,7 @@ void main( PS_IN fragment, out PS_OUT result ) localNormal.z = sqrt( 1.0f - dot3( localNormal, localNormal ) ); float3 globalNormal; -#if 1 +#if 0 globalNormal.x = dot3( localNormal, fragment.texcoord2 ); globalNormal.y = dot3( localNormal, fragment.texcoord3 ); globalNormal.z = dot3( localNormal, fragment.texcoord4 ); From 9d45866a1a5cb159fd54f580e25f0d21002e043d Mon Sep 17 00:00:00 2001 From: Robert Beckebans Date: Wed, 8 Feb 2023 09:24:23 +0100 Subject: [PATCH 12/12] Simplified old SSAO backend code --- neo/renderer/GLMatrix.cpp | 2 +- neo/renderer/Passes/SsaoPass.cpp | 2 +- neo/renderer/RenderBackend.cpp | 138 +----------------- neo/renderer/RenderBackend.h | 4 +- .../builtin/SSAO/ssao_deinterleave.cs.hlsl | 6 +- 5 files changed, 12 insertions(+), 140 deletions(-) diff --git a/neo/renderer/GLMatrix.cpp b/neo/renderer/GLMatrix.cpp index 444b2602..33e5f149 100644 --- a/neo/renderer/GLMatrix.cpp +++ b/neo/renderer/GLMatrix.cpp @@ -506,7 +506,7 @@ void R_SetupProjectionMatrix( viewDef_t* viewDef, bool doJitter ) float* projectionMatrix = doJitter ? viewDef->projectionMatrix : viewDef->unjitteredProjectionMatrix; -#if 1 +#if 0 float ymax = zNear * tan( viewDef->renderView.fov_y * idMath::PI / 360.0f ); float ymin = -ymax; diff --git a/neo/renderer/Passes/SsaoPass.cpp b/neo/renderer/Passes/SsaoPass.cpp index a1a85430..24526ef5 100644 --- a/neo/renderer/Passes/SsaoPass.cpp +++ b/neo/renderer/Passes/SsaoPass.cpp @@ -275,7 +275,7 @@ void SsaoPass::Render( ssaoConstants.radiusWorld = r_ssaoRadiusWorld.GetFloat(); ssaoConstants.surfaceBias = r_ssaoSurfaceBias.GetFloat(); ssaoConstants.powerExponent = r_ssaoPowerExponent.GetFloat(); - ssaoConstants.radiusToScreen = 0.5f * viewDef->viewport.GetHeight() * abs( viewDef->projectionMatrix[1 * 4 + 1] ); + ssaoConstants.radiusToScreen = 0.5f * viewDef->viewport.GetHeight() * abs( projectionMatrix[1 * 4 + 1] ); commandList->writeBuffer( m_ConstantBuffer, &ssaoConstants, sizeof( ssaoConstants ) ); uint32_t dispatchWidth = ( quarterResExtent.width() + 7 ) / 8; diff --git a/neo/renderer/RenderBackend.cpp b/neo/renderer/RenderBackend.cpp index a0c90c34..00790856 100644 --- a/neo/renderer/RenderBackend.cpp +++ b/neo/renderer/RenderBackend.cpp @@ -5870,9 +5870,8 @@ void idRenderBackend::Bloom( const viewDef_t* _viewDef ) } -void idRenderBackend::DrawScreenSpaceAmbientOcclusion( const viewDef_t* _viewDef, bool downModulateScreen ) +void idRenderBackend::DrawScreenSpaceAmbientOcclusion( const viewDef_t* _viewDef ) { -#if !defined(USE_VULKAN) if( !_viewDef->viewEntitys || _viewDef->is2Dgui ) { // 3D views only @@ -5915,7 +5914,6 @@ void idRenderBackend::DrawScreenSpaceAmbientOcclusion( const viewDef_t* _viewDef // build hierarchical depth buffer if( r_useHierarchicalDepthBuffer.GetBool() ) { -#if defined( USE_NVRHI ) renderLog.OpenBlock( "Render_HiZ" ); //if( R_GetMSAASamples() > 1 ) @@ -5934,63 +5932,6 @@ void idRenderBackend::DrawScreenSpaceAmbientOcclusion( const viewDef_t* _viewDef hiZGenPass->Dispatch( commandList, MAX_HIERARCHICAL_ZBUFFERS ); renderLog.CloseBlock(); -#else - renderLog.OpenBlock( "Render_HiZ", colorDkGrey ); - - renderProgManager.BindShader_AmbientOcclusionMinify(); - - GL_Color( 0, 0, 0, 1 ); - - GL_SelectTexture( 0 ); - //globalImages->currentDepthImage->Bind(); - - for( int i = 0; i < MAX_HIERARCHICAL_ZBUFFERS; i++ ) - { - int width = globalFramebuffers.csDepthFBO[i]->GetWidth(); - int height = globalFramebuffers.csDepthFBO[i]->GetHeight(); - - globalFramebuffers.csDepthFBO[i]->Bind(); - - GL_Viewport( 0, 0, width, height ); - GL_Scissor( 0, 0, width, height ); - - GL_State( GLS_SRCBLEND_ONE | GLS_DSTBLEND_ZERO | GLS_DEPTHMASK | GLS_DEPTHFUNC_ALWAYS | GLS_CULL_TWOSIDED ); - - glClear( GL_COLOR_BUFFER_BIT ); - - if( i == 0 ) - { - renderProgManager.BindShader_AmbientOcclusionReconstructCSZ(); - - globalImages->currentDepthImage->Bind(); - } - else - { - renderProgManager.BindShader_AmbientOcclusionMinify(); - - GL_SelectTexture( 0 ); - globalImages->hierarchicalZbufferImage->Bind(); - } - - float jitterTexScale[4]; - jitterTexScale[0] = i - 1; - jitterTexScale[1] = 0; - jitterTexScale[2] = 0; - jitterTexScale[3] = 0; - SetFragmentParm( RENDERPARM_JITTERTEXSCALE, jitterTexScale ); // rpJitterTexScale - - float screenCorrectionParm[4]; - screenCorrectionParm[0] = 1.0f / width; - screenCorrectionParm[1] = 1.0f / height; - screenCorrectionParm[2] = width; - screenCorrectionParm[3] = height; - SetFragmentParm( RENDERPARM_SCREENCORRECTIONFACTOR, screenCorrectionParm ); // rpScreenCorrectionFactor - - DrawElementsWithCounters( &unitSquareSurface ); - } - - renderLog.CloseBlock(); -#endif } if( previousFramebuffer != NULL ) @@ -6009,41 +5950,6 @@ void idRenderBackend::DrawScreenSpaceAmbientOcclusion( const viewDef_t* _viewDef GL_Viewport( 0, 0, aoScreenWidth, aoScreenHeight ); GL_Scissor( 0, 0, aoScreenWidth, aoScreenHeight ); - if( downModulateScreen ) - { - if( r_ssaoFiltering.GetBool() ) - { - globalFramebuffers.ambientOcclusionFBO[0]->Bind(); - -#if defined( USE_NVRHI ) - GL_Clear( true, false, false, 0, 0, 0, 0, 0, false ); -#else - glClearColor( 0, 0, 0, 0 ); - glClear( GL_COLOR_BUFFER_BIT ); -#endif - - renderProgManager.BindShader_AmbientOcclusion(); - } - else - { - if( r_ssaoDebug.GetInteger() <= 0 ) - { - GL_State( GLS_SRCBLEND_DST_COLOR | GLS_DSTBLEND_ZERO | GLS_ALPHAMASK | GLS_DEPTHMASK | GLS_DEPTHFUNC_ALWAYS ); - } - - if( previousFramebuffer != NULL ) - { - previousFramebuffer->Bind(); - } - else - { - Framebuffer::Unbind(); - } - - renderProgManager.BindShader_AmbientOcclusionAndOutput(); - } - } - else { globalFramebuffers.ambientOcclusionFBO[0]->Bind(); @@ -6086,19 +5992,6 @@ void idRenderBackend::DrawScreenSpaceAmbientOcclusion( const viewDef_t* _viewDef windowCoordParm[3] = aoScreenHeight; SetFragmentParm( RENDERPARM_WINDOWCOORD, windowCoordParm ); // rpWindowCoord -#if 0 - // RB: set unprojection matrices so we can convert zbuffer values back to camera and world spaces - idRenderMatrix modelViewMatrix; - idRenderMatrix::Transpose( *( idRenderMatrix* )backEnd.viewDef->worldSpace.modelViewMatrix, modelViewMatrix ); - idRenderMatrix cameraToWorldMatrix; - if( !idRenderMatrix::Inverse( modelViewMatrix, cameraToWorldMatrix ) ) - { - idLib::Warning( "cameraToWorldMatrix invert failed" ); - } - - SetVertexParms( RENDERPARM_MODELMATRIX_X, cameraToWorldMatrix[0], 4 ); - //SetVertexParms( RENDERPARM_MODELMATRIX_X, viewDef->unprojectionToWorldRenderMatrix[0], 4 ); -#endif SetVertexParms( RENDERPARM_MODELMATRIX_X, viewDef->unprojectionToCameraRenderMatrix[0], 4 ); const float jitterSampleScale = 1.0f; @@ -6171,26 +6064,7 @@ void idRenderBackend::DrawScreenSpaceAmbientOcclusion( const viewDef_t* _viewDef DrawElementsWithCounters( &unitSquareSurface ); // AO blur Y - if( downModulateScreen ) - { - if( previousFramebuffer != NULL ) - { - previousFramebuffer->Bind(); - } - else - { - Framebuffer::Unbind(); - } - - if( r_ssaoDebug.GetInteger() <= 0 ) - { - GL_State( GLS_SRCBLEND_DST_COLOR | GLS_DSTBLEND_ZERO | GLS_DEPTHMASK | GLS_DEPTHFUNC_ALWAYS ); - } - } - else - { - globalFramebuffers.ambientOcclusionFBO[0]->Bind(); - } + globalFramebuffers.ambientOcclusionFBO[0]->Bind(); renderProgManager.BindShader_AmbientOcclusionBlurAndOutput(); @@ -6207,7 +6081,6 @@ void idRenderBackend::DrawScreenSpaceAmbientOcclusion( const viewDef_t* _viewDef DrawElementsWithCounters( &unitSquareSurface ); } - if( !downModulateScreen ) { // go back to main scene render target if( previousFramebuffer != NULL ) @@ -6238,7 +6111,7 @@ void idRenderBackend::DrawScreenSpaceAmbientOcclusion( const viewDef_t* _viewDef /* NVRHI SSAO using compute shaders. */ -void idRenderBackend::DrawScreenSpaceAmbientOcclusion2( const viewDef_t* _viewDef, bool downModulateScreen ) +void idRenderBackend::DrawScreenSpaceAmbientOcclusion2( const viewDef_t* _viewDef ) { if( !r_useSSAO.GetBool() ) { @@ -6271,7 +6144,6 @@ void idRenderBackend::DrawScreenSpaceAmbientOcclusion2( const viewDef_t* _viewDe renderLog.CloseBlock(); renderLog.CloseMainBlock(); -#endif } void idRenderBackend::DrawScreenSpaceGlobalIllumination( const viewDef_t* _viewDef ) @@ -6863,12 +6735,12 @@ void idRenderBackend::DrawViewInternal( const viewDef_t* _viewDef, const int ste #if defined( USE_NVRHI ) if( r_useNewSsaoPass.GetBool() ) { - DrawScreenSpaceAmbientOcclusion2( _viewDef, false ); + DrawScreenSpaceAmbientOcclusion2( _viewDef ); } else #endif { - DrawScreenSpaceAmbientOcclusion( _viewDef, false ); + DrawScreenSpaceAmbientOcclusion( _viewDef ); } //------------------------------------------------- diff --git a/neo/renderer/RenderBackend.h b/neo/renderer/RenderBackend.h index d32e4de0..65cc2027 100644 --- a/neo/renderer/RenderBackend.h +++ b/neo/renderer/RenderBackend.h @@ -353,8 +353,8 @@ private: void Tonemap( const viewDef_t* viewDef ); void Bloom( const viewDef_t* viewDef ); - void DrawScreenSpaceAmbientOcclusion( const viewDef_t* _viewDef, bool downModulateScreen ); - void DrawScreenSpaceAmbientOcclusion2( const viewDef_t* _viewDef, bool downModulateScreen ); + void DrawScreenSpaceAmbientOcclusion( const viewDef_t* _viewDef ); + void DrawScreenSpaceAmbientOcclusion2( const viewDef_t* _viewDef ); void DrawScreenSpaceGlobalIllumination( const viewDef_t* _viewDef ); // Experimental feature diff --git a/neo/shaders/builtin/SSAO/ssao_deinterleave.cs.hlsl b/neo/shaders/builtin/SSAO/ssao_deinterleave.cs.hlsl index 444f71fa..7951a392 100644 --- a/neo/shaders/builtin/SSAO/ssao_deinterleave.cs.hlsl +++ b/neo/shaders/builtin/SSAO/ssao_deinterleave.cs.hlsl @@ -78,15 +78,15 @@ void main( uint3 globalId : SV_DispatchThreadID ) //float4 clipPos = float4( 0, 0, depth * 2.0 - 1.0, 1 ); // adjust depth - depth = depth * 2.0 - 1.0; + depth = ( depth * 2.0 - 1.0 ); float4 clipPos = float4( 0, 0, depth, 1 ); float4 viewPos = mul( clipPos, g_Ssao.matClipToView ); float linearDepth = viewPos.z / viewPos.w; // HACK: adjust linear depth to fit into [0 .. 16000] range - linearDepth += 0.35; - linearDepth = saturate( linearDepth ); + //linearDepth += 0.35; + //linearDepth = saturate( linearDepth ); //linearDepth = 1.0 - linearDepth; // reverse depth //linearDepth *= 4000; // zFar //linearDepth *= DOOM_TO_METERS;