Because the displays of different devices have problems such as color difference and brightness difference, the first step to confirm the problem is to copy it to the same device through screen capture for observation. Screen capture of mobile phone, sent to computer, and then compared under the same screen, it is found that the brightness difference of the scene is really great, and the characters have not observed this phenomenon, presumably related to lightmap.
Make a simple Demo, compare the materials used in our own project with the standard materials, and find that there is this problem, and eliminate the bugs in our own materials.
Because we use linear space, we switch color space to carry out comparative experiments, and find that gamma space has chromatic aberration, but it is not as obvious as linear space.
As usual, search first and collect relevant information.
Doubt is the official bug of Unity engine (which Unity is good at. . . ), search for a bug report on issuetracker first? Aked lightmap is blacker on Android platform than on PC platform, and it is said to be Unity version 5.5.5 fix, without mentioning the setting of linear space. I can't wait for the 5.5.5 version test in July, so I will temporarily record it and continue.
UWA's question has a post asking related questions, and there is an answer: Lightmap is displayed normally on PC, but switching to Android platform will have color difference, and the color is generally dark. The following is a passage from the answer:
The reason for the difference is given here, that is, it is normal that the lightmap map is stored in exr format, and then it is processed according to LDR on mobile devices. We gave my suggestion and looked at it, but there was no corresponding problem.
Then, find an article to solve the problem that Lightmap's performance on PC is different from that on ios and Android? There is a basic principle analysis, a solution, and source code, which looks very reliable. I made a demonstration and tried to go through the process, which can solve the problem of dimming, but it will become brighter than on the PC. . . There is still a deviation. I don't know if it is a linear space problem. More importantly, the process is too complicated and the maintenance cost is high. All materials need to be modified accordingly, which is not ideal. Moreover, the converted map should be in the format of RGBA8, and a map of 1024 needs to occupy about 4-5M of package and memory space, which is unbearable to implement.
Not long ago, I saw a post on Zhihu: Talking about the baking skills of light maps, which mentioned the cross-platform problem and mentioned:
After investigation, the texture brightness used for demonstration is 0.63, and the illumination brightness is adjusted to 1. The color before baking is also about 0.5-0.7. I don't know if it is because of the linear space problem, but it hasn't been solved anyway. However, this article directly mentioned the source code in UnityCG.cginc, that is, the color resolution process of lightmap, and went to have a look.
After a night of struggle, I finally decided to choose the method of modifying DecodeLightmapDeubleLDR to solve it, and tried to modify the material while testing:
1. Using the DecodeLightmapRGBM function directly on the device can achieve the same effect as on the PC;
2. Internally modify DecodeLightmapDeubleLDR to (DecodeInstructions.x * pow (data.a, DecodeInstructions.y)) * data.rgb; The result is the same;
3. directly use unity _ lightmap _ hdr.x * color.rgb; The result looks the same.
I feel very uneasy. Although the test results are good, I can't find out where unity_Lightmap_HDR is assigned and what it means because the calculation process is different. I tried to modify the values and compare the results. I feel that this value is around 5.0. . . There is a macro definition and comment. I wonder if it has anything to do with it:
Looking at the light map in PS, I found that the Alpha channel used to adjust RGB values is almost black and white, and only some edges have some gray values, which may explain why the adjustment calculation result of removing Alpha seems correct-after all, the alpha channel has no effect at all. I found a light map of an indoor scene and looked at it. It's still like this. I wonder if there is any god horse setting when art baking is useless. . .
Note: After modification, light map compression can only use ETC(2)_RGB4 format, and alpha channel is no longer needed. The previous 1M 1024 diagram changed to 0.5M Happy ~ ~ (The intermediate test used ETC2_RGBA8 format, but the scene was completely black, which was difficult for me to understand. . . If you have any friends who know the reason, please tell me, thank you very much ~)
Finally, replace it with UnityCG.cginc file again, delete the compiled Shader cached under Libery, restart Unity, set all exr format maps to ETC2_RGB4, re-import, package them on the mobile phone, and then take screenshots to PC for comparison. Our scenes are almost the same.
In engineering, the process of solving problems is always accompanied by various guesses and puzzles. After the final problem is solved, some problems are solved, and some problems may not be solved yet.
The choice of the final scheme is based on the balance of time cost, maintenance cost and consistent final effect. I know that this scheme may not be suitable for all projects. In order to achieve more delicate figure effect and consistent light and shadow effect before and after baking, we completely use linear space for development and production on the mobile platform. Now, in order to solve the problem of inconsistent baking results on the device and PC, we modified the UnityCG.cginc file again without knowing where to set the variable unity_Lightmap_HDR. . .
In fact, I don't know if the final solution hides any other loopholes, but as the artist said when he saw the result-"It's perfect, it looks exactly like the one on the PC!" It is the famous saying in computer graphics: if it looks right, it is right.
At present, can do, also only in this way. ...
Finally, if you have the Unity source code, you can know the setting details of the variable unity_Lightmap_HDR, or know its documentation or setting logic, please let me know. If you think there are any loopholes in this scheme, please discuss with me ~ thank you very much!