Mateusz Zelent avatar image
Mateusz Zelent asked ·

How to get object rotation (orientation) to change color.


Is it possible to get object rotation or space orientation?

I would like to know what is current object orientation / rotation in space and then based on this data I would like to change the color of this arrow. Is it possible to do?


I tried to use the UV pointer to get information when an object is, for example, turned down or down. But it works quite badly.

point UV = transform("object",point(u,v,0)),

In fact I would like to build similliar shader like I have in Blender:


In Blender, Vector Transform works perfectly.


I wrote simple shader:


and partially it works, but its space-dependent colorization, not rotation.

x = Pos[0]-vec[0]-UV[0];
y = Pos[1]-vec[1]-UV[1];
z = Pos[2]-vec[2]-UV[2];

This code is "brute force testing", but at this moment it works quite close to this what I would like to achieve.

1616876229197.png (66.3 KiB)
1616876240566.png (14.0 KiB)
1616928454011.png (570.8 KiB)
1616928480961.png (577.0 KiB)
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

1 Answer

· Write an Answer
Mads Drøschler avatar image
Mads Drøschler answered ·

I would say that you could just tap into the shading normal in world space instead.


Will always return a face direction based on the face currect alignment in world space.
Next you want to take a measure of how much this normal deviates from an "up vector" normal which is a normal taken from a default position.


We also have the practical to-camera normal. Bit what you attempt to solve with "I" the hit ray.
You could use this as well.

Calculate the difference and return this as a float value for hue.

Do note this needs to happen in worldspace -1 to 1. Where if your arrows point into negative space, it will be black.

www.pngSo and you want to make 3 calculations, for each axis, and rotate them.
you can use rotate(); its a core OSL function.
So that the hue position aligns on all 3 axis, and thus if you build a vector from these 3 floats, it will return the same color and make the object 1 solid color.

After this, you would want to move it into 0-1 space so you get a visual sampling the negative space.

You can also map it out to 6 debug colors, since RGB is not enough to visualize a position in space, this is why a world space normal will never show the negative direction since its not possible to derive, so you create 3 complementary colors for the negative space.

You will never be able to use only RGB only on a 360 dependant scheme, unless you compress it into 0-1 space, but that wont return RGB, it will return 50% of that in the positive space and 50% in negative space. So some artistic debug color needed.

I would use Magenta, Yellow, and perhaps Petrol green.

cc.pngOr, simply just reverse the normal so the positive lies in a normal blue/green spectrum, and the negative lies in a red/yellow.

ccc.gif (498.1 KiB)
eee.gif (359.6 KiB)
www.png (15.4 KiB)
cc.png (153.8 KiB)
eee.gif (891.6 KiB)
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Welcome to the Arnold Answers community.

This is the place for Arnold renderer users everywhere to ask and answer rendering questions, and share knowledge about using Arnold, Arnold plugins, workflows and developing tools with Arnold.

If you are a new user to Arnold Answers, please first check out our FAQ and User Guide for more information.

When posting questions, please be sure to select the appropriate Space for your Arnold plugin and include the plugin version you are using.

Please include images, scene and log files whenever possible as this helps the community answer your questions.

Instructions for generating full verbosity log files are available for MtoA, MaxtoA, C4DtoA, HtoA, KtoA, and Kick.

If you are looking for Arnold Documentation and Support please visit the Arnold Support site.

To try Arnold please visit the Arnold Trial page.

Bottom No panel present for this section.