Logo: Procedural Materials And Shaders

Procedural Materials And Shaders

Communautéit
TMHSDigital
procedural-materials-and-shaders

Build materials and shader node graphs from Python: bpy.data.materials, node_tree, Principled BSDF and its 4.0+ socket names, default values, links and shader node groups, for EEVEE and Cycles. Use when the user creates or edits materials in a script, generates many material variations, hits a KeyError on a Principled BSDF input such as Specular or Emission, restricts a light to some objects with light linking (object.light_linking receiver_collection / blocker_collection, AttributeError on Light.light_linking), or asks about EEVEE vs Cycles differences or the deferred Layered Textures system. Targets 5.2 LTS.

Iwwersiicht

EditeurTMHSDigital
RepositoryBlender-Developer-Tools
Skill-Nummprocedural-materials-and-shaders
Stären
20
Forks
5
Matgeliwwert Dateien
Nëmmen Instruktiounen
Linken
  • Instruktiounen am Markdown-Format

    Eng SKILL.md-Datei, déi de Modell bei Bedarf luet, soudatt nëmmen Token ufalen, wann eng Ufro tatsächlech dozou passt.

  • Funktionéiert mat all LLM

    KI-Skills si reng Markdown, keen ubidderspezifesche Code. Dofir funktionéiert dëse Skill mat GPT, Claude, Gemini, Grok oder engem lokale Modell.

  • Alles an den Instruktiounen

    Alles, wat de Modell brauch, steet an den Instruktiounen — keng zousätzlech Dateien ze synchroniséieren.

  • Open Source

    TMHSDigital huet de Skill op GitHub verëffentlecht. Liest de Quelltext, ier Dir de Skill installéiert.

Installatioun

Installéiert de KI-Skill Procedural Materials And Shaders an TypingMind, fir e mat all LLM ze benotzen, oder setzt en an en anere KI-Agent an, deen SKILL.md liest.

1

An TypingMind installéieren

TypingMind installéiert e Skill direkt aus sengem GitHub-Dossier — dobäi gëtt SKILL.md gelies, d'Ressourcedateie gi gebëndelt an d'Resultat gëtt lokal gespäichert.

  1. Maacht d'App op a gitt op Plugins → Skills.
  2. Wielt „Vu GitHub installéieren“.
  3. Pecht d'URL vum Skill-Dossier, déi hei drënner steet, an a bestätegt d'Installatioun.
    https://github.com/TMHSDigital/Blender-Developer-Tools/tree/main/skills/procedural-materials-and-shaders
  4. Aktivéiert de Skill an all Chat, an deem Dir e benotze wëllt.
Plugins → Skills → Skill derbäisetzen → Iwwer eng GitHub-URL. Pecht dann d'URL vum Dossier an a klickt op Weider.
2

An engem anere KI-Agent installéieren

All KI-Agent, deen d'Format Agent Skills liest, kann dëse Skill benotzen — kopéiert den Dossier an d'Skill-Verzeechnes vun deem KI-Agent.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/TMHSDigital/Blender-Developer-Tools.git /tmp/Blender-Developer-Tools
mkdir -p .claude/skills
cp -r /tmp/Blender-Developer-Tools/skills/procedural-materials-and-shaders .claude/skills/procedural-materials-and-shaders
Start Claude Code nom Kopéieren nei, fir datt den neie Skill erkannt gëtt.

An TypingMind benotzen

Aktivéiert Procedural Materials And Shaders an engem Chat vun TypingMind, an de Modell iwwerhëlt de Rescht. Den Numm an d'Beschreiwung stinn am System-Prompt. Soubal eng Ufro dozou passt, luet de Modell déi komplett Instruktioune selwer — Dir musst de Skill ni manuell opruffen, an et fale keng Token un, bis en tatsächlech benotzt gëtt.

De Modell luet Procedural Materials And Shaders automatesch, soubal eng Ufro dozou passt.

Funktionéiert mat all KI-Modell

