Shader.AddSharedTextureLayer

導入

v4.0

詳細

コンテナに既存のテクスチャレイヤを追加します。レイヤは最初から少なくとも1 つ以上の別のテクスチャレイヤコンテナ(ShaderまたはMaterial)に属しています。

テクスチャレイヤは、シェーダおよびマテリアルの上のテクスチャエフェクトのレイヤリングを簡略化するためのオブジェクトです。各レイヤごとに、その特性(カラー、ミキシングモード、ウェイトなど)を説明するプロパティのセットがあり、制御するシェーダポートに対する影響の度合いを指定できます。コンテナの下にレイヤが表示される順序はレイヤ化が適用された順序であり、「N 色をミックス」したシェーダ ノードが動作する場合と似ています。 テクスチャレイヤポートのオブジェクト(TextureLayer.AddTextureLayerPortコマンドを参照)はレイヤに所有され、レイヤが影響するシェーダポートを指定するために使用されます。

ヒント:Materialのテクスチャレイヤコンテナもあり、この場合も同じ関連メソッドのセットを持ちます。

スクリプト 構文

Shader.AddSharedTextureLayer( Layer, [After], [Reference] );

パラメータ

パラメータ タイプ 詳細
レイヤ TextureLayerまたはString コンテナに追加するテキスチャレイヤ
Boolean True の場合は、新しいテクスチャ レイヤはリファレンス レイヤの後に挿入されます。 False の場合は、リファレンス レイヤの前に挿入されます。 リファレンス レイヤがないときは、True の場合はコンテナのリストの最後に、False の場合はリストの最初に追加されます。

デフォルト値: True

リファレンス TextureLayerまたはString 新しく追加されたレイヤが配置されるスタック内の位置を示す、リファレンステクスチャレイヤ。レイヤはリファレンス レイヤの前後に挿入されます。 指定しない場合には、新しいレイヤはこの後に続く引数に応じて先頭または末尾に追加されます。

1. JScript の例

/*
        This JScript example shows creating and sharing 
        texture layers.  It also shows how both Shaders and
        Materials can be texture layer containers, and the same
        layer can drive ports on each of them (if desired).
*/
oRoot = ActiveProject.ActiveScene.Root;
oSph = oRoot.AddGeometry( "Sphere", "MeshSurface" );
oMat = oSph.AddMaterial( "Phong" );
oPhong = oMat.Shaders(0);
// Add a layer to the Phong.
oShared = oPhong.CreateTextureLayer( "SharedLayer" );
// Add an unshared layer to the Material.
oRough = oMat.CreateTextureLayer( "Rough" );
// Add the first layer to the material, thereby sharing it.
// We'll put it before the Rough layer.
oMat.AddSharedTextureLayer( oShared, false, oRough );
// Now for fun, let's create a Fractal, attach it to the
// color input of the shared layer, and make it drive
// both the Phong's diffuse and the Material's displacement.
oParam = Application.Dictionary.GetObject( oShared + ".Color" );
oFractal = oParam.ConnectFromPreset( "Fractal", siTextureShaderFamily );
oDiffuse = oShared.AddTextureLayerPort( oPhong.Parameters( "diffuse" ) );
oDispl = oShared.AddTextureLayerPort( oMat.Parameters( "displacement" ) );
// Now let's explore what we have created...
DumpTextureLayerContainer( oMat );
function DumpTextureLayerContainer( in_cont )
{
        Application.LogMessage( "CONTAINER: " + in_cont.Name );
        for ( var i = 0; i < in_cont.TextureLayers.Count; i++ )
        {
                oTextureLayer = in_cont.TextureLayers(i);
                DumpTextureLayer( oTextureLayer, i+1 );
        }
}
function DumpTextureLayer( in_layer, in_index )
{
        Application.LogMessage( "   Layer " + in_index + ": " + in_layer.Name );
        oColor = in_layer.Parameters("Color");
        var empty;
        if ( oColor == empty )
        {
                Application.LogMessage( "     Color: (" + in_layer.Red.Value +
                                                "," + in_layer.Green.Value +
                                                "," + in_layer.Blue.Value + ")" );
        }
        else
        {
                oColorSrc = in_layer.Color.Source;
                Application.LogMessage( "     Color driven by: " + oColorSrc.Name );
        }
        oPorts = in_layer.TextureLayerPorts;
        count = oPorts.Count;
        Application.LogMessage( "     Layer drives:" );
        if ( count == 0 )
                Application.LogMessage( "       <nothing>" );
        else
        {
                for ( i = 0; i < count; i++ )
                {
                        Application.LogMessage( "       " + oPorts(i).Target.FullName );
                }
        }
}
// This example should log something like:
//INFO : CONTAINER: Material
//INFO :    Layer 1: SharedLayer
//INFO :      Color driven by: Fractal
//INFO :      Layer drives:
//INFO :        Sources.Materials.DefaultLib.Material.Phong.diffuse
//INFO :        Sources.Materials.DefaultLib.Material.displacement
//INFO :    Layer 2: Rough
//INFO :      Color: (0.699999988079071,0.699999988079071,0.699999988079071)
//INFO :      Layer drives:
//INFO :        <nothing>

