Debug NaNs for shading.n in primitive.rs
wahn opened this issue · 4 comments
wahn commented
After commit 15ec371 the task is to figure out why we get NaNs with the following test scene (ecosys.pbrt
):
> ~/git/github/rs_pbrt/target/release/examples/rs_pbrt -i ecosys_rust.pbrt
...
DEBUG ME
thread '<unnamed>' panicked at 'n: Normal3 { x: 0.0, y: 0.0, z: 1.0 } dot shading.n: Normal3 { x: NaN, y: NaN, z: NaN }', src/core/primitive.rs:43:9
Here are the relevant lines of code in Rust:
> rg -trust "DEBUG ME" -B 1 -A 7
src/core/primitive.rs
40- if isect.shading.n.x.is_nan() {
41: println!("DEBUG ME");
42- }
43- assert!(
44- nrm_dot_nrm(&isect.n, &isect.shading.n) > 0.0,
45- "n: {:?} dot shading.n: {:?}",
46- isect.n,
47- isect.shading.n
48- );
wahn commented
Tracked it down a bit further: After calling Self::bump(...)
here:
impl Material for MirrorMaterial {
fn compute_scattering_functions(
...
) {
if let Some(ref bump) = self.bump_map {
Self::bump(bump, si);
...
We get:
(gdb) p si.shading
$4 = Shading = {n = Normal3<f32> = {x = nan(0x400000), y = nan(0x400000), z = nan(0x400000)},
dpdu = Vector3<f32> = {x = nan(0x400000), y = nan(0x400000), z = nan(0x400000)},
dpdv = Vector3<f32> = {x = 0, y = -100, z = -13.6056271},
dndu = Normal3<f32> = {x = 0, y = 0, z = 0},
dndv = Normal3<f32> = {x = 0, y = 0, z = 0}}
wahn commented
So, dpdus
seems to cause it:
(gdb) p *dpdus
$8 = Vector3<f32> = {x = nan(0x400000), y = nan(0x400000), z = nan(0x400000)}
Just before the call here:
fn bump(d: &Arc<Texture<Float> + Send + Sync>, si: &mut SurfaceInteraction)
where
Self: Sized,
{
...
si.set_shading_geometry(&dpdu, &dpdv, &dndu, &dndv, false);
}
wahn commented
(gdb) p u_displace
$9 = nan(0x400000)