Beer glass scene creation
This course contains a little bit of everything with modeling, UVing, texturing and dynamics in Maya, as well as compositing multilayered EXR's in Photoshop.
# 1 13-02-2003 , 04:10 AM
grunze's Avatar
Registered User
Join Date: Nov 2002
Posts: 117

help with script to create a random shine effect on a shader

Hi there,

I'm a big time newbie when it comes to mel scripting, or any scripting for that matter.

I have a wall, like in the pic below.
The wall used a shader with a 2D grid map for the colour.

I want to have the different squares have slight subtle random shine to them.

Or if that is too complicated, maybe just have each face of the sphere have the afforementioned shine.

:banana:


Thanks,
Ari
# 2 13-02-2003 , 06:58 AM
mark_wilkins's Avatar
Registered User
Join Date: Jan 2003
Posts: 161
ok, is this what you're looking for?

I made this by perturbing the normals with a texture. More in a sec...

-- Mark


Mark R. Wilkins
author of MEL Scripting for Maya Animators
www.melscripting.com
# 3 13-02-2003 , 07:01 AM
mark_wilkins's Avatar
Registered User
Join Date: Jan 2003
Posts: 161
OK. So here's how this works. No MEL scripting was involved.

First, I opened Photoshop and made a little 20x20 pixel file. I filled it with black and used the Noise function to randomize the pixels. Then, I used Nearest Neighbor resampling to size the thing up to 1k by 1k. Here's a sized-down version of the image that resulted...


Mark R. Wilkins
author of MEL Scripting for Maya Animators
www.melscripting.com
# 4 13-02-2003 , 07:12 AM
mark_wilkins's Avatar
Registered User
Join Date: Jan 2003
Posts: 161
Now, to hook it all up, I made the following shader network. A little background -- you can get data from whatever Maya's trying to shade with the samplerInfo node. In particular, I wanted to grab the normals for whatever Maya sees with the shader attached, and add on a little tweak based on the color of my texture.

I first made a file texture node and pointed it at my noise image. This maps the texture onto the object based on its UV space, unless I do something special with a projection or something like that.

I use the connection editor to connect the file texture's outputColor node to the input of a multiplyDivide node. The reason is that I want to be able to control how much of a tweak to apply to the object's pre-existing normals by scaling the texture up and down. I used the channel box to set the input2 values manually to 0.3 for X, Y, and Z. (Playing with this number gives you more or less of an effect.)

Then, I took the output of the multiplyDivide node and plugged it into one of the input3D attributes of a plusMinusAverage node. Since the inputs to this node are arrays, you have to use MEL if you want to connect more than one. There's no way to do this in the connection editor. The MEL looked something like this:

connectAttr multiplyDivide1.output plusMinusAverage.input3D[0];

Then, I made a samplerInfo node. This doesn't need to be connected to anything on the input side... it just serves to spit out data about whatever surface the renderer's shading. I connected the output normalCamera attribute to the other input of plusMinusAverage using a MEL command like the above. The normalCamera attribute contains the normal direction of whatever point is currently being shaded, so we'll use the plusMinusAverage node to add this value to the scaled texture that we plugged in before:

connectAttr samplerInfo1.normalCamera plusMinusAverage.input3D[1];

Then, I took the output of the plusMinusAverage node (which now is outputting the original normal for whatever part of the sphere Maya's shading, plus my scaled texture) and attached it to the normalCamera attribute for the phong2 shader with the connection editor. This is the inputs that bump maps use to tweak the normals, but since bump maps are supposed to represent height and not tweaks to the normals themselves I didn't want to use a bump map for this.

Assign the phong2 shader to the sphere, and voila! :-)

-- Mark


Mark R. Wilkins
author of MEL Scripting for Maya Animators
www.melscripting.com

Last edited by mark_wilkins; 13-02-2003 at 07:58 AM.
# 5 13-02-2003 , 07:26 AM
mark_wilkins's Avatar
Registered User
Join Date: Jan 2003
Posts: 161
I guess there was a LITTLE scripting after all... lol

-- Mark


Mark R. Wilkins
author of MEL Scripting for Maya Animators
www.melscripting.com
# 6 13-02-2003 , 09:26 AM
mark_wilkins's Avatar
Registered User
Join Date: Jan 2003
Posts: 161
I saw the image you were trying to replicate in the other forum, by the way, and it looks like all you need is an environment map to get the reflections, rather than what I did. Oh, well, at least now you have a disco ball!! :-)

-- Mark


Mark R. Wilkins
author of MEL Scripting for Maya Animators
www.melscripting.com
# 7 13-02-2003 , 01:39 PM
kbrown's Avatar
Moderator
Join Date: Sep 2002
Location: London, UK
Posts: 3,198

[i]Oh, well, at least now you have a disco ball!! :-)

-- Mark [/B]

Hehe, cool user added image


Kari
- My Website
- My IMDB

Do a lot, Fail a lot and Learn a lot!
# 8 13-02-2003 , 04:04 PM
grunze's Avatar
Registered User
Join Date: Nov 2002
Posts: 117
Wow,

Thanks Mark. I really appreicate the time you spent on me...
Its quite a bit more complicated than i had expected.
One question before i do it...
With this method, can i control the amount of shine that is given off by a grid square? and can i control the freuency of how often they shine? i.e. to have a square shine every 20 frames for a period of 5 frames?


Thanks,
Ari
# 9 13-02-2003 , 05:18 PM
mark_wilkins's Avatar
Registered User
Join Date: Jan 2003
Posts: 161
to do what you describe you'd need to animate a specularity map. Not that difficult, but you might need something more than Photoshop to make nice animated maps.

-- Mark


Mark R. Wilkins
author of MEL Scripting for Maya Animators
www.melscripting.com
Posting Rules Forum Rules
You may not post new threads | You may not post replies | You may not post attachments | You may not edit your posts | BB code is On | Smilies are On | [IMG] code is On | HTML code is Off

Similar Threads