-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
80 lines (71 loc) · 2 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
// TODO Use pointers when needed to reduce memory
package main
import (
"math"
"math/rand"
"github.com/schollz/progressbar"
)
const (
// Height of frame
Height = 1000
// Width of frame
Width = 2000
// TMin is the minimal no zero time
TMin = 0.001
// TMax limits time
TMax = 1000
// RaysPerPixel for anti-aliasing
RaysPerPixel = 10
// MaxDepth for ray boucing
MaxDepth = 50
// FPS Frames per second for movies
FPS = 60
)
func main() {
// Scene
camera := NewCamera(90.0, float64(Width)/float64(Height))
r := math.Cos(math.Pi / 4)
blue := Lambertian{Color{0.0, 0.0, 1.0}}
red := Lambertian{Color{1.0, 0.0, 0.0}}
World := HitableList{
Sphere{Vec3D{-r, 0.0, -1.0}, r, blue},
Sphere{Vec3D{r, 0.0, -1.0}, r, red},
}
// matRed := Lambertian{Color{0.7, 0.3, 0.3}}
// matGreen := Lambertian{Color{0.8, 0.8, 0.0}}
// metalGrey := Metal{Color{0.8, 0.8, 0.8}, 0.3}
// metalBrown := Metal{Color{0.8, 0.6, 0.2}, 1.0}
// glass := Dielectric{1.5}
// World := HitableList{
// Sphere{Vec3D{0.0, 0.0, -1.0}, 0.5, glass},
// Sphere{Vec3D{-1.0, 0.0, -1.0}, 0.5, metalGrey},
// Sphere{Vec3D{1.0, 0.0, -1.0}, 0.5, matRed},
// Sphere{Vec3D{0.0, -100.5, -1.0}, 100.0, matGreen},
// }
// Program
// start := AddVec3D(Origin, Vec3D{-1.0, 0.0, 0.0})
// move := Vec3D{2.0, 0.0, 0.0}
frame := Frame{}
bar := progressbar.New(Height)
bar.RenderBlank()
// for k := 0; k < FPS*DURATION; k++ {
// origin := AddVec3D(start, ScalarProduct(float64(k)/float64(FPS*DURATION), move))
// camera.origin = origin
for x := 0; x < Height; x++ {
for y := 0; y < Width; y++ {
var colorList [RaysPerPixel]Color
for it := 0; it < RaysPerPixel; it++ {
u := (float64(y) + rand.Float64()) / float64(Width)
v := (float64(x) + rand.Float64()) / float64(Height)
ray := camera.GetRay(u, v)
colorList[it] = RayColor(ray, World, 0)
}
color := ColorMeanSquare(colorList)
frame[Height-1-x][y] = color.ToPixel()
}
bar.Add(1)
}
frame.Save("img.png")
// frame.Save(fmt.Sprintf("frames/frame_%06d.ppm", k))
}
// }