From 0c79c332a61cefd9a364cd44f7e5cd597c25ed7f Mon Sep 17 00:00:00 2001 From: MadDeCoDeR Date: Sun, 10 Dec 2023 18:34:45 +0200 Subject: [PATCH] Improve (???) Screen Space Ambient Occulsion (at least the shadow arches are removed now) (ref #61 #84 #135) --- base/renderprogs/AmbientOcclusion_AO.ps.hlsl | 19 ++++++++++--------- neo/renderer/RenderBackend.cpp | 2 +- neo/renderer/RenderSystem_init.cpp | 4 ++-- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/base/renderprogs/AmbientOcclusion_AO.ps.hlsl b/base/renderprogs/AmbientOcclusion_AO.ps.hlsl index da1ab86f..2ae58947 100644 --- a/base/renderprogs/AmbientOcclusion_AO.ps.hlsl +++ b/base/renderprogs/AmbientOcclusion_AO.ps.hlsl @@ -146,9 +146,10 @@ float3 reconstructNonUnitCSFaceNormal( float3 C ) float3 reconstructCSPosition( float2 S, float z ) { float4 P; - P.z = z * 2.0 - 1.0; - P.xy = ( S * rpScreenCorrectionFactor.xy ) * 2.0 - 1.0; - P.w = 1.0; + //P.z = z * 2.0 - 1.0; + //P.xy = S * 2.0 - 1.0; + //P.w = 1.0; + P = float4(S * rpScreenCorrectionFactor.xy, z, 1.0) * 4.0 - 1.0; float4 csP; csP.x = dot4( P, rpModelMatrixX ); @@ -158,7 +159,7 @@ float3 reconstructCSPosition( float2 S, float z ) csP.xyz /= csP.w; - return csP.xyz; + return (csP.xyz * 0.5) + 0.5; } float3 sampleNormal( sampler2D normalBuffer, int2 ssC, int mipLevel ) @@ -312,7 +313,7 @@ float sampleAO( int2 issC, in float3 C, in float3 n_C, in float ssDiskRadius, in return max( aoValueFromPositionsAndNormal( C, n_C, Q0 ), aoValueFromPositionsAndNormal( C, n_C, Q1 ) ); #else // The occluding point in camera space - vec3 Q = getOffsetPosition( issC, unitOffset, ssR, cszBuffer, invCszBufferScale ); + float3 Q = getOffsetPosition( issC, unitOffset, ssR, cszBuffer, invCszBufferScale ); return aoValueFromPositionsAndNormal( C, n_C, Q ); #endif @@ -335,13 +336,13 @@ void main( PS_IN fragment, out PS_OUT result ) #endif // Pixel being shaded - //float2 ssC = fragment.texcoord0; - //int2 issC = int2( ssC.x * rpScreenCorrectionFactor.z, ssC.y * rpScreenCorrectionFactor.w ); + //float2 ssC = fragment.texcoord0 * rpScreenCorrectionFactor.xy; + //int2 ssP = int2( ssC.x * rpScreenCorrectionFactor.z, ssC.y * rpScreenCorrectionFactor.w ); - int2 ssP = int2( gl_FragCoord.xy ); + int2 ssP = int2(gl_FragCoord.xy); // World space point being shaded - vec3 C = getPosition( ssP, CS_Z_buffer ); + float3 C = getPosition( ssP, CS_Z_buffer ); //float z = length( C - rpGlobalEyePos.xyz ); //bilateralKey = CSZToKey( C.z ); diff --git a/neo/renderer/RenderBackend.cpp b/neo/renderer/RenderBackend.cpp index c26dab62..e4fc6eef 100644 --- a/neo/renderer/RenderBackend.cpp +++ b/neo/renderer/RenderBackend.cpp @@ -4749,7 +4749,7 @@ void idRenderBackend::DrawScreenSpaceAmbientOcclusion( const viewDef_t* _viewDef glClearColor( 0, 0, 0, 1 ); GL_SelectTexture( 0 ); - globalImages->currentDepthImage->Bind(); + //globalImages->currentDepthImage->Bind(); for( int i = 0; i < MAX_HIERARCHICAL_ZBUFFERS; i++ ) { diff --git a/neo/renderer/RenderSystem_init.cpp b/neo/renderer/RenderSystem_init.cpp index 84a76837..3dc2f0a1 100644 --- a/neo/renderer/RenderSystem_init.cpp +++ b/neo/renderer/RenderSystem_init.cpp @@ -283,7 +283,7 @@ idCVar r_ssgiFiltering( "r_ssgiFiltering", "1", CVAR_RENDERER | CVAR_BOOL, "" ); idCVar r_useSSAO( "r_useSSAO", "1", CVAR_RENDERER | CVAR_ARCHIVE | CVAR_BOOL, "use screen space ambient occlusion to darken corners" ); idCVar r_ssaoDebug( "r_ssaoDebug", "0", CVAR_RENDERER | CVAR_INTEGER, "" ); idCVar r_ssaoFiltering( "r_ssaoFiltering", "1", CVAR_RENDERER | CVAR_BOOL, "" ); -idCVar r_useHierarchicalDepthBuffer( "r_useHierarchicalDepthBuffer", "1", CVAR_RENDERER | CVAR_BOOL, "" ); +idCVar r_useHierarchicalDepthBuffer( "r_useHierarchicalDepthBuffer", "0", CVAR_RENDERER | CVAR_BOOL, "" ); idCVar r_exposure( "r_exposure", "0.5", CVAR_ARCHIVE | CVAR_RENDERER | CVAR_FLOAT, "HDR exposure or LDR brightness [0.0 .. 1.0]", 0.0f, 1.0f ); // RB end @@ -1948,7 +1948,7 @@ void R_VidRestart_f( const idCmdArgs& args ) } // set the mode without re-initializing the context - R_SetNewMode( false ); + R_SetNewMode(false); // GK: Borderless Mode resolution fixup. // While we are in exclusive fullscreen we can control the monitor resolution alongside with the game's resolution. // But in borderless we are limited to the System's resolution and without any DPI awareness System.