Skip to content

Commit 883ed07

Browse files
committed
Account for gamma in textures and output
- Swap chain format is rgba8unorm, sRGB values should be written by shader - Textures are presumed to be stored in sRGB format, conversion to linear implemented in texture lookup
1 parent 4e72d88 commit 883ed07

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/pt/raytracer.wgsl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ fn fsMain(in: VertexOutput) -> @location(0) vec4f {
7575
let tonemapFn = postProcessingParams.tonemapFn;
7676
let rgb = expose(tonemapFn, exposure * estimator);
7777

78-
return vec4f(rgb, 1f);
78+
let srgb = pow(rgb, vec3(1f / 2.2f));
79+
return vec4f(srgb, 1f);
7980
}
8081

8182
const EPSILON = 0.00001f;
@@ -574,8 +575,10 @@ fn textureLookup(desc: TextureDescriptor, uv: vec2f) -> vec3f {
574575
let i = u32(v * f32(desc.height));
575576
let idx = i * desc.width + j;
576577

577-
let rgba = textures[desc.offset + idx];
578-
return vec3f(f32(rgba & 0xffu), f32((rgba >> 8u) & 0xffu), f32((rgba >> 16u) & 0xffu)) / 255f;
578+
let pixel = textures[desc.offset + idx];
579+
let srgb = vec3(f32(pixel & 0xffu), f32((pixel >> 8u) & 0xffu), f32((pixel >> 16u) & 0xffu)) / 255f;
580+
let linearRgb = pow(srgb, vec3(2.2f));
581+
return linearRgb;
579582
}
580583

581584
@must_use

0 commit comments

Comments
 (0)