mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-03-22 15:05:03 +01:00
fix gtao glitches; add timer to measure animation phase
This commit is contained in:
@@ -161,21 +161,21 @@ namespace XeGTAO
|
||||
template<class T> inline T clamp( T const & v, T const & min, T const & max ) { assert( max >= min ); if( v < min ) return min; if( v > max ) return max; return v; }
|
||||
|
||||
// If using TAA then set noiseIndex to frameIndex % 64 - otherwise use 0
|
||||
inline void GTAOUpdateConstants( XeGTAO::GTAOConstants& consts, int viewportWidth, int viewportHeight, const XeGTAO::GTAOSettings & settings, const float projMatrix[16], bool rowMajor, unsigned int frameCounter )
|
||||
inline void GTAOUpdateConstants( XeGTAO::GTAOConstants& consts, int viewportWidth, int viewportHeight, const XeGTAO::GTAOSettings & settings, const glm::mat4& projMatrix, bool rowMajor, unsigned int frameCounter )
|
||||
{
|
||||
consts.ViewportSize = { viewportWidth, viewportHeight };
|
||||
consts.ViewportPixelSize = { 1.0f / (float)viewportWidth, 1.0f / (float)viewportHeight };
|
||||
|
||||
float depthLinearizeMul = (rowMajor)?(-projMatrix[3 * 4 + 2]):(-projMatrix[3 + 2 * 4]); // float depthLinearizeMul = ( clipFar * clipNear ) / ( clipFar - clipNear );
|
||||
float depthLinearizeAdd = (rowMajor)?( projMatrix[2 * 4 + 2]):( projMatrix[2 + 2 * 4]); // float depthLinearizeAdd = clipFar / ( clipFar - clipNear );
|
||||
float depthLinearizeMul = -projMatrix[3][2]; // float depthLinearizeMul = ( clipFar * clipNear ) / ( clipFar - clipNear );
|
||||
float depthLinearizeAdd = -projMatrix[2][2]; // float depthLinearizeAdd = clipFar / ( clipFar - clipNear );
|
||||
|
||||
// correct the handedness issue. need to make sure this below is correct, but I think it is.
|
||||
if( depthLinearizeMul * depthLinearizeAdd < 0 )
|
||||
depthLinearizeAdd = -depthLinearizeAdd;
|
||||
consts.DepthUnpackConsts = { -depthLinearizeMul, depthLinearizeAdd };
|
||||
consts.DepthUnpackConsts = { depthLinearizeMul, depthLinearizeAdd };
|
||||
|
||||
float tanHalfFOVY = 1.0f / ((rowMajor)?(projMatrix[1 * 4 + 1]):(projMatrix[1 + 1 * 4])); // = tanf( drawContext.Camera.GetYFOV( ) * 0.5f );
|
||||
float tanHalfFOVX = 1.0F / ((rowMajor)?(projMatrix[0 * 4 + 0]):(projMatrix[0 + 0 * 4])); // = tanHalfFOVY * drawContext.Camera.GetAspect( );
|
||||
float tanHalfFOVY = 1.0f / projMatrix[1][1]; // = tanf( drawContext.Camera.GetYFOV( ) * 0.5f );
|
||||
float tanHalfFOVX = 1.0F / projMatrix[0][0]; // = tanHalfFOVY * drawContext.Camera.GetAspect( );
|
||||
consts.CameraTanHalfFOV = { tanHalfFOVX, tanHalfFOVY };
|
||||
|
||||
consts.NDCToViewMul = { consts.CameraTanHalfFOV.x * 2.0f, consts.CameraTanHalfFOV.y * -2.0f };
|
||||
|
||||
@@ -1321,6 +1321,8 @@ void NvRenderer::DebugUi() {
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Bloom Config")) m_bloom->ShowGui();
|
||||
ImGui::SameLine();
|
||||
m_ssao->OnGui(ImGui::Button("GTAO Config"));
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Take Screenshot")) MakeScreenshot();
|
||||
}
|
||||
ImGui::End();
|
||||
|
||||
@@ -129,6 +129,27 @@ void NvSsao::Init() {
|
||||
.addBindingLayout(blPrefilterDepths));
|
||||
}
|
||||
|
||||
{
|
||||
BindingLayoutHandle blPrefilterDepths;
|
||||
BindingSetDesc bsDescPrefilter =
|
||||
BindingSetDesc()
|
||||
.addItem(BindingSetItem::ConstantBuffer(0, m_constantBuffer))
|
||||
.addItem(BindingSetItem::Texture_SRV(0, m_gbuffer->m_gbuffer_depth))
|
||||
.addItem(BindingSetItem::Sampler(0, sampler_point));
|
||||
for (int i = 0; i < XE_GTAO_DEPTH_MIP_LEVELS; ++i) {
|
||||
bsDescPrefilter.addItem(
|
||||
BindingSetItem::Texture_UAV(i, m_workingDepths, Format::UNKNOWN,
|
||||
TextureSubresourceSet(i, 1, 0, 1)));
|
||||
}
|
||||
utils::CreateBindingSetAndLayout(m_backend->GetDevice(),
|
||||
ShaderType::Compute, 0, bsDescPrefilter,
|
||||
blPrefilterDepths, m_BSPrefilterDepths);
|
||||
m_PSOPrefilterDepths = m_backend->GetDevice()->createComputePipeline(
|
||||
ComputePipelineDesc()
|
||||
.setComputeShader(m_CSPrefilterDepths16x16)
|
||||
.addBindingLayout(blPrefilterDepths));
|
||||
}
|
||||
|
||||
{
|
||||
BindingLayoutHandle blGTAO;
|
||||
utils::CreateBindingSetAndLayout(
|
||||
@@ -187,12 +208,8 @@ void NvSsao::Render(nvrhi::ICommandList* command_list,
|
||||
command_list->beginMarker("XeGTAO");
|
||||
|
||||
XeGTAO::GTAOConstants constants{};
|
||||
XeGTAO::GTAOSettings settings{};
|
||||
settings.QualityLevel = 2;
|
||||
settings.Radius = 10.f;
|
||||
settings.ThinOccluderCompensation = .7f;
|
||||
XeGTAO::GTAOUpdateConstants(constants, m_width, m_height, settings,
|
||||
glm::value_ptr(projection), false, frame_index);
|
||||
projection, false, frame_index);
|
||||
command_list->writeBuffer(m_constantBuffer, &constants, sizeof(constants));
|
||||
|
||||
{
|
||||
@@ -222,7 +239,7 @@ void NvSsao::Render(nvrhi::ICommandList* command_list,
|
||||
|
||||
{
|
||||
command_list->beginMarker("Denoise Pass");
|
||||
int num_passes = 4;
|
||||
int num_passes = settings.DenoisePasses;
|
||||
nvrhi::ITexture* ping = m_workingAOTerm;
|
||||
nvrhi::ITexture* pong = m_workingAOTermPong;
|
||||
for (int i = 0; i < num_passes; ++i) {
|
||||
@@ -260,3 +277,22 @@ void NvSsao::Render(nvrhi::ICommandList* command_list,
|
||||
}
|
||||
command_list->endMarker();
|
||||
}
|
||||
|
||||
void NvSsao::OnGui(bool const open_now) {
|
||||
static bool open = false;
|
||||
open |= open_now;
|
||||
if(open && ImGui::Begin("GTAO Settings", &open)) {
|
||||
ImGui::InputInt("Quality level", &settings.QualityLevel);
|
||||
ImGui::InputInt("Denoise passes", &settings.DenoisePasses);
|
||||
ImGui::InputFloat("Radius", &settings.Radius);
|
||||
if(ImGui::CollapsingHeader("Advanced")) {
|
||||
ImGui::InputFloat("Radius multiplier", &settings.RadiusMultiplier);
|
||||
ImGui::InputFloat("Falloff range", &settings.FalloffRange);
|
||||
ImGui::InputFloat("Sample distribution power", &settings.SampleDistributionPower);
|
||||
ImGui::InputFloat("Thin occluder compensation", &settings.ThinOccluderCompensation);
|
||||
ImGui::InputFloat("Final value power", &settings.FinalValuePower);
|
||||
ImGui::InputFloat("Depth MIP sampling offset", &settings.DepthMIPSamplingOffset);
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <nvrhi/nvrhi.h>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <memory>
|
||||
|
||||
#include <nvrhi/nvrhi.h>
|
||||
#include "XeGTAO.h"
|
||||
|
||||
struct NvSsao {
|
||||
NvSsao(class NvRenderer* renderer);
|
||||
void Init();
|
||||
|
||||
XeGTAO::GTAOSettings settings{};
|
||||
|
||||
class NvRendererBackend* m_backend;
|
||||
struct NvGbuffer* m_gbuffer;
|
||||
|
||||
@@ -52,4 +55,6 @@ struct NvSsao {
|
||||
|
||||
void Render(nvrhi::ICommandList* command_list, const glm::mat4& projection,
|
||||
size_t frame_index);
|
||||
|
||||
void OnGui(bool open_now);
|
||||
};
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "nvrenderer/nvrenderer.h"
|
||||
#include "nvrendererbackend.h"
|
||||
|
||||
#include <Timer.h>
|
||||
#include <AnimModel.h>
|
||||
#include <simulation.h>
|
||||
|
||||
@@ -1057,6 +1058,7 @@ void NvRenderer::Render(const Renderable& renderable, const RenderPass& pass,
|
||||
|
||||
void NvRenderer::Animate(const glm::dvec3& origin, double radius,
|
||||
uint64_t frame) {
|
||||
Timer::subsystem.gfx_animate.start();
|
||||
{
|
||||
auto motion_scope = m_motion_cache->SetInstance(nullptr);
|
||||
auto& motion_cache = m_motion_cache->Get(nullptr);
|
||||
@@ -1095,6 +1097,7 @@ void NvRenderer::Animate(const glm::dvec3& origin, double radius,
|
||||
if (!instance.m_animatable && instance.m_was_once_animated) return;
|
||||
Animate(instance, origin, frame);
|
||||
});
|
||||
Timer::subsystem.gfx_animate.stop();
|
||||
}
|
||||
|
||||
void NvRenderer::GatherSpotLights(const RenderPass& pass) {
|
||||
|
||||
@@ -54,6 +54,7 @@ SamplerState g_samplerPointClamp : register( s0 );
|
||||
// Engine-specific normal map loader
|
||||
lpfloat3 LoadNormal( int2 pos )
|
||||
{
|
||||
return (float3)0.;
|
||||
#if 0
|
||||
// special decoding for external normals stored in 11_11_10 unorm - modify appropriately to support your own encoding
|
||||
uint packedInput = g_srcNormalmap.Load( int3(pos, 0) ).x;
|
||||
|
||||
@@ -111,11 +111,10 @@ float3 XeGTAO_ComputeViewspacePosition( const float2 screenPos, const float view
|
||||
|
||||
float XeGTAO_ScreenSpaceToViewSpaceDepth( const float screenDepth, const GTAOConstants consts )
|
||||
{
|
||||
float depthLinearizeMul = consts.DepthUnpackConsts.x;
|
||||
float depthLinearizeAdd = consts.DepthUnpackConsts.y;
|
||||
// Optimised version of "-cameraClipNear / (cameraClipFar - projDepth * (cameraClipFar - cameraClipNear)) * cameraClipFar"
|
||||
//return 2500. / (.1 - screenDepth * (.1 - 2500.)) * .1;
|
||||
return depthLinearizeMul / (depthLinearizeAdd - screenDepth);
|
||||
float depthLinearizeMul = consts.DepthUnpackConsts.x;
|
||||
float depthLinearizeAdd = consts.DepthUnpackConsts.y;
|
||||
// Optimised version of "-cameraClipNear / (cameraClipFar - projDepth * (cameraClipFar - cameraClipNear)) * cameraClipFar"
|
||||
return depthLinearizeMul / (depthLinearizeAdd - screenDepth);
|
||||
}
|
||||
|
||||
lpfloat4 XeGTAO_CalculateEdges( const lpfloat centerZ, const lpfloat leftZ, const lpfloat rightZ, const lpfloat topZ, const lpfloat bottomZ )
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
templates:
|
||||
# Partially pre-filled containers to avoid excessive copypasta
|
||||
XeGTAO:
|
||||
# TODO Depth conversion is broken since converting to reversed depth buffer
|
||||
# after attempting to fix it, it is still broken but with hardcoded values
|
||||
source: XeGTAO/GTAO
|
||||
target: compute
|
||||
definitions: # TODO (mostly) move to shader file I guess
|
||||
@@ -14,6 +12,7 @@ templates:
|
||||
XE_GTAO_USE_HALF_FLOAT_PRECISION: 0
|
||||
VA_COMPILED_AS_SHADER_CODE: 1
|
||||
VA_SATURATE: saturate
|
||||
XE_GTAO_GENERATE_NORMALS_INPLACE: 1
|
||||
envmap:
|
||||
source: envmap
|
||||
target: compute
|
||||
|
||||
Reference in New Issue
Block a user