If your application’s framebuffer orientation doesn’t match the display’s native orientation (portrait, for most devices), Android needs to apply an additional rotation every time a rendered frame appears on the screen. This additional rotation might incur a performance cost, depending on the device’s hardware capabilities.
In most cases, you can apply this rotation during rendering with very little overhead. To do this, navigate to the Android Player Settings (see also:
PlayerSettings.vulkanEnablePreTransform) and enable Apply display rotation during rendering.
Note: The rotation only applies when Unity renders directly to the backbuffer. It has no effect when rendering to a Render Texture.
To apply the rotation, Unity modifies the projection matrix (UNITY_MATRIX_MVP, UNITY_MATRIX_P). This means that the rotation itself is applied in the vertex shader.
preTransform setting doesn’t affect the behavior of Unity’s C# API. For example, the value of
Screen.width doesn’t change because of the
preTransform setting. The same applies to viewports and scissor rects. Unity adjusts these as needed, and also handles readback operations from the backbuffer such as Grab Pass, ReadPixels, or Screenshot.
Unity provides utility macros to handle special cases in shaders (for more information, see the Known limitations section below).
The macro UNITY_PRETRANSFORM_TO_DISPLAY_ORIENTATION is only defined if all of the following conditions are true (otherwise, it’s undefined):
preTransformis enabled in the Player Settings
UNITY_DISPLAY_ORIENTATION_PRETRANSFORM is a constant that is set to the current
preTransform rotation. Its value is one of the following:
If UNITY_PRETRANSFORM_TO_DISPLAY_ORIENTATION is undefined, or when rendering to a Render Texture, the value of UNITY_DISPLAY_ORIENTATION_PRETRANSFORM is UNITY_DISPLAY_ORIENTATION_0.
UNITY_DISPLAY_ORIENTATION_PRETRANSFORM is translated into a Vulkan specialization constant, which makes it efficient to use in
In the following cases, it’s likely that enabling preTransform requires additional modifications to your Unity Project before you can use it:
These cases only apply when rendering directly to the backbuffer.