From a12db413fc939605ec30271f3ea64d43b165e775 Mon Sep 17 00:00:00 2001 From: Robert Beckebans Date: Sat, 11 Feb 2023 18:08:00 +0100 Subject: [PATCH] Added missing TAA pixeloffset to SSAO pass --- neo/renderer/Passes/SsaoPass.cpp | 3 + neo/renderer/Passes/SsaoPass.h | 13 ---- .../Passes/TemporalAntiAliasingPass.cpp | 68 +------------------ neo/shaders/builtin/SSAO/ssao_blur.cs.hlsl | 2 + neo/shaders/builtin/SSAO/ssao_compute.cs.hlsl | 7 +- .../builtin/SSAO/ssao_deinterleave.cs.hlsl | 2 + 6 files changed, 12 insertions(+), 83 deletions(-) diff --git a/neo/renderer/Passes/SsaoPass.cpp b/neo/renderer/Passes/SsaoPass.cpp index 613882de..5fbeb5f0 100644 --- a/neo/renderer/Passes/SsaoPass.cpp +++ b/neo/renderer/Passes/SsaoPass.cpp @@ -41,6 +41,8 @@ struct SsaoConstants { idVec2 viewportOrigin; idVec2 viewportSize; + idVec2 pixelOffset; + idVec2 unused; idRenderMatrix matClipToView; idRenderMatrix matWorldToView; // unused @@ -258,6 +260,7 @@ void SsaoPass::Render( SsaoConstants ssaoConstants = {}; ssaoConstants.viewportOrigin = idVec2( viewDef->viewport.x1, viewDef->viewport.y1 ); ssaoConstants.viewportSize = idVec2( viewDef->viewport.GetWidth(), viewDef->viewport.GetHeight() ); + ssaoConstants.pixelOffset = tr.backend.GetCurrentPixelOffset(); // RB: this actually should work but it only works with the old SSAO method ... //ssaoConstants.matClipToView = viewDef->unprojectionToCameraRenderMatrix; diff --git a/neo/renderer/Passes/SsaoPass.h b/neo/renderer/Passes/SsaoPass.h index a8725018..c642f5c2 100644 --- a/neo/renderer/Passes/SsaoPass.h +++ b/neo/renderer/Passes/SsaoPass.h @@ -22,19 +22,6 @@ #ifndef RENDERER_PASSES_SSAOPASS_H_ #define RENDERER_PASSES_SSAOPASS_H_ -/* -struct SsaoParameters -{ - float amount = 2.f; - float backgroundViewDepth = 100.f; - float radiusWorld = 0.5f; - float surfaceBias = 0.1f; - float powerExponent = 2.f; - bool enableBlur = true; - float blurSharpness = 16.f; -}; -*/ - class SsaoPass { private: diff --git a/neo/renderer/Passes/TemporalAntiAliasingPass.cpp b/neo/renderer/Passes/TemporalAntiAliasingPass.cpp index 20ec9806..2a6079c5 100644 --- a/neo/renderer/Passes/TemporalAntiAliasingPass.cpp +++ b/neo/renderer/Passes/TemporalAntiAliasingPass.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved. +* Copyright (C) 2022 Robert Beckebans (id Tech 4x integration) * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -162,22 +163,6 @@ void TemporalAntiAliasingPass::Init( bindingSetDesc.bindings.push_back( nvrhi::BindingSetItem::Texture_SRV( 1, params.sourceDepth, stencilFormat ) ); } m_MotionVectorsBindingSet = device->createBindingSet( bindingSetDesc, m_MotionVectorsBindingLayout ); - -#if 0 - nvrhi::GraphicsPipelineDesc pipelineDesc; - pipelineDesc.primType = nvrhi::PrimitiveType::TriangleStrip; - pipelineDesc.VS = taaMotionVectorsShaderInfo.vs; //m_CommonPasses->m_FullscreenVS; - pipelineDesc.PS = taaMotionVectorsShaderInfo.ps; //m_MotionVectorPS; - pipelineDesc.bindingLayouts = { m_MotionVectorsBindingLayout }; - - pipelineDesc.renderState.rasterState.setCullNone(); - pipelineDesc.renderState.depthStencilState.depthTestEnable = false; - pipelineDesc.renderState.depthStencilState.stencilEnable = false; - - //nvrhi::IFramebuffer* sampleFramebuffer = m_MotionVectorsFramebufferFactory->GetFramebuffer( *sampleView ); - nvrhi::IFramebuffer* sampleFramebuffer = globalFramebuffers.taaMotionVectorsFBO->GetApiObject(); - m_MotionVectorsPso = device->createGraphicsPipeline( pipelineDesc, sampleFramebuffer ); -#endif } { @@ -208,55 +193,6 @@ void TemporalAntiAliasingPass::Init( } } -#if 0 -void TemporalAntiAliasingPass::RenderMotionVectors( - nvrhi::ICommandList* commandList, - const ICompositeView& compositeView, - const ICompositeView& compositeViewPrevious, - dm::float3 preViewTranslationDifference ) -{ - assert( compositeView.GetNumChildViews( ViewType::PLANAR ) == compositeViewPrevious.GetNumChildViews( ViewType::PLANAR ) ); - assert( m_MotionVectorsPso ); - - commandList->beginMarker( "MotionVectors" ); - - for( uint viewIndex = 0; viewIndex < compositeView.GetNumChildViews( ViewType::PLANAR ); viewIndex++ ) - { - const IView* view = compositeView.GetChildView( ViewType::PLANAR, viewIndex ); - const IView* viewPrevious = compositeViewPrevious.GetChildView( ViewType::PLANAR, viewIndex ); - - const nvrhi::ViewportState viewportState = view->GetViewportState(); - - // This pass only works for planar, single-viewport views - assert( viewportState.viewports.size() == 1 ); - - const nvrhi::Viewport& inputViewport = viewportState.viewports[0]; - - TemporalAntiAliasingConstants taaConstants = {}; - affine3 viewReprojection = inverse( view->GetViewMatrix() ) * translation( -preViewTranslationDifference ) * viewPrevious->GetViewMatrix(); - taaConstants.reprojectionMatrix = inverse( view->GetProjectionMatrix( false ) ) * affineToHomogeneous( viewReprojection ) * viewPrevious->GetProjectionMatrix( false ); - taaConstants.inputViewOrigin = float2( inputViewport.minX, inputViewport.minY ); - taaConstants.inputViewSize = float2( inputViewport.width(), inputViewport.height() ); - taaConstants.stencilMask = m_StencilMask; - commandList->writeBuffer( m_TemporalAntiAliasingCB, &taaConstants, sizeof( taaConstants ) ); - - nvrhi::GraphicsState state; - state.pipeline = m_MotionVectorsPso; - state.framebuffer = m_MotionVectorsFramebufferFactory->GetFramebuffer( *view ); - state.bindings = { m_MotionVectorsBindingSet}; - state.viewport = viewportState; - commandList->setGraphicsState( state ); - - nvrhi::DrawArguments args; - args.instanceCount = 1; - args.vertexCount = 4; - commandList->draw( args ); - } - - commandList->endMarker(); -} -#endif - void TemporalAntiAliasingPass::TemporalResolve( nvrhi::ICommandList* commandList, const TemporalAntiAliasingParameters& params, @@ -279,9 +215,7 @@ void TemporalAntiAliasingPass::TemporalResolve( taaConstants.inputViewSize = idVec2( viewportInput.width() + 1, viewportInput.height() + 1 ); taaConstants.outputViewOrigin = idVec2( viewportOutput.minX, viewportOutput.minY ); taaConstants.outputViewSize = idVec2( viewportOutput.width() + 1, viewportOutput.height() + 1 ); - //taaConstants.inputPixelOffset.Set( 0, 0 ); // TODO = viewInput->GetPixelOffset(); taaConstants.inputPixelOffset = GetCurrentPixelOffset(); - // SRS - FIXME: Is this correct? Replaces 1.0f / idVec2 () which does not compile using Clang taaConstants.outputTextureSizeInv = idVec2( 1.0f, 1.0f ) / idVec2( float( renderSystem->GetWidth() ), float( renderSystem->GetHeight() ) ); taaConstants.inputOverOutputViewSize = taaConstants.inputViewSize / taaConstants.outputViewSize; taaConstants.outputOverInputViewSize = taaConstants.outputViewSize / taaConstants.inputViewSize; diff --git a/neo/shaders/builtin/SSAO/ssao_blur.cs.hlsl b/neo/shaders/builtin/SSAO/ssao_blur.cs.hlsl index 8ba3c435..0b487464 100644 --- a/neo/shaders/builtin/SSAO/ssao_blur.cs.hlsl +++ b/neo/shaders/builtin/SSAO/ssao_blur.cs.hlsl @@ -28,6 +28,8 @@ struct SsaoConstants { float2 viewportOrigin; float2 viewportSize; + float2 pixelOffset; + float2 unused; // padding float4x4 matClipToView; float4x4 matWorldToView; diff --git a/neo/shaders/builtin/SSAO/ssao_compute.cs.hlsl b/neo/shaders/builtin/SSAO/ssao_compute.cs.hlsl index c142360e..4ded9a85 100644 --- a/neo/shaders/builtin/SSAO/ssao_compute.cs.hlsl +++ b/neo/shaders/builtin/SSAO/ssao_compute.cs.hlsl @@ -28,6 +28,8 @@ struct SsaoConstants { float2 viewportOrigin; float2 viewportSize; + float2 pixelOffset; + float2 unused; // padding float4x4 matClipToView; float4x4 matWorldToView; @@ -182,9 +184,8 @@ float2 WindowToClip( float2 windowPos ) float2 windowToClipScale = 1.0 / clipToWindowScale; float2 windowToClipBias = -clipToWindowBias * windowToClipScale; - // TODO add pixelOffset for TAA - //windowPos = windowPos * 2.0 - 1.0; - return windowPos.xy * windowToClipScale + windowToClipBias; + //return windowPos.xy * windowToClipScale + windowToClipBias; + return ( windowPos.xy + g_Ssao.pixelOffset.xy ) * windowToClipScale + windowToClipBias; } float3 ViewDepthToViewPos( float2 clipPosXY, float viewDepth ) diff --git a/neo/shaders/builtin/SSAO/ssao_deinterleave.cs.hlsl b/neo/shaders/builtin/SSAO/ssao_deinterleave.cs.hlsl index 2ac93728..7b2a1f9f 100644 --- a/neo/shaders/builtin/SSAO/ssao_deinterleave.cs.hlsl +++ b/neo/shaders/builtin/SSAO/ssao_deinterleave.cs.hlsl @@ -28,6 +28,8 @@ struct SsaoConstants { float2 viewportOrigin; float2 viewportSize; + float2 pixelOffset; + float2 unused; // padding float4x4 matClipToView; float4x4 matWorldToView;