Skip to content

Materials

Materials use the PBR metallic-roughness model, compatible with glTF 2.0 and Unity HDRP.

local mat = scene:create_material("Gold")
mat.base_color = { r=1, g=0.84, b=0, a=1 } -- RGBA, default {1,1,1,1}
mat.metallic = 1.0 -- 0 = dielectric, 1 = metal
mat.roughness = 0.3 -- 0 = mirror, 1 = diffuse
mat.emissive = { r=0, g=0, b=0 } -- self-illumination color
mat.emissive_strength = 1.0 -- multiplier
mat.alpha_mode = "opaque" -- "opaque" | "mask" | "blend"
mat.alpha_cutoff = 0.5 -- for "mask" mode
mat.double_sided = false -- render back faces
mat.normal_scale = 1.0 -- normal map intensity
mat.occlusion_strength = 1.0 -- ambient occlusion strength

Assign textures by file path or Texture reference:

mat:set_texture("base_color", "textures/gold_albedo.png")
mat:set_texture("normal", "textures/gold_normal.png")
mat:set_texture("metallic_roughness", "textures/gold_mr.png")
mat:set_texture("emissive", "textures/gold_emit.png")
mat:set_texture("occlusion", "textures/gold_ao.png")
local tex = mat:get_texture("base_color") -- Texture or nil

These properties are accepted and stored but not rendered until the renderer supports them:

mat.clearcoat = 0.0 -- clear coat layer intensity
mat.clearcoat_roughness = 0.0
mat.sheen_color = { r=0, g=0, b=0 }
mat.transmission = 0.0 -- glass/transparency
mat.ior = 1.5 -- index of refraction

Common material setups:

-- Plastic
local plastic = scene:create_material("Plastic")
plastic.metallic = 0.0
plastic.roughness = 0.5
plastic.base_color = { r=0.8, g=0.2, b=0.2, a=1 }
-- Chrome
local chrome = scene:create_material("Chrome")
chrome.metallic = 1.0
chrome.roughness = 0.05
chrome.base_color = { r=0.9, g=0.9, b=0.9, a=1 }
-- Glass
local glass = scene:create_material("Glass")
glass.alpha_mode = "blend"
glass.base_color = { r=1, g=1, b=1, a=0.2 }
glass.metallic = 0.0
glass.roughness = 0.0
glass.transmission = 0.9
glass.ior = 1.5