Make renderer actually use the material system properly.
The intersection code still isn't using any kind of shading, and materials aren't parsed by the parser, but the renderer class itself is using them.
This commit is contained in:
parent
543f2719e4
commit
0880a0f19d
|
@ -234,7 +234,7 @@ impl LightPath {
|
||||||
pos,
|
pos,
|
||||||
nor,
|
nor,
|
||||||
local_space: _,
|
local_space: _,
|
||||||
uv: _ } = isect {
|
closure } = isect {
|
||||||
// Hit something! Do the stuff
|
// Hit something! Do the stuff
|
||||||
self.interaction = *isect; // Store interaction for use in next phase
|
self.interaction = *isect; // Store interaction for use in next phase
|
||||||
|
|
||||||
|
@ -267,7 +267,7 @@ impl LightPath {
|
||||||
// Calculate and store the light that will be contributed
|
// Calculate and store the light that will be contributed
|
||||||
// to the film plane if the light is not in shadow.
|
// to the film plane if the light is not in shadow.
|
||||||
self.pending_color_addition = {
|
self.pending_color_addition = {
|
||||||
let material = LambertClosure::new(XYZ::new(0.8, 0.8, 0.8));
|
let material = closure.as_surface_closure();
|
||||||
let la = material.evaluate(ray.dir, shadow_vec, nor, self.wavelength);
|
let la = material.evaluate(ray.dir, shadow_vec, nor, self.wavelength);
|
||||||
light_color * la * self.light_attenuation / light_pdf
|
light_color * la * self.light_attenuation / light_pdf
|
||||||
};
|
};
|
||||||
|
@ -307,10 +307,10 @@ impl LightPath {
|
||||||
incoming,
|
incoming,
|
||||||
nor,
|
nor,
|
||||||
local_space: _,
|
local_space: _,
|
||||||
uv: _ } = self.interaction {
|
closure } = self.interaction {
|
||||||
// Sample material
|
// Sample material
|
||||||
let (dir, filter, pdf) = {
|
let (dir, filter, pdf) = {
|
||||||
let material = LambertClosure::new(XYZ::new(0.8, 0.8, 0.8));
|
let material = closure.as_surface_closure();
|
||||||
let u = self.next_lds_samp();
|
let u = self.next_lds_samp();
|
||||||
let v = self.next_lds_samp();
|
let v = self.next_lds_samp();
|
||||||
material.sample(incoming, nor, (u, v), self.wavelength)
|
material.sample(incoming, nor, (u, v), self.wavelength)
|
||||||
|
|
|
@ -4,8 +4,23 @@ use sampling::cosine_sample_hemisphere;
|
||||||
use std::f32::consts::PI as PI_32;
|
use std::f32::consts::PI as PI_32;
|
||||||
const INV_PI: f32 = 1.0 / PI_32;
|
const INV_PI: f32 = 1.0 / PI_32;
|
||||||
|
|
||||||
|
#[derive(Debug, Copy, Clone)]
|
||||||
|
pub enum SurfaceClosureUnion {
|
||||||
|
EmitClosure(EmitClosure),
|
||||||
|
LambertClosure(LambertClosure),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SurfaceClosureUnion {
|
||||||
|
pub fn as_surface_closure(&self) -> &SurfaceClosure {
|
||||||
|
match self {
|
||||||
|
&SurfaceClosureUnion::EmitClosure(ref closure) => closure as &SurfaceClosure,
|
||||||
|
&SurfaceClosureUnion::LambertClosure(ref closure) => closure as &SurfaceClosure,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Trait for surface closures.
|
/// Trait for surface closures.
|
||||||
pub trait SurfaceClosure: Copy {
|
pub trait SurfaceClosure {
|
||||||
/// Returns whether the closure has a delta distribution or not.
|
/// Returns whether the closure has a delta distribution or not.
|
||||||
fn is_delta(&self) -> bool;
|
fn is_delta(&self) -> bool;
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ use std::fmt::Debug;
|
||||||
|
|
||||||
pub mod triangle_mesh;
|
pub mod triangle_mesh;
|
||||||
|
|
||||||
|
use shading::surface_closure::SurfaceClosureUnion;
|
||||||
use ray::{Ray, AccelRay};
|
use ray::{Ray, AccelRay};
|
||||||
use math::{Point, Vector, Normal, Matrix4x4};
|
use math::{Point, Vector, Normal, Matrix4x4};
|
||||||
use boundable::Boundable;
|
use boundable::Boundable;
|
||||||
|
@ -19,7 +20,7 @@ pub enum SurfaceIntersection {
|
||||||
incoming: Vector,
|
incoming: Vector,
|
||||||
nor: Normal,
|
nor: Normal,
|
||||||
local_space: Matrix4x4,
|
local_space: Matrix4x4,
|
||||||
uv: (f32, f32),
|
closure: SurfaceClosureUnion,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,8 @@ use triangle;
|
||||||
use bbox::BBox;
|
use bbox::BBox;
|
||||||
use boundable::Boundable;
|
use boundable::Boundable;
|
||||||
use bvh::BVH;
|
use bvh::BVH;
|
||||||
|
use shading::surface_closure::{SurfaceClosureUnion, LambertClosure};
|
||||||
|
use color::XYZ;
|
||||||
|
|
||||||
use super::{Surface, SurfaceIntersection};
|
use super::{Surface, SurfaceIntersection};
|
||||||
|
|
||||||
|
@ -76,7 +78,7 @@ impl Surface for TriangleMesh {
|
||||||
let mat_space = lerp_slice(space, wr.time);
|
let mat_space = lerp_slice(space, wr.time);
|
||||||
let mat_inv = mat_space.inverse();
|
let mat_inv = mat_space.inverse();
|
||||||
let tri = (tri.0 * mat_inv, tri.1 * mat_inv, tri.2 * mat_inv);
|
let tri = (tri.0 * mat_inv, tri.1 * mat_inv, tri.2 * mat_inv);
|
||||||
if let Some((t, tri_u, tri_v)) = triangle::intersect_ray(wr, tri) {
|
if let Some((t, _, _)) = triangle::intersect_ray(wr, tri) {
|
||||||
if t < r.max_t {
|
if t < r.max_t {
|
||||||
if r.is_occlusion() {
|
if r.is_occlusion() {
|
||||||
isects[r.id as usize] = SurfaceIntersection::Occlude;
|
isects[r.id as usize] = SurfaceIntersection::Occlude;
|
||||||
|
@ -88,7 +90,10 @@ impl Surface for TriangleMesh {
|
||||||
incoming: wr.dir,
|
incoming: wr.dir,
|
||||||
nor: cross(tri.0 - tri.1, tri.0 - tri.2).into_normal(),
|
nor: cross(tri.0 - tri.1, tri.0 - tri.2).into_normal(),
|
||||||
local_space: mat_space,
|
local_space: mat_space,
|
||||||
uv: (tri_u, tri_v),
|
// TODO
|
||||||
|
closure: SurfaceClosureUnion::LambertClosure(
|
||||||
|
LambertClosure::new(XYZ::new(0.8, 0.8, 0.8))
|
||||||
|
),
|
||||||
};
|
};
|
||||||
r.max_t = t;
|
r.max_t = t;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user