Additive方式加载场景真机上存在的光照贴图问题

 

在场景光照贴图这块,最近遇到了一个场景莫名变暗的问题。记录如下

  • 在AB模式下,使用Additive方式加载场景(3D物件场景,有进行烘焙)
  • 加载3个场景a,b,c
  • 卸载掉一个场景a
  • 然后执行AB卸载(true方式卸载),会发现剩下两个的场景b,c的光照贴图变暗了 (场景光照贴图卸载ab后与卸载ab前对比)
  • 再加载回场景a,发现变暗的光照贴图恢复了,但是场景b,c的光照贴图UV错乱了。场景a的光照贴图正常

分析

在mac用ab模式执行了测试后,采集了在上述几个步骤中,光照贴图数组(LightmapSettings.lightmaps)的数据变化。(标橙色的是场景a所用的光照贴图)

操作加载a,b,c卸载aAB卸载加载1
表现结果光照正常光照正常光照异常:光照贴图变黑光照异常:光照贴图UV错误;新场景光照正常
变暗的光照贴图恢复了
分析有重复光照贴图?
非Additive模式?:不会有重复。场景切换会数组会重置干净
并没有全部卸载掉1所用的光照贴图场景1所用的全部被清理掉了物件Render的LMIndex不变,但是数组里面对应Index的贴图已改变
 Index0,grassland01_LMA5_finalIndex0,grassland01_LMA5_finalIndex0,Index0,grassland01_LMA5_final
 Index1,grassland01_LMA4_finalIndex1,Index1,Index1,grassland01_LMA4_final
 Index2,grassland01_LMA7_finalIndex2,Index2,Index2,grassland01_LMA7_final
 Index3,grassland01_LMA6_finalIndex3,Index3,Index3,grassland01_LMA6_final
 Index4,grassland01_LMA3_finalIndex4,Index4,Index4,grassland01_LMA3_final
 Index5,grassland01_LM31_finalIndex5,Index5,Index5,grassland01_LM31_final
 Index6,grassland01_LMA1_finalIndex6,Index6,Index6,grassland01_LMA1_final
 Index7,grassland01_LMA2_finalIndex7,Index7,Index7,grassland01_LMA2_final
 Index8,grassland01_LMA5_finalIndex8,grassland01_LMA5_finalIndex8,Index8,
 Index9,grassland01_LMA4_finalIndex9,grassland01_LMA4_finalIndex9,Index9,
 Index10,grassland01_LMA7_finalIndex10,grassland01_LMA7_finalIndex10,Index10,
 Index11,grassland01_LMA6_finalIndex11,grassland01_LMA6_finalIndex11,Index11,
 Index12,grassland01_LMA3_finalIndex12,grassland01_LMA3_finalIndex12,Index12,
 Index13,grassland01_LM31_finalIndex13,grassland01_LM31_finalIndex13,Index13,
 Index14,grassland01_LMA1_finalIndex14,grassland01_LMA1_finalIndex14,Index14,
 Index15,grassland01_LMA2_finalIndex15,grassland01_LMA2_finalIndex15,Index15,grassland02_LMA2_final
 Index16,grassland02_LMA2_finalIndex16,grassland02_LMA2_finalIndex16,grassland02_LMA2_finalIndex16,grassland02_LMA3_final
 Index17,grassland02_LMA3_finalIndex17,grassland02_LMA3_finalIndex17,grassland02_LMA3_finalIndex17,grassland02_LMA4_final
 Index18,grassland02_LMA4_finalIndex18,grassland02_LMA4_finalIndex18,grassland02_LMA4_finalIndex18,grassland02_LM34_final
 Index19,grassland02_LM34_finalIndex19,grassland02_LM34_finalIndex19,grassland02_LM34_finalIndex19,grassland02_LMA1_final
 Index20,grassland02_LMA1_finalIndex20,grassland02_LMA1_finalIndex20,grassland02_LMA1_finalIndex20,grassland02_LMA2_final
 Index21,grassland02_LMA2_finalIndex21,grassland02_LMA2_finalIndex21,grassland02_LMA2_finalIndex21,grassland02_LMA3_final
 Index22,grassland02_LMA3_finalIndex22,grassland02_LMA3_finalIndex22,grassland02_LMA3_finalIndex22,grassland02_LMA4_final
 Index23,grassland02_LMA4_finalIndex23,grassland02_LMA4_finalIndex23,grassland02_LMA4_finalIndex23,grassland02_LM34_final
 Index24,grassland02_LM34_finalIndex24,grassland02_LM34_finalIndex24,grassland02_LM34_finalIndex24,grassland02_LMA1_final
 Index25,grassland02_LMA1_finalIndex25,grassland02_LMA1_finalIndex25,grassland02_LMA1_finalIndex25,grassland03_LMA6_final
 Index26,grassland03_LMA6_finalIndex26,grassland03_LMA6_finalIndex26,grassland03_LMA6_finalIndex26,grassland03_LMA5_final
 Index27,grassland03_LMA5_finalIndex27,grassland03_LMA5_finalIndex27,grassland03_LMA5_finalIndex27,grassland03_LMA7_final
 Index28,grassland03_LMA7_finalIndex28,grassland03_LMA7_finalIndex28,grassland03_LMA7_finalIndex28,grassland03_LMA9_final
 Index29,grassland03_LMA9_finalIndex29,grassland03_LMA9_finalIndex29,grassland03_LMA9_finalIndex29,grassland03_LMA4_final
 Index30,grassland03_LMA4_finalIndex30,grassland03_LMA4_finalIndex30,grassland03_LMA4_finalIndex30,grassland03_LMA1_final
 Index31,grassland03_LMA1_finalIndex31,grassland03_LMA1_finalIndex31,grassland03_LMA1_finalIndex31,grassland03_LM57_final
 Index32,grassland03_LM57_finalIndex32,grassland03_LM57_finalIndex32,grassland03_LM57_finalIndex32,grassland03_LMA3_final
 Index33,grassland03_LMA3_finalIndex33,grassland03_LMA3_finalIndex33,grassland03_LMA3_finalIndex33,grassland03_LMA2_final
 Index34,grassland03_LMA2_finalIndex34,grassland03_LMA2_finalIndex34,grassland03_LMA2_finalIndex34,grassland03_LMA6_final
 Index35,grassland03_LMA6_finalIndex35,grassland03_LMA6_finalIndex35,grassland03_LMA6_finalIndex35,grassland03_LMA5_final
 Index36,grassland03_LMA5_finalIndex36,grassland03_LMA5_finalIndex36,grassland03_LMA5_finalIndex36,grassland03_LMA7_final
 Index37,grassland03_LMA7_finalIndex37,grassland03_LMA7_finalIndex37,grassland03_LMA7_finalIndex37,grassland03_LMA9_final
 Index38,grassland03_LMA9_finalIndex38,grassland03_LMA9_finalIndex38,grassland03_LMA9_finalIndex38,grassland03_LMA4_final
 Index39,grassland03_LMA4_finalIndex39,grassland03_LMA4_finalIndex39,grassland03_LMA4_finalIndex39,grassland03_LMA1_final
 Index40,grassland03_LMA1_finalIndex40,grassland03_LMA1_finalIndex40,grassland03_LMA1_finalIndex40,grassland03_LM57_final
 Index41,grassland03_LM57_finalIndex41,grassland03_LM57_finalIndex41,grassland03_LM57_finalIndex41,grassland03_LMA3_final
 Index42,grassland03_LMA3_finalIndex42,grassland03_LMA3_finalIndex42,grassland03_LMA3_finalIndex42,grassland03_LMA2_final
 Index43,grassland03_LMA2_finalIndex43,grassland03_LMA2_finalIndex43,grassland03_LMA2_finalIndex43,grassland01_LMA5_final
    Index44,grassland01_LMA4_final
    Index45,grassland01_LMA7_final
    Index46,grassland01_LMA6_final
    Index47,grassland01_LMA3_final
    Index48,grassland01_LM31_final
    Index49,grassland01_LMA1_final
    Index50,grassland01_LMA2_final

