-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (40 loc) · 1.22 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
package main
import (
"math"
"github.com/y-taka-23/raytracing-go"
)
func main() {
width, height := 384, 282
scene := getScene()
camera := getCamera(width, height)
cfg := raytracing.NewRendererConfig(width, height)
raytracing.NewRenderer(cfg).Render(scene, camera)
}
func getScene() raytracing.Scene {
scene := raytracing.NewScene()
scene.Add(raytracing.NewSphere(
raytracing.NewPoint(0, -1000, 0), 1000,
raytracing.NewLambertian(raytracing.NewColor(0.5, 0.5, 0.5))))
scene.Add(raytracing.NewSphere(
raytracing.NewPoint(0, 1, 0), 1,
raytracing.NewDielectric(1.5)))
scene.Add(raytracing.NewSphere(
raytracing.NewPoint(-4, 1, 0), 1,
raytracing.NewLambertian(raytracing.NewColor(0.4, 0.2, 0.1))))
scene.Add(raytracing.NewSphere(
raytracing.NewPoint(4, 1, 0), 1,
raytracing.NewMetal(raytracing.NewColor(0.7, 0.6, 0.5), 0)))
return *scene
}
func getCamera(width, height int) raytracing.Camera {
cfg := raytracing.NewCameraConfig(
float64(width)/float64(height),
raytracing.WithPointOfView(
raytracing.NewPoint(13, 2, 3),
raytracing.NewPoint(2, 0.75, 0)),
raytracing.WithVerticalFOV(math.Pi/9.0),
raytracing.WithAperture(0.1),
raytracing.WithFocusDistance(10.0),
)
return raytracing.NewCamera(cfg)
}