Fixed bug in GTRClosure that was resulting in all NaN outputs.
This commit is contained in:
parent
0b05d364e4
commit
114f11c583
|
@ -413,6 +413,9 @@ impl GTRClosure {
|
||||||
(top / bottom).sqrt()
|
(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 {
|
fn dist(&self, nh: f32, rough: f32) -> f32 {
|
||||||
// Other useful numbers
|
// Other useful numbers
|
||||||
let roughness2 = rough * rough;
|
let roughness2 = rough * rough;
|
||||||
|
@ -442,7 +445,7 @@ impl SurfaceClosure for GTRClosure {
|
||||||
wavelength: f32)
|
wavelength: f32)
|
||||||
-> (Vector, SpectralSample, f32) {
|
-> (Vector, SpectralSample, f32) {
|
||||||
// Get normalized surface normal
|
// 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()
|
nor.normalized()
|
||||||
} else {
|
} else {
|
||||||
-nor.normalized() // If back-facing, flip normal
|
-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
|
let hh = (aa + bb).normalized(); // Half-way between aa and bb
|
||||||
|
|
||||||
// Surface normal
|
// Surface normal
|
||||||
let nn = if dot(nor.into_vector(), hh) <= 0.0 {
|
let nn = if dot(nor.into_vector(), hh) < 0.0 {
|
||||||
nor.normalized()
|
|
||||||
} else {
|
|
||||||
-nor.normalized() // If back-facing, flip normal
|
-nor.normalized() // If back-facing, flip normal
|
||||||
|
} else {
|
||||||
|
nor.normalized()
|
||||||
}
|
}
|
||||||
.into_vector();
|
.into_vector();
|
||||||
|
|
||||||
|
@ -561,10 +564,10 @@ impl SurfaceClosure for GTRClosure {
|
||||||
let hh = (aa + bb).normalized(); // Half-way between aa and bb
|
let hh = (aa + bb).normalized(); // Half-way between aa and bb
|
||||||
|
|
||||||
// Surface normal
|
// Surface normal
|
||||||
let nn = if dot(nor.into_vector(), hh) <= 0.0 {
|
let nn = if dot(nor.into_vector(), hh) < 0.0 {
|
||||||
nor.normalized()
|
|
||||||
} else {
|
|
||||||
-nor.normalized() // If back-facing, flip normal
|
-nor.normalized() // If back-facing, flip normal
|
||||||
|
} else {
|
||||||
|
nor.normalized()
|
||||||
}
|
}
|
||||||
.into_vector();
|
.into_vector();
|
||||||
|
|
||||||
|
@ -588,7 +591,7 @@ impl SurfaceClosure for GTRClosure {
|
||||||
assert!(cos_theta <= 1.0);
|
assert!(cos_theta <= 1.0);
|
||||||
|
|
||||||
// Surface normal
|
// Surface normal
|
||||||
let nn = if dot(nor.into_vector(), inc) <= 0.0 {
|
let nn = if dot(nor.into_vector(), inc) < 0.0 {
|
||||||
nor.normalized()
|
nor.normalized()
|
||||||
} else {
|
} else {
|
||||||
-nor.normalized() // If back-facing, flip normal
|
-nor.normalized() // If back-facing, flip normal
|
||||||
|
|
|
@ -7,7 +7,7 @@ use color::XYZ;
|
||||||
use lerp::{lerp, lerp_slice, lerp_slice_with};
|
use lerp::{lerp, lerp_slice, lerp_slice_with};
|
||||||
use math::{Point, Matrix4x4, cross};
|
use math::{Point, Matrix4x4, cross};
|
||||||
use ray::{Ray, AccelRay};
|
use ray::{Ray, AccelRay};
|
||||||
use shading::surface_closure::{SurfaceClosureUnion, LambertClosure};
|
use shading::surface_closure::{SurfaceClosureUnion, GTRClosure};
|
||||||
|
|
||||||
use super::{Surface, SurfaceIntersection};
|
use super::{Surface, SurfaceIntersection};
|
||||||
use super::triangle;
|
use super::triangle;
|
||||||
|
@ -97,10 +97,17 @@ 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,
|
||||||
// TODO
|
// TODO: get surface closure from surface shader.
|
||||||
closure: SurfaceClosureUnion::LambertClosure(
|
//closure: SurfaceClosureUnion::LambertClosure(
|
||||||
LambertClosure::new(XYZ::new(0.8, 0.8, 0.8))
|
// 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;
|
r.max_t = t;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user