Skip to content

Commit

Permalink
Selective merge of seminar contribution of Eckholz via pr #31
Browse files Browse the repository at this point in the history
Co-authored-by: Eric <Windholz.Eric@yahoo.de>
  • Loading branch information
PearCoding and Eggholz committed Sep 5, 2022
1 parent f6826db commit 1261af6
Show file tree
Hide file tree
Showing 17 changed files with 1,013 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/artic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ set(ARTIC_EXTRA_SRC
${CMAKE_CURRENT_SOURCE_DIR}/impl/technique/debugtracer.art
${CMAKE_CURRENT_SOURCE_DIR}/impl/technique/infobuffer.art
${CMAKE_CURRENT_SOURCE_DIR}/impl/technique/pathtracer.art
${CMAKE_CURRENT_SOURCE_DIR}/impl/technique/restir.art
${CMAKE_CURRENT_SOURCE_DIR}/impl/technique/photonmapper.art
${CMAKE_CURRENT_SOURCE_DIR}/impl/technique/volpathtracer.art
${CMAKE_CURRENT_SOURCE_DIR}/impl/technique/wireframe.art
Expand Down
3 changes: 3 additions & 0 deletions src/artic/impl/camera/common.art
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// Special camera to satisfy issues when using tracing mode
fn @make_null_camera() = Camera {
near = 0,
far = 0,
fov = 0,
generate_ray = @ |_, _, _| make_zero_ray(),
differential = @ |_| ( make_vec3(0,0,0), make_vec3(0,0,0) )
};
3 changes: 3 additions & 0 deletions src/artic/impl/camera/fishlens.art
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ fn @make_fishlens_camera(eye: Vec3, dir: Vec3, up: Vec3, w: f32, h: f32, mode: F
}

Camera {
near = tmin,
far = tmax,
fov = 0,
generate_ray = @ |_, x, y| {
make_ray(eye, compute_d(x,y), tmin, tmax, ray_flag_camera)
},
Expand Down
3 changes: 3 additions & 0 deletions src/artic/impl/camera/orthogonal.art
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
fn @make_orthogonal_camera(eye: Vec3, dir: Vec3, up: Vec3, scale: Vec2, tmin: f32, tmax: f32) -> Camera {
let right = vec3_normalize(vec3_cross(dir, up));
Camera {
near = tmin,
far = tmax,
fov = 0,
generate_ray = @ |_, x, y| {
let pos = vec3_add(vec3_add(vec3_mulf(right, scale.x * x), vec3_mulf(up, scale.y * y)), eye);
make_ray(pos, dir, tmin, tmax, ray_flag_camera)
Expand Down
8 changes: 7 additions & 1 deletion src/artic/impl/camera/perspective.art
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ fn @compute_scale_from_vfov(fov: f32, aspect: f32) -> Vec2 {
}

// Creates a perspective camera
fn @make_perspective_camera(eye: Vec3, dir: Vec3, up: Vec3, scale: Vec2, tmin: f32, tmax: f32) -> Camera {
fn @make_perspective_camera(eye: Vec3, dir: Vec3, up: Vec3, scale: Vec2, tmin: f32, angle: f32, tmax: f32) -> Camera {
let right = vec3_normalize(vec3_cross(dir, up));
let view = make_mat3x3(right, up, dir);

Camera {
near = tmin,
far = tmax,
fov = angle,
generate_ray = @ |_, x, y| {
let d = vec3_normalize(mat3x3_mul(view, make_vec3(scale.x * x, scale.y * y, 1)));
make_ray(eye, d, tmin, tmax, ray_flag_camera)
Expand All @@ -37,6 +40,9 @@ fn @make_perspective_dof_camera(eye: Vec3, dir: Vec3, up: Vec3, scale: Vec2, ape
let view = make_mat3x3(right, up, dir);

Camera {
near = tmin,
far = tmax,
fov = 0,
generate_ray = @ |rnd, x, y| {
let global_dir = vec3_normalize(mat3x3_mul(view, make_vec3(scale.x * x, scale.y * y, 1)));
let focus_pos = vec3_mulf(global_dir, focal_length);
Expand Down
3 changes: 2 additions & 1 deletion src/artic/impl/emitter.art
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@

type RayStateInitializer = fn () -> RayPayload;

fn @make_camera_emitter(camera: Camera, iter: i32, spi: i32, sampler: PixelSampler, initState: RayStateInitializer) -> RayEmitter {
fn @make_camera_emitter(camera: Camera, iter: i32, spi: i32, frame: i32, sampler: PixelSampler, initState: RayStateInitializer) -> RayEmitter {
@ |sample, x, y, width, height| {
let mut hash = fnv_init();
hash = fnv_hash(hash, sample as u32);
hash = fnv_hash(hash, iter as u32);
hash = fnv_hash(hash, x as u32);
hash = fnv_hash(hash, y as u32);
hash = fnv_hash(hash, frame as u32);
let mut rnd = hash /*as RndState*/;
let (rx, ry) = sampler(&mut rnd, iter * spi + sample, x, y);
let kx = 2 * (x as f32 + rx) / (width as f32) - 1;
Expand Down
6 changes: 6 additions & 0 deletions src/artic/impl/pixel_sampler.art
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ fn @make_uniform_pixel_sampler() -> PixelSampler {
}
}

fn @make_in_the_middle_sampler() -> PixelSampler {
@| _, _, _, _| {
(0.5, 0.5)
}
}

// --------------------------
fn @make_mjitt_pixel_sampler(bin_x: u32, bin_y: u32) -> PixelSampler {
let F1 = 0xa511e9b3 : u32;
Expand Down
17 changes: 17 additions & 0 deletions src/artic/impl/sampling.art
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ fn @sample_triangle(mut u: f32, mut v: f32) -> (f32, f32) {
// Probability density function for uniform sphere sampling
fn @uniform_sphere_pdf() = 1 / (4 * flt_pi);

fn @uniform_hemisphere_pdf() = 1 / (2 * flt_pi);

// Samples a direction uniformly on a sphere
fn @sample_uniform_sphere(u: f32, v: f32) -> DirSample {
let c = 2 * v - 1;
Expand All @@ -55,6 +57,21 @@ fn @sample_uniform_sphere(u: f32, v: f32) -> DirSample {
make_dir_sample(c, s, phi, uniform_sphere_pdf())
}

fn @sample_uniform_hemisphere(u: f32, v: f32) -> DirSample {

let phi = 2.0 * flt_pi * v;

let sinTheta = safe_sqrt(1.0 - u * u);

DirSample
{
dir = make_vec3(sinTheta * math_builtins::cos(phi),
sinTheta * math_builtins::sin(phi),
u),
pdf = uniform_hemisphere_pdf()
}
}

// Probability density function for equal area sphere sampling
// Note: Keep in mind this is essentially the same as uniform_sphere, but a bit faster
fn @equal_area_sphere_pdf() = uniform_sphere_pdf();
Expand Down
Loading

0 comments on commit 1261af6

Please sign in to comment.