Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

Optimiser les performances 3D

Culling

Godot effectuera automatiquement un frustrum culling de la vue afin d'éviter de rendre des objets qui se trouvent en dehors du viewport. Cela fonctionne bien pour les jeux qui se déroulent dans une petite zone, mais les choses peuvent rapidement devenir problématiques dans les niveaux plus large.

Occlusion culling

En vous promenant dans une ville par exemple, vous ne pourrez peut-être voir que quelques bâtiments dans la rue où vous vous trouvez, ainsi que le ciel et quelques oiseaux qui volent au-dessus de vous. En ce qui concerne un moteur de rendu naïf, vous pouvez cependant voir toute la ville. Il ne se contentera pas de rendre les bâtiments devant vous, il rendra la rue derrière, avec les gens dans cette rue, les bâtiments derrière. Vous vous retrouvez rapidement dans des situations où vous essayez de rendre 10×, ou 100× plus que ce qui est visible.

Things aren't quite as bad as they seem, because the Z-buffer usually allows the GPU to only fully shade the objects that are at the front. This is called depth prepass and is enabled by default in Godot when using the Forward+ or Compatibility rendering methods. However, unneeded objects are still reducing performance.

One way we can potentially reduce the amount to be rendered is to take advantage of occlusion. Godot 4.0 and later offers a new approach to occlusion culling using occluder nodes. See Occlusion culling for instructions on setting up occlusion culling in your scene.

Note

In some cases, you may have to adapt your level design to add more occlusion opportunities. For example, you may have to add more walls to prevent the player from seeing too far away, which would decrease performance due to the lost opportunities for occlusion culling.

Objets transparents

Godot trie les objets par Material et par Shader pour améliorer les performances. Toutefois, cela ne peut pas être fait sur des objets transparents. Les objets transparents sont rendus de l'arrière vers l'avant pour se fondre avec ce qui se trouve derrière. Par conséquent, essayez de réduire au minimum les objets transparents. Si un objet a une petite section avec transparence, essayez de faire de cette section une surface séparée avec son propre Material.

Pour plus d'informations, voir la documentation GPU optimizations.

Niveau de détail (LOD)

Dans certaines situations, en particulier à distance, il peut être judicieux de remplacer une géométrie complexe par des versions plus simples. L'utilisateur final ne verra probablement pas beaucoup de différence. Envisagez de regarder un grand nombre d'arbres à distance. Il existe plusieurs stratégies pour remplacer les modèles à distance variable. Vous pouvez utiliser des modèles à plus faible polygones, ou utiliser la transparence pour simuler une géométrie plus complexe.

Godot 4 offers several ways to control level of detail:

While they can be used independently, these approaches are most effective when used together. For example, you can set up visibility ranges to hide particle effects that are too far away from the player to notice. At the same time, you can rely on mesh LOD to make the particle effect's meshes rendered with less detail at a distance.

Visibility ranges are also a good way to set up impostors for distant geometry (see below).

Billboards(panneaux d'affichage) et imposteurs

The simplest version of using transparency to deal with LOD is billboards. For example, you can use a single transparent quad to represent a tree at distance. This can be very cheap to render, unless of course, there are many trees in front of each other. In this case, transparency may start eating into fill rate (for more information on fill rate, see Optimisation GPU).

Une alternative consiste à rendre non pas un seul arbre, mais plusieurs arbres ensemble en tant que groupe. Cela peut être particulièrement efficace si vous pouvez voir une zone mais ne pouvez pas l'approcher physiquement dans un jeu.

Vous pouvez créer des imposteurs en pré-rendant des vues d'un objet sous différents angles. Vous pouvez même aller plus loin et re-rendre périodiquement une vue d'un objet sur une texture pour l'utiliser comme un imposteur. À distance, vous devez déplacer le spectateur sur une distance considérable pour que l'angle de vue change de manière significative. Cela peut être complexe à mettre en œuvre, mais peut en valoir la peine selon le type de projet que vous réalisez.

Utiliser l'instanciation (MultiMesh)

Si plusieurs objets identiques doivent être dessinés au même endroit ou à proximité, essayez d'utiliser MultiMesh. MultiMesh permet de dessiner des dizaines de milliers d'objets à très faible coût de performance, ce qui le rend idéal pour les troupeaux, l'herbe, les particules et tout ce qui comporte des milliers d'objets identiques.

See also the Using MultiMesh documentation.

Préparation de l’éclairage

Lighting objects is one of the most costly rendering operations. Realtime lighting, shadows (especially multiple lights), and global illumination are especially expensive. They may simply be too much for lower power mobile devices to handle.

Consider using baked lighting, especially for mobile. This can look fantastic, but has the downside that it will not be dynamic. Sometimes, this is a tradeoff worth making.

See Using Lightmap global illumination for instructions on using baked lightmaps. For best performance, you should set lights' bake mode to Static as opposed to the default Dynamic, as this will skip real-time lighting on meshes that have baked lighting.

The downside of lights with the Static bake mode is that they can't cast shadows onto meshes with baked lighting. This can make scenes with outdoor environments and dynamic objects look flat. A good balance between performance and quality is to keep Dynamic for the DirectionalLight3D node, and use Static for most (if not all) omni and spot lights.

Animation et skinning

Animation and vertex animation such as skinning and morphing can be very expensive on some platforms. You may need to lower the polycount considerably for animated models, or limit the number of them on screen at any given time. You can also reduce the animation rate for distant or occluded meshes, or pause the animation entirely if the player is unlikely to notice the animation being stopped.

The VisibleOnScreenEnabler3D and VisibleOnScreenNotifier3D nodes can be useful for this purpose.

Grands mondes

Si vous créez de grands mondes, il y a des considérations différentes de celles que vous connaissez peut-être avec les jeux plus petits.

Les grands mondes peuvent devoir être construits dans des tuiles qui peuvent être chargées à la demande lorsque vous vous déplacez dans le monde. Cela peut éviter que l'utilisation de la mémoire ne devienne incontrôlable et limiter le traitement nécessaire à la zone locale.

There may also be rendering and physics glitches due to floating point error in large worlds. This can be resolved using Large world coordinates. If using large world coordinates is an option, you may be able to use techniques such as orienting the world around the player (rather than the other way around), or shifting the origin periodically to keep things centred around Vector3(0, 0, 0).