5.76. Texture (property)

<texture> ‐ A texture bitmap

5.76.1. Attributes

NameTypeDefaults
idIDNone (required)
typeSTRINGbitmap_texture
encodingSTRINGEmpty string
env_modeSTRINGdecal
xlink:hrefURINone (required)
offset_sFLOAT0.0
offset_tFLOAT0.0
offset_uFLOAT0.0
tile_sFLOAT1.0
tile_tFLOAT1.0
tile_uFLOAT1.0
dimensionINTEGER2
noiseSTRINGno-noise
color_stripesINTEGER0
mipmappedBOOLEANtrue

5.76.2. Description

This element defines a 2- or 3-dimensional texture that is wrapped around a 3-D object. The integer value of the dimension attribute defines the texture dimension (2 or 3). In interactive rendering, the texture image metrics (width, height, and depth for 3D textures) must be a power of two. If the string value of the type attribute is bitmap_texture, the texture is copied from a file. If the value is noise the texture is a synthetic Perlin noise, if the value is multi_color the texture is a set of colored stripes. In the case of interactive rendering, if the value is frame_buffer_cleared the texture is a copy of the frame buffer (also called render to texture) and the frame buffer is cleared for future rendering, if the value is frame_buffer_uncleared the texture is a copy of the frame buffer and the frame buffer is kept as it is for future rendering.

The external file reference, given by the xlink:href attribute, defines the URI reference (Uniform Resource Identifier) of the file that contains the bitmap image.

The string value of the encoding attribute is equal to jpeg, tiff, png, pnga, png_gray, or pnga_gray depending on the image format. The formats png_gray, pnga_gray, png, and pnga are PNG formats; pnga and pnga_gray contain alpha (transparency) information while png and png_gray do not. The PNG format is accepted for RGB images with or without alpha channel (png and pnga), and gray level images with or without alpha channel (png_gray and pnga_gray). Indexed PNG images cannot be used for textures.

The boolean value of the mipmapped attribute controls whether mipmapping is used for computing textured pixels at different levels of detail.

The string value of the env_mode attribute defines how the texture is applied to each pixel. If it is equal to decal,the texture color is used as the final color. In the case of the modulate value, the texture is used to modulate (or scale) the fragment's color; this technique is useful for combining the effects of lighting with texturing. The blend value is used to blend a texture color with the surface color. Blending in OpenGL can also be used to combine the color already in the framebuffer with the color of a primitive. In this case the order in which primitives are displayed must be carefully chosen for obtaining a satisfying effect. This option must be used to render partially transparent textures. The blend_fragment value is used to blend a possibly transparent texture color with a possibly transparent surface color or material properties. If the surface color or material properties are opaque black, the result is an opaque texture. If the surface color or material properties are opaque red, the result is an opaque reddish texture. If the surface color or material properties are transparent black, the result is a transparent texture.

For 2-dimensional textures, the float values of the tile_s and tile_t attributes are used to control how many times the texture is repeated on the surface. If both attributes have the default value 1.0, a single copy of the texture appears on the surface. An additional attribute tile_u is used for 3-dimensional textures. The float values of the offset_s, offset_t, and offset_u attributes control the values that should be added to the coordinate textures defined on the geometric primitive to obtain the actual texture coordinates used to render the texture. The formula that relates the actual coordinates to the geometrical coordinates is the following

Equation 5-3. Texture Coordinate Calculation

If the value of the type attribute is equal to noise, the string value of the noise attribute defines a procedural texture based on Perlin noise function. The basic Perlin noise corresponds the value Perlin. The fractal Perlin noise (value Perlin-fractal) corresponds to a sum of 8 samples of the Perlin noise at spatial intervals x, 2×x, 4×x... with values divided by 2, 22, 23... Last, Perlin-fractal-absolute is the same computation as Perlin-fractal, but absolute values of the samples are taken instead of signed values. Perlin noise can be used with 3D textures that are displayed slice by slice resulting in an animation effect. [1]

If the value of thetype attribute is equal to multi_color, the integer value of the color_stripes attribute defines the number of color_stripes child node that define the texture.

5.76.3. Expected children

As many color_stripes as the integer value of the color_stripes attribute if the texture type is multi_color.

5.76.4. Example

The example below defines a PNG texture with alpha value. Blending is enabled in order to take advantage of the image transparency. The texture is not repeated, and it is reversed along the second parameter of the surface.

<texture  type="bitmap_texture" encoding="pnga" env_mode="blend" 
  xlink:href="textures/commuter1.png" id="commuter1_active" 
  tile_s="1" tile_t="-1" />

The example below defines a multicolor texture with 20% red, 30% yellow and 50% blue:

<texture type="multi_color" color_stripes="3" encoding="raw" id="sky-sea">
  <color_stripe index="1" r="1.0" g="0.0" b="0.0" a="1.0" length="0.2" />
  <color_stripe index="2" r="1.0" g="1.0" b="0.0" a="1.0" length="0.3" />
  <color_stripe index="3" r="0.0" g="0.0" b="1.0" a="1.0" length="0.5" />
</texture>

The example below defines a texture that is a copy of the frame buffer, the frame buffer is cleared after the copy:

<texture type="frame_buffer_cleared" encoding="raw" env_mode="decal" 
         mipmapped="true" id="ground_metal" tile_s="1" tile_t="1" />

Notes

[1]

http://cmpa.ca.scad.edu/faculty/kesson/tutorials/c4serious/noise/perlin/perlin.html