Object Hierarchy | Related C++ Class: Shader
Inheritance
SIObject
ProjectItem
Shader
Introduced
1.5
Description
The Shader object represents a node in the render tree of an object. The initial Shader of a render tree can be created with SceneItem.AddMaterial and additional shaders can be created and connected together with Parameter.ConnectFromPreset and Parameter.Connect.
A Shader is a type of DataSource.
Methods
|
|
Properties
|
|
|
|
Examples
1. VBScript Example
'
' This example shows how to access the shader on an object
'
NewScene , false
dim root, grid
set root = ActiveProject.ActiveScene.Root
set grid = root.AddGeometry("Grid", "MeshSurface")
'Create a Lambert shader
grid.AddMaterial "Lambert"
'Access the new Shader
LogMessage "Shader name:" & grid.Material.Shaders(0).Name
2. VBScript Example
'
' This example shows how to recursively search a render tree
'
' It shows how to access Shaders via the Source property of a Parameter
' It also shows how to use XSICollection object to accumulate a list of objects
'
' Note: to find ImageClips the Material.ImageClips property can be used rather
' a recursive scan like this. And the FindObjects command can be used to find
' all shaders of a particular type.
'
set oObj = BuildDemoScene
FindShaders( oObj )
'This is the actual code doing the searching
sub FindShaders( in_oObj )
dim oShaderList, oImageClipList
set oShaderList = CreateObject( "XSI.Collection" )
oShaderList.Unique = true
'We expect the input object to be a "SceneItem" object
set oMat = in_oObj.Material
'Although not actually a shader, we start searching
'for shaders from the parameters of the material
SearchShader oMat, oShaderList
logmessage "SUMMARY: Searched " & oShaderList.Count & _
" shaders"
if ( oShaderList.Count > 0 ) then
logmessage "SHADERS SEARCHED:"
for each o in oShaderList
logmessage o.Fullname
next
end if
end sub
'Recursively search any connected shaders
'Each shader is visited only once
sub SearchShader( in_oShader, io_oVisitedShaderList)
for each oParam in in_oShader.Parameters
if typename( oParam.Source ) = "Shader" then
if ( NOT IsShaderInList( oParam.Source, io_oVisitedShaderList ) ) then
io_oVisitedShaderList.Add( oParam.Source )
'Recursively search this shader
SearchShader oParam.Source, io_oVisitedShaderList
end if
end if
next
end sub
'Determines if a shader is already in a XSI Collection
function IsShaderInList( oShader, io_oVisitedShaderList )
for each o in io_oVisitedShaderList
if ( o.FullName = oShader.FullName ) then
logmessage "Skipping " & oShader.FullName
IsShaderInList = true
exit function
end if
next
IsShaderInList = false
end function
' Create a little sample render tree
' It has no interesting visual appearance but is a render tree with
' various shaders and two images so that we can demonstrate the
' FindImageClips routine
'
' Return value is the X3DObject
function BuildDemoScene
NewScene ,false
ImageFile1 = XSIUtils.BuildPath( Application.InstallationPath(siFactoryPath), _
"Data", _
"XSI_SAMPLES",_
"Pictures",_
"jaiqua_face.jpg" )
ImageFile2 = XSIUtils.BuildPath( Application.InstallationPath(siFactoryPath), _
"Data", _
"XSI_SAMPLES",_
"Pictures",_
"ehair_08.jpg" )
newscene , false
set oObj = ActiveSceneRoot.AddGeometry( "Sphere", "MeshSurface" )
oObj.AddMaterial "Phong"
dim oPhongShader, oAmbientParam, oDiffuseParam, oShinyParam
set oPhongShader = oObj.Material.Shaders(0)
set oAmbientParam = oPhongShader.Parameters( "ambient" )
set oDiffuseParam = oPhongShader.Parameters( "diffuse" )
set oShinyParam= oPhongShader.Parameters( "shiny" )
dim oImageClip1, oImageClip2
SICreateImageClip ImageFile1, ,oImageClip1
SICreateImageClip ImageFile2, ,oImageClip2
dim oImageNode1,oImageNode2
set oImageNode1 = oAmbientParam.connectfrompreset("Image", siTextureShaderFamily)
oDiffuseParam.Connect( oImageNode1 )
oImageNode1.Parameters( "tex" ).Connect( oImageClip1 )
set oImageNode2 = oShinyParam.connectfrompreset("Image", siTextureShaderFamily)
oImageNode2.Parameters( "tex" ).Connect( oImageClip2 )
'Commands can also be used to build a render tree
CopyPaste , "Shaders\Material\Lambert.Preset", "TransientObjectContainer"
SIConnectShaderToCnxPoint "TransientObjectContainer.Lambert", oObj.Material & ".Photon"
set BuildDemoScene = oObj
end function
'Example output:
'INFO : Skipping sphere.Material.Phong.Image
'INFO : Skipping sphere.Material.Phong
'INFO : SUMMARY: Searched 5 shaders
'INFO : SHADERS SEARCHED:
'INFO : sphere.Material.Phong
'INFO : sphere.Material.Phong.Image
'INFO : sphere.Material.Phong.Color2scalar
'INFO : sphere.Material.Phong.Color2scalar.Image1
'INFO : sphere.Material.Lambert
3. JScript Example
/*
This example lists all installed shaders with their ProgId and OutputType,
plus all texturable parameters and their shader input type.
*/
var re = / /g;
var strShaderNames = Dictionary.info("",siShaderFamily).replace(re,"");
var aShaders = strShaderNames.split(",");
XSIUtils.QuickSort( aShaders );
var colitem = XSIFactory.CreateObject("XSI.CollectionItem");
var cShaders = 0;
for ( var i = 0; i < aShaders.length; i++ )
{
var shader = null;
var progid = "Softimage." + aShaders[i];
if ( progid == "Softimage.TraversalCallback" ) continue;
try {
shader = XSIFactory.CreateObject( progid );
} catch (e) {
logmessage( "Error: can't create shader : " + progid );
continue;
}
cShaders++;
logmessage( progid + " " + ShaderParameterTypeAsText(shader.OutputType) );
var params = shader.parameters;
for ( var j = 0; j < params.count; j++ )
{
var param = shader.parameters(j);
if ( param.capabilities & siTexturable )
logmessage( "\t" + param.name + " " + ShaderParameterTypeAsText(shader.GetShaderInputType(param.scriptname)));
}
}
logmessage( "Shaders found = " + cShaders );
function ShaderParameterTypeAsText(type)
{
switch (type)
{
case siUnknownParameterType : return "siUnknownParameterType";
case siBooleanParameterType : return "siBooleanParameterType";
case siColorParameterType : return "siColorParameterType";
case siDataParameterType : return "siDataParameterType";
case siIntegerParameterType : return "siIntegerParameterType";
case siLensParameterType : return "siLensParameterType";
case siLightParameterType : return "siLightParameterType";
case siMaterialParameterType : return "siMaterialParameterType";
case siMatrixParameterType : return "siMatrixParameterType";
case siModelParameterType : return "siModelParameterType";
case siRealTimeParameterType : return "siRealTimeParameterType";
case siReferenceParameterType : return "siReferenceParameterType";
case siScalarParameterType : return "siScalarParameterType";
case siShaderParameterType : return "siShaderParameterType";
case siStringParameterType : return "siStringParameterType";
case siStructParameterType : return "siStructParameterType";
case siTextureParameterType : return "siTextureParameterType";
case siTextureSpaceParameterType : return "siTextureSpaceParameterType";
case siVectorParameterType : return "siVectorParameterType";
default: return type;
}
}
//
See Also
|
|
SOFTIMAGE|XSI v6.01