From 83d8516b78c8821bd83ae2301fe6be08ddaa963d Mon Sep 17 00:00:00 2001 From: Johann Muszynski Date: Wed, 3 Jul 2024 19:47:55 +0300 Subject: [PATCH] some attempts to get visible velocity --- src/pt/deferred_renderer.cpp | 2 +- src/pt/deferred_renderer_debug_pass.wgsl | 5 ++--- src/pt/deferred_renderer_gbuffer_pass.wgsl | 5 +++-- src/pt/shader_source.hpp | 10 +++++----- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/pt/deferred_renderer.cpp b/src/pt/deferred_renderer.cpp index ced789d..69dc13a 100644 --- a/src/pt/deferred_renderer.cpp +++ b/src/pt/deferred_renderer.cpp @@ -953,7 +953,7 @@ DeferredRenderer::GbufferPass::GbufferPass( .nextInChain = nullptr, .format = VELOCITY_TEXTURE_FORMAT, .blend = &blendState, - .writeMask = WGPUColorWriteMask_All, + .writeMask = WGPUColorWriteMask_Red | WGPUColorWriteMask_Green, }}; const WGPUFragmentState fragmentState{ diff --git a/src/pt/deferred_renderer_debug_pass.wgsl b/src/pt/deferred_renderer_debug_pass.wgsl index 8ff745d..79b3b97 100644 --- a/src/pt/deferred_renderer_debug_pass.wgsl +++ b/src/pt/deferred_renderer_debug_pass.wgsl @@ -38,9 +38,8 @@ fn fsMain(in: VertexOutput) -> @location(0) vec4f { let a = 0.1; rgb = vec3((1.0 + a) * x / (x + vec3(a))); } else { - let uvVelocity = textureLoad(gbufferVelocity, idx, 0).rg; - let velocity = vec2(uvVelocity.x, 1.0 - uvVelocity.y); - rgb = vec3f(velocity, 0.0); + let velocity = textureLoad(gbufferVelocity, idx, 0).rg; + rgb = vec3f(vec2(0.5) + velocity, 0.0); } let srgb = pow(rgb, vec3(1.0 / 2.2)); return vec4(srgb, 1.0); diff --git a/src/pt/deferred_renderer_gbuffer_pass.wgsl b/src/pt/deferred_renderer_gbuffer_pass.wgsl index 72dd520..bd6e98b 100644 --- a/src/pt/deferred_renderer_gbuffer_pass.wgsl +++ b/src/pt/deferred_renderer_gbuffer_pass.wgsl @@ -43,7 +43,8 @@ fn fsMain(in: VertexOutput) -> GbufferOutput { let encodedNormal = 0.5f * in.normal.xyz + vec3f(0.5f); let currentNdc = in.position.xy / in.position.w; let previousNdc = in.previousPosition.xy / in.previousPosition.w; - let ndcVelocity = previousNdc - currentNdc; // From the current pixel to the previous one - let uvVelocity = ndcVelocity * vec2f(0.5f, -0.5f) + vec2f(0.5f); + let currentUv = currentNdc * vec2f(0.5f, -0.5f) + vec2f(0.5f); + let previousUv = previousNdc * vec2f(0.5f, -0.5f) + vec2f(0.5f); + let uvVelocity = previousUv - currentUv; // From the current pixel to the previous one return GbufferOutput(vec4(linearAlbedo, 1f), vec4(encodedNormal, 1f), uvVelocity); } diff --git a/src/pt/shader_source.hpp b/src/pt/shader_source.hpp index bc2b48f..d5206e2 100644 --- a/src/pt/shader_source.hpp +++ b/src/pt/shader_source.hpp @@ -668,8 +668,9 @@ fn fsMain(in: VertexOutput) -> GbufferOutput { let encodedNormal = 0.5f * in.normal.xyz + vec3f(0.5f); let currentNdc = in.position.xy / in.position.w; let previousNdc = in.previousPosition.xy / in.previousPosition.w; - let ndcVelocity = previousNdc - currentNdc; // From the current pixel to the previous one - let uvVelocity = ndcVelocity * vec2f(0.5f, -0.5f) + vec2f(0.5f); + let currentUv = currentNdc * vec2f(0.5f, -0.5f) + vec2f(0.5f); + let previousUv = previousNdc * vec2f(0.5f, -0.5f) + vec2f(0.5f); + let uvVelocity = previousUv - currentUv; // From the current pixel to the previous one return GbufferOutput(vec4(linearAlbedo, 1f), vec4(encodedNormal, 1f), uvVelocity); } )"; @@ -714,9 +715,8 @@ fn fsMain(in: VertexOutput) -> @location(0) vec4f { let a = 0.1; rgb = vec3((1.0 + a) * x / (x + vec3(a))); } else { - let uvVelocity = textureLoad(gbufferVelocity, idx, 0).rg; - let velocity = vec2(uvVelocity.x, 1.0 - uvVelocity.y); - rgb = vec3f(velocity, 0.0); + let velocity = textureLoad(gbufferVelocity, idx, 0).rg; + rgb = vec3f(vec2(0.5) + velocity, 0.0); } let srgb = pow(rgb, vec3(1.0 / 2.2)); return vec4(srgb, 1.0);