diff --git a/neo/CMakeLists.txt b/neo/CMakeLists.txt index 0e56f792..e1d81c01 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) @@ -1816,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) 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/GLMatrix.cpp b/neo/renderer/GLMatrix.cpp index a23d4341..33e5f149 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"). @@ -494,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 0 + float ymax = zNear * tan( viewDef->renderView.fov_y * idMath::PI / 360.0f ); float ymin = -ymax; @@ -503,47 +517,13 @@ 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; 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; @@ -563,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/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..6b0266fe 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" @@ -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 1b19436a..49c1bbad 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" @@ -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(); } @@ -1755,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 ); } } @@ -1858,12 +1848,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..24526ef5 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,8 +26,23 @@ 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_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, "" ); + struct SsaoConstants { + idVec2 viewportOrigin; + idVec2 viewportSize; + + idRenderMatrix matClipToView; + idRenderMatrix matWorldToView; + idRenderMatrix matViewToWorld; + idVec2 clipToView; idVec2 invQuantizedGbufferSize; @@ -223,58 +232,72 @@ 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] ); 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; - 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 ssaoConstants = {}; - ssaoConstants.clipToView = idVec2( - viewDef->projectionMatrix[2 * 4 + 3] / viewDef->projectionMatrix[0 * 4 + 0], - viewDef->projectionMatrix[2 * 4 + 3] / viewDef->projectionMatrix[0 * 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] ); - commandList->writeBuffer( m_ConstantBuffer, &ssaoConstants, sizeof( ssaoConstants ) ); + ssaoConstants.matClipToView = viewDef->unprojectionToCameraRenderMatrix; - uint32_t dispatchWidth = ( quarterResExtent.width() + 7 ) / 8; - uint32_t dispatchHeight = ( quarterResExtent.height() + 7 ) / 8; + // SRS - FIXME: These transformations need to be verified - nvrhi::ComputeState state; - state.pipeline = m_Deinterleave.Pipeline; - state.bindings = { m_Deinterleave.BindingSets[bindingSetIndex] }; - commandList->setComputeState( state ); - commandList->dispatch( dispatchWidth, dispatchHeight, 1 ); + // RB: TODO: only need for DIRECTIONAL_OCCLUSION + //ssaoConstants.matViewToWorld = viewDef->worldSpace; + //idRenderMatrix::Inverse( ssaoConstants.matViewToWorld, ssaoConstants.matWorldToView ); + // SRS end - state.pipeline = m_Compute.Pipeline; - state.bindings = { m_Compute.BindingSets[bindingSetIndex] }; - commandList->setComputeState( state ); - commandList->dispatch( dispatchWidth, dispatchHeight, 16 ); + float projectionMatrix[16]; - dispatchWidth = ( viewExtent.width() + 15 ) / 16; - dispatchHeight = ( viewExtent.height() + 15 ) / 16; + //R_MatrixTranspose( viewDef->projectionMatrix, projectionMatrix ); + memcpy( projectionMatrix, viewDef->projectionMatrix, 16 * 4 ); - state.pipeline = m_Blur.Pipeline; - state.bindings = { m_Blur.BindingSets[bindingSetIndex] }; - commandList->setComputeState( state ); - commandList->dispatch( dispatchWidth, dispatchHeight, 1 ); + 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( projectionMatrix[1 * 4 + 1] ); + commandList->writeBuffer( m_ConstantBuffer, &ssaoConstants, sizeof( ssaoConstants ) ); - commandList->endMarker(); -} \ No newline at end of file + 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 ); + + 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; + + state.pipeline = m_Blur.Pipeline; + state.bindings = { m_Blur.BindingSets[bindingSetIndex] }; + commandList->setComputeState( state ); + commandList->dispatch( dispatchWidth, dispatchHeight, 1 ); + } +} diff --git a/neo/renderer/Passes/SsaoPass.h b/neo/renderer/Passes/SsaoPass.h index edbbcd2c..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,9 +88,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..00790856 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; /* ================ @@ -5868,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 @@ -5878,7 +5879,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,13 +5909,11 @@ 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 if( r_useHierarchicalDepthBuffer.GetBool() ) { -#if defined( USE_NVRHI ) renderLog.OpenBlock( "Render_HiZ" ); //if( R_GetMSAASamples() > 1 ) @@ -5933,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 ) @@ -6008,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(); @@ -6085,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; @@ -6148,6 +6042,10 @@ void idRenderBackend::DrawScreenSpaceAmbientOcclusion( const viewDef_t* _viewDef { 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(); @@ -6166,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(); @@ -6202,7 +6081,6 @@ void idRenderBackend::DrawScreenSpaceAmbientOcclusion( const viewDef_t* _viewDef DrawElementsWithCounters( &unitSquareSurface ); } - if( !downModulateScreen ) { // go back to main scene render target if( previousFramebuffer != NULL ) @@ -6233,16 +6111,16 @@ 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( !_viewDef->viewEntitys || _viewDef->is2Dgui ) + if( !r_useSSAO.GetBool() ) { - // 3D views only return; } - if( r_useSSAO.GetInteger() <= 0 || r_useSSAO.GetInteger() < 2 ) + if( !_viewDef->viewEntitys || _viewDef->is2Dgui ) { + // 3D views only return; } @@ -6257,8 +6135,15 @@ void idRenderBackend::DrawScreenSpaceAmbientOcclusion2( const viewDef_t* _viewDe return; } - //GL_CheckErrors(); -#endif + renderLog.OpenMainBlock( MRB_SSAO_PASS ); + renderLog.OpenBlock( "Render_SSAO2", colorBlue ); + + commandList->clearTextureFloat( globalImages->ambientOcclusionImage[0]->GetTextureHandle(), nvrhi::AllSubresources, nvrhi::Color( 1.f ) ); + + ssaoPass->Render( commandList, _viewDef, 0 ); + + renderLog.CloseBlock(); + renderLog.CloseMainBlock(); } void idRenderBackend::DrawScreenSpaceGlobalIllumination( const viewDef_t* _viewDef ) @@ -6600,14 +6485,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() ); } @@ -6641,7 +6519,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 ) { @@ -6651,7 +6529,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 ); @@ -6674,7 +6552,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; @@ -6854,7 +6732,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 ); + } + else +#endif + { + DrawScreenSpaceAmbientOcclusion( _viewDef ); + } //------------------------------------------------- // render static lighting and consider SSAO results 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/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/shaders/builtin/SSAO/AmbientOcclusion_AO.ps.hlsl b/neo/shaders/builtin/SSAO/AmbientOcclusion_AO.ps.hlsl index ea847563..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.*/ @@ -93,11 +92,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/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 ) { diff --git a/neo/shaders/builtin/SSAO/ssao_blur.cs.hlsl b/neo/shaders/builtin/SSAO/ssao_blur.cs.hlsl index e7e9d42c..8ba3c435 100644 --- a/neo/shaders/builtin/SSAO/ssao_blur.cs.hlsl +++ b/neo/shaders/builtin/SSAO/ssao_blur.cs.hlsl @@ -26,6 +26,13 @@ struct SsaoConstants { + float2 viewportOrigin; + float2 viewportSize; + + float4x4 matClipToView; + float4x4 matWorldToView; + float4x4 matViewToWorld; + float2 clipToView; float2 invQuantizedGbufferSize; @@ -170,8 +177,8 @@ 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.view.viewportOrigin.xy) && all(storePosF < g_Ssao.view.viewportOrigin.xy + g_Ssao.view.viewportSize.xy)) - //{ - // u_RenderTarget[storePos] = totalOcclusion; - //} + 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 902ad610..12a1bdc7 100644 --- a/neo/shaders/builtin/SSAO/ssao_compute.cs.hlsl +++ b/neo/shaders/builtin/SSAO/ssao_compute.cs.hlsl @@ -26,6 +26,13 @@ struct SsaoConstants { + float2 viewportOrigin; + float2 viewportSize; + + float4x4 matClipToView; + float4x4 matWorldToView; + float4x4 matViewToWorld; + float2 clipToView; float2 invQuantizedGbufferSize; @@ -169,12 +176,13 @@ 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; + // TODO add pixelOffset for TAA return windowPos.xy * windowToClipScale + windowToClipBias; } @@ -199,13 +207,8 @@ 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 ), rpModelMatrixX ); - pN.y = dot4( float4( pixelNormal, 0 ), rpModelMatrixY ); - pN.z = dot4( float4( pixelNormal, 0 ), rpModelMatrixZ ); - - pixelNormal = normalize( pN ); + // 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 ); @@ -268,12 +271,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 ), rpModelMatrixX ); - worldSpaceResult.y = dot4( float4( normalize( result.xyz ), 0 ), rpModelMatrixY ); - worldSpaceResult.z = dot4( float4( normalize( result.xyz ), 0 ), rpModelMatrixZ ); - - 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 695c90a2..7951a392 100644 --- a/neo/shaders/builtin/SSAO/ssao_deinterleave.cs.hlsl +++ b/neo/shaders/builtin/SSAO/ssao_deinterleave.cs.hlsl @@ -26,6 +26,13 @@ struct SsaoConstants { + float2 viewportOrigin; + float2 viewportSize; + + float4x4 matClipToView; + float4x4 matWorldToView; + float4x4 matViewToWorld; + float2 clipToView; float2 invQuantizedGbufferSize; @@ -67,14 +74,22 @@ void main( uint3 globalId : SV_DispatchThreadID ) #if LINEAR_DEPTH float linearDepth = depth; #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 ); + //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/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/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 ); diff --git a/neo/shaders/builtin/mipmapgen.cs.hlsl b/neo/shaders/builtin/mipmapgen.cs.hlsl index 145db1e2..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* @@ -138,4 +142,4 @@ groupshared VALUE_TYPE s_ReductionData[GROUP_SIZE][GROUP_SIZE]; GroupMemoryBarrierWithGroupSync(); } -} \ No newline at end of file +} 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 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;