5
  • The Object Info node gives me access to the location of the shaded object('s origin) in World Space
  • The Texture Coordinate node gives me access to the coordinates of the shading point in the Object Space of any object.

How in a shader tree, could I retrieve the location of the shaded object in another object's space? For instance, the location of the shaded object in its parent's space?

Somehow apply the parent's inverse transform to the Object Info > Location?

Robin Betts
  • 76,260
  • 8
  • 77
  • 190
  • 1
    Subtracting Combine XYZ (drived with parent world coordinates) from Object Info - is not what you are looking for? – Serge L Mar 11 '19 at 05:56
  • @Serge L That is a partial solution, yes, as long as you can be sure that only translations are involved? Maybe the best that can be reached conveniently. It just seems odd to me that location isn't available in other bases.. you could do it in OSL, I think, if Cycles had it fully hooked up.. you could get to the transformation matrices of named objects.. but I don't think it's there, in the Cycles implementation. – Robin Betts Mar 11 '19 at 06:23
  • @Serge L maybe rotations are all that screw it.. by taking the transformed 0,0,0 and 1,1,1 you could deal with translation and scale... – Robin Betts Mar 11 '19 at 06:40
  • 1
    Too bad, it is currently not implemented. You can track it here : https://developer.blender.org/T52154 . Related question : https://blender.stackexchange.com/questions/81793/location-of-object-in-osl – cppBeginner Jul 17 '20 at 01:21
  • @cppBeginner Thanks for bringing me back to this question! I'd forgotten it. Not in OSL.. it doesn't provide the space of a named object? But ordinary shader nodes can do it.. see answer. – Robin Betts Jul 17 '20 at 07:54

1 Answers1

6

I was being dim.. to return the location of object A in the space of object B, in all A's shading points:

enter image description here

Here, 'A' is the shaded object, 'B' is an Empty.

Robin Betts
  • 76,260
  • 8
  • 77
  • 190
  • 1
    Wow. Thank for sharing. Do you know any other nodes that receive Object as input besides "Texture Coordinate"? e.g. Is it possible to get the object name in string? – cppBeginner Jul 17 '20 at 08:13
  • 1
    Don't think so, other than self ... there's Object Info > Location, (which I could have used here) and Camera space is available via Camera Data, ( So, for example, you could tell where the camera is, without using drivers, the way many people do.. I think I've done that myself..) – Robin Betts Jul 17 '20 at 08:23
  • Isn't this the same as TextureCoordinate().Object + TextureCoordinate(Empty).Object? – ArtBIT Jan 19 '22 at 14:10
  • 1
    @ArtBIT True! :D.. (with a flipped sign, but I see what you mean ) Addition and subtraction are associative, so it's the same as TextureCoordinate(Empty).Object - TextureCoordinate().Object. I think when I answered I was going "kerchunk.. kerchunk" getting the positions and then subtracting. Object Info > Location would do for the first chunk, too. However, the whole thing fails under relative rotations, so nowadays a better way might be to use Geometry Nodes and feed the location out as an attribute? – Robin Betts Jan 19 '22 at 16:58
  • 1
    Right, I forgot to negate the first arg. I guess I was also going "kerchunk... kerchunk" :P Geo nodes are one way to do it, yeah, but sometimes you want to do it purely in shader nodes. – ArtBIT Jan 19 '22 at 17:15