bidirectional: implement path building
This commit is contained in:
parent
a774ecce47
commit
c4557adce1
|
@ -1,7 +1,11 @@
|
||||||
use super::super::Renderer;
|
use super::super::Renderer;
|
||||||
use super::path::*;
|
use super::path::*;
|
||||||
use crate::scene::Scene;
|
use crate::material::Material;
|
||||||
|
use crate::render::utils::sample_hemisphere;
|
||||||
|
use crate::scene::{Object, Scene};
|
||||||
|
use crate::shape::Shape;
|
||||||
use crate::{Point, Vector};
|
use crate::{Point, Vector};
|
||||||
|
use beevee::ray::Ray;
|
||||||
use image::RgbImage;
|
use image::RgbImage;
|
||||||
use nalgebra::Unit;
|
use nalgebra::Unit;
|
||||||
|
|
||||||
|
@ -30,17 +34,35 @@ impl BidirectionalPathtracer {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
fn construct_path(&self, point: Point, _direction: Unit<Vector>) -> Path {
|
fn construct_path(&self, mut origin: Point, mut direction: Unit<Vector>) -> Path {
|
||||||
let mut res = Path::new(point);
|
let mut res = Path::new(origin);
|
||||||
for _ in 0..self.scene.reflection_limit {
|
for _ in 0..self.scene.reflection_limit {
|
||||||
// FIXME:
|
let ray = Ray::new(origin, direction);
|
||||||
// * cast_ray: if no intersection, return the empty path
|
match self.cast_ray(ray) {
|
||||||
// * look-up information at intersection
|
Some((distance, obj)) => {
|
||||||
// * append to path
|
let hit_pos = origin + direction.as_ref() * distance;
|
||||||
// * start again with new origin
|
let texel = obj.shape.project_texel(&hit_pos);
|
||||||
|
let properties = obj.material.properties(texel);
|
||||||
|
let normal = obj.shape.normal(&hit_pos);
|
||||||
|
let p = PathPoint::new(origin, direction, normal, properties);
|
||||||
|
|
||||||
|
res.push_point(p);
|
||||||
|
|
||||||
|
let (new_direction, _) = sample_hemisphere(normal);
|
||||||
|
// Calculate the incoming light along the new ray
|
||||||
|
origin = hit_pos + new_direction.as_ref() * 0.001;
|
||||||
|
direction = new_direction;
|
||||||
|
}
|
||||||
|
None => break,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
|
fn cast_ray(&self, ray: Ray) -> Option<(f32, &Object)> {
|
||||||
|
self.scene.bvh.walk(&ray, &self.scene.objects)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Renderer for BidirectionalPathtracer {
|
impl Renderer for BidirectionalPathtracer {
|
||||||
|
|
Loading…
Reference in a new issue