Skip to content

Textures

Textures are images used by materials for base color, normals, emission, and more. Load them from files or create them procedurally.

local tex = scene:load_texture("textures/brick_diffuse.png")

Supported formats: .png, .jpg, .hdr, .exr

local tex = scene:create_texture({
width = 256,
height = 256,
data = { ... }, -- flat RGBA bytes (optional)
format = "rgba8", -- "rgba8" | "rgba16f" | "rgba32f"
})

If data is omitted, the texture is created with zeroed pixels.

PropertyTypeAccessDescription
widthnumberr/oPixel width
heightnumberr/oPixel height
formatstringr/oPixel format ("rgba8", "rgba16f", "rgba32f")

Control how the GPU samples the texture:

-- Magnification / minification filter
tex.filter_mag = "linear" -- "nearest" | "linear"
tex.filter_min = "linear" -- "nearest" | "linear"
-- Wrap mode (how UVs outside 0–1 behave)
tex.wrap_s = "repeat" -- "repeat" | "clamp" | "mirror"
tex.wrap_t = "repeat" -- "repeat" | "clamp" | "mirror"
ParameterValuesDefaultDescription
filter_mag"nearest", "linear""linear"Filter when texels are larger than pixels
filter_min"nearest", "linear""linear"Filter when texels are smaller than pixels
wrap_s"repeat", "clamp", "mirror""repeat"Horizontal wrap mode
wrap_t"repeat", "clamp", "mirror""repeat"Vertical wrap mode

Textures are assigned to materials via slot name:

local mat = scene:create_material("Brick")
local tex = scene:load_texture("textures/brick.png")
mat:set_texture("base_color", tex)
mat:set_texture("normal", "textures/brick_normal.png") -- path also works
local t = mat:get_texture("base_color") -- Texture or nil

Available slots: "base_color", "metallic_roughness", "normal", "emissive", "occlusion"

local size = 64
local data = {}
for y = 0, size - 1 do
for x = 0, size - 1 do
local white = ((x + y) % 2 == 0)
local v = white and 255 or 40
table.insert(data, v) -- R
table.insert(data, v) -- G
table.insert(data, v) -- B
table.insert(data, 255) -- A
end
end
local checker = scene:create_texture({
width = size, height = size,
data = data, format = "rgba8",
})
checker.filter_mag = "nearest" -- crisp pixels
checker.wrap_s = "repeat"
checker.wrap_t = "repeat"
local mat = scene:create_material("Checker")
mat:set_texture("base_color", checker)