Versions Compared

Key

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

...

Code Block
languagecpp
themeMidnight
/** We can inline OSL source code directly */
const char *sourcecode = "shader uv() { Ci = emission() * color(u, v, 0); } ";
nsi.Create( "uv", "shader" );
nsi.SetAttribute( "uvshader", NSI::CStringPArg("shadersource", sourcecode) );

/** We can now connect our new shader node into our simple emitter */
nsi.Connect( "uvshader", "Ci", "simplesshader", "Cs" );

Assignment Priorities

Now that we have one mesh instanced twice with the same shader, how to we override the shader of one of the two instances ? It is usual in scene graph APIs to have a hierarchical assignment strategy where the leaf nodes inherit parent attributes. In such scenarios, overriding of attributes is possible only on the child nodes. In our case, the child node has a shader assigned to it already. Thankfully, NSI allows you to perform top-down overrides by specifying priories on connections.  We can connect an attribute node, along with its shader, on the instance transform node.

To be continued ...

Code Block
languagecpp
themeMidnight
/**
	Create another simple shader node using the standard OSL "emitter" shader.
	User default shader prameters.
*/
nsi.Create( "simpleshader2", "shader" );
nsi.SetAttribute( "simpleshader",
	NSI::CStringPArg("shaderfilename", "emitter") );

const char *k_attributes_override = "attribute override";
nsi.Create( k_attributes_override, "attribute" );

nsi.Connect( k_simpler_shader2, k_attributes_override );

Multi-Camera output, in One Render.

...