# Querying Attribute Variants in Shading Networks

One special characteristic of Attribute Variants is their ability to be queried from shading networks: any Attribute Variant which has been named with the prefix keyword primvars: can be queried in a shading network via your renderer of choice primvar reader utilities.

Note

Attribute variants are USD attributes so, in case you have written custom USD primvars attributes, you can query them in the same way as described below.

Let's make an example: imagine you have a character's jacket that needs a "dirty" variation. Using one of the authoring workflows for Attribute Variants described in the Variants documentation you can create:

  • variant set name: primvars:jacketLook
    • variant name: clean
      • type: int
      • value: 0
    • variant name: dirty
      • type: int
      • value: and 1

Then, once you have written your variants to a USD file, whether asset or override, read them back in your Multiverse Compound, then open Maya Hypershade or Node Editor and create a network to read and use your primvars.

The following is a generic example that does not mention specifically a particular renderer, it will work with any renderer supported by Multiverse since every renderer has its own relative tools to achieve this:

  1. Create a material & shading group for the jacket: jacketMT --> jacketSG

  2. Assign this material: you can assign it to the whole Compound with the classic Maya shape->material assignment, or in MEOW as a material override to the desired item(s). As long as there are primvars to query encapsulated in the compound they will be queried for the items that have them specified.

  3. Connect a layered texture / multi blend node your material color, and set two layers with different file textures.

  4. Create the desired conditional logic in your shading network, for this you have many nodes at your disposal, Maya condition, choice, math nodes and your renderer may offer others nodes too. For example a texture in your layered texture / multi blend node can be enabled/disabled according from the value returned by a primitive variable reader node.

    The following tables shows each renderer primvar reader nodes and the supported types:

    Renderer Node Types
    3Delight dlPrimitiveAttribute Float, Color, Point, UV, Integer
    Arnold aiUserData* Color, Float Int, String
    Redshift rsUserData* Color, Integer, Scalar, Vector
    Renderman pxrPrimVar Normal, Vector, Color, Point, Float, Float2
    VRay vrayUser* Color, Integer, Scalar
  5. Render, you will see that according to the value of your primitive variable a different texture will be used for rendering, according to the logic you have setup.

There are many other possibilities, you could query different types of primvars and use them to switch shading parameter directly, or as in the example before to load a different texture that represent a particular state of your asset. The possibilities are unlimited!

Also, don't forget that primvars are attributes and attributes can be animated before authoring, this means that the value of a primvar can change over time and you can leverage this information to take decisions in your shading network.

Technically speaking you can setup the same logic, albeit without Variants, by writing USD attributes, see the relative documentation about Writing Custom Attributes to USD.

Last Updated: 10/7/2020, 1:22:18 PM