get the line of sight vector with nodes

I would like to make a material that displays the line of sight vector using the RGB channels : for example, here, let's say i am looking from the camera, the line of sight vector would be : →E(X=0; Y=1; Z=0)

so the sphere should appear all green.

Also, i wanna precise that I don't want it to use the camera (the object) orientation but the viewport.

I think the vector transform node would help, i found this thread in which the material displayed the rotation of the object so i think it could help : Change color with object rotation

If you just want the line of sight of the camera, (regardless of where the sphere is in the view,) this will do it:

But, of course, the colors will go black when the line of sight goes negative. You may want to map the -1 to 1 range in each dimension to something more to your liking.

• It works well, thanks to both of you. (lol the thread i linked gave a really close setup) Apr 9 at 18:19
• @alexth91 I was just thinking.. you could signify 'negative' with a texture, or transparency, or someting other than color. Apr 9 at 18:23
• aight thx, english isn't my native language so sometimes i have trouble explaining things like this one (also how do i give a reputation point ?) Apr 9 at 18:26
• Click the little up and down triangles next to the answer, and tick the answer you think best meets your requirements. Apr 9 at 18:30

Use a camera data/view vector node. Because this provides a camera space vector, you can use a vector transform node to transform it into a world space vector like you want.

The "camera" being referred to here is not the camera I have in the scene-- notice the axes and camera position, notice that the same sphere is different colors in different viewports. The camera being referred to is whatever eye is looking at the scene. In the case of a render, that's the camera, but in the case of a viewport, it's whatever your viewport is using as a "virtual" camera.

Another way to do this, in Eevee, is to use geometry/incoming, then reverse the vector. In Eevee, the incoming is vector is always the view vector (but reversed, to point at the camera.) In Cycles, this vector doesn't always refer to the view vector, but instead refers to the most recent direction any particular ray that hit the object took.

• thank you @Nathan but with this node setup the object doesn't have a single color : image Apr 9 at 17:27
• what i would like is that the object only has a single color on it Apr 9 at 17:49