发现了几个要点:

  • 在数组中有两份重复的光照贴图数据
  • 卸载a后,并没有卸载掉a所有的光照贴图,有残留了一份在数组里,而且index为0的数据始终不会被清除
  • 执行卸载ab强制卸载资源后,所有a所用的光照贴图被清除了。这时其他场景的光照贴图变暗了。经谷歌原因是index为0的数据被清除后,就会导致变暗(具体原因不清楚,可能是Unity的bug)
  • index为0的数据被清除后,如果后续加载了新的光照贴图,会导致数据错乱

尝试主场景烘焙一张比较小的光照贴图,以保证光照贴图数组中index为0一直有数据,不会被清空。重新测试后,解决了变暗的问题。

重新采集了光照贴图数组数据:(标橙色的还是场景a所用的光照贴图,绿色的是主场景所用光照贴图)

操作加载1,2,3卸载1AB卸载加载1
 正常正常正常正常
 Index0,Lightmap-0_comp_light Index0,Lightmap-0_comp_light Index0,Lightmap-0_comp_light Index0,Lightmap-0_comp_light 
 Index1,grassland01_LMA5_final Index1,Index1,Index1,grassland01_LMA5_final 
 Index2,grassland01_LMA4_final Index2,Index2,Index2,grassland01_LMA4_final 
 Index3,grassland01_LMA7_final Index3,Index3,Index3,grassland01_LMA7_final 
 Index4,grassland01_LMA6_final Index4,Index4,Index4,grassland01_LMA6_final 
 Index5,grassland01_LMA3_final Index5,Index5,Index5,grassland01_LMA3_final 
 Index6,grassland01_LM31_final Index6,Index6,Index6,grassland01_LM31_final 
 Index7,grassland01_LMA1_final Index7,Index7,Index7,grassland01_LMA1_final 
 Index8,grassland01_LMA2_final Index8,Index8,Index8,grassland01_LMA2_final 
 Index9,grassland01_LMA5_final Index9,grassland01_LMA5_final Index9,Index9,
 Index10,grassland01_LMA4_final Index10,grassland01_LMA4_final Index10,Index10,
 Index11,grassland01_LMA7_final Index11,grassland01_LMA7_final Index11,Index11,
 Index12,grassland01_LMA6_final Index12,grassland01_LMA6_final Index12,Index12,
 Index13,grassland01_LMA3_final Index13,grassland01_LMA3_final Index13,Index13,
 Index14,grassland01_LM31_final Index14,grassland01_LM31_final Index14,Index14,
 Index15,grassland01_LMA1_final Index15,grassland01_LMA1_final Index15,Index15,
 Index16,grassland01_LMA2_final Index16,grassland01_LMA2_final Index16,Index16,
 Index17,grassland02_LMA2_final Index17,grassland02_LMA2_final Index17,grassland02_LMA2_final Index17,grassland02_LMA2_final 
 Index18,grassland02_LMA3_final Index18,grassland02_LMA3_final Index18,grassland02_LMA3_final Index18,grassland02_LMA3_final 
 Index19,grassland02_LMA4_final Index19,grassland02_LMA4_final Index19,grassland02_LMA4_final Index19,grassland02_LMA4_final 
 Index20,grassland02_LM34_final Index20,grassland02_LM34_final Index20,grassland02_LM34_final Index20,grassland02_LM34_final 
 Index21,grassland02_LMA1_final Index21,grassland02_LMA1_final Index21,grassland02_LMA1_final Index21,grassland02_LMA1_final 
 Index22,grassland02_LMA2_final Index22,grassland02_LMA2_final Index22,grassland02_LMA2_final Index22,grassland02_LMA2_final 
 Index23,grassland02_LMA3_final Index23,grassland02_LMA3_final Index23,grassland02_LMA3_final Index23,grassland02_LMA3_final 
 Index24,grassland02_LMA4_final Index24,grassland02_LMA4_final Index24,grassland02_LMA4_final Index24,grassland02_LMA4_final 
 Index25,grassland02_LM34_final Index25,grassland02_LM34_final Index25,grassland02_LM34_final Index25,grassland02_LM34_final 
 Index26,grassland02_LMA1_final Index26,grassland02_LMA1_final Index26,grassland02_LMA1_final Index26,grassland02_LMA1_final 
 Index27,grassland03_LMA6_final Index27,grassland03_LMA6_final Index27,grassland03_LMA6_final Index27,grassland03_LMA6_final 
 Index28,grassland03_LMA5_final Index28,grassland03_LMA5_final Index28,grassland03_LMA5_final Index28,grassland03_LMA5_final 
 Index29,grassland03_LMA7_final Index29,grassland03_LMA7_final Index29,grassland03_LMA7_final Index29,grassland03_LMA7_final 
 Index30,grassland03_LMA9_final Index30,grassland03_LMA9_final Index30,grassland03_LMA9_final Index30,grassland03_LMA9_final 
 Index31,grassland03_LMA4_final Index31,grassland03_LMA4_final Index31,grassland03_LMA4_final Index31,grassland03_LMA4_final 
 Index32,grassland03_LMA1_final Index32,grassland03_LMA1_final Index32,grassland03_LMA1_final Index32,grassland03_LMA1_final 
 Index33,grassland03_LM57_final Index33,grassland03_LM57_final Index33,grassland03_LM57_final Index33,grassland03_LM57_final 
 Index34,grassland03_LMA3_final Index34,grassland03_LMA3_final Index34,grassland03_LMA3_final Index34,grassland03_LMA3_final 
 Index35,grassland03_LMA2_final Index35,grassland03_LMA2_final Index35,grassland03_LMA2_final Index35,grassland03_LMA2_final 
 Index36,grassland03_LMA6_final Index36,grassland03_LMA6_final Index36,grassland03_LMA6_final Index36,grassland03_LMA6_final 
 Index37,grassland03_LMA5_final Index37,grassland03_LMA5_final Index37,grassland03_LMA5_final Index37,grassland03_LMA5_final 
 Index38,grassland03_LMA7_final Index38,grassland03_LMA7_final Index38,grassland03_LMA7_final Index38,grassland03_LMA7_final 
 Index39,grassland03_LMA9_final Index39,grassland03_LMA9_final Index39,grassland03_LMA9_final Index39,grassland03_LMA9_final 
 Index40,grassland03_LMA4_final Index40,grassland03_LMA4_final Index40,grassland03_LMA4_final Index40,grassland03_LMA4_final 
 Index41,grassland03_LMA1_final Index41,grassland03_LMA1_final Index41,grassland03_LMA1_final Index41,grassland03_LMA1_final 
 Index42,grassland03_LM57_final Index42,grassland03_LM57_final Index42,grassland03_LM57_final Index42,grassland03_LM57_final 
 Index43,grassland03_LMA3_final Index43,grassland03_LMA3_final Index43,grassland03_LMA3_final Index43,grassland03_LMA3_final 
 Index44,grassland03_LMA2_final Index44,grassland03_LMA2_final Index44,grassland03_LMA2_final Index44,grassland03_LMA2_final 
    Index45,grassland01_LMA5_final 
    Index46,grassland01_LMA4_final 
    Index47,grassland01_LMA7_final 
    Index48,grassland01_LMA6_final 
    Index49,grassland01_LMA3_final 
    Index50,grassland01_LM31_final 
    Index51,grassland01_LMA1_final 
    Index52,grassland01_LMA2_final 

仍然存在的问题是光照贴图数组长度会增加,待后续解决

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值