|
223 | 223 | Scatter(Ray(rec.p, reflected), mat.albedo)
|
224 | 224 | end
|
225 | 225 |
|
226 |
| -"Scene with 2 Lambertian spheres" |
227 |
| -function scene_2_spheres(; elem_type::Type{T}) where T |
228 |
| - spheres = Sphere[] |
229 |
| - |
230 |
| - # small center sphere |
231 |
| - push!(spheres, Sphere((SA{T}[0,0,-1]), T(0.5), Lambertian(SA{T}[0.7,0.3,0.3]))) |
232 |
| - |
233 |
| - # ground sphere |
234 |
| - push!(spheres, Sphere((SA{T}[0,-100.5,-1]), T(100), Lambertian(SA{T}[0.8,0.8,0.0]))) |
235 |
| - HittableList(spheres) |
236 |
| -end |
237 |
| - |
238 |
| -"""Scene with 2 Lambertian, 2 Metal spheres. |
239 |
| -
|
240 |
| - See https://raytracing.github.io/images/img-1.11-metal-shiny.png""" |
241 |
| -function scene_4_spheres(; elem_type::Type{T}) where T |
242 |
| - scene = scene_2_spheres(; elem_type=elem_type) |
243 |
| - |
244 |
| - # left and right Metal spheres |
245 |
| - push!(scene, Sphere((SA{T}[-1,0,-1]), T(0.5), Metal((SA{T}[0.8,0.8,0.8]), T(0.3)))) |
246 |
| - push!(scene, Sphere((SA{T}[ 1,0,-1]), T(0.5), Metal((SA{T}[0.8,0.6,0.2]), T(0.8)))) |
247 |
| - return scene |
248 |
| -end |
249 |
| - |
250 | 226 | struct Camera{T <: AbstractFloat}
|
251 | 227 | origin::Vec3{T}
|
252 | 228 | lower_left_corner::Vec3{T}
|
|
408 | 384 | Scatter(Ray{T}(rec.p, dir), attenuation) # TODO: rename reflected -> !absorbed?
|
409 | 385 | end
|
410 | 386 |
|
411 |
| -@inline function scene_diel_spheres(left_radius=0.5; elem_type::Type{T}) where T # dielectric spheres |
412 |
| - spheres = Sphere[] |
413 |
| - |
414 |
| - # small center sphere |
415 |
| - push!(spheres, Sphere((SA{T}[0,0,-1]), T(0.5), Lambertian(SA{T}[0.1,0.2,0.5]))) |
416 |
| - |
417 |
| - # ground sphere (planet?) |
418 |
| - push!(spheres, Sphere((SA{T}[0,-100.5,-1]), T(100), Lambertian(SA{T}[0.8,0.8,0.0]))) |
419 |
| - |
420 |
| - # # left and right spheres. |
421 |
| - # # Use a negative radius on the left sphere to create a "thin bubble" |
422 |
| - push!(spheres, Sphere((SA{T}[-1,0,-1]), T(left_radius), Dielectric(T(1.5)))) |
423 |
| - push!(spheres, Sphere((SA{T}[1,0,-1]), T(0.5), Metal((SA{T}[0.8,0.6,0.2]), T(0)))) |
424 |
| - HittableList(spheres) |
425 |
| -end |
426 |
| - |
427 |
| -function scene_blue_red_spheres(; elem_type::Type{T}) where T # dielectric spheres |
428 |
| - spheres = Sphere[] |
429 |
| - R = cos(pi/4) |
430 |
| - push!(spheres, Sphere((SA{T}[-R,0,-1]), R, Lambertian(SA{T}[0,0,1]))) |
431 |
| - push!(spheres, Sphere((SA{T}[ R,0,-1]), R, Lambertian(SA{T}[1,0,0]))) |
432 |
| - HittableList(spheres) |
433 |
| -end |
434 |
| - |
435 |
| -function scene_random_spheres(; elem_type::Type{T}) where T |
436 |
| - spheres = Sphere[] |
437 |
| - |
438 |
| - # ground |
439 |
| - push!(spheres, Sphere((SA{T}[0,-1000,-1]), T(1000), |
440 |
| - Lambertian(SA{T}[0.5,0.5,0.5]))) |
441 |
| - |
442 |
| - for a in -11:10, b in -11:10 |
443 |
| - choose_mat = trand(T) |
444 |
| - center = SA[a + T(0.9)*trand(T), T(0.2), b + T(0.9)*trand(T)] |
445 |
| - |
446 |
| - # skip spheres too close? |
447 |
| - if norm(center - SA{T}[4,0.2,0]) < T(0.9) continue end |
448 |
| - |
449 |
| - if choose_mat < T(0.8) |
450 |
| - # diffuse |
451 |
| - albedo = @SVector[trand(T) for i ∈ 1:3] .* @SVector[trand(T) for i ∈ 1:3] |
452 |
| - push!(spheres, Sphere(center, T(0.2), Lambertian(albedo))) |
453 |
| - elseif choose_mat < T(0.95) |
454 |
| - # metal |
455 |
| - albedo = @SVector[random_between(T(0.5),T(1.0)) for i ∈ 1:3] |
456 |
| - fuzz = random_between(T(0.0), T(5.0)) |
457 |
| - push!(spheres, Sphere(center, T(0.2), Metal(albedo, fuzz))) |
458 |
| - else |
459 |
| - # glass |
460 |
| - push!(spheres, Sphere(center, T(0.2), Dielectric(T(1.5)))) |
461 |
| - end |
462 |
| - end |
463 |
| - |
464 |
| - push!(spheres, Sphere((SA{T}[0,1,0]), T(1), Dielectric(T(1.5)))) |
465 |
| - push!(spheres, Sphere((SA{T}[-4,1,0]), T(1), |
466 |
| - Lambertian(SA{T}[0.4,0.2,0.1]))) |
467 |
| - push!(spheres, Sphere((SA{T}[4,1,0]), T(1), |
468 |
| - Metal((SA{T}[0.7,0.6,0.5]), T(0)))) |
469 |
| - HittableList(spheres) |
470 |
| -end |
| 387 | +include("scenes.jl") |
471 | 388 |
|
472 | 389 | end
|
0 commit comments