Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
fogleman committed Aug 11, 2016
1 parent 98097c4 commit 5d46fdc
Show file tree
Hide file tree
Showing 29 changed files with 49 additions and 76 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ This is a CPU-only [path tracing](http://en.wikipedia.org/wiki/Path_tracing) eng
* Supports OBJ, Binary STL and ASCII STL
* Supports textures, bump maps and normal maps
* Supports volume rendering from image slices
* Uses k-d trees to accelerate ray intersection tests
* Supports various material properties
* Light sources with configurable attenuation
* Supports configurable depth of field
* Supports iterative rendering
* Uses k-d trees to accelerate ray intersection tests
* Uses all CPU cores in parallel

### TODO
Expand Down
2 changes: 1 addition & 1 deletion examples/beads.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func frame(path string, t float64) {
scene.Add(sphere)
}
}
scene.Add(NewSphere(V(4, 4, 20), 2, LightMaterial(HexColor(0xFFFFFF), 30, NoAttenuation)))
scene.Add(NewSphere(V(4, 4, 20), 2, LightMaterial(HexColor(0xFFFFFF), 30)))
fovy := 40.0
camera := LookAt(eye, center, up, fovy)
sampler := NewSampler(4, 4)
Expand Down
4 changes: 2 additions & 2 deletions examples/bunny.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ func main() {
scene.Add(mesh)
floor := GlossyMaterial(HexColor(0x33332D), 1.2, Radians(20))
scene.Add(NewCube(V(-10000, -10000, -10000), V(10000, 0, 10000), floor))
scene.Add(NewSphere(V(0, 5, 0), 1, LightMaterial(Color{1, 1, 1}, 20, NoAttenuation)))
scene.Add(NewSphere(V(4, 5, 4), 1, LightMaterial(Color{1, 1, 1}, 20, NoAttenuation)))
scene.Add(NewSphere(V(0, 5, 0), 1, LightMaterial(Color{1, 1, 1}, 20)))
scene.Add(NewSphere(V(4, 5, 4), 1, LightMaterial(Color{1, 1, 1}, 20)))
camera := LookAt(V(-1, 2, 3), V(0, 0.75, 0), V(0, 1, 0), 50)
sampler := NewSampler(4, 4)
IterativeRender("out%03d.png", 1000, &scene, &camera, sampler, 1920/2, 1080/2, -1)
Expand Down
2 changes: 1 addition & 1 deletion examples/cornell.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ func main() {
white := DiffuseMaterial(Color{0.740, 0.742, 0.734})
red := DiffuseMaterial(Color{0.366, 0.037, 0.042})
green := DiffuseMaterial(Color{0.163, 0.409, 0.083})
light := LightMaterial(Color{0.780, 0.780, 0.776}, 20, NoAttenuation)
light := LightMaterial(Color{0.780, 0.780, 0.776}, 20)
scene := Scene{}
n := 10.0
scene.Add(NewCube(V(-n, -11, -n), V(n, -10, n), white))
Expand Down
2 changes: 1 addition & 1 deletion examples/counties.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func LoadTriangles(path string) []*Triangle {
func main() {
rand.Seed(6)
floor := GlossyMaterial(HexColor(0xFCFFF5), 1.5, Radians(20))
light := LightMaterial(HexColor(0xFFFFFF), 1, QuadraticAttenuation(0.002))
light := LightMaterial(HexColor(0xFFFFFF), 1)
triangles := LoadTriangles("examples/counties.csv")
mesh := NewMesh(triangles)
mesh.FitInside(Box{V(-1, -1, 0), V(1, 1, 1)}, V(0.5, 0.5, 0))
Expand Down
2 changes: 1 addition & 1 deletion examples/cube.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func main() {
scene.Add(NewTransformedShape(meshes[rand.Intn(len(meshes))], Translate(Vector{fx, fy - 1, fz})))
}
}
scene.Add(NewSphere(Vector{8, 10, 0}, 3, LightMaterial(Color{1, 1, 1}, 30, NoAttenuation)))
scene.Add(NewSphere(Vector{8, 10, 0}, 3, LightMaterial(Color{1, 1, 1}, 30)))
camera := LookAt(Vector{-10, 10, 0}, Vector{-2, 0, 0}, Vector{0, 1, 0}, 45)
sampler := NewSampler(4, 4)
IterativeRender("out%03d.png", 1000, &scene, &camera, sampler, 1920/2, 1080/2, -1)
Expand Down
2 changes: 1 addition & 1 deletion examples/cylinder.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func main() {
scene.Add(NewTransformedShape(mesh, Translate(Vector{fx, fy, fz})))
}
}
scene.Add(NewSphere(Vector{1, 0, 10}, 3, LightMaterial(Color{1, 1, 1}, 20, NoAttenuation)))
scene.Add(NewSphere(Vector{1, 0, 10}, 3, LightMaterial(Color{1, 1, 1}, 20)))
camera := LookAt(Vector{-5, 0, 5}, Vector{1, 0, 0}, Vector{0, 0, 1}, 45)
sampler := NewSampler(4, 4)
IterativeRender("out%03d.png", 1000, &scene, &camera, sampler, 1920/2, 1080/2, -1)
Expand Down
2 changes: 1 addition & 1 deletion examples/dragon.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func main() {
scene.Add(mesh)
floor := GlossyMaterial(HexColor(0xD8CAA8), 1.2, Radians(20))
scene.Add(NewCube(Vector{-1000, -1000, -1000}, Vector{1000, 0, 1000}, floor))
scene.Add(NewSphere(Vector{0, 10, 0}, 1, LightMaterial(Color{1, 1, 1}, 20, NoAttenuation)))
scene.Add(NewSphere(Vector{0, 10, 0}, 1, LightMaterial(Color{1, 1, 1}, 20)))
camera := LookAt(Vector{-3, 2, -1}, Vector{0, 0.5, 0}, Vector{0, 1, 0}, 35)
sampler := NewSampler(4, 4)
IterativeRender("out%03d.png", 1000, &scene, &camera, sampler, 1920/4, 1080/4, -1)
Expand Down
2 changes: 1 addition & 1 deletion examples/ellipsoid.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import . "github.com/fogleman/pt/pt"
func main() {
scene := Scene{}
wall := GlossyMaterial(HexColor(0xFCFAE1), 1.333, Radians(30))
scene.Add(NewSphere(Vector{10, 10, 10}, 2, LightMaterial(Color{1, 1, 1}, 50, NoAttenuation)))
scene.Add(NewSphere(Vector{10, 10, 10}, 2, LightMaterial(Color{1, 1, 1}, 50)))
scene.Add(NewCube(Vector{-100, -100, -100}, Vector{-12, 100, 100}, wall))
scene.Add(NewCube(Vector{-100, -100, -100}, Vector{100, -1, 100}, wall))
material := GlossyMaterial(HexColor(0x167F39), 1.333, Radians(30))
Expand Down
21 changes: 11 additions & 10 deletions examples/example1.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import . "github.com/fogleman/pt/pt"

func main() {
scene := Scene{}
scene.Add(NewSphere(V(1.5, 1.25, 0), 1.25, SpecularMaterial(HexColor(0x334D5C), 1.3)))
scene.Add(NewSphere(V(-1, 1, 2), 1, SpecularMaterial(HexColor(0xEFC94C), 1.3)))
scene.Add(NewSphere(V(-2.5, 0.75, 0), 0.75, SpecularMaterial(HexColor(0xEFC94C), 10000)))
scene.Add(NewSphere(V(-0.75, 0.75, -1), 0.5, TransparentMaterial(Color{}, 1.333, 0, 0)))
scene.Add(NewCube(V(-100, -1, -100), V(100, 0, 100), DiffuseMaterial(Color{1, 1, 1})))
scene.Add(NewSphere(V(-1.5, 4, 0), 0.5, LightMaterial(Color{1, 1, 1}, 100, LinearAttenuation(1))))
// scene.Add(NewSphere(V(0, 4, 0), 0.5, LightMaterial(Color{1, 1, 1}, 100, LinearAttenuation(1))))
// scene.Add(NewSphere(V(1.5, 4, 0), 0.5, LightMaterial(Color{1, 1, 1}, 100, LinearAttenuation(1))))
camera := LookAt(V(0, 2, -5), V(0, 0, 3), V(0, 1, 0), 45)
sampler := NewSampler(4, 4)
scene.Add(NewSphere(V(1.5, 1.25, 0), 1.25, SpecularMaterial(HexColor(0x004358), 1.2)))
scene.Add(NewSphere(V(-1, 1, 2), 1, SpecularMaterial(HexColor(0xFFE11A), 1.2)))
scene.Add(NewSphere(V(-2.5, 0.75, 0), 0.75, SpecularMaterial(HexColor(0xFD7400), 1.2)))
scene.Add(NewSphere(V(-0.75, 0.5, -1), 0.5, SpecularMaterial(HexColor(0xBEDB39), 1.2)))
scene.Add(NewCube(V(-100, -1, -100), V(100, 0, 100), GlossyMaterial(Color{1, 1, 1}, 1.1, Radians(10))))
scene.Add(NewSphere(V(-1.5, 4, 0), 0.5, LightMaterial(Color{1, 1, 1}, 30)))
// scene.Add(NewSphere(V(0, 4, 0), 0.5, LightMaterial(Color{1, 1, 1}, 50)))
// scene.Add(NewSphere(V(1.5, 4, 0), 0.5, LightMaterial(Color{1, 1, 1}, 50)))
camera := LookAt(V(0, 2.5, -5), V(0, 0, 3), V(0, 1, 0), 45)
camera.SetFocus(V(-0.75, 1, -1), 0.15)
sampler := NewSampler(4, 8)
IterativeRender("out%03d.png", 1000, &scene, &camera, sampler, 1920/2, 1080/2, -1)
}
2 changes: 1 addition & 1 deletion examples/example2.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func main() {
}
}
scene.Add(NewCube(V(-100, -1, -100), V(100, 0, 100), whiteMat))
scene.Add(NewSphere(V(-1, 4, -1), 1, LightMaterial(Color{1, 1, 1}, 30, NoAttenuation)))
scene.Add(NewSphere(V(-1, 4, -1), 1, LightMaterial(Color{1, 1, 1}, 30)))
camera := LookAt(V(0, 4, -8), V(0, 0, -2), V(0, 1, 0), 45)
sampler := NewSampler(4, 4)
IterativeRender("out%03d.png", 1000, &scene, &camera, sampler, 1920/2, 1080/2, -1)
Expand Down
2 changes: 1 addition & 1 deletion examples/example3.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func main() {
scene.Add(NewCube(min, max, material))
}
}
scene.Add(NewCube(V(-5, 10, -5), V(5, 11, 5), LightMaterial(Color{1, 1, 1}, 20, QuadraticAttenuation(0.05))))
scene.Add(NewCube(V(-5, 10, -5), V(5, 11, 5), LightMaterial(Color{1, 1, 1}, 5)))
camera := LookAt(V(20, 10, 0), V(8, 0, 0), V(0, 1, 0), 45)
sampler := NewSampler(4, 4)
IterativeRender("out%03d.png", 1000, &scene, &camera, sampler, 1920/2, 1080/2, -1)
Expand Down
2 changes: 1 addition & 1 deletion examples/gopher.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ func main() {
// create materials
gopher := GlossyMaterial(Color{}, 1.2, Radians(30))
wall := GlossyMaterial(HexColor(0xFCFAE1), 1.5, Radians(10))
light := LightMaterial(Color{1, 1, 1}, 80, NoAttenuation)
light := LightMaterial(Color{1, 1, 1}, 80)

// add walls and lights
scene.Add(NewCube(V(-10, -1, -10), V(-2, 10, 10), wall))
Expand Down
2 changes: 1 addition & 1 deletion examples/hits.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import . "github.com/fogleman/pt/pt"
func main() {
scene := Scene{}
material := DiffuseMaterial(Color{0.95, 0.95, 1})
light := LightMaterial(Color{1, 1, 1}, 1300, LinearAttenuation(1))
light := LightMaterial(Color{1, 1, 1}, 300)
scene.Add(NewSphere(Vector{-0.75, -0.75, 5}, 0.25, light))
scene.Add(NewCube(Vector{-1000, -1000, -1000}, Vector{1000, 1000, 0}, material))
mesh, err := LoadSTL("examples/hits.stl", material)
Expand Down
6 changes: 3 additions & 3 deletions examples/love.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ func main() {
}
mesh.FitInside(Box{Vector{-0.5, 0, -0.5}, Vector{0.5, 1, 0.5}}, Vector{0.5, 0, 0.5})
scene.Add(mesh)
scene.Add(NewSphere(Vector{-2, 10, 2}, 1, LightMaterial(Color{1, 1, 1}, 30, NoAttenuation)))
scene.Add(NewSphere(Vector{0, 10, 2}, 1, LightMaterial(Color{1, 1, 1}, 30, NoAttenuation)))
scene.Add(NewSphere(Vector{2, 10, 2}, 1, LightMaterial(Color{1, 1, 1}, 30, NoAttenuation)))
scene.Add(NewSphere(Vector{-2, 10, 2}, 1, LightMaterial(Color{1, 1, 1}, 30)))
scene.Add(NewSphere(Vector{0, 10, 2}, 1, LightMaterial(Color{1, 1, 1}, 30)))
scene.Add(NewSphere(Vector{2, 10, 2}, 1, LightMaterial(Color{1, 1, 1}, 30)))
camera := LookAt(Vector{0, 1.5, 2}, Vector{0, 0.5, 0}, Vector{0, 1, 0}, 35)
sampler := NewSampler(4, 4)
IterativeRender("out%03d.png", 1000, &scene, &camera, sampler, 1920/2, 1080/2, -1)
Expand Down
2 changes: 1 addition & 1 deletion examples/materials.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func main() {
scene.Add(NewSphere(V(0, 1.5, -4), 1.5, material))

scene.Add(NewCube(V(-1000, -1, -1000), V(1000, 0, 1000), GlossyMaterial(HexColor(0xFFFFFF), 1.4, Radians(20))))
scene.Add(NewSphere(V(0, 5, 0), 1, LightMaterial(Color{1, 1, 1}, 50, LinearAttenuation(0.4))))
scene.Add(NewSphere(V(0, 5, 0), 1, LightMaterial(Color{1, 1, 1}, 25)))
camera := LookAt(V(0, 3, 6), V(0, 1, 0), V(0, 1, 0), 30)
sampler := NewSampler(16, 16)
IterativeRender("out%03d.png", 1000, &scene, &camera, sampler, 1920/2, 1080/2, -1)
Expand Down
3 changes: 1 addition & 2 deletions examples/maze.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ func main() {
}
}
}
a := NoAttenuation // QuadraticAttenuation(0.25)
scene.Add(NewSphere(V(0, 0, 2.25), 0.25, LightMaterial(Color{1, 1, 1}, 500, a)))
scene.Add(NewSphere(V(0, 0, 2.25), 0.25, LightMaterial(Color{1, 1, 1}, 500)))
camera := LookAt(V(1, 0, 30), V(0, 0, 0), V(0, 0, 1), 35)
sampler := NewSampler(4, 4)
IterativeRender("out%03d.png", 1000, &scene, &camera, sampler, 1920/2, 1080/2, -1)
Expand Down
2 changes: 1 addition & 1 deletion examples/noise.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func main() {
}
}
}
light := NewSphere(V(100, 0, 50), 5, LightMaterial(Color{1, 1, 1}, 300, NoAttenuation))
light := NewSphere(V(100, 0, 50), 5, LightMaterial(Color{1, 1, 1}, 300))
scene.Add(light)
camera := LookAt(V(0, 0, -20), V(0, 0, 0), V(0, 1, 0), 30)
sampler := NewSampler(4, 4)
Expand Down
2 changes: 1 addition & 1 deletion examples/qbert.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func main() {
}
}
scene.Add(NewCube(V(-1000, -1000, -1), V(1000, 1000, 0), floor))
scene.Add(NewSphere(V(fn, fn/3, fn*2), 1, LightMaterial(Color{1, 1, 1}, 100, NoAttenuation)))
scene.Add(NewSphere(V(fn, fn/3, fn*2), 1, LightMaterial(Color{1, 1, 1}, 100)))
camera := LookAt(V(fn*2, fn*2, fn*2), V(0, 0, fn/4), V(0, 0, 1), 35)
sampler := NewSampler(4, 4)
IterativeRender("out%03d.png", 1000, &scene, &camera, sampler, 1920/2, 1080/2, -1)
Expand Down
2 changes: 1 addition & 1 deletion examples/spheres-anim.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func frame(i int) {
scene := Scene{}
scene.Color = HexColor(0xFFFFFF)
sphere(&scene, Vector{}, Vector{}, 1, 0, 7, t)
scene.Add(NewSphere(Vector{0, 0, 6}, 0.5, LightMaterial(Color{1, 1, 1}, 1, NoAttenuation)))
scene.Add(NewSphere(Vector{0, 0, 6}, 0.5, LightMaterial(Color{1, 1, 1}, 1)))
camera := LookAt(Vector{x, y, 1}, Vector{0, 0, 0}, Vector{0, 0, 1}, 30)
template := fmt.Sprintf("out%03d.png", i)
// IterativeRender(template, 1, &scene, &camera, 1920, 1080, 16, 16, 4)
Expand Down
2 changes: 1 addition & 1 deletion examples/spheres.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func main() {
scene := Scene{}
scene.Color = HexColor(0xFFFFFF)
sphere(&scene, Vector{}, Vector{}, 1, 8)
scene.Add(NewSphere(Vector{0, 0, 6}, 0.5, LightMaterial(Color{1, 1, 1}, 1, NoAttenuation)))
scene.Add(NewSphere(Vector{0, 0, 6}, 0.5, LightMaterial(Color{1, 1, 1}, 1)))
camera := LookAt(Vector{3, 1.75, 1}, Vector{0.75, 0.5, 0}, Vector{0, 0, 1}, 30)
sampler := NewSampler(4, 4)
IterativeRender("out%03d.png", 1000, &scene, &camera, sampler, 1920/2, 1080/2, -1)
Expand Down
2 changes: 1 addition & 1 deletion examples/sponza.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func main() {
}
mesh.MoveTo(Vector{}, Vector{0.5, 0, 0.5})
scene.Add(mesh)
scene.Add(NewSphere(Vector{0, 20, 0}, 3, LightMaterial(Color{1, 1, 1}, 100, NoAttenuation)))
scene.Add(NewSphere(Vector{0, 20, 0}, 3, LightMaterial(Color{1, 1, 1}, 100)))
camera := LookAt(Vector{-10, 2, 0}, Vector{0, 4, 0}, Vector{0, 1, 0}, 45)
sampler := NewSampler(4, 4)
IterativeRender("out%03d.png", 1000, &scene, &camera, sampler, 1920/2, 1080/2, -1)
Expand Down
4 changes: 2 additions & 2 deletions examples/suzanne.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import . "github.com/fogleman/pt/pt"
func main() {
scene := Scene{}
material := DiffuseMaterial(HexColor(0x334D5C))
scene.Add(NewSphere(Vector{0.5, 1, 3}, 1, LightMaterial(Color{1, 1, 1}, 10, NoAttenuation)))
// scene.Add(NewSphere(Vector{1.5, 1, 3}, 1, LightMaterial(Color{1, 1, 1}, 10, NoAttenuation)))
scene.Add(NewSphere(Vector{0.5, 1, 3}, 1, LightMaterial(Color{1, 1, 1}, 10)))
// scene.Add(NewSphere(Vector{1.5, 1, 3}, 1, LightMaterial(Color{1, 1, 1}, 10)))
scene.Add(NewCube(Vector{-5, -5, -2}, Vector{5, 5, -1}, material))
mesh, err := LoadOBJ("examples/suzanne.obj", SpecularMaterial(HexColor(0xEFC94C), 1.3))
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions examples/teapot.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import . "github.com/fogleman/pt/pt"

func main() {
scene := Scene{}
scene.Add(NewSphere(Vector{-2, 5, -3}, 0.5, LightMaterial(Color{1, 1, 1}, 50, NoAttenuation)))
scene.Add(NewSphere(Vector{5, 5, -3}, 0.5, LightMaterial(Color{1, 1, 1}, 50, NoAttenuation)))
scene.Add(NewSphere(Vector{-2, 5, -3}, 0.5, LightMaterial(Color{1, 1, 1}, 50)))
scene.Add(NewSphere(Vector{5, 5, -3}, 0.5, LightMaterial(Color{1, 1, 1}, 50)))
scene.Add(NewCube(Vector{-30, -1, -30}, Vector{30, 0, 30}, SpecularMaterial(HexColor(0xFCFAE1), 2)))
mesh, err := LoadOBJ("examples/teapot.obj", SpecularMaterial(HexColor(0xB9121B), 2))
if err != nil {
Expand Down
2 changes: 0 additions & 2 deletions examples/toybrick.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ func main() {
}
}
}
// light := LightMaterial(Color{0.2, 0.2, 0.2}, 10, QuadraticAttenuation(0.01))
// scene.Add(NewSphere(Vector{0, 0, 25}, 1, light))
camera := LookAt(Vector{-23, 13, 20}, Vector{0, 0, 0}, Vector{0, 0, 1}, 45)
sampler := NewSampler(4, 4)
IterativeRender("out%03d.png", 1000, &scene, &camera, sampler, 1920/2, 1080/2, -1)
Expand Down
2 changes: 1 addition & 1 deletion examples/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func main() {
// wall := GlossyMaterial(Color{1, 1, 1}, 1.1, Radians(20))
// scene.Add(NewCube(V(-10, 0.65, -10), V(10, 10, 10), wall))

// light := LightMaterial(Color{1, 1, 1}, 20, NoAttenuation)
// light := LightMaterial(Color{1, 1, 1}, 20)
// scene.Add(NewSphere(V(1, -5, -1), 1, light))

fmt.Println(volume.W, volume.H, volume.D)
Expand Down
21 changes: 0 additions & 21 deletions pt/attenuation.go

This file was deleted.

15 changes: 7 additions & 8 deletions pt/material.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,32 @@ type Material struct {
BumpTexture Texture
BumpMultiplier float64
Emittance float64
Attenuation Attenuation
Index float64 // refractive index
Gloss float64 // reflection cone angle in radians
Tint float64 // specular and refractive tinting
Transparent bool
}

func DiffuseMaterial(color Color) Material {
return Material{color, nil, nil, nil, 1, 0, NoAttenuation, 1, 0, 0, false}
return Material{color, nil, nil, nil, 1, 0, 1, 0, 0, false}
}

func SpecularMaterial(color Color, index float64) Material {
return Material{color, nil, nil, nil, 1, 0, NoAttenuation, index, 0, 0, false}
return Material{color, nil, nil, nil, 1, 0, index, 0, 0, false}
}

func GlossyMaterial(color Color, index, gloss float64) Material {
return Material{color, nil, nil, nil, 1, 0, NoAttenuation, index, gloss, 0, false}
return Material{color, nil, nil, nil, 1, 0, index, gloss, 0, false}
}

func ClearMaterial(index, gloss float64) Material {
return Material{Color{}, nil, nil, nil, 1, 0, NoAttenuation, index, gloss, 0, true}
return Material{Color{}, nil, nil, nil, 1, 0, index, gloss, 0, true}
}

func TransparentMaterial(color Color, index, gloss, tint float64) Material {
return Material{color, nil, nil, nil, 1, 0, NoAttenuation, index, gloss, tint, true}
return Material{color, nil, nil, nil, 1, 0, index, gloss, tint, true}
}

func LightMaterial(color Color, emittance float64, attenuation Attenuation) Material {
return Material{color, nil, nil, nil, 1, emittance, attenuation, 1, 0, 0, false}
func LightMaterial(color Color, emittance float64) Material {
return Material{color, nil, nil, nil, 1, emittance, 1, 0, 0, false}
}
6 changes: 2 additions & 4 deletions pt/sampler.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ func (s *DefaultSampler) sample(scene *Scene, ray Ray, emission bool, samples, d
if s.DirectLighting && !emission {
return Color{}
}
attenuation := info.Material.Attenuation.Compute(hit.T)
result = result.Add(info.Color.MulScalar(emittance * attenuation * float64(samples)))
result = result.Add(info.Color.MulScalar(emittance * float64(samples)))
}
n := int(math.Sqrt(float64(samples)))
for u := 0; u < n; u++ {
Expand Down Expand Up @@ -126,7 +125,6 @@ func (s *DefaultSampler) directLight(scene *Scene, n Ray, rnd *rand.Rand) Color
material := light.MaterialAt(point)
color := light.ColorAt(point)
emittance := material.Emittance
attenuation := material.Attenuation.Compute(hit.T)

// compute solid angle (hemisphere coverage)
hyp := center.Sub(n.Origin).Length()
Expand All @@ -138,6 +136,6 @@ func (s *DefaultSampler) directLight(scene *Scene, n Ray, rnd *rand.Rand) Color
r := math.Sin(theta) * adj
coverage := (r * r) / (d * d)

m := diffuse * emittance * attenuation * coverage * float64(nLights)
m := diffuse * emittance * coverage * float64(nLights)
return color.MulScalar(m)
}

0 comments on commit 5d46fdc

Please sign in to comment.