- Home /
Lightmaps on mobile inconsistant
Having a big issue with using linear lightmaps in Unity 5.5 when targetting mobile platforms.
There seems to be some kind of encoding happening on the lightmaps that makes them display incorrectly when compared with the unbaked scene, or the same lightmaps used in a PC build.
As always, pictures speak a thousand words. The attached images illustrate the problems we are having:
The 2 images on the left are in the iOS build editor, the 2 on the right are targetting PC
The PC baked version, with lightmaps, looks very close to the realtime setup.
The iOS Baked version looks almost like the linear space is not being used.
We are doing tests with a Gamma based setup too, but this is also giving huge differences between realtime and baked lighting. This would suggest the issue has nothing to do with linear vs Gamma, but more to do with the encoding/decoding of lightmaps on mobile platforms.
The lightmaps are displayed in the image too - these are actually identical lightmaps, but it can be seen clearly that the ones on PC build are being displayed differently.
Can anyone help?
Answer by chrisb1976 · Dec 09, 2016 at 12:44 PM
**EDIT 12-12-2016:
The solution below worked, but only in the editor window. When we built the project on mobile the same washed-out textures were visible. After further testing, we realised that the issue was actually with the use of RGBM textures for lightmaps on mobile. Unity converts all the lightmaps to RGBM format when building for mobile. However, as RGBM cannot display the full HDR range, the lightmaps we used did not display correctly. On of the reasons why the lightmaps looked so bad was because we had a lot of dark materials, and almost all lights were maxed out to 8 to compensate. We are now recreating the full scene with lighter materials, no ambient lighting, and with adjusted point lights (generally now around 2.5 strength). Whilst we miss the full range we got from the HDR lightmaps, we are able to achieve an acceptable result. More importantly, we are able to better judge the final look of the built project.
The biggest learning from this process: When creating a scene for use on mobile, you should avoid cranking lights up to 8. If this is happening a lot in your scene, lighten your materials and reduce the intensity of your lights.
**END OF EDIT
ORIGINAL ANSWER
After a quite insane amount of testing and frustration, I have finally found a fix to this problem, and it seems to be a bug within unity texture type definitions:
Lightmaps are by default (and logically) created as 'Lightmap' Texture Type. This results in the washed-out, darkened feel shown in my original attachment.
In order to rectify this (Unity 5.5), the lightmaps need to be converted to 'Default' Texture Type.
In Unity 5.4, this should be the 'Texture' Texture Type.
For some reason, I cannot attach an image here, but the above description should be sufficient.
I have tested this in both Linear and Gamma modes in Unity 5.5, and in Gamma mode in Unity 5.4, and it seems to solve this issue in all cases. The Gamma lightmaps are still not as accurate as the linear ones, but way better than the results I was getting previously.
Hope this helps anyone else who may have similar issues. I will submit this as a bug.
EDIT: changed this from a comment to answer, now I can post a screenshot of the solution.
Answer by NoseKills · Dec 08, 2016 at 07:13 PM
Probably this issue? It was fixed in 5.5.0p1.
Funny things is that I am on the latest version of unity and still have this annoying editor bug and the bug report $$anonymous$$m just sent me a link which you showed us here that it has been solved, but it is clearly not solved. The PC/$$anonymous$$ac version lightmap works perfectly, but the mobile version looks really dark in the editor, but look normal when built. It is really difficult to work with lighting in the editor.
Do you have the latest main unity build (5.5.0f3) or the patch version (5.5.0p1). You need to get the patch version, which fixes the bug you have:
https://unity3d.com/unity/qa/patch-releases?_ga=1.212164884.1220397441.1481226827
Answer by chrisb1976 · Dec 09, 2016 at 06:17 AM
Thanks for the answer.
I tried this in the new patch release (5.5.0p1), and produce exactly the same result. Also turned off DX11, assigned metal for the iOS target, and iOS 8.0.
The lightmaps look just as bad when we run the build on an iOS device.
Does anyone else have similar issues? We've really started to get stuck with this problem...
What I did is set up the lighting and bake the lightmap on PC/$$anonymous$$ac platform and then switch to mobile and it looked fine on the built version, but it is really annoying to work in dark since the whole scene is a lot darker then it is supposed to be
Answer by scottharber · Jan 05, 2017 at 11:49 AM
More info (and a code fix!):
The issue itself lies within the DecodeLightmap function in the shaders.
In UnityCG.cgInc, there are two code paths that define what to do with the lighting; one for RGBM, and one that just doubles the brightness of an LDR lightmap.
inline half3 DecodeLightmap( fixed4 color )
{
#if defined(UNITY_NO_RGBM)
return DecodeLightmapDoubleLDR( color );
#else
return DecodeLightmapRGBM( color, unity_Lightmap_HDR );
#endif
}
As far as I can tell, the function presumes RGBM at all times when using baked lightmaps, but mobile re-compresses all lightmaps into double LDR. So if you're using custom shaders, you can avoid changing the "Texture Type" settings on the lightmaps by using this code.
#if !UNITY_STANDALONE_WIN
DecodedLightMap = 2.0f * UNITY_SAMPLE_TEX2D(unity_Lightmap, IN.uv1.xy);
#else
DecodedLightMap = DecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap, IN.uv1.xy));
#endif
Your answer
![](https://koobas.hobune.stream/wayback/20220612102311im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
About a realistic indoor scene... 1 Answer
Emission baked Black, lightmap very blocky? 1 Answer
Lightmap is not imorted to other project after exporting. 0 Answers
Generate Lighting when loading the game 0 Answers
What is causing these texture artifacts, seen on device since switching to Unity 5 1 Answer