KI-Skills si reng Markdown-Instruktiounen amplaz vun ubidderspezifeschem Code. Dofir ass Procedural Materials And Shaders net un de Modell gebonnen, fir deen de Skill geschriwwe gouf. Installéiert en eemol an TypingMind a benotzt e mat GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama oder engem lokale Modell, deen Dir selwer bedreift — alles mat Ären eegenen API-Schlësselen.

  • Gëtt nëmme gelueden, wann et néideg ass

    De System-Prompt enthält nëmmen den Numm an d'Beschreiwung. D'Instruktioune gi bei der éischter passender Ufro gelueden, soudatt en onbenotzte Skill näischt kascht.

  • De Modell am lafende Chat wiesselen

    Well de Skill aus Instruktiounen amplaz vu Code besteet, funktionéiert en och no engem Modellwiessel — den nächste Modell liest déi selwecht SKILL.md-Datei.

Skill-Instruktiounen

Dëst ass den Inhalt vu SKILL.md, deen de Modell luet. Liest e virun der Installatioun — e Skill besteet aus Instruktiounen, déi Äre Modell befollegt.

Procedural Materials and Shaders

Trigger

Use this skill when the user:

  • Wants to create or edit materials from Python rather than the shader editor
  • Mentions bpy.data.materials, node_tree, ShaderNodeBsdfPrincipled, inputs[...].default_value
  • Needs to generate many materials parametrically (asset libraries, batch import, color variations)
  • Asks about EEVEE Next vs Cycles material differences
  • Restricts which objects a light illuminates (light linking, receiver_collection, blocker_collection)
  • Asks about "Layered Textures" or "the new shader system" (see version-correctness section)

Required inputs

  • What kind of material: opaque PBR, transparent, emissive, glass, hair, volumetric
  • What controls you want exposed: base color, metallic, roughness, IOR, normal map, etc.
  • Render engine target: Cycles, EEVEE Next, or both. Most Principled BSDF setups port between the two without changes.

The minimum viable material

Every Python-built material follows the same four steps:

  1. Create the material datablock with bpy.data.materials.new(name=...).
  2. Make sure the node tree exists. On 5.x, materials.new() already creates mat.node_tree with a default Principled BSDF and Material Output, and Material.use_nodes is deprecated (setting it warns; removal is planned for 6.0). On 4.5 LTS the tree is None until you set mat.use_nodes = True. Gate it: if bpy.app.version < (5, 0, 0): mat.use_nodes = True. You can keep the default nodes or wipe them.
  3. Add nodes to mat.node_tree.nodes and configure their inputs[...].default_value.
  4. Wire mat.node_tree.links between sockets.
python
import bpy


def make_principled_material(name, base_color=(0.8, 0.8, 0.8, 1.0), metallic=0.0, roughness=0.5):
    """Create a material with a single Principled BSDF wired to Material Output."""
    mat = bpy.data.materials.new(name=name)
    if bpy.app.version < (5, 0, 0):
        mat.use_nodes = True  # 4.5 LTS: no node tree until enabled; deprecated on 5.x

    nodes = mat.node_tree.nodes
    links = mat.node_tree.links

    nodes.clear()

    bsdf = nodes.new(type='ShaderNodeBsdfPrincipled')
    bsdf.location = (0, 0)
    bsdf.inputs['Base Color'].default_value = base_color
    bsdf.inputs['Metallic'].default_value = metallic
    bsdf.inputs['Roughness'].default_value = roughness

    output = nodes.new(type='ShaderNodeOutputMaterial')
    output.location = (300, 0)

    links.new(bsdf.outputs['BSDF'], output.inputs['Surface'])
    return mat

To assign the result to an object:

python
obj.data.materials.clear()
obj.data.materials.append(mat)

Socket access pattern

Sockets are accessed by name (string key) or by index. Names are stable in the public API and survive translation; indices are not. Use names.

