Texture from attribute

   5415   8   1
User Avatar
Member
79 posts
Joined: 2月 2008
Offline
I have an object that has multiple meshes, each with a custom string attribute “texture_filepath” that contains a path to a texture to display in the viewport. I'm trying to use one main principle shader that would look up that primitive string attribute and apply the proper texture to each primitive.

I've been unsuccessful in my attempt to do that. I've tried using a Parameter node to look up the attribute and plug that into the basecolor_texture port, but that's not working. I doubled checked the attributes to make sure it points to the right textures and if I enter the path manually in the Base Color Texture parameter, it works, so my data is right, it just ain't passing through a Parameter node. I could create a materiel per texture and link a different material per primitive, but that just creates a ton of materials… I would much rather have one material that looks up the relative texture per primitive. How can I do something like that?
User Avatar
Member
8652 posts
Joined: 7月 2007
Offline
Parameter VOP or Bind VOP should work assuming your path attribute is primitive string attribute (can be also detail if it's not varying)

you can even just use plain Principled Shader and name your attribute s@basecolor_texture which will automatically override that map since internally it's just Parameter VOP as well
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
306 posts
Joined:
Online
The material SOP can also create material overrides for shader parameters if your attribute has a local variable associated with it.
Edited by jparker - 2020年2月3日 18:29:45
User Avatar
Member
79 posts
Joined: 2月 2008
Offline
tamte
Parameter VOP or Bind VOP should work assuming your path attribute is primitive string attribute (can be also detail if it's not varying)

you can even just use plain Principled Shader and name your attribute s@basecolor_texture which will automatically override that map since internally it's just Parameter VOP as well


That's what I'm trying, but it's not working. I created a Principled Shader and named it proxy. I assign these primitive attributes on my object with a wrangle :

s@basecolor_texture = ‘F:/tests/tex/proxy/meshA_midres_proxy.jpg’;
s@shop_materialpath = “/mat/proxy”;

I tried with the Princippled Shader and nothing plugged into it… it doesn't work.
I tried plugging a “bind” to the basecolor_texture port and setting name to basecolor_texture as Type string… it doesn't work.
I tried plugging a “Parameter” to the basecolor_texture port and setting name to basecolor_texture as Type string… it doesn't work.

The only thing that works is when I write the full texture path directly inside the Principle Shader or put an expression on it… but that means I can only assign one texture per shader. I don't understand why it's not working.
User Avatar
Member
79 posts
Joined: 2月 2008
Offline
jparker
The material SOP can also create material overrides for shader parameters if your attribute has a local variable associated with it.

That one works. I guess I can create the attributes material_override in VEX to assign the proper texture… Thanks for that.
User Avatar
Member
7870 posts
Joined: 9月 2011
Offline
MathieuLeclaire
That's what I'm trying, but it's not working. I created a Principled Shader and named it proxy. I assign these primitive attributes on my object with a wrangle :

s@basecolor_texture = ‘F:/tests/tex/proxy/meshA_midres_proxy.jpg’;
s@shop_materialpath = “/mat/proxy”;

There's many reasons it won't pick up on the principled shader. Some have to do with the way nested shader calls work, the other with how packed primitives pass attributes to materials.

Are you applying the attribute to a packed primitive by chance? If so then you cannot use a bind/parameter in the shader to bind the attribute value. A renderstate would need to be used with “packed:basecolor_texture” as the property name.

If not, then perhaps there is an issue with the material topology preventing the attribute from binding. Are there any nodes plugged into the principled shader? If so then you may need to promote the pin for the texture path.
User Avatar
Member
81 posts
Joined: 2月 2014
Offline
The material SOP can also create material overrides for shader parameters if your attribute has a local variable associated with it.

I am struggeling with that. I have made a prim attribute with the correct texture paths per primitive. What would bethe correct syntax for the material override in the material SOP?

Attachments:
Schermafbeelding 2020-10-23 114835.png (97.2 KB)

User Avatar
Member
7870 posts
Joined: 9月 2011
Offline
mackerBaehr
The material SOP can also create material overrides for shader parameters if your attribute has a local variable associated with it.

I am struggeling with that. I have made a prim attribute with the correct texture paths per primitive. What would bethe correct syntax for the material override in the material SOP?

When using an attribute that matches the name of the parameter in the shader, material overrides are not required–the attributes will bind automatically.
User Avatar
Member
81 posts
Joined: 2月 2014
Offline
Thanks, Jsmack, indeed that works. To view it did actually do that, I had to render with Mantra, while expecting earlier it would be visible already through openGL. It all makes sense now.
  • Quick Links