importing_images.rst 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. .. _doc_import_images:
  2. Importing images
  3. ================
  4. Why import them?
  5. ----------------
  6. In Godot 3+, image files are no longer native resources and they must be imported.
  7. The reason behind this is the large amount of configuration parameters that
  8. image files can be imported with.
  9. This small tutorial will explain what these parameters are and how to best
  10. make use of them.
  11. Importing textures
  12. ------------------
  13. The default action in Godot is to import images as textures. Textures are stored
  14. in video memory and can't be accessed directly. This is what makes drawing them
  15. efficient.
  16. Import options are vast:
  17. .. image:: img/image_import1.png
  18. Compression
  19. -----------
  20. Images are one of the largest assets in a game. To handle them efficiently, they need to be compressed.
  21. Godot offers several compression methods, depending on the use case.
  22. Compress Mode
  23. ~~~~~~~~~~~~~
  24. * VRAM Compression: This is the most common compression mode for 3D assets. File on disk is reduced and
  25. video memory usage is also reduced considerably. For 3D, it may present unwanted artifacts, though.
  26. * Lossless Compression: This is the most common compression for 2D assets. It shows assets without any
  27. kind of artifacting, and disk compression is decent. It will use considerably more amount of video memory than VRAM, though.
  28. * Lossy Compression: For games with lots of large 2D assets, lossy compression can be a great choice. It has some artifacting,
  29. but less than VRAM and the file size is almost a tenth of Lossless.
  30. * Uncompressed: Only useful for formats that can't be compressed (like, raw float).
  31. In this table, each of the four options are described together with their
  32. advantages and disadvantages ( |good| = Best, |bad| =Worst ):
  33. +----------------+------------------------+---------------------------+-------------------------+------------------------------------------------------+
  34. | | Uncompressed | Compress Lossless (PNG) | Compress Lossy (WebP) | Compress VRAM |
  35. +================+========================+===========================+=========================+======================================================+
  36. | Description | Stored as raw pixels | Stored as PNG | Stored as WebP | Stored as S3TC/BC,PVRTC/ETC, depending on platform |
  37. +----------------+------------------------+---------------------------+-------------------------+------------------------------------------------------+
  38. | Size on Disk | |bad| Large | |regular| Small | |good| Very Small | |regular| Small |
  39. +----------------+------------------------+---------------------------+-------------------------+------------------------------------------------------+
  40. | Memory Usage | |bad| Large | |bad| Large | |bad| Large | |good| Small |
  41. +----------------+------------------------+---------------------------+-------------------------+------------------------------------------------------+
  42. | Performance | |regular| Normal | |regular| Normal | |regular| Normal | |good| Fast |
  43. +----------------+------------------------+---------------------------+-------------------------+------------------------------------------------------+
  44. | Quality Loss | |good| None | |good| None | |regular| Slight | |bad| Moderate |
  45. +----------------+------------------------+---------------------------+-------------------------+------------------------------------------------------+
  46. | Load Time | |regular| Normal | |bad| Slow | |bad| Slow | |good| Fast |
  47. +----------------+------------------------+---------------------------+-------------------------+------------------------------------------------------+
  48. .. |bad| image:: img/bad.png
  49. .. |good| image:: img/good.png
  50. .. |regular| image:: img/regular.png
  51. HDR Mode
  52. ~~~~~~~~
  53. Godot supports high dynamic range textures (as .HDR or .EXR). These are mostly useful as high dynamic range equirectangular panorama skies (the internet
  54. has plenty if you search for them), which replace Cubemaps in Godot 2.x. Modern PCs support the BC6H VRAM format, but there are still plenty that do not.
  55. If you want Godot to ensure full compatibility in terms of the kind of textures, enable the "Force RGBE" option.
  56. Normal Map
  57. ~~~~~~~~~~
  58. When using a texture as normal map, only the red and green channels are required. Given regular texture compression algorithms produce artifacts that don't
  59. look that nice in normal maps, the RGTC compression format is the best fit for this data. Forcing this option to "Enabled" will make Godot import the
  60. image as RGTC compressed. By default, it's set to "Detect", which means that if the texture is ever used as a normal map, it will be changed to "Enabled" and
  61. reimported automatically.
  62. Flags
  63. -----
  64. There are plenty of settings that can be toggled when importing an image as a texture, depending on the use case.
  65. Repeat
  66. ~~~~~~
  67. This setting is most commonly used in 3D, and is therefore generally disabled in 2D. It sets UV coordinates going beyond the 0,0 - 1,1 range to "loop".
  68. Repeating can optionally be set to mirrored mode.
  69. Filter
  70. ~~~~~~
  71. When pixels become larger than the screen pixels, this option enables linear interpolation for them. The result is a smoother (less blocky) texture. This setting can be commonly used in 2D and 3D, but it's usually disabled when making pixel perfect games.
  72. Mipmaps
  73. ~~~~~~~
  74. When pixels become smaller than the screen, mipmaps kick in. This helps reduce the grainy effect when shrinking the textures. Keep in mind that, in older hardware
  75. (GLES2, mainly mobile), there are some requirements to use mipmaps:
  76. * Texture width and height must be powers of 2
  77. * Repeat must be enabled
  78. Keep in mind the above when making phone games and applications, want to aim for full compatibility, and need mipmaps.
  79. When doing 3D, mipmap should be turned on, as this also improves performance (smaller versions of the texture are used for objects further away).
  80. Anisotropic
  81. ~~~~~~~~~~~
  82. When textures are near parallel to the view (like floors), this option makes them have more detail by reducing blurriness.
  83. SRGB
  84. ~~~~
  85. Godot uses Linear colorspace when rendering 3D. Textures mapped to albedo or detail channels need to have this option turned on in order for colors to look correct.
  86. When set to "Detect" mode, the texture will be marked as SRGB when used in albedo channels.
  87. Process
  88. -------
  89. Some special processes can be applied to images when imported as textures.
  90. Fix Alpha Border
  91. ~~~~~~~~~~~~~~~~
  92. This puts pixels of the same surrounding color in transition from transparency to non transparency. It helps mitigate the outline effect when exporting images
  93. from Photoshop and the like.
  94. .. image:: img/fixedborder.png
  95. It's a good idea to leave it on by default, unless specific values are needed.
  96. Premultiplied Alpha
  97. ~~~~~~~~~~~~~~~~~~~
  98. An alternative to fix darkened borders is to use premultiplied alpha. By enabling this option, the texture will be converted to this format.
  99. Keep in mind that a material will need to be created that uses the PREMULT ALPHA blend mode on canvas items that need it.
  100. HDR as sRGB
  101. ~~~~~~~~~~~
  102. A few HDR files are broken and contain sRGB color data. It is advised not to use them, but, in the worst-case scenario, toggling this option on will make them look right.
  103. Invert Color
  104. ~~~~~~~~~~~~
  105. Reverses the image's color. This is useful, for example, to convert a height map generated by external programs to depth map to use with :ref:`doc_spatial_material`.
  106. Detect 3D
  107. ---------
  108. This option makes Godot be aware of when a texture (which is imported for 2D as default) is used in 3D. If this happens, setting are changed so the texture flags
  109. are friendlier to 3D (mipmaps, filter and repeat become enabled and compression is changed to VRAM). Texture is also reimported automatically.