属性はシェーダ定義に定義するか、パラメータ定義ごとに定義できます。 たとえば、PPGLayout 属性の 1 つを直接シェーダ定義に設定できます(ヘルプファイルの場所の設定など)。シェーダパラメータ定義では、属性はパラメータデータタイプを指定したり、関連付けられたプロパティページで使用するプロパティルックアップまたはリファレンスウィジットを設定したり、カスタムデータタイプのカラーを設定したりするために使用できます。
レンダラ オプションと同様に、属性は ValueMap または ValueMap に格納されます。これは名前と値の組み合わせで構成される連想配列と類似しています。ShaderDef.Attributes または ShaderDef::GetAttributes メンバーを介して、シェーダ定義の属性を含む値マップにアクセスします。
ShaderParamDefOptions または ShaderParamDefOptions オブジェクトがパラメータ属性およびその他の設定を格納するために、パラメータ定義を追加する前に ShaderParamDefOptions.SetAttribute または ShaderParamDefOptions::SetAttribute メソッドを使用して属性値を設定することもできます。
| 実行するタスク |
ValueMap メンバ |
コメント |
|
|---|---|---|---|
| 単一エントリの追加または変更 |
引数には名前と値を指定します。 指定した名前と一致するエントリがない場合は、新しいエントリが追加されます。それ以外の場合は、既存の値が上書きされます。 |
||
| 単一エントリの取得 |
指定した名前と一致するエントリの値を取得します。 |
||
| 単一エントリの削除 |
指定した名前と一致するエントリを削除します。 一致するエントリが見つからなくても、エラーは発生しません。 |
||
| エントリのリストの繰り返し |
ValueMap インターフェイスでは名前のリストに加えて値のリストにもアクセスできるため、名前を完全にスキップして値だけを繰り返すことも、または名前を繰り返し、各エントリから ValueMap.Get または ValueMap::Get メンバーを介して一致する値にアクセスすることもできます。 |
ValueMap::GetAll 関数(C++ API)。名前と値の出力配列を引数として指定します。 |
Python の例: ShaderDef 属性を設定、削除、繰り返し
Python および VBScript は safearray とうまく機能するため、ValueMap のエントリの繰り返しは非常に簡単です。
# Get the ValueMap from the shader definition and add a couple of entries
oAttribs = oShaderDef.Attributes
oAttribs.Set("user", "test")
oAttribs.Set("a", 123456)
# Get the safearray of names and use each name to find the matching value
aAttribNames = oAttribs.Names
Application.LogMessage("Before removal there are %d attributes" % len(aAttribNames))
for vKey in aAttribNames :
Application.LogMessage("Attribute key,value: %s, %s" % (vKey, str(oAttribs.Get(vKey))))
# Remove one of the entries from the list
oAttribs.Remove("user")
aAttribValues = oAttribs.Values
Application.LogMessage("After removal there are %d attribute(s) left" % len(aAttribValues))
# Results:
# INFO : Before removal there are 2 attributes
# INFO : Attribute key,value: a, 123456
# INFO : Attribute key,value: user, test
# INFO : After removal there are 1 attribute(s) leftJScript の例: ShaderParamDef への書き込み可能イメージ タイプの設定
この例は、シェーダ パラメータ定義を書き込み可能イメージ データ タイプとして設定する方法です。
// When you set up the options for your shader parameter definition you could
// set parameter attributes using the ShaderParamDefOptions object
var oParamDefOpts = XSIFactory.CreateShaderParamDefOptions();
oParamDefOpts.SetAttribute(siWritableImageAttribute, true);
oParamDefOpts.SetTexturable(true);
oParamDefOpts.SetInspectable(false);
// Alternatively, you could use the Attributes property to get the ValueMap and
// set the siWritableImageAttribute directly on the ValueMap
var oInParamDefs = oShaderDef.InputParamDefs;
var oParamDef = oInParamDefs.AddParamDef("texture", siShaderDataTypeImage, oParamDefOpts);
oParamDef.Attributes.Set(siWritableImageAttribute, true);