From f414f8428584cc609d7ca302faf56c82ebf7fa67 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Tue, 6 Dec 2022 22:02:39 +0900 Subject: 4.1 --- src/main.zig | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src') diff --git a/src/main.zig b/src/main.zig index 0979ca9..fac7648 100644 --- a/src/main.zig +++ b/src/main.zig @@ -234,6 +234,9 @@ const HitRecord = struct { material: *const Material, // p = ray.at(t) t: f64, + // The coordinate of the surface where the ray intersects. + u: f64, + v: f64, // True if the ray hits the hittable from the front face, i.e., outside of it. front_face: bool, }; @@ -627,6 +630,31 @@ const BvhNode = struct { } }; +const TextureTag = enum { + solid, +}; + +const Texture = union(TextureTag) { + solid: SolidTexture, + + fn value(tx: Texture, u: f64, v: f64, p: Vec3) Color { + return switch (tx) { + TextureTag.solid => |solidTx| solidTx.value(u, v, p), + }; + } +}; + +const SolidTexture = struct { + color: Color, + + fn value(tx: SolidTexture, u: f64, v: f64, p: Vec3) Color { + _ = u; + _ = v; + _ = p; + return tx.color; + } +}; + const Camera = struct { origin: Point3, horizontal: Vec3, -- cgit v1.2.3-70-g09d2