View Full Version : multiple colored shader
Scott212 11282004, 03:31 AM I'm looking for a hint to the shading network it would require to create a shader that can change color in different places on the surface. Such as, a nurbs plane that changes from red to green only in a certain place based on a condition. For instance, if a ball rolls down a green plane it leaves a red trail behind it. I just can't figure out how to have multiple colors on one shader that's locations or patterns aren't predefined. Any clues?
Cheers ya'll
Scott


Tallacus
11282004, 11:14 PM
layered shading...........
I can maybe get you half way there. I know a way to make the shader color dependant on the relative locations of two or more objects. So in your example with the ball rolling down the green plane it is possible to make the plane red near the ball  but Im not sure how to make it stay red and leave a trail as the ball moves away.
Basically you need a samplerInfo node (called si in the example) and an expression to choose a color from a ramp texture.
The main part of the expression is:
ramp1.vCoord = sqrt((sphere1.translateXsi.pointWorldX)*(sphere1.translateXsi.pointWorldX)+(sphere1.translateYsi.pointWorldY)*(sphere1.translateYsi.pointWorldY)+(sphere1.translateZsi.pointWorldZ)*(sphere1.translateZsi.pointWorldZ));
but I am oversimplifying things a bit. The expression is calculating the distance between the center of the sphere and the point on the plane being rendered, then using that distance to choose where on the ramp texture to get the color. So in practice you need to normalize the distance to be between 0 and 1 (which can be done using a setrange utility node).
All of the above I learnt from a tutorial but it was several years ago and I have forgotten where I found it. However I still have the scene file that I ended up with. In it, a spider walks across a plane and the color of the plane changes as the spider moves its feet. I am happy to pass this on to you if you think it would be of help.
Scott212
11292004, 05:58 AM
hey thanks for your info, it's a great help. I'm trying to break down your expression since I also found a very similar expression in a scene file from highend3d that does the exact function of what I'm trying to do. So it seams common. If you find that tutorial that would be great, maybe some further explanation on the expression. The file from highend3d is 'expressiondriven distance shader v1.1'. Very cool shader setup. Thanks again!
thematt
11292004, 11:28 AM
All of the above I learnt from a tutorial but it was several years ago and I have forgotten where I found it. However I still have the scene file that I ended up with. In it, a spider walks across a plane and the color of the plane changes as the spider moves its feet. I am happy to pass this on to you if you think it would be of help.
ok the tut you're refering to is a shader available at Alias, don't remenber which one but you can find it in the appropriate section.
this can be done with the distance between and closestPointOnSurface node.
But to let the color active that's a lot more complicated...
cheers
The expression uses the samplerInfo node to get information from the surface as each pixel is being rendered. The attribute called "pointWorldX" is the world X coordinate location of the point on the surface being rendered. So the expression is simply using the old pythagoras theorem to compute the distance=sqrt((x1x0)*(x1x0) + (y1y0)*(y1y0) + (z1z0)*(z1z0)).
You can use a ramp shader as a source of color. Its quite common to connect the facingRatio to the vCoord to do the toon shader thing. But the facing ratio nicely fits between zero and 1, where as the distance most probably doesnt. So in paractice you would connect something like the setRange node between the expression and the ramp. You can use setRange to squash the distance to fit into the zeroto1 range.
Im not sure if I am explaining this well. If you want the scene file, let me know and I will email it  although it sounds like that distance driven shader you have is almost doing the same thing.
One difference might be that the spider has eight legs. The expression uses and array to store the distance to each of the 8 feet, then works out the shortest, and uses that.
Scott212
11292004, 11:22 PM
this is great information guys, thank you so much! Excuse my slow response because I'm digesting it all...
cheers
CGTalk Moderation
01202006, 01:00 AM
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.