raytracing/in_one_weekend/src/color.zig

17 lines
547 B
Zig

const std = @import("std");
const math = std.math;
const Vec3 = @import("vec3.zig").Vec3;
pub const Color = Vec3;
pub fn averageColor(pixelColor: Color, samplesPerPixel: i32) Color {
// Divide the color by the number of samples.
// const scale = 1.0 / @intToFloat(f32, samplesPerPixel);
var scaledColor = pixelColor.div(@intToFloat(f32, samplesPerPixel));
return Color{
.x = math.clamp(scaledColor.x, 0, 0.999),
.y = math.clamp(scaledColor.y, 0, 0.999),
.z = math.clamp(scaledColor.z, 0, 0.999),
};
}