PDA

View Full Version : Animating A shaders color with Mel



yencaray
07-20-2006, 12:37 AM
Hey guys! I'm in a bind! I'm creating a short animation for a film festival and One of the characters has lights around the middle of him that you can see here.http://i16.photobucket.com/albums/b41/moon_lit_eyes/Lights_adaption.jpg the blue and white glowing squares. Well My plan is to have them randomly changing colors from blue to white while times progessing. The only problem is the character is one whole object and has three different shaders applied to the geometry as of right now. Do you guys know any ideas on how to achieve the changing colors so they change randomly? As in sometimes there might be more blue quares sometimes more white quares as each square is changing independly of all the others? And i'm also wondering if anyone has a way of making the change not to sudden as in each time it changes i can specify the amount of time the lights(color) fades off and the amount of time the new color fades in. blinking but not so sudden and harsh.

glick_c
07-20-2006, 08:55 AM
Yes, I think I know how, but I'm not at a Maya workstation right now so I'll come back to this tonight.

yencaray
07-20-2006, 03:46 PM
ok Cool thanks!

glick_c
07-20-2006, 07:21 PM
Well now that I'm going through it the answer is a bit tougher but doable. I hope you like MEL :wink:



side note: is there a bug in Maya 6.0 with Layered Shaders? My coworker Adam was having trouble with them too in Maya 7.0. It seems that the specularity/reflectivity is multiplied, no matter what the transparency/reflectivity is set at. I have two blinns and a Layered shader, one blue at 0 transparency adn with all the specular/reflectivity turned to 0 but the Layered shader was still blown out. Odd. Back to fixing the problem!

yencaray
07-20-2006, 07:45 PM
I was figuring it would be something hard to achieve!!! hehe. Thats not a bad idea to start from i havn't tried a layered texture yet. There must be some reason why the shaders doing that. but You did just give me an idea with the layered texture.
Why not Make a uv set with all the squares on there own uv space in the 0 to 1 space so i could say make a simple texture in photoshop with each square in it's own layer then bring it into after affects and animate the squares in there? Render it out to a format that has frames. bring it into maya and in the texture node write an expression in the Image number under the Use Image sequence??? I'm going to try that out and let you guys know how it goes and looks! Still wish there was a way to do this in maya though it would save alot of time with after effects.

glick_c
07-20-2006, 08:55 PM
Okay! Here is the begining.

copy this and put it in the bottom of your Window -> General -> script editor. This will create the ramp node. I'll add some random animation soon. Coding is fun! :laugh

okay, finally finished. I // commented the parts that you need to change. I'll upload the test file so you can look at it. This code just makes the ramp for you.



//some sort of crazy ramp generator
//7/20/2006 - Chris Glick for www.digitaltutors.com
// fun stuff.

shadingNode -asTexture ramp;
$crg_ramp = `ls -sl`;
$crg_ramp_interp = $crg_ramp[0] + ".interpolation" ;
setAttr $crg_ramp_interp 0;
$crg_ramp_type = $crg_ramp[0] + ".type" ;
setAttr $crg_ramp_type 1;
shadingNode -asUtility place2dTexture;
$crg_texture = `ls -sl`;
$crg_I_dont_like_maya_sometimes = $crg_texture[0] + ".outUV " ;
$crg_I_dont_like_maya_sometimes_uv = $crg_ramp[0] + ".uv" ;
connectAttr $crg_I_dont_like_maya_sometimes $crg_I_dont_like_maya_sometimes_uv;
updateBinMembershipAfterConnection $crg_I_dont_like_maya_sometimes;
$crg_I_dont_like_maya_sometimes_ha = $crg_texture[0] + ".outUvFilterSize" ;
$crg_I_dont_like_all_da_time = $crg_ramp[0] + ".uvFilterSize" ;
connectAttr $crg_I_dont_like_maya_sometimes_ha $crg_I_dont_like_all_da_time;
updateBinMembershipAfterConnection $crg_texture[0];


// YOU NEED TO EDIT THIS
//how many sides is your cylinder
int $number_sides = 20;
//PUT A NUMBER THERE

