PapaBlueMarlin opened this issue on Aug 18, 2006 · 87 posts
bagginsbill posted Tue, 22 August 2006 at 8:01 PM
Ah now I understand.
You tried to add it to this:
ApplyBruise(c.Head, Add(.4).labelled("PM:Bruise U"), Add(.525).labelled("PM:Bruise V"),
Add(.07).labelled("PM:Bruise R"), Add(0).labelled("PM:Bruise Blend"),
)
This is the invocation of the "ApplyBruise" function that I made for that script. You are trying to pass an extra argument, but there is no parameter in the function declaration to receive it. Have I overwhelmed you with computer jargon? I tried to covere this in the manual where I "gently" introduce you to Python.
We can do one of two things:
Add a parameter to the ApplyBruise function, so you can pass the argument.
Just forget about the parameter - build it into the function automatically.
The latter is quicker, but less flexible. It all depends on how you want to use the function and the resulting shader.
To add a parameter to the function we could do this:
def ApplyBruise(s, cx, cy, br, maxblend, graniteamount):
Then inside we have to figure out how to use the graniteamount value.
To my mind a very simple way is to just use it to blend between two alternatives. We just need to change one line - the place where you create the granite:
myGraniteNode = Blend(WHITE, Granite(myNoiseNode), graniteamount)
Blend takes two values and blends them using the third. It will generate a Blender node, most of the time. However, if Matmatic sees that graniteamount is always 0, it will skip the blend and just use WHITE. And later when you multiply bruiseclr * WHITE, it will reduce that to bruiseclr. In other words, when you turn things off, Matmatic will optimize away crap you don't use in the shader. Cool huh?
If you pass an Add node for the argument to graniteamount, then Matmatic can see that it is not constant - it can change. So it will produce the Blender node and wire it in.
Now you can add the additional PM value to the invocation with all the others.
Now for the coolest part. Because we wrote the ApplyBruise function in such a way that it just adds some more stuff to the Alternate_Diffuse shader tree, you can call it MORE THAN ONCE!
For example, if you want a matched pair of bruises separated by some distance, you could make yet another function:
def ApplyBruisePair(s, cx, cy, br, separation, maxblend, graniteamount):
ApplyBruise(s, cx - separation/2, cy, br, maxblend, graniteamount)
ApplyBruise(s, cx + separation/2, cy, br, maxblend, graniteamount)
Then change your call at the bottom from ApplyBruise to ApplyBruisePair and add another argument for the separation parameter, which you probably want to be a PM value.
Renderosity forum reply notifications are wonky. If I read a follow-up in a thread, but I don't myself reply, then notifications no longer happen AT ALL on that thread. So if I seem to be ignoring a question, that's why. (Updated September 23, 2019)