21 lines
635 B
Zig
21 lines
635 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));
|
|
|
|
const r = math.sqrt(scaledColor.x);
|
|
const g = math.sqrt(scaledColor.y);
|
|
const b = math.sqrt(scaledColor.z);
|
|
|
|
return Color{
|
|
.x = math.clamp(r, 0, 0.999),
|
|
.y = math.clamp(g, 0, 0.999),
|
|
.z = math.clamp(b, 0, 0.999),
|
|
};
|
|
} |