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 g = c.y();
var b = c.z(); var b = c.z();
// Divide the color by the number of samples. // Divide the color by the number of samples and gamma-correct for gamma=2.0.
var scale = 1.0 / @intToFloat(f32, samples_per_pixel); const scale = 1.0 / @intToFloat(f32, samples_per_pixel);
r *= scale; r = @sqrt(scale * r);
g *= scale; g = @sqrt(scale * g);
b *= scale; b = @sqrt(scale * b);
// Write the translated [0,255] value of each color component. // Write the translated [0,255] value of each color component.
var ir = @floatToInt(u8, 256 * clamp(r, 0, 0.999)); var ir = @floatToInt(u8, 256 * clamp(r, 0, 0.999));