@@ -2,14 +2,14 @@ package main
2
2
3
3
import (
4
4
"fmt"
5
- "io"
6
5
"math"
7
6
"math/rand"
8
7
"os"
9
8
10
9
"github.com/bhaney/raytracing/camera"
11
10
"github.com/bhaney/raytracing/env"
12
11
"github.com/bhaney/raytracing/ray"
12
+ "github.com/bhaney/raytracing/utils"
13
13
"github.com/golang/geo/r3"
14
14
)
15
15
@@ -19,13 +19,13 @@ func ColorRay(r *ray.Ray, world env.Hittable, depth int) ray.Color {
19
19
rec := new (env.HitRecord )
20
20
// If we've exceed the ray bounce limit, no more light is gathered
21
21
if depth <= 0 {
22
- return Color {0 , 0 , 0 }
22
+ return ray. Color {0 , 0 , 0 }
23
23
}
24
24
if world .Hit (r , 0.001 , math .Inf (1 ), rec ) { // Remember, Go is pass-by-value!
25
25
scattered := new (ray.Ray )
26
26
attenuation := new (ray.Color )
27
27
if rec .MatPtr .Scatter (r , scattered , rec , attenuation ) {
28
- resultVec := ray . ColorRay (scattered , world , depth - 1 )
28
+ resultVec := ColorRay (scattered , world , depth - 1 )
29
29
return ray.Color {attenuation .X * resultVec .X , attenuation .Y * resultVec .Y , attenuation .Z * resultVec .Z }
30
30
}
31
31
return ray.Color {0 , 0 , 0 }
@@ -80,7 +80,7 @@ func RandomScene() env.HittableList {
80
80
world = append (world , & env.Sphere {center , 0.2 , sphereMaterial })
81
81
} else if chooseMat < 0.95 {
82
82
// metal
83
- albedo := ray .Color (utis .RandomVectorFromRange (0.5 , 1. ))
83
+ albedo := ray .Color (utils .RandomVectorFromRange (0.5 , 1. ))
84
84
fuzz := utils .RandomFromRange (0. , 0.5 )
85
85
sphereMaterial = & env.Metal {albedo , fuzz }
86
86
world = append (world , & env.Sphere {center , 0.2 , sphereMaterial })
@@ -94,9 +94,9 @@ func RandomScene() env.HittableList {
94
94
95
95
material1 := env.Dielectric {1.5 }
96
96
world = append (world , & env.Sphere {r3.Vector {0 , 1 , 0 }, 1.0 , & material1 })
97
- material2 := env.Lambertian {Color {0.4 , 0.2 , 0.1 }}
97
+ material2 := env.Lambertian {ray. Color {0.4 , 0.2 , 0.1 }}
98
98
world = append (world , & env.Sphere {r3.Vector {- 4 , 1 , 0 }, 1.0 , & material2 })
99
- material3 := env.Metal {Color {0.7 , 0.6 , 0.5 }, 0.0 }
99
+ material3 := env.Metal {ray. Color {0.7 , 0.6 , 0.5 }, 0.0 }
100
100
world = append (world , & env.Sphere {r3.Vector {4 , 1 , 0 }, 1.0 , & material3 })
101
101
102
102
return world
@@ -107,46 +107,48 @@ func RandomScene() env.HittableList {
107
107
108
108
func main () {
109
109
// Image
110
- aspectRatio := 3.0 / 2.0
111
- imageWidth := 1200.
112
- imageHeight := imageWidth / aspectRatio
113
- samplesPerPixel := 500
114
- maxDepth := 50
115
110
/*
116
- aspectRatio := 16 .0 / 9 .0
117
- imageWidth := 400 .
111
+ aspectRatio := 3 .0 / 2 .0
112
+ imageWidth := 1200 .
118
113
imageHeight := imageWidth / aspectRatio
119
- samplesPerPixel := 100
114
+ samplesPerPixel := 500
120
115
maxDepth := 50
121
116
*/
117
+ aspectRatio := 16.0 / 9.0
118
+ imageWidth := 400.
119
+ imageHeight := imageWidth / aspectRatio
120
+ samplesPerPixel := 100
121
+ maxDepth := 50
122
122
123
123
// Camera
124
- vfov := 20.
125
- lookfrom := r3.Vector {13 , 2 , 3 }
126
- lookat := r3.Vector {0 , 0 , 0 }
127
- vup := r3.Vector {0 , 1 , 0 }
128
- distToFocus := 10.0
129
- aperture := 0.1
130
124
/*
131
- lookfrom := r3.Vector{3, 3, 2}
132
- lookat := r3.Vector{0, 0, -1}
125
+ vfov := 20.
126
+ lookfrom := r3.Vector{13, 2, 3}
127
+ lookat := r3.Vector{0, 0, 0}
133
128
vup := r3.Vector{0, 1, 0}
134
- distToFocus := lookfrom.Sub(lookat).Norm()
129
+ distToFocus := 10.0
135
130
aperture := 0.1
136
131
*/
132
+ vfov := 20.
133
+ lookfrom := r3.Vector {3 , 3 , 2 }
134
+ lookat := r3.Vector {0 , 0 , - 1 }
135
+ vup := r3.Vector {0 , 1 , 0 }
136
+ distToFocus := lookfrom .Sub (lookat ).Norm ()
137
+ aperture := 0.1
137
138
138
139
cam := camera .NewCamera (aspectRatio , vfov , aperture , distToFocus , lookfrom , lookat , vup )
139
140
140
141
// World
141
- world := RandomScene ()
142
+ //world := RandomScene()
143
+ world := PracticeScene ()
142
144
// Render
143
145
144
146
fmt .Printf ("P3\n %d %d\n 255\n " , int (imageWidth ), int (imageHeight ))
145
147
146
148
for j := int (imageHeight ) - 1 ; j >= 0 ; j -- {
147
149
fmt .Fprintf (os .Stderr , "\r Scanlines remaining: %d \n " , j )
148
150
for i := int (imageWidth ) - 1 ; i >= 0 ; i -- {
149
- c := Color {0 , 0 , 0 }
151
+ c := ray. Color {0 , 0 , 0 }
150
152
for s := 0 ; s < samplesPerPixel ; s ++ {
151
153
u := (float64 (i ) + rand .Float64 ()) / float64 (imageWidth - 1 )
152
154
v := (float64 (j ) + rand .Float64 ()) / float64 (imageHeight - 1 )
0 commit comments