Materials
Materials use the PBR metallic-roughness model, compatible with glTF 2.0 and Unity HDRP.
Creating Materials
Section titled “Creating Materials”local mat = scene:create_material("Gold")Base PBR Properties
Section titled “Base PBR Properties”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 = metalmat.roughness = 0.3 -- 0 = mirror, 1 = diffusemat.emissive = { r=0, g=0, b=0 } -- self-illumination colormat.emissive_strength = 1.0 -- multiplierAlpha & Rendering
Section titled “Alpha & Rendering”mat.alpha_mode = "opaque" -- "opaque" | "mask" | "blend"mat.alpha_cutoff = 0.5 -- for "mask" modemat.double_sided = false -- render back facesNormal & Occlusion
Section titled “Normal & Occlusion”mat.normal_scale = 1.0 -- normal map intensitymat.occlusion_strength = 1.0 -- ambient occlusion strengthTextures
Section titled “Textures”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 nilExtended PBR (Future)
Section titled “Extended PBR (Future)”These properties are accepted and stored but not rendered until the renderer supports them:
mat.clearcoat = 0.0 -- clear coat layer intensitymat.clearcoat_roughness = 0.0mat.sheen_color = { r=0, g=0, b=0 }mat.transmission = 0.0 -- glass/transparencymat.ior = 1.5 -- index of refractionMaterial Presets
Section titled “Material Presets”Common material setups:
-- Plasticlocal plastic = scene:create_material("Plastic")plastic.metallic = 0.0plastic.roughness = 0.5plastic.base_color = { r=0.8, g=0.2, b=0.2, a=1 }
-- Chromelocal chrome = scene:create_material("Chrome")chrome.metallic = 1.0chrome.roughness = 0.05chrome.base_color = { r=0.9, g=0.9, b=0.9, a=1 }
-- Glasslocal glass = scene:create_material("Glass")glass.alpha_mode = "blend"glass.base_color = { r=1, g=1, b=1, a=0.2 }glass.metallic = 0.0glass.roughness = 0.0glass.transmission = 0.9glass.ior = 1.5