circle-loader
0
by
0/ 37/ /0

This time we will share several technical topic which related to Program development. It is recommended to read for 15 minutes. Any unique insights or discoveries, please feel free to contact us or discuss.

UWA Q&A Community:answer.uwa4d.com


Texture:

Q1: 1. When the scene mapping is in compressed format, can it distinguish between high-end and low-end models?

 

2. If not, it means that no matter what the configuration model is, it will load the scene mapping with the same memory. Then here is the problem, if the compression rate is high, the effect is not very good on high-end mobile phones, if the compression rate is low, the memory is insufficient on low-end mobile phones, is there any good solution in this case?

 

3. In addition, there is another question. Normally, a 2048×2048 mapping, in the case of Mipmap and in RGB24 format, the memory should be 16MB (12MB mapping + about 3MB Mipmap). But when I package it on my mobile phone, the picture I see in the real machine profile takes up 4MB of memory. When Mipmap is turned off, it is normal, and the display is 16MB. Does the memory occupation got on real machine profile is not the real memory occupation but the video memory occupation? Or is this a bug in Unity Profile?

 

Added: I test it on UWA and the situation is the same, after opening Mipmap, the image with the size 2048×2048 occupies also 4MB.

1. It can be distinguished, but the cost is that the package will be large, and the logic of loading different resources needs to be additionally loaded according to the high and low configuration settings. Of course, it is a common practice to use small packages to decide which resources are suitable for downloading according to the current hardware.

 

2. Apart from the way that different machines directly download different resources, or the method that multiple sets of mappings are in the package, is there any other good way? TextureQuality in Unity’s QualitySettings configuration is a feasible option. I have not performed a memory comparison. According to my previous understanding, it should be based on Mipmap to save memory. You can try it, but this is not the main way to compress different formats which you want.

3. For the memory usage of size 2048×2048, I don’t know the reason either, you can refet to other’s reply. However, you are using RGB24 format, it is normal that the memory usage is high. It is recommended to use the compression format directly supported on the corresponding target device. High-quality compression, especially in 3D scenes, except for Normal and other special mappings, no obvious difference can be seen.

Thanks to Jia Weihao for providing the answer above.

Now, many games will be adapted according to the model, the standard for most games to adapt to Android Top 300 is ETC2, which can be used as a standard compression format, iOS needs PVRTC4 when considering the situation of iPhone 5s, if you don’t consider the model, you can use ASTC.

 

In the standard package, we only compress the above formats, but on high-end models, we can let users choose to download high-definition resources. For this part of high-definition resources, we can modify the image compression format to ASTC, and then repackage the AssetBundle to allow users to download it themselves and give certain game props rewards.

 

The above strategy is more suitable for heavy and large games such as MMO. For casual or light games, you can select some resources to be saved in two different compression formats and load different resources according to the model.

Thanks to Zheng Xiao for providing the answer above.

Unity version you used is 2018.3, it is likely that the Texture Mipmap Steaming function is turned on. Since the memory Budget has reached the upper limit, the engine only loads the contents of Mipmap1 ~ n layers. For the problem that the original image memory is 12MB, the total usage after the first layer of Mipmap is about 4MB. So personally, the reason for your third question is this.

This answer is provided by UWA.


Lua

Q2: Our project is connected to XLua, and it is mainly used for UI logic writing and hot update. When writing UI logic, I need to read the data of game configuration table in the Lua script, I find several solutions online:

 

1. The C # layer provides a look-up table interface for Lua, but I feel that the performance of this method is not very good;

 

2. Convert the Excel configuration table of the game to Lua Table through the tool and use it directly in Lua, but the open source tool has not been selected yet;

 

3. Other solutions.

 

I hope you can provide specific project experience and reference to corresponding open source tools to facilitate others who also want to develop it.

For solution 2, share the tool of tabtoy excel exporter.It can convert Excel configuration tables into Lua files and use them directly in Lua.

 

Example of code:

-- Add search path
package.path = package.path .. ";../?.lua"

-- Loading
local t = require "Config"

-- Direct access to raw data
print(t.Sample[1].Name)

-- Access by index
print(t.SampleByID[103].ID)

print(t.SampleByName["Black Cat Sheriff"].ID)

Thanks to Zhang Rui for providing the answer above.

There are many tools on GitHub which can export Excel to Lua, but the essence is similar, all of them need to formulate some rules to modify and constrain the existing table, you should decide which format is closer to your project, and then adapt it yourself.

 

I made an exporter for my project at the beginning of 2014, but it has been constantly modified, and now it is the tool XlsxToLua.

Thanks to 厅级码农 for providing the answer above.


Lightmap

Q3: Loading the scene through AssetBundle, I find there is no lighting effect.

 