string $crgcolor;
string $crgrmpposition;
float $crg_position = 0;
int $crgi = 0;

for ($crgi=0; $crgi < $number_sides; $crgi++)
{
$crgcolor = $crg_ramp[0] +".colorEntryList[" + $crgi + "].color" ;
$crgrmpposition = $crg_ramp[0] +".colorEntryList[" + $crgi + "].position" ;
setAttr $crgrmpposition $crg_position;
if ($crgi % 2)
{
setAttr $crgcolor -type double3 0 0 0;
}
else {
setAttr $crgcolor -type double3 1 1 1;
}

//YOU NEED TO EDIT THIS
// whip out your windows calculator and do 1 / number of sides
// I dont know why maya won't do this but it literally will not cooperate
$crg_position = $crg_position + .05;
//---------------------------------------
}

float $the_colors[3] = <<0,0,0>>;
int $crg_aye = 0;
int $go_through_ramp = 0;
int $rand_which_frame = 0;

////-----------------------------
for ($go_through_ramp = 0; $go_through_ramp < 20; $go_through_ramp ++)
// 20 = number of sides on your cylinder


{

// edit 300 to be however many frames you want--------
for ($crg_aye = 0; $crg_aye < 300; $crg_aye++)

// ---------------
{


//this is the range between color changes
$rand_which_frame = `rand 10 20`;
//---------------------------------------

$crg_aye += $rand_which_frame;
currentTime $crg_aye;
$crgcolor_w_quotes = $crg_ramp[0] +".colorEntryList[" + $go_through_ramp + "].color" ;
$the_colors = `getAttr $crgcolor_w_quotes`;
setKeyframe $crgcolor_w_quotes;

//how many frames do you want the color change to take?
$crg_aye += 3;
//----------------------------------------------- thats it!

currentTime -update false $crg_aye;

if ($the_colors[1] == 0) {

setAttr $crgcolor_w_quotes -type double3 1 1 1;
setKeyframe $crgcolor_w_quotes;
}
else {
setAttr $crgcolor_w_quotes -type double3 0 0 0;
setKeyframe $crgcolor_w_quotes;
}


}
$crg_aye = 0;

}

glick_c
07-20-2006, 09:54 PM
Herte is the scene file. It's pretty simple. I just created two ramps, deleted 2 of the colors so it would be one color then put them into a layered texture. Then I ran the script which gave me another ramp. Just middle click and drag the script_ramp into the alpha box of the first layer of the layered texture.

:laugh :laugh :laugh :laugh :laugh :laugh

yencaray
07-20-2006, 10:24 PM
holy cow man!!!! this is amazing!!! how did you know how to do this?? i wouldn't have even thought of this that and i don't know mel this well either but wow this is freaking amazing!!!!! I can't believe it!!!! This is amazing It's EXACTLY what i was visualizing in my head!!! Thanks so much!

also since i'm using this for a film festival and all is it alright being you made and created this that i use it?

glick_c
07-20-2006, 10:52 PM
Yea, it's all good, use it for whatever you want. Edit: Well, I dont know the rules of the film festival so I don't know if it has to be 100% of your own work, or if this even would violate that rule. :redface:

Just don't forget me when you blow up and start working at a major game studio.

yencaray
07-20-2006, 11:09 PM
well the only rule is it has to be within 60 seconds. And I'd also like to give you creadit for this so if it's alright with you i'd like to put you into the creadits. Just with in any movie creadit of work and ideas need to be given. So if you want to PM your name or I could use your DT profile name and link it to DT.
like this

Mel Scripting (or something fitting) --- glick_c of Digital Tutors.com

Edit:
alright so here is what i was able to do with that Mel you provided me!!! it was a sinch to make it happen and work i had to change nothing other then link the textures and uv's!!! Thanks again man
HERE IS THE LINK TO THE VIDEO CHECK IT OUT!
http://www.digitaltutors.com/gallery/showphoto.php?photo=2488&cat=500&ppuser=1624