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
17 changes: 16 additions & 1 deletion src/emitters/constant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ geometry that uses basic (e.g. diffuse) materials.
template <typename Float, typename Spectrum>
class ConstantBackgroundEmitter final : public Emitter<Float, Spectrum> {
public:
MI_IMPORT_BASE(Emitter, m_flags)
MI_IMPORT_BASE(Emitter, m_flags, m_sampling_weight)
MI_IMPORT_TYPES(Scene, Shape, Texture)

ConstantBackgroundEmitter(const Properties &props) : Base(props) {
Expand All @@ -60,10 +60,17 @@ class ConstantBackgroundEmitter final : public Emitter<Float, Spectrum> {

m_radiance = props.texture_d65<Texture>("radiance", 1.f);

// By default NEE is disabled with Constant emitter as BSDF sampling will always perform better
m_enable_nee = props.get<bool>("enable_nee", false);

if (m_radiance->is_spatially_varying())
Throw("Expected a non-spatially varying radiance spectra!");

m_flags = +EmitterFlags::Infinite;

// Disable NEE with constant emitters
if (!m_enable_nee)
m_sampling_weight = 0.f;
}

void traverse(TraversalCallback *callback) override {
Expand Down Expand Up @@ -123,6 +130,9 @@ class ConstantBackgroundEmitter final : public Emitter<Float, Spectrum> {
Mask active) const override {
MI_MASKED_FUNCTION(ProfilerPhase::EndpointSampleDirection, active);

if (!m_enable_nee)
return { dr::zeros<DirectionSample3f>(), 0.f }; // Disable NEE with constant emitters

Vector3f d = warp::square_to_uniform_sphere(sample);

// Automatically enlarge the bounding sphere when it does not contain the reference point
Expand Down Expand Up @@ -153,6 +163,9 @@ class ConstantBackgroundEmitter final : public Emitter<Float, Spectrum> {
Mask active) const override {
MI_MASKED_FUNCTION(ProfilerPhase::EndpointEvaluate, active);

if (!m_enable_nee)
return 0.f; // Disable NEE with constant emitters

return warp::square_to_uniform_sphere_pdf(ds.d);
}

Expand Down Expand Up @@ -204,6 +217,8 @@ class ConstantBackgroundEmitter final : public Emitter<Float, Spectrum> {

/// Surface area of the bounding sphere
Float m_surface_area;

bool m_enable_nee;
};

MI_IMPLEMENT_CLASS_VARIANT(ConstantBackgroundEmitter, Emitter)
Expand Down
11 changes: 7 additions & 4 deletions src/render/scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,14 @@ MI_VARIANT
void Scene<Float, Spectrum>::update_emitter_sampling_distribution() {
// Check if we need to use non-uniform emitter sampling.
bool non_uniform_sampling = false;
for (auto &e : m_emitters) {
if (e->sampling_weight() != ScalarFloat(1.0)) {
non_uniform_sampling = true;
break;

if (m_emitters.size() > 1) {
for (auto &e : m_emitters) {
if (e->sampling_weight() != ScalarFloat(1.0)) {
non_uniform_sampling = true;
break;
}
}
}
size_t n_emitters = m_emitters.size();
if (non_uniform_sampling) {
Expand Down