surfaceLuminance ノードを使うことによって、 オブジェクトの表面における輝度を使ったシェーダーを作ることができます。 これによって、様々な特殊効果を実現することができます。
surfaceLuminance ノードを使用したシェーダーの例として、
輝度の明るいところだけ別のマテリアルになるシェーダーを作ってみましょう。
以下の lightShader1 は、輝度が 0.5 以上のところは blinn、
0.5 以下のところは lambert になるシェーダーをエクスプレッションによって作成するプロシージャです。
global proc lightShader1()
{
string $shname1 = `shadingNode -asShader lambert`;
string $sgname1 = `sets -renderable true -noSurfaceShader true -empty`;
connectAttr -f ($shname1 + ".outColor") ($sgname1 + ".surfaceShader");
string $shname2 = `shadingNode -asShader blinn`;
string $sgname2 = `sets -renderable true -noSurfaceShader true -empty`;
connectAttr -f ($shname2 + ".outColor") ($sgname2 + ".surfaceShader");
string $shname3 = `shadingNode -asShader surfaceShader`;
string $sgname3 = `sets -renderable true -noSurfaceShader true -empty`;
connectAttr -f ($shname3 + ".outColor") ($sgname3 + ".surfaceShader");
string $slname = `shadingNode -asUtility surfaceLuminance`;
expression -o $shname3 -s
("if(" + $slname + ".o > 0.5)"
+ "{"
+ "ocr = " + $shname2 + ".ocr;"
+ "ocg = " + $shname2 + ".ocg;"
+ "ocb = " + $shname2 + ".ocb;"
+ "}"
+ "else"
+ "{"
+ "ocr = " + $shname1 + ".ocr;"
+ "ocg = " + $shname1 + ".ocg;"
+ "ocb = " + $shname1 + ".ocb;"
+ "}");
}
global proc lightShader1()
string $shname1 = `shadingNode -asShader lambert`;
string $sgname1 = `sets -renderable true -noSurfaceShader true -empty`;
connectAttr -f ($shname1 + ".outColor") ($sgname1 + ".surfaceShader");
string $shname2 = `shadingNode -asShader blinn`;
string $sgname2 = `sets -renderable true -noSurfaceShader true -empty`;
connectAttr -f ($shname2 + ".outColor") ($sgname2 + ".surfaceShader");
string $shname3 = `shadingNode -asShader surfaceShader`;
string $sgname3 = `sets -renderable true -noSurfaceShader true -empty`;
connectAttr -f ($shname3 + ".outColor") ($sgname3 + ".surfaceShader");
string $slname = `shadingNode -asUtility surfaceLuminance`;
expression -o $shname3 -s
("if(" + $slname + ".o > 0.5)"
+ "{"
+ "ocr = " + $shname2 + ".ocr;"
+ "ocg = " + $shname2 + ".ocg;"
+ "ocb = " + $shname2 + ".ocb;"
+ "}"
+ "else"
+ "{"
+ "ocr = " + $shname1 + ".ocr;"
+ "ocg = " + $shname1 + ".ocg;"
+ "ocb = " + $shname1 + ".ocb;"
+ "}");
("if(" + $slname + ".o > 0.5)"
+ "ocr = " + $shname2 + ".ocr;"
+ "ocg = " + $shname2 + ".ocg;"
+ "ocb = " + $shname2 + ".ocb;"
+ "ocr = " + $shname1 + ".ocr;"
+ "ocg = " + $shname1 + ".ocg;"
+ "ocb = " + $shname1 + ".ocb;"
global proc lightShader2(string マテリアル名, string マテリアル名)
float $val = smoothstep(0.3, 0.6, $outValue);
ocr = マテリアル名2.ocr * $val + マテリアル名1.ocr * (1.0 - $val);