Question 1: It is found that static attribute has changed, will this affect the batching?

 

Question 2: It is found that Shadowmask is not referenced. Is this feasible to process it according to the LightmapLight processing method?

 

Question 3: The most important thing is how to get lighting information through the scene loaded by AssetBundle.

 

After the test, I find that there is no problem if the entire scene is packed into an AssetBundle, but if the common resources are extracted, the lighting will be invalid.

 

If you know how to solve it, please tell me.

 

Image 1 is the scene information in Unity, and Image 2 is the scene information loaded through the AssetBundle simulation.

Summarize the questions you raised:

 

1. Shader Variants are lost;

 

2. Lightmap is optimized when AssetBundle is packaged;

 

3. Static only takes effect on objects placed in the scene under Editor, instantiation does not take effect during Runtime, and will not be statically batched.

 

Solution:

 

1. Create Shader Variants Collection, choose the correct Shader variant, and pack the Shader Variants Collection and the used Shader into the same AssetBundle, then the AssetBundle package of Shader can strip the scene.

 

2. Editor-> Project Settings-> Graphics-> Shader Stripping, change Lightmap Modes to Custom, and then select the corresponding mode according to the Lightmap baking mode. The main reason is that Auto will set these options according to the scene you opened when you pack AssetBundle. For empty scenes, without Lightmap, the Lightmap part in Shader will be optimized firstly.

 

3. Mesh can be merged manually to reduce DrawCall, you can check the related API of CombineInstance for details.

Thanks to Zheng Xiao for providing the answer above.


Overdraw

Q4: Recently, we are doing optimization of OverDraw. Since our UI interface is window-style and does not cover the full screen, the main camera has been always rendering. In order to reduce DrawCall and OverDraw, we take a screenshot of the main camera, place it behind the pop-up UI window, and turn off the main camera, greatly reducing the DrawCall when opening the UI interface. This is Plan A.

 

But because this is a whole background screenshot, there is a large block in the middle which is blocked by UI and cannot be seen, so we want to dig out the part blocked by UI in the middle, leaving only the visible part, in this way, OverDraw can be reduced. This is Option B.

 

Now here is the question, solution A has 3 DrawCall lower than solution B, but there will be more than 0.4x OverDraw. CPU and GPU in our project have not encountered bottlenecks, if we only consider power consumption and temperature, which solution should be chosen?

First of all, it is necessary to say that both A and B are good solutions. You can consider Option B, indicating that your team has high self-request and execution ability.

 

Secondly, if CPU and GPU have not reached the bottleneck in solutions A and B, then in fact, there are no problems in these two solutions, and you should only see which method has the least labor cost. However, if we only consider it from the perspective of computing power, I recommend Option B, because the increase of 3 DrawCalls is almost negligible, but 0.4x OverDraw is still a non-negligible overhead.

This answer is provided by UWA.


UI

Q5: There are multiple combat floating character effects in the game, corresponding to multiple BMFont artistic fonts. How to optimize these into a DrawCall? Various types of damage and sources have different effects of floating characters, such as critical hit, poisoning, dodge, blood return, etc. The previous solution was to use BMFont to create multiple fonts, corresponding to the customized fonts in UGUI. Then the problem is that when various floating characters appear at the same time, the UI batch will be interrupted, resulting in a lot of DrawCall.

 

An optimization solution is to put different artistic fonts in different layers, then the number of DrawCall is the same with that of fonts, but the obvious problem with this solution is that one type of damage will be blocked by another type, but the desired effect of planners is that different types of floating character effects can intersect each other.

 

The current idea is to make all artistic fonts into a BMFont file. For different types of damage numbers, we can use ASCII codes of different groups to access different expressions of the same number.

 

I would like to ask which solution you are using?

I will choose “make all artistic fonts into a BMFont file”, and use different characters instead of different numbers. However, it should be noted that the problems related to the unity of font size under different artistic characters, but this is easy to solve.

 

And it is recommended that you’d better consider treating the words “critical hit” or “poisoning” in Chinese as one word, and for the corresponding character, you can select a specific symbol. The advantage of this is that if you make Thai or English versions later, these artistic characters are likely to be connected together, but if a word is regarded as a whole, the corresponding characters can be unified.

Thanks to hcj for providing the answer above.


This is the 63th UWA Technology Sharing for Unity Development. As we all know, Our life has a limit but knowledge has none. These problems are only the tip of the iceberg and there are more technical problems during our program development which deserve to discuss. Welcome to join UWA Q&A community, let‘s explore and share knowledge together!

UWA website:en.uwa4d.com

UWA Blog:blog.en.uwa4d.com

UWA Q&A community:answer.uwa4d.com

Post a Reply