0

I have a physical camera in the scene which renders a 3D Scene. The 3D Scene is rendered between the Top UI Bar and the Bottom UI Bar and has been set properly for reference resolution 720 x 1280.

So, the problem is when the resolution changes, the UI is set properly for that particular resolution. But the 3D scene that is rendered between the 2 UI parts, doesn't sit properly between them. I am attaching 2 reference images for easier understanding.

The below-given image is based on the reference resolution and the 3D Scene is properly fit between the 2 UI parts.

enter image description here

The below-given image is for another resolution where the UI adjusts itself accordingly. But the 3D scene doesn't, i.e the camera should move to fit the 3D Scene between the UI.

enter image description here

So, is there any way I can move the camera according to the resolution so that it fits properly between the UI for different aspect ratios.

Thank you.

1 Answers1

0

First of all, try looking at the ViewportRect property of the camera - it enables you to crop the viewport to an area which should enable the effect you seek.

This however has the limitation of keeping the 'center scren' axis of perspective, which in some cases is uncalled for.

An 'should always work' solution is rendering to a RednerTexture - camera adapts its screen aspect to the aspect of the RenderTexture, and if you display your texture on RawImage, you should get dececnt results. This however has some performance cost (memory readout is not the fastest on mobile).

In case the cost woul be unnaceptable, its possible to construct custom camera projection matrix, that would respect your desired viewport rect, and also allow arbitrary perspective, but its not trivial unfrotunately. Here is some more information

https://docs.unity3d.com/ScriptReference/Camera-projectionMatrix.html

zambari
  • 4,797
  • 1
  • 12
  • 22
  • Thanks for the suggestions. But unfortunately we can't use RenderTexture because of the performance issues. And also ViewportRect is not possible as it affects the look of the scene. Only option that i have is to move the camera on Y axis, but I am not able to get the proper ratio for it. – Raghavendra Upadhya Jul 14 '20 at 06:44
  • it is possible to achieve with proejction matrix, please see https://docs.unity3d.com/ScriptReference/Camera-projectionMatrix.html – zambari Jul 16 '20 at 19:59