You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit c3ca5d8
Browse filesBrowse the repository at this point in the historyBrowse files
fix(skills): procedural-materials 4.5 socket residue, Specular date, use_nodes on 5.x
- Node-group paragraph still offered `inputs`/`outputs` for 4.5 LTS;
group.inputs.new was removed in 4.0 (the version table already said so).
It now names interface.new_socket for every supported version.
- set_specular docstring dated the 'Specular IOR Level' rename to 5.0; it was
4.0 (Principled v2). References link now points at the 4.0 notes.
- `mat.use_nodes = True` is deprecated on 5.x (DeprecationWarning, removal
planned for 6.0) and unnecessary there: materials.new() already builds the
Principled + Output tree. On 4.5 LTS the tree is None until it is set. The
skill, snippets/principled-bsdf-material.py, snippets/setup_bake_target_image.py
and the bake-high-to-low skill now gate it on bpy.app.version < (5, 0, 0),
and the "common mistakes" text says which version needs it.
Proof (local, --factory-startup):
- .scratch/blender-4.5.11-windows-x64: materials.new -> use_nodes False,
node_tree None. .scratch/blender-5.2.1-windows-x64: use_nodes True, tree has
ShaderNodeBsdfPrincipled + ShaderNodeOutputMaterial; setting it warns.
- Both patched snippets run on 4.5.11 and 5.2.1: exit 0, Principled + Output
built, bake image node active, zero use_nodes warnings captured.
Closes#327
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: skills/procedural-materials-and-shaders/SKILL.md
+16-9Lines changed: 16 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,7 +27,7 @@ Use this skill when the user:
27
27
Every Python-built material follows the same four steps:
28
28
29
29
1. Create the material datablock with `bpy.data.materials.new(name=...)`.
30
-
2.Enable nodes with `mat.use_nodes = True`. This populates`mat.node_tree` with a default Principled BSDF and Material Output. You can keep them or wipe them.
30
+
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.
31
31
3. Add nodes to `mat.node_tree.nodes` and configure their `inputs[...].default_value`.
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 `interface` (5.x) or `inputs`/`outputs` (4.5 LTS) sockets, then instantiate it inside any material's tree as a `ShaderNodeGroup` with `node.node_tree = my_group`. See snippet `shader-node-group.py`.
150
+
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`.
148
151
149
152
## Common AI mistakes
150
153
151
-
-**Forgetting `mat.use_nodes = True`**. Without nodes enabled, `mat.node_tree` is `None` and any node access raises `AttributeError`.
154
+
-**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)`.
152
155
-**Using indices for sockets**. `bsdf.inputs[0]` is fragile. The Principled BSDF input order has shifted across Blender releases. Always use string keys.
153
156
-**Setting RGB without alpha**. Color sockets expect 4-tuples. `(0.5, 0.5, 0.5)` raises a length error.
154
157
-**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.
155
158
-**Calling `bpy.ops.material.new()`** to create a material when `bpy.data.materials.new()` works headlessly and is faster.
156
159
-**Trying to wire sockets across material boundaries**. Each material has its own `node_tree`. To share logic, use a shader node group.
157
-
-**Forgetting to clear default nodes**. After `mat.use_nodes = True`, Blender adds a Principled BSDF and an Output. If you also add your own and link, you end up with two BSDFs feeding the output and the visible behavior is undefined. Either reuse the defaults or `nodes.clear()` first.
160
+
-**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 also add your own and link, you end up with two BSDFs feeding the output and the visible behavior is undefined. Either reuse the defaults or `nodes.clear()` first.
158
161
159
162
## Version correctness
160
163
@@ -173,7 +176,11 @@ When writing code that must run on both 4.5 LTS and 5.x, look up sockets defensi
173
176
174
177
```python
175
178
defset_specular(bsdf, value):
176
-
"""Specular socket renamed to 'Specular IOR Level' in Blender 5.0."""
179
+
"""Specular socket renamed to 'Specular IOR Level' in Blender 4.0.
180
+
181
+
Every supported version (4.5 LTS, 5.x) has the new name; the fallback
182
+
branch only matters for files that must also run on 3.x.
183
+
"""
177
184
if'Specular IOR Level'in bsdf.inputs:
178
185
bsdf.inputs['Specular IOR Level'].default_value = value
179
186
elif'Specular'in bsdf.inputs:
@@ -198,5 +205,5 @@ Almost everything you want to do with materials has a `bpy.data` path. The two n
0 commit comments