Unity's audio and picture optimization

Reporter: Why write this? Many optimization resource posts on the Internet are very good. I wrote because although I took notes, I still always forget so...

One: audio

 1: Sound type

  (1): aif/aiff is suitable for short music files as fighting repetitive sound effects
 (2): wav is suitable for short music files as fighting repetitive sound effects
 (3): mp3 is suitable for long music files as bgm
 (4): ogg is suitable for long music files as bgm (ogg is smaller than MP3, can't it be used as fighting sound effects)   
   ps: ogg, a non-mobile platform such as pc host, is a better choice than MP3, which is more suitable for mobile devices (iphone comes with MP3 decoder)
           If you want to use seamless loop for music or sound effects, it is recommended to use OGG as the source file. And use the hardware playback method to reduce the loss of memory.

2: Import settings

 
(1) Force to Mono: Force mono, some "unimportant" audio does not require left and right channels, we can check this to reduce memory

(2) load in background: The loading of the clip will be delayed on a separate thread without blocking the main thread. If enabled, audio clips will be loaded in the background instead of being imported in the main thread.
        Caused a standstill, which is off by default, to ensure that all the audio clips have completed standard behavior Unity loaded when the scene starts to play. Note that the audio clip is still loading in the background
        The broadcast put the request will be delayed until the clip has finished loading. The loading state can be queried through the AudioClip.loadState property.

(_) Ambisonic (2017 version) High-fidelity stereo surround sound is more suitable for 360 panorama and XR

(3) There are three types of loadType
 [1]: decompress on load upon load when decompressed, frequently used for audio note, decompression Vorbis encoding when loading sound about ten times more than its use compressed memory
     (About 3.5 times for ADPCM encoding) , so don't use this option in large files.

 [2]: compresse in memory memory compression decompression will increase when playing cpu but only for large files to save memory decompressed thread on the mixer, the window may Profiler
        Monitor the "DSP CPU" part of the audio panel

 [3]: Streaming reading saves the smallest cpu and memory. The disadvantage is that it can only be referenced once for singleton audio, suitable for bgm (this method is not preferred for mobile games)
    Note: Even if no audio data is loaded, the streaming clip will have an overload of about 200KB.

(4) preload audio data will be loaded at the beginning of the scene 

(. 5) the compress the format compression format
 [1]: PCM provides high-quality files that will be larger, suitable for short sound effects
 [2]: ADPCM is suitable for heavily used sound effects, such as footstep bullets, which are 3.5 times less than PCM, and the CPU usage rate is much lower than vorbis/mp3. It is the first choice for these reusable sound effects
 [3]: Vorbis/mp3 is smaller than PCM but has lower quality and consumes more CPU than ADPCM. First choice for mobile devices (choose MP3 for iPhone with decoder and vorbis for Android). Check this
        You can also adjust the quality, this format is most suitable for medium-length sound effects and music.
  [4] : HEVAG This is the native format used on PS Vita. This specification is very similar to the ADPCM format.

(. 6) Sample Rate Setting sampling rate PCM and ADPCM compression format allows automatic optimization manually or decrease the sampling rate
  [1]: Preserve Sample Rate keep the sample rate unchanged
  [2]: Optimize Sample Rate This setting automatically optimizes the sample rate according to the highest frequency content analyzed
[3]: Override Sample Rate allows manual override of sample rate, so it can be effectively used to discard frequency content

3: Disable the built-in audio when using third-party plug-ins

 

4: Some other Tips

 (1) Generally speaking, PCM and Vorbis/MP3 formats are preferable to keep the sound as close to the original as possible. PCM has very light requirements on the CPU, because the sound is uncompressed and can only be taken from the memory
        Read. Vorbis/MP3 allows adaptively discarding less audible information through the quality slider.  
(2) ADPCM is a compromise between memory and CPU usage, because it only uses slightly more CPU than the uncompressed PCM option, but produces a constant compression factor of 3.5, which is usually better than using Vorbis or
          MP3可以达到的压缩要差3倍压缩。 此外,ADPCM(如PCM)允许使用自动优化或手动设置的采样率,这取决于声音的频率内容和可接受的
            质量损失
(3) 模块文件(.mod,.it,.s3m..xm)可以以极低的占用空间提供非常高的质量。使用模块文件时,除非特别需要,否则请确保将“加载类型”设置
        为“Compressed In Memory  因为如果设置为“Decompress On Load 整首歌曲将被解压缩。这是Unity 5.0中的一个新行为,它允许在这些类型的
        剪辑上使用GetData / SetData,但是跟踪器模块的一般和默认用例是将它们压缩到内存

二:贴图

            1:贴图的导入

            (1)如果图片是作为UI那么去掉Generate Mip maps 一般不勾选read/write enable(除非要对图片进行读写才勾选)。 

            (2)ui图片小图片打包成图集,大图片一般不打图集(大图会把图集撑大)。 

            (3)对于不必要使用透明通道的图片,可以使用jpg代替png,图形学决定图片的像素大小都要遵循2的n次方,UI图集会默认遵循这个原则,但是对于单个图片,可以在图片导入进行设置(一般勾选toNearest(最接近))

            

            2:图片压缩方式

               Android:android所有机器都支持etc1压缩方式,但是etc1不支持透明通道。etc2是支持透明通道的,但是这是基于opengl3.0,在某些低端机无法使用。目前很多使用最多的是etc1+alpha通道分离技术,在unity5.3以后 unity自带etc1分离技术


        注意点:必须打图集,只有图片是2的n次方的图片才能使用etc1压缩,导出apk的时候如果出现材质丢失,在Project Setting--Graphic--Always Included Shaders里面添加 UI/DefaultETC1,可以看另一个链接

IOS:使用PVRTC格式压缩,它支持含Alpha通道的图片压缩。

PC:有偷透明通道的压缩为DXT5,没有透明通道的使用DXT1

另外,unity 5.3Crunch压缩库是一种很好的压缩方式 缺点就是压缩计算时间有点长,官方链接




Guess you like

Origin blog.csdn.net/K20132014/article/details/79199954