Maya Training

Introduction to Hard Surface Modeling

Maya Training

Interiors and Furniture Vol 1 & 2 - Modeling & Cloth

Maya Training

Shading, Lighting and Rendering the Bedroom in MR

Maya Training

Robot volume one - Modeling with animation in mind

Maya Training

Spach-Alspaugh House the complete courseware

Maya Training

Burt The Cartoon Dinosaur Vol 01 - Modeling

New Maya Training

Robot Volume 02 - Hybrid Rigging
You are here > Home > SimplyMaya Community Forums
Loading

Welcome to Simply Maya

Please Sign in or Sign up for an account

Member Login

Lost your password?

Not a member yet? Sign Up!

Old 13-02-2003, 04:10 AM   #1
grunze
Registered User
 
grunze's Avatar
 
Join Date: Nov 2002
Posts: 117
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
grunze is offline   Reply With Quote
Old 13-02-2003, 06:58 AM   #2
mark_wilkins
Registered User
 
mark_wilkins's Avatar
 
Join Date: Jan 2003
Posts: 161
Thanks: 0
Thanked 1 Time in 1 Post
Default

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
mark_wilkins is offline   Reply With Quote
Old 13-02-2003, 07:01 AM   #3
mark_wilkins
Registered User
 
mark_wilkins's Avatar
 
Join Date: Jan 2003
Posts: 161
Thanks: 0
Thanked 1 Time in 1 Post
Default

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
mark_wilkins is offline   Reply With Quote
Old 13-02-2003, 07:12 AM   #4
mark_wilkins
Registered User
 
mark_wilkins's Avatar
 
Join Date: Jan 2003
Posts: 161
Thanks: 0
Thanked 1 Time in 1 Post
Default

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.
mark_wilkins is offline   Reply With Quote
Old 13-02-2003, 07:26 AM   #5
mark_wilkins
Registered User
 
mark_wilkins's Avatar
 
Join Date: Jan 2003
Posts: 161
Thanks: 0
Thanked 1 Time in 1 Post
Default

I guess there was a LITTLE scripting after all... lol

-- Mark
__________________
Mark R. Wilkins
author of MEL Scripting for Maya Animators
www.melscripting.com
mark_wilkins is offline   Reply With Quote
Old 13-02-2003, 09:26 AM   #6
mark_wilkins
Registered User
 
mark_wilkins's Avatar
 
Join Date: Jan 2003
Posts: 161
Thanks: 0
Thanked 1 Time in 1 Post
Default

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
mark_wilkins is offline   Reply With Quote
Old 13-02-2003, 01:39 PM   #7
kbrown
Moderator
 
kbrown's Avatar
 
Join Date: Sep 2002
Location: London, UK
Posts: 3,198
Thanks: 0
Thanked 8 Times in 8 Posts
Default

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

-- Mark [/b]
Hehe, cool
__________________
Kari
- My Website
- My IMDB

Do a lot, Fail a lot and Learn a lot!
kbrown is offline   Reply With Quote
Old 13-02-2003, 04:04 PM   #8
grunze
Registered User
 
grunze's Avatar
 
Join Date: Nov 2002
Posts: 117
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
grunze is offline   Reply With Quote
Old 13-02-2003, 05:18 PM   #9
mark_wilkins
Registered User
 
mark_wilkins's Avatar
 
Join Date: Jan 2003
Posts: 161
Thanks: 0
Thanked 1 Time in 1 Post
Default

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
mark_wilkins is offline   Reply With Quote
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
Stepping effect in fluid gubar Dynamics & Special Effects 2 03-12-2010 10:42 PM

Thread Tools





A little bit about who we are
Links you might find useful
Catch up with SimplyMaya
SimplyMaya specialises in Maya tutorials. We offer over 1,000 individual Maya training videos, ranging from basic Maya tutorials through to intermediate Maya tutorials. Our tutorials are created by instructors with industry experience and are designed to get you up and running in Maya quickly without making it seem like hard work.

Copyright © 1999-2015 SimplyMaya - vBulletin® Copyright © 2000-2015, Jelsoft Enterprises Ltd.