Skip to content

Commit

Permalink
fix more warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
gillett-hernandez committed May 20, 2024
1 parent 31a29b0 commit 9d9c28b
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 127 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ egui_extras = { version = "~0", optional = true }
sdfu = { git = "https://github.com/fu5ha/sdfu", optional = true, features = [
"ultraviolet",
] }
ultraviolet = { version = "~0.9", optional = true }
ultraviolet = { version = "~0.8", optional = true }
math = { git = "https://github.com/gillett-hernandez/rust_cg_math" }
# math = { git = "https://github.com/gillett-hernandez/rust_cg_math", default-features = false}
rust_optics = { git = "https://github.com/gillett-hernandez/rust_optics", optional = true }
Expand Down
2 changes: 2 additions & 0 deletions data/raymarch_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ russian_roulette = true
only_direct = false
# wavelength_bounds = [380.0, 750.0]
# wavelength_bounds = [500.0, 510.0]
[render_settings.colorspace_settings]
type = "Rec2020"
[render_settings.tonemap_settings]
type = "Reinhard1"
# exposure = -2.0
Expand Down
11 changes: 0 additions & 11 deletions data/scenes/raymarch.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,7 @@ env_sampling_probability = 0.5
type = "HDRI"
strength = 1.0
texture_name = "sunny_vondelpark_8k"
# texture_name = "machine_shop_4k"
# [environment]
# type="Sun"
# sun_direction=[0, 0, 1]
# strength = 1.0
# color = "D65"
# angular_diameter = 0.565

# instances are ignored
[[instances]]
material_name = "ggx_gold"
# material_name = "ggx_glass_dispersive"
Expand All @@ -25,7 +17,6 @@ type = "Sphere"
radius = 1.0
origin = [0.0, 0.0, 0.0]

# instances are ignored
[[instances]]
material_name = "diffuse_light"
# material_name = "sharp_light_xenon"
Expand All @@ -34,8 +25,6 @@ type = "Sphere"
radius = 1.0
origin = [0.0, 0.0, 0.0]


# instances are ignored
[[instances]]
material_name = "lambertian_white"
[instances.aggregate]
Expand Down
2 changes: 1 addition & 1 deletion src/bin/color_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ impl View {
panic!("{}", e);
});
// Limit to max ~60 fps update rate
window.limit_update_rate(Some(std::time::Duration::from_micros(16666)));
window.set_target_fps(60);
let buffer = vec![0u32; width * height];

