Chris
November 10, 2020, 3:29pm
#1
Just noticed the docs for optimization have been expanded, very nice!
Wanted to mention a minor typo. The second link correctly goes to the docs for renderNextFrame
, but it says pc.Application#autoRender
instead of pc.Application#renderNextFrame
.
Hi @Chris ,
Thanks for reporting those, if you feel like it the docs are opensource as well and a typo correcting PR is more than welcome:
---
title: Optimization Guidelines
template: usermanual-page.tmpl.html
position: 1
---
Here are some tips and hints on how to achieve good performance in your PlayCanvas app.
## JavaScript
* Calling 'new' to allocate a JavaScript object (particularly vectors, matrices and quaternions) represents a dynamic allocation and can be expensive. Therefore you should, where possible, preallocate objects in a script's initialize function and reuse them in the update function. It also leads to Garbage Collection which can cause periodical freezes.
## Graphics
* As the value for texture anisotropy increases, visual improve but performance decreases. Be careful to balance visuals against performance.
* Look for opportunities to pack multiple textures into single images. For example, a greyscale opacity map can be stored in the alpha channel of a diffuse map. Or a greyscale gloss map can be stored in the alpha channel of a specular map. This results in lower VRAM usage.
* Be mindful of the number of dynamic lights in your scene. Keep them to a minimum.
* Enabling shadow casting on dynamic lights is expensive. Point light shadows are particularly expensive. For each point light that casts shadow, the scene must be rendered 6 times into a shadow map.
* In PlayCanvas, a mesh instance is a draw call (a command to draw an individual graphical primitive). Each draw call requires some effort on the CPU to dispatch to WebGL. Therefore, keeping the number of draw calls low is advisable, particularly on mobile. You can see a list of the draw calls for a particular Model by selecting the model asset and viewing it in the Inspector. 100-200 draw calls is a rough target for low end mobile devices. High end desktop machines on the other hand can process thousands every frame and still maintain 60fps.
* Use [Batching][1] to reduce draw calls. By creating Batch Groups in your Project and assigning them to Model and Element components, the engine will try to merge them in as few mesh instances as possible, reducing draw calls and increasing performance.
This file has been truncated. show original
1 Like
Chris
November 10, 2020, 3:34pm
#3
That’s where they are! Was trying to find a separate repo and I couldn’t find them. Thanks Leo!
1 Like