I am trying to develop several shaders that need to take into account the position or orientation of another object in my scene. Seems like a generally useful thing to be able to do.
Here's an example of something that almost does what I want (for a simplified case). Here is a Cycles shader node tree that will shade an object green for points that are more than 1 unit from the origin and red if they are less than 1 unit from the origin.
And here I'm moving a cube with the material close to the origin to see the effect.
Here is the crux of what I am looking for... Rather than having the origin be the source of the red colored region, I would like an Empty to be the center of the red colored region. And I would like to move the Empty around rather than the other objects to control the effect. Thanks!
The .blend file for my example can be found at...
http://readyposition.org/PositionBasedShader.blend
I can use a geometry node to get things like normal and position from the shaded object. But I'm unsure of how to get properties from the other object.
I have just started down the road of using drivers. I figured I could create a custom property on the shaded object and add a driver that sets it to the other object's properties. Then I'm hoping I can use an Attribute node to get at the custom property.
However, I'm at a loss how to best do this via the UI. In particular...
- Can I add a custom property for a vector quantity (e.g. position)?
- Can I create custom property groups so I can add drivers to x, y, and z at once (as the built in property groups for things like position, rotation, and scale have)?
- Do I need to do x, y, and z separately and then convert them to vectors with a Combine XYZ node?
- Can I even refer to a custom property via an Attribute node?
- Do I need to resort to Python?
- Can this be done at all or do I need to find some other way with multiple passes?
If someone can provide an extremely simple example for Cycles it would help me a lot. How about a shader for a UV Sphere where the sphere is green where it is within 1 blender unit of an Empty and red where it is more than 1 blender unit from the Empty? Can even just be in x to make things simpler.