Skip to content

Commit 75f8a2c

Browse files
oktomusest77
authored andcommitted
Fix regression: crash when using light tree and motion blur (appleseedhq#2659)
1 parent 8fce145 commit 75f8a2c

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

src/appleseed/renderer/kernel/lighting/backwardlightsampler.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,11 @@ void BackwardLightSampler::sample_light_tree(
288288
else
289289
{
290290
assert(light_type == EmittingShapeType);
291-
sample_emitting_shapes(
291+
sample_emitting_shape(
292292
time,
293-
s,
293+
Vector2f(s[1], s[2]),
294+
light_index,
295+
light_prob,
294296
light_sample);
295297
}
296298

src/appleseed/renderer/kernel/lighting/lightsamplerbase.cpp

+21-1
Original file line numberDiff line numberDiff line change
@@ -633,19 +633,39 @@ void LightSamplerBase::store_object_area_in_shadergroups(
633633
}
634634
}
635635

636+
void LightSamplerBase::sample_emitting_shape(
637+
const ShadingRay::Time& time,
638+
const Vector2f& s,
639+
const size_t shape_index,
640+
const float shape_prob,
641+
LightSample& light_sample) const
642+
{
643+
// Fetch the emitting shape.
644+
const EmittingShape& emitting_shape = m_emitting_shapes[shape_index];
645+
646+
// Uniformly sample the surface of the shape.
647+
light_sample.m_light = nullptr;
648+
emitting_shape.sample_uniform(s, shape_prob, light_sample);
649+
650+
assert(light_sample.m_shape);
651+
assert(light_sample.m_probability > 0.0f);
652+
}
653+
636654
void LightSamplerBase::sample_emitting_shapes(
637655
const ShadingRay::Time& time,
638656
const Vector3f& s,
639657
LightSample& light_sample) const
640658
{
641659
assert(m_emitting_shapes_cdf.valid());
642660

661+
// Fetch the emitting shape.
643662
const EmitterCDF::ItemWeightPair result = m_emitting_shapes_cdf.sample(s[0]);
644663
const size_t emitter_index = result.first;
645664
const float emitter_prob = result.second;
665+
const EmittingShape& emitting_shape = m_emitting_shapes[emitter_index];
646666

667+
// Uniformly sample the surface of the shape.
647668
light_sample.m_light = nullptr;
648-
const EmittingShape& emitting_shape = m_emitting_shapes[emitter_index];
649669
emitting_shape.sample_uniform(Vector2f(s[1], s[2]), emitter_prob, light_sample);
650670

651671
assert(light_sample.m_shape);

src/appleseed/renderer/kernel/lighting/lightsamplerbase.h

+8
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,14 @@ class LightSamplerBase
140140
const float object_area,
141141
const MaterialArray& materials);
142142

143+
// Sample a given emitting shape.
144+
void sample_emitting_shape(
145+
const ShadingRay::Time& time,
146+
const foundation::Vector2f& s,
147+
const size_t shape_index,
148+
const float shape_prob,
149+
LightSample& light_sample) const;
150+
143151
// Sample the set of emitting shapes.
144152
void sample_emitting_shapes(
145153
const ShadingRay::Time& time,

0 commit comments

Comments
 (0)