MaterialX + String path attributes?

   6539   22   4
User Avatar
Member
207 posts
Joined: Nov. 2015
Offline
Oh this is pretty interesting, and I'm grateful for other examples of how to do this! Thank you! The creation of extra materials is not something I'm specifically trying to do, though it's an interesting way to solve this problem.

Where I'm coming from is as someone who used to write custom renderman shaders at a vfx facility a while ago, before RIS and when shaders were written in RSL (I'm not sure how relatable that is, but I'll try to explain it nevertheless). There was this notion of data stamped onto your geometry; if this data had a name that matched a shader parameter, the data would 'override' the shader parameter. Mantra has functionality similar to this.

An example of this: maybe I have a scene with several splashes happening. When I mesh my water sim, I could stamp a point attribute onto the mesh called "foam". Then, in my shader, I could have a parameter called "foam". As long as the two names lined up, I could control the shader parameter by adjusting the data I had on the mesh. I could have several splashes, each of which might have different "foam" data stamped onto it, and I could assign a single shader to all splashes and see variation, without needing to have a separate shader for each splash.

The same idea existed for textures; if I had three spheres, I could stick string data onto each sphere. That string data could point to different texture paths, and if I had a similarly-named shader parameter, I could assign a single shader to all three spheres, and they would render differently because of this string data flowing through to the shader.

Renderman parlance calls this on-geometry data "primvars", and I suppose I've got it in my head that I can create and assign a single shader setup to a bunch of geometry (in my current case: rocks and trees). Each rock and tree is different, and I know which texture files are meant to go with which geometry. I assume that if I provide the path to my texture file on the geometry itself, that I can make a shader setup to 'receive' this data, and voila, I get lots of rock variation with a single shader.

What I find, though, is that this doesn't work with MaterialX. MaterialX can't/won't read string primvars, so this trick I'm used to doing no longer works. After a LOT of pestering forums with questions, @jmack helpfully offered the notion that this is no longer possible because it is not efficient in the USD/Hydra world Karma operates in (at least, this is my current understanding).

So, it seems like there are more modern ways to accomplish this, and Houdini's native awesomeness probably expands this even more. But, I'm having trouble shifting my head gears away from the way I'm used to do this to whatever way I'm meant to be doing it now. The python methodology you're using above makes total sense to me. I have no idea whether manually cloning/binding shaders is "the right way" to do this. Is there even a right way anymore? @jmack's example adjusts properties set on the shading node after the fact. Instinctively, the "parameter override" feature on the Material Assign node seems like the most familiar-to-what-I-used-to-do thing I've seen, but I can't seem to make it work on my own, and I'm so out of my element with this that I'm not sure it's a reasonable tree to be barking up.

Whew. Learning all of this is very hard and complicated!

In any case! Thank you, again, for this example you provide! I enjoy that it's very explicit and easy to understand. I would like to avoid 'noising up' my Materials section of my scene graph (if I have 1000 rocks, the scene graph gets out of hand quickly), but if that's the path I need to go down I will!
User Avatar
Member
273 posts
Joined: Nov. 2013
Offline
Yep yep I get the primvar workflow, but like jsmack said already it won't currently work with materialx. I hope they figure something out b/c primvars driving textures is generally ok for offline renderers and super useful. So in the meantime, other than udims and/or switch nodes, specialized materials is the only thing I can think of. But absolutely it's kind of messy!
Edited by antc - Aug. 8, 2022 10:57:53
User Avatar
Member
207 posts
Joined: Nov. 2015
Offline
Ha, sorry for my verbosity, and thanks for all your help! Messy is better than nothing at all, so for now these ideas are very helpful!
  • Quick Links