How can I get the camera vector in worldspace in a material?

I wanted to create a material that would give me the angle in radians in X and Y between the camera and the object the material is applied to. (I wanted this as a basis for a effect that would change depending on whether I looked to the left, right, top, or bottom of the object).

I’m not a programmer so I wrote down the calculations I thought I’d need in order to get this to work.
Basically I figured I would need the WSposition of the object and the WSposition of the camera in order to get the WSvector from the camera to the object.
And I would need the WSvector of the camera.
Then I could just just normalize those vectors and use a asin to get radians for both of them in WS, and subtract one from the other in order to get the angle in rad between the cameraforward and the direction of the object.

Problem is, apparently for some reason Camera vector gives your the vector of the camera compared to the normal of each pixel? And I have no idea what “cameradirectionvector” does but not what I thought it would.

Is there a way to get the rotation of the camera in a material blueprint or is there something I’m missing? I’m guessing I might be able to do it by making it a dynamic material and driving a few parameters through blueprints but since you directly have the “cameravector” node in the material blueprint editor I figured it should logically be possible there as well, or is there a reason that’s not possible?

Any help would be greatly appreciated

Thanks for the reply, I did use the actor position for the object itself, and that works just fine, and camera position is great for getting the position of the camera.
But I also need to know the direction the camera is looking at and the position doesn’t tell me that.
I figured camera vector would, but from what I can tell that gives me the camera vector in local pixel space.

(I know I don’t know the official terms, trying to improvise).

There are multiple nodes in material editor dealing with camera position and “Camera vector” is not what you need, you should use “Camera Position” which gives you the camera position in World Space and also for getting your object position you should use “Actor Position” node instead of “Absolute World Position”. Hope it helps

Could you describe what you want to achieve with an image?

Actually I’m not much expert at shaders but I can suggest two other methods that you may find them useful.
There is a “Transform Vector” node that can convert different spaces to each other.
Also you can drive any material parameter that you want from blueprints. So you can calculate your data and feed it in the material as a simple “Scalar Parameter” (Set Scalar Parameter)

Sure, I wanted to learn how to work with custom nodes for shaders in unreal. I figured out how to do some basic glsl shader programming with shadertoy last week and I figured it would be a good exercise to try and get that to work using custom blueprints.

The shader was a simple emoticon that would look left/right/up/down depending on the position of your mouse. I couldn’t really do that in standard unreal (with the fps character) since your mouse is basically locked at the center of your screen, but since it was just a test that didn’t really matter, I just needed two values between -1 and 1 that would drive that particular variable.

I figured that I would drive the variable by where you were aiming at (where the camera is pointing towards). So if the material was on a plane, and you looked to the right of the plane, the emoticon would look in the proper direction.

I thought the easiest way to do this would be to take the vector from the camera position to the object position, and the forward vector of the camera. If I had those two, it would be easy to figure out the relative rotation of the camera vector in radians using “asin”. Which I could in turn use to drive the emoticon.

Yeah I think driving them through regular blueprints with a dynamic material should work, just wondering how I could get it to work in just the material.

I’ll look into Transform Vector, thanks a lot for the help.