Skip to content

Commit

Permalink
some attempts to get visible velocity
Browse files Browse the repository at this point in the history
  • Loading branch information
Nelarius committed Jul 3, 2024
1 parent ef90fb3 commit 83d8516
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/pt/deferred_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
5 changes: 2 additions & 3 deletions src/pt/deferred_renderer_debug_pass.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions src/pt/deferred_renderer_gbuffer_pass.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
10 changes: 5 additions & 5 deletions src/pt/shader_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
)";
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 83d8516

Please sign in to comment.