Skip to content

Commit

Permalink
Add early-exit for lighting invocation coords outside of framebuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
Nelarius committed Jul 14, 2024
1 parent 55c9cf8 commit 8289aa6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/pt/deferred_renderer_lighting_pass.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ const T_MAX = 10000f;

@compute @workgroup_size(8, 8)
fn main(@builtin(global_invocation_id) globalInvocationId: vec3<u32>) {
if globalInvocationId.x >= u32(uniforms.framebufferSize.x) || globalInvocationId.y >= u32(uniforms.framebufferSize.y) {
return;
}

let textureIdx = globalInvocationId.xy;
let uv = (vec2f(globalInvocationId.xy) + vec2f(0.5)) / uniforms.framebufferSize;

Expand Down
10 changes: 7 additions & 3 deletions src/pt/shader_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,10 @@ const T_MAX = 10000f;
@compute @workgroup_size(8, 8)
fn main(@builtin(global_invocation_id) globalInvocationId: vec3<u32>) {
if globalInvocationId.x >= u32(uniforms.framebufferSize.x) || globalInvocationId.y >= u32(uniforms.framebufferSize.y) {
return;
}
let textureIdx = globalInvocationId.xy;
let uv = (vec2f(globalInvocationId.xy) + vec2f(0.5)) / uniforms.framebufferSize;
Expand Down Expand Up @@ -1214,10 +1218,10 @@ fn offsetPosition(p: vec3f, n: vec3f) -> vec3f {
// Source: A Fast and Robust Method for Avoiding Self-Intersection, Ray Tracing Gems
let offset = vec3i(i32(INT_SCALE * n.x), i32(INT_SCALE * n.y), i32(INT_SCALE * n.z));
// Offset added straight into the mantissa bits to ensure the offset is scale-invariant,
// except for when close to the origin, where we use FLOAT_SCALE as a small epsilon.
// )"
R"(except for when close to the origin, where we use FLOAT_SCALE as a small epsilon.
let po = vec3f(
bitcast<f32>(bitcast<i32>(p.x) + sele)"
R"(ct(offset.x, -offset.x, (p.x < 0))),
bitcast<f32>(bitcast<i32>(p.x) + select(offset.x, -offset.x, (p.x < 0))),
bitcast<f32>(bitcast<i32>(p.y) + select(offset.y, -offset.y, (p.y < 0))),
bitcast<f32>(bitcast<i32>(p.z) + select(offset.z, -offset.z, (p.z < 0)))
);
Expand Down

0 comments on commit 8289aa6

Please sign in to comment.