aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNat Lasseter <user@4574.co.uk>2024-06-25 00:13:41 +0100
committerNat Lasseter <user@4574.co.uk>2024-06-25 00:13:41 +0100
commit2211a942161d6509421915996f4351419adb990f (patch)
treef50fa8b2100b14860d23162f1549762982defc06
parente6ef8088e25750bca6ab61bda24fcb7e9e929ed1 (diff)
Final Render (yeah like)
-rw-r--r--camera.go8
-rw-r--r--rtiaw.go77
2 files changed, 56 insertions, 29 deletions
diff --git a/camera.go b/camera.go
index 8ca0664..5eefad5 100644
--- a/camera.go
+++ b/camera.go
@@ -4,6 +4,7 @@ import (
"fmt"
maths "math"
"os"
+ "time"
)
type Camera struct {
@@ -68,6 +69,8 @@ func NewCamera(wi uint, ar float64,
}
func (cam Camera) Render(world Hittable) {
+ start := time.Now();
+
fmt.Printf("P3\n%d %d\n255\n", cam.ImageWidth, cam.ImageHeight);
for row := uint(0); row < cam.ImageHeight; row++ {
fmt.Fprintf(os.Stderr,
@@ -85,6 +88,11 @@ func (cam Camera) Render(world Hittable) {
}
fmt.Printf("\n");
}
+
+ dur := time.Since(start);
+ fmt.Fprintf(os.Stderr,
+ "Done, in %5.2f seconds! \n",
+ dur.Seconds());
}
func (cam Camera) GetRay(row uint, col uint) Ray {
diff --git a/rtiaw.go b/rtiaw.go
index ab2c503..392db71 100644
--- a/rtiaw.go
+++ b/rtiaw.go
@@ -1,36 +1,55 @@
package main
-import (
- "fmt"
- "os"
- "time"
-)
-
func main() {
- start := time.Now();
+ var world Hittables;
- mat_ground := Lambertian{Vec3{0.8, 0.8, 0}};
- mat_centre := Lambertian{Vec3{0.1, 0.2, 0.5}};
- mat_left := Dielectric{1.5};
- mat_bubble := Dielectric{1.0 / 1.5};
- mat_right := Metal{Vec3{0.8, 0.6, 0.2}, 1.0};
+ mat_ground := Lambertian{Vec3{0.5, 0.5, 0.5}};
+ world.Add(Sphere{Vec3{0, -1000, 0}, 1000, mat_ground});
- var world Hittables;
- world.Add(Sphere{Vec3{ 0, -100.5, -1 }, 100 , mat_ground});
- world.Add(Sphere{Vec3{ 0, 0 , -1.2}, 0.5, mat_centre});
- world.Add(Sphere{Vec3{-1.0, 0 , -1 }, 0.5, mat_left});
- world.Add(Sphere{Vec3{-1.0, 0 , -1 }, 0.4, mat_bubble});
- world.Add(Sphere{Vec3{ 1.0, 0 , -1 }, 0.5, mat_right});
-
- cam := NewCamera(400, 16.0/9.0,
- 100, 50,
- 20, Vec3{-2, 2, 1},
- Vec3{0, 0, -1}, Vec3{0, 1, 0},
- 10.0, 3.4);
- cam.Render(world);
+ 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.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.Add(Sphere{centre, 0.2, mat_sphere});
+ } else {
+ // glass
+ mat_sphere := Dielectric{1.5};
+ world.Add(Sphere{centre, 0.2, mat_sphere});
+ }
+ }
+ }
+ }
- dur := time.Since(start);
- fmt.Fprintf(os.Stderr,
- "Done, in %5.2f seconds! \n",
- dur.Seconds());
+ mat1 := Dielectric{1.5};
+ world.Add(Sphere{Vec3{0, 1, 0}, 1.0, mat1});
+
+ mat2 := Lambertian{Vec3{0.4, 0.2, 0.1}};
+ world.Add(Sphere{Vec3{-4, 1, 0}, 1.0, mat2});
+
+ mat3 := Metal{Vec3{0.7, 0.6, 0.5}, 0.0};
+ 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);
}