If your application’s framebuffer orientation doesn’t match the device’s native display orientation (portrait, for most devices), Android rotates the application’s framebuffer to match the device’s display every frame. Depending on the device’s hardware capabilities, this additional rotation can negatively affect performance. If your application uses the Vulkan Graphics API and the device supports Vulkan, Unity can apply this rotation during rendering which reduces the performance impact of the rotation. This is called pre-rotation.
To make Unity apply pre-rotation, you can use C# scriptsA piece of code that allows you to create your own Components, trigger game events, modify Component properties over time and respond to user input in any way you like. More info
See in Glossary or the Unity editor:
Through C# scripts: Set PlayerSettings.vulkanEnablePreTransform to true
.
Through the Unity Editor:
In the Project settings window, select the Player tab, then open Android Player Settings:
In the Other Settings section, enable Apply display rotation during rendering.
Unity applies pre-rotation when it renders directly to the device’s backbuffer, not when it renders to a Render TextureA special type of Texture that is created and updated at runtime. To use them, first create a new Render Texture and designate one of your Cameras to render into it. Then you can use the Render Texture in a Material just like a regular Texture. More info
See in Glossary
. To apply the rotation, Unity modifies the projection matrix which affects the UNITY_MATRIX_MVP
and UNITY_MATRIX_P
Built-in shader variables. This means that Unity applies the rotation in the vertex shaderA program that runs on the GPU. More info
See in Glossary.
Using pre-rotation doesn’t affect the behavior of Unity’s C# API. For example, you can still use Screen.width
to access the width of the screen. The same applies to viewportsThe user’s visible area of an app on their screen.
See in Glossary 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 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):
preTransform
is enabled in the Player SettingsUNITY_DISPLAY_ORIENTATION_PRETRANSFORM is a constant that is set to the current preTransform
rotation. Its value is one of the following:
UNITY_DISPLAY_ORIENTATION_PRETRANSFORM_0
UNITY_DISPLAY_ORIENTATION_PRETRANSFORM_90
UNITY_DISPLAY_ORIENTATION_PRETRANSFORM_180
UNITY_DISPLAY_ORIENTATION_PRETRANSFORM_270
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 if or switch statements.
In the following cases, it’s likely that enabling preTransform requires additional modifications to your Unity Project before you can use it:
SV_Position
)These cases only apply when rendering directly to the backbuffer.
When you visit any website, it may store or retrieve information on your browser, mostly in the form of cookies. This information might be about you, your preferences or your device and is mostly used to make the site work as you expect it to. The information does not usually directly identify you, but it can give you a more personalized web experience. Because we respect your right to privacy, you can choose not to allow some types of cookies. Click on the different category headings to find out more and change our default settings. However, blocking some types of cookies may impact your experience of the site and the services we are able to offer.
More information
These cookies enable the website to provide enhanced functionality and personalisation. They may be set by us or by third party providers whose services we have added to our pages. If you do not allow these cookies then some or all of these services may not function properly.
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us to know which pages are the most and least popular and see how visitors move around the site. All information these cookies collect is aggregated and therefore anonymous. If you do not allow these cookies we will not know when you have visited our site, and will not be able to monitor its performance.
These cookies may be set through our site by our advertising partners. They may be used by those companies to build a profile of your interests and show you relevant adverts on other sites. They do not store directly personal information, but are based on uniquely identifying your browser and internet device. If you do not allow these cookies, you will experience less targeted advertising. Some 3rd party video providers do not allow video views without targeting cookies. If you are experiencing difficulty viewing a video, you will need to set your cookie preferences for targeting to yes if you wish to view videos from these providers. Unity does not control this.
These cookies are necessary for the website to function and cannot be switched off in our systems. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms. You can set your browser to block or alert you about these cookies, but some parts of the site will not then work. These cookies do not store any personally identifiable information.