Changing Shading Groups Or Materia Shaders

Hi everyone!

Yesterday I was tryin to make an expression that changes surface material in dependence of "if" condition. Nothing worked.
Problem is in that i don't know correct operations, and finished up with

{blinn2SG.surfaceShader=blinn1SG.surfaceShader;}

but, of course it is wrong.

So whether its better to change a shading group or just the material within it? And please give me body { } for that operation.

I would be very grateful if you also give me some explanations on it.

Depends on what you need... i can se 3 cases, and 6 solutions for some of them, cases are

  • your interested in having different viewport feedback material and swap them for the renderer
  • You want to implement render layers yourself
  • you want to animate the material
  • In either case you do not want to use a expression for any of the above operations. Least of all for the 3rd option, because that is just not going to work out. (reconnection will not affect anything once the frame starts rendering)

    Pick one or clarify. Then i can help you.

    PS: expressions cant affect connections, entire dg shouldnt touch connections (atleast on sg level), expressions can only reroute the default numeric types. (however there is a node that can, but you only want to use it for option 1 even then thats a questionable choice)

    Well i really tried to be clear, sorry.

    I want to animate the material.(for ex. about 300 objects within same shading group. I want to switch shader atrributes for certain object when null object passes near it.)

    I decided to switch material shader for object when "if" condition is true;

    Actually I did it via -Hypershade -assign, but it don't render.(only viewport feedback works the way I want);

    Ahh, then definitely you do not want to switch the shadinggroup. Do you understand how the shading engine works? And do you understand how it does not work for things such as mentalray. As mentalray will not see anything thats inside maya, and expressions wont work for mentlaray (because its inside maya not inside mentalray, however the exporter does bake down the prerender state to mentalray attributes, but that only affects in the end of chain per attribute things, and no per shading, not this attribute must shade something that mental ray accepts a s a color source, if you use MR that is. Sometimes they must be baked into anim curves so mr gets it right tho.).

    Unfortunately theres not much more options here than to understand quite a bit in order to get this to work properly for you. I wish people would actually test their hypotheses BEFORE they start doing the sytuff its much easier to get things to work when you design your stuff up front preoperly.

    Now, you might get into problems of updating your render (remember batch isnt the same program as the one you run the graphics in!)

    Anyway theres several options a bit depending on what you want,

    if you want a per object attribution, then make a triple shading switch which you connect each objects translate to its own shading slot (for this you will need a for loop), then run this into a plus minus average node, connect your locator to slot 2 run this out to a multiply divide node, into both inputs. Then run thsi into a second multiply divide node, set mode to power and second term to 0.5 0.5 0.5, the output of this now represents each objects distanc to the locator you can now connect this to ramp or rewmap to drive your per shading primitive values.

    If you want the point without per object discard the switch. connect sampler info in instead.

    PS: expressions arent mel!

    PPS: its alltogether different to help people to do their job, against doing it for them. Any questions fine but i wont do your job for you, neither should you expect anybody either. Dont push your deadline on other people, they either answer you or not, deadline is your problem and yours alone sorry . See advice free is free, but also free of any obligation to you or anybody else for that matter. Its alltogether different if you hire somebody to do the job.

    Thanks for an answer.

    Im very sory if it looked like pushing my deadline to anyone, or tryin to make anyone to do my job.

    Dont be im just saying its a bit unfair on anybody who answers. Especially since it does push pressure on us. We answer because we like it so form a purely effectivity onlook its possibly best not to mention anything about the bad sides of work. The minute we feel its too suchlike work we might and often will withdraw.

    See its not so nice to start a thread where you know you have possibility to fail up front. See we hang on forums because theres other people willing to learn and share with us, but a contributor who is only interested in it works is no fun at all.

    Hell even philosophy debate that aggravates you out of your wits gives you something We are here for knowledge, information and company.