load_dict different bsdf #1164
-
Hi, I want to load different bsdf within my custom integrator but am not sure how to do so. Here is my attempt-- bsdf_pink : mi.BSDF = mi.load_dict({
'type': 'twosided',
'bsdf': {
'type': 'diffuse',
'reflectance': {
'type': 'rgb',
'value': [0.8, 0.2, 0.2]
}
}
})
bsdf_mirror : mi.BSDF = mi.load_dict({
'type': 'roughconductor',
'material': 'Al',
'alpha': 0.005
})
dot = dr.dot((itx.p - Point3f(0.4,0.5,0.25)), Vector3f(0.1,0,0.25))
bsdf = dr.select(dot < 1e-2, bsdf_mirror, bsdf_pink) which produces the following error-- Traceback (most recent call last):
File "/home/zw336/IR/bp2/evaluate/finitediff.py", line 130, in <module>
image1 = sdf_integrator.render(scene=scene, sdf=sdf1, sensor=sensor, spp=spp, max_depth=max_depth)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/zw336/IR/bp2/integrators/base.py", line 110, in render
L, mask, motion = self.sample(scene, sdf, sampler, ray, max_depth)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/zw336/IR/bp2/integrators/path.py", line 274, in sample
bsdf = dr.select(dot < 1e-2, bsdf_mirror, bsdf_pink)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/zw336/.conda/envs/diff-sdf/lib/python3.11/site-packages/drjit/router.py", line 1891, in select
m, t, f = _var_promote_select(m, t, f)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/zw336/.conda/envs/diff-sdf/lib/python3.11/site-packages/drjit/router.py", line 172, in _var_promote_select
t12 = base.ReplaceScalar(_builtins.max(vt1, vt2), diff)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/zw336/.conda/envs/diff-sdf/lib/python3.11/site-packages/drjit/router.py", line 213, in _replace_scalar
return getattr(module, name)
^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'drjit.cuda.ad' has no attribute 'Pointer' Basically I want to assign different bsdf to different shapes, but since my shapes are SDFs I cannot specify them in the scene file and have to do this within my custom integrator. Many thanks for any advice on how can I do so! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @zichenwang01, That's an interesting question. If I understand correctly, the ideal solution would be to be able to declare your Python-based SDF shapes as a custom Mitsuba So you second solution is to try to create an array of BSDF pointers, on which you can then do a vcall (emulating the shape -> BSDF assignment). import mitsuba as mi
import drjit as dr
mi.set_variant("cuda_ad_rgb")
bsdf_pink : mi.BSDF = mi.load_dict({
'type': 'twosided',
'bsdf': {
'type': 'diffuse',
'reflectance': {
'type': 'rgb',
'value': [0.8, 0.2, 0.2]
}
}
})
bsdf_mirror : mi.BSDF = mi.load_dict({
'type': 'roughconductor',
'material': 'Al',
'alpha': 0.005
})
p = dr.full(mi.Point3f, 0.1, 100)
dot = dr.dot((p - mi.Point3f(0.4,0.5,0.25)), mi.Vector3f(0.1,0,0.25))
bsdf = dr.select(dot < 1e-2, mi.BSDFPtr(bsdf_mirror), mi.BSDFPtr(bsdf_pink))
ctx = mi.BSDFContext()
si = dr.zeros(mi.SurfaceInteraction3f, 1)
wo = dr.normalize(mi.Vector3f(1.0))
result = bsdf.pdf(ctx, si, wo)
print(result) If you really only have two (or a small number of) BSDFs, a third solution would be to simply evaluate both BSDFs always and |
Beta Was this translation helpful? Give feedback.
Hi @zichenwang01,
That's an interesting question. If I understand correctly, the ideal solution would be to be able to declare your Python-based SDF shapes as a custom Mitsuba
Shape
. But unlike BSDFs, as far as I know, custom Python-based shapes are not possible yet because the corresponding trampoline classes are not present in the bindings.So you second solution is to try to create an array of BSDF pointers, on which you can then do a vcall (emulating the shape -> BSDF assignment).
For sensors, emitters and shapes, I know that you can create such pointer arrays by gathering from e.g.
scene.emitters_dr()
. For BSDFs that you have created yourself in Python, it looks like the following wo…