Skip to content

Commit

Permalink
Make all Scene members private
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Oom committed Sep 3, 2024
1 parent ee817db commit 54d86f6
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 18 deletions.
8 changes: 4 additions & 4 deletions kdtree-tester-cli/src/ray_bouncer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ impl RayBouncer {
ray: &Ray,
t_range: RangeInclusive<f32>,
) -> Option<KdIntersection> {
let indices = 0u32..self.scene.geometries.len() as u32;
intersect_closest_geometry(&self.scene.geometries, indices, ray, t_range)
let indices = 0u32..self.scene.geometries().len() as u32;
intersect_closest_geometry(self.scene.geometries(), indices, ray, t_range)
}

fn checked_ray_intersect(
Expand All @@ -38,7 +38,7 @@ impl RayBouncer {
) -> CheckedIntersection {
let kdtree = self
.kdtree
.intersect(&self.scene.geometries, ray, t_range.clone());
.intersect(self.scene.geometries(), ray, t_range.clone());
let reference = self.reference_ray_intersect(ray, t_range);
CheckedIntersection {
ray: ray.clone(),
Expand Down Expand Up @@ -76,7 +76,7 @@ impl RayBouncer {

let incoming_fails = self
.scene
.lights
.lights()
.iter()
.filter_map(|light| {
let shadow_ray = Ray::between(point_above, sample_light(light, &mut rng));
Expand Down
4 changes: 2 additions & 2 deletions kdtree-tester-cli/src/ray_tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ pub(crate) fn kdtree_ray_tester(
let scene = Scene::read_obj_file_with_print_logging(&input);

println!("Building kdtree...");
let kdtree = build_kdtree(&scene.geometries, &sah);
let kdtree = build_kdtree(scene.geometries(), &sah);

println!("Testing up to {} rays...", size.x * size.y * bounces);
let camera = Pinhole::new(scene.cameras[0].clone(), size.as_uvec2());
let camera = Pinhole::new(scene.cameras()[0].clone(), size.as_uvec2());
let bouncer = RayBouncer {
scene,
kdtree,
Expand Down
4 changes: 2 additions & 2 deletions pathtracer-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ fn main() {

println!("Building kdtree...");
let kdtree = build_kdtree(
&scene.geometries,
scene.geometries(),
&SahCost {
traverse_cost: args.traverse_cost,
intersect_cost: args.intersect_cost,
Expand All @@ -172,7 +172,7 @@ fn main() {
"Rendering {} px image with {} thread(s) and {} total iteration(s)...",
args.size, args.threads, total_iterations,
);
let camera = Pinhole::new(scene.cameras[0].clone(), args.size.as_uvec2());
let camera = Pinhole::new(scene.cameras()[0].clone(), args.size.as_uvec2());
let pathtracer = Pathtracer {
max_bounces: args.max_bounces,
scene,
Expand Down
4 changes: 2 additions & 2 deletions pathtracer-gui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn main() {

println!("Building kdtree...");
let kdtree = build_kdtree(
&scene.geometries,
scene.geometries(),
&SahCost {
traverse_cost: args.traverse_cost,
intersect_cost: args.intersect_cost,
Expand All @@ -45,7 +45,7 @@ fn main() {
};

miniquad::start(Conf::default(), move || {
let camera = pathtracer.scene.cameras[0].clone();
let camera = pathtracer.scene.cameras()[0].clone();
Box::new(Stage::new(pathtracer, camera))
});
}
28 changes: 24 additions & 4 deletions scene/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ struct TriangleProperties {
}

pub struct Scene {
pub geometries: Vec<Geometry>,
geometries: Vec<Geometry>,
properties: Vec<TriangleProperties>,
materials: Vec<Material>,
pub cameras: Vec<Camera>,
pub lights: Vec<SphericalLight>,
pub environment: Vec3,
cameras: Vec<Camera>,
lights: Vec<SphericalLight>,
environment: Vec3,
}

fn blend_from_mtl(image_directory: &Path, material: &mtl::Material) -> Material {
Expand Down Expand Up @@ -182,6 +182,26 @@ impl Scene {
scene
}

#[inline]
pub fn geometries(&self) -> &[Geometry] {
&self.geometries
}

#[inline]
pub fn cameras(&self) -> &[Camera] {
&self.cameras
}

#[inline]
pub fn lights(&self) -> &[SphericalLight] {
&self.lights
}

#[inline]
pub fn environment(&self) -> Vec3 {
self.environment
}

#[inline]
pub fn get_material(&self, index: u32) -> &Material {
&self.materials[self.properties[index as usize].material_index]
Expand Down
8 changes: 4 additions & 4 deletions tracing/src/pathtracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl Pathtracer {
for bounce in 1..=self.max_bounces {
let intersection = self
.kdtree
.intersect(&self.scene.geometries, &ray, 0.0..=f32::MAX);
.intersect(self.scene.geometries(), &ray, 0.0..=f32::MAX);
ray_logger
.log_ray(
&intersection
Expand All @@ -39,7 +39,7 @@ impl Pathtracer {
)
.unwrap();
if intersection.is_none() {
return accumulated_radiance + accumulated_transport * self.scene.environment;
return accumulated_radiance + accumulated_transport * self.scene.environment();
}
let intersection = intersection.unwrap();
let intersection_index = intersection.index;
Expand All @@ -60,14 +60,14 @@ impl Pathtracer {

let incoming_radiance: Vec3 = self
.scene
.lights
.lights()
.iter()
.map(|light| {
// TODO: Offset should depend on incoming direction, not only surface normal.
let shadow_ray = Ray::between(point_above, sample_light(light, rng));
let intersection =
self.kdtree
.intersect(&self.scene.geometries, &shadow_ray, 0.0..=1.0);
.intersect(self.scene.geometries(), &shadow_ray, 0.0..=1.0);
ray_logger
.log_shadow(&shadow_ray, bounce, intersection.is_some())
.unwrap();
Expand Down

0 comments on commit 54d86f6

Please sign in to comment.