From de57cfc9a7320eb1f376c2061a58939dc405202c Mon Sep 17 00:00:00 2001 From: Johann Muszynski Date: Sun, 23 Jun 2024 19:44:00 +0300 Subject: [PATCH] wip --- src/pt/deferred_renderer.cpp | 30 ++++++++++------------ src/pt/deferred_renderer.hpp | 5 +--- src/pt/deferred_renderer_gbuffer_pass.wgsl | 5 ++-- src/pt/shader_source.hpp | 5 ++-- 4 files changed, 18 insertions(+), 27 deletions(-) diff --git a/src/pt/deferred_renderer.cpp b/src/pt/deferred_renderer.cpp index 4214419..6b166f3 100644 --- a/src/pt/deferred_renderer.cpp +++ b/src/pt/deferred_renderer.cpp @@ -299,6 +299,13 @@ void DeferredRenderer::render( const Extent2f framebufferSize = Extent2f(renderDesc.framebufferSize); const std::uint32_t frameCount = mFrameCount++; + const glm::mat4 jitterMat = [this, framebufferSize, frameCount]() -> glm::mat4 { + glm::mat4 jitterMat = glm::mat4(1.0f); + const glm::vec2 j = r2Sequence(frameCount, 1 << 20); + jitterMat[3][0] = (j.x - 0.5f) / framebufferSize.x; + jitterMat[3][1] = (j.y - 0.5f) / framebufferSize.y; + return jitterMat; + }(); // GBuffer pass @@ -308,13 +315,11 @@ void DeferredRenderer::render( offsetof(TimestampsLayout, gbufferPassStart) / TimestampsLayout::MEMBER_SIZE); mGbufferPass.render( gpuContext, - renderDesc.viewReverseZProjectionMatrix, + jitterMat * renderDesc.viewReverseZProjectionMatrix, encoder, mDepthTextureView, mAlbedoTextureView, - mNormalTextureView, - framebufferSize, - frameCount); + mNormalTextureView); wgpuCommandEncoderWriteTimestamp( encoder, mQuerySet, @@ -328,7 +333,7 @@ void DeferredRenderer::render( offsetof(TimestampsLayout, lightingPassStart) / TimestampsLayout::MEMBER_SIZE); { const glm::mat4 inverseViewProjectionMat = - glm::inverse(renderDesc.viewReverseZProjectionMatrix); + glm::inverse(jitterMat * renderDesc.viewReverseZProjectionMatrix); mLightingPass.render( gpuContext, encoder, @@ -457,9 +462,7 @@ void DeferredRenderer::renderDebug( encoder, mDepthTextureView, mAlbedoTextureView, - mNormalTextureView, - framebufferSize, - mFrameCount++); + mNormalTextureView); mDebugPass.render(gpuContext, encoder, textureView, framebufferSize, gui); @@ -1007,16 +1010,9 @@ void DeferredRenderer::GbufferPass::render( const WGPUCommandEncoder cmdEncoder, const WGPUTextureView depthTextureView, const WGPUTextureView albedoTextureView, - const WGPUTextureView normalTextureView, - const Extent2f& framebufferSize, - const std::uint32_t frameCount) + const WGPUTextureView normalTextureView) { - Uniforms uniforms{viewReverseZProjectionMatrix, glm::mat4(1.0f)}; - { - const glm::vec2 j = r2Sequence(frameCount, 1 << 20); - uniforms.jitterMat[3][0] = (j.x - 0.5f) / framebufferSize.x; - uniforms.jitterMat[3][1] = (j.y - 0.5f) / framebufferSize.y; - } + const Uniforms uniforms{viewReverseZProjectionMatrix}; wgpuQueueWriteBuffer(gpuContext.queue, mUniformBuffer.ptr(), 0, &uniforms, sizeof(Uniforms)); const WGPURenderPassEncoder renderPassEncoder = [cmdEncoder, diff --git a/src/pt/deferred_renderer.hpp b/src/pt/deferred_renderer.hpp index 3395fbb..ec10102 100644 --- a/src/pt/deferred_renderer.hpp +++ b/src/pt/deferred_renderer.hpp @@ -109,7 +109,6 @@ class DeferredRenderer struct Uniforms { glm::mat4 viewProjectionMat; - glm::mat4 jitterMat; }; public: @@ -129,9 +128,7 @@ class DeferredRenderer WGPUCommandEncoder cmdEncoder, WGPUTextureView depthTextureView, WGPUTextureView albedoTextureView, - WGPUTextureView normalTextureView, - const Extent2f& framebufferSize, - std::uint32_t frameCount); + WGPUTextureView normalTextureView); }; struct DebugPass diff --git a/src/pt/deferred_renderer_gbuffer_pass.wgsl b/src/pt/deferred_renderer_gbuffer_pass.wgsl index d81e28e..b1e3015 100644 --- a/src/pt/deferred_renderer_gbuffer_pass.wgsl +++ b/src/pt/deferred_renderer_gbuffer_pass.wgsl @@ -1,6 +1,5 @@ struct Uniforms { - viewReverseZProjectionMat: mat4x4f, - jitterMat: mat4x4f + viewReverseZProjectionMat: mat4x4f } @group(0) @binding(0) var uniforms: Uniforms; @@ -20,7 +19,7 @@ struct VertexOutput { @vertex fn vsMain(in: VertexInput) -> VertexOutput { var out: VertexOutput; - out.position = uniforms.jitterMat * uniforms.viewReverseZProjectionMat * in.position; + out.position = uniforms.viewReverseZProjectionMat * in.position; out.normal = in.normal; out.texCoord = in.texCoord; return out; diff --git a/src/pt/shader_source.hpp b/src/pt/shader_source.hpp index 98610dd..88680b3 100644 --- a/src/pt/shader_source.hpp +++ b/src/pt/shader_source.hpp @@ -624,8 +624,7 @@ fn animatedBlueNoise(coord: vec2u, frameIdx: u32, totalSampleCount: u32) -> vec2 )"; const char* const DEFERRED_RENDERER_GBUFFER_PASS_SOURCE = R"(struct Uniforms { - viewReverseZProjectionMat: mat4x4f, - jitterMat: mat4x4f + viewReverseZProjectionMat: mat4x4f } @group(0) @binding(0) var uniforms: Uniforms; @@ -645,7 +644,7 @@ struct VertexOutput { @vertex fn vsMain(in: VertexInput) -> VertexOutput { var out: VertexOutput; - out.position = uniforms.jitterMat * uniforms.viewReverseZProjectionMat * in.position; + out.position = uniforms.viewReverseZProjectionMat * in.position; out.normal = in.normal; out.texCoord = in.texCoord; return out;