Skip to content

MaterialRandomizer ​

SUMMARY

Gives the target models a new material in every scene: either a registered PBR texture set (selected by group or name) or a procedural material whose color and roughness are sampled from ranges. Material variety is one of the cheapest ways to make a detector ignore surface appearance and learn shape.

Usage ​

python
from telekinesis.illusion import config
from telekinesis.illusion.randomizer.randomizer_node import MaterialRandomizer

environment.add(config.MaterialConfig.discover(assets / "materials"))   # register the pool first

randomizer.add(
    MaterialRandomizer(config.MaterialRandomizerConfig(target_models=["gear"], groups=["metal"])),
    "gear_material",
)

Every instance of gear gets one of the registered metal texture sets, drawn independently per instance and per scene. Textures are loaded the first time a set is picked and cached after that.

MaterialRandomizerConfig ​

Which models: the union of both fields; with neither, every registered model:

FieldDefaultDescription
target_modelsNoneRegistered model names, matched exactly.
target_groupsNoneModel groups, from ModelConfig(groups=...).

Which materials: pick one source:

FieldDefaultDescription
groupsNoneGroups of registered PBR materials, e.g. ["metal", "plastic"]. A group is drawn first, then a material within it.
namesNoneNames of registered PBR materials. Combined with groups as a union.
materialsNoneExplicit choices: PBR group names and/or PrincipledMaterialConfig recipes. Cannot be combined with groups or names.

With none of the three, any registered material group can be drawn.

How they are applied:

FieldDefaultDescription
modederived"active" replaces the active material slot, "model" uses one material for every slot of a model, "slots" samples each slot independently. Without mode: "slots" if material_slots is set, "model" if materials is set, else "active".
material_slotsNone"all" to sample every slot independently, or a mapping from slot name or zero-based index to its own choices.
seedNoneSeed for a private random generator, for reproducible material choices.

The second positional argument, environment, is optional. Pass it to validate the targets and load the selected textures right away instead of before the first scene.

Procedural Materials ​

python
brushed_steel = config.PrincipledMaterialConfig("metal", parameters={"roughness": (0.2, 0.5)}, surface_imperfections=True)
painted = config.PrincipledMaterialConfig("plastic", parameters={"base_color": ((0.6, 0.0, 0.0), (1.0, 0.2, 0.1))})

MaterialRandomizer(config.MaterialRandomizerConfig(target_models=["gear"], materials=[brushed_steel, painted, "metal"]))

A PrincipledMaterialConfig is a recipe for a Blender Principled BSDF. Each parameter is a fixed value or a (min, max) range sampled per scene, so one recipe produces endless variants. Mixing recipes with a PBR group name ("metal" above) draws from both.

FieldDefaultDescription
presetNoneStarting point: "metal", "plastic" or "rubber", or None for plain Principled defaults.
parameters{}Overrides: base_color, metallic, roughness, ior, specular_ior_level, transmission, alpha, coat_weight, coat_roughness, subsurface_weight, subsurface_radius, emission_color, emission_strength. Colors are linear RGB(A).
surface_imperfectionsFalseTrue adds scratch and smudge maps from <assets>/surface_imperfections to roughness and bump, or pass a mapping to tune roughness_strength, bump_strength, bump_distance, scale and directory.
PresetBase colorMetallicRoughness
metalgray 0.3–0.81.00.15–0.45
plastic0.05–0.80.00.25–0.65
rubbernear black, 0.01–0.080.00.65–0.95

Per-Slot Materials ​

Models with several material slots, such as a housing with a seal, can get different materials per slot. Keep the slots on import with material_preprocessing="preserve":

python
environment.add(config.ModelConfig.from_path("housing.glb", model_name="housing", material_preprocessing="preserve"))

MaterialRandomizer(config.MaterialRandomizerConfig(
    target_models=["housing"],
    material_slots={"Body": ["metal"], "Seal": [config.PrincipledMaterialConfig("rubber")]},
    seed=17,
))

Named slots must exist on every target; use one node per slot layout.

BackgroundRandomizer
Swap the HDRI behind, and lighting around, the scene.
Next node →