Skip to content

Commit

Permalink
wip render to velocity buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
Nelarius committed Jun 28, 2024
1 parent e131675 commit e975c9a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
31 changes: 29 additions & 2 deletions src/pt/deferred_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace
const WGPUTextureFormat DEPTH_TEXTURE_FORMAT = WGPUTextureFormat_Depth32Float;
const WGPUTextureFormat ALBEDO_TEXTURE_FORMAT = WGPUTextureFormat_BGRA8Unorm;
const WGPUTextureFormat NORMAL_TEXTURE_FORMAT = WGPUTextureFormat_RGBA16Float;
const WGPUTextureFormat VELOCITY_TEXTURE_FORMAT = WGPUTextureFormat_RG16Float;

struct TimestampsLayout
{
Expand Down Expand Up @@ -96,6 +97,8 @@ DeferredRenderer::DeferredRenderer(
mAlbedoTextureView(nullptr),
mNormalTexture(nullptr),
mNormalTextureView(nullptr),
mVelocityTexture(nullptr),
mVelocityTextureView(nullptr),
mSampleBuffer(
gpuContext.device,
"Deferred renderer :: sample buffer",
Expand Down Expand Up @@ -178,6 +181,18 @@ DeferredRenderer::DeferredRenderer(
mNormalTexture, "Gbuffer normal texture view", NORMAL_TEXTURE_FORMAT);
NLRS_ASSERT(mNormalTextureView != nullptr);

mVelocityTexture = createGbufferTexture(
gpuContext.device,
"Gbuffer velocity texture",
WGPUTextureUsage_RenderAttachment | WGPUTextureUsage_TextureBinding,
rendererDesc.framebufferSize,
VELOCITY_TEXTURE_FORMAT);
NLRS_ASSERT(mVelocityTexture != nullptr);

mVelocityTextureView = createGbufferTextureView(
mVelocityTexture, "Gbuffer velocity texture view", VELOCITY_TEXTURE_FORMAT);
NLRS_ASSERT(mVelocityTextureView != nullptr);

{
const WGPUQuerySetDescriptor querySetDesc{
.nextInChain = nullptr,
Expand Down Expand Up @@ -210,6 +225,10 @@ DeferredRenderer::~DeferredRenderer()
{
querySetSafeRelease(mQuerySet);
mQuerySet = nullptr;
textureViewSafeRelease(mVelocityTextureView);
mVelocityTextureView = nullptr;
textureSafeRelease(mVelocityTexture);
mVelocityTexture = nullptr;
textureViewSafeRelease(mNormalTextureView);
mNormalTextureView = nullptr;
textureSafeRelease(mNormalTexture);
Expand Down Expand Up @@ -240,6 +259,10 @@ DeferredRenderer::DeferredRenderer(DeferredRenderer&& other)
other.mNormalTexture = nullptr;
mNormalTextureView = other.mNormalTextureView;
other.mNormalTextureView = nullptr;
mVelocityTexture = other.mVelocityTexture;
other.mVelocityTexture = nullptr;
mVelocityTextureView = other.mVelocityTextureView;
other.mVelocityTextureView = nullptr;
mSampleBuffer = std::move(other.mSampleBuffer);
mQuerySet = other.mQuerySet;
other.mQuerySet = nullptr;
Expand Down Expand Up @@ -271,6 +294,10 @@ DeferredRenderer& DeferredRenderer::operator=(DeferredRenderer&& other)
other.mNormalTexture = nullptr;
mNormalTextureView = other.mNormalTextureView;
other.mNormalTextureView = nullptr;
mVelocityTexture = other.mVelocityTexture;
other.mVelocityTexture = nullptr;
mVelocityTextureView = other.mVelocityTextureView;
other.mVelocityTextureView = nullptr;
mSampleBuffer = std::move(other.mSampleBuffer);
mQuerySet = other.mQuerySet;
other.mQuerySet = nullptr;
Expand Down Expand Up @@ -1045,8 +1072,8 @@ void DeferredRenderer::GbufferPass::render(
.resolveTarget = nullptr,
.loadOp = WGPULoadOp_Clear,
.storeOp = WGPUStoreOp_Store,
.clearValue = WGPUColor{0.0, 0.0, 0.0, 1.0},
}};
.clearValue = WGPUColor{0.0, 0.0, 0.0, 1.0}},
WGPURenderPassColorAttachment{}};

const WGPURenderPassDepthStencilAttachment depthStencilAttachment{
.view = depthTextureView,
Expand Down
2 changes: 2 additions & 0 deletions src/pt/deferred_renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ class DeferredRenderer
WGPUTextureView mAlbedoTextureView;
WGPUTexture mNormalTexture;
WGPUTextureView mNormalTextureView;
WGPUTexture mVelocityTexture;
WGPUTextureView mVelocityTextureView;
GpuBuffer mSampleBuffer;
WGPUQuerySet mQuerySet;
GpuBuffer mQueryBuffer;
Expand Down
3 changes: 2 additions & 1 deletion src/pt/deferred_renderer_gbuffer_pass.wgsl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
struct Uniforms {
viewReverseZProjectionMat: mat4x4f,
jitterMat: mat4x4f
jitterMat: mat4x4f,
}

@group(0) @binding(0) var<uniform> uniforms: Uniforms;
Expand Down Expand Up @@ -32,6 +32,7 @@ fn vsMain(in: VertexInput) -> VertexOutput {
struct GbufferOutput {
@location(0) albedo: vec4<f32>,
@location(1) normal: vec4<f32>,
@location(2) velocity: vec2<f32>,
}

@fragment
Expand Down

0 comments on commit e975c9a

Please sign in to comment.