Texture map variants

Hello,
I’m trying to figure out how to create a texture map variant across a crowd of characters.
For example I have 100 characters each wearing a hat. The hat is assigned a USDPreviewmaterial with a texture wired into the diffuseColor
The texture path is something like: …/textures/hat.1.tif

say I have 30 different hat maps (i.e. hat.1.tif → hat.30.tif)

I want to perform an ‘over’ in my stage, to assign/vary which character gets which hat colour map.
I can do this semi-manually at the moment, by creating a separate material for each map. and then the over will set the specific material for that character.
But that means 30 individual materials(3 x shader node) per map - which is obviously quite cumbersome over a real shaded character with loads of material parts

is there a way to override the texture map, to use something more traditional in CG like a primvar, to read in / override the map? eg: …/textures/hat.<hat_map>.tif
I tried doing:
over “mtl/usdpreviewmaterial/usduvtexture1” {
asset inputs:file = @/textures/hat2.tif@
}

but that isnt working (I cant target the usduvtexture1 shader)

thanks

For a texture /path/to/texture/hat.1.tif
Set the primvar like this.
asset primvars:txcolor = @/path/to/texture/hat.1.tif@
and then use a UsdPrimvarReader node or some user attribute reader node to fetch the txcolor primvar and plug it to the texture filename.


This way, they all use the same material but the texture can vary per agent.
The name of the primvar txcolor has no importance, you can use whatever you like.
Not all renderers support this workflow. It’s a bit more complicated if you need UDIMs.
This does not work with MaterialX at the moment.