5
$\begingroup$
  • 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?

$\endgroup$
5
  • 1
    $\begingroup$ Subtracting Combine XYZ (drived with parent world coordinates) from Object Info - is not what you are looking for? $\endgroup$
    – Serge L
    Commented Mar 11, 2019 at 5:56
  • $\begingroup$ @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. $\endgroup$
    – Robin Betts
    Commented Mar 11, 2019 at 6:23
  • $\begingroup$ @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... $\endgroup$
    – Robin Betts
    Commented Mar 11, 2019 at 6:40
  • 1
    $\begingroup$ Too bad, it is currently not implemented. You can track it here : developer.blender.org/T52154 . Related question : blender.stackexchange.com/questions/81793/… $\endgroup$ Commented Jul 17, 2020 at 1:21
  • $\begingroup$ @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. $\endgroup$
    – Robin Betts
    Commented Jul 17, 2020 at 7:54

1 Answer 1

7
$\begingroup$

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.

$\endgroup$
5
  • 1
    $\begingroup$ 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? $\endgroup$ Commented Jul 17, 2020 at 8:13
  • 1
    $\begingroup$ 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..) $\endgroup$
    – Robin Betts
    Commented Jul 17, 2020 at 8:23
  • $\begingroup$ Isn't this the same as TextureCoordinate().Object + TextureCoordinate(Empty).Object? $\endgroup$
    – ArtBIT
    Commented Jan 19, 2022 at 14:10
  • 1
    $\begingroup$ @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? $\endgroup$
    – Robin Betts
    Commented Jan 19, 2022 at 16:58
  • 1
    $\begingroup$ 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. $\endgroup$
    – ArtBIT
    Commented Jan 19, 2022 at 17:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .