mirror of
https://github.com/c-cube/moonpool.git
synced 2026-01-28 04:04:52 -05:00
Avoid initializing world in each call to get_color
This commit is contained in:
parent
7b01a47c16
commit
7b75b7c2fc
1 changed files with 10 additions and 11 deletions
|
|
@ -63,16 +63,7 @@ and hit h ray (tmin, tmax) =
|
|||
| World w -> hit_world w ray (tmin, tmax)
|
||||
|
||||
|
||||
let get_color ray =
|
||||
let sphere1 = Sphere {center = Vec3.of_floats (0., 0., -1.);
|
||||
radius = 0.5 } in
|
||||
let sphere2 = Sphere {center = Vec3.of_floats (0., -100.5, -1.);
|
||||
radius = 100.0 } in
|
||||
let sphere3 = Sphere {center = Vec3.of_floats (-1.0, -0.75, -2.);
|
||||
radius = 0.25 } in
|
||||
|
||||
let world = World [sphere2; sphere1; sphere3] in
|
||||
|
||||
let get_color world ray =
|
||||
match (hit world ray (0., Float.infinity)) with
|
||||
Some hit_result ->
|
||||
let t = hit_result.t in
|
||||
|
|
@ -90,6 +81,14 @@ let get_color ray =
|
|||
|
||||
let write_to_file filename =
|
||||
Random.self_init ();
|
||||
|
||||
let sphere1 = Sphere {center = Vec3.of_floats (0., 0., -1.);
|
||||
radius = 0.5 } in
|
||||
let sphere2 = Sphere {center = Vec3.of_floats (0., -100.5, -1.);
|
||||
radius = 100.0 } in
|
||||
let sphere3 = Sphere {center = Vec3.of_floats (-1.0, -0.75, -2.);
|
||||
radius = 0.25 } in
|
||||
let world = World [sphere2; sphere1; sphere3] in
|
||||
|
||||
let nx = 200 in
|
||||
let ny = 100 in
|
||||
|
|
@ -114,7 +113,7 @@ let write_to_file filename =
|
|||
|
||||
let r = { origin = origin;
|
||||
dir = Vec3.add lower_left_corner (Vec3.add (Vec3.mul u horizontal) (Vec3.mul v vertical)) } in
|
||||
color := Vec3.add !color (get_color r);
|
||||
color := Vec3.add !color (get_color world r);
|
||||
|
||||
done;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue