aboutsummaryrefslogtreecommitdiff
path: root/lib/material.rb
diff options
context:
space:
mode:
authorNat Lasseter <user@4574.co.uk>2024-06-14 12:23:49 +0100
committerNat Lasseter <user@4574.co.uk>2024-06-14 12:23:49 +0100
commit3549acb5dbd2f6fe43be6cce9828785ccead7e77 (patch)
treec4cb0f2db631d3b60b641f6c8e654663940b3d38 /lib/material.rb
parent3bf56da7aa64ea3ca05559a4e52df8f596bcf86b (diff)
Finished! Good god performance nope.HEADmain
Diffstat (limited to 'lib/material.rb')
-rw-r--r--lib/material.rb17
1 files changed, 7 insertions, 10 deletions
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)