2. VBScript の例

'
' This VBScript example shows creating and sharing 
' texture layers.  It also shows how both Shaders and
' Materials can be texture layer containers, and the same
' layer can drive ports on each of them (if desired).
'
set oRoot = ActiveProject.ActiveScene.Root
set oSph = oRoot.AddGeometry( "Sphere", "MeshSurface" )
set oMat = oSph.AddMaterial( "Phong" )
set oPhong = oMat.Shaders(0)
' Add a layer to the Phong.
set oShared = oPhong.CreateTextureLayer( "SharedLayer" )
' Add an unshared layer to the Material.
set oRough = oMat.CreateTextureLayer( "Rough" )
' Add the first layer to the material, thereby sharing it.
' We'll put it before the Rough layer.
oMat.AddSharedTextureLayer oShared, False, oRough
' Now for fun, let's create a Fractal, attach it to the
' color input of the shared layer, and make it drive
' both the Phong's diffuse and the Material's displacement.
set oParam = Dictionary.GetObject( oShared & ".Color" )
set oFractal = oParam.ConnectFromPreset( "Fractal", siTextureShaderFamily )
set oDiffuse = oShared.AddTextureLayerPort( oPhong.Parameters( "diffuse" ) )
set oDispl = oShared.AddTextureLayerPort( oMat.Parameters( "displacement" ) )
' Now let's explore what we have created...
DumpTextureLayerContainer oMat
sub DumpTextureLayerContainer( in_cont )
        LogMessage "CONTAINER: " & in_cont.Name
        i = 1
        for each oTextureLayer in in_cont.TextureLayers
                DumpTextureLayer oTextureLayer, i
                i = i + 1
        next
end sub
sub DumpTextureLayer( in_layer, in_index )
        LogMessage "   Layer " & in_index & ": " & in_layer.Name
        set oColor = in_layer.Parameters("Color")
        if TypeName( oColor ) = "Nothing" then
                LogMessage "     Color: (" & in_layer.Red.Value & _
                                                "," & in_layer.Green.Value & _
                                                "," & in_layer.Blue.Value & ")"
        else
                set oColorSrc = in_layer.Color.Source
                LogMessage "     Color driven by: " & oColorSrc.Name
        end if
        set oPorts = in_layer.TextureLayerPorts
        count = oPorts.Count
        if count = 0 then
                LogMessage "     <layer driving no ports>"
        else
                LogMessage "     Layer drives:"
                for i = 0 to count - 1
                        LogMessage "       " & oPorts(i).Target.FullName
                next                            
        end if
end sub
' This example should log something like:
'INFO : CONTAINER: Material
'INFO :    Layer 1: SharedLayer
'INFO :      Color driven by: Fractal
'INFO :      Layer drives:
'INFO :        sphere.Material.Phong.diffuse
'INFO :        sphere.Material.Color2scalar.input
'INFO :    Layer 2: Rough
'INFO :      Color: (0.7,0.7,0.7)
'INFO :      <layer driving no ports>

関連項目

AddTextureLayer Shader.CreateTextureLayer Material.CreateTextureLayer Material.AddSharedTextureLayer