Avatar SDK Performance Optimization Guide
Optimization means that you want to display the best Avatar quality with as little resources possible (The best for the less). In fact there are a few important points to consider when designing an Avatar.
– Triangle count (Also called Polygon Count)
– Material count
– Skin-mesh count
– Texture size (In Pixels and in Mega Bytes)
– Special effects (Particles, cloth, dynamic bones, shaders, layers etc)
First of all, the first question to ask yourself is: “what is really necessary on my Avatar ?”. Considering we could easily be more than 20 avatars in one close location, we need to be sure we won’t contribute to the poorly optimized avatars. Or at least it is important to understand and be mindful that you can affect low spec PC players.
Known as polygon count, these represent the total amount of final triangles that will shade an avatar. There are few reasons why triangle count will impact performance. First, more triangles mean more overhead when rendering the same surface, since there is extra steps to do. Also, those triangles are deformed every frame by the armature. So the more triangles you have, the longer it is to apply the bones pose to the skin.
Ideally we try to be around 32k triangles up to 70k if you think your model really need that level of details. Maybe you could reduce the material amount and other effects to counter balance the cost.
Materials are a complete step of rendering a batch of triangles, and include a lot of overhead steps. it is important to keep the material count as low as possible.
In theory, one material for opaque and one for transparency is normally plenty. The rest is about optimization.
Complex shaders are a very unique problem. Since it is very hard to optimize Amplify-Shader shaders. a good idea would be to reduce to the maximum complexity and the surface that this shader is applied to. It could be an idea to use an individual material for this shader to be sure it is not applied to the entire Avatar. In fact, even if you say to the shader “display this complex effect to 1% of the surface” by defaults it will execute the complex computation on all the surface even if you don’t see it. For texture it is different, Amplify Shader can understand in most of the case if a texture is displayed or not and prevent using it in some instances.
The story is again very similar, when you divide the same task into multiple ones you create overhead because you repeat steps that could have been done once.
One of the biggest impact of texture size is the memory access, the bigger the texture the more access is needed on the GPU. This part is very hard to predict and to understand. Normally we try to have the least texture possible even if it means combining the texture together. For example, a high quality Avatars could use a 4K texture for color, a 4K for normal map and one other for Metallic and Smoothness for a total of 3.
Making an avatar in total symmetry can help increasing pixel density since you have 2 time less surface to spread on the texture
A day to day avatar should not have to much special effects since you will penalize everyone with this extra GPU cost. “What is the minimal effect i really need on my avatar ?”
Dynamic bones really add something on avatars when you look at yourself in the mirror. Normally you can even use few bones to move all your hair or a huge piece of cloth.
Custom shader can be problematic because there is no real limits. And you have to remember that all your shader logic is executed on every single pixel ! A few effects are heavier than others and if you add them together it can get out of control very fast. Parallax, noise generator, screen space sampler are few examples of intensives tasks. Sometimes you may want to use the less logic possible and use texture instead to do part of the job. In fact GPU are made to do a balanced load of everything so it is not necessarily faster to have no texture for example. So you should never use too much of anything but instead keeping a balance (Material count, triangle count, texture size, shader complexity etc).
Particles system are one of the heaviest effect on games. This load comes from the accumulation of transparent rendering layers. Normally in a game you don’t have that much accumulation of surface in front of each other and there is technique to reduce it. For particles it is different, because it is easy to render 1000 times the same area by accident in a transparent mode. Another thing to consider is the invisible render cost of particles. In fact, even if a huge part of the particles are invisible, the render cost is still there. So if you render lines particles the hidden area can easily be 90% and every particles area add to each other for the rendering step.