Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Shaders are created as any other nodes using the NSICreate API call. They are not assigned directly on geometry but through an intermediate attributes nodes. Having an extra indirection allows for more flexible export as we will see in the following chapters.

Code Block
languagecpp
themeMidnight
/** Create a simple shader node using the standard OSL "emissive" shader */
nsi.Create( "simpleshader", "shader" );
nsi.SetAttribute( "simpleshader", NSI::CStringPArg("shaderfilename", "emissiveemitter") );

/** Create an attributes nodes and connect our shader to it */
nsi.Create( "attr", "attributes" );
nsi.Connect( "simpleshader", "", "attr", "surfaceshader" );

/* Connecting the attributes node to the mesh assign completes the assignment */
nsi.Connect( "attr", "", "simple mesh", "geometryattributes" );

Creating shading networks uses the same NSIConnect calls as for scene description.

Code Block
languagecpp
themeMidnight
/** We can inline OSL source code directly */
const char *st = "shader st() { Ci = color(s, t, 0); } ";
nsi.Create( "st", "shader" );
nsi.SetAttribute( "stshader", NSI::CStringPArg("shadersource", "st") );
nsi.Connect( "stshader", "Ci", "simplesshader", "Cs" );