python
bsdf.inputs['Base Color'].default_value = (0.9, 0.1, 0.1, 1.0)
bsdf.inputs['Metallic'].default_value = 0.0
bsdf.inputs['Roughness'].default_value = 0.4
bsdf.inputs['IOR'].default_value = 1.45

The default_value field accepts:

  • A 4-tuple (r, g, b, a) for color sockets, even if the channel is RGB-only (alpha is ignored)
  • A scalar float for value sockets
  • A 3-vector (x, y, z) for vector sockets

Worked example: procedural metal with parameters

python
import bpy


def make_metal(name, base_color=(0.8, 0.8, 0.85, 1.0), roughness=0.2):
    """Procedural metal with adjustable color and surface roughness."""
    mat = bpy.data.materials.new(name=name)
    if bpy.app.version < (5, 0, 0):
        mat.use_nodes = True  # 4.5 LTS: no node tree until enabled; deprecated on 5.x

    nodes = mat.node_tree.nodes
    links = mat.node_tree.links

    nodes.clear()

    bsdf = nodes.new(type='ShaderNodeBsdfPrincipled')
    bsdf.location = (0, 0)
    bsdf.inputs['Base Color'].default_value = base_color
    bsdf.inputs['Metallic'].default_value = 1.0
    bsdf.inputs['Roughness'].default_value = roughness
    bsdf.inputs['IOR'].default_value = 2.5

    output = nodes.new(type='ShaderNodeOutputMaterial')
    output.location = (300, 0)

    links.new(bsdf.outputs['BSDF'], output.inputs['Surface'])
    return mat


for name, color in [
    ("Steel", (0.8, 0.8, 0.85, 1.0)),
    ("Gold", (1.0, 0.84, 0.4, 1.0)),
    ("Copper", (0.95, 0.64, 0.54, 1.0)),
]:
    make_metal(name, base_color=color)

Worked example: emissive material with strength control

python
def make_emissive(name, color=(1.0, 0.4, 0.1, 1.0), strength=5.0):
    mat = bpy.data.materials.new(name=name)
    if bpy.app.version < (5, 0, 0):
        mat.use_nodes = True  # 4.5 LTS: no node tree until enabled; deprecated on 5.x
    nodes = mat.node_tree.nodes
    links = mat.node_tree.links
    nodes.clear()

    emission = nodes.new(type='ShaderNodeEmission')
    emission.inputs['Color'].default_value = color
    emission.inputs['Strength'].default_value = strength
    emission.location = (0, 0)

    output = nodes.new(type='ShaderNodeOutputMaterial')
    output.location = (300, 0)

    links.new(emission.outputs['Emission'], output.inputs['Surface'])
    return mat

Reusing graphs via node groups

When the same subgraph appears across multiple materials, factor it into a ShaderNodeTree group. Create the group once with bpy.data.node_groups.new(name='MyGroup', type='ShaderNodeTree'), build its internal nodes and its sockets with group.interface.new_socket(...) (the same API on 4.5 LTS and 5.x; group.inputs.new was removed in 4.0), then instantiate it inside any material's tree as a ShaderNodeGroup with node.node_tree = my_group. See snippet shader-node-group.py.

Light linking

Light linking restricts a light to a set of receiver objects, or stops a set of blocker objects from casting its shadows. It is the look-dev tool for "this key lights the hero, not the set". Python reaches it in one place, and that place is the trap: the settings live on the light object, not on the Light datablock.

python
import bpy

hero = bpy.data.collections.new("Hero")
bpy.context.scene.collection.children.link(hero)
hero.objects.link(bpy.data.objects["Cube"])

light_data = bpy.data.lights.new("Key", type="AREA")
key = bpy.data.objects.new("Key", light_data)
bpy.context.scene.collection.objects.link(key)

key.light_linking.receiver_collection = hero   # lights only objects in Hero
key.light_linking.blocker_collection = None    # shadow linking: casters, same shape

