Up to date

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

Optimizando las prestaciones en 3D

Polling

Godot realizará automáticamente culling de frustum de vista para evitar renderizar objetos que están fuera de la vista del viewport. Esto funciona bien para juegos que se desarrollan en áreas pequeñas, sin embargo, puede haber problemas rápidamente en niveles más grandes.

Eliminación de oclusión

Al caminar por una ciudad, por ejemplo, es posible que solo puedas ver unos pocos edificios en la calle en la que te encuentras, así como el cielo y algunos pájaros volando por encima. Sin embargo, desde la perspectiva de un renderizador ingenuo, aún podrías ver toda la ciudad. No solo renderizará los edificios que tienes enfrente, sino también la calle detrás de ellos, con las personas en esa calle y los edificios que están más lejos. Rápidamente te encontrarás en situaciones en las que intentas renderizar 10× o 100× más de lo que es 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 Eliminación de oclusión for instructions on setting up occlusion culling in your scene.

Nota

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.

Objetos transparentes

Como se mencionó antes, Godot clasifica los objetos por material y shader para mejorar el rendimiento. Esto, sin embargo, no se puede hacer en objetos transparentes. Los objetos transparentes se renderizan de atrás hacia adelante para hacer que se mezclen con lo que hay detrás del trabajo. Por lo tanto ¡intenta reducir al mínimo la transparencia de los objetos! Si un objeto tiene una sección pequeña con transparencia, intenta hacer de esa sección un material independiente.Godot ordena los objetos por Material y Shader para mejorar el rendimiento. Sin embargo, esto no se puede hacer con objetos transparentes. Los objetos transparentes se renderizan de atrás hacia adelante para combinarlos con lo que hay detrás. Como resultado, intente utilizar la menor cantidad posible de objetos transparentes. Si un objeto tiene una sección pequeña con transparencia, intente hacer de esa sección una superficie separada con su propio material.

Para obtener más información, consulte GPU optimizations doc.

Nivel de detalle (LOD)

En algunas situaciones, particularmente a distancia, puede ser una buena idea ** reemplazar geometrías complejas con versiones más simples **. El usuario final probablemente no podrá ver mucha diferencia. Considere mirar una gran cantidad de árboles a lo lejos. Existen varias estrategias para reemplazar modelos a diferentes distancias. Puede usar modelos con polígonos mas bajos o usar transparencia para simular geometrías más complejas.

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).

Vallas publicitarias e impostores

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 Optimización de GPU).

Una alternativa es renderizar no solo un árbol, sino un numero de arboles juntos como grupo. Esto puede ser efectivo especialmente si puedes ver el área pero no puedes aproximarte físicamente en el juego.

Puedes crear impostores mediante la pre-renderización de vistas de un objeto desde diferentes ángulos. Incluso puedes ir un paso más allá y volver a renderizar periódicamente una vista de un objeto en una textura para utilizarla como impostor. A una distancia, es necesario mover al observador una distancia considerable para que el ángulo de visión cambie significativamente. Esto puede ser complejo de implementar, pero puede valer la pena dependiendo del tipo de proyecto que estés desarrollando.

Usar la instanciación (MultiMesh)

Si hay que dibujar varios objetos iguales en el mismo lugar o cercanos entre sí, intenta usar MultiMesh en su lugar. MultiMesh permite dibujar decenas de miles de objetos con un coste de rendimiento muy bajo, lo que lo hace ideal para multitudes, hierba, partículas, etc.

See also the Using MultiMesh documentation.

Bake de iluminación

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.

Animación y 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.

Mundos extensos

Si está creando mundos grandes, hay consideraciones diferentes que le puede ser familiar en los juegos más pequeños.

Mundos grandes pueden necesitar ser construidos en tiles que se pueden cargar bajo demanda mientras se mueve por el mundo. Esto puede evitar que el uso de la memoria se vaya de las manos y también limitar el procesamiento necesario al área local.

There may also be rendering and physics glitches due to floating point error in large worlds. This can be resolved using Coordenadas de mundo extenso. 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).