How to distort the camera image to neutralize perspective distortion when tilting the phone?

Hi!
I’m new to Godot and graphics programming and I need help implementing this effect.

Suppose I have a cube in a 3d world and I am displaying it on the screen of my mobile phone. If the camera in the 3d world is positioned right above the cube I will see a square. When I rotate my phone and the image on the screen stays the same, my eyes will of course perceive the square as trapezoid because the screen is tilted.

How can I distort the image on my phone screen to counteract the deformation of a square into a trapezoid as perceived by my eyes and as caused by tilting the screen? I hope the attached doodle helps to illustrated what I mean.

To simplify, let’s assume that the eye (let’s just look with one eye) is right above the center of the screen, at a distance of 40 cm. Let’s also assume I know the orientation of the phone in the real world.

I figured that I could calculate the real world coordinates of the corners of the phone screen relative to the eye, project these coordinates onto a 2d image my eye would see and then interpolate the image caught by the camera in my Godot level to counteract the perspective deformation. Do you think this is the right way to go?

Or is there a way I can define a custum frustum that will distort my cube to the trapezoid I need to display?

Any pointers will be appreciated. Also, is there a name for this effect? Google AI said “magic window” but I did not find any meaningful resources with this wording.