打包Android时Shader报错

我们在打包Android时,会出shader报错,报错内容是:Shader error in ‘Cesium/CesiumDefaultTilesetShader’: undeclared identifier ‘UNITY_DISPLAY_ORIENTAION_PRETRANSFORM’ at/Unity/2021.3.2f1c1/Editor/Date/CGlncludes/UnityCG.cginc(817) (on vulkan)
并且,在Android平台上运行时,看不见地形跟影响。

That’s strange. We have built and run Cesium applications successfully on Android devices. Do you have this problem with the Cesium for Unity Samples project as well, or only with your own project?

Thank you for your reply. I did not use the cesium for unity Samples example for building. I learned to install cesium for unity on the official website and then simply built the scene for building. However, after building, an error occurred as mentioned earlier, and when running on the platform, the terrain and images were not loaded. I don’t know how to handle this problem now, I hope you can solve it.

Does it work on a newer version of Unity? We’ve been testing on 2021.3.10f1 and up, so maybe we lost some backwards compatibility during development.

I have the same problem, and I’m test new project that only contain a “Cesium World Terrain + Bing Maps Aerial with Labels imagery”. like the image.
image

I tested it on versions 2021.3.10, 2021.3.18, 2022.2.9, and 2022.2.17. The results show that in 2021.3.10 and 2021.3.18, after building on Android, an error message appeared, as follows:

Shader error in ‘Cesium/CesiumDefaultTilesetShader’: undeclared identifier ‘UNITY_DISPLAY_ORIENTATION_PRETRANSFORM’ at Files/Unity/Hub/Editor/2021.3.18f1/Editor/Data/CGIncludes/UnityCG.cginc(817) (on vulkan)

For versions 2022.2.9 and 2022.2.17, no error was displayed. Both of these Unity versions can be built successfully. However, when I run the .apk file on my Android device, the map does not display.

I think the error may be caused by a shader file with Vulkan. Since I’m not an expert in shaders, I cannot determine exactly where it occurs from. Maybe this is an error from Unity, as shown in this link:
Unity Issue Tracker - [Android][Vulkan] Visualisation corruption occurs when rendering Particles to Render Texture (unity3d.com)

I really hope you can provide a solution. If you need any further information, please feel free to contact me anytime.

Can you please try the Cesium for Unity Samples project and let us know if you have the same issue? That will help to narrow down the problem.

It seems like this is a Unity bug with Vulkan. See this thread here: Shader graph bug: undeclared identifier 'UNITY_DISPLAY_ORIENTATION_PRETRANSFORM' - Questions & Answers - Unity Discussions

Unfortunately I don’t think we can do anything about it. You may have to switch from Vulkan to another graphics API.

Thank you!~
It works for me now!~

I have checked the player setting of the Cesium for Unity Samples project, and find some differences with mine.

All the player settings of my project is using the default one, and i uncheck the “Auto Graphics API”, and delete the OPEN GLES, shows like below.
image

Also, I changed the Scripting Backend from “Mono” to “IL2CPP”, change the Target Architectures from ARMv7(which is the default one) to ARM64.
image

Then, it works fine for me!~

Thank you~

Hi Tonny, do you mind to send me your project settings file? I followed your steps but couldn’t get it to work. Cheers

in ProjectSettings\ProjectSettings.asset

if vulkanEnablePreTransform set to 1

then change it to 0 like this below.

vulkanEnablePreTransform: 0

I had same problem. and I share the solution here. this might help to someone who have this issue.