当前位置:网站首页>UWA Q & a collection

UWA Q & a collection

2022-07-07 22:25:00 UWATech

1)Unity Performance optimization thinking
​2) Resource packaging dependency tree
3)SpriteAtlas in Include in Build The role of
4) Use Streaming Mipmap There is no doubt that the post texture memory will drop
5)URP Renderer Feature Realize quadratic element tracing ,Cutout To deal with the problem


UWA Weekly knowledge column 《 whole | Technology sharing 》 It's been with you all 330 Six working weeks . Selected 2022 Share with you the wonderful Q & A in the first half of the year , expect UWA Q & A continues to be accompanied by you .

UWA Question answering community :answer.uwa4d.com
UWA QQ Group 2:793972859( The original group is full )

Unity

Q:Unity How many optimization points are there ? Such as joint approval : Static batch 、SRP Combined batch 、GPU Instantiation 、UGUI Reruild、 Light baking 、 Reflection probe 、 Light probe 、Shader.Parse、Shader.CreateGPUProgram、 Scene loading optimization and GC Optimize , What are the optimization points ?

A1: The general direction can be from CPU、 Memory 、GPU These three directions cut into .

You can subdivide it from CPU、 Memory 、 Rendering 、 resource optimization 、 Power consumption optimization 、 network optimization 、 Carton optimization 、 The choice of optimization tools starts with mastering these points .
One 、CPU Optimize

  1. Cache calculation results
  2. Preprocessing
  3. Frame limiting method
  4. Primary and secondary method
  5. Multithreading
  6. Engine modules ( Animation 、 Physics 、 The particle 、 Navigation )
  7. Logic optimization

Two 、 Memory optimization

  1. Cache method
  2. Memory pool
  3. Explorer
  4. control GC
  5. Logic optimization
  6. Shader The number of variants is optimized

3、 ... and 、 Rendering optimization

  1. SetPassCall Render state switching frequency control
  2. DrawCall Quantity control
  3. Bandwidth load
  4. Memory occupation
  5. GPU Amount of computation

Four 、 Carton optimization

  1. Frame reduction method
  2. Frame spreading method
  3. Limited quantity method
  4. Logic optimization
  5. IO Optimize
  6. Use progress bar

5、 ... and 、 resource optimization

  1. Texture Optimization
  2. UI Optimize
  3. Font optimization
  4. Model optimization
  5. Scenario optimization
  6. Particle optimization
  7. Material optimization
  8. Specify standard art specifications
  9. Shader The number of variants is optimized

6、 ... and 、 Power consumption optimization
The optimization points mentioned above , More or less will affect the power consumption of mobile phones , It is also a measure to optimize power consumption , In addition to that :

  1. Dynamically adjust the frame limit
  2. Dynamically adjust the picture quality

7、 ... and 、 network optimization

  1. Reduce useless fields
  2. Reduce field precision
  3. Avoid sending repeatedly
  4. Network asynchronization
  5. Compress invalid bytes
  6. Compressed protocol package

These points mentioned above , Most of the excerpts are summarized from 《 General techniques for mobile game performance optimization 》. It is strongly recommended to spend more time reading this article carefully , Then use this article as a guide , Then carefully study how the optimization details mentioned in it should be carried out .

Thank you, Ma San @UWA The Q & a community provides answers

A2: Optimization points must be endless , Carry here UWA Client performance optimization ideas , The related problems of common engine modules are analyzed , It's quite comprehensive and thorough , Common optimization problems are listed .

《Unity performance optimization — Physical modules 》
《Unity performance optimization — Animation module 》
《Unity Performance optimization series — Resource memory leak 》
《Unity Performance optimization series —Lua Code optimization 》
《 Particle system optimization —— How to optimize your skill effects 》
《Unity Performance optimization series — Loading and resource management 》
《Unity Performance optimization series — Rendering module 》
《Unity performance optimization — UI modular 》
《 Support resource loading analysis 、 Scene segmentation 》
《UWA Tips for reporting , you get Did you? ?》
《UWA Local resource detection update , Help you stick to every corner of the project performance !》