assert key.light_linking.receiver_collection == hero
assert not hasattr(light_data, "light_linking")  # not on the datablock
  • Object, not datablock. obj.light_linking is an ObjectLightLinking with receiver_collection and blocker_collection. light_data.light_linking raises AttributeError on 4.5 LTS and 5.x alike, so no version branch is needed.
  • Linking to a collection, not to objects. Put the receivers in a collection and assign the collection. None removes the restriction.
  • Cycles and EEVEE both honour it. light-link-studio measures the linked hero at 3.6x the luminance of an identical unlinked decoy in Cycles, and 3.8x with EEVEE on 4.5 (BLENDER_EEVEE_NEXT) and 5.1 (BLENDER_EEVEE). Unlinking raises the decoy by over 200% while the hero moves under 0.5%, so the restriction is surgical.
  • Measure under view_transform = 'Standard'. AgX compresses the luminance ratios a pixel check depends on.

Common AI mistakes

  • Forgetting mat.use_nodes = True on 4.5 LTS. There, a new material's mat.node_tree is None until nodes are enabled, and any node access raises AttributeError. On 5.x the tree exists from materials.new() and setting use_nodes only emits a DeprecationWarning, so gate the line on bpy.app.version < (5, 0, 0).
  • 3.x socket names. inputs["Emission"], ["Clearcoat"], ["Subsurface"], ["Transmission"], ["Specular"] raise KeyError: 'bpy_prop_collection[key]: key "Emission" not found' on 4.5 and 5.x. Use the table in Principled BSDF socket names below.
  • Using indices for sockets. bsdf.inputs[0] is fragile. The Principled BSDF input order has shifted across Blender releases. Always use string keys.
  • Setting RGB without alpha. Color sockets expect 4-tuples. (0.5, 0.5, 0.5) raises a length error.
  • Targeting Layered Textures. The Layered Textures roadmap is deferred to 2027. Do not generate code that imports from bpy.types.LayeredTextureNode or similar; these do not exist in 5.1 stable. Stick with classic ShaderNodeTex* (ShaderNodeTexImage, ShaderNodeTexNoise, etc.) for 5.1.
  • Calling bpy.ops.material.new() to create a material when bpy.data.materials.new() works headlessly and is faster.
  • Trying to wire sockets across material boundaries. Each material has its own node_tree. To share logic, use a shader node group.
  • Forgetting to clear default nodes. A new material's tree (5.x, or 4.5 after use_nodes = True) holds a Principled BSDF and an Output. If you add your own BSDF and link it to Surface, the new link replaces the old one (an input socket takes one link), so the default Principled BSDF is left orphaned in the tree, confusing anyone who reads it and anything that later looks it up by type or name. Either reuse the defaults or nodes.clear() first.
  • Setting light linking on the Light datablock. bpy.data.lights["Key"].light_linking raises AttributeError; use the light object: bpy.data.objects["Key"].light_linking.receiver_collection = collection.

Version correctness

