Displacement マッピングされた球をアニメーションさせることによって、
爆発のエフェクトを作成してみましょう。
Fractal と Ramp を使用して色を決め、
Displacement マッピングによって凹凸をつけます。
アニメーションにはエクスプレッションとキーフレームを併用します。
ここでは、240 フレームのアニメーションを作成します。
フレーム | ScaleX, Y, Z |
---|---|
1 | 0.0 |
4 | 0.5 |
25 | 0.9 |
240 | 1.3 |
フレーム | colorGainR |
---|---|
1 | 0.0 |
2 | 3 |
5 | 0.5 |
7 | 2.0 |
10 | 1.2 |
240 | 1.0 |
フレーム | alphaGain |
---|---|
1 | 0.0 |
6 | -0.2 |
240 | -0.425 |
爆発をシュミレートするシェーダーの作成を MEL スクリプトで自動化してみましょう。
proc string [] makeSurfaceShader(string $obj) { string $sname[]; $sname[0] = `shadingNode -asShader surfaceShader`; $sname[1] = `sets -renderable true -noSurfaceShader true -empty`; connectAttr -f ($sname[0] + ".outColor") ($sname[1] + ".surfaceShader"); select $obj; sets -e -forceElement $sname[1]; return $sname; } proc makeDisplacementShader(string $dest, string $src) { string $dsname = `shadingNode -asShader displacementShader`; string $dname = `sets -renderable true -noSurfaceShader true -empty`; connectAttr -f ($dsname + ".displacement") ($dname + ".displacementShader"); connectAttr -f ($dest + ".outAlpha") ($dsname + ".displacement"); connectAttr -f ($dsname + ".displacement") ($src + ".displacementShader"); } 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; } proc makeKeyframe(int $keys[], float $vals[], string $obj, string $attr) { int $i = 0; for($k in $keys) { currentTime $k; setAttr ($obj + "." + $attr) $vals[$i]; setKeyframe -at $attr $obj; $i++; } } proc makeKeyframe3(int $keys[], float $vals[], string $obj, string $attr) { int $i = 0; for($k in $keys) { currentTime $k; setAttr ($obj + "." + $attr) -type double3 $vals[$i] $vals[$i] $vals[$i]; setKeyframe -at $attr $obj; $i++; } } global proc makeBomb1() { string $sname[] = `sphere`; int $keys[] = {1, 4, 25, 240}; float $vals[] = {0.0, 0.5, 0.9, 1.3}; makeKeyframe3($keys, $vals, $sname[0], "scale"); string $shname[] = makeSurfaceShader($sname[0]); string $ramp[] = make2dTexture("ramp"); connectAttr -f ($ramp[0] + ".outColor") ($shname[0] + ".outColor"); string $fractal[] = make2dTexture("fractal"); connectAttr -f ($fractal[0] + ".outColorR") ($ramp[0] + ".vCoord"); setAttr ($fractal[0] + ".amplitude") 0.058; setAttr ($fractal[0] + ".ratio") 0.699; setAttr ($fractal[0] + ".frequencyRatio") 2.398; setAttr ($fractal[0] + ".levelMax") 6.553; setAttr ($fractal[0] + ".bias") 0.476; setAttr ($fractal[0] + ".inflection") 1; setAttr ($fractal[0] + ".animated") 1; setAttr ($fractal[0] + ".timeRatio") 1.55; setAttr ($fractal[0] + ".alphaGain") 0.097; setAttr ($fractal[0] + ".colorGain") -type double3 5 5 5 ; expression -s ($fractal[0] + ".time = 0.1*sind(frame/2.6);"); expression -o $fractal[1] -s "offsetU = 0.02*time;"; $keys = {1, 2, 5, 7, 10, 240}; $vals = {0.0, 3.0, 0.5, 2.0, 1.2, 1.0}; makeKeyframe3($keys, $vals, $ramp[0], "colorGain"); $keys = {1, 6, 240}; $vals = {0.0, -0.2, -0.425}; makeKeyframe($keys, $vals, $ramp[0], "alphaGain"); string $mname = `shadingNode -asUtility multiplyDivide`; string $obj[] = `listConnections ($ramp[0] + ".alphaGain")`; connectAttr -f ($obj[0] + ".output") ($mname + ".input1X"); setAttr ($mname + ".input2X") -1; connectAttr -f ($mname + ".outputX") ($ramp[0] + ".alphaOffset"); setAttr ($ramp[0] + ".colorEntryList[0].color") -type double3 0.2 0.0 0 ; setAttr ($ramp[0] + ".colorEntryList[1].color") -type double3 0.36 0.14 0.02 ; setAttr ($ramp[0] + ".colorEntryList[2].color") -type double3 1.0 0.3 0.0 ; setAttr ($ramp[0] + ".colorEntryList[3].color") -type double3 1 0.45 0 ; setAttr ($ramp[0] + ".colorEntryList[4].color") -type double3 1 0.78 0 ; setAttr ($ramp[0] + ".colorEntryList[5].color") -type double3 1 1 1 ; $keys = {1, 240}; $vals = {0.93, 0.38}; makeKeyframe($keys, $vals, $ramp[0], "colorEntryList[0].position"); $vals = {0.62, 0.28}; makeKeyframe($keys, $vals, $ramp[0], "colorEntryList[1].position"); $vals = {0.47, 0.20}; makeKeyframe($keys, $vals, $ramp[0], "colorEntryList[2].position"); $vals = {0.38, 0.19}; makeKeyframe($keys, $vals, $ramp[0], "colorEntryList[3].position"); $vals = {0.31, 0.15}; makeKeyframe($keys, $vals, $ramp[0], "colorEntryList[4].position"); $vals = {0.21, 0.09}; makeKeyframe($keys, $vals, $ramp[0], "colorEntryList[5].position"); makeDisplacementShader($ramp[0], $shname[1]); }
proc string [] makeSurfaceShader(string $obj)
string $sname[];
$sname[0] = `shadingNode -asShader surfaceShader`;
$sname[1] = `sets -renderable true -noSurfaceShader true -empty`;
connectAttr -f ($sname[0] + ".outColor") ($sname[1] + ".surfaceShader");
select $obj;
sets -e -forceElement $sname[1];
return $sname;
proc makeDisplacementShader(string $dest, string $src)
string $dsname = `shadingNode -asShader displacementShader`;
string $dname = `sets -renderable true -noSurfaceShader true -empty`;
connectAttr -f ($dsname + ".displacement") ($dname + ".displacementShader");
connectAttr -f ($dest + ".outAlpha") ($dsname + ".displacement");
connectAttr -f ($dsname + ".displacement") ($src + ".displacementShader");
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;
proc makeKeyframe(int $keys[], float $vals[], string $obj, string $attr)
int $i = 0;
for($k in $keys)
currentTime $k;
setAttr ($obj + "." + $attr) $vals[$i];
setKeyframe -at $attr $obj;
$i++;
proc makeKeyframe3(int $keys[], float $vals[], string $obj, string $attr)
int $i = 0;
for($k in $keys)
currentTime $k;
setAttr ($obj + "." + $attr) -type double3 $vals[$i] $vals[$i] $vals[$i];
setKeyframe -at $attr $obj;
$i++;
global proc makeBomb1()
string $sname[] = `sphere`;
int $keys[] = {1, 4, 25, 240};
float $vals[] = {0.0, 0.5, 0.9, 1.3};
makeKeyframe3($keys, $vals, $sname[0], "scale");
string $shname[] = makeSurfaceShader($sname[0]);
string $ramp[] = make2dTexture("ramp");
connectAttr -f ($ramp[0] + ".outColor") ($shname[0] + ".outColor");
string $fractal[] = make2dTexture("fractal");
connectAttr -f ($fractal[0] + ".outColorR") ($ramp[0] + ".vCoord");
setAttr ($fractal[0] + ".amplitude") 0.058;
setAttr ($fractal[0] + ".ratio") 0.699;
setAttr ($fractal[0] + ".frequencyRatio") 2.398;
setAttr ($fractal[0] + ".levelMax") 6.553;
setAttr ($fractal[0] + ".bias") 0.476;
setAttr ($fractal[0] + ".inflection") 1;
setAttr ($fractal[0] + ".animated") 1;
setAttr ($fractal[0] + ".timeRatio") 1.55;
setAttr ($fractal[0] + ".alphaGain") 0.097;
setAttr ($fractal[0] + ".colorGain") -type double3 5 5 5 ;
expression -s ($fractal[0] + ".time = 0.1*sind(frame/2.6);");
expression -o $fractal[1] -s "offsetU = 0.02*time;";
$keys = {1, 2, 5, 7, 10, 240};
$vals = {0.0, 3.0, 0.5, 2.0, 1.2, 1.0};
makeKeyframe3($keys, $vals, $ramp[0], "colorGain");
$keys = {1, 6, 240};
$vals = {0.0, -0.2, -0.245};
makeKeyframe($keys, $vals, $ramp[0], "alphaGain");
string $mname = `shadingNode -asUtility multiplyDivide`;
string $obj[] = `listConnections ($ramp[0] + ".alphaGain")`;
connectAttr -f ($obj[0] + ".output") ($mname + ".input1X");
setAttr ($mname + ".input2X") -1;
connectAttr -f ($mname + ".outputX") ($ramp[0] + ".alphaOffset");
setAttr ($ramp[0] + ".colorEntryList[0].color") -type double3 0.2 0 0 ;
setAttr ($ramp[0] + ".colorEntryList[1].color") -type double3 0.36 0.14 0.02 ;
setAttr ($ramp[0] + ".colorEntryList[2].color") -type double3 1.0 0.3 0.0 ;
setAttr ($ramp[0] + ".colorEntryList[3].color") -type double3 1 0.45 0 ;
setAttr ($ramp[0] + ".colorEntryList[4].color") -type double3 1 0.78 0 ;
setAttr ($ramp[0] + ".colorEntryList[5].color") -type double3 1 1 1 ;
$keys = {1, 240};
$vals = {0.93, 0.38};
makeKeyframe($keys, $vals, $ramp[0], "colorEntryList[0].position");
$vals = {0.62, 0.28};
makeKeyframe($keys, $vals, $ramp[0], "colorEntryList[1].position");
$vals = {0.47, 0.20};
makeKeyframe($keys, $vals, $ramp[0], "colorEntryList[2].position");
$vals = {0.38, 0.19};
makeKeyframe($keys, $vals, $ramp[0], "colorEntryList[3].position");
$vals = {0.31, 0.15};
makeKeyframe($keys, $vals, $ramp[0], "colorEntryList[4].position");
$vals = {0.21, 0.09};
makeKeyframe($keys, $vals, $ramp[0], "colorEntryList[5].position");
makeDisplacementShader($ramp[0], $shname[1]);