Keywords: main

Next: 1.3 Environments Up: 1. Base Shaders/A> Previous: 1.1 Overview

# 1.2 Texture Space Mapping

These shaders take care of selecting, creating, and remapping texture spaces, computing basis vectors, and other tasks necessary before a color or displacement can be applied. Some of these functions have a select parameter that has one of the following values:

0..63 | selects a texture vector. If this exceeds the number of defined texture spaces, default to -1 (the point in space).
-1 | selects the 3D point in space directly, and may apply a space point transformation.
-2 | selects the normal vector, and may apply a space vector transformation.
-3 | selects the motion vector, and may apply a space vector transformation.
-4 | selects the ray direction, and may apply a space vector transformation.
-5..-9 | select a surface derivative vector, and may apply a space vector transformation. The values are P/U, P/V, P/U2, P/V, and P/(U V). The object must be defined to contain derivatives.
-10 | selects a 2D background plate coordinate with (0, 0, 0) in the lower left corner of the screen, and (1, 1, 0) just outside the upper right corner of the screen. selspace has no effect in this mode. The transformation is similar to the one in mib_lookup_background.
-11 | selects the texture coordinate in the state, where it is typically put by a material shader when evaluating a parameter of type texture, for use by a texture shader.

Space transformations allow transforming the vector that the projection is based on into object, world, or camera coordinates. selspace may have the following values:

0 | does not apply a transformation, using internal space.
1 | converts the vector into object space.
2 | converts the vector into world space.
3 | converts the vector into camera space.
4 | returns the current screen space coordinates in the interval [0, 0...1, 1).

An additional projection1.1 can be applied to the resulting vector by setting the project parameter:

0 | disables projections.
1 | selects an UV projection if available.
2 | selects an orthographic XY projection.
3 | selects an orthographic XZ projection.
4 | selects an orthographic YZ projection.
5 | selects a spherical projection.
6 | selects a cylindrical projection. U = 0 is at +X, and V = 0 is at +Y. Y is also the cylinder axis.
7 | selects the lollipop projection, which puts the center of the texture (after texture vector normalization) at X=0.5 Z=1, and the corners at the parameter corners. On a sphere, the texture center is at the north pole and the texture corners are at the south pole, like a lollipop wrapper.

Texture Vertex Generator

Return a texture vector derived from orthographic projections of the 3D point in space (XY, XZ, YZ), non-orthographic projections (spherical or cylindrical); or return a numbered texture vector from the texture vector list. Optionally, this shader can base its calculations on object, camera, world, or screen space.

        vector "mib_texture_vector" (
            integer         "select",
            integer         "selspace",
            integer         "vertex",
            integer         "project")

select specifies the value to look up, as described above.

selspace allows choosing the source space for projections, as described above. Space conversion is done before the projection specified by the select parameter. If selspace is 4 (screen space), select, vertex, and project are ignored.

vertex specifies the location of the vertex: 0 is the intersection point, and 1, 2, and 3 are the vertices of the intersected triangle. It has no effect if select is -10.

project specifies a projection that is performed after selection and space conversion. It has no effect if select is -10.

Texture Vertex Remapping

Accepts a texture vertex and scales, rotates, translates, crops, and joins textures. The order of operations is transform first, then repeat, alternate, torus, and finally min/max crop. The result is returned (and stored in state - > tex, where it can be picked up by other shaders).

        vector "mib_texture_remap" (
            vector          "input",
            transform       "transform",
            vector          "repeat",
            boolean         "alt_x",
            boolean         "alt_y",
            boolean         "alt_z",
            boolean         "torus_x",
            boolean         "torus_y",
            boolean         "torus_z",
            vector          "min",
            vector          "max")

input is a texture vector from a generator such as mib_texture_vector that returns texture vectors. input is overridden when this shader is called with a nonzero arg parameter in mi_call_shader_x. This is useful for remapping multiple texture coordinates when the remapping parameters are identical for all of them.

transform is a general transformation applied to the texture vector before the remaining parameters are applied. If transform[3][3] is 0.0, the matrix is ignored (normally transform[3][3] is 1.0).

repeat contains repetition factors in X, Y, and Z that the texture vector is multiplied with. A value of 2, for example, shrinks the texture such that it fits twice in the [0, 1) interval. Repeating has no effect outside this interval. After the multiplication by the repetition factor, the integer part is removed. This algorithm allows finite repetition in an interval determined by the transform parameter. A repetition value of 0 turns off repetition in the corresponding component, as if the value were 1.

alt_* specifies whether every other copy of the repetition would be reversed such that successive copies of the texture are traversed in alternate, back-and-forth directions. Alternate flags have an effect only if the corresponding repetition component is greater than 1, and also work only in the [0, 1) interval.

torus_* maps the texture space into the range [0, 1) such that values less than 0 and equal to or greater than 1 are put into this range by cutting off the integer part.

min and max implement image or volume cropping by specifying the range of the texture to be considered. Portions of the texture outside this range are trimmed off. If repetition is used, the max point of one copy joins the min point of the next copy (unless alternation is turned on). min is inclusive, max is exclusive. If a min component is equal to the corresponding max component, both are ignored.

Rotation of Surface Orientation

An angle is used to rotate the surface orientation around the surface normal. An orthogonal vector pair is returned that, together with the normal which both are orthogonal to, define the rotated orientation. This is especially useful for anisotropic reflection (see below).

        struct {
            vector          "u",
            vector          "v"
        } "mib_texture_rotate" (
            vector          "input",
            scalar          "angle",
            scalar          "min",
            scalar          "max")

u and v are the returned orthogonal vectors.

input is the texture vector to be rotated. It is expected in internal space.

angle is a scalar that is interpreted as a rotation. A value equal to min specifies no rotation, and a value equal to max specifies a 360-degree rotation. The angle can for example be the intensity from a texture lookup.

min and max specify the value limits corresponding to no and full rotation. An angle value is first mapped to . (max - min) + min. If min and max are both 0, they default to 0 and 0.25, corresponding to 0 and 90 degrees counter-clockwise.

Bump Basis Generator

Given the intersection point, compute a pair of bump basis vectors, based on the projection method (as above: UV, XY, XZ, YZ, spherical, or cylindrical).

        struct {
            vector          "u",
            vector          "v"
        } "mib_bump_basis" (
            integer         "project",
            integer         "ntex")

project specifies the projection to perform, as described above. All projections are based on the 3D point in space after conversion to object space. This parameter is used to orient the bump basis.

ntex is the texture space to use, in the range 0...63. It is used only if project is UV (5) or disabled (0 or negative). Otherwise ntex is ignored.

Bump Mapping

Apply a texture to the normal vector by evaluating the texture at multiple points to compute U and V gradients that are multiplied with the basis vectors, combined with the original normal, normalized, and written back. Also return the normal. state - > tex is left undefined.

        vector "mib_bump_map" (
            vector          "u",
            vector          "v",
            vector          "coord",
            vector          "step",
            scalar          "factor",
            boolean         "torus_u",
            boolean         "torus_v",
            boolean         "alpha",
            color texture   "tex")

u and v are the bump basis vectors. They can be generated from another base shader such as mib_bump_basis.

coord is the texture coordinate for which the bump should be calculated.