Importing a Texture

From C4 Engine Wiki

Jump to: navigation, search

Contents

Overview

Texture maps used by the C4 Engine have the .tex file extension. These texture map resources are created by importing texture images from a sub-directory of the Import/ directory using the Texture Importer tool.

The Texture Importer tool supports TGA files, which may be in 8-bit grayscale, 16-bit color, 24-bit color, or 32-bit color format, with or without RLE compression.

To import a texture, either choose Tools > Import Texture or invoke the itexture [name] command in the Command Console window. If the menu command is chosen, or the name is omitted from the console command, then the Texture Importer tool will open an Import Texture dialog that lists all of the sub-directories in the Import/ directory:

Image:ImportTexture.png

Navigate to a sub-directory to select a TGA file to import.

After selecting an image file to import, the Import dialog is opened with the following default settings:

Image:itexture.png

The default settings are usually appropriate for ordinary color texture maps.

Texture Format

The Texture type menu selects the OpenGL texture target for this texture map. It can be one of the following values.

  • 2D An ordinary 2D texture whose coordinates lie in the range [0, 1] in both dimensions. The width and height of a 2D texture must be a power of two.
  • RECT A rectangle texture whose coordinates lie in the range [0, width] and [0, height]. This uses the GL_ARB_texture_rectangle extension.
  • CUBE A cube map texture. See below.

The Image format menu selects the output pixel format for this texture map. It can be one of the following values.

  • RGBA Color The image has four channels: red, green, blue, and alpha.
  • Luminance Alpha The image has two channels: grayscale luminance and alpha.
  • Luminance The image has one grayscale channel, and the alpha is always interpreted to be the maximum value.
  • Intensity The image has one grayscale channel, and the alpha is always interpreted to be equal to the gray value.

The Alpha channel menu specifies what kind of information is stored in the alpha channel of the texture. It can be one of the following values. (If alpha channel information is specified, then the TGA file being imported must use a 32-bit format.)

  • None There is no information stored in the alpha channel.
  • Transparency The alpha channel contains transparency information.
  • Gloss The alpha channel contains a gloss map. Whenever a texture containing a gloss map in the alpha channel is used in a material, any specularity, environment map, or reflection term is modulated by the gloss map.
  • Opacity The alpha channel contains an opacity map. Whenever a texture containing an opacity map in the alpha channel is used in a material, the opacity is used to linearly interpolate between the diffuse term and the refraction term.
  • Glow The alpha channel contains glow intensity values that are used by the glow post-processing effect. This should only be used for emission maps.
  • Occlusion The alpha channel will contain ambient occlusion information. This can be a precomputed channel, or it can be generated when the texture is imported. See the description of the “Calculate ambient occlusion in alpha” box below.
  • Parallax The alpha channel of the import texture contains a height map from which parallax mapping information should be calculated. This can only be selected by checking the “Generate parallax data” box, and in this case, all four channels of the import texture should contain the same values. If the alpha channel of a normal map in a material contains parallax information, the parallax mapping is applied during all rendering passes.

The S wrap mode and T wrap mode menus specify what wrap modes to apply to the texture map. They can each be one of the following values.

  • Repeat The texture is addressed using the GL_REPEAT wrap mode.
  • Clamp The texture is addressed using the GL_CLAMP_TO_EDGE wrap mode. If this mode is not available, the GL_CLAMP is used instead.
  • Clamp to Border The texture is addressed using the GL_CLAMP_TO_BORDER wrap mode.
  • Mirror Repeat The texture is addressed using the GL_MIRRORED_REPEAT wrap mode.
  • Mirror Clamp The texture is addressed using the GL_MIRROR_CLAMP_TO_EDGE wrap mode.
  • Mirror Clamp to Border The texture is addressed using the GL_MIRROR_CLAMP_TO_BORDER wrap mode.

If the “Use S3TC compression” box is checked, then the output texture is compressed. This setting is ignored if the image format is not RGBA Color.

Texture Flags

If the “Disable filtering” box is checked, then no filtering is applied to this texture map and point sampling is used instead.

If the “Disable anisotropic filtering” box is checked, then anisotropic filtering is disabled for this texture map, but ordinary bilinear or trilinear filtering is still applied.

If the “Require high-resolution rendering” box is checked, then the texture map will always be rendered using the highest resolution available, even if the user has selected a lower-quality option in the Graphics Settings dialog.

Map/Channel Generation

If the “Calculate normal map” box is checked, then the import texture is treated as a height map from which a normal map should be calculated. Each height is multiplied by the value specified in the “Height map scale” field and used to determine the normal vector at each pixel.

If the “Generate parallax data” box is checked, then the same height map must be stored in all four channels of the import texture. The height in the alpha channel is converted into special parallax data used by the engine.

If the “Generate horizon maps” box is checked, then two additional textures are generated that contain horizon map data. These textures have the same name as the normal map, but with the suffixes -h1 and -h2. Horizon maps are applied to a material when the “Enable horizon mapping” box is checked in the Material Manager.

If the “Calculate ambient occlusion in alpha” box is checked, then the alpha channel of the import texture should contain a height map. The heights in this map are scaled by the value specified in the “Height map scale” field and used to calculate an ambient occlusion factor that is applied in the ambient rendering pass.

The “Height map channel” menu lets you select a channel to be used as the source of the height map for all calculations.

In order to access all features of the engine, normal maps should be created by the C4 texture importer, not by external programs. You can still use normal maps generated outside C4, but if you do, then S3TC compression cannot be used, and you can't have associated parallax maps, horizon maps, or ambient occlusion maps.

Options

The “Output file name” field contains the name of the texture file that will be created. (It should not include the extension.)

If the “Calculate mipmap levels” box is checked, then all mipmap levels for this texture are calculated and stored in the texture resource. Turning this off for textures that are used in a 3D environment can have a negative effect on performance.

If the “Create terrain palette” box is checked, then a terrain palette texture is created. See below.

If the “Treat RGB channels as vector” box is checked, then mipmaps are calculated for vector data instead of color data. This is useful if you're importing a precomputed normal map as opposed to calculating a normal map from a height field.

If the “Invert green channel” box is checked, then the green channel is inverted. This is useful for changing handedness in normal maps.

If the “Flip image vertically” box is checked, then the texture image is flipped in the vertical direction before being stored in the texture resource.

Cube Maps

A cube map can be imported by creating a TGA file that is six times as tall as it is wide. The width must be a power of two, and each sixth of the image represents one face of the cube. As shown in the image to the right, the order of faces is positive x, negative x, positive y, negative y, positive z, and finally negative z. Each face must have the correct orientation in order for the cube map to work properly, and these are shown in the figure. The z axis always represents the up direction, and the direction specified in the center of each face represents the axis that points into the image.


Terrain Palettes

A terrain palette is a special kind of texture map that is used when rendering terrain. It packs many different textures into the same image so that several different textures can be used on a single piece of terrain without exceeding the number of available hardware texture units. A terrain palette is required for triplanar texture mapping and is created by checking the “Create terrain palette” box.

Terrain palettes come in three sizes: 9 entries, 18 entries, and 36 entries. The texture images for each entry of a palette must be square and should be stacked vertically in a single TGA file. For example, a terrain palette containing 9 images of size 512×512 should be stored in a TGA file having dimensions 512×4608 (because 9×512 = 4608). It's possible to use any number of entries less than or equal to 36, and the terrain palette will be smallest of the three sizes that can contain all of the entries.

For a 9-entry terrain palette, the texture images can be no larger than 2048×2048 in size. For both an 18-entry and 36-entry terrain palette, the texture images must be 1024×1024 or smaller.

Command Line

The itexture command can take parameters corresponding to all of the settings in the texture import dialog. The general form of this command is as follows.

itexture name params

If any parameters are specified on the command line, then the import dialog is not displayed. This facilitates batch texture importing by allowing itexture commands to be executed from a CFG file.

The parameters accepted by the itexture command are listed in the following table. Multiple parameters should be separated by a space. Any unrecognized parameters are ignored.

Parameter Description
-o name The name of the output file is given by name. (The extension should not be included in the file name.) By default, the output path is the same as the input path, except that it's in the Data directory instead of the Import directory.
-type id The texture type is given by id. The value of id must be 2D, RECT, or CUBE. The default is 2D.
-format id The image format is given by id. Accepted values are RGBA, LMAL, LUMI, and INTS. The default is RGBA.
-alpha id The alpha channel data type is given by id. Accepted values are ALFA, GLOS, OPAC, GLOW, and OCCL. By default, the alpha channel is considered empty.
-swrap id The S wrap mode is given by id. Accepted values are REPT, CLMP, CBDR, MRPT, MCLP, and MCBD. The default is REPT.
-twrap id The T wrap mode is given by id. Accepted values are the same as for the S wrap mode. The default is REPT.
-compress S3TC compression is applied.
-normal Calculate normal map.
-parallax Generate parallax data.
-horizon Generate horizon maps.
-occlusion Calculate ambient occlusion in alpha.
-scale value Set the height map scale to value. The default is 8.0.
-height channel Get the height map from channel, which must be 0–3, representing (in order) red, green, blue, or alpha. The default is 0 (red channel).
-nomipmaps Do not calculate mipmap levels.
-terrain Create a terrain texture palette.
-vector Treat RGB channels as vector.
-invgreen Invert green channel.
-flip Flip image vertically.
-nofilter Disable filtering.
-noaniso Disable anisotropic filtering.
-highres Require high-resolution rendering.

See Also

Personal tools