Website powered by

Convert Polygon based shader assignment to a single shader (Maya/Arnold/Python) (WIP)

Introduction

Usually, Game Assets have shaders assigned on faces/polygons. Arnold has a process to make that into a single shader with the help of custom attribute/user data. I have made a simple python script, which will do everything for us. You can refer to the below link to get basic understanding of how it works.


There are 3 things required for Arnold to read any Attribute inside Maya while creating a new attribute.

  1. mtoa - Prefix for any Attribute for Arnold to understand.
  2. attribute_type - Arnold out of the box supports 3 types of Attributes.
    • constant - To apply anything on the entire Geometry/Shape.
    • uniform - To Apply anything per Face/Polygon.
    • varying - To apply anything per Vertex/Point.
  3. attribute_name - Any Variable/Name we can give to the Attribute.


Any Attribute which we create will be written as follows.

mtoa_constant_diffuse


For any Attribute to store any Data/Value, we have to define its data_type. Different attribute type supports different data types.

  1. constant - Common data types (Integer, Float, Vector, etc.)
  2. uniform - Array
  3. varying - Array


Any attribute can store only a single value of the defined data type. Maya supports common data types, we can easily create mtoa_constant attribute. But since mtoa_uniform and mtoa_varying require per face/vertex values to be stored, we have different data types which are Arrays. An Array can store multiple values in a single attribute.

So for example, let's say we have a default Cube inside Maya, which is made of 6 faces and 8 vertices. So any mtoa_uniform array attribute will store 6 values and mtoa_varying array attribute will store 8 values in a single attribute. Unfortunately there is no easy way of creating array attribute inside Maya, it is only possible to create using MEL/Python. You can refer to below link to get the basic understanding using Python.