Is there an Object Rotation Material Node?

I found the solution on this Japanese blog post:

Add a custom node with these contents to retrieve a Float3 containing the object’s rotation in radians (recommend making this a material function):

float3x3 WtoL = LWCToFloat(GetPrimitiveData(Parameters.PrimitiveId).WorldToLocal);
float3 R = float3(
atan2(WtoL[2].y,WtoL[2].z) * -1.0,
asin(WtoL[2].x),
atan2(WtoL[1].x,WtoL[0].x)
);
return R < 0 ? 2 * pi - abs(R) : R;

In this case, pi is an argument to the custom node. (the pi node is being plugged in)
To convert to degrees, multiply the result by 57.2958.

Note that if you want to use this in the “RotateAboutAxis” material node, Component Mask out the degrees value of, for example, B (yaw), divide by 360 (RotateAboutAxis uses a 0-1 scale for rotation), and input it into RotationAngle. Add the result of the RotationAngle node to the initial vector that you’re rotating in order to acquire the final rotated vector.

Edit: It looks like the above code is returning an incorrect Y value. Refer to this thread for more details: Get Actor x, y, z rotation angle in shader - #6 by mpxc

1 Like