Thank you, Barney @UWA The Q & a community provides answers


AssetBundle

Q: Want to do inclusion resource analysis , Do you have any good tree display tools or ideas to recommend ? It's OK to have a good open source solution . The simplest is like N Like a fork tree , such as root A file name , Then expand the whole tree structure .

A1: I made one myself , For reference . It's all used Unity Their own IMGUI The most basic interface to implement .
EditorWindows
GUI.Box
GUI.BeginGroup
GUI.Label
Handles.DrawBezier
Handles.DrawWireDisc
TreeView
Basically , Organize all AssetBundle The dependencies of are actually well presented .

 

Thank you Huang Cheng @UWA The Q & a community provides answers

A2: Recommend an easy-to-use plug-in , There are more than dependency trees , There are other packaged resource data available for analysis :
https://assetstore.unity.com/packages/tools/utilities/build-report-tool-8162

 

 

 

Thank you, Zheng Xiao @UWA The Q & a community provides answers


AssetBundle

Q:SpriteAtlas in Include in Build What is the role of ?

A: Some tests have been specially done , As follows :

In the following expression Sprite The corresponding is Sprite Object of type ,Texture2D The corresponding is Texture2D The object of , This sum Sprite Objects are completely different things ,sactx Represents the generated atlas texture .

The test conditions include 2 A variable :

  1. SpriteAtlas Whether the object is actively packaged AssetBundle
  2. SpriteAtlas Whether to check Include in Build

Case one ,SpriteAtlas pack AssetBundle:

What should be considered here is SpriteAtlas Refer to the Sprite Whether it will be packed separately , If these are small Sprite Don't take the initiative to pack , Will passively enter this SpriteAtlas Of AssetBundle Inside , If anything else UI Prefab in , Such as a Image Used a small Sprite, So this little Sprite Redundancy .

Check here Include in Build The difference is that : load Image When , This Image Will it automatically display , Checked Include in Build, The picture will be displayed automatically , Don't check , Scripts need to add callbacks to actively load SpriteAtlas, and callback(spriteatlas).

The second case ,SpriteAtlas Do not join AssetBundle pack :

  1. Don't check Include in Build
    Suppose the small Sprite pack AssetBundle, In this AssetBundle There won't be sactx, This sactx Of Texture2D The texture of becomes “ disappear ” The state of , Nothing can be quoted to this sactx texture , And because there are SpriteAtlas The existence of , So in small Sprite Of AssetBundle It can't make its own corresponding small Texture2D Texture advance AssetBundle package , So the image will never be displayed .
  2. Check Include in Build
    All the small Sprite Where AssetBundle It will passively contain sactx Graph , And it will include all small ones that are not actively packaged Sprite.

    Such as Sprite1 and Sprite2 yes SpriteAtlas Two small ones inside Sprite.Sprite1 Take the initiative to pack ,Sprite2 Don't take the initiative to pack , that Sprite1 Of AssetBundle There will be Sprite1 and Sprite2 as well as sactx texture .

summary :

  1. If there is Sprite Joined a SpriteAtlas, So any real use of this Sprite None of the resources will be right Sprite Corresponding small Texture2D Texture references , It's right sactx Reference of atlas texture .
  2. If SpriteAtlas No packaging , Must be checked Include in Build, otherwise sactx The texture is “ disappear ” 了 , Check Include in Build Under the premise of , and SpriteAtlas All the small ones in sprite Must be packaged in the same AssetBundle Inside , otherwise sactx Will be redundant .
  3. If SpriteAtlas Packed AssetBundle,sactx There will never be redundancy ( Redundancy here refers to packaging AssetBundle Redundancy caused by ).SpriteAtlas The small one inside Sprite It's also best to pack AssetBundle, Otherwise, these small Sprite It will be redundant . Check or uncheck Include in Build Does not affect various dependencies , The only difference is whether the image will be displayed actively , If checked, the picture will be displayed automatically , If you don't check it, you need script control to display pictures .

thank [email protected] The Q & a community provides answers


Texture

