managing_image_files.rst 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. .. _doc_managing_image_files:
  2. Managing image files
  3. ====================
  4. If you have read the previous tutorials on :ref:`doc_resources` and :ref:`doc_file_system`, at this point you know that regular image files (.png, .jpg,
  5. etc) are treated as regular resources in Godot.
  6. Unlike texture resources (.tex files), image files contain no extra
  7. information on tiling (texture repeat), mipamps or filtering. Editing
  8. this information and saving the texture back will have not any effect,
  9. since such formats can't contain that information.
  10. Image loader
  11. ------------
  12. Loading of images is done by the image loader. The behavior of the
  13. loader for all image files can be changed in the Project Settings dialog
  14. (Scene -> Project Settings). There is a section with values that
  15. correspond to the every image file when loaded:
  16. .. image:: /img/imgloader.png
  17. Image loader options
  18. --------------------
  19. Filter
  20. ~~~~~~
  21. Filter is used when the image is stretched more than it's original size,
  22. so a texel in the image is bigger than a pixel on the screen. Turning
  23. off the fiter produces a retro-like look:
  24. .. image:: /img/imagefilter.png
  25. Repeat
  26. ~~~~~~
  27. Repeat is mainly used for 3D textures, so it's off by default (textures
  28. are imported with the scenes and usually are not in the project as image
  29. files). When using UV coordinates (something not as common in 2D), and
  30. the UV value goes beyond the 0,0,1,1 rect, the texture repeats instead
  31. of clamping to the edge.
  32. Mipmaps
  33. ~~~~~~~
  34. When the mipmaps option is enabled, Godot will generate mip-maps.
  35. Mipmaps are versions of the image shrunk by half in both axis,
  36. recursively, until the image is 1 pixel of size. When the 3D hardware
  37. needs to shrink the image, it finds the largest mipmap it can scale
  38. from, and scales from there. This improves performance and image
  39. quality.
  40. .. image:: /img/mipmaps.png
  41. When Mip-Maps are disabled, images start distorting badly when shrunk
  42. excessively:
  43. .. image:: /img/imagemipmap.png
  44. Alpha blending
  45. ~~~~~~~~~~~~~~
  46. The `blending
  47. equation <http://en.wikipedia.org/wiki/Alpha_compositing>`__ used by
  48. applications like Photoshop is too complex for real-time. There are
  49. better approximations such as `pre-multiplied
  50. alpha <http://blogs.msdn.com/b/shawnhar/archive/2009/11/06/premultiplied-alpha.aspx?Redirected=true>`__,
  51. but they impose more stress in the asset pipeline. In the end, we are
  52. left with textures that have artifacts in the edges, because apps such
  53. as Photoshop store white pixels in completely transparent areas. Such
  54. white pixels end up showing thanks to the texture filter (when active).
  55. Godot has an option to fix the edges of the image (by painting invisible
  56. pixels the same color as the visible neighbours):
  57. .. image:: /img/fixedborder.png
  58. To do this, open the image from the resources tab, or edit it from the
  59. property editor from another node or resource, then go to the object
  60. options and select "Fix Border Alpha", then save it.
  61. .. image:: /img/imagefixalpha.png
  62. Since fixing this in so many images can be a little annoying, both
  63. Texture Import and Image Export can also perform this operation.
  64. Texture import
  65. ~~~~~~~~~~~~~~
  66. Sometimes, it might be desired to change the above settings per image.
  67. Unfortunately, the image loader settings are global. Texture flags also
  68. can't be saved in a regular .png or .jpg file.
  69. For such cases, the image can be imported as a texture (.tex), where the
  70. individual flags can be changed. Godot also keeps track of the original
  71. file and will re-import if it changes.
  72. Importing also allows conversion to other formats (WebP, or RAM
  73. compression) which might be of use in some cases. . More information on
  74. the [[Importing textures]] page.
  75. Image export
  76. ~~~~~~~~~~~~
  77. It is also possible to convert images to other formats (WebP or RAM
  78. compression) on export, as well as instructing the exporter to create an
  79. Atlas for a set of images. It is also possible to ask the exporter to
  80. scale all images (or selected groups).
  81. More information on the :ref:`doc_exporting_images` page.