How to squish an object along camera's facing axis?

I want to take a 3D mesh and squish it along the camera’s facing axis inside a shader without changing the position of the object.

The left side is a mockup of the result I need to produce. The right side is just to show that this teapot is being squished along the camera’s facing axis.

I’ve been trying to wrap my head around matrix math for the last couple days and got kinda close but I’m losing my mind trying to maintain the position of the object.

Any help would be appreciated!

I think just apply camera projection matrix to the local vertices position? and you can make teapot thinner by increasing the distance between near/far planes of your projection matrix.

Now, one thing I am not sure about is whether you should divide the xyzw vertices by w after the local–>projection transformation. Recall that division by w just takes your squashed frustum (and in fact all the Ether (aka air) around it in a similar manner) volume and deforms it into a squashed box, which results in perspective-effect

Also, I am not sure if the near-plane should be very-very close to the far plane.

You can then multiply the result by the final MVP like usual.

If my assumptions were right, the teapot should squash, but always in one direction. To make it squash relative to the camra, you will have to build the rotation look-at matrix by pointing it from the pivot of teapot in local space to the pivot of camera in teapot’s local space. You can bring camera into teapot’s local space by multiplying camera gameObject’s world position by the inverse of Model matrix of the teapot

Your steps would then look like: localSpace --> apply look-at rotation (perhaps inverse rotation?), --> apply projection.

We basically need to postpone displacing the teapot from its zero-th coordinate. Recall that all squishing and squashing (just as rotation) always happens relative to ZERO.

Teapot sits by default at zero. After were to apply Model matrix, it would no longer sit at zero. Wherever it would sit after that matrix is what we reffer to as “its world position”. That’s why rotations usually done before displacement, otherwise object will be orbiting the zero. It affects projections as well.