Skip to content

Commit

Permalink
wip reject samples out of bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
Nelarius committed Jul 5, 2024
1 parent aa53ed0 commit 90feba0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
23 changes: 14 additions & 9 deletions src/pt/deferred_renderer_resolve_pass.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,27 @@ fn fsMain(in: VertexOutput) -> @location(0) vec4f {
let sample: array<f32, 3> = sampleBuffer[sampleBufferIdx];
let currentColor = vec3f(sample[0], sample[1], sample[2]);

var outputColor = vec3f(0f);
var color = vec3f(0f);
if uniforms.frameCount == 0u {
accumulationBuffer[sampleBufferIdx] = sample;
outputColor = currentColor;
color = currentColor;
} else {
let depth = textureLoad(gbufferDepth, textureIdx, 0);
let previousUv = cameraReproject(uv, depth);
let previousTextureIdx = vec2u(floor(previousUv * uniforms.framebufferSize));
let previousSampleBufferIdx = previousTextureIdx.y * u32(uniforms.framebufferSize.x) + previousTextureIdx.x;
let previousSample: array<f32, 3> = accumulationBuffer[previousSampleBufferIdx];
let previousColor = vec3f(previousSample[0], previousSample[1], previousSample[2]);
outputColor = 0.1 * currentColor + 0.9 * previousColor;
accumulationBuffer[sampleBufferIdx] = array<f32, 3>(outputColor.r, outputColor.g, outputColor.b);
if previousUv.x >= 0f && previousUv.x < 1f && previousUv.y >= 0f && previousUv.y < 1f {
let previousTextureIdx = vec2u(floor(previousUv * uniforms.framebufferSize));
let previousSampleBufferIdx = previousTextureIdx.y * u32(uniforms.framebufferSize.x) + previousTextureIdx.x;
let previousSample: array<f32, 3> = accumulationBuffer[previousSampleBufferIdx];
let previousColor = vec3f(previousSample[0], previousSample[1], previousSample[2]);
color = 0.1 * currentColor + 0.9 * previousColor;
accumulationBuffer[sampleBufferIdx] = array<f32, 3>(color.r, color.g, color.b);
} else {
accumulationBuffer[sampleBufferIdx] = sample;
color = currentColor;
}
}

let rgb = acesFilmic(uniforms.exposure * outputColor);
let rgb = acesFilmic(uniforms.exposure * color);
let srgb = pow(rgb, vec3(1f / 2.2f));
return vec4(srgb, 1f);
}
Expand Down
23 changes: 14 additions & 9 deletions src/pt/shader_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1321,22 +1321,27 @@ fn fsMain(in: VertexOutput) -> @location(0) vec4f {
let sample: array<f32, 3> = sampleBuffer[sampleBufferIdx];
let currentColor = vec3f(sample[0], sample[1], sample[2]);
var outputColor = vec3f(0f);
var color = vec3f(0f);
if uniforms.frameCount == 0u {
accumulationBuffer[sampleBufferIdx] = sample;
outputColor = currentColor;
color = currentColor;
} else {
let depth = textureLoad(gbufferDepth, textureIdx, 0);
let previousUv = cameraReproject(uv, depth);
let previousTextureIdx = vec2u(floor(previousUv * uniforms.framebufferSize));
let previousSampleBufferIdx = previousTextureIdx.y * u32(uniforms.framebufferSize.x) + previousTextureIdx.x;
let previousSample: array<f32, 3> = accumulationBuffer[previousSampleBufferIdx];
let previousColor = vec3f(previousSample[0], previousSample[1], previousSample[2]);
outputColor = 0.1 * currentColor + 0.9 * previousColor;
accumulationBuffer[sampleBufferIdx] = array<f32, 3>(outputColor.r, outputColor.g, outputColor.b);
if previousUv.x >= 0f && previousUv.x < 1f && previousUv.y >= 0f && previousUv.y < 1f {
let previousTextureIdx = vec2u(floor(previousUv * uniforms.framebufferSize));
let previousSampleBufferIdx = previousTextureIdx.y * u32(uniforms.framebufferSize.x) + previousTextureIdx.x;
let previousSample: array<f32, 3> = accumulationBuffer[previousSampleBufferIdx];
let previousColor = vec3f(previousSample[0], previousSample[1], previousSample[2]);
color = 0.1 * currentColor + 0.9 * previousColor;
accumulationBuffer[sampleBufferIdx] = array<f32, 3>(color.r, color.g, color.b);
} else {
accumulationBuffer[sampleBufferIdx] = sample;
color = currentColor;
}
}
let rgb = acesFilmic(uniforms.exposure * outputColor);
let rgb = acesFilmic(uniforms.exposure * color);
let srgb = pow(rgb, vec3(1f / 2.2f));
return vec4(srgb, 1f);
}
Expand Down

0 comments on commit 90feba0

Please sign in to comment.