Skip to content

Commit 3d1c871

Browse files
committed
Do gamma correction once in display pass
1 parent b34ab9b commit 3d1c871

File tree

5 files changed

+16
-20
lines changed

5 files changed

+16
-20
lines changed

src/pt/hybrid_renderer_debug_pass.wgsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fn fsMain(in: VertexOutput) -> @location(0) vec4f {
3434
} else {
3535
let d = vec3(1.0) - textureLoad(gbufferDepth, idx, 0);
3636
let x = d;
37-
let a = 0.05;
37+
let a = 0.1;
3838
return vec4((1.0 + a) * x / (x + vec3(a)), 1.0);
3939
}
4040
}

src/pt/hybrid_renderer_gbuffer_pass.wgsl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ struct GbufferOutput {
3131

3232
@fragment
3333
fn fsMain(in: VertexOutput) -> GbufferOutput {
34-
var out: GbufferOutput;
35-
out.albedo = textureSample(texture, textureSampler, in.texCoord);
36-
out.normal = vec4(normalize(in.normal.xyz), 1.0);
37-
return out;
34+
var c = pow(textureSample(texture, textureSampler, in.texCoord).xyz, vec3(2.2f));
35+
return GbufferOutput(vec4(c, 1f), vec4(normalize(in.normal.xyz), 1f));
3836
}

src/pt/reference_path_tracer.wgsl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ fn fsMain(in: VertexOutput) -> @location(0) vec4f {
6666

6767
let tonemapFn = postProcessingParams.tonemapFn;
6868
let rgb = expose(tonemapFn, exposure * estimator);
69-
70-
let srgb = pow(rgb, vec3(1f / 2.2f));
71-
return vec4f(srgb, 1f);
69+
return vec4f(rgb, 1f);
7270
}
7371

7472
const EPSILON = 0.00001f;

src/pt/shader_source.hpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ fn fsMain(in: VertexOutput) -> @location(0) vec4f {
7272
7373
let tonemapFn = postProcessingParams.tonemapFn;
7474
let rgb = expose(tonemapFn, exposure * estimator);
75-
76-
let srgb = pow(rgb, vec3(1f / 2.2f));
77-
return vec4f(srgb, 1f);
75+
return vec4f(rgb, 1f);
7876
}
7977
8078
const EPSILON = 0.00001f;
@@ -551,8 +549,8 @@ const INT_SCALE = 256f;
551549
552550
@must_use
553551
fn offsetRay(p: vec3f, n: vec3f) -> vec3f {
554-
// Source: A Fast and Robust Method fo)"
555-
R"(r Avoiding Self-Intersection, Ray Tracing Gems
552+
// Source: A Fast and Robust Method for Avoiding Self-Intersection, Ray Tracing Ge)"
553+
R"(ms
556554
let offset = vec3i(i32(INT_SCALE * n.x), i32(INT_SCALE * n.y), i32(INT_SCALE * n.z));
557555
// Offset added straight into the mantissa bits to ensure the offset is scale-invariant,
558556
// except for when close to the origin, where we use FLOAT_SCALE as a small epsilon.
@@ -693,7 +691,9 @@ fn vsMain(in: VertexInput) -> VertexOutput {
693691
694692
@fragment
695693
fn fsMain(in: VertexOutput) -> @location(0) vec4f {
696-
return textureSample(texture, textureSampler, in.texCoord);
694+
let c = textureSample(texture, textureSampler, in.texCoord);
695+
let srgb = pow(c.xyz, vec3(1f / 2.2f));
696+
return vec4f(srgb, 1f);
697697
}
698698
)";
699699

@@ -730,10 +730,8 @@ struct GbufferOutput {
730730
731731
@fragment
732732
fn fsMain(in: VertexOutput) -> GbufferOutput {
733-
var out: GbufferOutput;
734-
out.albedo = textureSample(texture, textureSampler, in.texCoord);
735-
out.normal = vec4(normalize(in.normal.xyz), 1.0);
736-
return out;
733+
var c = pow(textureSample(texture, textureSampler, in.texCoord).xyz, vec3(2.2f));
734+
return GbufferOutput(vec4(c, 1f), vec4(normalize(in.normal.xyz), 1f));
737735
}
738736
)";
739737

@@ -773,7 +771,7 @@ fn fsMain(in: VertexOutput) -> @location(0) vec4f {
773771
} else {
774772
let d = vec3(1.0) - textureLoad(gbufferDepth, idx, 0);
775773
let x = d;
776-
let a = 0.05;
774+
let a = 0.1;
777775
return vec4((1.0 + a) * x / (x + vec3(a)), 1.0);
778776
}
779777
}

src/pt/texture_blit.wgsl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,7 @@ fn vsMain(in: VertexInput) -> VertexOutput {
2222

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

0 commit comments

Comments
 (0)