-
Notifications
You must be signed in to change notification settings - Fork 12
/
main.go
96 lines (85 loc) · 2.09 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
package main
import (
"fmt"
"math"
"math/rand"
"github.com/unixpickle/model3d/model3d"
"github.com/unixpickle/model3d/render3d"
)
func main() {
bounds := &model3d.Rect{
MinVal: model3d.XYZ(-20, -20, -3),
MaxVal: model3d.XYZ(20, 30, 10),
}
scene := render3d.JoinedObject{
&render3d.ParticipatingMedium{
Collider: bounds,
Material: &render3d.HGMaterial{
G: 0.5,
ScatterColor: render3d.NewColor(0.9),
},
Lambda: 0.01,
},
// A room to surround the scene.
&render3d.ColliderObject{
Collider: model3d.MeshToCollider(
model3d.NewMeshRect(
bounds.MinVal,
bounds.MaxVal,
).MapCoords(model3d.XYZ(-1, 1, 1).Mul),
),
Material: &render3d.LambertMaterial{
DiffuseColor: render3d.NewColor(0.45),
},
},
// A ceiling light.
&render3d.ColliderObject{
Collider: &model3d.Sphere{
Center: model3d.Coord3D{Z: bounds.MaxVal.Z + 1.0, Y: 7},
Radius: 2.0,
},
Material: &render3d.LambertMaterial{
EmissionColor: render3d.NewColor(100.0),
},
},
}
// Some spheres to look at.
for i := 0; i < 20; i++ {
scene = append(scene, &render3d.ColliderObject{
Collider: &model3d.Sphere{
Center: model3d.NewCoord3DRandNorm().Mul(
model3d.XYZ(5, 10, 1),
).Add(model3d.Y(5)),
Radius: 1,
},
Material: &render3d.PhongMaterial{
Alpha: 10.0,
SpecularColor: render3d.NewColor(0.1),
DiffuseColor: render3d.NewColorRGB(rand.Float64(), rand.Float64(),
rand.Float64()).Scale(0.45),
},
})
}
renderer := render3d.RecursiveRayTracer{
Camera: render3d.NewCameraAt(model3d.Coord3D{Y: -13, Z: 2},
model3d.Coord3D{Y: 0, Z: 2}, math.Pi/3.6),
FocusPoints: []render3d.FocusPoint{
&render3d.PhongFocusPoint{
Target: model3d.Coord3D{Z: bounds.MaxVal.Z, Y: 7},
Alpha: 50.0,
},
},
FocusPointProbs: []float64{0.3},
MaxDepth: 10,
NumSamples: 1000,
Antialias: 1.0,
Cutoff: 1e-4,
LogFunc: func(p, samples float64) {
fmt.Printf("\rRendering %.1f%%...", p*100)
},
}
img := render3d.NewImage(200, 200)
renderer.Render(img, scene)
fmt.Println()
img.Save("output.png")
}