Skip to content

KRasterImporter

Alfish edited this page Dec 10, 2022 · 15 revisions

Source Image Import Settings

This defines how to import source images from your project's "Assets" folder into the Unity Editor.
Select one or more image files in the Project window so that the import settings appear in the Inspector.
Enable the desired import method, then click Apply.

No import method is enabled by default. If you want, you can select one of the included KRasterImporter presets (or create your own preset) and use the button on the Inspector to set it as the default for the project.

You can hover the mouse on any field's label to show a tooltip explaining what it does.

Generate File

This is the recommended method, since that allows to use all features of Unity's built-in texture importer.
This will generate each image file on the specific path/name pattern you set.
You can then select these new texture asset files and import them as normal.

Source Image Import Settings in Unity Inspector: Generate File

The default pattern generates the file on the same folder as the source image. This is usually appropriate for Image.
For Animation, you can use the pattern from the Generate Animation preset to put the files for each frame under the same <name>/ folder.

Variables (e.g. <name>) are used to specify the path pattern generically. This allows you to import many files at once.
Simply hover the mouse on Generate To for a tooltip explanation of each variable.

For example, if you want to change just the top folder under Assets to "Textures", you could use one of these:

  • <root>/Textures/<subpath>/<name>.<ext>.<format>
  • <root>/Textures/_auto/<guid>.<format>

The Generate File importation method can use the External Program Mode when necessary - for example, when generating a file in any format other than PNG. Install Krita and enable the preference to use this mode. The <format> variable at the end will ensure that exr is used only when appropriate (since it requires the external converter program), otherwise png is preferred. If you have issues with the external converter, make sure the last used export settings for that format in Krita are right (e.g., "flatten image" option).

You can also use a different format if desired. Formats natively supported by both Unity and Krita include:

  • PNG: recommended for all simple images
  • EXR: recommended for linear HDR color images
  • TIFF: used more in printers and scanners
  • PSD: supports many advanced features, but it's proprietary
  • TGA: simple format, but it's technically proprietary
  • BMP: inappropriate for alpha channel or for compression
  • JPEG: inappropriate for alpha channel and uses lossy compression
  • GIF: inappropriate for alpha channel and uses only 256 colors

You should generally not need to enable Force Converter, since the plugin automatically detects when it's better or necessary to use it. However, if you believe a specific image should be using the external converter, but it's using the internal PNG data (and it happens to be wrong), you can force it on just that image.

If you want to change the default texture import settings for the generated files, you can create custom TextureImporter preset patterns for their specific folders, according to your use case.

Import Image

You might prefer to import textures and sprites directly as sub-assets. Only single sprite mode is supported at the moment.

This direct importation method has less options than the built-in importer, but, on the other hand, you may prefer its convenience of grouping assets together. It uses the Internal PNG Mode, which reads the flattened PNG data (merged image) as it was rendered by the image editor. It's fast and doesn't require installing any separate program.

Most options here correspond to the same option in Unity's built-in Texture Importer or Sprite Editor, so only differences will be explained below.

Source Image Import Settings in Unity Inspector: Import Image - Sprite

Texture Name, Sprite Name

Name of the sub-asset. These fields allow the same variables as in the path patterns explained before. The default is <name>, which is the filename of the source image without the extension.

sRGB (Color Texture)

You probably want this enabled. If you're dealing with linear files, where you would need to disable this field, you have to be careful because the PNG data used in importation may still be in sRGB space even when the source file is linear. You'll see a warning if the plugin thinks this setting has the wrong value. When in doubt, it's simpler to instead use external mode to generate a separate EXR file for linear files and use the built-in importer on that file.

Alpha Is Transparency

Leave it enabled unless you're using the alpha channel for something other than opacity. Note that no color dilation filter is applied; result can be slightly different from the built-in texture importer. If you choose to import as an opaque format (no alpha channel), then this flag controls whether it should put the image over a black background or just discard the alpha channel.

Wrap Mode

Like in Unity's built-in TextureImporter, you can set it per-axis for the U and V coordinates individually.
To set both to the same value, you can use the convenient small dropdown at the right.

Texture Format

Similar to Unity's built-in TextureImporter, but only the options below are available.

  • DXT1 (Compressed RGB): Opaque colors, compressed. 64 bits per 4x4 block of pixels.
  • DXT5 (Compressed ARGB): Colors with alpha transparency, compressed. 128 bits per 4x4 block of pixels.
  • RGB8 (Uncompressed): Opaque colors, uncompressed. 8 bits per channel.
  • ARGB8 (Uncompressed): Colors with alpha transparency, uncompressed. 8 bits per channel.

DXT compression is lossy, but this effect is minimized when higher resolutions are downscaled.
If you need a different format, platform-specific overrides, or any other feature unavailable here (including HDR), use Unity's built-in importer instead of this direct importation method. To do so, you can use the external mode to generate a separate EXR file.

World Unit

What size in the sprite corresponds to 1 unit in the world. This is the sprite's Pixels Per Unit setting when the unit is set to px. Otherwise, this value will be set relatively to the image size or pixel density (ppi or px/cm) as set in the image editor.

  • px: Value is the exact amount of Pixels Per Unit.
    E.g., 100px means 100px in the unscaled sprite is 1 world unit.
  • in, cm: Value is the amount of inches or centimeters per world unit, measured using the image's pixel density value. This allows you to design sprites using these physical units in the image editor.
    E.g., 100cm means 1 meter in the unscaled sprite is 1 world unit.
  • % width, % height: Value is Pixels Per Unit relative to % of either width or height.
    E.g., 25% width means unscaled sprite width is 4 world units.
  • % container: % of width or height, whichever is larger, per world unit.
    E.g., when it's 100% containing, then an unscaled image will fit inside a 1x1 world unit square without stretching.
  • % coverage: % of width or height, whichever is smaller, per world unit.
    E.g., when it's 100% covering, then: if an unscaled image has "portrait" aspect, its width will cover 1 world unit; if it has "landscape" aspect, height will cover 1 unit.

Pivot

Corresponds to the normalized Custom Pivot setting, where (0, 0) is bottom left and (1, 1) is top right.
Use the small dropdown to conveniently set the most common values.

Preview Area

Source Image in Unity Inspector: Preview Area

The preview area shows info about the source image being inspected:

  • File extension (KRA, KRZ or ORA)
  • Image size in pixels (e.g.: 512×512)
  • If the file has animation frames:
    • Number of frames (e.g.: ×8)
    • Framerate (e.g.: @8fps)
    • Duration (in seconds, e.g: 0.25s)
  • Pixel density (ppi or px/cm)
  • If the color space is recognized:
    • Color format (e.g.: RGBA16f) composed of:
      • Color model (e.g.: RGBA, GrayA, CMYKA, YCbCrA)
      • Bit depth per channel (8-bit, 16-bit, 32-bit)
      • Range (if it ends with f, channels are float, which allows HDR; otherwise it's integer)
    • Tone response curve (TRC):
      • linear (gamma=1) or decoding gamma value (e.g.: gamma[2.2])
      • sRGB or another trc[...] (e.g.: BT.709, PQ, L*)
    • Color gamut:
      • sRGB or another gamut[...] (e.g.: Rec2020, DisplayP3, AP1)
  • If color space couldn't be inferred:
    • Color profile name (icc[...])
  • File length in bytes (e.g.: 1.2MiB)
  • When internal PNG info is shown:
    • PNG image size in pixels (when different)
    • PNG color format (e.g.: RGBA8)
    • PNG length in bytes (e.g.: 12.3KiB)

Clone this wiki locally