View Full Version : Changing shading dymatically
07 July 2007, 11:00 PM
I am trying to map/connect several objects to a single shader, which has its trancparency already connected to a ramp shader.
(you can take a look here (http://tinyurl.com/35q27f) for illustration)
As the illustration shown at the right-lower corner, I would like to add a custom attribute to each of these objects (say ".trans"), and write an expression (maybe on "ramp" or somewhere) in order for each object with this shader connected dynamically change its transparency based on the ".trans" attribute value.
Is this doable? How and where should I arrange/put this expression on?
This (http://tinyurl.com/3bjz43) is my original maya .ma file (~85k). (recommanding using Firefox, but IE would work as well)
07 July 2007, 05:48 AM
Select your objects and type in -
sets -e -forceElement ShaderNameSG;
Or just select your objects, open the hypershader and with the objects selected just right click on the main shader and hit "Assign Material to Selection"
07 July 2007, 08:07 AM
Hi, thanks for the reply but this is not what I need.
I'm asking how to write an expression that can dynamically allocate different ramp values to multiple objects using just a single SG. I.e., the ramp value of this single SG will alter based on different objects.
sg.ramp.uValue = 0.05 ----> object1
sg.ramp.uValue = 0.10 ----> object2
sg.ramp.uValue = 0.15 ----> object3
sg.ramp.uValue = 0.20 ----> object4
sg.ramp.uValue = 0.25 ----> object5
Thus an expression will be tied to sg.ramp.uValue, whereas this value will be based on a custom attribute (eg. ".trans") in object*.
07 July 2007, 11:14 AM
for that you need to look at tripleShadingSwitch (for color) then write an expression to set the value of the shadingSwitch to be a random number of the ramp.
The rand fonction do just that as you probably know.
Put it in a loop and you'll have a different number for each object.
hope it helps.
07 July 2007, 11:58 AM
Actually for your question, sorry I misread it.
If you want the object to sample the color on one ramp, you need to use the simpleSadingSwitch.
Connect the output of this one to the VCoord of the ramp itself, then connect the ramp to the color of the shader.
Clicking on the add surface of the shading switch will show all the object that the shader is assign to.
Then you need to put a value on the .input of the shadingShitch.This value must be inbetween 0 and 1 to be able to sample the 0to1 value of the ramp.
You can do it dynamically by adding a new attribute to each object connected to the shading switch and connect that float attr to each corresponding input of the SSwitch.
Then changing this attribute on each object should change the color of the object for the corresponding color sample on the ramp.Meaning a 0.5 value will sample the middle of the ramp.
this should put you on the good direction.
You could them assign a rand value comprise between o and 1 to each attribute using mel.
ex:Select all you obj:
string $myObject =`ls -sl`;
for ($i in $myObject)
//create a random value
float $randvalue =rand (0,1);
//set each attribute with that random value in that case the attribute is name "VrampAttr"
setAttr ($i+".VrampAttr") $randvalue;
hope this one help.
07 July 2007, 03:13 AM
pretty close to what I need, but I guess I didn't get it.
How do I "assign" a custom attribute from the object and connect it back as the input of Simple Switch?
I did following the tutorial in Maya about the Simple Switch, did a bump map, but as supposed to assigning an new "external" shader connected to it, how do I use an internal custom attr from the object itself?
This is the tutorial I refered to:
07 July 2007, 06:15 AM
well simply add a new float attribute to your object and use this one as your input on each object for the switch utility as explain above.
Your float attr must be a 0to1 attr for the ramp to read it correctly.
check the addAttr command for adding attribute to your object in mel.
Or modify->add attribute in maya
07 July 2007, 06:17 AM
Many thanks. I think it's working now. :)
07 July 2007, 03:11 PM
great, glad i could help, this is really something not a lot of people use, but it's very powerfull and usefull.
07 July 2007, 03:11 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.