Optimizando las prestaciones en 3D¶
Godot will automatically perform view frustum culling in order to prevent rendering objects that are outside the viewport. This works well for games that take place in a small area, however things can quickly become problematic in larger levels.
Eliminación de oclusión¶
Walking around a town for example, you may only be able to see a few buildings in the street you are in, as well as the sky and a few birds flying overhead. As far as a naive renderer is concerned however, you can still see the entire town. It won't just render the buildings in front of you, it will render the street behind that, with the people on that street, the buildings behind that. You quickly end up in situations where you are attempting to render 10× or 100× more than what is 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 GLES3 renderer. However, unneeded objects are still reducing performance.
One way we can potentially reduce the amount to be rendered is to take advantage of occlusion. As of Godot 3.2.2, there is no built in support for occlusion in Godot. However, with careful design you can still get many of the advantages.
For instance, in our city street scenario, you may be able to work out in advance
that you can only see two other streets,
C, from street
Z are hidden. In order to take advantage of occlusion, all
you have to do is work out when your viewer is in street
A (perhaps using
Godot Areas), then you can hide the other streets.
This is a manual version of what is known as a "potentially visible set". It is a very powerful technique for speeding up rendering. You can also use it to restrict physics or AI to the local area, and speed these up as well as rendering.
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 opportunies for occlusion culling.
Other occlusion techniques¶
There are other occlusion techniques such as portals, automatic PVS, and raster-based occlusion culling. Some of these may be available through add-ons and may be available in core Godot in the future.
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)¶
In some situations, particularly at a distance, it can be a good idea to replace complex geometry with simpler versions. The end user will probably not be able to see much difference. Consider looking at a large number of trees in the far distance. There are several strategies for replacing models at varying distance. You could use lower poly models, or use transparency to simulate more complex geometry.
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 which case transparency may start eating into fill rate (for more information on fill rate, see Optimización de GPU).
An alternative is to render not just one tree, but a number of trees together as a group. This can be especially effective if you can see an area but cannot physically approach it in a game.
You can make imposters by pre-rendering views of an object at different angles. Or you can even go one step further, and periodically re-render a view of an object onto a texture to be used as an imposter. At a distance, you need to move the viewer a considerable distance for the angle of view to change significantly. This can be complex to get working, but may be worth it depending on the type of project you are making.
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.
Also see the Using MultiMesh doc.
Bake de iluminación¶
Lighting objects is one of the most costly rendering operations. Realtime lighting, shadows (especially multiple lights), and GI 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 trade-off worth making.
En general, si varias luces necesitan afectar una escena, es mejor usar Baked lightmaps. Hornear también puede mejorar la calidad de la escena al agregar rebotes de luz indirectos.
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 one time.
If you are making large worlds, there are different considerations than what you may be familiar with from smaller games.
Large worlds may need to be built in tiles that can be loaded on demand as you move around the world. This can prevent memory use from getting out of hand, and also limit the processing needed to the local area.
There may also be rendering and physics glitches due to floating point error in
large worlds. 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).