aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main.zig
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2022-11-27 15:07:34 +0900
committernsfisis <nsfisis@gmail.com>2022-11-27 15:07:34 +0900
commit8cc3e2ada26af6a45e577b9c7ffffb0bc795b7d3 (patch)
treec941ad08187b903a968c989814976ef8b3441dd0 /src/main.zig
parent3227ecb8e029d2026d6cc23fd3beb50982685029 (diff)
downloadRayTracingInOneWeekend.zig-8cc3e2ada26af6a45e577b9c7ffffb0bc795b7d3.tar.gz
RayTracingInOneWeekend.zig-8cc3e2ada26af6a45e577b9c7ffffb0bc795b7d3.tar.zst
RayTracingInOneWeekend.zig-8cc3e2ada26af6a45e577b9c7ffffb0bc795b7d3.zip
8.4
Diffstat (limited to 'src/main.zig')
-rw-r--r--src/main.zig8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/main.zig b/src/main.zig
index 216a302..7e78372 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -251,7 +251,7 @@ fn rayColor(r: Ray, world: Hittable, rand: std.rand.Random, depth: u32) Color {
// If we've exceeded the ray bounce limit, no more ligth is gathered.
return Color{ .x = 0.0, .y = 0.0, .z = 0.0 };
}
- if (world.hit(r, 0, inf, &rec)) {
+ if (world.hit(r, 0.001, inf, &rec)) {
const target = rec.p.add(rec.normal).add(randomPointInUnitSphere(rand));
return rayColor(Ray{ .origin = rec.p, .dir = target.sub(rec.p) }, world, rand, depth - 1).mul(0.5);
}
@@ -263,9 +263,9 @@ fn rayColor(r: Ray, world: Hittable, rand: std.rand.Random, depth: u32) Color {
fn writeColor(out: anytype, c: Color, samples_per_pixel: u32) !void {
const scale = 1.0 / @intToFloat(f64, samples_per_pixel);
try out.print("{} {} {}\n", .{
- @floatToInt(u8, 256.0 * math.clamp(c.x * scale, 0.0, 0.999)),
- @floatToInt(u8, 256.0 * math.clamp(c.y * scale, 0.0, 0.999)),
- @floatToInt(u8, 256.0 * math.clamp(c.z * scale, 0.0, 0.999)),
+ @floatToInt(u8, 256.0 * math.clamp(@sqrt(c.x * scale), 0.0, 0.999)),
+ @floatToInt(u8, 256.0 * math.clamp(@sqrt(c.y * scale), 0.0, 0.999)),
+ @floatToInt(u8, 256.0 * math.clamp(@sqrt(c.z * scale), 0.0, 0.999)),
});
}