Share

Creating a Shader Loader - Arnold for Maya

See Multiple Nodes in a Library for an example of how to create two shaders in a single shared library, using a shader loader.

loader.cpp

#include <ai.h>
#include <cstring>

extern const AtNodeMethods* Shader1Mtd;
extern const AtNodeMethods* Shader2Mtd;

enum{
   SHADER_1 = 0,
   SHADER_2
};

node_loader
{
   switch (i)
   {
   case SHADER_1:
      node->methods = Shader1Mtd;
      node->output_type = AI_TYPE_RGB;
      node->name = "shader1";
      node->node_type = AI_NODE_SHADER;
      break;

   case SHADER_2:
      node->methods = Shader2Mtd;
      node->output_type = AI_TYPE_RGB;
      node->name = "shader2";
      node->node_type = AI_NODE_SHADER;
      break;

   default:
      return false;
   }

   strcpy(node->version, AI_VERSION);
   return true;
} 

Add the metadata file

To make MtoA recognize metadata information for the created shaders, you can create a metadata file for all the shaders.

A simple metadata file for these shaders could be like this:

simple_shaders.mtd

# shader1                     0x00070001
# shader2                     0x00070002

[node shader1]
    maya.name                 STRING     "aiShader1"
    maya.id                 INT     0x00070001
    maya.classification     STRING     "shader/surface"
    maya.output_name         STRING     "outColor"
    maya.output_shortname     STRING     "out"
    [attr color1]
        maya.name                 STRING     "color"

[node shader2]
    maya.name                 STRING     "aiShader2"
    maya.id                 INT     0x00070002
    maya.classification     STRING     "shader/surface"
    maya.output_name         STRING     "outColor"
    maya.output_shortname     STRING     "out"
    [attr color2]
        maya.name                 STRING     "color" 

Then copy this file to the same folder where the compiled shaders are: MTOA_PATH\shaders\

Remember that the meta?le name should be the same as the compiled shader; if for example, your loader is called simple_shaders.dll, the metadata file must be simple_shaders.mtd.

Was this information helpful?