Topic4.5 LTS5.1 / 5.2 LTSNotes
Principled BSDFShaderNodeBsdfPrincipledSameInputs were renamed in 4.0 with the Principled v2 rewrite (full table below; 4.0 release notes: https://developer.blender.org/docs/release_notes/4.0/). Both versions use the 4.0+ names; Thin Wall is 5.2+ only.
Node group socket interfacegroup.interface.new_socketgroup.interface.new_socketSame API on every supported version. group.inputs.new / outputs.new were removed in 4.0; see snippet shader-node-group.py.
EEVEE engine string'BLENDER_EEVEE_NEXT''BLENDER_EEVEE'Legacy EEVEE was removed in 4.2. EEVEE Next used the id 'BLENDER_EEVEE_NEXT' on 4.2-4.5, then reclaimed the plain 'BLENDER_EEVEE' id in 5.0.
Layered TexturesNot presentNot present in 5.1Roadmap pushed to 2027. Do not generate code referencing it.

EEVEE Next stabilized in Blender 5.1 with material caching and feature parity improvements; most Principled BSDF graphs render identically across EEVEE Next and Cycles.

Principled BSDF socket names (v2, 4.0+)

Principled v2 (Blender 4.0) renamed or removed most of the 3.x inputs. 4.5 LTS and 5.x share the 4.0+ names, so code for supported versions uses them directly: no fallback to the old name, which only adds a branch that never runs. Code from 3.x tutorials and models fails with

text
KeyError: 'bpy_prop_collection[key]: key "Emission" not found'

(measured on 4.5.14 and 5.2.1).

3.x input4.0+ input (4.5 LTS, 5.x)
EmissionEmission Color (with Emission Strength)
SubsurfaceSubsurface Weight
Subsurface Colorremoved: subsurface takes Base Color
SpecularSpecular IOR Level
Specular Tintsame name, but now a color (RGBA, default white), not a float
ClearcoatCoat Weight
Clearcoat RoughnessCoat Roughness
Clearcoat NormalCoat Normal
SheenSheen Weight
Sheen Tintsame name, now a color (RGBA)
TransmissionTransmission Weight
Transmission Roughnessremoved: transmission uses Roughness

New in v2, no 3.x counterpart: Coat IOR, Coat Tint, Sheen Roughness, Subsurface Scale, Subsurface IOR, Subsurface Anisotropy, Diffuse Roughness, Thin Film Thickness, Thin Film IOR. 5.2 adds Thin Wall (not on 4.5.14). Look a socket up by name only where it exists on every version you target:

python
bsdf.inputs["Emission Color"].default_value = (1.0, 0.5, 0.1, 1.0)
bsdf.inputs["Emission Strength"].default_value = 3.0
bsdf.inputs["Specular IOR Level"].default_value = 0.0   # was "Specular"
if "Thin Wall" in bsdf.inputs:                          # 5.2+ only
    bsdf.inputs["Thin Wall"].default_value = True

When operators are unavoidable

Almost everything you want to do with materials has a bpy.data path. The two notable exceptions:

  • Baking textures (bpy.ops.object.bake), which needs context and a render engine.
  • Some shader linking operations exposed via bpy.ops.node.* for interactive UX. In Python, build links directly with mat.node_tree.links.new().

See also

  • Rule prefer-data-over-ops-in-loops: the same principle applies when generating many materials.
  • Snippet principled-bsdf-material.py for a minimal copy-paste.
  • Snippet shader-node-group.py for reusable shader node groups with the cross-version interface API.

Runnable examples

Each example runs headless, asserts the contract, and exits non-zero when it breaks. Run one with blender --background --python <script> --; pass a falsifier flag to watch the check fail.

  • light-link-studio: One key, one hero: a light linked to a receiver collection lights only the hero, proven by two pixel renders in one pass. Falsify: --skip-link (exit 6).
  • shader-node-group: One reusable shader group declared via tree.interface.new_socket, instanced in five materials with different Tint values — one dipped-glaze group, five stoneware mugs, five colors. Falsify: --same-tint (exit 8).
  • sky-texture-sun-elevation: World ShaderNodeTexSky driving Background Color — the sky contract across 4.5 LTS and 5.1. Falsify: --unlink-sky (exit 7).
  • swatch-grid: Procedural Principled materials — metal and dielectric, the emission pattern, and the cross-version set_specular shim. Falsify: --output swatch.png --engine cycles --samples 8 --width 640 --same-base (exit 6).

Snippets

Short standalone patterns to copy. Each one runs in CI on 5.2 and 4.5 with a check and a falsifier.

References

Heefeg gestallte Froen

Wat mécht de KI-Skill Procedural Materials And Shaders?

Build materials and shader node graphs from Python: bpy.data.materials, node_tree, Principled BSDF and its 4.0+ socket names, default values, links and shader node groups, for EEVEE and Cycles. Use when the user creates or edits materials in a script, generates many material variations, hits a KeyError on a Principled BSDF input such as Specular or Emission, restricts a light to some objects with light linking (object.light_linking receiver_collection / blocker_collection, AttributeError on Light.light_linking), or asks about EEVEE vs Cycles differences or the deferred Layered Textures syst...

Firwat Procedural Materials And Shaders op TypingMind benotzen?

Well Dir en eemol installéiert a mat all Modell benotze kënnt. Procedural Materials And Shaders besteet aus einfachem Markdown amplaz vun ubidderspezifeschem Code. Dee selwechte Skill funktionéiert also mat GPT-5, Claude, Gemini, Grok oder engem lokale Modell – an Dir kënnt de Modell matzen am Chat wiesselen, ouni datt de Skill ophält ze funktionéieren. TypingMind benotzt Är eegen API-Schlësselen, sou datt Dir d'Ubidder direkt bezuelt, amplaz en Abonnement pro Benotzerplaz ze bezuelen. Är Skills a Chats bleiwen an Ärem eegene Späicher.

Wéi installéieren ech Procedural Materials And Shaders an TypingMind?

Maacht an TypingMind Plugins → Skills → Vu GitHub installéieren op a setzt https://github.com/TMHSDigital/Blender-Developer-Tools/tree/main/skills/procedural-materials-and-shaders an. TypingMind liest d'Datei SKILL.md an installéiert de Skill, deen Dir pro Chat aktivéiere kënnt.

Wéi eng KI-Modeller kënnen Procedural Materials And Shaders benotzen?

All Modell, deen Dir an TypingMind verbënnt. KI-Skills sinn einfach Markdown-Instruktiounen an net ubidderspezifesche Code. Dofir kënne GPT, Claude, Gemini, Grok a lokal Modeller dëse Skill lueden, wann eng Ufro dozou passt.

Wéi vill KI-Modeller kann ech mat Procedural Materials And Shaders benotzen?

Esou vill wéi Dir wëllt. Soulaang e Modell Skills ënnerstëtzt, kënnt Dir Procedural Materials And Shaders domat benotzen – zum Beispill mat GPT, Claude, Gemini, Grok, DeepSeek, Mistral oder Llama – alles op TypingMind mat Ären eegenen API-Schlësselen.

Ass de KI-Skill Procedural Materials And Shaders gratis?

TMHSDigital huet de Skill op GitHub publizéiert. Kuckt am Repository no de Lizenzbedéngungen. Dir bezuelt nëmmen Ären eegene KI-Ubidder fir d'Token, déi Dir benotzt.

Wat si KI-Skills?

E KI-Skill ass e weiderverwendbare Pak vun Instruktiounen, deen engem KI-Modell bäibréngt, wéi en eng bestëmmt Aufgab erfëllt. E follegt dem oppenen Agent Skills-Format: eng Datei SKILL.md mat engem Numm an enger Beschreiwung, plus all Scripten, Virlagen oder Referenzdateien, déi de Modell eventuell brauch. De Modell liest d'Instruktiounen eréischt, wann Är Ufro zum Skill passt. En installéierte Skill kascht also näischt, bis e benotzt gëtt.

Wéi ënnerscheede sech KI-Skills vu Plugins oder MCP-Serveren?

E Plugin oder MCP-Server gëtt engem Modell nei Tools, déi en opruffe kann – Code, deen iergendwou leeft an e Resultat zeréckgëtt. E KI-Skill gëtt dem Modell dogéint Wëssen an eng Virgoensweis: wéi en eng Aufgab ugeet, wéi eng Schrëtt e maache soll a wéi eng gutt Ausgab ausgesäit. Skills bestinn aus einfachem Markdown, brauche kee Server, keen API-Schlëssel a kee Lafzäitëmfeld a funktionéiere mat all Modell.

Alleguer weisen

Elo Ären eegene KI-Aarbechtsberäich ariichten

Abonnéiert Iech op eisen Newsletter, fir iwwer nei Funktiounen an zukünfteg Gewënnspiller informéiert ze ginn 👇