Skip to content

Commit

Permalink
wip pass matrices to resolve pass
Browse files Browse the repository at this point in the history
  • Loading branch information
Nelarius committed Jun 24, 2024
1 parent b699b07 commit ee4d9d1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
30 changes: 25 additions & 5 deletions src/pt/deferred_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <array>
#include <bit>
#include <numeric>
#include <tuple>

namespace nlrs
{
Expand Down Expand Up @@ -306,6 +307,8 @@ void DeferredRenderer::render(
jitterMat[3][1] = (j.y - 0.5f) / framebufferSize.y;
return jitterMat;
}();
const glm::mat4 jitterViewReverseZProjectionMat =
jitterMat * renderDesc.viewReverseZProjectionMatrix;

// GBuffer pass

Expand All @@ -315,7 +318,7 @@ void DeferredRenderer::render(
offsetof(TimestampsLayout, gbufferPassStart) / TimestampsLayout::MEMBER_SIZE);
mGbufferPass.render(
gpuContext,
jitterMat * renderDesc.viewReverseZProjectionMatrix,
jitterViewReverseZProjectionMat,
encoder,
mDepthTextureView,
mAlbedoTextureView,
Expand All @@ -332,8 +335,7 @@ void DeferredRenderer::render(
mQuerySet,
offsetof(TimestampsLayout, lightingPassStart) / TimestampsLayout::MEMBER_SIZE);
{
const glm::mat4 inverseViewProjectionMat =
glm::inverse(jitterMat * renderDesc.viewReverseZProjectionMatrix);
const glm::mat4 inverseViewProjectionMat = glm::inverse(jitterViewReverseZProjectionMat);
mLightingPass.render(
gpuContext,
encoder,
Expand All @@ -359,6 +361,7 @@ void DeferredRenderer::render(
gpuContext,
encoder,
renderDesc.targetTextureView,
jitterViewReverseZProjectionMat,
framebufferSize,
renderDesc.exposure,
frameCount,
Expand Down Expand Up @@ -1776,7 +1779,8 @@ DeferredRenderer::ResolvePass::ResolvePass(
GpuBufferUsages{GpuBufferUsage::Storage},
3 * sizeof(float) * area(rendererDesc.maxFramebufferSize)},
mTaaBindGroup{},
mPipeline(nullptr)
mPipeline(nullptr),
mPreviousViewProjectionMat(1.f)
{
const GpuBindGroupLayout uniformBindGroupLayout{
gpuContext.device,
Expand Down Expand Up @@ -1945,6 +1949,7 @@ DeferredRenderer::ResolvePass::ResolvePass(ResolvePass&& other) noexcept
mTaaBindGroup = std::move(other.mTaaBindGroup);
mPipeline = other.mPipeline;
other.mPipeline = nullptr;
mPreviousViewProjectionMat = other.mPreviousViewProjectionMat;
}
}

Expand All @@ -1961,6 +1966,7 @@ DeferredRenderer::ResolvePass& DeferredRenderer::ResolvePass::operator=(
renderPipelineSafeRelease(mPipeline);
mPipeline = other.mPipeline;
other.mPipeline = nullptr;
mPreviousViewProjectionMat = other.mPreviousViewProjectionMat;
}
return *this;
}
Expand All @@ -1969,13 +1975,27 @@ void DeferredRenderer::ResolvePass::render(
const GpuContext& gpuContext,
const WGPUCommandEncoder cmdEncoder,
WGPUTextureView targetTextureView,
const glm::mat4& viewProjectionMat,
const Extent2f& fbsize,
const float exposure,
const std::uint32_t frameCount,
Gui& gui)
{
{
const Uniforms uniforms{glm::vec2(fbsize.x, fbsize.y), exposure, frameCount};
const auto [currentInverseViewProjectionMat, previousViewProjectionMat] =
[this, frameCount, &viewProjectionMat]() -> std::tuple<glm::mat4, glm::mat4> {
glm::mat4 previousViewProjectionMat =
frameCount == 0 ? viewProjectionMat : mPreviousViewProjectionMat;
mPreviousViewProjectionMat = viewProjectionMat;
return std::make_tuple(glm::inverse(viewProjectionMat), previousViewProjectionMat);
}();

const Uniforms uniforms{
currentInverseViewProjectionMat,
previousViewProjectionMat,
glm::vec2(fbsize.x, fbsize.y),
exposure,
frameCount};
wgpuQueueWriteBuffer(
gpuContext.queue, mUniformBuffer.ptr(), 0, &uniforms, sizeof(Uniforms));
}
Expand Down
4 changes: 4 additions & 0 deletions src/pt/deferred_renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,12 @@ class DeferredRenderer
GpuBuffer mAccumulationBuffer = GpuBuffer{};
GpuBindGroup mTaaBindGroup = GpuBindGroup{};
WGPURenderPipeline mPipeline = nullptr;
glm::mat4 mPreviousViewProjectionMat;

struct Uniforms
{
glm::mat4 currentInverseViewProjectionMat;
glm::mat4 previousViewProjectionMat;
glm::vec2 framebufferSize;
float exposure;
std::uint32_t frameCount;
Expand All @@ -268,6 +271,7 @@ class DeferredRenderer
const GpuContext& gpuContext,
WGPUCommandEncoder cmdEncoder,
WGPUTextureView targetTextureView,
const glm::mat4& viewProjectionMatrix,
const Extent2f& framebufferSize,
float exposure,
std::uint32_t frameCount,
Expand Down
2 changes: 2 additions & 0 deletions src/pt/deferred_renderer_resolve_pass.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ fn vsMain(in: VertexInput) -> VertexOutput {
}

struct Uniforms {
currentInverseViewProjectionMat: mat4x4f,
previousViewProjectionMat: mat4x4f,
framebufferSize: vec2f,
exposure: f32,
frameCount: u32,
Expand Down
2 changes: 2 additions & 0 deletions src/pt/shader_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,8 @@ fn vsMain(in: VertexInput) -> VertexOutput {
}
struct Uniforms {
currentInverseViewProjectionMat: mat4x4f,
previousViewProjectionMat: mat4x4f,
framebufferSize: vec2f,
exposure: f32,
frameCount: u32,
Expand Down

0 comments on commit ee4d9d1

Please sign in to comment.