From 3549acb5dbd2f6fe43be6cce9828785ccead7e77 Mon Sep 17 00:00:00 2001 From: Nat Lasseter Date: Fri, 14 Jun 2024 12:23:49 +0100 Subject: Finished! Good god performance nope. --- lib/material.rb | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'lib/material.rb') diff --git a/lib/material.rb b/lib/material.rb index 752b85f..14eb5f9 100644 --- a/lib/material.rb +++ b/lib/material.rb @@ -1,6 +1,6 @@ class Material - def initialize(r, g, b) - @albedo = Colour.new(r, g, b) + def initialize(albedo) + @albedo = albedo end def attenuation @@ -14,21 +14,21 @@ end class Lambertian < Material def scatter(ray, record) - scat = record.normal + Vec3.random_unit + scat = record.normal + Vec3.random_in_unit scat = rec.normal if scat.near_zero? Ray.new(record.point, scat) end end class Metal < Material - def initialize(r, g, b, fuzz) + def initialize(albedo, fuzz) @fuzz = fuzz < 1 ? fuzz : 1 - super(r, g, b) + super(albedo) end def scatter(ray, record) refl = ray.direction.reflect(record.normal) - refl = refl.unit + (Vec3.random_unit * @fuzz) + refl = refl.unit + (Vec3.random_in_unit * @fuzz) if refl.dot(record.normal) > 0 Ray.new(record.point, refl) else @@ -40,10 +40,7 @@ end class Dielectric < Material def initialize(ref_index) @ref_index = ref_index - end - - def attenuation - Colour.new(1.0, 1.0, 1.0) + super(Colour.new(1.0, 1.0, 1.0)) end def scatter(ray, record) -- cgit v1.2.1