A texture can be a number, a color, an image, or a computation that combines other textures. Feed its output into a material input to vary that input over the surface. The same scalar field can control several inputs: a pale region can also be rougher, or a dark stripe can also be polished.
This gallery contains 26 renders in ten comparisons. Each recipe below is the code used to generate its figure. The supplied images make the vignette quick to build; the final section explains how to regenerate them.
These are surface-parameter recipes. A stone-like color pattern does not create stone geometry, and varying roughness does not change the object’s silhouette.
texture_noise() produces a scalar between zero and one.
It is seeded smooth value noise, with smaller contributions from
successive octaves. Its seed is independent of the render’s sampling
seed.
texture_mix(a, b, weight) computes
(1 - weight) * a + weight * b. Its weight is clamped to
[0, 1]. The first mix below expands the noise range; using
that result as the next mix’s weight makes the patches more
distinct.
The left image shows the scalar field through a diffuse grayscale material, so its brightness also includes lighting and shadows. The middle and right images reuse that field for a two-color palette. On the right, the gold-colored patches also have greater roughness.
grain = texture_noise(scale = 3, octaves = 5, seed = 14)
# The outer mix clamps its weight. Expanding the noise range increases contrast.
mask = texture_mix(-.65, 1.65, weight = grain)
pigment = texture_mix("#153f54", "#e1a34c", weight = mask)
roughness = texture_mix(.04, .7, weight = mask)
texture_panel(
"shared-field",
list(
"Scalar mask" = diffuse(texture_mix(0, 1, mask)),
"Mask into color" = openpbr(
base_color = pigment,
base_metalness = .7,
specular_roughness = .25
),
"Same mask into roughness" = openpbr(
base_color = pigment,
base_metalness = .7,
specular_roughness = roughness
)
)
)grain, mask, pigment, and
roughness are serializable texture descriptions. They do
not contain R callbacks. Scene construction turns their graphs into
native nodes, which evaluate at surface hits.
A checker’s two children need not be colors. One child below is another checker. The third recipe turns a 3D checker into horizontal bands by setting its x and z coordinate scales to zero, then puts a noise-based palette between those bands.
fine_checker = texture_checker(
"#17495a",
"#f1d79c",
coordinates = texture_coordinates("object", scale = 9)
)
nested_checker = texture_checker(
fine_checker,
"#cc674b",
coordinates = texture_coordinates("object", scale = 2)
)
stripes = texture_checker(
0,
1,
coordinates = texture_coordinates("object", scale = c(0, 7, 0))
)
striped_stone = texture_mix(
texture_mix("#203d4a", "#a5c6bf", grain),
"#e0b85d",
weight = stripes
)
texture_panel(
"nested-patterns",
list(
"Fine checker" = diffuse(fine_checker),
"Checker inside checker" = diffuse(nested_checker),
"Noise with horizontal bands" = openpbr(
base_color = striped_stone,
specular_roughness = texture_mix(.12, .65, stripes)
)
)
)The pattern belongs to the texture; the material describes how it reflects light. A checker can therefore drive color, roughness, or another mix’s weight.
Unequal coordinate scales stretch the pattern. Here, a larger y scale creates closely spaced variation along y. A rotation tilts the pattern in the texture xy plane. The third material uses a second, broader noise field to blend two complete color recipes.
These suggest wood and stone rather than simulating their physical structure. All three objects retain exactly the same smooth spherical geometry.
stretched = texture_noise(
octaves = 5,
seed = 26,
coordinates = texture_coordinates(
"object",
scale = c(1, 22, 2),
rotation = 22
)
)
wood_tones = texture_mix("#351c12", "#d99a49", texture_mix(-.6, 1.6, stretched))
stone = texture_mix(
"#34464e",
"#dce0d8",
texture_mix(-.45, 1.45, texture_noise(scale = 5, seed = 42))
)
weathered = texture_mix(
wood_tones,
stone,
texture_mix(-1, 2, texture_noise(scale = 1.6, seed = 2))
)
texture_panel(
"stretched-noise",
list(
"Stretched, rotated noise" = openpbr(
base_color = wood_tones,
specular_roughness = texture_mix(.15, .6, stretched)
),
"Stone-like color variation" = diffuse(stone),
"Noise blends two recipes" = openpbr(
base_color = weathered,
specular_roughness = .45
)
)
)This rotation argument rotates about the texture z axis. It is useful for UV rotation and for tilting 3D patterns in xy; it is not an arbitrary three-axis texture transform or a domain-warping system.
texture_direction_mix() uses the geometric surface
normal. Its argument order follows PBRT: alignment weights the
first input. This differs from texture_mix(),
where a weight of one selects the second input.
With absolute = TRUE, the weight is
abs(dot(normal, direction)). Upward and downward faces
receive the same value. For a deposited-on-top appearance, use
absolute = FALSE, which uses
max(0, dot(normal, direction)) instead.
The final recipe multiplies that one-sided orientation mask by noise. It breaks up the pale region and also increases roughness there. It changes color and roughness; it does not add a physical layer of dust or snow.
both_poles = texture_direction_mix("#eee2c2", "#26465a", direction = c(0, 1, 0))
upper_only = texture_direction_mix(
"#eee2c2",
"#26465a",
direction = c(0, 1, 0),
absolute = FALSE
)
up_mask = texture_direction_mix(1, 0, direction = c(0, 1, 0), absolute = FALSE)
broken_deposit = texture_scale(up_mask, texture_mix(-.6, 1.6, grain))
texture_panel(
"directional",
list(
"Absolute: both poles" = diffuse(both_poles),
"One-sided: upper surfaces" = diffuse(upper_only),
"Orientation multiplied by noise" = openpbr(
base_color = texture_mix("#26465a", "#eee2c2", broken_deposit),
specular_roughness = texture_mix(.1, .8, broken_deposit)
)
)
)The direction is fixed in world space by default. This is not
a facing-ratio or Fresnel texture: moving the camera does not
move the mask. Set space = "object" to anchor its direction
to the object instead. Bump mapping does not change this
geometric-normal mask.
Object coordinates move with the primitive and survive instancing. World coordinates include the placement of each instance. The two spheres in each image below are instances of the same source sphere.
The object-space gradient repeats from blue to orange in each sphere. The world-space gradient spans both placements: the left sphere samples its blue end and the right sphere its orange end. The gradient clamps at its endpoints; it does not repeat.
object_gradient = texture_gradient(
"#1a6678",
"#db8549",
axis = "x",
coordinates = texture_coordinates("object", scale = .5, offset = c(.5, 0, 0))
)
world_gradient = texture_gradient(
"#1a6678",
"#db8549",
axis = "x",
coordinates = texture_coordinates("world", scale = .5, offset = c(.5, 0, 0))
)
texture_panel(
"coordinate-spaces",
list(
"Object: gradient repeats in each instance" = diffuse(object_gradient),
"World: one gradient spans both instances" = diffuse(world_gradient)
),
layout = "pair",
width = 560,
height = 392
)Each node owns its mapping. Changing an image node’s UV offset does not move a separate roughness node. Mapping applies scale, then rotation about z, then offset. Negative scales mirror a mapping; zero scales suppress variation along an axis.
A 3D checker evaluates the position of the surface inside a grid of cubes. Its intersection with a sphere need not look like square tiles. A UV checker instead uses the sphere’s parameterization. Its cells narrow and converge near the poles.
object_tiles = texture_checker(
"#15475c",
"#edcc82",
coordinates = texture_coordinates("object", scale = 4)
)
uv_tiles = texture_checker(
"#15475c",
"#edcc82",
coordinates = texture_coordinates("uv", scale = c(16, 8))
)
texture_panel(
"uv-versus-object",
list(
"3D checker cuts through the surface" = diffuse(object_tiles),
"UV checker follows the sphere's UVs" = diffuse(uv_tiles)
)
)Composing textures does not remove UV seams or stretching. Choose 3D coordinates for a pattern that should cut through an object, or supply suitable mesh UVs for a pattern that should follow its surface. UV images use the mapped x and y coordinates; they are not automatically projected triplanarly.
The first two spheres keep the same color texture and metallic base.
The roughness bands in the middle image alternate between sharp and
broad reflections. The third sphere shows that the same graph can feed
the existing microfacet() material.
bands = texture_checker(
0,
1,
coordinates = texture_coordinates("object", scale = c(0, 5, 0))
)
band_roughness = texture_mix(.03, .6, bands)
gold = texture_mix("#655035", "#ecc46d", grain)
texture_panel(
"roughness-finishes",
list(
"Constant roughness" = openpbr(
base_color = gold,
base_metalness = 1,
specular_roughness = .23
),
"Polished and rough bands" = openpbr(
base_color = gold,
base_metalness = 1,
specular_roughness = band_roughness
),
"Legacy microfacet roughness" = microfacet(
color = gold,
eta = c(.18, .42, 1.37),
kappa = c(3.42, 2.35, 1.77),
roughness = band_roughness
)
),
samples = 128L
)The numbers are interpreted by the receiving material.
microfacet() retains its existing numeric roughness
conversion; OpenPBR uses its own model. The same number is not a promise
of identical highlight width across the two shaders. Within each
material, a texture value follows that material’s numeric-input
semantics.
The checker floor makes refraction easier to see. Both spheres use OpenPBR solid transmission, constant IOR, and identical geometry. Only roughness changes.
The second sphere is clearest where its geometric normal aligns with a fixed direction close to the camera’s position, and rougher toward the silhouette. The camera is fixed for this example; moving it would not update the texture’s direction automatically.
view_axis = c(2.8, 1.4, 6)
glass_roughness = texture_direction_mix(.015, .28, direction = view_axis)
texture_panel(
"glass",
list(
"Clear glass" = openpbr(
transmission_weight = 1,
specular_ior = 1.45,
specular_roughness = .015
),
"Roughness increases toward silhouette" = openpbr(
transmission_weight = 1,
specular_ior = 1.45,
specular_roughness = glass_roughness
)
),
layout = "glass",
samples = 128L
)This is the same kind of parameter operation as PBRT’s
directionmix roughness texture. PBRT import transforms the
declared direction and evaluates its roughness remapping
after the texture blend. It does not blend the BSDFs of
two separate glass materials.
The small RGB tile below is generated entirely in R, so the example needs no downloaded assets. Its channels deliberately contain different patterns.
tile_file = file.path(gallery_dir, "source-tile.png")
if (rebuild_gallery || !file.exists(tile_file)) {
# An original RGB test tile: rings in red, a ramp in green, diagonal bands in blue.
uv = (seq_len(128) - .5) / 128
xx = matrix(rep(uv, each = 128), 128, 128)
yy = matrix(rep(rev(uv), 128), 128, 128)
tile = array(0, c(128, 128, 3))
tile[,, 1] = .1 + .8 * (sin(32 * sqrt((xx - .5)^2 + (yy - .5)^2)) > 0)
tile[,, 2] = .15 + .7 * yy
tile[,, 3] = .15 + .7 * (sin(15 * (xx + yy)) > 0)
png::writePNG(tile, tile_file)
}Extracting its red channel gives a scalar mask that can drive a new palette. The last sphere uses another image node with its own repeat, rotation, and offset to control roughness. Changing that mapping leaves the color mapping alone.
image_color = texture_image(tile_file, encoding = "srgb")
red_mask = texture_channel(image_color, "r")
recolored = texture_mix("#123d51", "#dca554", red_mask)
image_roughness = texture_scale(
texture_image(
tile_file,
type = "scalar",
coordinates = texture_coordinates(
"uv",
scale = c(3, 2),
rotation = 25,
offset = c(.1, -.15)
)
),
.7
)
texture_panel(
"image-composition",
list(
"RGB image" = openpbr(
base_color = image_color,
base_metalness = .65,
specular_roughness = .3
),
"Red channel into a new palette" = openpbr(
base_color = recolored,
base_metalness = .65,
specular_roughness = .3
),
"Independent roughness image mapping" = openpbr(
base_color = recolored,
base_metalness = .65,
specular_roughness = image_roughness
)
),
samples = 128L
)Color-to-scalar conversion is explicit. Use
texture_channel(x, "r"), "g",
"b", "average", or "luminance". A
scalar can broadcast to a color, but a color cannot silently become a
roughness value or mixing weight.
For images, encoding = "auto" treats scalar maps as
linear data and ordinary LDR color images as sRGB; EXR/HDR defaults to
linear. Use an explicit encoding when the file’s contents differ from
those assumptions. Decoding happens before bilinear filtering and
mixing. A scalar image averages its RGB channels; it does not
automatically interpret its alpha channel as a mask. The
red_mask above uses the red channel after sRGB
decoding, while image_roughness reads the RGB
average as linear data.
Procedural patterns currently evaluate a point sample. They have no knowledge of the pixel’s projected footprint. The dense checker below has cells smaller than a pixel in parts of the image, so the render cannot resolve every cell.
coarse_floor = texture_checker(
"#173b49",
"#e3d9ba",
texture_coordinates("world", scale = 3)
)
fine_floor = texture_checker(
"#173b49",
"#e3d9ba",
texture_coordinates("world", scale = 90)
)
texture_panel(
"fine-patterns",
list(
"Resolved checker cells" = diffuse(coarse_floor),
"Subpixel cells: sampling artifacts" = diffuse(fine_floor)
),
layout = "plane",
samples = 64L
)More samples can reduce sampling noise, and rendering larger and downsampling can help. Neither supplies analytic filtering to the procedural texture. For stable fine detail, reduce the pattern frequency. Image nodes use bilinear filtering, but do not yet have mipmapped or anisotropic footprint filtering.
| Material | Inputs that currently accept graphs |
|---|---|
diffuse() |
color |
microfacet() |
color, roughness |
openpbr() |
base_color,
specular_roughness |
The examples stay within those inputs. In particular:
transmission_weight, coat_weight, or
subsurface_color is not supported.texture_mix() produces values for one material. There is no
public graph-based mix_material() operation. Blending two
roughness values constructs one intermediate distribution, rather than a
weighted sum of two complete BSDFs.image_texture, checker, noise, or gradient
arguments for that same color. Likewise, choose a roughness graph or
roughness_texture, not both.microfacet() roughness uses a minimum alpha of
1e-6; a constant zero roughness selects its existing smooth
material. OpenPBR has its own reference-model roughness floor. A
transmitting microfacet() color graph requires nonzero
roughness.Unsupported inputs should not be replaced by guessed alternatives in examples. For example, this is intentionally an error:
openpbr(coat_weight = texture_noise())
#> Error:
#> ! Texture graphs are not supported for `coat_weight` yet.Use a constant coat_weight with a supported texture
input until that slot gains graph support.
scripts/texture-gallery.R contains every recipe above
and the small texture_panel() rendering helper. It uses a
common studio, fixed exposure and camera within each comparison, seed
20261002, and six rendering cores. Images
are 420 by 420 pixels, except the wider instancing comparison. Samples
are 64 per pixel, or 128 for metal, glass, and image comparisons. No
denoising or bloom is applied.
From the repository root, with this development version of rayrender installed:
Sys.setenv(RAYRENDER_REBUILD_TEXTURES = "true")
source("vignettes/scripts/texture-gallery.R", chdir = FALSE)
Sys.unsetenv("RAYRENDER_REBUILD_TEXTURES")The script switches into the vignette directory when run from the
repository root. Set RAYRENDER_TEXTURE_GROUPS to a
comma-separated set of figure names (for example,
"glass,image-composition") to regenerate selected
comparisons once the gallery exists. Individual renders, labeled
comparisons, and per-image timings are retained under
figures/composable-textures/.
The material recipes also work without the gallery helper. A minimal standalone render looks like this:
library(rayrender)
options(cores = 6L)
n = texture_noise(scale = 5, seed = 7)
surface = openpbr(
base_color = texture_mix("steelblue", "wheat", n),
specular_roughness = texture_mix(.05, .6, n)
)
scene = sphere(material = surface) |>
add_object(generate_ground(depth = -1))
set.seed(20261002)
render_scene(scene, width = 600, height = 600, samples = 64,
lookfrom = c(3, 1.5, 5), lookat = c(0, 0, 0),
ambient_light = TRUE, denoise = FALSE, filename = "my-texture.png")To build this document from the existing images, leave
RAYRENDER_REBUILD_TEXTURES unset and use
rmarkdown::render() or the package’s normal vignette build.
No gallery path tracing is performed in that mode.