zigrtiow: gamma correct.

This commit is contained in:
Bill Thiede 2022-08-04 21:46:08 -07:00
parent 94b0f8355e
commit 58646e4142

View File

@ -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));