Skip to content

Commit c991c70

Browse files
Addressed Merlin's comments
1 parent 8be76ca commit c991c70

31 files changed

+151
-312
lines changed

include/mitsuba/core/field.h

-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ struct field<DeviceType, HostType,
116116
public:
117117
void traverse_1_cb_ro(void *payload,
118118
drjit::detail::traverse_callback_ro fn) const {
119-
120119
drjit ::traverse_1_fn_ro(m_value, payload, fn);
121120
}
122121
void traverse_1_cb_rw(void *payload,

include/mitsuba/core/fwd.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -368,15 +368,15 @@ extern "C" {
368368
})
369369
#endif
370370

371-
#define MI_DECLARE_TRAVERSE_CB() \
371+
#define MI_DECLARE_TRAVERSE_CB() \
372372
public: \
373373
void traverse_1_cb_ro(void *payload, \
374374
drjit::detail::traverse_callback_ro fn) \
375375
const override; \
376376
void traverse_1_cb_rw( \
377377
void *payload, drjit::detail::traverse_callback_rw fn) override;
378378

379-
#define MI_IMPLEMENT_TRAVERSE_CB(Type, Base, ...) \
379+
#define MI_IMPLEMENT_TRAVERSE_CB(Type, Base, ...) \
380380
MI_VARIANT \
381381
void Type<Float, Spectrum>::traverse_1_cb_ro( \
382382
void *payload, drjit::detail::traverse_callback_ro fn) const { \

include/mitsuba/render/scene.h

+12
Original file line numberDiff line numberDiff line change
@@ -637,8 +637,20 @@ class MI_EXPORT_LIB Scene : public Object {
637637

638638
bool m_shapes_grad_enabled;
639639

640+
/**
641+
* When the scene is defined on the CPU, traversal of the acceleration
642+
* structure has to be handled separately. These functions are defined
643+
* either for the Embree or native version of the scene, and handle its
644+
* traversal.
645+
*/
640646
void traverse_1_cb_ro_cpu(void *payload,
641647
drjit::detail::traverse_callback_ro fn) const;
648+
/**
649+
* When the scene is defined on the CPU, traversal of the acceleration
650+
* structure has to be handled separately. These functions are defined
651+
* either for the Embree or native version of the scene, and handle its
652+
* traversal.
653+
*/
642654
void traverse_1_cb_rw_cpu(void *payload,
643655
drjit::detail::traverse_callback_rw fn);
644656

src/bsdfs/bumpmap.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ class BumpMap final : public BSDF<Float, Spectrum> {
8383
MI_IMPORT_BASE(BSDF, m_flags, m_components)
8484
MI_IMPORT_TYPES(Texture)
8585

86-
DR_TRAVERSE_CB(Base, m_nested_texture, m_nested_bsdf);
87-
8886
BumpMap(const Properties &props) : Base(props) {
8987
for (auto &[name, obj] : props.objects(false)) {
9088
auto bsdf = dynamic_cast<Base *>(obj.get());
@@ -242,6 +240,8 @@ class BumpMap final : public BSDF<Float, Spectrum> {
242240
ScalarFloat m_scale;
243241
ref<Texture> m_nested_texture;
244242
ref<Base> m_nested_bsdf;
243+
244+
DR_TRAVERSE_CB(Base, m_nested_texture, m_nested_bsdf);
245245
};
246246

247247
MI_IMPLEMENT_CLASS_VARIANT(BumpMap, BSDF)

src/bsdfs/circular.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ class CircularPolarizer final : public BSDF<Float, Spectrum> {
6161
MI_IMPORT_BASE(BSDF, m_flags, m_components)
6262
MI_IMPORT_TYPES(Texture)
6363

64-
DR_TRAVERSE_CB(Base, m_transmittance);
65-
6664
CircularPolarizer(const Properties &props) : Base(props) {
6765
m_transmittance = props.texture<Texture>("transmittance", 1.f);
6866
m_left_handed = props.get<bool>("left_handed", false);
@@ -168,6 +166,8 @@ class CircularPolarizer final : public BSDF<Float, Spectrum> {
168166
private:
169167
ref<Texture> m_transmittance;
170168
bool m_left_handed;
169+
170+
DR_TRAVERSE_CB(Base, m_transmittance);
171171
};
172172

173173
MI_IMPLEMENT_CLASS_VARIANT(CircularPolarizer, BSDF)

src/bsdfs/dielectric.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,7 @@ class SmoothDielectric final : public BSDF<Float, Spectrum> {
397397
ref<Texture> m_specular_reflectance;
398398
ref<Texture> m_specular_transmittance;
399399

400-
DR_TRAVERSE_CB(Base, m_eta, m_specular_reflectance,
401-
m_specular_transmittance);
400+
DR_TRAVERSE_CB(Base, m_eta, m_specular_reflectance,m_specular_transmittance);
402401
};
403402

404403
MI_IMPLEMENT_CLASS_VARIANT(SmoothDielectric, BSDF)

src/bsdfs/hair.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,7 @@ class Hair final : public BSDF<Float, Spectrum> {
791791
m_v[0], m_v[1], m_v[2], m_v[3], m_s, m_sin_2k_alpha[0],
792792
m_sin_2k_alpha[1], m_sin_2k_alpha[2], m_cos_2k_alpha[0],
793793
m_cos_2k_alpha[1], m_cos_2k_alpha[2])
794+
static_assert(P_MAX == 3, "Please update the DR_TRAVERSE_CB() macro when changing P_MAX.");
794795
};
795796

796797
MI_IMPLEMENT_CLASS_VARIANT(Hair, BSDF)

src/bsdfs/measured.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ class Measured final : public BSDF<Float, Spectrum> {
7474
MI_IMPORT_BASE(BSDF, m_flags, m_components)
7575
MI_IMPORT_TYPES()
7676

77-
DR_TRAVERSE_CB(Base, m_ndf, m_sigma, m_vndf, m_luminance, m_spectra);
78-
7977
using Warp2D0 = Marginal2D<Float, 0, true>;
8078
using Warp2D2 = Marginal2D<Float, 2, true>;
8179
using Warp2D3 = Marginal2D<Float, 3, true>;
@@ -497,6 +495,8 @@ class Measured final : public BSDF<Float, Spectrum> {
497495
bool m_isotropic;
498496
bool m_jacobian;
499497
int m_reduction;
498+
499+
DR_TRAVERSE_CB(Base, m_ndf, m_sigma, m_vndf, m_luminance, m_spectra);
500500
};
501501

502502
MI_IMPLEMENT_CLASS_VARIANT(Measured, BSDF)

src/bsdfs/measured_polarized.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@ class MeasuredPolarized final : public BSDF<Float, Spectrum> {
108108
MI_IMPORT_BASE(BSDF, m_flags, m_components)
109109
MI_IMPORT_TYPES(Texture, MicrofacetDistribution)
110110

111-
DR_TRAVERSE_CB(Base, m_interpolator);
112-
113111
using Interpolator = Marginal2D<Float, 4, true>;
114112

115113
MeasuredPolarized(const Properties &props) : Base(props) {
@@ -400,6 +398,8 @@ class MeasuredPolarized final : public BSDF<Float, Spectrum> {
400398
ScalarFloat m_wavelength;
401399
ScalarFloat m_alpha_sample;
402400
Interpolator m_interpolator;
401+
402+
DR_TRAVERSE_CB(Base, m_interpolator);
403403
};
404404

405405
MI_IMPLEMENT_CLASS_VARIANT(MeasuredPolarized, BSDF)

src/bsdfs/normalmap.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ class NormalMap final : public BSDF<Float, Spectrum> {
8181
MI_IMPORT_BASE(BSDF, m_flags, m_components)
8282
MI_IMPORT_TYPES(Texture)
8383

84-
DR_TRAVERSE_CB(Base, m_nested_bsdf, m_normalmap);
85-
8684
NormalMap(const Properties &props) : Base(props) {
8785
for (auto &[name, obj] : props.objects(false)) {
8886
auto bsdf = dynamic_cast<Base *>(obj.get());
@@ -230,6 +228,8 @@ class NormalMap final : public BSDF<Float, Spectrum> {
230228
protected:
231229
ref<Base> m_nested_bsdf;
232230
ref<Texture> m_normalmap;
231+
232+
DR_TRAVERSE_CB(Base, m_nested_bsdf, m_normalmap);
233233
};
234234

235235
MI_IMPLEMENT_CLASS_VARIANT(NormalMap, BSDF)

src/bsdfs/plastic.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,7 @@ class SmoothPlastic final : public BSDF<Float, Spectrum> {
392392
bool m_nonlinear;
393393

394394
DR_TRAVERSE_CB(Base, m_diffuse_reflectance, m_specular_reflectance,
395-
m_specular_sampling_weight);
396-
395+
m_specular_sampling_weight);
397396
};
398397

399398
MI_IMPLEMENT_CLASS_VARIANT(SmoothPlastic, BSDF)

src/bsdfs/polarizer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ class LinearPolarizer final : public BSDF<Float, Spectrum> {
8181
MI_IMPORT_BASE(BSDF, m_flags, m_components)
8282
MI_IMPORT_TYPES(Texture)
8383

84-
DR_TRAVERSE_CB(Base, m_theta, m_transmittance);
85-
8684
LinearPolarizer(const Properties &props) : Base(props) {
8785
m_theta = props.texture<Texture>("theta", 0.f);
8886
m_transmittance = props.texture<Texture>("transmittance", 1.f);
@@ -220,6 +218,8 @@ class LinearPolarizer final : public BSDF<Float, Spectrum> {
220218
bool m_polarizing;
221219
ref<Texture> m_theta;
222220
ref<Texture> m_transmittance;
221+
222+
DR_TRAVERSE_CB(Base, m_theta, m_transmittance);
223223
};
224224

225225
MI_IMPLEMENT_CLASS_VARIANT(LinearPolarizer, BSDF)

src/bsdfs/pplastic.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,6 @@ class PolarizedPlastic final : public BSDF<Float, Spectrum> {
149149
MI_IMPORT_BASE(BSDF, m_flags, m_components)
150150
MI_IMPORT_TYPES(Texture, MicrofacetDistribution)
151151

152-
DR_TRAVERSE_CB(Base, m_diffuse_reflectance, m_specular_reflectance,
153-
m_alpha_u, m_alpha_v, m_eta, m_specular_sampling_weight);
154-
155152
PolarizedPlastic(const Properties &props) : Base(props) {
156153
m_diffuse_reflectance = props.texture<Texture>("diffuse_reflectance", .5f);
157154

@@ -473,6 +470,9 @@ class PolarizedPlastic final : public BSDF<Float, Spectrum> {
473470

474471
/// Sampling weight for specular component
475472
Float m_specular_sampling_weight;
473+
474+
DR_TRAVERSE_CB(Base, m_diffuse_reflectance, m_specular_reflectance,
475+
m_alpha_u, m_alpha_v, m_eta, m_specular_sampling_weight);
476476
};
477477

478478
MI_IMPLEMENT_CLASS_VARIANT(PolarizedPlastic, BSDF)

src/bsdfs/principled.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,6 @@ class Principled final : public BSDF<Float, Spectrum> {
185185
MI_IMPORT_BASE(BSDF, m_flags, m_components)
186186
MI_IMPORT_TYPES(Texture, MicrofacetDistribution)
187187

188-
DR_TRAVERSE_CB(Base, m_base_color, m_roughness, m_anisotropic, m_sheen,
189-
m_sheen_tint, m_spec_trans, m_flatness, m_spec_tint,
190-
m_clearcoat, m_clearcoat_gloss, m_metallic, m_eta,
191-
m_specular);
192-
193188
using GTR1 = GTR1Isotropic<Float, Spectrum>;
194189

195190
Principled(const Properties &props) : Base(props) {
@@ -900,6 +895,11 @@ class Principled final : public BSDF<Float, Spectrum> {
900895
bool m_has_sheen_tint;
901896
bool m_has_anisotropic;
902897
bool m_has_flatness;
898+
899+
DR_TRAVERSE_CB(Base, m_base_color, m_roughness, m_anisotropic, m_sheen,
900+
m_sheen_tint, m_spec_trans, m_flatness, m_spec_tint,
901+
m_clearcoat, m_clearcoat_gloss, m_metallic, m_eta,
902+
m_specular);
903903
};
904904

905905
MI_IMPLEMENT_CLASS_VARIANT(Principled, BSDF)

src/bsdfs/principledthin.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,6 @@ class PrincipledThin final : public BSDF<Float, Spectrum> {
159159
MI_IMPORT_BASE(BSDF, m_flags, m_components)
160160
MI_IMPORT_TYPES(Texture, MicrofacetDistribution)
161161

162-
DR_TRAVERSE_CB(Base, m_base_color, m_roughness, m_anisotropic, m_sheen,
163-
m_sheen_tint, m_spec_trans, m_flatness, m_spec_tint,
164-
m_diff_trans, m_eta_thin);
165-
166162
PrincipledThin(const Properties &props) : Base(props) {
167163

168164
m_base_color = props.texture<Texture>("base_color", 0.5f);
@@ -757,6 +753,10 @@ class PrincipledThin final : public BSDF<Float, Spectrum> {
757753
bool m_has_sheen_tint;
758754
bool m_has_anisotropic;
759755
bool m_has_flatness;
756+
757+
DR_TRAVERSE_CB(Base, m_base_color, m_roughness, m_anisotropic, m_sheen,
758+
m_sheen_tint, m_spec_trans, m_flatness, m_spec_tint,
759+
m_diff_trans, m_eta_thin);
760760
};
761761

762762
MI_IMPLEMENT_CLASS_VARIANT(PrincipledThin, BSDF)

src/bsdfs/retarder.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ class LinearRetarder final : public BSDF<Float, Spectrum> {
7272
MI_IMPORT_BASE(BSDF, m_flags, m_components)
7373
MI_IMPORT_TYPES(Texture)
7474

75-
DR_TRAVERSE_CB(Base, m_theta, m_delta, m_transmittance);
76-
7775
LinearRetarder(const Properties &props) : Base(props) {
7876
m_theta = props.texture<Texture>("theta", 0.f);
7977
// As default, instantiate as a quarter-wave plate
@@ -208,6 +206,8 @@ class LinearRetarder final : public BSDF<Float, Spectrum> {
208206
ref<Texture> m_theta;
209207
ref<Texture> m_delta;
210208
ref<Texture> m_transmittance;
209+
210+
DR_TRAVERSE_CB(Base, m_theta, m_delta, m_transmittance);
211211
};
212212

213213
MI_IMPLEMENT_CLASS_VARIANT(LinearRetarder, BSDF)

src/bsdfs/thindielectric.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ class ThinDielectric final : public BSDF<Float, Spectrum> {
231231
ref<Texture> m_specular_transmittance;
232232
ref<Texture> m_specular_reflectance;
233233

234-
DR_TRAVERSE_CB(Base, m_specular_reflectance, m_specular_transmittance);
234+
DR_TRAVERSE_CB(Base, m_eta, m_specular_reflectance,
235+
m_specular_transmittance);
235236
};
236237

237238
MI_IMPLEMENT_CLASS_VARIANT(ThinDielectric, BSDF)

src/bsdfs/twosided.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ class TwoSidedBRDF final : public BSDF<Float, Spectrum> {
376376
MI_DECLARE_CLASS()
377377
protected:
378378
ref<Base> m_brdf[2];
379-
379+
380380
DR_TRAVERSE_CB(Base, m_brdf[0], m_brdf[1]);
381381
};
382382

src/core/python/object.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include <mitsuba/python/python.h>
55
#include <nanobind/stl/string.h>
66
#include <nanobind/stl/vector.h>
7-
#include <drjit/python.h>
87

98
extern nb::object cast_object(Object *o);
109

@@ -41,7 +40,7 @@ MI_PY_EXPORT(Object) {
4140
return cast_object(pmgr.create_object(props, class_));
4241
}, D(PluginManager, create_object));
4342

44-
auto obj = nb::class_<Object, drjit::TraversableBase>(
43+
nb::class_<Object, drjit::TraversableBase>(
4544
m, "Object",
4645
nb::intrusive_ptr<Object>(
4746
[](Object *o, PyObject *po) noexcept { o->set_self_py(po); }),

src/media/heterogeneous.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,6 @@ class HeterogeneousMedium final : public Medium<Float, Spectrum> {
214214
private:
215215
ref<Volume> m_sigmat, m_albedo;
216216
ScalarFloat m_scale;
217-
218217
Float m_max_density;
219218

220219
DR_TRAVERSE_CB(Base, m_sigmat, m_albedo, m_max_density);

src/python/python/ad/integrators/prb.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def sample(self,
103103
max_iterations=self.max_depth,
104104
label="Path Replay Backpropagation (%s)" % mode.name,
105105
# include=[ sampler, ray, depth, L, δL, β, active ],
106-
exclude=[ scene, ],
106+
exclude=[scene,],
107107
):
108108
active_next = mi.Bool(active)
109109

src/python/python/ad/integrators/prb_basic.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def sample(self,
8181

8282
while dr.hint(active,
8383
max_iterations=self.max_depth,
84-
label="Path Replay Backpropagation (%s)" % mode.name,
84+
label="Path Replay Backpropagation (%s)" % mode.name,
8585
exclude = [scene]):
8686
active_next = mi.Bool(active)
8787

@@ -163,7 +163,7 @@ def sample(self,
163163

164164
return (
165165
L if primal else δL, # Radiance/differential radiance
166-
depth != 0, # Ray validity flag for alpha blending
166+
depth != 0, # Ray validity flag for alpha blending
167167
[], # Empty typle of AOVs
168168
L # State the for differential phase
169169
)

src/python/python/ad/integrators/prb_projective.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,14 @@ def sample(self,
172172
# Projective seed ray information
173173
cnt_seed = mi.UInt32(0) # Number of valid seed rays encountered
174174
ray_seed = dr.zeros(mi.Ray3f) # Seed ray to be projected
175-
active_seed = mi.Bool(active) # Active SIMD lanes
176-
177-
while dr.hint(active,
178-
max_iterations=self.max_depth,
179-
label="PRB Projective (%s)" % mode.name,
180-
exclude = [scene],
181-
):
175+
active_seed = mi.Bool(active) # Active SIMD lanes
176+
177+
while dr.hint(
178+
active,
179+
max_iterations=self.max_depth,
180+
label="PRB Projective (%s)" % mode.name,
181+
exclude=[scene],
182+
):
182183
active_next = mi.Bool(active)
183184

184185
# Compute a surface interaction that tracks derivatives arising

src/python/python/ad/optimizers.py

+3
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ class SGD(Optimizer):
133133
"state": dict,
134134
"variables": dict,
135135
"lr_default_v": None,
136+
"lr_v": dict,
137+
"lr": dict,
136138
}
137139

138140
def __init__(self, lr, momentum=0, mask_updates=False, params: dict = None):
@@ -242,6 +244,7 @@ class Adam(Optimizer):
242244
"variables": dict,
243245
"lr_default_v": None,
244246
"lr_v": dict,
247+
"lr": dict,
245248
"t": dict,
246249
}
247250
def __init__(self, lr, beta_1=0.9, beta_2=0.999, epsilon=1e-8,

src/render/python/interaction_v.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include <mitsuba/render/scene.h>
77
#include <mitsuba/python/python.h>
88
#include <nanobind/stl/string.h>
9-
#include <drjit/python.h>
109

1110
MI_PY_EXPORT(Interaction) {
1211
MI_PY_IMPORT_TYPES()

0 commit comments

Comments
 (0)