Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Nelarius committed Jun 23, 2024
1 parent 6a425d0 commit de57cfc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 27 deletions.
30 changes: 13 additions & 17 deletions src/pt/deferred_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -457,9 +462,7 @@ void DeferredRenderer::renderDebug(
encoder,
mDepthTextureView,
mAlbedoTextureView,
mNormalTextureView,
framebufferSize,
mFrameCount++);
mNormalTextureView);

mDebugPass.render(gpuContext, encoder, textureView, framebufferSize, gui);

Expand Down Expand Up @@ -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,
Expand Down
5 changes: 1 addition & 4 deletions src/pt/deferred_renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ class DeferredRenderer
struct Uniforms
{
glm::mat4 viewProjectionMat;
glm::mat4 jitterMat;
};

public:
Expand All @@ -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
Expand Down
5 changes: 2 additions & 3 deletions src/pt/deferred_renderer_gbuffer_pass.wgsl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
struct Uniforms {
viewReverseZProjectionMat: mat4x4f,
jitterMat: mat4x4f
viewReverseZProjectionMat: mat4x4f
}

@group(0) @binding(0) var<uniform> uniforms: Uniforms;
Expand All @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions src/pt/shader_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uniform> uniforms: Uniforms;
Expand All @@ -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;
Expand Down

0 comments on commit de57cfc

Please sign in to comment.