# Change object color depending on camera rotation

Say that I have a cube. I'd like for it to change into one of 5 colors: black, red, green, blue, or white depending on which direction the camera is facing towards it.

If the camera moves to face the cube's right side, for instance, it will turn green. The same concept applies with the other parts (front, back, and left), each color blending into the other. The cube then would default to white if the camera faces either the top or bottom.

See the gifs below:

The cube would be free to rotate on its own without having to worry about its color changing. It would only be the camera that would affect it.

How could that be done in Blender (specifically EEVEE) using nodes/drivers? I really don't want to use scripts if I can avoid them.

EDIT:

I should probably add that the closest I've gotten thus far is in separating the Incoming vector (from the Geometry node) into separate color channels, however it poses this issue:

It's so irritatingly close to a solution, yet the lack of solid coloring renders it useless for my purposes.

• You may find something here related to Camera Data "View Vector" blender.stackexchange.com/a/132840/111042 Oct 26, 2021 at 20:14
• @james_t Yeah, I was actually looking at that! However, I can't use it like I said in the edit. From what I can tell, vectors (and therefore nodes by association) aren't the way to go for something like this, as a gradient of that sort is an inevitability with them. Drivers seem to be the only way. Oct 26, 2021 at 20:30
• No apology needed :) So the object could spin as much as it liked, but would always be red, say, if it was being looked at from positive world X direction? Oct 26, 2021 at 20:51
• @RobinBetts That is correct! Oct 26, 2021 at 20:54
• @RobinBetts After fiddling around with it for a bit longer, I noticed that if you have multiple objects in different areas, they all have different colors. I found one solution via attaching an empty to the camera and using its coordinates, but if there's a better way you can think of, feel free to let me know! Thanks again. Oct 27, 2021 at 2:50

The point (0,0,0), converted from Camera Space to World Space using a Vector Transform node, is the location of the camera in World Space.
You commentary tells me you're interested only in the World Space orientation of the camera, regardless of the shaded object's location. That's simpler. You just have to get Vector Transform to convert the Camera-Space vector (0,0,-1) (its viewing axis,) to World Space: