Define (Shader)


Description

Defines the shader definition, including all parameters that underlie the controls on the property page. This is where you define the number of parameters, their type, any defaults, value limitations, and so on.

This callback is fired the first time a shader is initialized. Once the definition is intialized, the shader definition is in the system and does not need to be redefined.


Applies To

Custom Shaders


Syntax

public class <plugin-item_name>

{

	public bool Define( Context in_context )

	{

		...

	}

}
CStatus <plugin-item_name>_Define( CRef& in_context ) 

{ 

	... 

}
function <plugin-item_name>_Define( in_context ) 

{ 

	... 

}
def <plugin-item_name>_Define( in_context ):

	...
Function <plugin-item_name>_Define( in_context )

	...

End Function
sub <plugin-item_name>_Define 

{ 

	my $in_context = shift; 

}

<plugin-item-name> is a special string constructed from the plug-in name, the name specified in the call to PluginRegistrar.RegisterShader, and the major and minor version numbers, with any spaces converted to underscores. For example, if you register a shader definition in a plug-in called "MyPlugin" with the shader class name "My Shader", and the version number 1.0, the callback function names start with "MyPlugin_My_Shader_1_0".


Parameters

Parameter Language Type Description
in_context Scripting and C# Context Context.GetAttribute("Definition") returns the ShaderDef.
C++ CRef& Context::GetAttribute("Definition") returns a reference to the ShaderDef.


Context Attributes

Attribute Get/Set Description
Definition Returns or sets a ShaderDef The shader definition to populate/query.
Errors Returns a String or CString The parser can output parse errors.
Warnings Returns a String or CString The parser can output parse warnings.


Example

SICALLBACK UtShaderPlugin_ColorShare_1_0_Define( CRef& in_ctxt  )

{

	XSI::Context ctxt(in_ctxt);

	XSI::ShaderDef shaderDef = ctxt.GetAttribute( L"Definition" );



	// Check if the user attribute is there

	{

		CValue valDune = shaderDef.GetAttributes().GetAttribute( L"{F2EF07FE-1B57-4245-BF08-F5556212BFDF}" );

		assert( !valDune.IsEmpty() );

	}



	// Define PassThrough ports

	definePassThroughPorts( shaderDef, XSI::siColorParameterType );



	// Fill Meta shader section

	{	

		shaderDef.AddType( L"texture" );



		MetaShaderRendererDef rendererDef = shaderDef.AddRendererDef( L"Mental Ray");

		assert( rendererDef.IsValid() );

		rendererDef.PutSymbolName( L"sib_color_passthrough" );

		rendererDef.PutCodePath( L"{LIBS}/sibase.{EXT}" );

		rendererDef.GetRendererOptions().SetAttribute( L"version", CValue((LONG)1) );

	}



	return CStatus::OK;

}





// Helper function

void definePassThroughPorts( ShaderDef& in_ShaderDef, XSI::siShaderParameterType in_eParamType )

{

	XSI::Application app;

	XSI::Factory fact=app.GetFactory();



	XSI::ShaderParamDefOptions optDefault= fact.CreateShaderParamDefOptions();

	optDefault.SetTexturable(true);



	ShaderParamDefOptions opt= fact.CreateShaderParamDefOptions();

	opt.SetTexturable(true);



	// Add input + 8 channels + output

	if( in_eParamType==XSI::siColorParameterType )

	{

		XSI::CValueArray valArray;

		valArray.Add( 0.5f );

		valArray.Add( 0.5f );

		valArray.Add( 0.5f );

		valArray.Add( 1.0f );

		optDefault.SetDefaultValue( valArray );

	}

	

	XSI::ShaderParamDef pdef;

	pdef = in_ShaderDef.GetInputParamDefs().AddParamDef( L"input", in_eParamType, optDefault );

	pdef = in_ShaderDef.GetInputParamDefs().AddParamDef( L"channel1", in_eParamType, opt );

	pdef = in_ShaderDef.GetInputParamDefs().AddParamDef( L"channel2", in_eParamType, opt );

	pdef = in_ShaderDef.GetInputParamDefs().AddParamDef( L"channel3", in_eParamType, opt );

	pdef = in_ShaderDef.GetInputParamDefs().AddParamDef( L"channel4", in_eParamType, opt );

	pdef = in_ShaderDef.GetInputParamDefs().AddParamDef( L"channel5", in_eParamType, opt );

	pdef = in_ShaderDef.GetInputParamDefs().AddParamDef( L"channel6", in_eParamType, opt );

	pdef = in_ShaderDef.GetInputParamDefs().AddParamDef( L"channel7", in_eParamType, opt );

	pdef = in_ShaderDef.GetInputParamDefs().AddParamDef( L"channel8", in_eParamType, opt );

	pdef = in_ShaderDef.GetOutputParamDefs().AddParamDef( L"out_result", in_eParamType );

	

	// Get the ShaderDefs Layouts

	XSI::PPGLayout layoutPPG = in_ShaderDef.GetPPGLayout();

	XSI::PPGLayout layoutRT = in_ShaderDef.GetRenderTreeLayout();



	// Define the PPG Layout.. only input should be visible

	layoutPPG.AddItem( L"name", L"Name" );

	layoutPPG.AddItem( L"input", L"Input" );



	// Define the RT Layout.. input alone, then all the channels in a group

	{

		layoutRT.AddItem( L"input", L"Input" );

		layoutRT.AddGroup( L"Channels", false );

			layoutRT.AddItem( L"channel1", L"Channel 1" );

			layoutRT.AddItem( L"channel2", L"Channel 2" );

			layoutRT.AddItem( L"channel3", L"Channel 3" );

			layoutRT.AddItem( L"channel4", L"Channel 4" );

			layoutRT.AddItem( L"channel5", L"Channel 5" );

			layoutRT.AddItem( L"channel6", L"Channel 6" );

			layoutRT.AddItem( L"channel7", L"Channel 7" );

			layoutRT.AddItem( L"channel8", L"Channel 8" );

		layoutRT.EndGroup();

	}

}


See Also