...
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 |
---|
|
/** 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 |
---|
|
/** 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" ); |