-
Notifications
You must be signed in to change notification settings - Fork 12
/
main.go
100 lines (83 loc) · 2.23 KB
/
main.go
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package main
import (
"fmt"
"math"
"github.com/unixpickle/model3d/model3d"
"github.com/unixpickle/model3d/render3d"
)
// ErrorMargin controls the amount of allowed noise in an
// HD rendering of the scene.
const ErrorMargin = 0.01
func main() {
ceilingLights := CreateCeilingLights()
lamp := CreateLamp()
wallLights := CreateWallLights()
scene := render3d.JoinedObject{
NewGlobe(),
NewWalls(ceilingLights),
CreateTable(),
lamp,
wallLights,
}
allLights := make([]render3d.AreaLight, 0, len(ceilingLights)+2)
for _, x := range ceilingLights {
allLights = append(allLights, x)
}
allLights = append(allLights, lamp, wallLights)
renderer := render3d.BidirPathTracer{
Camera: render3d.NewCameraAt(model3d.Coord3D{Y: -13, Z: 2},
model3d.Coord3D{Y: 0, Z: 2}, math.Pi/3.6),
Light: render3d.JoinAreaLights(allLights...),
MaxDepth: 15,
MinDepth: 3,
NumSamples: 200,
MinSamples: 200,
// Gamma-aware convergence criterion.
Convergence: func(mean, stddev render3d.Color) bool {
stddevs := stddev.Array()
for i, m := range mean.Array() {
s := stddevs[i]
if m-3*s > 1 {
// Oversaturated, so even if the variance
// is high, this region is stable.
continue
}
if math.Pow(m+s, 1/2.2)-math.Pow(m, 1/2.2) > ErrorMargin {
return false
}
}
return true
},
RouletteDelta: 0.2,
Antialias: 1.0,
Cutoff: 1e-4,
LogFunc: func(p, samples float64) {
fmt.Printf("\rRendering %.1f%%...", p*100)
},
}
fmt.Println("Ray variance:", renderer.RayVariance(scene, 200, 200, 5))
img := render3d.NewImage(200, 200)
renderer.Render(img, scene)
fmt.Println()
img.Save("output.png")
}
func CreateTable() render3d.Object {
createPiece := func(min, max model3d.Coord3D) render3d.Object {
return &render3d.ColliderObject{
Collider: model3d.MeshToCollider(model3d.NewMeshRect(min, max)),
Material: &render3d.PhongMaterial{
Alpha: 5,
SpecularColor: render3d.NewColor(0.2),
DiffuseColor: render3d.NewColor(0.4),
},
}
}
return render3d.JoinedObject{
createPiece(model3d.XYZ(-3, -2, -1.2),
model3d.XYZ(3, 2, -1)),
createPiece(model3d.XYZ(-3, -2, -5),
model3d.XYZ(-2.8, 2, -1.2)),
createPiece(model3d.XYZ(2.8, -2, -5),
model3d.XYZ(3, 2, -1.2)),
}
}