Community
Arnold General Rendering Forum
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

1 REPLY 1
Reply
Message 1 of 2
mz52720
328 Views, 1 Reply

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

Hello,


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?


1616876240566.png


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:


1616876229197.png

In Blender, Vector Transform works perfectly.



EDIT:


I wrote simple shader:


1616928480961.png


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.

Tags (1)
Labels (1)
  • OSL
1 REPLY 1
Message 2 of 2
madsd
in reply to: mz52720

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

transform("world",N);


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.


eee.gif
transform("object",N);


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.
eee.giftransform("camera,"N");


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.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report