Difference between camera direction vector and object normal vector in material.

Hi guys

Are it possible to get value which define the difference between camera direction vector (or maybe i can say - camera normal?) and normals direction of object in material?

Sounds like you could use the dot product between the camera direction vector and the object’s vertex normals (or perhaps pixel normals). If you inverse the camera direction, the dot product will describe how aligned the vectors are. 1 = fully aligned. 0 = 90 degrees off. -1 = 180 degrees off etc.

you can also just use the Dot Product. No need to invert the Direction Vector.
Dot Product will then retun 0 (aligned) and != 0 (not aligned/orthogonal)

Thanks guys!

Unfortunately - i was wrong :frowning: That solution doesnt help in fact. Im imagine all of thet in the wrong way.

The final goal which im trying to achieve is to know when the object move off screen. For example - we look straight at the object = color is red, object move to side of the screen (left, right or top, bottom) = object becomes green.

It looks like Object position node gives me what i want, but i cant figure out how to convert the ViewportUV to proper values, like 0 - if object are center on the screen, and -1 if object on side of the screen.

Use “TransformPosition” with the VertexPosition (you can also use ObjectPosition if thats enough).
Transform from WorldSpace to CameraSpace (NOT View Space).

Currently not sure but either it transform to the Viewport Coordinates (from 0 to 1920 in Width for example)
or to the Device Coordinates (-1 to 1). You have to exeperiment here.

You can then easily lerp the color depending of the position in Camera Space

Yeah! Look like that may works. Thank you :slight_smile:

If someone will search for similar solutions, here’s the final shader:

TransformPosition node should be:
Source: absolute world space
Destination: camera space[SPOILER]


1 Like

Just to add, instead of doing the above, this can easily be done and be controlled with a Fresnel node. It does exactly that. I know this is old but I stumbled upon this and wanted to drop this hear just in case anyone or I myself stumble upon it again. :smiley: