Skip to content

import_textures

reduz edited this page Mar 13, 2014 · 24 revisions

Importing Textures

Rationale

What For?

Godot can work with images directly on the filesystem and open them just like any other resource. So the first issue that comes to mind is.. is it worth it? When developing 2D games specially, there's no denying that having the image files around in the filesystem in their standard formats (png, jpg, etc) is nice and useful.

Still, there are a few advantages to using the texture importer. For 3D it's done automatically when importing models, but in 2D it must be done manually.

When NOT to import them.

In most cases you don't want images imported. Just copy them to the filesystem. Read the tutorial on exporting textures before continuing!

So, if you have read the previous tutorial basically using the texture importer gives you more finer grained control on how textures are imported. If you want to change flags such as repeat, filter, mip-maps, fix edges, etc PER texture, importing them is the best way to accomplish this. For the bulk, it's probably more comfortable to use the methods in the above mentioned link.

Lack of MipMaps

Images in 3D hardware are scaled with a (bi)linear filter, but this method has limitations. When images are shrunk too much, two problems arise:

  • Aliasing: Pixels are skipped too much, and the image shows discontinuities. This decrases quality.
  • Cache Misses: Pixels being read are too far apart, so texture cache reads a lot more data than it should. This decreases performance.

(Todo, find image sample of why it looks bad)

To solve this, mipmaps are created. Mipmaps are versions of the image shrunk by half in both axis, recursively, until the image is 1 pixel of size. When the 3D hardware needs to shrink the image, it finds the largest mipmap it can scale from, and scales from there. This improves performance and image quality.

blending equation used by applications like Photoshop is too complex for real-time. There are better approximations such as pre-multiplied alpha, but they impose more stress in the asset pipeline. In the end, we are left with textures that have artifacts in the edges, because apps such as Photoshop store white pixels in completely transparent areas. Such white pixels end up showing thanks to the texture filter.

Godot has an option to fix the edges of the image (by painting invisible pixels the same color as the visible neighbours):

=Best,

=Worst):

| | Uncompressed | Compress Lossless (PNG) | Compress Lossy (WebP) | Compress VRAM | | | ------------ | ----------------------- | --------------------- | ------------- | | Description | Stored as raw pixels | Stored as PNG | Stored as WebP | Stored as S3TC/BC,PVRTC/ETC, depending on platform|
| Size on Disk | {{:bad.png|}}Large |

Small |

Very Small |

Small |
| Memory Usage | {{:bad.png|}}Large | {{:bad.png|}}Large | {{:bad.png|}}Large |

Small |
| Performance |

Normal |

Normal |

Normal |

Fast | | Quality Loss |

None |

None |

Slight | {{:bad.png|}}Moderate |
| Load Time |

Normal | {{:bad.png|}}Slow | {{:bad.png|}}Slow |

Fast |

Texture Options:

Provided are a small amount of options for fine grained import control:

Streaming Format

This does nothing as of yet, but a texture format for streaming different mipmap levels is planned. Big engines have support for this.

Fix Border Alpha

This will fix texture borders to avoid the white auras created by white invisible pixels (see the rant above).

Alpha Bit Hint

Godot auto-detects if the texture needs alpha bit support for transparency (instead of full range), which is useful for compressed formats such as BC. This forces alpha to be 0 or 1.

Compress Extra

Some VRAM compressions have alternate formats that compress more at the expense of quality (PVRTC2 for example). If this is ticked, texture will be smaller but look worse.

No MipMaps

Force imported texture to NOT use mipmaps. This may be desirable in some cases for 2D (as explained in the rant above), though it's NEVER desirable for 3D.

Repeat

Texture will repeat when UV coordinates go beyond 1 and below 0. This is often desirable in 3D, but may generate artifacts in 2D.

Filter

Enables linear filtering when a texture texel is larger than a screen pixel. This is usually turned on, unless it's required for artistic purposes (minecraft look, for example).

--- //Juan Linietsky 2013/11/10 18:11//

Clone this wiki locally