Unity 3D Optimization and best Practices
1) Textures:
It depend on so many factors first of all try to use the textures to a
power of two (256x256, 512x512 and 1024x1024 etc.) And depends on
the platform we have to use the texture compression
IOS: Preferable
is PVRTC
Android/ BlackBerry: PVRTC compression is best
Windows Phone/Pc: DX1 is the preferable for environment
texture (without alpha), DX5 is the preferable for GUI texture (with alpha)
Work with a
high-resolution source file outside your unity project (such as a PSD or Gimp
file). You can always downsize from source but not the other way
round.
Use the texture resolution
output you require in your scene (save a copy, for example a 256x256 optimized
PNG or a TGA file). You can make a judgment based on where the texture will be
seen and where it is mapped.
Store your output texture files together in your Unity project (for example: \Assets\textures). Make
sure your 3D working file is referring to the same textures for consistency
when you save/export.
Make use of the
available space in your texture, but be aware of different materials requiring
different parts of the same texture. You can end up using/loading that texture
multiple times. For alpha (cutout) and elements that may require different
shaders, separate the textures. For example, the single texture below (left)
has been replaced by three smaller textures below (right) Make use of
tiling textures (which seamlessly repeat) then you can use better resolution
repeating over space Unity takes care of compression for the output
platform, so unless your source is already a JPG of the correct resolution it’s
better to use a loss less format for your textures. When creating a
texture page from photographs, reduce the page to individual modular sections
that can repeat. For example, you don’t need twelve of the same windows
using up texture space. That way you can have more pixel detail for that one
window.
2) Sound files:
Use the compress the large files like Background music use uncompressed
for small music like button click sound and effects if size is greater
than 100kb try to make it less than 100 by setting the compression
rate and load type as stream from disc or compressed in memory (64
bit compression is preferable)
3) Model Optimization (Mesh data):
Set your system and project units for your software to work consistently with
Unity e.g. Metric. Do not scale the object try to use the uniform scaling
as if you want to scale the object scale the FBX by changing the scale
factor. Working to scale can be important for both lighting and physics
simulation. Be aware that, for example, the Max system unit default is
inches and Maya is centimeters. Unity has different scaling for FBX and
3D application files on import check the FBX import scale setting in
Inspector. Animation frame rate defaults can be different in packages, is
a good idea to set consistently across your pipeline, for example 30fps.
4) Mesh Optimization :
static batching is only works if your model consists of less than 300
trice so make sure the trice count is less much as possible
Build with an efficient topology. Use polygons only where you need them.
Optimize your geometry if it has too many polygons. Many character models need
to be intelligently optimized or even rebuilt by an artist especially if
sourced/built from: 1) 3D capture data 2) Poser 3) Z brush
Other high density
Nurbs/Patch models designed for render Where you can afford them, evenly
spaced polygons in buildings, landscape and architecture will help spread
lighting and avoid awkward kinks. Avoid really long thin triangles.
5) Shaders :
try to use the mobile version of shaders as it will gives the best performance
as if you want to go with your custom shaders that's very good
alternative for you. Avoid the pixel light shaders use the custom sphere
or plane and avoid the standard sky box as it will cost 8 Draw calls.
6) Scripting Optimization:
Void OnBecameVisible
() {
enabled = true;
}
void OnBecameInvisible
() {
enabled = false;
}
1) Use OnBecameVisible and OnBecameInvisible methods
automatically
These two functions will make sure the code optimization
techniques as if camera rendering the object then only script will be in
running state else would be in disable state it would be use for effects and
coins rotation scripts. We can reduce the over head
2) Try to avoid the finding the game objects at run time
(just load once in Start or Awake)
3) Try to use the generic GUI like NGUI try to run less updates and On
GUI methods.
4) For Object pooling you can get here.
http://thepigstudio.com/common-patterns-in-unity3d-singleton-and-object-pooling/
references :
1) http://wiki.unity3d.com/index.php?title=General_Performance_Tips
2) http://docs.unity3d.com/Manual/ReducingFilesize.html
3) http://docs.unity3d.com/Manual/HOWTO-ArtAssetBestPracticeGuide.html
4)http://docs.unity3d.com/Documentation/Manual/OptimizingGraphicsPerformance.html
5)http://docs.unity3d.com/Documentation/Manual/ReducingFilesize.html
6)http://unity3d.com/Documentation/Manual/Character-Animation.html
7)http://www.digitaltutors.com/tutorial/1467-Game-Optimization-Techniques-in-Unity
It depend on so many factors first of all try to use the textures to a power of two (256x256, 512x512 and 1024x1024 etc.) And depends on the platform we have to use the texture compression
Android/ BlackBerry: PVRTC compression is best
Windows Phone/Pc: DX1 is the preferable for environment texture (without alpha), DX5 is the preferable for GUI texture (with alpha)
Store your output texture files together in your Unity project (for example: \Assets\textures). Make sure your 3D working file is referring to the same textures for consistency when you save/export.
2) Sound files:
Use the compress the large files like Background music use uncompressed for small music like button click sound and effects if size is greater than 100kb try to make it less than 100 by setting the compression rate and load type as stream from disc or compressed in memory (64 bit compression is preferable)
3) Model Optimization (Mesh data):
Set your system and project units for your software to work consistently with Unity e.g. Metric. Do not scale the object try to use the uniform scaling as if you want to scale the object scale the FBX by changing the scale factor. Working to scale can be important for both lighting and physics simulation. Be aware that, for example, the Max system unit default is inches and Maya is centimeters. Unity has different scaling for FBX and 3D application files on import check the FBX import scale setting in Inspector. Animation frame rate defaults can be different in packages, is a good idea to set consistently across your pipeline, for example 30fps.
4) Mesh Optimization :
static batching is only works if your model consists of less than 300 trice so make sure the trice count is less much as possible Build with an efficient topology. Use polygons only where you need them. Optimize your geometry if it has too many polygons. Many character models need to be intelligently optimized or even rebuilt by an artist especially if sourced/built from: 1) 3D capture data 2) Poser 3) Z brush
5) Shaders :
try to use the mobile version of shaders as it will gives the best performance as if you want to go with your custom shaders that's very good alternative for you. Avoid the pixel light shaders use the custom sphere or plane and avoid the standard sky box as it will cost 8 Draw calls.
enabled = true;
}
void OnBecameInvisible () {
enabled = false;
}
3) Try to use the generic GUI like NGUI try to run less updates and On GUI methods.
4) For Object pooling you can get here.
1) http://wiki.unity3d.com/index.php?title=General_Performance_Tips
2) http://docs.unity3d.com/Manual/ReducingFilesize.html
3) http://docs.unity3d.com/Manual/HOWTO-ArtAssetBestPracticeGuide.html
4)http://docs.unity3d.com/Documentation/Manual/OptimizingGraphicsPerformance.html
5)http://docs.unity3d.com/Documentation/Manual/ReducingFilesize.html
6)http://unity3d.com/Documentation/Manual/Character-Animation.html
7)http://www.digitaltutors.com/tutorial/1467-Game-Optimization-Techniques-in-Unity
You have a good point here!I totally agree with what you have said!!Thanks for sharing your views...hope more people will read this article!!!
ReplyDeleteWall Lights