Q: Why do I use... In my project Streaming Mipmap But in GOT According to the report, the texture memory has not decreased ? Is it not effective correctly or there is a statistical problem ?

A: I have done relevant tests before , Find out GOT Online It can be counted to be Streaming Mipmap Affects the correct memory of the texture , So I speculate that the situation you encounter has a high probability of not taking effect correctly . Here's how to make a texture apply Streaming Mipmap Summary of the simple process , Some conditions that require special attention will be noted ( Some are included in official documents , Some documents do not , But experiments have proved necessary ):

  1. stay Project Settings-Quality In the open Texture Streaming Options . However, the experiment found that Editor When this option is enabled in, it will fail on the real machine , Resulting in all textures Streaming Mipmap All settings are invalid . So in order to ensure that it takes effect , First you should call... In your code QualitySettings.streamingMipmapsActive API Turn this option on globally , To ensure Streaming Mipmap You can use .

  2. adjustment 1 Parameters set in . The more important parameter is Memory Budget Parameters and Max Level Reduction Parameters .Memory Budget Represents the budget of texture resources , The default value is 512MB, But according to UWA According to a large number of project data , Generally, the medium and low-end computers are 200MB about . Its value represents the budget of all texture resources —— namely , It includes both non streaming textures 、 It also includes the texture we want to use streaming —— But this “ The budget ” It does not represent the upper limit of texture resources , It's just Unity Judge for an open Streaming Mipmap Which of its textures do you use Mipmap The reference value of the channel , Non streaming textures can easily break this budget .

    Max Level Reduction It means Unity What is the highest level that can be accessed through streaming storage Mipmap passageway , This parameter has priority over Memory Budget higher , It will also cause the actual memory to exceed the budget .( For example, the parameter is 2 when , At most Mipmap0 and 1 passageway , Even if it is far beyond the budget after being discarded, it will not be further eliminated .)

    in other words , If Memory Budget The value is set much higher than the actual memory occupied by the texture in the project , be Texture Streaming It may not work at all , All on Streaming Mipmap The textures of will still retain all of them Mipmap passageway .

  3. Set on Streaming Mipmap The texture of .1、2 The settings mentioned in are only enabled for Streaming Mipmap The texture of works , And this is just the official document , In terms of practical operation ,Texture Streaming Only works for textures that meet the following three conditions :

    1) Open the Streaming Mipmap And it turns on Generate Mipmap The texture of ( This is not mentioned in the official documents , Actually open Generate Mipmap Generation Mipmap Channel supply Streaming Mipmap To eliminate );

    2) A texture that is loaded instantly ( Such as the texture that has been relied on in the scene from the beginning , Even if it's on Streaming Mipmap Its memory will not change , adopt AssetBundle Load and Res.Load() The loaded texture can ), That is, the actual meaning of this sentence in the official documents :

    If it's going on Android Development , You still need to open it Build Setting, And will Compression Method Set to LZ4 or LZ4HC.Unity You need to use one of these compression methods for asynchronous texture loading , This is a necessary operation for texture streaming system .

    3)Gfx Some memory ( This means that texture resources are enabled Read/Write Option , Copied to the CPU The part of memory on the end is not affected by Streaming Mipmap Affected );

  4. Streaming Mipmap To eliminate Mipmap The law of passage . Its mechanism is actually similar to Texture Quality It's similar . We know , Turn on Mipmap The reason why the texture of becomes the original 4/3 times , In fact, it is the sum of the memory occupied by each channel . For example , One has 11 individual Mipmap The original size of the channel is 1MB The texture of (10241024 The resolution of the 、ASTC44 Format ), Its memory usage is 1+1/4+1/16+… Of 11 The sum of the series of items , About 4/3. The items of the proportional series correspond to Mipmap0、Mipmap1、Mipmap2… Wait for each Mipmap passageway . that , When Max Level Reduction Parameter set to 2 when , Its practical significance is to retain Mipmap2 And all subsequent smaller channels , And eliminate Mipmap0 and Mipmap1 passageway , At this time, the memory size is 4/3MB-1MB-1/4MB=85.33KB. This is with me Profiler or GOT Online The data seen in are basically the same .

     

  5. About adopting Streaming Mipmap Proposal for the scheme . According to the above experiments and analysis, it is not difficult to see ,Streaming Mipmap It does have some advantages , Memory sensitive , In particular, texture memory takes up a lot of projects , use Streaming Mipmap The scheme is a very reasonable and recommended option . meanwhile , Its actual use requires a considerable understanding and planning of the memory occupation of texture resources in the project —— The relevant settings are in Quality in , Of course, different devices should be considered Lod Different settings for grading . In the middle and low-end machines , Set as low as possible Memory Budget And as high as possible Max Level Reduction; On high-end machines, the opposite is true , Try to open the best picture performance within the acceptable range of memory . besides , For which textures to turn on Streaming Mipmap, Usually in the scene 3D The texture of an object , and UI The texture used in the module shall be closed as far as possible . because Mipmap The significance of texture is mainly to meet the performance needs of texture when it is far and near from the lens 、 Avoid distortion, etc , and UI You don't need these at all , Opening it will only waste memory and computing time .

