7

I have an object, and I would like to project an image onto it within its material, using the camera view. I want the projected image to remain centered on the object even when I move either the object or the camera.

However, it's important that this projection remains orthographic. Therefore, the projection is not a direct line between the camera's position and the object's position, but rather based on the 2D position that the object occupies within the camera view space. (I still want to render the object in perspective tho)

enter image description here

By now I only managed to do it in a perspective way, I also make the image grow and shrink based on the distance from the camera :

enter image description here

enter image description here

What I want is this :

enter image description here

The circle image must stay at the center of the object, and scale according to how far it is.

Also I think my method for scaling based on the distance between the camera and the object is also wrong because it's using the camera position and not a point corresponding to the object postion on the 2D camera view space (I hope I'm clear ).

Thank You !

1 Answers1

10

This approach calculates the direction from the camera to the shading point, as if the object was at (0,0,Z) in Camera space, by subtracting the object's location in Camera space from the shading-point's location in Camera space, all normalized.

The coordinate is further offset by 0.5 to put the origin at the bottom left of Image-space:

enter image description here

.. prior to the offset, the coordinates are scaled by distance-from-camera, so the image gets smaller as the surface recedes, with this kind of result:

enter image description here

The texture is still subject to fisheye distortion, along with the geometry, through a wide-angle lens.

Edit:

On second thoughts, to be strictly orthographic-per-object, it would probably be better to scale by object-distance than by surface-distance:

enter image description here

The visual difference is subtle unless close-up wide angle, but you may prefer it.

Robin Betts
  • 76,260
  • 8
  • 77
  • 190
  • Hello! Thank you for your answer! This works great in almost all cases, but I noticed an issue when the focal length of the camera is really low; the texture starts to distort severely at the edges. I am not a vector expert; do you know why this happens? – Valentin LARRAS Jan 27 '24 at 21:25
  • You're looking at an ortho projection onto the surface alright, but then you're looking at the surface through a perspective lens. Not sure how to get around that.. perhaps there's a way, using drivers, in Window space.. but I'm not sure.. if only that was one of the options in Vector Transform – Robin Betts Jan 28 '24 at 09:48