Skip to content

Commit

Permalink
Do gamma correction once in display pass
Browse files Browse the repository at this point in the history
  • Loading branch information
Nelarius committed Mar 29, 2024
1 parent b34ab9b commit 3d1c871
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/pt/hybrid_renderer_debug_pass.wgsl
Expand Up @@ -34,7 +34,7 @@ fn fsMain(in: VertexOutput) -> @location(0) vec4f {
} else {
let d = vec3(1.0) - textureLoad(gbufferDepth, idx, 0);
let x = d;
let a = 0.05;
let a = 0.1;
return vec4((1.0 + a) * x / (x + vec3(a)), 1.0);
}
}
6 changes: 2 additions & 4 deletions src/pt/hybrid_renderer_gbuffer_pass.wgsl
Expand Up @@ -31,8 +31,6 @@ struct GbufferOutput {

@fragment
fn fsMain(in: VertexOutput) -> GbufferOutput {
var out: GbufferOutput;
out.albedo = textureSample(texture, textureSampler, in.texCoord);
out.normal = vec4(normalize(in.normal.xyz), 1.0);
return out;
var c = pow(textureSample(texture, textureSampler, in.texCoord).xyz, vec3(2.2f));
return GbufferOutput(vec4(c, 1f), vec4(normalize(in.normal.xyz), 1f));
}
4 changes: 1 addition & 3 deletions src/pt/reference_path_tracer.wgsl
Expand Up @@ -66,9 +66,7 @@ fn fsMain(in: VertexOutput) -> @location(0) vec4f {

let tonemapFn = postProcessingParams.tonemapFn;
let rgb = expose(tonemapFn, exposure * estimator);

let srgb = pow(rgb, vec3(1f / 2.2f));
return vec4f(srgb, 1f);
return vec4f(rgb, 1f);
}

const EPSILON = 0.00001f;
Expand Down
20 changes: 9 additions & 11 deletions src/pt/shader_source.hpp
Expand Up @@ -72,9 +72,7 @@ fn fsMain(in: VertexOutput) -> @location(0) vec4f {
let tonemapFn = postProcessingParams.tonemapFn;
let rgb = expose(tonemapFn, exposure * estimator);
let srgb = pow(rgb, vec3(1f / 2.2f));
return vec4f(srgb, 1f);
return vec4f(rgb, 1f);
}
const EPSILON = 0.00001f;
Expand Down Expand Up @@ -551,8 +549,8 @@ const INT_SCALE = 256f;
@must_use
fn offsetRay(p: vec3f, n: vec3f) -> vec3f {
// Source: A Fast and Robust Method fo)"
R"(r Avoiding Self-Intersection, Ray Tracing Gems
// Source: A Fast and Robust Method for Avoiding Self-Intersection, Ray Tracing Ge)"
R"(ms
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.
Expand Down Expand Up @@ -693,7 +691,9 @@ fn vsMain(in: VertexInput) -> VertexOutput {
@fragment
fn fsMain(in: VertexOutput) -> @location(0) vec4f {
return textureSample(texture, textureSampler, in.texCoord);
let c = textureSample(texture, textureSampler, in.texCoord);
let srgb = pow(c.xyz, vec3(1f / 2.2f));
return vec4f(srgb, 1f);
}
)";

Expand Down Expand Up @@ -730,10 +730,8 @@ struct GbufferOutput {
@fragment
fn fsMain(in: VertexOutput) -> GbufferOutput {
var out: GbufferOutput;
out.albedo = textureSample(texture, textureSampler, in.texCoord);
out.normal = vec4(normalize(in.normal.xyz), 1.0);
return out;
var c = pow(textureSample(texture, textureSampler, in.texCoord).xyz, vec3(2.2f));
return GbufferOutput(vec4(c, 1f), vec4(normalize(in.normal.xyz), 1f));
}
)";

Expand Down Expand Up @@ -773,7 +771,7 @@ fn fsMain(in: VertexOutput) -> @location(0) vec4f {
} else {
let d = vec3(1.0) - textureLoad(gbufferDepth, idx, 0);
let x = d;
let a = 0.05;
let a = 0.1;
return vec4((1.0 + a) * x / (x + vec3(a)), 1.0);
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/pt/texture_blit.wgsl
Expand Up @@ -22,5 +22,7 @@ fn vsMain(in: VertexInput) -> VertexOutput {

@fragment
fn fsMain(in: VertexOutput) -> @location(0) vec4f {
return textureSample(texture, textureSampler, in.texCoord);
let c = textureSample(texture, textureSampler, in.texCoord);
let srgb = pow(c.xyz, vec3(1f / 2.2f));
return vec4f(srgb, 1f);
}

0 comments on commit 3d1c871

Please sign in to comment.