diff --git a/zigrtiow/src/color.zig b/zigrtiow/src/color.zig index 4adca61..ac98f3c 100644 --- a/zigrtiow/src/color.zig +++ b/zigrtiow/src/color.zig @@ -8,11 +8,11 @@ pub fn write_color(c: Color, samples_per_pixel: isize) anyerror!void { var g = c.y(); var b = c.z(); - // Divide the color by the number of samples. - var scale = 1.0 / @intToFloat(f32, samples_per_pixel); - r *= scale; - g *= scale; - b *= scale; + // Divide the color by the number of samples and gamma-correct for gamma=2.0. + const scale = 1.0 / @intToFloat(f32, samples_per_pixel); + r = @sqrt(scale * r); + g = @sqrt(scale * g); + b = @sqrt(scale * b); // Write the translated [0,255] value of each color component. var ir = @floatToInt(u8, 256 * clamp(r, 0, 0.999));