Textures
Textures are images used by materials for base color, normals, emission, and more. Load them from files or create them procedurally.
Loading Textures
Section titled “Loading Textures”local tex = scene:load_texture("textures/brick_diffuse.png")Supported formats: .png, .jpg, .hdr, .exr
Creating Textures from Data
Section titled “Creating Textures from Data”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.
Properties
Section titled “Properties”| Property | Type | Access | Description |
|---|---|---|---|
width | number | r/o | Pixel width |
height | number | r/o | Pixel height |
format | string | r/o | Pixel format ("rgba8", "rgba16f", "rgba32f") |
Sampling Parameters
Section titled “Sampling Parameters”Control how the GPU samples the texture:
-- Magnification / minification filtertex.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"| Parameter | Values | Default | Description |
|---|---|---|---|
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 |
Assigning to Materials
Section titled “Assigning to Materials”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 nilAvailable slots: "base_color", "metallic_roughness", "normal", "emissive", "occlusion"
Example: Procedural Checkerboard
Section titled “Example: Procedural Checkerboard”local size = 64local 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 endend
local checker = scene:create_texture({ width = size, height = size, data = data, format = "rgba8",})checker.filter_mag = "nearest" -- crisp pixelschecker.wrap_s = "repeat"checker.wrap_t = "repeat"
local mat = scene:create_material("Checker")mat:set_texture("base_color", checker)