aboutsummaryrefslogtreecommitdiff
path: root/rtiaw.go
blob: b0d2106163fdaeea9bc0cf5b45aef5df655f19cc (plain)
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
package main

import (
  "os"
  "runtime/pprof"
)

func main() {
  f, _ := os.Create("rtiaw.prof");
  pprof.StartCPUProfile(f);
  defer pprof.StopCPUProfile();

  var world Hittables;

  mat_ground := Lambertian{Vec3{0.5, 0.5, 0.5}};
  world = world.Add(Sphere{Vec3{0, -1000, 0}, 1000, mat_ground});

  i := Interval{0, 1};
  for a := -11; a < 11; a++ {
    for b := -11; b < 11; b++ {
      choose_mat := i.Sample();
      centre := Vec3{float64(a) + 0.9 * i.Sample(),
                     0.2,
                     float64(b) + 0.9 * i.Sample()};

      if centre.Sub(Vec3{4, 0.2, 0}).Mag() > 0.9 {
        if (choose_mat < 0.8) {
          // diffuse
          albedo := Vec3{i.Sample(), i.Sample(), i.Sample()}.
                    Mul(Vec3{i.Sample(), i.Sample(), i.Sample()});
          mat_sphere := Lambertian{albedo};
          world = world.Add(Sphere{centre, 0.2, mat_sphere});
        } else if (choose_mat < 0.95) {
          // metal
          j := Interval{0.5, 1};
          albedo := Vec3{j.Sample(), j.Sample(), j.Sample()};
          fuzz := j.Sample() - 0.5;
          mat_sphere := Metal{albedo, fuzz};
          world = world.Add(Sphere{centre, 0.2, mat_sphere});
        } else {
          // glass
          mat_sphere := Dielectric{1.5};
          world = world.Add(Sphere{centre, 0.2, mat_sphere});
        }
      }
    }
  }

  mat1 := Dielectric{1.5};
  world = world.Add(Sphere{Vec3{0, 1, 0}, 1.0, mat1});

  mat2 := Lambertian{Vec3{0.4, 0.2, 0.1}};
  world = world.Add(Sphere{Vec3{-4, 1, 0}, 1.0, mat2});

  mat3 := Metal{Vec3{0.7, 0.6, 0.5}, 0.0};
  world = world.Add(Sphere{Vec3{4, 1, 0}, 1.0, mat3});

  cam := NewCamera(1200, 16.0/9.0,
                   500, 50,
                   20, Vec3{13, 2, 3},
                   Vec3{0, 0, 0}, Vec3{0, 1, 0},
                   0.6, 10.0);
  cam.Render(world);
}