aboutsummaryrefslogtreecommitdiff
path: root/lib/material.rb
diff options
context:
space:
mode:
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)