-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create sampler.ml. Defines a super-sampler signature, which implement…
…s super sampling: where color samples are taken at several instances inside the pixel and an average color is calculated. Implements a Stochastic (Random) sampler.
- Loading branch information
Showing
2 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
open Base | ||
|
||
module type S = sig | ||
type t | ||
val sample : t -> Image.xy -> Color.t | ||
end | ||
|
||
module Stochastic (C: Camera.S) (T: Tracer.S) = struct | ||
type t = { camera: C.t; tracer: T.t; n: int} | ||
let make ~camera ~tracer ~n = { camera; tracer; n } | ||
|
||
let sample { camera; tracer; n } (x, y) = | ||
let open Color in | ||
let f c = Float.of_int c +. Random.float 1. in | ||
(List.range 1 n | ||
|> List.map ~f:(fun _ -> C.ray_generate camera (f x, f y) |> T.trace tracer) | ||
|> List.fold_left ~init:black ~f:( |+| )) | ||
|/ (Float.of_int n) | ||
end | ||
|
||
(* TODO: Add more samplers *) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module type S = sig | ||
type t | ||
val sample : t -> Image.xy -> Color.t | ||
end | ||
|
||
module Stochastic (C: Camera.S) (T: Tracer.S) : sig | ||
include S | ||
val make : camera:C.t -> tracer:T.t -> n:int -> t | ||
end | ||
|