aboutsummaryrefslogtreecommitdiff
path: root/material.go
blob: a36fb524594c2d2639f7eda56de8219a114c6f86 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

package main

type Material interface {
	Scatter(ray Ray, hit HitRecord) (Ray, Color)
}

type Lambertian struct {
	albedo Color
}

func (lambertian Lambertian) Scatter(ray Ray, hit HitRecord) (Ray, Color) {
	// TODO: Use the correct distribution
	direction := AddVec3D(hit.normal, RandomInUnitSphere())
	scattered := Ray{hit.point, direction}
	return scattered, lambertian.albedo
}

type Metal struct {
	albedo Color
	fuzz   float64
}

func (metal Metal) Scatter(ray Ray, hit HitRecord) (Ray, Color) {
	reflected := AddVec3D(ray.direction.Unit().Reflect(hit.normal), ScalarProduct(metal.fuzz, RandomInUnitSphere()))
	scattered := Ray{hit.point, reflected}
	return scattered, metal.albedo
}