Instancing multiple objects from list of parameter dictionaries #1009
-
Hi! I'm wondering if there is a way to instantiate objects from an array of parameter dictionaries directly in Python. For instance, I can create a single rough plastic BRDF from a dictionary with one roughness value, but I would like to do this for e.g. N different roughness values in parallel without having to loop over my dictionaries. This is essentially what's done under the hood when tracing rays in a rendering loop but I'm looking for a way to achieve this without any scene. My use case is that I want to be able to query some of the BRDF class functions (e.g., Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @joeylitalien ! Without going too much into the technical details, there is an implicit limitation of plugins that their members must be scalar (this is not exactly true, but for the purposes of this discussion we can consider that it is). Basically, a Suggestion 1 To improve the loading time, you could create a custom my_huge_dict = {
'type': 'my_bsdf_holder',
'bsdf1': {
'type': 'principled',
....
},
'bsdf2': {
'type': 'principled',
....
},
.....
} The advantage of this, is that when you call Finally, you need to call all the BSDFs in a vectorized manner, you can see this thread on how to build a Suggestion 2 I can't imagine the first suggestion scaling very well with millions of instances. It would take a significant amount of time for Dr.Jit to record the If you really only need two methods from a specific BSDF plugin, I think it would be fairly easy to copy/re-write those functions in Python and replace the access to the scalar class members by some function argument which is the array of parameters you want to us. This has the following benefits:
|
Beta Was this translation helpful? Give feedback.
Hi @joeylitalien !
Without going too much into the technical details, there is an implicit limitation of plugins that their members must be scalar (this is not exactly true, but for the purposes of this discussion we can consider that it is). Basically, a
BSDF
plugin can't have many roughness values, for example. You therefore need to instantiate one plugin per parameter configuration.Suggestion 1
To improve the loading time, you could create a custom
BSDF
class, which just acts as a holder of the NBSDF
you'd want, so you could declare a single massive dictionary: