Textures

The following section describes the available texture data sources. In Mitsuba 3, textures are objects that can be attached to certain surface scattering model parameters to introduce spatial variation. In the documentation, these are listed as supporting the texture type. See the last sections about BSDFs for many examples.

Textures take an (optional) <transform> called to_uv which can be used to translate, scale, or rotate the lookup into the texture accordingly.

An example in XML looks as follows:

<scene version="3.0.0">
    <!-- Create a BSDF that supports textured parameters -->
    <bsdf type=".. BSDF type .." id="my_textured_material">
        <texture type=".. texture type .." name=".. parameter name ..">
            <!-- .. Texture parameters go here .. -->

            <transform name="to_uv">
                <!-- Scale texture by factor of 2 -->
                <scale x="2" y="2"/>
                <!-- Offset texture by [0.5, 1.0] -->
                <translate x="0.5" y="1.0"/>
            </transform>
        </texture>

        <!-- .. Non-spatially varying BSDF parameters ..-->
    </bsdf>
</scene>

Similar to BSDFs, named textures can alternatively be defined at the top level of the scene and later referenced. This is particularly useful if the same texture would be loaded many times otherwise.

<scene version="3.0.0">
    <!-- Create a named texture at the top level -->
    <texture type=".. texture type .." id="my_named_texture">
        <!-- .. Texture parameters go here .. -->
    </texture>

    <!-- Create a BSDF that supports textured parameters -->
    <bsdf type=".. BSDF type ..">
        <!-- Example of referencing a named texture -->
        <ref id="my_named_texture" name=".. parameter name .."/>

        <!-- .. Non-spatially varying BSDF parameters ..-->
    </bsdf>
</scene>

Bitmap texture (bitmap)

Parameter

Type

Description

Flags

filename

string

Filename of the bitmap to be loaded.

index

integer

When filename refers to a .packed texture container, this parameter can optionally be used to select a file by index. (Default: 0)

name

string

When filename refers to a .packed texture container, this parameter can optionally be used to select a file by name.

bitmap

Bitmap object

When creating a Bitmap texture at runtime, e.g. from Python or C++, an existing Bitmap image instance can be passed directly rather than loading it from the filesystem with filename.

data

tensor

Tensor array containing the texture data. Similarly to the bitmap parameter, this field can only be used at runtime. The data is assumed to be linear. Unless raw is set, spectral variants upsample three-channel tensors like any other color texture.

P, ∂

filter_type

string

Specifies how pixel values are interpolated and filtered when queried over larger UV regions. The following options are currently available:

  • bilinear (default): perform bilinear interpolation, but no filtering.

  • nearest: disable filtering and interpolation. In this mode, the plugin performs nearest neighbor lookups of texture values.

  • trilinear: build a MIP pyramid and blend the two levels that match the size of the lookup’s footprint. See the discussion of texture filtering below.

  • anisotropic: like trilinear, but with additional taps along the major axis of the footprint, up to max_anisotropy.

The two filtered modes are unsupported for color textures in spectral variants and fall back to bilinear there.

max_anisotropy

integer

Upper bound on the number of taps used by anisotropic filtering, in the range \([1, 16]\). (Default: 8)

wrap_mode

string

Controls the behavior of texture evaluations that fall outside of the \([0, 1]\) range. The following options are currently available:

  • repeat (default): tile the texture infinitely.

  • mirror: mirror the texture along its boundaries.

  • clamp: clamp coordinates to the edge of the texture.

format

string

Specifies the underlying texture storage format. The following options are currently available:

  • auto (default): Match the storage precision to the source: use 8 bits

    per channel for 8-bit images, half precision for 16-bit images, and otherwise the native floating point representation of the Mitsuba variant. Note that 8-bit storage is not differentiable. Request float16 or variant to optimize such textures.

  • variant: Use the corresponding native floating point representation

    of the Mitsuba variant

  • float16: Store the texture in half precision

  • uint8: Store the texture using 8 bits per channel. When the source

    image is sRGB-encoded and raw is false, the values are linearized on each lookup. This mode is the most memory efficient, but note that the texture is not differentiable.

raw

boolean

Should the transformation to the stored color data (e.g. sRGB to linear, spectral upsampling) be disabled? You will want to enable this when working with bitmaps storing normal maps that use a linear encoding. (Default: false)

to_uv

transform

Specifies an optional 3x3 transformation matrix that will be applied to UV values. A 4x4 matrix can also be provided, in which case the extra row and column are ignored.

P

accel

boolean

Hardware acceleration features can be used in CUDA mode. These features can cause small differences as hardware interpolation methods typically have a loss of precision (not exactly 32-bit arithmetic). (Default: true)

This plugin provides a bitmap texture that performs interpolated lookups given a JPEG, PNG, OpenEXR, RGBE, TGA, or BMP input file.

When loading the plugin, the data is first converted into a usable color representation for the renderer:

  • In rgb modes, sRGB textures are converted into a linear color space.

  • In spectral modes, sRGB textures are spectrally upsampled to plausible smooth spectra [JH19].

  • In monochrome modes, sRGB textures are converted to grayscale.

These conversions can alternatively be disabled with the raw flag, e.g. when textured data is already in linear space or does not represent colors at all.

Texture filtering. A distant or obliquely viewed texture covers many texels per pixel, which can introduce significant variance and aliasing, especially at low sampling rates. Mitsuba can optionally use ray cones [AMollerNA+19] to track the elliptical texture region visible within a pixel and perform filtered texture lookups that average over this footprint. Set filter_type to trilinear or anisotropic to enable this behavior. The trilinear filter reduces the footprint to a single level of detail, while the anisotropic filter takes several taps along its major axis, which is slower but produces better quality. Filtering currently only affects directly visible surfaces, and the cone_scale sensor parameter adjusts the footprint size.

../../_images/bitmap_filtering.svg

Single-sample renderings of a checkerboard plane with the bilinear, trilinear, and anisotropic filter modes, each next to a converged reference. Unfiltered lookups alias near the horizon, trilinear filtering removes the aliasing but blurs the grazing view, and anisotropic filtering preserves most detail.

Block-compressed textures. The plugin supports block-compressed texture formats (BC4, BC5, and BC7), which greatly reduce memory usage when rendering large textured assets on a GPU. The Metal and CUDA backends decode such textures in hardware, while the LLVM backend unpacks them into regular textures. Spectral variants unpack color textures, since the spectral upsampling step is incompatible with block compression. Block-compressed textures use 8 bits per channel, are not differentiable, and ignore the format parameter. The trilinear and anisotropic filters require a container entry with a complete MIP chain and otherwise fall back to bilinear.

To use this feature, run python -m mitsuba.pack_tex <scene.xml>, which packs the textures of a scene into a .packed container (see the file format description, which also explains the role of the different BC variants) and writes an updated scene referencing it. The bitmap textures of that scene specify the container as filename and select an entry via index.

<texture type="bitmap">
    <string name="filename" value="texture.png"/>
    <string name="wrap_mode" value="mirror"/>
</texture>

Checkerboard texture (checkerboard)

Parameter

Type

Description

Flags

color0, color1

spectrum or texture

Color values for the two differently-colored patches (Default: 0.4 and 0.2)

P, ∂

to_uv

transform

Specifies an optional 3x3 UV transformation matrix. A 4x4 matrix can also be provided. In that case, the last row and columns will be ignored. (Default: none)

P

This plugin provides a simple procedural checkerboard texture with customizable colors.

../../_images/texture_checkerboard.jpg

Checkerboard applied to the material test object as well as the ground plane.

<texture type="checkerboard">
    <rgb name="color0" value="0.1, 0.1, 0.1"/>
    <rgb name="color1" value="0.5, 0.5, 0.5"/>
</texture>

Lookup table texture (lut)

Parameter

Type

Description

Flags

input

texture

Texture to be transformed by the lookup table.

P, ∂

filename

string

Filename of an image holding the table. Its pixels in scanline order form the entries, and its channel count selects between a scalar (Y) and an RGB table (RGB). Alpha channels are dropped. Images with 8-bit sRGB-encoded data are converted to linear values.

data

tensor

Alternative to filename when instantiating the plugin from Python: a Dr.Jit tensor of shape (N,), (N, 1) or (N, 3).

P, ∂

input_min, input_max

float

These values denote the range of the input texture. Inputs outside of this range are clamped. An image file may provide defaults through the domain_min and domain_max metadata entries. (Default: 0 and 1)

filter_type

string

Specifies how the table is read between entries: linear interpolates the two enclosing entries, and nearest returns the closest one. (Default: linear)

curve

boolean

Apply the table to each channel of the input separately (see below). (Default: false)

This texture maps the value of another texture through a table of \(N\) scalar or RGB entries \(t_0, \ldots, t_{N-1}\). Given the input range \([a, b]\) specified by input_min and input_max, entry \(t_i\) is the value of the table at the input

\[x_i = a + \frac{i}{N - 1} \, (b - a).\]

By default, the plugin evaluates the input as a monochromatic quantity and uses it to look up an entry. An RGB table then acts as a color map that assigns a color to each input value. In spectral variants, RGB entries are upsampled to smooth spectra (like in the bitmap plugin) before they are interpolated.

With curve set to true, the plugin operates in curve mode and looks up every channel of the input separately. A scalar table then specifies one curve that applies to every channel (or to every wavelength sample in spectral variants), while an RGB table specifies a separate curve per channel. Spectral variants evaluate the latter on the RGB representation of the input and upsample the result.

<texture type="lut">
    <string name="filename" value="colormap.exr"/>
    <texture type="bitmap" name="input">
        <string name="filename" value="mask.png"/>
    </texture>
</texture>

Math expression texture (math)

Parameter

Type

Description

Flags

expr

string

Expression to evaluate using the simple language described below.

in0, in1, …

texture or spectrum

Inputs, which the expression refers to as in[0], in[1], etc. Each is either a nested texture or a constant color. They must be numbered consecutively starting from zero.

P, ∂

This texture evaluates a mathematical expression involving an arbitrary number of input textures. This can be helpful to transform textures in ways that are not covered by any existing plugin.

The expression consists of an optional sequence of assignments to temporaries tmp[0], tmp[1], …, separated by semicolons, followed by a final expression that produces the result of the texture. Each temporary must be assigned exactly once before use. For example:

tmp[0] = clip(in[0], 0, 1); lerp(in[1], in[2], tmp[0])

The language provides

  • The arithmetic operators +, -, *, /, unary -, and parentheses.

  • Comparisons <, <=, >, >=, ==, != and the ternary operator cond ? a : b to consume them.

  • The logical operators &&, ||, and !, which treat any nonzero operand as true.

  • Unary functions: abs, sign, sqrt, cbrt, rcp, rsqrt, erf, sin, cos, tan, asin, acos, atan, sinh, cosh, tanh, asinh, acosh, atanh, exp, log, exp2, log2, round, trunc, floor, ceil.

  • Binary and ternary functions: min, max, pow, atan2, fmod, lerp(a, b, t), clip(x, lo, hi), fma(a, b, c).

  • Color handling: The suffixes .r, .g, and .b extract a single channel of an expression and broadcast it to all channels. The functions mean and luminance similarly broadcast the channel average or ITU-R BT.709 luminance. rgb(r, g, b) assembles a trichromatic value from monochromatic inputs. Given RGB inputs v0.., v2, rgb(v0, v1, v2) is equivalent to rgb(v0.r, v1.g, v2.b). The functions rgb_to_hsv, hsv_to_rgb, rgb_to_hsl, and hsl_to_rgb convert between RGB and the HSV/HSL color spaces. Hue, saturation, and value or lightness occupy the three channels in this order and lie in [0, 1], where a hue of 0 and 1 both denote red and any hue given to the inverse conversions wraps around.

  • Floating point literals and the constants pi and e.

Operator precedence follows the C language. The language only supports floating point values and represents Boolean values as 0.0 and 1.0.

Evaluation is independent per color channel, except for the color handling operations listed above that move information between channels. When a math texture using color handling operations is used in a monochromatic context (e.g., bump map height), Mitsuba evaluates it trichromatically and then reduces the result to the scalar luminance.

The plugin compiles the expression into a compact stack machine bytecode representation that is interpreted during texture evaluation. In JIT-compiled variants, this interpretation runs once at kernel trace time, hence the evaluation cost matches that of directly written arithmetic.

<texture type="math">
    <string name="expr" value="in[0] * (1 - in[1])"/>
    <texture type="bitmap" name="in0">
        <string name="filename" value="texture.png"/>
    </texture>
    <rgb name="in1" value="0.2 0.5 0.8"/>
</texture>

Mesh attribute texture (mesh_attribute)

Parameter

Type

Description

Flags

name

string

Name of the attribute to evaluate. It should always start with "vertex_" or "face_".

scale

float

Scaling factor applied to the interpolated attribute value during evaluation. (Default: 1.0)

P

This plugin provides a simple mechanism to expose Mesh attributes (e.g. vertex color) as a texture.

../../_images/texture_mesh_attribute_vertex.jpg

Bunny with random vertex color (using barycentric interpolation).

../../_images/texture_mesh_attribute_face.jpg

Bunny with random face color.

The following XML snippet describes a mesh with diffuse material, whose reflectance is specified using the vertex_color attribute of that mesh:

<shape type="ply">
    <string name="filename" value="my_mesh_with_vertex_color_attr.ply"/>

    <bsdf type="diffuse">
        <texture type="mesh_attribute" name="reflectance">
            <string name="name" value="vertex_color"/>
        </texture>
    </bsdf>
</shape>

Note

For spectral variants of the renderer (e.g. scalar_spectral), when a mesh attribute name contains the string "color", the tri-stimulus RGB values will be converted to rgb2spec model coefficients automatically.

Volumetric texture (volume)

Parameter

Type

Description

Flags

volume

float, spectrum or volume

Volumetric texture (Default: 0.75).

P, ∂

This plugin allows using a 3D texture (i.e. a volume plugin) to texture a 2D surface. This is intended to be used to texture surfaces without a meaningful UV parameterization (e.g., an implicit surface) or to apply procedural 3D textures. At a given point on a surface, the texture value will be determined by looking up the corresponding value in the referenced volume. This is done in world space and potentially requires using the volume’s to_world transformation to align the volume with the object using the texture.

<texture type="volume">
    <volume name="volume" type="gridvolume">
        <string name="filename" value="my_volume.vol"/>
    </volume>
</texture>