mirror of
https://github.com/c-cube/moonpool.git
synced 2025-12-06 11:15:38 -05:00
Gamma correction
This commit is contained in:
parent
612e9d8af0
commit
c092de81ce
1 changed files with 20 additions and 11 deletions
|
|
@ -16,14 +16,15 @@ type hit_rec = { t : float;
|
||||||
type hit = hit_rec option
|
type hit = hit_rec option
|
||||||
|
|
||||||
let random_in_unit_sphere () =
|
let random_in_unit_sphere () =
|
||||||
let p = ref (Vec3.of_floats ((Random.float 1.0),
|
let p = ref (Vec3.sub (Vec3.mul 2.0 (Vec3.of_floats ((Random.float 1.0),
|
||||||
(Random.float 1.0),
|
(Random.float 1.0),
|
||||||
(Random.float 1.0))) in
|
(Random.float 1.0))))
|
||||||
|
(Vec3.of_floats (1., 1., 1.))) in
|
||||||
while ((Vec3.dot !p !p) >= 1.0) do
|
while ((Vec3.dot !p !p) >= 1.0) do
|
||||||
p := Vec3.mul 2.0 (Vec3.sub (Vec3.of_floats ((Random.float 1.0),
|
p := Vec3.sub (Vec3.mul 2.0 (Vec3.of_floats ((Random.float 1.0),
|
||||||
(Random.float 1.0),
|
(Random.float 1.0),
|
||||||
(Random.float 1.0)))
|
(Random.float 1.0))))
|
||||||
(Vec3.of_floats (1., 1., 1.)))
|
(Vec3.of_floats (1., 1., 1.))
|
||||||
done;
|
done;
|
||||||
!p
|
!p
|
||||||
;;
|
;;
|
||||||
|
|
@ -38,22 +39,22 @@ let hit_sphere sphere ray (tmin, tmax) =
|
||||||
|
|
||||||
if (discriminant > 0.0)
|
if (discriminant > 0.0)
|
||||||
then
|
then
|
||||||
let t = (-.b +. (sqrt discriminant)) /. a in
|
let t = (-.b -. (sqrt discriminant)) /. a in
|
||||||
|
|
||||||
if (t < tmax && t > tmin)
|
if (t < tmax && t > tmin)
|
||||||
then
|
then
|
||||||
let p = Ray.point_at_parameter ray t in
|
let p = Ray.point_at_parameter ray t in
|
||||||
Some { t = t;
|
Some { t = t;
|
||||||
p = p;
|
p = p;
|
||||||
normal = unit_vector (sub p sphere.center); }
|
normal = mul (1. /. sphere.radius) (sub p sphere.center); }
|
||||||
else
|
else
|
||||||
let t = (-.b -. (sqrt discriminant)) /. a in
|
let t = (-.b +. (sqrt discriminant)) /. a in
|
||||||
if (t < tmax && t > tmin)
|
if (t < tmax && t > tmin)
|
||||||
then
|
then
|
||||||
let p = Ray.point_at_parameter ray t in
|
let p = Ray.point_at_parameter ray t in
|
||||||
Some { t = t;
|
Some { t = t;
|
||||||
p = p;
|
p = p;
|
||||||
normal = unit_vector (sub p sphere.center); }
|
normal = mul (1. /. sphere.radius) (sub p sphere.center); }
|
||||||
else None
|
else None
|
||||||
else None
|
else None
|
||||||
|
|
||||||
|
|
@ -128,6 +129,10 @@ let write_to_file filename =
|
||||||
done;
|
done;
|
||||||
|
|
||||||
color := Vec3.mul (1. /. (Float.of_int ns)) !color ;
|
color := Vec3.mul (1. /. (Float.of_int ns)) !color ;
|
||||||
|
(* gamma correction *)
|
||||||
|
color := Vec3.of_floats (sqrt(!color.x),
|
||||||
|
sqrt(!color.y),
|
||||||
|
sqrt(!color.z));
|
||||||
let {x=r; y=g; z=b} = !color in
|
let {x=r; y=g; z=b} = !color in
|
||||||
let (ir, ig, ib) = (Int.of_float (r*.255.99),
|
let (ir, ig, ib) = (Int.of_float (r*.255.99),
|
||||||
Int.of_float (g*.255.99),
|
Int.of_float (g*.255.99),
|
||||||
|
|
@ -139,3 +144,7 @@ let write_to_file filename =
|
||||||
done;
|
done;
|
||||||
Out_channel.close oc;
|
Out_channel.close oc;
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
let () =
|
||||||
|
write_to_file "matte.ppm"
|
||||||
|
;;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue