fractal テクスチャーを使用した雲をアニメーションを作成してみましょう。
テクスチャーのアトリビュートを、
エクスプレッションによってアニメーションさせることによって作成します。
fractal テクスチャーは不規則な数値を発生させるために使い、
実際の色や透明度は ramp テクスチャーによって決定します。
そして、色と透明度のテクスチャーを配置している place2dTexture の
offsetU と offsetV をエクスプレッションでアニメーションさせて、
雲を移動させます。
雲のシェーダーによるアニメーション作成を MEL スクリプトで自動化してみましょう。
proc string makeLambert(string $obj)
{
string $shname = `shadingNode -asShader lambert`;
string $sgname = `sets -renderable true -noSurfaceShader true -empty`;
connectAttr -f ($shname + ".outColor") ($sgname + ".surfaceShader");
select $obj;
sets -e -forceElement $sgname;
return $shname;
}
proc string [] make2dTexture(string $name)
{
string $sname[];
$sname[0] = `shadingNode -asTexture $name`;
$sname[1] = `shadingNode -asUtility place2dTexture`;
connectAttr ($sname[1] + ".outUV") ($sname[0] + ".uv");
connectAttr ($sname[1] + ".outUvFilterSize") ($sname[0] + ".uvFilterSize");
return $sname;
}
global proc makeSky1()
{
string $pname1[] = `nurbsPlane -axis 0 1 0`;
scale 26 26 26;
move -0.7 6.5 0;
rotate 0 0 30;
string $pname2[] = `nurbsPlane -axis 0 1 0`;
scale 26 26 26;
move 0 4.8 0;
rotate 0 0 22;
directionalLight;
rotate 90 80 35;
select persp;
move 8 0 0;
rotate 22 90 0;
string $shname1 = makeLambert($pname1[0]);
setAttr ($shname1 + ".color") -type double3 0.15 0.2 1 ;
string $fractal1[] = make2dTexture("fractal");
string $ramp1[] = make2dTexture("ramp");
connectAttr ($fractal1[0] + ".outColorR") ($ramp1[0] + ".vCoord");
string $fractal2[] = make2dTexture("fractal");
string $ramp2[] = make2dTexture("ramp");
connectAttr ($fractal2[0] + ".outColorR") ($ramp2[0] + ".vCoord");
string $shname2 = makeLambert($pname2[0]);
connectAttr ($ramp1[0] + ".outColor") ($shname2 + ".color");
connectAttr ($ramp2[0] + ".outColor") ($shname2 + ".transparency");
setAttr ($fractal1[0] + ".amplitude") 0.68;
setAttr ($fractal1[0] + ".ratio") 0.58;
setAttr ($fractal2[0] + ".threshold") 0.243;
setAttr ($fractal2[0] + ".ratio") 0.64;
setAttr ($fractal2[0] + ".levelMax") 10;
setAttr ($ramp1[0] + ".interpolation") 4;
setAttr ($ramp1[0] + ".colorEntryList[0].color") -type double3 0.4 0.4 0.4;
setAttr ($ramp1[0] + ".colorEntryList[1].position") 0.195;
setAttr ($ramp1[0] + ".colorEntryList[1].color") -type double3 0.5 0.5 0.5;
setAttr ($ramp1[0] + ".colorEntryList[2].position") 0.31;
setAttr ($ramp1[0] + ".colorEntryList[2].color") -type double3 0.6 0.6 0.6;
setAttr ($ramp1[0] + ".colorEntryList[3].position") 0.425;
setAttr ($ramp1[0] + ".colorEntryList[3].color") -type double3 0.86 0.86 0.86;
setAttr ($ramp1[0] + ".colorEntryList[4].position") 0.495;
setAttr ($ramp1[0] + ".colorEntryList[4].color") -type double3 0.97 0.97 0.97;
setAttr ($ramp2[0] + ".colorEntryList[0].color") -type double3 0 0 0 ;
setAttr ($ramp2[0] + ".colorEntryList[1].position") 0.77;
setAttr ($ramp2[0] + ".colorEntryList[1].color") -type double3 0 0 0 ;
setAttr ($ramp2[0] + ".colorEntryList[2].position") 0.9;
setAttr ($ramp2[0] + ".colorEntryList[2].color") -type double3 0.6 0.6 0.6 ;
setAttr ($ramp2[0] + ".colorEntryList[3].position") 1;
setAttr ($ramp2[0] + ".colorEntryList[3].color") -type double3 1 1 1 ;
expression -o $fractal1[1] -s "offsetU = 0.006 * time + 0.006;";
expression -o $fractal1[1] -s "offsetV = 0.006 * time + 0.003;";
setAttr ($fractal1[0] + ".animated") 1;
expression -o $fractal1[0] -s "fractal1.time = 0.006 * time;";
expression -o $fractal2[1] -s "offsetU = 0.006 * time;";
expression -o $fractal2[1] -s "offsetV = 0.006 * time;";
setAttr ($fractal2[0] + ".animated") 1;
expression -o $fractal2[0] -s "fractal2.time = 0.006 * time;";
}
proc string makeLambert(string $obj)
string $shname = `shadingNode -asShader lambert`;
string $sgname = `sets -renderable true -noSurfaceShader true -empty`;
connectAttr -f ($shname + ".outColor") ($sgname + ".surfaceShader");
select $obj;
sets -e -forceElement $sgname;
return $shname;
proc string [] make2dTexture(string $name)
string $sname[];
$sname[0] = `shadingNode -asTexture $name`;
$sname[1] = `shadingNode -asUtility place2dTexture`;
connectAttr ($sname[1] + ".outUV") ($sname[0] + ".uv");
connectAttr ($sname[1] + ".outUvFilterSize") ($sname[0] + ".uvFilterSize");
return $sname;
global proc makeSky1()
string $pname1[] = `nurbsPlane -axis 0 1 0`;
scale 26 26 26;
move -0.7 6.5 0;
rotate 0 0 30;
string $pname2[] = `nurbsPlane -axis 0 1 0`;
scale 26 26 26;
move 0 4.8 0;
rotate 0 0 22;
directionalLight;
rotate 90 80 35;
select persp;
move 8 0 0;
rotate 22 90 0;
string $shname1 = makeLambert($pname1[0]);
setAttr ($shname1 + ".color") -type double3 0.15 0.2 1 ;
string $fractal1[] = make2dTexture("fractal");
string $ramp1[] = make2dTexture("ramp");
connectAttr ($fractal1[0] + ".outColorR") ($ramp1[0] + ".vCoord");
string $fractal2[] = make2dTexture("fractal");
string $ramp2[] = make2dTexture("ramp");
connectAttr ($fractal2[0] + ".outColorR") ($ramp2[0] + ".vCoord");
string $shname2 = makeLambert($pname2[0]);
connectAttr ($ramp1[0] + ".outColor") ($shname2 + ".color");
connectAttr ($ramp2[0] + ".outColor") ($shname2 + ".transparency");
setAttr ($fractal1[0] + ".amplitude") 0.68;
setAttr ($fractal1[0] + ".ratio") 0.58;
setAttr ($fractal2[0] + ".threshold") 0.243;
setAttr ($fractal2[0] + ".ratio") 0.64;
setAttr ($fractal2[0] + ".levelMax") 10;
setAttr ($ramp1[0] + ".interpolation") 4;
setAttr ($ramp1[0] + ".colorEntryList[0].color") -type double3 0.4 0.4 0.4;
setAttr ($ramp1[0] + ".colorEntryList[1].position") 0.195;
setAttr ($ramp1[0] + ".colorEntryList[1].color") -type double3 0.5 0.5 0.5;
setAttr ($ramp1[0] + ".colorEntryList[2].position") 0.31;
setAttr ($ramp1[0] + ".colorEntryList[2].color") -type double3 0.6 0.6 0.6;
setAttr ($ramp1[0] + ".colorEntryList[3].position") 0.425;
setAttr ($ramp1[0] + ".colorEntryList[3].color") -type double3 0.86 0.86 0.86;
setAttr ($ramp1[0] + ".colorEntryList[4].position") 0.495;
setAttr ($ramp1[0] + ".colorEntryList[4].color") -type double3 0.97 0.97 0.97;
setAttr ($ramp2[0] + ".colorEntryList[0].color") -type double3 0 0 0 ;
setAttr ($ramp2[0] + ".colorEntryList[1].position") 0.77;
setAttr ($ramp2[0] + ".colorEntryList[1].color") -type double3 0 0 0 ;
setAttr ($ramp2[0] + ".colorEntryList[2].position") 0.9;
setAttr ($ramp2[0] + ".colorEntryList[2].color") -type double3 0.6 0.6 0.6 ;
setAttr ($ramp2[0] + ".colorEntryList[3].position") 1;
setAttr ($ramp2[0] + ".colorEntryList[3].color") -type double3 1 1 1 ;
expression -o $fractal1[1] -s "offsetU = 0.006 * time + 0.006;";
expression -o $fractal1[1] -s "offsetV = 0.006 * time + 0.003;";
setAttr ($fractal1[0] + ".animated") 1;
expression -o $fractal1[0] -s "fractal1.time = 0.006 * time;";
expression -o $fractal2[1] -s "offsetU = 0.006 * time;";
expression -o $fractal2[1] -s "offsetV = 0.006 * time;";
setAttr ($fractal2[0] + ".animated") 1;
expression -o $fractal2[0] -s "fractal2.time = 0.006 * time;";