Texturing Basics

return to main index


This tutorial provides some basic information about texture mapping using handwritten rib files, for example,
    use of txmake to create texture files,
    'st' coordinates of simple polygons,
    'st' coordinates of quadric and nurbs surfaces.

Source Image Conversion

PRMan expects source images, such as .hdr, .tif and .png files, to be converted to a proprietary Pixar file format known as a "texture" file. Such files can be recognized by their .tex or .tx file extension. The creation of a .tex file is done using a utility application called txmake.

Maya & txmake

In Maya txmake is run automatically by the RfM plugin to convert an image when using the PxrTexture node. Althought in the UI it appears an image is being used directly as a map it is, in fact, "quietly" converted to a .tex file by txmake.

Figure 1
"seal.tif" is automatically converted to
a texture before rendering begins.

Cutter & txmake

When editing a handwritten rib file it is the responisibility of the artist to explicitly perform the .tex conversion. Such conversions can be accomplished using a CMD window (Windows) or a terminal (Linux and OSX). However, we can take advantage of a couple of features of Cutter that will enable txmake to be used without the need to open a CMD window or a terminal. Rib files produced by Cutter ie.

Figure 2

specify a "searchpath" for texture files ie.

    Option "searchpath" "texture" ["../textures:@"]

For convenience .tex files should be saved in the directory specified by this "searchpath". For example, suppose we have the following directory structure.

            |_ cutter/
            |        |_ cutter.jar
            |        |_ run.bat
            |_ ribs/
            |      |_ textured_scene.rib
            |_ tiffs/
            |       |_ seal.tif
            |_ textures/

In the "textured_scene.rib" file we might be using the PxrTexture and PxrSurface nodes to apply and image to a square polygon. For example,

        # txmake -mode periodic ../tiffs/seal.tif ../textures/seal.tex
        Pattern "PxrTexture" "PxrTexture1"
                "string filename" ["seal.tex"]
                "int linearize" [1]
        Bxdf "PxrSurface" "PxrSurface1"
             "reference color diffuseColor" ["PxrTexture:resultRGB"]
        Scale 5 1 5
        Polygon "P" [-0.5 0 -0.5  -0.5 0 0.5  0.5 0 0.5  0.5 0 -0.5]
                "st" [0 0  0 1  1 1  1 0]

If the line of commented text is selected and the keyboard shortcut Alt+e, Control+e or Apple+e is used, Cutter will ignore the leading # comment character and run the txmake command as if it were being executed in a CMD or terminal window. Because the text is executed relative to the cutter directory, the txmake command can be given the relative paths to the source and the destination directories.

The text "-mode periodic" is known as an option which in this instance forces txmake to create a tileable texture. A full list of flags and options can be found here.

Texture Coordinates and Polygons

The square polygon specified below defines the xyz coordinates of each vertex and their 'st' texture coordinates. Extra space between the 'st' coordinates is used to emphasise their correspondence to each vertex.

    #                 A            B          C          D
    Polygon "P" [-0.5 0 -0.5  -0.5 0 0.5  0.5 0 0.5  0.5 0 -0.5]
           "st" [    0 0           0 1       1 1        1 0]

The source image is considered to have a fixed overlay of 'st' coordinates. For example, the origin of the image of the seal (s = 0, t = 0) matches the origin of the texture coordinates of the polygon - vertex A.

Figure 3
Image Texture Coordinates

Figure 4
Vertex XYZs and their Texture Coordinates

Polygons - Rotated and Scaled Texture Space

By changing the "binding" of the 'st' coordinates on the polygon we can rotate the texture map. For example,

    Polygon "P" [-0.5 0 -0.5  -0.5 0 0.5  0.5 0 0.5  0.5 0 -0.5]
           "st" [0 1  1 1  1 0  0 0] # <-- 'st' coords turned 90 degrees
         # "st" [0 0  0 1  1 1  1 0]   <-- original 'st' coords

Figure 5

Changing the 1's to, say, 4's results in a 4 by 4 repetition of texture space. For example,

    Polygon "P" [-0.5 0 -0.5  -0.5 0 0.5  0.5 0 0.5  0.5 0 -0.5]
           "st" [0 0  0 4  4 4  4 0]

Figure 6

Texture Coordinates and Quadrics

The texture coordinates of quadric surfaces are "bound" in the order shown below.

Figure 7
90 Quadrant of a Nurbs Cylinder

In RIB the nurbs cylinder shown above would be,

© 2002- Malcolm Kesson. All rights reserved.