Skip to content

Commit

Permalink
fix even more warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
gillett-hernandez committed May 20, 2024
1 parent 9d9c28b commit 7940afb
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 116 deletions.
3 changes: 1 addition & 2 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ extern crate log;
// use simplelog::*;
use simplelog::{ColorChoice, CombinedLogger, TermLogger, TerminalMode, WriteLogger};

use std::error::Error;
use std::fs;
use std::fs::File;
use std::path::PathBuf;
Expand All @@ -47,7 +46,7 @@ struct Opt {
pub write_log_level: String,
}

fn construct_scene(config: &Config) -> Result<World, Box<dyn Error>> {
fn construct_scene(config: &Config) -> anyhow::Result<World> {
construct_world(PathBuf::from(config.scene_file.clone()))
}

Expand Down
104 changes: 31 additions & 73 deletions src/bin/raymarch.rs
Original file line number Diff line number Diff line change
@@ -1,46 +1,33 @@
#![feature(portable_simd)]
#[macro_use]
extern crate log;
extern crate rust_pathtracer as root;
extern crate simplelog;

// std imports
use std::cmp::Ordering;
use std::fs::File;
use std::ops::{Add, Div, Mul, Neg, RangeInclusive, Sub};

// third party but non-subject-matter imports
use log::LevelFilter;
use log_once::warn_once;
use math::curves::*;
use math::prelude::{direction_to_uv, Point3, XYZColor};
use math::ray::Ray;
use math::sample::{RandomSampler, Sampler};
use math::spectral::{SingleWavelength, WavelengthEnergyTrait, BOUNDED_VISIBLE_RANGE};
use math::*;

use math::tangent_frame::TangentFrame;
use math::vec::Vec3;
use minifb::WindowOptions;
use pbr::ProgressBar;
use root::camera::ProjectiveCamera;
use rayon::iter::ParallelIterator;
use simplelog::{ColorChoice, CombinedLogger, TermLogger, TerminalMode, WriteLogger};
use structopt::StructOpt;

// our imports
use math::prelude::*;
use root::hittable::{HasBoundingBox, AABB};
use root::parsing::tonemap::TonemapSettings;
use root::parsing::{
config::*, construct_world, get_settings, load_scene, parse_config_and_cameras,
parse_tonemap_settings,
config::*, construct_world, get_settings, parse_config_and_cameras, parse_tonemap_settings,
};
use root::prelude::*;
use root::renderer::{output_film, Vec2D};
use root::tonemap::{Clamp, Tonemapper};
use root::world::{EnvironmentMap, Material, MaterialEnum};

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

use math::prelude::*;
// third party but subject-matter-relevant imports
use sdfu::ops::{HardMin, Union};
use sdfu::{Sphere, SDF};
use sdfu::SDF;
use ultraviolet::vec::Vec3 as uvVec3;

trait Convert {
Expand Down Expand Up @@ -115,7 +102,7 @@ enum MarchResult {
// generate_primitive_enum!(Sphere => Sphere<f32>);

trait MaterialTag {
fn material(&self, p: uvVec3) -> usize {
fn material(&self, _: uvVec3) -> usize {
0
}
}
Expand All @@ -142,7 +129,7 @@ impl<S: SDF<f32, uvVec3>> SDF<f32, uvVec3> for TaggedSDF<S> {
}

impl<S: SDF<f32, uvVec3>> MaterialTag for TaggedSDF<S> {
fn material(&self, p: uvVec3) -> usize {
fn material(&self, _: uvVec3) -> usize {
self.material
}
}
Expand Down Expand Up @@ -215,42 +202,18 @@ where

impl<S: SDF<f32, uvVec3> + MaterialTag> Scene<S> {
fn sdf(&self, p: Point3) -> (f32, usize) {
let mut min_time = f32::INFINITY;
let mut selected = 0;

// for (index, prim) in self.primitives.iter().enumerate() {
// let time = prim.dist(convert(p));

// if time < min_time {
// min_time = time;
// selected = index
// }
// }
selected = self.primitives.material(convert(p));
min_time = self.primitives.dist(convert(p));
(min_time, selected)
let p = convert(p);

(self.primitives.dist(p), self.primitives.material(p))
}
fn normal(&self, p: Point3, threshold: f32) -> Vec3 {
// get normal from prim[index]
// Vec3(deconvert(
// self.primitives[index]
// .normals(threshold)
// .normal_at(convert(p)),
// ))

Vec3(deconvert(
self.primitives.normals(threshold).normal_at(convert(p)),
))
}
// fn material(&self, p: Point3, threshold: f32) -> Option<usize> {
// // dead code?
// for (i, prim) in self.primitives.iter().enumerate() {
// if prim.dist(convert(p)) < threshold {
// // considered on or inside surface
// return Some(i);
// }
// }
// None
// }

pub fn march(
&self,
r: Ray,
Expand Down Expand Up @@ -323,7 +286,7 @@ impl<S: SDF<f32, uvVec3> + MaterialTag> Scene<S> {
let mut throughput = 1.0;
let mut sum = 0.0;
let mut flipped_sdf = false;
let mut last_bsdf_pdf = 0.0;
// let mut last_bsdf_pdf = 0.0;
for bounce in 0..bounces {
match self.march(r, 0.001, 0.001, flipped_sdf, printout) {
MarchResult::SurfaceIntersection {
Expand Down Expand Up @@ -415,7 +378,7 @@ macro_rules! find_and_add_material {
.materials
.iter()
.enumerate()
.find(|(index, material)| matches!(material, $scrutinee))
.find(|(_, material)| matches!(material, $scrutinee))
.and_then(|(i, material)| {
$materials.push(i);
Some(material)
Expand Down Expand Up @@ -559,7 +522,7 @@ fn main() {
TonemapSettings::Clamp {
exposure,
luminance_only,
silenced,
..
} => TonemapSettings::Clamp {
exposure,
luminance_only,
Expand All @@ -568,7 +531,7 @@ fn main() {
TonemapSettings::Reinhard0 {
key_value,
luminance_only,
silenced,
..
} => TonemapSettings::Reinhard0 {
key_value,
luminance_only,
Expand All @@ -578,7 +541,7 @@ fn main() {
key_value,
white_point,
luminance_only,
silenced,
..
} => TonemapSettings::Reinhard1 {
key_value,
white_point,
Expand All @@ -596,9 +559,9 @@ fn main() {
let mut sampler: Box<dyn Sampler> = Box::new(RandomSampler::new());
let lambda = wavelength_bounds.sample(sampler.draw_1d().x);
let (u, v) = (0.501, 0.5);
let (r, pdf) = camera.get_ray(&mut sampler, lambda, u, v);
let (r, _) = camera.get_ray(&mut sampler, lambda, u, v);

let color = scene.color(r, lambda, bounces, &mut sampler, true);
let _ = scene.color(r, lambda, bounces, &mut sampler, true);
return;
}

Expand All @@ -624,15 +587,15 @@ fn main() {
(px as f32 + film_sample.x) / width as f32,
(py as f32 + film_sample.y) / height as f32,
);
let (r, pdf) = camera.get_ray(&mut sampler, lambda, u, v);
let (r, _) = camera.get_ray(&mut sampler, lambda, u, v);
*pixel += scene.color(r, lambda, bounces, &mut sampler, false);
}
});
pb.add((width * height) as u64);
}
pb.finish();
}
RendererType::Tiled { tile_size } => {}
RendererType::Tiled { .. } => {}
RendererType::Preview { .. } => {
root::window_loop(
width,
Expand All @@ -656,20 +619,15 @@ fn main() {
(px as f32 + film_sample.x) / width as f32,
(py as f32 + film_sample.y) / height as f32,
);
let (r, pdf) = camera.get_ray(&mut sampler, lambda, u, v);
let (r, _) = camera.get_ray(&mut sampler, lambda, u, v);
*pixel += scene.color(r, lambda, bounces, &mut sampler, false);
}
});
total_samples += samples_per_frame;

let factor = 1.0 / (total_samples as f32 + 1.0);

update_window_buffer(
window_buffer,
&render_film,
tonemapper.as_mut(),
factor,
);
update_window_buffer(window_buffer, &render_film, tonemapper.as_mut(), factor);
},
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/camera/realistic_camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ impl Camera<f32, f32> for RealisticCamera {
todo!();
}

fn eval_we(&self, lambda: f32, normal: Vec3, from: Point3, to: Point3) -> (f32, PDF<f32, SolidAngle>) {
// TODO
fn eval_we(&self, _lambda: f32, _normal: Vec3, _from: Point3, _to: Point3) -> (f32, PDF<f32, SolidAngle>) {
// TODO implement We, requires backwards tracing to be robust
todo!()
}

Expand Down
1 change: 0 additions & 1 deletion src/mediums/hg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,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, 1.0),
Expand Down
13 changes: 6 additions & 7 deletions src/parsing/cameras.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ use std::collections::HashMap;
use std::fs::File;
use std::io::Read;


use serde::Deserialize;
use serde::{Deserialize, Serialize};

use super::config::{Config, TOMLConfig};

Expand All @@ -20,7 +19,7 @@ use optics::aperture::{ApertureEnum, CircularAperture, SimpleBladedAperture};
use optics::parse_lenses_from;

#[cfg(feature = "realistic_camera")]
#[derive(Deserialize, Clone, Copy)]
#[derive(Serialize, Deserialize, Clone, Copy)]
#[serde(tag = "type")]
pub enum ApertureData {
Circular,
Expand All @@ -44,7 +43,7 @@ impl Into<ApertureEnum> for ApertureData {
}

#[cfg(feature = "realistic_camera")]
#[derive(Deserialize, Clone)]
#[derive(Serialize, Deserialize, Clone)]
pub struct RealisticCameraData {
pub name: String,
pub lens_spec: String,
Expand All @@ -63,7 +62,7 @@ pub struct RealisticCameraData {
pub solver_heat: Option<f32>, // defaults to 0.01
}

#[derive(Deserialize, Clone)]
#[derive(Serialize, Deserialize, Clone)]
pub struct SimpleCameraData {
pub name: String,
pub look_from: [f32; 3],
Expand All @@ -78,7 +77,7 @@ pub struct SimpleCameraData {
// pub shutter_close_time: Option<f32>,
}

#[derive(Deserialize, Clone)]
#[derive(Serialize, Deserialize, Clone)]
pub struct PanoramaCameraData {
pub name: String,
pub look_from: [f32; 3],
Expand All @@ -87,7 +86,7 @@ pub struct PanoramaCameraData {
pub fov: [f32; 2], // in degrees. x should be in (0, 360], y should be in (0, 180]
}

#[derive(Deserialize, Clone)]
#[derive(Serialize, Deserialize, Clone)]
#[serde(tag = "type")]
pub enum CameraSettings {
SimpleCamera(SimpleCameraData),
Expand Down
16 changes: 8 additions & 8 deletions src/parsing/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

use crate::parsing::tonemap::TonemapSettings;

use serde::Deserialize;
use serde::{Deserialize, Serialize};

use super::cameras::CameraSettings;

#[derive(Deserialize, Copy, Clone)]
#[derive(Serialize, Deserialize, Copy, Clone)]
pub struct Resolution {
pub width: usize,
pub height: usize,
}

#[derive(Deserialize, Copy, Clone)]
#[derive(Serialize, Deserialize, Copy, Clone)]
#[serde(tag = "type")]
pub enum IntegratorKind {
PT {
Expand All @@ -28,15 +28,15 @@ pub enum IntegratorKind {
}

#[allow(non_camel_case_types)]
#[derive(Deserialize, Clone)]
#[derive(Serialize, Deserialize, Clone)]
#[serde(tag = "type")]
pub enum ColorSpaceSettings {
sRGB,
Rec709,
Rec2020,
}

#[derive(Deserialize, Clone)]
#[derive(Serialize, Deserialize, Clone)]
pub struct RenderSettings {
pub filename: Option<String>,
pub resolution: Resolution,
Expand All @@ -56,7 +56,7 @@ pub struct RenderSettings {
pub tonemap_settings: TonemapSettings,
}

#[derive(Deserialize, Clone)]
#[derive(Serialize, Deserialize, Clone)]
pub struct TOMLRenderSettings {
pub filename: Option<String>,
pub resolution: Resolution,
Expand Down Expand Up @@ -100,7 +100,7 @@ impl From<TOMLRenderSettings> for RenderSettings {
}
}

#[derive(Deserialize, Copy, Clone)]
#[derive(Serialize, Deserialize, Copy, Clone)]
#[serde(tag = "type")]
pub enum RendererType {
Naive,
Expand All @@ -113,7 +113,7 @@ pub enum RendererType {
},
}

#[derive(Deserialize, Clone)]
#[derive(Serialize, Deserialize, Clone)]
pub struct TOMLConfig {
pub env_sampling_probability: Option<f32>, //defaults to 0.5
pub default_scene_file: String,
Expand Down
Loading

0 comments on commit 7940afb

Please sign in to comment.