Self {
Expand Down
37 changes: 16 additions & 21 deletions src/bin/raymarch.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![feature(portable_simd)]
#[macro_use]
extern crate log;
extern crate rust_pathtracer as root;
Expand All @@ -17,7 +18,6 @@ use math::*;

use math::tangent_frame::TangentFrame;
use math::vec::Vec3;
use packed_simd::f32x4;
use pbr::ProgressBar;
use root::camera::ProjectiveCamera;
use root::hittable::{HasBoundingBox, AABB};
Expand All @@ -26,21 +26,20 @@ use root::parsing::{
config::*, construct_world, get_settings, load_scene, parse_config_and_cameras,
parse_tonemap_settings,
};
use root::prelude::Camera;
use root::prelude::*;
use root::renderer::{output_film, Vec2D};
use root::rgb_to_u32;
use root::tonemap::{Clamp, ColorSpace, Tonemapper};
use root::tonemap::{Clamp, Tonemapper};
use root::world::{EnvironmentMap, Material, MaterialEnum};
use root::*;

use log::LevelFilter;
use minifb::{Key, KeyRepeat, Scale, Window, WindowOptions};
use rayon::iter::ParallelIterator;
use rayon::prelude::*;
use sdfu::ops::{HardMin, Union};
use simplelog::{ColorChoice, CombinedLogger, TermLogger, TerminalMode, WriteLogger};
use structopt::StructOpt;

use math::prelude::*;
use sdfu::ops::{HardMin, Union};
use sdfu::{Sphere, SDF};
use ultraviolet::vec::Vec3 as uvVec3;

Expand Down Expand Up @@ -154,7 +153,7 @@ impl<S1: SDF<f32, uvVec3> + MaterialTag, S2: SDF<f32, uvVec3> + MaterialTag> Mat
fn material(&self, p: uvVec3) -> usize {
let d0 = self.sdf1.dist(p);
let d1 = self.sdf2.dist(p);
match d0.partial_cmp(&d1) {
match PartialOrd::partial_cmp(&d0, &d1) {
Some(Ordering::Less) => self.sdf1.material(p),
Some(Ordering::Greater) => self.sdf2.material(p),
_ => {
Expand Down Expand Up @@ -587,7 +586,7 @@ fn main() {
silenced: true,
},
};
let (mut tonemapper, converter) = parse_tonemap_settings(tonemap_settings);
let mut tonemapper = parse_tonemap_settings(tonemap_settings);

let mut total_samples = 0;
let samples_per_frame = 1;
Expand Down Expand Up @@ -641,7 +640,7 @@ fn main() {
144,
WindowOptions::default(),
true,
|_, film, width, height| {
|_, window_buffer, width, height| {
render_film
.buffer
.par_iter_mut()
Expand All @@ -663,18 +662,14 @@ fn main() {
});
total_samples += samples_per_frame;

tonemapper.initialize(&render_film, 1.0 / (total_samples as f32 + 1.0));
film.par_iter_mut().enumerate().for_each(|(pixel_idx, v)| {
let y: usize = pixel_idx / width;
let x: usize = pixel_idx % width;
let [r, g, b, _]: [f32; 4] = converter
.transfer_function(
tonemapper.map(&render_film, (x as usize, y as usize)),
false,
)
.into();
*v = rgb_to_u32((256.0 * r) as u8, (256.0 * g) as u8, (256.0 * b) as u8);
});
let factor = 1.0 / (total_samples as f32 + 1.0);

update_window_buffer(
window_buffer,
&render_film,
tonemapper.as_mut(),
factor,
);
},
);
}
Expand Down
41 changes: 19 additions & 22 deletions src/camera/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,8 @@ pub trait Camera<L: Field, E: Field> {
// TODO: refactor this to actually coorespond to the function as defined by Veach (x == position on film, w = incoming direction, l = lambda)
// TODO: after the above has been completed, address the fact that if lambda is any nonscalar value (f32x4, etc), then eval_we would return 0 for all lanes/channels except for the main wavelength
// perhaps by splitting the WavelengthEnergy packet into its constituents, and sampling paths to the film for each lambda
fn eval_we(
&self,
lambda: L,
normal: Vec3,
from: Point3,
to: Point3,
) -> (E, PDF<E, SolidAngle>);
fn eval_we(&self, lambda: L, normal: Vec3, from: Point3, to: Point3)
-> (E, PDF<E, SolidAngle>);
fn sample_we(
&self,
film_sample: Sample2D,
Expand All @@ -52,7 +47,18 @@ pub trait Camera<L: Field, E: Field> {
}
}

macro_rules! generate_camera {
macro_rules! generate_camera_enum {
($name: ident, $($item:ident),+) => {
#[derive(Debug, Clone)]
pub enum $name {
$(
$item($item),
)+
}
};
}

macro_rules! generate_camera_impl {

($name: ident, $l: ty, $e: ty, $($item:ident),+) => {

Expand Down Expand Up @@ -124,24 +130,15 @@ macro_rules! generate_camera {
unsafe impl Sync for $name {}

};
($name: ident, $($item:ident),+) => {
#[derive(Debug, Clone)]
pub enum $name {
$(
$item($item),
)+
}
};

}

#[cfg(not(feature = "realistic_camera"))]
generate_camera! {CameraEnum, ProjectiveCamera, PanoramaCamera}
generate_camera_enum! {CameraEnum, ProjectiveCamera, PanoramaCamera}
#[cfg(not(feature = "realistic_camera"))]
generate_camera! {CameraEnum, f32, f32, ProjectiveCamera, PanoramaCamera}


generate_camera_impl! {CameraEnum, f32, f32, ProjectiveCamera, PanoramaCamera}

#[cfg(feature = "realistic_camera")]
generate_camera! {CameraEnum, ProjectiveCamera, PanoramaCamera, RealisticCamera}
generate_camera_enum! {CameraEnum, ProjectiveCamera, PanoramaCamera, RealisticCamera}
#[cfg(feature = "realistic_camera")]
generate_camera! {CameraEnum, f32, f32, ProjectiveCamera, PanoramaCamera, RealisticCamera}
generate_camera_impl! {CameraEnum, f32, f32, ProjectiveCamera, PanoramaCamera, RealisticCamera}
15 changes: 10 additions & 5 deletions src/camera/realistic_camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl RealisticCamera {
}
}

impl Camera for RealisticCamera {
impl Camera<f32, f32> for RealisticCamera {
fn get_ray(&self, sampler: &mut Box<dyn Sampler>, lambda: f32, s: f32, t: f32) -> (Ray, f32) {
// crop sensor to match aspect ratio
// aspect ratio is something like 16/9 for normal screens, where 16 == width and 9 == height
Expand Down Expand Up @@ -166,6 +166,7 @@ impl Camera for RealisticCamera {
Input::new(ray, lambda / 1000.0),
1.0,
|e| (self.aperture.intersects(self.aperture_radius, e), false),
drop,
);
if let Some(Output {
ray: mut pupil_ray,
Expand Down Expand Up @@ -198,7 +199,7 @@ impl Camera for RealisticCamera {
todo!();
}

fn eval_we(&self, lambda: f32, normal: Vec3, from: Point3, to: Point3) -> (f32, PDF) {
fn eval_we(&self, lambda: f32, normal: Vec3, from: Point3, to: Point3) -> (f32, PDF<f32, SolidAngle>) {
// TODO
todo!()
}
Expand All @@ -208,7 +209,7 @@ impl Camera for RealisticCamera {
film_sample: Sample2D,
sampler: &mut Box<dyn Sampler>,
lambda: f32,
) -> (Ray, Vec3, PDF) {
) -> (Ray, Vec3, PDF<f32, SolidAngle>) {
let (ray, tau) = self.get_ray(sampler, lambda, film_sample.x, film_sample.y);
(ray, self.direction, tau.into())
}
Expand Down Expand Up @@ -333,8 +334,12 @@ mod test {
let result = camera_surface.sample(sample, sample_from);
println!("{:?}", result);
let to = transform.to_world(Point3::ORIGIN);
let result2 =
camera_surface.psa_pdf(Vec3::X * (to - sample_from).normalized(), sample_from, to);
let result2 = camera_surface.psa_pdf(
Vec3::X * (to - sample_from).normalized(),
1.0,
sample_from,
to,
);
println!("{:?}", result2);
}
}
8 changes: 1 addition & 7 deletions src/materials/sharp_light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,13 +391,7 @@ mod test {
}

let factor = 1.0 / ((total_samples as f32).sqrt() + 1.0);
update_window_buffer(
&mut window_buffer,
&film,
&mut tonemapper,
crate::tonemap::sRGB,
factor,
);
update_window_buffer(&mut window_buffer, &film, &mut tonemapper, factor);
},
);
}
Expand Down
8 changes: 1 addition & 7 deletions src/mediums/hg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,7 @@ mod test {
1.0 / ((total_samples as f32).sqrt() + 1.0)
}
};
update_window_buffer(
&mut window_buffer,
&film,
&mut tonemapper,
converter,
factor,
);
update_window_buffer(&mut window_buffer, &film, &mut tonemapper, factor);
},
);
}
Expand Down
9 changes: 1 addition & 8 deletions src/mediums/rayleigh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ mod test {
let wi = Vec3::new(0.0, 1.0, 1.0).normalized();
// let wi = Vec3::Z;
let mut total_samples = 0;
let converter = crate::tonemap::sRGB;

let (samples_per_iteration, exposure): (usize, f32) = match mode {
TestMode::ViewPhase => (10, 17.0),
Expand Down Expand Up @@ -249,13 +248,7 @@ mod test {
1.0 / ((total_samples as f32).sqrt() + 1.0)
}
};
update_window_buffer(
&mut window_buffer,
&film,
&mut tonemapper,
converter,
factor,
);
update_window_buffer(&mut window_buffer, &film, &mut tonemapper, factor);
},
);
}
Expand Down
2 changes: 2 additions & 0 deletions src/parsing/cameras.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use crate::camera::{CameraEnum, PanoramaCamera, ProjectiveCamera};
use crate::camera::RealisticCamera;

use std::collections::HashMap;
use std::fs::File;
use std::io::Read;


use serde::Deserialize;
Expand Down
10 changes: 5 additions & 5 deletions src/renderer/preview.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// only needed because the actual code that uses these imports is gated
// behind a feature flag which the compiler does not seem to detect even though
// behind a feature flag which the compiler does not seem to detect even though
#![allow(unused_imports)]
use super::prelude::*;

Expand Down Expand Up @@ -102,7 +102,7 @@ impl Renderer for PreviewRenderer {
panic!("{}", e);
});
// Limit to max ~60 fps update rate
window.limit_update_rate(Some(std::time::Duration::from_micros(16666)));
window.set_target_fps(60);
let mut buffer = vec![0u32; width * height];
let now = Instant::now();
Expand Down Expand Up @@ -174,7 +174,7 @@ impl Renderer for PreviewRenderer {
panic!("{}", e);
});
// Limit to max ~60 fps update rate
light_window.limit_update_rate(Some(std::time::Duration::from_micros(16666)));
light_window.set_target_fps(60);
let light_buffer = Arc::new(Mutex::new(vec![0u32; width * height]));
let light_buffer_ref = Arc::clone(&light_buffer);
let render_settings_copy = render_settings.clone();
Expand Down Expand Up @@ -402,7 +402,7 @@ impl Renderer for PreviewRenderer {
panic!("{}", e);
});
// Limit to max ~60 fps update rate
window.limit_update_rate(Some(std::time::Duration::from_micros(16666)));
window.set_target_fps(60);
let mut buffer = vec![0u32; width * height];

let max_samples = render_settings
Expand Down Expand Up @@ -569,7 +569,7 @@ impl Renderer for PreviewRenderer {
panic!("{}", e);
});
// Limit to max ~60 fps update rate
light_window.limit_update_rate(Some(std::time::Duration::from_micros(16666)));
light_window.set_target_fps(60);
let light_buffer = Arc::new(Mutex::new(vec![0u32; width * height]));
let light_buffer_ref = Arc::clone(&light_buffer);
let render_settings_copy = render_settings.clone();
Expand Down
Loading

0 comments on commit 9d9c28b

Please sign in to comment.