Skip to content

Commit

Permalink
fix specular lobe sampling in disney bsdf; fix possible crash in imag…
Browse files Browse the repository at this point in the history
…e3d loader (in editor)
  • Loading branch information
AirGuanZ committed Dec 2, 2020
1 parent 6a6c84c commit 0dc8409
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/editor/src/texture3d/image3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,11 @@ void Image3DWidget::browse_filename()
if(new_filename.isEmpty())
return;

std::ifstream fin(new_filename.toStdString(), std::ios::in);
std::ifstream fin(new_filename.toStdString());
if(!fin)
throw tracer::ObjectConstructionException(
"failed to open file: " + new_filename.toStdString());

new_real_data = tracer::toRC(
tracer::texture3d_load::load_real_from_ascii(fin));

Expand Down
2 changes: 1 addition & 1 deletion src/tracer/src/core/material/disney.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ namespace disney_impl
{
if(sam_selector < sample_w.transmission)
lwi = sample_transmission(lwo, new_sam);
else if(sam_selector -= sample_w.specular;
else if(sam_selector -= sample_w.transmission;
sam_selector < sample_w.specular)
lwi = sample_specular(lwo, new_sam);
else
Expand Down
8 changes: 5 additions & 3 deletions src/tracer/src/core/material/dream_works_fabric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ namespace
return {};

const FVec3 lwh = (lwi + lwo).normalize();
const real S = std::pow(1 - std::abs(lwh.x), n_);
const real S = std::pow(1 - std::abs(lwh.x), static_cast<real>(n_));

return color_ * S / Io[n_];
}
Expand Down Expand Up @@ -139,7 +139,8 @@ namespace

// construct result

const real S = std::pow(1 - std::abs(sin_theta_h), n_);
const real S = std::pow(
1 - std::abs(sin_theta_h), static_cast<real>(n_));

SampleResult ret;
ret.f = color_ * S / Io[n_];
Expand All @@ -157,7 +158,8 @@ namespace
const FVec3 lwh = (lwi + lwo).normalize();
const real sin_theta_h = lwh.x;

const real S = std::pow(1 - std::abs(sin_theta_h), n_);
const real S = std::pow(
1 - std::abs(sin_theta_h), static_cast<real>(n_));

return real(n_ + 1) * S / (8 * PI_r * dot(lwi, lwh));
}
Expand Down
2 changes: 1 addition & 1 deletion src/tracer/src/core/material/utility/microfacet.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace microfacet
inline real one_minus_5(real x) noexcept
{
real t = 1 - x, t2 = t * t; return t2 * t2 * t;
}
}

real gtr2(real cos_theta_h, real alpha) noexcept;

Expand Down

0 comments on commit 0dc8409

Please sign in to comment.