-
Notifications
You must be signed in to change notification settings - Fork 0
/
scene.jl
67 lines (52 loc) · 2.02 KB
/
scene.jl
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
# create random scatter_direction ground = Sphere([0.0, -1000.0, 0.0], 1000.0, Lambertian([0.5, 0.5, 0.5]))
function random_scene(seed=123456)
Random.seed!(seed)
ground = Sphere([0, -1000.0, 0], 1000.0, Lambertian([0.5, 0.5, 0.5]))
world = AbstractHittable[ground]
for a in -11:10
for b in -11:10
d = rand()
origin = [a + 0.9d, 0.2, b + 0.9d]
if norm(origin - [4, 0.2, 0]) > 0.9
if d < 0.8
# diffuse
albedo = rand(3) .^ 2
sphere_material = Lambertian(albedo)
sphere = Sphere(origin, 0.2, sphere_material)
push!(world, sphere)
elseif d < 0.95
# metal
albedo = 0.5rand(3) .+ 0.5 # 0.5:1.0
fuzz = 0.5rand()
sphere_material = Metal(albedo, fuzz)
sphere = Sphere(origin, 0.2, sphere_material)
push!(world, sphere)
else
# glass
sphere_material = Dielectric(1.5)
sphere = Sphere(origin, 0.2, sphere_material)
push!(world, sphere)
end
end
end
end
material1 = Dielectric(1.5)
push!(world, Sphere([0.0, 1, 0], 1.0, material1))
material2 = Lambertian([0.4, 0.2, 0.1])
push!(world, Sphere([-4.0, 1, 0], 1.0, material2))
material3 = Metal([0.7, 0.6, 0.5], 0.0)
push!(world, Sphere([4.0, 1.0, 0], 1.0, material3))
return world
end
function two_sphere_scene()
ground = Sphere([0, -1000.0, 0], 1000.0, Lambertian([0.5, 0.5, 0.5]))
world = AbstractHittable[ground]
# spheres
material1 = Dielectric(1.5)
push!(world, Sphere([0.0, 1, 0], 1.0, material1))
material2 = Lambertian([0.4, 0.2, 0.1])
push!(world, Sphere([-4.0, 1, 0], 1.0, material2))
material3 = Metal([0.7, 0.6, 0.5], 0.0)
push!(world, Sphere([4.0, 1.0, 0], 1.0, material3))
return world
end