First shadows :D
This commit is contained in:
parent
b5e4647c0c
commit
e166a6fc97
2 changed files with 48415 additions and 48384 deletions
35
main.go
35
main.go
|
@ -118,6 +118,29 @@ func Unit_vector(v Vec3) Vec3 {
|
||||||
return new_v
|
return new_v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func RandomInUnitSphere() Vec3 {
|
||||||
|
for true {
|
||||||
|
p := RandomVec3(-1, 1)
|
||||||
|
if (p.Length_squared() < 1) {
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NewVec3(0,0,0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func RandomUnitVector() Vec3 {
|
||||||
|
return Unit_vector(RandomInUnitSphere())
|
||||||
|
}
|
||||||
|
|
||||||
|
func RandomOnHemisphere(normal Vec3) Vec3 {
|
||||||
|
var on_unit_sphere Vec3 = RandomUnitVector()
|
||||||
|
if (Dot(on_unit_sphere, normal) > 0.0) {
|
||||||
|
return on_unit_sphere
|
||||||
|
} else {
|
||||||
|
return on_unit_sphere.Neg()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const pi float32 = 3.1415926535897932385
|
const pi float32 = 3.1415926535897932385
|
||||||
|
|
||||||
func Degrees_to_radians(degrees float32) float32 {
|
func Degrees_to_radians(degrees float32) float32 {
|
||||||
|
@ -134,6 +157,13 @@ func RandomDoubleInRange(min, max float32) float32 {
|
||||||
return min + (max-min)*RandomDouble()
|
return min + (max-min)*RandomDouble()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func RandomVec3(borders ...float32) Vec3 {
|
||||||
|
if (len(borders) == 2) {
|
||||||
|
return NewVec3(RandomDoubleInRange(borders[0], borders[1]),RandomDoubleInRange(borders[0], borders[1]),RandomDoubleInRange(borders[0], borders[1]))
|
||||||
|
} else {
|
||||||
|
return NewVec3(RandomDouble(),RandomDouble(),RandomDouble())
|
||||||
|
}
|
||||||
|
}
|
||||||
// ============== COLOUR CLASS ==============
|
// ============== COLOUR CLASS ==============
|
||||||
|
|
||||||
func Write_color(v Vec3, samples_per_pixel int) {
|
func Write_color(v Vec3, samples_per_pixel int) {
|
||||||
|
@ -331,7 +361,8 @@ func NewCamera() *Camera {
|
||||||
func Ray_color(r Ray, world *Hittable) Vec3 {
|
func Ray_color(r Ray, world *Hittable) Vec3 {
|
||||||
var rec Hit_record
|
var rec Hit_record
|
||||||
if (world.Hit(&r, *NewInterval(0, float32(math.Inf(1))), &rec)) {
|
if (world.Hit(&r, *NewInterval(0, float32(math.Inf(1))), &rec)) {
|
||||||
return rec.normal.Add(NewColor(1,1,1)).Mult(0.5)
|
direction := RandomOnHemisphere(rec.normal)
|
||||||
|
return Ray_color(*((NewRay(rec.p, direction))), world).Mult(0.5)
|
||||||
}
|
}
|
||||||
unit_direction := Unit_vector(r.Direction())
|
unit_direction := Unit_vector(r.Direction())
|
||||||
a := (unit_direction.Y() + 1.0)*0.5
|
a := (unit_direction.Y() + 1.0)*0.5
|
||||||
|
@ -418,7 +449,7 @@ func main() {
|
||||||
cam := NewCamera()
|
cam := NewCamera()
|
||||||
cam.aspect_ratio = 16.0 / 9.0
|
cam.aspect_ratio = 16.0 / 9.0
|
||||||
cam.image_width = 400
|
cam.image_width = 400
|
||||||
cam.samples_per_pixel = 100
|
cam.samples_per_pixel = 50
|
||||||
cam.Render(world)
|
cam.Render(world)
|
||||||
// INFO: The pixels are written out in rows.
|
// INFO: The pixels are written out in rows.
|
||||||
// Image file can be created with
|
// Image file can be created with
|
||||||
|
|
Loading…
Reference in a new issue