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⁄∂U², ∂²P⁄∂V², and ∂²P⁄(∂UV). 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:

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

An additional projection can be applied to the resulting vector by setting the project parameter:

0disables projections.
1selects an UV projection if available.
2selects an orthographic XY projection.
3selects an orthographic XZ projection.
4selects an orthographic YZ projection.
5selects a spherical projection.
6selects a cylindrical projection. U=0 is at +X, and V=0 is at +Y. Y is also the cylinder axis.
7selects 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.

mib_texture_vector
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).

mib_texture_remap
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",
    vector	        "offset")
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
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.
offset
is a vector added to the texture vector before the texture lookup.

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).

mib_texture_rotate
struct {
    vector          "u",
    vector          "v"
} "mib_texture_rotate" (
    vector          "input",
    scalar          "angle",
    scalar          "min",
    scalar          "max")
u
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
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).

mib_bump_basis
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.

mib_bump_map
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",
    boolean         "clamp")
u
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.
step
are offsets to coord. The shader samples three times: at (coord_x, coord_v), at (coord_x + step_x, coord_v), and at (coord_x, coord_v + step_v). The resulting U and V gradients are multiplied by the u and v basis vectors, respectively, then multiplied by the factor, and finally added to the normal, which is then renormalized. If the step components are 0, they default to 0.01.
factor
controls the strength of the effect. If it is 0, it defaults to 1.
torus_u
torus_v
specify that, when step is added to coord, the result (X, Y, and Z) should be wrapped back into the interval [0 ... 1).
alpha
if true, specifies that the alpha component instead of the intensity of the color texture should be used.
tex
is a color texture or shader to look up three times. (Only use shader assignment using the "=" notation if the assigned shader returns a shader.)
clamp
if true, restricts bump mapping area to the [0, 1] texture coordinate range.

The following shader is identical to the previous, including the parameters, except that it returns a color instead of a vector. This color is not modified. This allows the shader to be used in material shader lists by prepending it to the actual material shader. In this configuration it is called first and modifies the normal vector in the state before the material shader uses it to compute illumination. At the same time, it does not in any way affect the computed result color.

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

See above for a description of the parameters.


This is a another approach of a bump map shader, which differs from the previous ones by modifying the state→normal and then evaluating any shading graph connected to the color input. This way the perturbed normal will be visible to the connected shader or tree. Typically, illumination shaders such as Phong should be connected to the color parameter.

The bump map will look at 3 texture samples from the texture, using the texture space 0. The differences of the 3 returned values indicate the bending of the normal. The normal will be bent in the direction of the bump_vectors if they exist, or in the direction of the derivatives otherwise. The modified normal is saved in the state before calling the evaluation of color. All shaders attached to color will then used this modified normal. The normal is set back to its original value at the end.

mib_bump_map2
color "mib_bump_map2" (
	scalar          "factor",
	scalar          "scale",
	color texture   "tex",
	color           "color")
factor
deternimes how strong the bumps are.
scale
determines how many times the bump map is repeated using the first texture coordinates.
tex
specifies the texture to look up for the perturbation of the normal.
color
is the color to attach illumination shaders to (e.g. Phong).

Copyright © 1986, 2015 NVIDIA ARC GmbH. All rights reserved.