diff --git a/src/shading/surface_closure.rs b/src/shading/surface_closure.rs index 5fc743b..3109acb 100644 --- a/src/shading/surface_closure.rs +++ b/src/shading/surface_closure.rs @@ -413,6 +413,9 @@ impl GTRClosure { (top / bottom).sqrt() } + /// Microfacet distribution function. + /// + /// nh: cosine of the angle between the surface normal and the microfacet normal. fn dist(&self, nh: f32, rough: f32) -> f32 { // Other useful numbers let roughness2 = rough * rough; @@ -442,7 +445,7 @@ impl SurfaceClosure for GTRClosure { wavelength: f32) -> (Vector, SpectralSample, f32) { // Get normalized surface normal - let nn = if dot(nor.into_vector(), inc) <= 0.0 { + let nn = if dot(nor.into_vector(), inc) < 0.0 { nor.normalized() } else { -nor.normalized() // If back-facing, flip normal @@ -472,10 +475,10 @@ impl SurfaceClosure for GTRClosure { let hh = (aa + bb).normalized(); // Half-way between aa and bb // Surface normal - let nn = if dot(nor.into_vector(), hh) <= 0.0 { - nor.normalized() - } else { + let nn = if dot(nor.into_vector(), hh) < 0.0 { -nor.normalized() // If back-facing, flip normal + } else { + nor.normalized() } .into_vector(); @@ -561,10 +564,10 @@ impl SurfaceClosure for GTRClosure { let hh = (aa + bb).normalized(); // Half-way between aa and bb // Surface normal - let nn = if dot(nor.into_vector(), hh) <= 0.0 { - nor.normalized() - } else { + let nn = if dot(nor.into_vector(), hh) < 0.0 { -nor.normalized() // If back-facing, flip normal + } else { + nor.normalized() } .into_vector(); @@ -588,7 +591,7 @@ impl SurfaceClosure for GTRClosure { assert!(cos_theta <= 1.0); // Surface normal - let nn = if dot(nor.into_vector(), inc) <= 0.0 { + let nn = if dot(nor.into_vector(), inc) < 0.0 { nor.normalized() } else { -nor.normalized() // If back-facing, flip normal diff --git a/src/surface/triangle_mesh.rs b/src/surface/triangle_mesh.rs index 88b29a0..d4fa217 100644 --- a/src/surface/triangle_mesh.rs +++ b/src/surface/triangle_mesh.rs @@ -7,7 +7,7 @@ use color::XYZ; use lerp::{lerp, lerp_slice, lerp_slice_with}; use math::{Point, Matrix4x4, cross}; use ray::{Ray, AccelRay}; -use shading::surface_closure::{SurfaceClosureUnion, LambertClosure}; +use shading::surface_closure::{SurfaceClosureUnion, GTRClosure}; use super::{Surface, SurfaceIntersection}; use super::triangle; @@ -97,10 +97,17 @@ impl Surface for TriangleMesh { incoming: wr.dir, nor: cross(tri.0 - tri.1, tri.0 - tri.2).into_normal(), local_space: mat_space, - // TODO - closure: SurfaceClosureUnion::LambertClosure( - LambertClosure::new(XYZ::new(0.8, 0.8, 0.8)) - ), + // TODO: get surface closure from surface shader. + //closure: SurfaceClosureUnion::LambertClosure( + // LambertClosure::new(XYZ::new(0.8, 0.8, 0.8)) + //), + closure: + SurfaceClosureUnion::GTRClosure(GTRClosure::new(XYZ::new(0.8, + 0.8, + 0.8), + 0.1, + 2.0, + 1.2)), }; r.max_t = t; }