@@ -115,24 +115,27 @@ class BlendBSDF final : public BSDF<Float, Spectrum> {
115
115
Mask active) const override {
116
116
MI_MASKED_FUNCTION (ProfilerPhase::BSDFSample, active);
117
117
118
+ BSDFSample3f bs = dr::zeros<BSDFSample3f>();
119
+ Spectrum result (0 .f );
120
+
121
+ Mask sample_all = dr::eq (ctx.component , (uint32_t ) -1 );
122
+
118
123
Float weight = eval_weight (si, active);
119
- if (unlikely (ctx.component != (uint32_t ) -1 )) {
120
- bool sample_first = ctx.component < m_nested_bsdf[0 ]->component_count ();
124
+
125
+ if (dr::any_or<true >(!sample_all)) {
126
+ Mask sample_first = ctx.component < m_nested_bsdf[0 ]->component_count ();
121
127
BSDFContext ctx2 (ctx);
122
- if ( !sample_first)
123
- ctx2. component -= ( uint32_t ) m_nested_bsdf[ 0 ]-> component_count () ;
124
- else
125
- weight = 1 . f - weight;
126
- auto [bs, result] = m_nested_bsdf[sample_first ? 0 : 1 ]->sample (ctx2, si, sample1, sample2, active);
127
- result *= weight ;
128
- return { bs, result } ;
128
+ dr::masked (ctx2. component , !sample_first) -= ( uint32_t ) m_nested_bsdf[ 0 ]-> component_count ();
129
+ dr::masked (weight, sample_first) = 1 . f - weight ;
130
+ auto [bs_, result_] = dr::select (sample_first,
131
+ m_nested_bsdf[ 0 ]-> sample (ctx2, si, sample1, sample2, active),
132
+ m_nested_bsdf[ 1 ]->sample (ctx2, si, sample1, sample2, active) );
133
+ dr::masked (bs, !sample_all) = bs_ ;
134
+ dr::masked (result, !sample_all) = result_ * weight ;
129
135
}
130
136
131
- BSDFSample3f bs = dr::zeros<BSDFSample3f>();
132
- Spectrum result (0 .f );
133
-
134
- Mask m0 = active && sample1 > weight,
135
- m1 = active && sample1 <= weight;
137
+ Mask m0 = active && sample1 > weight && sample_all,
138
+ m1 = active && sample1 <= weight && sample_all;
136
139
137
140
if (dr::any_or<true >(m0)) {
138
141
auto [bs0, result0] = m_nested_bsdf[0 ]->sample (
@@ -155,36 +158,57 @@ class BlendBSDF final : public BSDF<Float, Spectrum> {
155
158
const Vector3f &wo, Mask active) const override {
156
159
MI_MASKED_FUNCTION (ProfilerPhase::BSDFEvaluate, active);
157
160
161
+ Spectrum result (0 .f );
162
+
163
+ Mask sample_all = dr::eq (ctx.component , (uint32_t ) -1 );
158
164
Float weight = eval_weight (si, active);
159
- if (unlikely (ctx.component != (uint32_t ) -1 )) {
160
- bool sample_first = ctx.component < m_nested_bsdf[0 ]->component_count ();
165
+
166
+ if (dr::any_or<true >(!sample_all)) {
167
+ Mask sample_first = ctx.component < m_nested_bsdf[0 ]->component_count ();
161
168
BSDFContext ctx2 (ctx);
162
- if (!sample_first)
163
- ctx2.component -= (uint32_t ) m_nested_bsdf[0 ]->component_count ();
164
- else
165
- weight = 1 .f - weight;
166
- return weight * m_nested_bsdf[sample_first ? 0 : 1 ]->eval (ctx2, si, wo, active);
169
+ dr::masked (ctx2.component , !sample_first) -= (uint32_t ) m_nested_bsdf[0 ]->component_count ();
170
+ dr::masked (weight, sample_first) = 1 .f - weight;
171
+ dr::masked (result, !sample_all) =
172
+ weight * dr::select (sample_first,
173
+ m_nested_bsdf[0 ]->eval (ctx2, si, wo, active),
174
+ m_nested_bsdf[1 ]->eval (ctx2, si, wo, active));
167
175
}
168
176
169
- return m_nested_bsdf[0 ]->eval (ctx, si, wo, active) * (1 - weight) +
170
- m_nested_bsdf[1 ]->eval (ctx, si, wo, active) * weight;
177
+ if (dr::any_or<true >(sample_all)) {
178
+ dr::masked (result, sample_all) =
179
+ m_nested_bsdf[0 ]->eval (ctx, si, wo, active) * (1 - weight) +
180
+ m_nested_bsdf[1 ]->eval (ctx, si, wo, active) * weight;
181
+ }
182
+
183
+ return result;
171
184
}
172
185
173
186
Float pdf (const BSDFContext &ctx, const SurfaceInteraction3f &si,
174
187
const Vector3f &wo, Mask active) const override {
175
188
MI_MASKED_FUNCTION (ProfilerPhase::BSDFEvaluate, active);
176
189
177
- if (unlikely (ctx.component != (uint32_t ) -1 )) {
178
- bool sample_first = ctx.component < m_nested_bsdf[0 ]->component_count ();
190
+ Float result (0 .f );
191
+
192
+ Mask sample_all = dr::eq (ctx.component , (uint32_t ) -1 );
193
+
194
+ if (dr::any_or<true >(!sample_all)) {
195
+ Mask sample_first = ctx.component < m_nested_bsdf[0 ]->component_count ();
179
196
BSDFContext ctx2 (ctx);
180
- if (!sample_first)
181
- ctx2.component -= (uint32_t ) m_nested_bsdf[0 ]->component_count ();
182
- return m_nested_bsdf[sample_first ? 0 : 1 ]->pdf (ctx2, si, wo, active);
197
+ dr::masked (ctx2.component , !sample_first) -= (uint32_t ) m_nested_bsdf[0 ]->component_count ();
198
+ dr::masked (result, !sample_all) =
199
+ dr::select (sample_first,
200
+ m_nested_bsdf[0 ]->pdf (ctx2, si, wo, active),
201
+ m_nested_bsdf[1 ]->pdf (ctx2, si, wo, active));
183
202
}
184
203
185
- Float weight = eval_weight (si, active);
186
- return m_nested_bsdf[0 ]->pdf (ctx, si, wo, active) * (1 - weight) +
187
- m_nested_bsdf[1 ]->pdf (ctx, si, wo, active) * weight;
204
+ if (dr::any_or<true >(sample_all)) {
205
+ Float weight = eval_weight (si, active);
206
+ dr::masked (result, sample_all) =
207
+ m_nested_bsdf[0 ]->pdf (ctx, si, wo, active) * (1 - weight) +
208
+ m_nested_bsdf[1 ]->pdf (ctx, si, wo, active) * weight;
209
+ }
210
+
211
+ return result;
188
212
}
189
213
190
214
std::pair<Spectrum, Float> eval_pdf (const BSDFContext &ctx,
@@ -193,24 +217,33 @@ class BlendBSDF final : public BSDF<Float, Spectrum> {
193
217
Mask active) const override {
194
218
MI_MASKED_FUNCTION (ProfilerPhase::BSDFEvaluate, active);
195
219
220
+ Spectrum val (0 .f );
221
+ Float pdf (0 .f );
222
+
223
+ Mask sample_all = dr::eq (ctx.component , (uint32_t ) -1 );
196
224
Float weight = eval_weight (si, active);
197
- if (unlikely (ctx.component != (uint32_t ) -1 )) {
198
- bool sample_first = ctx.component < m_nested_bsdf[0 ]->component_count ();
199
- BSDFContext ctx2 (ctx);
200
- if (!sample_first)
201
- ctx2.component -= (uint32_t ) m_nested_bsdf[0 ]->component_count ();
202
- else
203
- weight = 1 .f - weight;
204
225
205
- auto [val, pdf] = m_nested_bsdf[sample_first ? 0 : 1 ]->eval_pdf (ctx2, si, wo, active);
206
- return { weight * val, pdf };
226
+ if (dr::any_or<true >(!sample_all)) {
227
+ Mask sample_first = ctx.component < m_nested_bsdf[0 ]->component_count ();
228
+ BSDFContext ctx2 (ctx);
229
+ dr::masked (ctx2.component , !sample_first) -= (uint32_t ) m_nested_bsdf[0 ]->component_count ();
230
+ dr::masked (weight, sample_first) = 1 .f - weight;
231
+ auto [val_, pdf_] =
232
+ dr::select (sample_first,
233
+ m_nested_bsdf[0 ]->eval_pdf (ctx2, si, wo, active),
234
+ m_nested_bsdf[1 ]->eval_pdf (ctx2, si, wo, active));
235
+ dr::masked (val, !sample_all) = weight * val_;
236
+ dr::masked (pdf, !sample_all) = pdf_;
207
237
}
208
238
209
- auto [val_0, pdf_0] = m_nested_bsdf[0 ]->eval_pdf (ctx, si, wo, active);
210
- auto [val_1, pdf_1] = m_nested_bsdf[1 ]->eval_pdf (ctx, si, wo, active);
239
+ if (dr::any_or<true >(sample_all)) {
240
+ auto [val_0, pdf_0] = m_nested_bsdf[0 ]->eval_pdf (ctx, si, wo, active);
241
+ auto [val_1, pdf_1] = m_nested_bsdf[1 ]->eval_pdf (ctx, si, wo, active);
242
+ dr::masked (val, sample_all) = val_0 * (1 - weight) + val_1 * weight;
243
+ dr::masked (pdf, sample_all) = pdf_0 * (1 - weight) + pdf_1 * weight;
244
+ }
211
245
212
- return { val_0 * (1 - weight) + val_1 * weight,
213
- pdf_0 * (1 - weight) + pdf_1 * weight };
246
+ return { val, pdf };
214
247
}
215
248
216
249
MI_INLINE Float eval_weight (const SurfaceInteraction3f &si, const Mask &active) const {
0 commit comments