Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/render/medium.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,11 @@ Medium<Float, Spectrum>::transmittance_eval_pdf(const MediumInteraction3f &mi,
Mask active) const {
MI_MASKED_FUNCTION(ProfilerPhase::MediumEvaluate, active);

Float t = dr::minimum(mi.t, si.t) - mi.mint;
UnpolarizedSpectrum tr = dr::exp(-t * mi.combined_extinction);
Float t = dr::minimum(mi.t, si.t) - mi.mint;
// Clamp the optical depth: callers use the ratio tr / pdf, and on a long
// flight under a large majorant both would underflow to zero
UnpolarizedSpectrum tau = dr::minimum(t * mi.combined_extinction, 80.f);
UnpolarizedSpectrum tr = dr::exp(-tau);
UnpolarizedSpectrum pdf = dr::select(si.t < mi.t, tr, tr * mi.combined_extinction);
return { tr, pdf };
}
Expand Down
15 changes: 13 additions & 2 deletions src/volumes/grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,19 @@ class GridVolume final : public Volume<Float, Spectrum> {

m_texture.update_inplace();

if (!m_fixed_max)
m_max = (float) dr::max_nested(dr::detach(m_texture.value()));
if (!m_fixed_max) {
if (is_spectral_v<Spectrum> && m_texture.channel_count() == 4 && !m_raw) {
// Spectral upsampling stores (c0, c1, c2, scale) per voxel.
// The model spectrum is bounded by 1, so the scale channel
// bounds the volume; the coefficients do not.
using Array = typename TensorXf::Array;
const Array &data = m_texture.tensor().array();
auto idx = dr::arange<dr::uint32_array_t<Array>>(data.size() / 4) * 4 + 3;
m_max = (float) dr::max_nested(dr::gather<Array>(dr::detach(data), idx));
} else {
m_max = (float) dr::max_nested(dr::detach(m_texture.value()));
}
}
}
}

Expand Down