optimizing_3d_performance.rst 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. .. meta::
  2. :keywords: optimization
  3. .. _doc_optimizing_3d_performance:
  4. Optimizing 3D performance
  5. =========================
  6. Culling
  7. =======
  8. Godot will automatically perform view frustum culling in order to prevent
  9. rendering objects that are outside the viewport. This works well for games that
  10. take place in a small area, however things can quickly become problematic in
  11. larger levels.
  12. Occlusion culling
  13. ~~~~~~~~~~~~~~~~~
  14. Walking around a town for example, you may only be able to see a few buildings
  15. in the street you are in, as well as the sky and a few birds flying overhead. As
  16. far as a naive renderer is concerned however, you can still see the entire town.
  17. It won't just render the buildings in front of you, it will render the street
  18. behind that, with the people on that street, the buildings behind that. You
  19. quickly end up in situations where you are attempting to render 10x, or 100x
  20. more than what is visible.
  21. Things aren't quite as bad as they seem, because the Z-buffer usually allows the
  22. GPU to only fully shade the objects that are at the front. However, unneeded
  23. objects are still reducing performance.
  24. One way we can potentially reduce the amount to be rendered is to take advantage
  25. of occlusion. As of version 3.2.2 there is no built in support for occlusion in
  26. Godot, however with careful design you can still get many of the advantages.
  27. For instance in our city street scenario, you may be able to work out in advance
  28. that you can only see two other streets, ``B`` and ``C``, from street ``A``.
  29. Streets ``D`` to ``Z`` are hidden. In order to take advantage of occlusion, all
  30. you have to do is work out when your viewer is in street ``A`` (perhaps using
  31. Godot Areas), then you can hide the other streets.
  32. This is a manual version of what is known as a 'potentially visible set'. It is
  33. a very powerful technique for speeding up rendering. You can also use it to
  34. restrict physics or AI to the local area, and speed these up as well as
  35. rendering.
  36. Other occlusion techniques
  37. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  38. There are other occlusion techniques such as portals, automatic PVS, and raster
  39. based occlusion culling. Some of these may be available through addons, and may
  40. be available in core Godot in the future.
  41. Transparent objects
  42. ~~~~~~~~~~~~~~~~~~~
  43. Godot sorts objects by :ref:`Material <class_Material>` and :ref:`Shader
  44. <class_Shader>` to improve performance. This, however, can not be done with
  45. transparent objects. Transparent objects are rendered from back to front to make
  46. blending with what is behind work. As a result, try to use as few transparent
  47. objects as possible. If an object has a small section with transparency, try to
  48. make that section a separate surface with its own Material.
  49. For more information, see the :ref:`GPU optimizations <doc_gpu_optimization>`
  50. doc.
  51. Level of detail (LOD)
  52. =====================
  53. In some situations, particularly at a distance, it can be a good idea to replace
  54. complex geometry with simpler versions - the end user will probably not be able
  55. to see much difference. Consider looking at a large number of trees in the far
  56. distance. There are several strategies for replacing models at varying distance.
  57. You could use lower poly models, or use transparency to simulate more complex
  58. geometry.
  59. Billboards and imposters
  60. ~~~~~~~~~~~~~~~~~~~~~~~~
  61. The simplest version of using transparency to deal with LOD is billboards. For
  62. example, you can use a single transparent quad to represent a tree at distance.
  63. This can be very cheap to render, unless of course, there are many trees in
  64. front of each other. In which case transparency may start eating into fill rate
  65. (for more information on fill rate, see :ref:`doc_gpu_optimization`).
  66. An alternative is to render not just one tree, but a number of trees together as
  67. a group. This can be especially effective if you can see an area but cannot
  68. physically approach it in a game.
  69. You can make imposters by pre-rendering views of an object at different angles.
  70. Or you can even go one step further, and periodically re-render a view of an
  71. object onto a texture to be used as an imposter. At a distance, you need to move
  72. the viewer a considerable distance for the angle of view to change
  73. significantly. This can be complex to get working, but may be worth it depending
  74. on the type of project you are making.
  75. Use instancing (MultiMesh)
  76. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  77. If several identical objects have to be drawn in the same place or nearby, try
  78. using :ref:`MultiMesh <class_MultiMesh>` instead. MultiMesh allows the drawing
  79. of many thousands of objects at very little performance cost, making it ideal
  80. for flocks, grass, particles, and anything else where you have thousands of
  81. identical objects.
  82. Also see the :ref:`Using MultiMesh <doc_using_multimesh>` doc.
  83. Bake lighting
  84. =============
  85. Lighting objects is one of the most costly rendering operations. Realtime
  86. lighting, shadows (especially multiple lights), and GI are especially expensive.
  87. They may simply be too much for lower power mobile devices to handle.
  88. Consider using baked lighting, especially for mobile. This can look fantastic,
  89. but has the downside that it will not be dynamic. Sometimes this is a trade off
  90. worth making.
  91. In general, if several lights need to affect a scene, it's best to use
  92. :ref:`doc_baked_lightmaps`. Baking can also improve the scene quality by adding
  93. indirect light bounces.
  94. Animation / Skinning
  95. ====================
  96. Animation and particularly vertex animation such as skinning and morphing can be
  97. very expensive on some platforms. You may need to lower poly count considerably
  98. for animated models or limit the number of them on screen at any one time.
  99. Large worlds
  100. ============
  101. If you are making large worlds, there are different considerations than what you
  102. may be familiar with from smaller games.
  103. Large worlds may need to be built in tiles that can be loaded on demand as you
  104. move around the world. This can prevent memory use from getting out of hand, and
  105. also limit the processing needed to the local area.
  106. There may be glitches due to floating point error in large worlds. You may be
  107. able to use techniques such as orienting the world around the player (rather
  108. than the other way around), or shifting the origin periodically to keep things
  109. centred around (0, 0, 0).