thank [email protected] The Q & a community provides answers


Rendering

Q: Before, our cartoon rendering was in Shader Write more than Pass To draw the stroke , Recently I tried to use SRP Batcher Found during optimization ,SRP Batcher Does not support multiple Pass Of Shader. So I tried URP Renderer Feature To render the stroke of all characters .

 

It's easy to implement , But there is one problem that cannot be solved , Namely Cutout The problem of .

 

The lower edge of the skirt is mapped Alpha The control of the , It's not really a vertex . Former Pass Written in character rendering Shader in , You can use maps to control , But with Renderer Feature To deal with it , The stroke of all character models uses the same material , You can't use the respective mapping channels of the model to deal with . The display effect is Cutout The stroke part of cannot be processed :

 

 

The edges are complicated , But there are only a few control vertices , It doesn't feel good to realize .

Now I have used the color information of model vertices ,RGB It's the stroke color ,A Is the stroke thickness . The way I can think of is to use A Some special values to deal with some vertices ( amount to Clip Drop some vertices , But it's definitely not relevant API), But it doesn't seem feasible . I don't know if you've ever met , Or is there any good way ?

I tried to mark points with vertex information , But there are flaws , The edges associated with the points are affected , The stroke is gone :

 

Let the art add some points , It can basically solve ( In fact, the outer edge will not show all , But I can't see it anymore ):

 

But this method is still not good . Best in Renderer Feature You can get the material information of the model being rendered .

Can you put more than one Pass Of Shader One of them Pass Get a separate Renderer Feature Li Hua , Instead of redrawing ? For example, disable this for the first time Pass,Renderer Feature Turn it on when you draw ?

A1: Customize a LightMode,Render Feature Set this in LightMode, In this way, the mapping data on the shader can be .

Add a screenshot that looks like this :

 

 

 

For custom LightMode,Unity Default ignore , Only Render Feature It is manually specified to draw this LightMode,Unity To draw .

thank [email protected] The Q & a community provides answers

A2: as follows , such SRP Batcher Finally, we can get more together Pass Of Shader 了 :

Don't disable normal rendering .

Two Pass, A normal Pass, A custom LightMode Of Pass,lightMode Of Pass For rendering stroke ScriptableRendererFeature Manually specify a custom rendering LightMode.Unity I won't render your custom LightMode.

Thanks to Qiu Lei @UWA The Q & a community provides answers


The cover map comes from the Internet

Today's sharing is here . Of course , There is no end to life but to know . In the long development cycle , The problems you see may be just the tip of the iceberg , We are already in UWA The Q & a website has more technical topics waiting for you to explore and share together . You are welcome to join us , Maybe your method can solve other people's urgent needs ; And he's a mountain “ stone ”, Can also attack you “ jade ”.

Official website :www.uwa4d.com
Official technology blog :blog.uwa4d.com
Official Q & a community :answer.uwa4d.com
UWA School :edu.uwa4d.com
Official technology QQ Group :793972859( The original group is full )

原网站

版权声明
本文为[UWATech]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207071926551195.html

随机推荐