Search Unity

Baked lightmaps not showing on mobile device (iPad/Android)

Discussion in 'Global Illumination' started by Tommie060708091011, Mar 15, 2015.

  1. Tommie060708091011

    Tommie060708091011

    Joined:
    Sep 11, 2014
    Posts:
    7
    Hey guys,

    I've been troubled with this problem for two days now (just so you know I didn't just ran to this forum to cry out for help).
    I've been trying to reproduce a simple baked scene, with one direct light, set to baked (no realtime), with hard shadows on, a plane, and a cube, both set to static, both with a standard shader.
    In the lighting tab I've thrown away the skybox (for testing purposes), put the ambient intensity to 0, and left the rest of the settings at their default.
    To be clear: in the editor view, everything looks fine.
    With continuous baking on, the lightmaps seemed to update properly.
    And in the lightmap tab, I can see the correct lightmap textures.
    However, when building and testing on a mobile device, everything is black (note that ambient GI was 0).
    Then I thought, maybe I do need to manually bake, press the bake button, and produce a lightmapsnapshot.
    But that didn't work either.
    I was also confused by something I found in the lightmapping cookbook in the unity documentation (file://localhost/Applications/Unity/Unity.app/Contents/Documentation/en/Manual/GlobalIllumination.html)
    • Assign a Texture to the Emission slot in a material using the Standard shader.
    This was one of the basic steps to getting lightmaps to work, but I don't get it..

    If I put the direct light to mixed, I think the realtime-diffuse part of the light is working, but I don't see any shadows..

    What am I doing wrong?
     
    smock_74 likes this.
  2. KEngelstoft

    KEngelstoft

    Unity Technologies

    Joined:
    Aug 13, 2013
    Posts:
    1,366
    Hi! The documentation that was shipped isn't as up to date as the online version. Please have a look here http://docs.unity3d.com/Manual/GIIntro.html

    Lightmapping on Android and iPad should work - no need to assign emission texture :)

    Sounds like you did the correct thing already - light set to baked and Baked GI checked in the lighting window.
     
  3. DudoTheStampede

    DudoTheStampede

    Joined:
    Mar 16, 2015
    Posts:
    81
  4. SpiriTx

    SpiriTx

    Graphics QA

    Joined:
    Apr 12, 2012
    Posts:
    252
    I'd be guessing that the culprit here is gles2.
    Realtime GI is supported only on gles3
     
  5. DudoTheStampede

    DudoTheStampede

    Joined:
    Mar 16, 2015
    Posts:
    81
    I thought the same but in my case that's not Realtime, is it?
    I've two directional lights (Baking: Mixed, but if I set them to Baked it's the same), a Reflection Probe (Baked) and in the Lighting Options I checked Baked GI... isn't that correct to have everything baked and no Realtime GI?
    Did I miss some options or did I misunderstood something?
     
  6. SpiriTx

    SpiriTx

    Graphics QA

    Joined:
    Apr 12, 2012
    Posts:
    252
    That's correct.

    I've just checked and indeed, something broke with gles2. Good catch, I'll forward it to devs.
     
  7. DudoTheStampede

    DudoTheStampede

    Joined:
    Mar 16, 2015
    Posts:
    81
    Thanks! Can you update us on this post with news?
    I'm working on games on mobile (both Android and IOS) and I'd like to upgrade my projects to Unity5! Lightmapping is now the only thing that is preventing me to that...
     
  8. Tommie060708091011

    Tommie060708091011

    Joined:
    Sep 11, 2014
    Posts:
    7
    Haha nice!
    I'd given up on this :)
     
  9. SpiriTx

    SpiriTx

    Graphics QA

    Joined:
    Apr 12, 2012
    Posts:
    252
    I've made the case public, so you can track it's status here
     
  10. Tommie060708091011

    Tommie060708091011

    Joined:
    Sep 11, 2014
    Posts:
    7
    Thanks a lot!

    We need to make more people aware of this.
    Don't you think it's strange that nobody since the release of Unity 5 has complained about this?
    Does this mean there aren't any mobile-developers targeting low-end or semi-low-end devices that made the step to Unity 5 yet? Because I would assume they would still use lightbakes.
    This is unbelievable! :)
     
    Keikff likes this.
  11. Almakos

    Almakos

    Joined:
    Dec 13, 2013
    Posts:
    179
    and I thought I was an idiot...

    I've been building with GL ES 2.0 as it runs faster than 3.0

    at least it works on metal
     
  12. davbar9

    davbar9

    Joined:
    May 19, 2014
    Posts:
    62
    Any news about it? Any can share a good settings to lightmap the project to use on Android?
     
  13. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    Well, I find it works on android 4.0.3 fine (My tab hasn't ever had an update out for it, so that's why I am using it still! ;))
     
  14. silentslack

    silentslack

    Joined:
    Apr 5, 2013
    Posts:
    393
    Any idea on when this will be fixed? - GL ES 2.0 required for GearVR competition which has a fast approaching deadline in 11 days!
     
  15. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    @silenstack: Again, I don't see the issue... :/ They work on my end!
    One thing I would check is if they work with other shaders that sample lightmaps. (E.g. legacy shaders)
    Also, if you guys wish me to do so, I can post shader code here for testing. (Such code will be based on my current shader framework, of which works with lightmaps flawlessly! :))
     
  16. silentslack

    silentslack

    Joined:
    Apr 5, 2013
    Posts:
    393
    Currently using the Standard Shader although I guess I loose all of its PBR wonderfulness during bake so may as well use legacy.

    Will attempt a bake now and report back!
     
  17. strandborg

    strandborg

    Joined:
    Dec 8, 2014
    Posts:
    32
    Hi,

    We've isolated this issue into the automatic baking mode. As a temporary workaround, disable continuous baking, click bake manually and it should start working again.

    Hope this helps.

    --Mikko
     
  18. silentslack

    silentslack

    Joined:
    Apr 5, 2013
    Posts:
    393
    Wait, I'm not using automatic baking - I'm only using manual bake and I get no lightmaps targeting ES 2.0. Have yet to test legacy shaders but will asap
     
  19. strandborg

    strandborg

    Joined:
    Dec 8, 2014
    Posts:
    32
    Hm, that's odd. The repro I have starts working if I disable automatic baking, and breaks again if I re-enable it. If you can get a repro that shows it broken in non-auto mode on GLES2 (and works on GLES3 or on desktop), please file a bug and PM the case number to me, I'd like to take a look.
     
  20. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    So auto-baking's the culprit? I will have to test this.
     
  21. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    Here, use this debug shader for testing both cases:
    Code (CG):
    1.  
    2. Shader "FuzzyLogicStudios/LightmapTest" {
    3. SubShader {
    4. Pass {
    5. CGPROGRAM
    6. #pragma vertex vert
    7. #pragma fragment frag
    8. #include "UnityCG.cginc"
    9.  
    10. struct v2f {
    11. float4 pos : POSITION;
    12. float2 uv : TEXCOORD0;
    13. };
    14.  
    15. float4 unity_LightmapST;
    16. v2f vert (appdata_full v) {
    17. v2f o;
    18. o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    19. o.uv = v.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw;
    20. return o;
    21. }
    22. fixed4 frag (v2f i) : COLOR {
    23. return DecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap, i.uv));
    24. }
    25. ENDCG
    26. }
    27. }
    28. }
     
    Last edited: May 1, 2015
  22. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    People, I found what broke: for some crazy reason, using shader keywords on GLES2 doesn't work anymore! And likewise, that's why lightmaps aren't showing on you guys devices: it isn't actually switching the shaders to lightmapping mode like it's supposed to.

    Likewise, it's no longer "lightmaps broken on GLES2" it's now "shader keywords broken on GLES2" I'm guessing someone modified something the wrong way by accident... :D

    The workaround? use a shader that ONLY uses lightmaps and NOT the #pragma multi_compile switch used in the Unity 5 standard shader. (The shader I posted above should work fine for non-directional lightmaps, I can post a directional one too! :))
     
  23. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    Ok, I have PMed @SpiriTx on the issue, just have to wait on a reply... ;)
     
  24. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    Here you guys, while bug is being fixed... use this for sampling your lightmaps!
    Code (csharp):
    1.  
    2. Shader "FuzzyLogic Studios/Mobile AAA (Static)" {
    3.     Properties {
    4.         _Color ("Color", Color) = (1,1,1,1)
    5.         _MainTex ("Albedo (RGB)", 2D) = "white" {}
    6.         _BumpMap ("Bump Map (Dot3)", 2D) = "bump" {}
    7.         _EmissionMap ("Emission Map (B&W)", 2D) = "black" {}
    8.         _ReflPower ("Fresnel", Range(0,10)) = 2.5
    9.         _ReflIntn ("Reflection Intensity", Range(0,1)) = 0.5
    10.     }
    11.     SubShader {
    12.     tags {"RenderType" = "Opaque"}
    13.         Pass {
    14.         tags {"LightMode" = "ForwardBase"}
    15.             CGPROGRAM
    16.             #pragma vertex vert
    17.             #pragma fragment frag
    18.             //done because shader does a few weird things...
    19.             #pragma exclude_renderers d3d11 xbox360
    20.          
    21.             #pragma glsl_no_auto_normalization
    22.             #include "UnityCG.cginc"
    23.  
    24.             struct v2f {
    25.                 float4 pos : POSITION;
    26.                 float2 uv : TEXCOORD0;
    27.                 float2 uv2 : TEXCOORD1;
    28.                 float vd : TEXCOORD2;
    29.                 float3 refl : TEXCOORD3;
    30.                 float4 shadowCoord : TEXCOORD4;
    31.             };
    32.          
    33.             fixed4x4 _ShadowMapMat;
    34.             fixed4x4 _ShadowMapMV;
    35.             fixed4 _CameraSettings;
    36.             sampler2D _NoiseMap;
    37.             sampler2D _MobileSHTex;
    38.             int _LightMode;
    39.          
    40.             v2f vert (appdata_full v) {
    41.                 v2f o;
    42.  
    43.                 //position and texture coordinates
    44.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    45.                 o.uv = v.texcoord.xy;
    46.  
    47.                 o.vd = dot(v.normal, normalize(ObjSpaceViewDir(v.vertex)));            
    48.                 o.refl = reflect(normalize(-WorldSpaceViewDir(v.vertex)), mul((float3x3)_Object2World,v.normal));
    49.              
    50.                 o.uv2 = v.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw;
    51.                 o.shadowCoord.xyz = mul(_ShadowMapMat, mul(_Object2World, v.vertex));
    52.                 COMPUTE_EYEDEPTH(o.shadowCoord.w);
    53.  
    54.                 return o;
    55.             }
    56.  
    57.             fixed4 _Color;
    58.             sampler2D _MainTex;
    59.             sampler2D _BumpMap;
    60.             sampler2D _EmissionMap;
    61.             samplerCUBE _Cube;
    62.             fixed _ReflPower;
    63.             fixed _ReflIntn;
    64.  
    65.             fixed4 frag (v2f i) : COLOR {
    66.                 fixed4 final = fixed4(0,0,0,0);
    67.              
    68.                 //calculate directional lightmap normal    
    69.                 float3 SDot = 1.0-dot(UNITY_SAMPLE_TEX2D_SAMPLER(unity_LightmapInd,unity_Lightmap, i.uv2), UnpackNormal(tex2D(_BumpMap, i.uv)));
    70.                 //sample diffuse, emission and shadows.
    71.                 fixed3 diffuse = tex2D(_MainTex, i.uv).rgb * _Color;
    72.                 fixed3 emission = tex2D(_EmissionMap, i.uv).rgb * diffuse;
    73.                 fixed3 lightmap = DecodeLightmap( UNITY_SAMPLE_TEX2D(unity_Lightmap, i.uv2) );
    74.                 //add directionality to lightmap result.
    75.                 lightmap += (SDot*0.5) * lightmap;
    76.                 //do final combine.
    77.                 fixed3 color = (diffuse * lightmap) + emission;
    78.                 final = fixed4 (color, 1);
    79.              
    80.                 //add reflection effect if requested.
    81.                 if (_ReflIntn > 0) {
    82.                     fixed3 refl = UNITY_SAMPLE_TEXCUBE(unity_SpecCube0, i.refl ) + final.rgb * 0.75;
    83.                     final.rgb = lerp( lerp(refl, refl*0.5, saturate(i.vd * _ReflPower)), final, 1.0-_ReflIntn);
    84.                 }
    85.  
    86.                 //return final results
    87.                 return final;
    88.             }
    89.             ENDCG
    90.         }
    91.     }
    92.     FallBack Off
    93. }
    Samples lightmaps... nothing else! Likewise, only use this for your lightmapped objects. Some of the texture slots are designed for my workflow, but feel free to ignore them.

    EDIT: I tell a lie; samples lightmaps, and also uses reflection cubemaps. (I hope to add reflection probe support soon)
     
    Last edited: May 5, 2015
  25. davbar9

    davbar9

    Joined:
    May 19, 2014
    Posts:
    62
    Can you create videotutorial creating the lightmap with this for mobile?
     
  26. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    @davbar9: You don't need to; it's designed to use unity's lightmaps automatically. :) Note that it will appear black initially until something is baked on it. ;)
    BTW, fixed up some of my game-project-specific things, it's more portable now. (I also added basic reflection probe support! :))
     
    davbar9 likes this.
  27. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    Ok, I've been working with SpiriTx on the issue, and we've found that shader keywords themselves work fine, it is that the internally reserved lightmap keywords aren't being switched properly by the engine on android for some reason.
     
    seansteezy likes this.
  28. grimmy

    grimmy

    Joined:
    Feb 2, 2009
    Posts:
    409
    Anyway know what's happening with this?!! I have tried every setting possible (although not your temp shader Fuzzy Quills) and I can't see any lightmaps on Android. If this is a bug then I am VERY surprised that it wasn't fixed the moment it was discovered. It seem that Android lightmaps have been out of action now for a couple of months!!!! This is quite a major flaw for a tool that cost me so much of money. And it's currently costing me more money by holding up my project! I have sent a bug to Unity personally but I find it odd that this is even a bug. I't like buying a car and finding out only one gear works. Less of a 'bug' and more of a 'missing feature' I'd say.

    BTW I'm using Unity Pro 5.0.2
     
  29. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    @grimmy: And I know what's done it; something internal related to the lightmap keywords switching broke. (That's why my shader works) And it's not fixed in 5.0.2?!
     
    i1drago likes this.
  30. SpiriTx

    SpiriTx

    Graphics QA

    Joined:
    Apr 12, 2012
    Posts:
    252
    Non directional mode does work on gles2. On gles3 both directional and non directional work.
    So if you are targeting lower end-devices, please use non directional for now.

    Attaching screenshot if you can't find this option

    I've also updated issue tracker description
     

    Attached Files:

    • 1.PNG
      1.PNG
      File size:
      38.6 KB
      Views:
      2,706
    Jimbow-Zheng likes this.
  31. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    So it's only directional lightmaps that don't work... odd. They work if I use the shader I posted above fine.

    For those who don't mind, either go without directional mode, or use my shader above. Sounds good until unity find a solution to the problem. :)
     
  32. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,822
    Does your shader above work with Directional Mode? Or how should it be setup?
     
  33. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    Yep! Honestly don't know how though, I simply looked at a reverse-engineered surface shader, and a couple of the .cginc files for things I could use, then I rolled my own shader. :)

    I was initially using ONLY the lightmap shader for static objects and a separate one for dynamic objects in my project. Of course though, I was initially wondering why you poor buggers couldn't use lightmaps on android, only to find that an "improved" version of my shader with auto-lightmap switching wouldn't work! :D

    That was how I found the cause of the bug myself, and that is why I provide the shader above. So yes, long-winded explanation though, but it will work out-of-the-box. :)
     
  34. ludo6577

    ludo6577

    Joined:
    Aug 19, 2014
    Posts:
    9
    We finally found a solution to this problem if you baked your light in non-directional.
    Just check the checkbox Baked Non-Directional in Graphics Settings.
     

    Attached Files:

    MattGen likes this.
  35. MattGen

    MattGen

    Joined:
    May 12, 2015
    Posts:
    63
    Hope it can be usefull for those like us !
     
    ludo6577 likes this.
  36. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    Approved! :) I actually use this mode for a different game. (It uses fancy texturing to get better details, rather than normal maps. ;)) For using directional lightmaps if you absolutely have to, feel free to use the shader I posted in any way, commercial or not. :) (Also, sorry for sounding like a broken record! :D Maybe the unity devs could include a special keyword that forces directional lightmaps on via a compile switch for lightmapped materials... Who knows? :))
     
    ludo6577 likes this.
  37. Harry73

    Harry73

    Joined:
    Nov 4, 2015
    Posts:
    1
    I also met this problem,in my project ,i replace the Mobile/Diffuse and Legacy shader with standard shader,and then the scene is not dark on the phone .But i am not sure if there is some other problem .
     
    DBar likes this.
  38. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    So you're saying only older shaders get the bug?
     
    DBar likes this.
  39. DBar

    DBar

    Joined:
    Jul 27, 2012
    Posts:
    71
    Hello, but the Standard Shader in Android isn't affecting performance?
    If i bake a simple map with just a directional light on it, then i put bake non-directional on the Lightmapping settings, take out Auto and build manually.... i need to build for Android with the Standard Shader in the materials and it will just work? Im getting confused and i will be so happy to understand this before making a new build without shadows and lights.
     
  40. DBar

    DBar

    Joined:
    Jul 27, 2012
    Posts:
    71
    Hi, do you managed to render lightmaps to Android?
     
  41. DBar

    DBar

    Joined:
    Jul 27, 2012
    Posts:
    71
    bump
     
  42. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    @DBar: If you're using directional lightmaps, try giving the shader I posted above a shot. :)
    Otherwise, as far as I know, switching to non-directional maps (without fiddling with shaders, like I did. :)) fixes it for mobile
     
    DBar likes this.
  43. DBar

    DBar

    Joined:
    Jul 27, 2012
    Posts:
    71
    Hi FuzzyQuills, im kinda newbie with baking lights, so, before proceeding, may i ask you, i have a directional light in my scene and 4 or 5 point lights (to do coloring), i need to use your shader in every material of my game and then put bake again?
     
  44. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    Every material... of objects that are marked lightmap static, and likewise are picked up by enlighten to bake lighting; all other objects don't need it. :)

    Example: say there's your player character, (let's call him Bob) and he's in an environment you want to bake, (say, super-acid forest... :p) you would select all the objects that won't move (All the trees and forest floor, and maybe the acid... ;)) and in their material properties, assign my shader to them. (Initially, they will be black, unless there's a light bake in your scene) However, because Bob (and maybe some dynamic elements in your environment) will be moving, just use whatever shader and material you were using before on them; all other static objects use my shader.

    I do agree too that it may be a bit cumbersome if you have 100+ materials in your scene (you probably shouldn't though for performance reasons...) but for android devices and directional lightmaps, it's our only workable option. Well, until unity give us a dir-lightmap android fix for Christmas. ;)

    If you need an example scene, I actually developed that shader in a separate project to the one I used it in, so I can possibly send that over. :) On second thought... maybe it's time I released my little pack of mobile shaders. :p
     
  45. aks_percept

    aks_percept

    Joined:
    Feb 24, 2015
    Posts:
    8
    Hi, I have this issue with my project, the baked data just doesn't show up on my ipad build. I have switched the general GI to non-directional, then i also tried using the lightmaps as prefabs. I am using one single directional light for the scene with 'Baked' mode. In the Lighting settings I have turned off precompute GI and its all baked. But they just dont show up on the device. I have been trying to solve this issue for more than a week now with absolute frustration. 1.jpg 2.jpg
     
  46. KEngelstoft

    KEngelstoft

    Unity Technologies

    Joined:
    Aug 13, 2013
    Posts:
    1,366
    Hi @aks_percept are you seeing the same issue on a simple scene in iPad (try just a few static objects, a baked light, non-directional mode)? I would be great if you could try this out, to figure out if it is caused by prefabs, some iPad issue or lightmaps or shaders missing from the build...