- Home /
Custom Camera Projection Matrix that "Horizontally Compresses" worldview
Hello everyone. I'm trying to create a camera with a custom projection matrix that will result in the rendering that it produces to be compressed horizontally, preferably by a factor of two. The reason is that I have a head mounted display and two cameras rendering in each eye, and they take up half the screen; as such, they need to produce a horizontally compressed view of the world in order to render correctly in the head mounted display. I'm terrible with matrices, so what kind of Matrix4x4 would I use to solve this problem? Thanks!
Answer by xavierwielemans · Jun 17, 2013 at 01:15 PM
Hi Darkyoddd, I suggest that you use the "off-center projection" example from Unity itself: http://docs.unity3d.com/Documentation/ScriptReference/Camera-projectionMatrix.html
It allows you to independently set the opening angles of your rendering cam in the four directions (top, bottom, left and right).
In your particular case, keep left = -right and top = -bottom in all cases, and adjust left and top to match the opening angles you like, in the horizontal and vertical direction. Using a fixed left value, increasing top will compress the rendered image horizontally.
Hope this is what you were looking for...
Cheers!
Willy
PS: be aware that using custom projection matrices will prevent you from using the following: - skyboxes - deferred shadows - render-to-texture (=> several post-processing image effects)
PPS: A much simpler solution might be to just modify Camera.aspect on your cam (no custom proj matrix involved)... http://docs.unity3d.com/Documentation/ScriptReference/Camera-aspect.html
Let me know...
Hi Willy, just saw ur old post while searching for answers to my issue, hope you can please help or kindly refer to someone who can: I am using vuforia to render an AR projection of a room over the actual view of the room, and the issue is that both don't match at the far end....the projection begins from the markers beautifully and accurately but the farthest wall of the AR projection appears smaller in size as compared to the actual view... I have posted this issue in the vuforia forum but rcvd no response as yet... i think the core issue is the projection matrix...the Ar projection matrix is rendering the room model in a different manner than the device camera view renders the actual room... how could I align both of them to be exactly the same?... below is something i found in my serach but i am not sure it applies in my case:
It seems that Vuforia’s AR camera uses its own specific version of projection matrix, which defines how the “world” will be shown on screen. A simple script solved the issue, just by applying the AR camera’s matrix to the UI camera:
private bool sync = false; void Update() { if (!sync) {
uiCamera.projection$$anonymous$$atrix = arCamera.projection$$anonymous$$atrix;
sync = true; } }
Only after I applied this change – the two cameras got synced. Now I could use the AR camera to detect a target image in the real world, attach a 3D object to that image, then move the object to be the child of the UI camera without experiencing any jump cuts. This makes the object’s new coordinates relate to the app’s UI, therefore I can move it around – to the center of the screen, or anywhere else I want in the app’s UI layout.
any help please?
Hi @$$anonymous$$aksdesk,
Cool idea! =)
I don't think projection matrices will help you. Vuforia handles it all beautifully, so the rendering camera matches your device camera perfectly, you shoouldn't worry about it.
I think your problem comes more from a physical difference between your device camera capture cone and your projection cone. A few tips:
place projector and camera focal points as close to each other as you can
try to match, through camera and projector zooms, the opening angles of camera and projector
match the camera and projector aspect ratios (might mean changing one of them) and ideally, resolution.
most cameras have a symmetrical capture cone, whereas most projectors have a totally assymetric projection cone in the vertical direction. Ttry to find a projector with a symmetrical projection cone (like the Optoma EH503 thanks to its huge vertical lens shift range)
Hope this helps... Let me know if I misunderstood sth. Email me if I you want a fast answer - xavier at tinybigstory dot be
Cheers!
Xavier
Your answer
Follow this Question
Related Questions
Flipping projection matrix problem: It flips everything but the Skybox. How do I fix this? 1 Answer
Generating rays from cameras with custom projection matrices 1 Answer
Setting the camera projection matrix does nothing 0 Answers
How do I calculate a view matrix using Matrix4x4.LookAt? 2 Answers
Does the projection matrix calculation affect the shader? 1 Answer