Extensible 3D (X3D)
Part 1: Architecture and base components
18 Texturing component
The name of this component is "Texturing". This name shall be used when referring to this component in the COMPONENT statement (see 7.2.5.4 Component statement).
This clause describes the Texturing component of this part of ISO/IEC 19775. This includes how textures are specified and how they are positioned on the subject geometry. Table 18.1 provides links to the major topics in this clause.
Node types specifying texture maps include Background, ImageTexture, MovieTexture, MultiTexture, and PixelTexture. In all cases, texture maps are defined by 2D images that contain an array of colour values describing the texture. The texture map values are interpreted differently depending on the number of components in the texture map and the specifics of the image format. In general, texture maps may be described using one of the following forms:
Note that image formats specify alpha (i.e., opacity), not transparency (where alpha = 1 − transparency).
See 17 Lighting component for a description of how the various texture types are applied.
While this part of ISO/IEC 19775 only supports two-dimensional map formats, future components may specify three-dimensional or n-dimensional texture map formats.
Texture nodes that require support for the PNG (see 2.[I15948]) image format shall interpret the PNG pixel formats in the following way:
If the image specifies colours as indexed-colour (i.e., palettes or colourmaps), the following semantics should be used (note that `greyscale' refers to a palette entry with equal red, green, and blue values):
Texture nodes that require support for JPEG files (see 2.[JPEG]) shall interpret JPEG files as follows:
Texture nodes that support MPEG files (see 2.[I11172-1]) shall treat MPEG files as full RGB textures.
Texture nodes that recommend support for GIF files (see [GIF]) shall follow the applicable semantics described above for the PNG format.
Texture maps are defined in a 2D coordinate system (s, t) that ranges from [0.0, 1.0] in both directions. The bottom edge of the image corresponds to the S-axis of the texture map, and left edge of the image corresponds to the T-axis of the texture map. The lower-left pixel of the image corresponds to s=0, t=0, and the top-right pixel of the image corresponds to s=1, t=1. Texture maps may be viewed as two dimensional colour functions that, given an (s, t) coordinate, return a colour value colour(s, t). These relationships are depicted in Figure 18.1.
The texture map nodes
ImageTexture,
MovieTexture, and
PixelTexture
contain two fields, repeatS and repeatT, that specify how the
texture wraps in the S and T directions. If repeatS is TRUE
(the default), the texture map is repeated outside the [0.0, 1.0] texture
coordinate range in the S direction so that it fills the shape. If repeatS
is FALSE
, the texture coordinates are clamped
in the S direction to lie within the [0.0, 1.0] range. The repeatT
field is analogous to the repeatS field.
Each vertex-based geometry node (e.g., IndexedFaceSet and ElevationGrid) uses a set of 2D texture coordinates that map textures to vertices. Texture coordinates for geometry nodes are specified using the TextureCoordinate and TextureCoordinateGenerator nodes. Texture map values ( ImageTexture, MovieTexture, and PixelTexture) range from [0.0, 1.0] along the S-axis and T-axis. However, texture coordinate values may be in the range (−∞,∞). Texture coordinates identify a location (and thus a colour value) in the texture map. The horizontal coordinate s is specified first, followed by the vertical coordinate t.
If the texture map is repeated in a given direction (S-axis or T-axis), a texture coordinate C (s or t) is mapped into a texture map that has N pixels in the given direction as follows:
Texture map location = (C − floor(C)) × N
If the texture map is not repeated, the texture coordinates are clamped to the 0.0 to 1.0 range as follows:
Texture map location = N, if C > 1.0, = 0.0, if C < 0.0, = C × N, if 0.0 ≤ C ≤ 1.0.
Texture coordinates may be transformed (scaled, rotated, translated) by supplying a TextureTransform node as a component of the texture's containing Appearance node.
Details on repeating textures are specific to texture map node types described in ImageTexture, MovieTexture, and PixelTexture.
Multiple textures may be applied to a single geometry node and blended according to a predefined set of operations. This enables a variety of visual effects that include light mapping and environment mapping. Multiple textures may be applied using multi-stage or multi-pass techniques, depending upon the available hardware. The number of textures to be blended may have a significant impact on performance, depending upon the available hardware.
Figure 18.2 depicts an example of light mapping, simulating a pre-lit object. Texture 2 is added on top of texture 1.
Multitexturing is accomplished using the MultiTexture, MultiTextureCoordinate, and MultiTextureTransform nodes. MultiTexture specifies a grouping of single textures and texture transformations. MultiTextureCoordinate specifies a grouping of texture coordinates to be used with the associated textures. MultiTextureTransform specifies a grouping of texture transforms to be used with the associated textures.
Table 18.2 compares the usage of single texture and multitexture attributes within Appearance and geometry nodes.
Table 18.2: Comparison of single texture and multitexture attributes
Texture Node appearance.texture | Texture Transform | Texture coordinate geometry.texCoord | Texture mode |
---|---|---|---|
ImageTexture { ...} |
appearance.textureTransform |
TextureCoordinate { coord [ ] } | implicit in lighting model: REPLACE / MODULATE |
MultiTexture { texture [ ImageTexture { ...} ImageTexture { ...} ]} |
MultiTexture { textureTransform [ TextureTransform { ...} TextureTransform { ...} ]} |
MultiTextureCoordinate { coord [ TextureCoordinate { coord [ ] }TextureCoordinate { coord [ ] } ]} |
MultiTexture { mode [ "MODULATE" "MODULATE" ]} |
If a programmable shader is defined for the Appearance node containing textures, texture mapping shall be disabled. Textures defined shall be considered as sources of input and/or output for a programmable shader. See 31.2.2.5 Per-object attributes for details on how to map textures to shader program inputs.
X3DTextureCoordinateNode : X3DGeometricPropertyNode { SFNode [in,out] metadata NULL [X3DMetadataObject] }
This abstract node type is the base type for all node types which specify texture coordinates. It adds a new geometric property node type to those specified in 11 Rendering component.
X3DTextureNode : X3DAppearanceChildNode { SFNode [in,out] metadata NULL [X3DMetadataObject] }
This abstract node type is the base type for all node types which specify sources for texture images.
X3DTexture2DNode : X3DTextureNode { SFNode [in,out] metadata NULL [X3DMetadataObject] SFBool [] repeatS TRUE SFBool [] repeatT TRUE }
This abstract node type is the base type for all node types which specify 2D sources for texture images.
X3DTextureTransformNode : X3DAppearanceChildNode { SFNode [in,out] metadata NULL [X3DMetadataObject] }
This abstract node type is the base type for all node types which specify a transformation of texture coordinates.
ImageTexture : X3DTexture2DNode { SFNode [in,out] metadata NULL [X3DMetadataObject] MFString [in,out] url [] [urn] SFBool [] repeatS TRUE SFBool [] repeatT TRUE }
The ImageTexture node defines a texture map by specifying an image file and general parameters for mapping to geometry.
The texture is read from the URL specified by the url field. When the url field contains no values ([]), texturing is disabled. Browsers shall support the JPEG (see 2. [JPEG]) and PNG (see 2.[I15948]) image file formats. In addition, browsers may support other image formats (EXAMPLE CGM, 2. [I8632]) which can be rendered into a 2D image. Support for the GIF format (see [GIF]) is also recommended (including transparency). Details on the url field can be found in 9.2.1 URLs.
See 18.2 Concepts, for a general description of texture maps.
See 17 Lighting component for a description of lighting equations and the interaction between textures, materials, and geometry appearance.
MovieTexture : X3DTexture2DNode, X3DSoundSourceNode, X3DUrlObject { SFBool [in,out] loop FALSE SFNode [in,out] metadata NULL [X3DMetadataObject] SFTime [in,out] pauseTime 0 (-∞,∞) SFTime [in,out] resumeTime 0 (-∞,∞) SFFloat [in,out] speed 1.0 (-∞,∞) SFTime [in,out] startTime 0 (-∞,∞) SFTime [in,out] stopTime 0 (-∞,∞) MFString [in,out] url [] [urn] SFBool [] repeatS TRUE SFBool [] repeatT TRUE SFTime [out] duration_changed SFTime [out] elapsedTime SFBool [out] isActive SFBool [out] isPaused }
The MovieTexture node defines a time dependent texture map (contained in a movie file) and parameters for controlling the movie and the texture mapping. A MovieTexture node can also be used as the source of sound data for a Sound node. In this special case, the MovieTexture node is not used for rendering.
The url field that defines the movie data shall support MPEG1-Systems (audio and video) or MPEG1-Video (video-only) movie file formats as defined in 2.[I11172-1]. Details on the url field can be found in 9.2.1 URLs.
MovieTexture nodes can be referenced by an Appearance node's texture field (as a movie texture) and by a Sound node's source field (as an audio source only).
As soon as the movie is loaded, a duration_changed field is sent. This indicates the duration of the movie in seconds. This field value can be read (for instance, by a Script node) to determine the duration of a movie. A value of "-1" implies the movie has not yet loaded or the value is unavailable for some reason.
The loop, pauseTime, resumeTime, startTime, and stopTime inputOutput fields and the elapsedTime, isActive, and isPaused outputOnly fields, and their effects on the MovieTexture node, are discussed in detail in 8 Time component. The cycle of a MovieTexture node is the length of time in seconds for one playing of the movie at the specified speed.
The speed field indicates how fast the movie shall be played. A speed of 2 indicates the movie plays twice as fast. The duration_changed output is not affected by the speed field. set_speed events are ignored while the movie is playing. A negative speed implies that the movie will play backwards.
If a MovieTexture node is inactive when the movie is first loaded, frame 0 of the movie texture is displayed if speed is non-negative or the last frame of the movie texture is shown if speed is negative (see 8.2.4 Time-dependent nodes). A MovieTexture node shall display frame 0 if speed = 0. For positive values of speed, an active MovieTexture node displays the frame at movie time t as follows (i.e., in the movie's local time system with frame 0 at time 0 with speed = 1):
t = (now − startTime) modulo (duration/speed)
If speed is negative, the MovieTexture node displays the frame at movie time:
t = duration - ((now - startTime) modulo |duration/speed|)
When a MovieTexture node becomes inactive, the frame corresponding to the time at which the MovieTexture became inactive will remain as the texture.
See 18.2 Concepts, for a general description of texture maps.
17 Lighting component contains details on lighting equations and the interaction between textures, materials, and geometries.
MultiTexture : X3DTextureNode { SFFloat [in,out] alpha 1 [0,1] SFColor [in,out] color 1 1 1 [0,1] MFString [in,out] function [] SFNode [in,out] metadata NULL [X3DMetadataObject] MFString [in,out] mode [] MFString [in,out] source [] MFNode [in,out] texture [] [X3DTextureNode] }
MultiTexture enables the application of several individual textures to a 3D object to achieve a more complex visual effect. MultiTexture can be used as a value for the texture field in an Appearance node.
The texture field contains a list of texture nodes (e.g., ImageTexture, PixelTexture, and MovieTexture). The texture field may not contain another MultiTexture node.
The color and alpha fields define base RGB and alpha values for SELECT mode operations.
The mode field controls the type of blending operation. The available modes include MODULATE for a lit Appearance, REPLACE for an unlit Appearance, and several variations of the two. The mode field may contain an additional Blending mode for the alpha channel.
EXAMPLE The mode value "MODULATE,REPLACE" specifies Color = (Arg1.color × Arg2.color, Arg1.alpha).
The number of used texture stages is determined by the length of the texture field. If there are fewer mode values, the default mode is "MODULATE".
Table 18.3 lists possible multitexture modes.
Table 18.3 — Multitexture modes
MODE | Description |
---|---|
MODULATE | Multiply texture color with current color Arg1 × Arg2 |
REPLACE | Replace current color Arg2 |
MODULATE2X | Multiply the components of the arguments, and shift the products to the left 1 bit (effectively multiplying them by 2) for brightening. |
MODULATE4X | Multiply the components of the arguments, and shift the products to the left 2 bits (effectively multiplying them by 4) for brightening. |
ADD | Add the components of the arguments Arg1 + Arg2 |
ADDSIGNED | Add the components of the arguments with a -0.5 bias, making the effective range of values from −0.5 through 0.5. |
ADDSIGNED2X | Add the components of the arguments with a -0.5 bias, and shift the products to the left 1 bit. |
SUBTRACT | Subtract the components of the second argument from those of the
first argument. Arg1 − Arg2 |
ADDSMOOTH | Add the first and second arguments, then subtract their product from
the sum. Arg1 + Arg2 − Arg1 × Arg2 = Arg1 + (1 − Arg1) × Arg2 |
BLENDDIFFUSEALPHA | Linearly blend this texture stage, using the interpolated alpha from
each vertex. Arg1 × (Alpha) + Arg2 × (1 − Alpha) |
BLENDTEXTUREALPHA | Linearly blend this texture stage, using the alpha from this stage's
texture. Arg1 × (Alpha) + Arg2 × (1 − Alpha) |
BLENDFACTORALPHA | Linearly blend this texture stage, using the alpha factor from the
MultiTexture node. Arg1 × (Alpha) + Arg2 × (1 − Alpha) |
BLENDCURRENTALPHA | Linearly blend this texture stage, using the alpha taken from the
previous texture stage. Arg1 × (Alpha) + Arg2 × (1 − Alpha) |
MODULATEALPHA_ADDCOLOR | Modulate the color of the second argument, using the alpha of the
first argument; then add the result to argument one. Arg1.RGB + Arg1.A × Arg2.RGB |
MODULATEINVALPHA_ADDCOLOR | Similar to MODULATEALPHA_ADDCOLOR, but use the inverse of the alpha
of the first argument. (1 − Arg1.A) × Arg2.RGB + Arg1.RGB |
MODULATEINVCOLOR_ADDALPHA |
Similar to MODULATECOLOR_ADDALPHA, but use the inverse of the color of
the first argument. (1 − Arg1.RGB) × Arg2.RGB + Arg1.A |
OFF | Turn off the texture unit |
SELECTARG1 | Use color argument 1 Arg1 |
SELECTARG2 | Use color argument 1 Arg2 |
DOTPRODUCT3 | Modulate the components of each argument (as signed components),
add their products, then replicate the sum to all color channels,
including alpha. This can do either diffuse or specular bump mapping with correct input. Performs the function (Arg1.R × Arg2.R + Arg1.G × Arg2.G + Arg1.B × Arg2.B) where each component has been scaled and offset to make it signed. The result is replicated into all four (including alpha) channels. |
The source field determines the colour source for the second argument. Table 18.4 lists valid values for the source field.
Table 18.4 — Values for the source field
MODE | Description |
---|---|
"" (default) | The second argument color (ARG2) is the color from the previous rendering stage (DIFFUSE for first stage). |
"DIFFUSE" | The texture argument is the diffuse color interpolated from vertex components during Gouraud shading. |
"SPECULAR" | The texture argument is the specular color interpolated from vertex components during Gouraud shading. |
"FACTOR" | The texture argument is the factor (color, alpha) from the MultiTexture node. |
The function field defines an optional function to be applied to the argument after the mode has been evaluated. Table 18.5 lists valid values for the function field.
Table 18.5 — Values for the function field
Operator | Description |
---|---|
"" (default) | No function is applied. |
"COMPLEMENT" | Invert the argument so that, if the result of the argument were referred to by the variable x, the value would be 1.0 minus x. |
"ALPHAREPLICATE" | Replicate the alpha information to all color channels before the operation completes. |
MultiTextureCoordinate : X3DTextureCoordinateNode { SFNode [in,out] metadata NULL [X3DMetadataObject] MFNode [in,out] texCoord NULL [X3DTextureCoordinateNode] }
MultiTextureCoordinate supplies multiple texture coordinates per vertex. This node can be used to set the texture coordinates for the different texture channels.
Each entry in the texCoord field may contain a TextureCoordinate or TextureCoordinateGenerator node.
If using a MultiTexture node with a geometry node without a MultiTextureTransform node, identity matrices are assumed for all channels. If there are too few entries in the textureTransform field, identity matrices shall be used for all remaining undefined channels.
Example:
Shape { appearance Appearance { texture MultiTexture { mode [ "MODULATE" "MODULATE" ] texture [ ImageTexture { url "brick.jpg") ImageTexture { repeatS FALSE repeatT FALSE url "light_gray.png"} ] } } geometry IndexedFaceSet { ... texCoord MultiTextureCoordinate { texCoord [ TextureCoordinate { ... } TextureCoordinate { ... } ] } } }
MultiTextureTransform : X3DTextureTransformNode { SFNode [in,out] metadata NULL [X3DMetadataObject] MFNode [in,out] textureTransform NULL [X3DTextureTransformNode] }
MultiTextureTransform supplies multiple texture transforms per appearance. This node can be used to set the texture transform for each of the different texture channels. MultiTextureTransform may appear in the scene graph wherever any X3DTextureTransformNode appears.
Each entry in the textureTransform field shall contain an X3DTextureTransformNode or NULL.
If using MultiTexture with an IndexedFaceSet without a MultiTextureTransform node, texture coordinates for channel 0 are replicated along the other channels. Similarly, if there are too few entries in the textureTransform field, the last entry is replicated.
Example:
Shape { appearance Appearance { texture MultiTexture { mode [ "MODULATE" "MODULATE" ] texture [ ImageTexture { url "brick.jpg") ImageTexture { repeatS FALSE repeatT FALSE url "light_gray.png"} ] } textureTransform MultiTextureTransform { textureTransform [ TextureTransform {} TextureTransform { scale 0.5 0.5 } ] } } }
PixelTexture : X3DTexture2DNode { SFImage [in,out] image 0 0 0 SFNode [in,out] metadata NULL [X3DMetadataObject] SFBool [] repeatS TRUE SFBool [] repeatT TRUE }
The PixelTexture node defines a 2D image-based texture map as an explicit array of pixel values (image field) and parameters controlling tiling repetition of the texture onto geometry.
The repeatS and repeatT fields specify how the
texture wraps in the S and T directions. If repeatS is
TRUE
(the default), the texture map is repeated outside the 0-to-1 texture coordinate
range in the S direction so that it fills the shape. If repeatS is
FALSE
, the texture coordinates are clamped
in the S direction to lie within the 0.0 to 1.0 range. The repeatT
field is analogous to the repeatS field.
See 18.2 Concepts, for a general description of texture maps.
See 17 Lighting component for a description of how the texture values interact with the appearance of the geometry. 5.7 SFImage and MFImage describes the specification of an image.
TextureCoordinate : X3DTextureCoordinateNode { SFNode [in,out] metadata NULL [X3DMetadataObject] MFVec2f [in,out] point [] (-∞,∞) }
The TextureCoordinate node is a geometry property node that specifies a set of 2D texture coordinates used by vertex-based geometry nodes (EXAMPLE IndexedFaceSet and ElevationGrid) to map textures to vertices.
TextureCoordinateGenerator : X3DTextureCoordinateNode { SFNode [in,out] metadata NULL [X3DMetadataObject] SFString [in,out] mode "SPHERE" [see Table 18.6] MFFloat [in,out] parameter [] [see Table 18.6] }
TextureCoordinateGenerator supports the automatic generation of texture coodinates for geometric shapes.
This node can be used to set the texture coordinates for a node with a texCoord field.
The mode field describes the algorithm used to compute texture coordinates, as depicted in Table 18.6.
Table 18.6 — Texture coordinate generation modes
Mode | Description |
---|---|
SPHERE | Creates texture coordinates for a spherical environment or "chrome"
mapping based on the vertex normals transformed to camera space. u = Nx/2 + 0.5 v = Ny/2 + 0.5 where u and v are the texture coordinates being computed, and Nx and Ny are the x and y components of the camera-space vertex normal. If the normal has a positive x component, the normal points to the right, and the u coordinate is adjusted to address the texture appropriately. Likewise for the v coordinate: positive y indicates that the normal points up. The opposite is of course true for negative values in each component. If the normal points directly at the camera, the resulting coordinates should receive no distortion. The +0.5 bias to both coordinates places the point of zero-distortion at the center of the sphere map, and a vertex normal of (0, 0, z) addresses this point. Note that this formula doesn't take account for the z component of the normal. |
CAMERASPACENORMAL | Use the vertex normal, transformed to camera space, as input texture coordinates, resulting coordinates are in −1 to 1 range. |
CAMERASPACEPOSITION | Use the vertex position, transformed to camera space, as input texture coordinates |
CAMERASPACEREFLECTIONVECTOR | Use the reflection vector, transformed to camera space, as input
texture coordinates. The reflection vector is computed from the input
vertex position and normal vector. R=2 × DotProd(E,N) × N − E; In the preceding formula, R is the reflection vector being computed, E is the normalized position-to-eye vector, and N is the camera-space vertex normal. Resulting coordinates are in −1 to 1 range. |
SPHERE-LOCAL | Sphere mapping but in local coordinates |
COORD | use vertex coordinates | COORD-EYE | use vertex coordinates transformed to camera space |
NOISE | computed by applying Perlin solid noise function on vertex coordinates, parameter contains scale and translation [scale.x scale.y scale.z translation.x translation.y translation.z] |
NOISE-EYE | same as above but transform vertex coordinates to camera space first |
SPHERE-REFLECT | similar to "CAMERASPACEREFLECTIONVECTOR"
with optional index of refraction, parameter[0]
contains index of refraction
Resulting coordinates are in −1 to 1 range. |
SPHERE-REFLECT-LOCAL | Similar to "SPHERE-REFLECT", parameter[0]
contains index of refraction, parameter[1 to 3] the eye point in local
coordinates. By animating parameter [1 to 3] the reflection changes
with respect to the point. Resulting coordinates are in −1 to 1 range. |
Some modes may be hardware accelerated. Some modes are view dependent.
TextureTransform : X3DTextureTransformNode { SFVec2f [in,out] center 0 0 (-∞,∞) SFNode [in,out] metadata NULL [X3DMetadataObject] SFFloat [in,out] rotation 0 (-∞,∞) SFVec2f [in,out] scale 1 1 (-∞,∞) SFVec2f [in,out] translation 0 0 (-∞,∞) }
The TextureTransform node defines a 2D transformation that is applied to texture coordinates (see TextureCoordinate). This node affects the way textures coordinates are applied to the geometric surface. The transformation consists of (in order):
These parameters support changes to the size, orientation, and position of textures on shapes. Note that these operations appear reversed when viewed on the surface of geometry. For example, a scale value of (2 2) will scale the texture coordinates and have the net effect of shrinking the texture size by a factor of 2 (texture coordinates are twice as large and thus cause the texture to repeat). A translation of (0.5 0.0) translates the texture coordinates +.5 units along the S-axis and has the net effect of translating the texture −0.5 along the S-axis on the geometry's surface. A rotation of π/2 of the texture coordinates results in a −π/2 rotation of the texture on the geometry.
The center field specifies a translation offset in texture coordinate space about which the rotation and scale fields are applied. The scale field specifies a scaling factor in S and T of the texture coordinates about the center point. scale values shall be in the range (−∞,∞). The rotation field specifies a rotation in radians of the texture coordinates about the center point after the scale has been applied. A positive rotation value makes the texture coordinates rotate counterclockwise about the centre, thereby rotating the appearance of the texture itself clockwise. The translation field specifies a translation of the texture coordinates.
In matrix transformation notation, where Tc is the untransformed texture coordinate, Tc' is the transformed texture coordinate, C (center), T (translation), R (rotation), and S (scale) are the intermediate transformation matrices,
Tc' = −C × S × R × C × T × Tc
Note that this transformation order is the reverse of the Transform node transformation order since the texture coordinates, not the texture, are being transformed (i.e., the texture coordinate system).
The Lighting component provides three levels of support as specified in Table 18.7.
Table 18.7 — Texturing component support levels
Level | Prerequisites | Nodes/Features | Support |
---|---|---|---|
1 | Core 1 Grouping 1 Shape 1 Rendering 1 |
||
X3DTextureCoordinateNode (abstract) | n/a | ||
X3DTextureNode (abstract) | n/a | ||
X3DTexture2DNode (abstract) | n/a | ||
X3DTextureTransformNode (abstract) | n/a | ||
ImageTexture | All fields fully supported | ||
PixelTexture | All fields fully supported | ||
TextureCoordinate | All fields fully supported | ||
TextureTransform | All field fully supported. | ||
2 | Core 1 Grouping 1 Shape 1 Rendering 1 |
||
All Level 1 Texturing nodes | All fields as supported in Level 1 | ||
MultiTexture | All fields fully supported | ||
MultiTextureCoordinate | All fields fully supported | ||
MultiTextureTransform | All fields fully supported | ||
TextureCoordinateGenerator | All fields fully supported | ||
3 | Core 1 Grouping 1 Shape 1 Rendering 1 |
||
All Level 2 Texturing nodes | All fields as supported in Level 2 | ||
MovieTexture | All fields fully supported |