Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
712 lines (657 loc) · 53.1 KB
/
Copy pathindex.html
File metadata and controls
712 lines (657 loc) · 53.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>swatch-grid — Examples — Blender Developer Tools</title>
<meta name="description" content="Procedural Principled materials — metal and dielectric, the emission pattern, and the cross-version set_specular shim." />
<link rel="canonical" href="https://tmhsdigital.github.io/Blender-Developer-Tools/gallery/swatch-grid/" />
<link rel="icon" href="../../assets/favicon.svg" type="image/svg+xml" />
<meta name="theme-color" content="#1a1b1e" />
<meta name="color-scheme" content="dark" />
<meta property="og:type" content="website" />
<meta property="og:title" content="swatch-grid — Examples — Blender Developer Tools" />
<meta property="og:description" content="Procedural Principled materials — metal and dielectric, the emission pattern, and the cross-version set_specular shim." />
<meta property="og:url" content="https://tmhsdigital.github.io/Blender-Developer-Tools/gallery/swatch-grid/" />
<meta property="og:image" content="https://tmhsdigital.github.io/Blender-Developer-Tools/gallery/assets/swatch-grid-hero.webp" />
<meta property="og:image:width" content="1280" />
<meta property="og:image:height" content="720" />
<meta property="og:image:alt" content="Six material spheres in two rows against a dark backdrop: mirror gold, brushed copper, red, blue, flat orange emission and white." />
<meta property="og:site_name" content="Blender Developer Tools" />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content="swatch-grid — Examples — Blender Developer Tools" />
<meta name="twitter:description" content="Procedural Principled materials — metal and dielectric, the emission pattern, and the cross-version set_specular shim." />
<meta name="twitter:image" content="https://tmhsdigital.github.io/Blender-Developer-Tools/gallery/assets/swatch-grid-hero.webp" />
<meta name="twitter:image:alt" content="Six material spheres in two rows against a dark backdrop: mirror gold, brushed copper, red, blue, flat orange emission and white." />
<style>
/* fonts are deployed by the landing build (docs/fonts/) */
@font-face { font-family: 'Barlow Condensed'; font-weight: 600; font-display: swap;
src: url('../../fonts/barlow-condensed-600.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-weight: 400; font-display: swap;
src: url('../../fonts/inter-regular.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-weight: 500; font-display: swap;
src: url('../../fonts/inter-medium.woff2') format('woff2'); }
@font-face { font-family: 'JetBrains Mono'; font-weight: 400; font-display: swap;
src: url('../../fonts/jetbrains-mono-regular.woff2') format('woff2'); }
/* Blender-viewport system, shared with the landing page. Dark only. */
:root {
color-scheme: dark;
--bg: #1a1b1e; --surface: #222327; --surface-2: #2a2b30; --bg2: #131417;
--border: #3a3b40; --text: #e8e9eb; --text-dim: #9698a0;
--select: #ff8c19; --ok: #6dc96d;
--radius: 4px; --radius-lg: 6px; --maxw: 1080px;
--font-display: 'Barlow Condensed', 'Arial Narrow', sans-serif;
--font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
--font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
--code-k: #ff7b72; --code-s: #a5d6ff; --code-c: #9698a0; --code-n: #79c0ff;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body { font-family: var(--font-sans); background: var(--bg); color: var(--text);
line-height: 1.6; min-height: 100vh; -webkit-font-smoothing: antialiased; }
a { color: var(--select); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--select); outline-offset: 2px; border-radius: 3px; }
::selection { background: color-mix(in srgb, var(--select) 40%, transparent); }
.skip { position: absolute; left: -999px; top: 0; background: var(--select); color: #1a1b1e;
padding: 0.5rem 1rem; border-radius: var(--radius); z-index: 10; font-weight: 500; }
.skip:focus { left: 0.5rem; top: 0.5rem; }
.hud { font-family: var(--font-mono); font-size: 0.6875rem; letter-spacing: 0.04em;
color: var(--text-dim); text-transform: uppercase; }
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center;
justify-content: space-between; gap: 1rem; padding: 0 1.25rem; height: 46px;
background: color-mix(in srgb, var(--surface) 92%, transparent);
backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
.topbar .back { color: var(--text-dim); font-size: 0.8125rem; font-weight: 500; }
.topbar .back:hover { color: var(--select); text-decoration: none; }
.topbar-right { display: flex; align-items: center; gap: 0.85rem; }
.topbar-right .ghlink { color: var(--text-dim); font-size: 0.8125rem; font-weight: 500; }
.topbar-right .ghlink:hover { color: var(--select); text-decoration: none; }
header.hero { max-width: var(--maxw); margin: 0 auto; padding: 2.75rem 1.25rem 1.25rem; }
header.hero h1 { font-family: var(--font-display); font-weight: 600; text-transform: uppercase;
font-size: clamp(2.2rem, 5vw, 3.4rem); letter-spacing: 0.005em; line-height: 0.98; }
header.hero p { color: var(--text-dim); max-width: 62ch; margin-top: 0.7rem; font-size: 1rem; }
/* ---- index: sticky controls (search, density toggle, tag chips) ---- */
.controls { position: sticky; top: 46px; z-index: 4;
background: color-mix(in srgb, var(--bg) 94%, transparent);
backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
border-bottom: 1px solid var(--border); }
.controls-inner { max-width: var(--maxw); margin: 0 auto; padding: 0.55rem 1.25rem 0.6rem;
display: flex; flex-direction: column; gap: 0.5rem; }
.controls-row { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.searchwrap { position: relative; flex: 1 1 240px; min-width: 150px; }
.searchwrap input { width: 100%; background: var(--surface-2); border: 1px solid var(--border);
color: var(--text); border-radius: var(--radius); padding: 0.34rem 1.9rem 0.34rem 0.7rem;
font-family: var(--font-sans); font-size: 0.85rem; line-height: 1.4; }
.searchwrap input:focus { border-color: var(--select); outline: none; }
.searchwrap input::placeholder { color: var(--text-dim); }
.searchwrap input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }
.q-clear { position: absolute; right: 0.2rem; top: 50%; transform: translateY(-50%);
background: none; border: none; color: var(--text-dim); font-size: 1.05rem; line-height: 1;
cursor: pointer; padding: 0.25rem 0.45rem; border-radius: 3px; }
.q-clear:hover { color: var(--select); }
.count { font-family: var(--font-mono); font-size: 0.68rem; letter-spacing: 0.04em;
text-transform: uppercase; color: var(--text-dim); white-space: nowrap; }
.density { display: flex; border: 1px solid var(--border); border-radius: var(--radius);
overflow: hidden; }
.density-btn { background: var(--surface-2); border: none; color: var(--text-dim); cursor: pointer;
font-family: var(--font-mono); font-size: 0.68rem; letter-spacing: 0.04em;
text-transform: uppercase; padding: 0.36rem 0.7rem; transition: color 0.15s, background 0.15s; }
.density-btn + .density-btn { border-left: 1px solid var(--border); }
.density-btn:hover { color: var(--select); }
.density-btn.active { background: var(--select); color: #1a1b1e; }
.tags-toggle { display: none; background: var(--surface-2); border: 1px solid var(--border);
color: var(--text-dim); border-radius: 3px; padding: 0.3rem 0.7rem; cursor: pointer;
font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.04em; text-transform: uppercase; }
.tags-toggle:hover, .tags-toggle.has-active { color: var(--select); border-color: var(--select); }
/* Tag chips wrap by default (no-JS safe). With JS the row becomes a scroll
strip on wide viewports and collapses behind the Tags toggle on narrow
ones, so the sticky bar never eats the mobile viewport. */
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
html.js .chips { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 0.25rem;
scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
html.js .chips::-webkit-scrollbar { height: 5px; }
html.js .chips::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.chip { background: var(--surface-2); border: 1px solid var(--border); color: var(--text-dim);
border-radius: 3px; padding: 0.22rem 0.7rem; font-size: 0.72rem; font-weight: 400;
font-family: var(--font-mono); cursor: pointer; white-space: nowrap; flex: 0 0 auto;
transition: color 0.15s, border-color 0.15s; }
.chip:hover { color: var(--select); border-color: var(--select); }
.chip.active { color: #1a1b1e; background: var(--select); border-color: var(--select); }
@media (max-width: 719px) {
html.js .tags-toggle { display: inline-block; }
html.js .chips { display: none; }
html.js .chips.open { display: flex; flex-wrap: wrap; overflow-y: auto; max-height: 40vh; }
}
/* Compact density: hero + name + one-line teaser. The description and
WITNESSES text stay in the DOM (searchable, screen-reader reachable,
present with JS disabled when the class is never applied) but are
visually collapsed. Applied only by JS via the density-compact class. */
html.density-compact .grid { gap: 1rem; }
html.density-compact .card-body { padding: 0.65rem 0.9rem 0.7rem; }
html.density-compact .card-body h2 { font-size: 0.88rem; margin-bottom: 0.15rem; }
html.density-compact .teaches { font-size: 0.8rem; color: var(--text-dim); margin-bottom: 0;
white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
html.density-compact .witnesses { position: absolute; width: 1px; height: 1px; margin: -1px;
padding: 0; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
html.density-compact .card-link { display: none; }
.noresults { color: var(--text-dim); text-align: center; padding: 3rem 1rem; font-size: 0.95rem; }
.noresults .chip { margin-left: 0.6rem; }
.to-top { position: fixed; right: 1.25rem; bottom: 1.25rem; z-index: 6; cursor: pointer;
background: var(--surface-2); border: 1px solid var(--border); color: var(--text-dim);
border-radius: var(--radius); padding: 0.45rem 0.75rem;
font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.04em;
text-transform: uppercase; opacity: 0; visibility: hidden;
transition: opacity 0.2s, visibility 0.2s, color 0.15s, border-color 0.15s; }
.to-top.show { opacity: 1; visibility: visible; }
.to-top:hover { color: var(--select); border-color: var(--select); }
main { max-width: var(--maxw); margin: 0 auto; padding: 1rem 1.25rem 2rem; }
.grid { display: grid; grid-template-columns: 1fr; gap: 1.5rem; align-items: stretch; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
overflow: hidden; display: flex; flex-direction: column;
outline: 2px solid transparent; outline-offset: -1px;
transition: outline-color 0.12s ease, border-color 0.12s ease; }
.card:hover { border-color: var(--select); outline-color: var(--select); }
.card.hidden { display: none; }
.card-media { display: block; background: var(--bg2); line-height: 0; }
.card-media img { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; }
.card-body { padding: 1.15rem 1.4rem 1.45rem; display: flex; flex-direction: column; flex: 1 1 auto; }
.card-body h2 { font-family: var(--font-mono); font-size: 1rem; font-weight: 400; margin-bottom: 0.5rem; }
.card-body h2 a { color: var(--text); }
.card-body h2 a:hover { color: var(--select); text-decoration: none; }
.teaches { color: var(--text); margin-bottom: 0.7rem; font-size: 0.92rem; }
.witnesses { color: var(--text-dim); font-size: 0.85rem; margin-bottom: 1rem; }
.tag { display: inline-block; font-family: var(--font-mono); font-size: 0.62rem; text-transform: uppercase;
letter-spacing: 0.06em; color: var(--select); border: 1px solid color-mix(in srgb, var(--select) 55%, transparent);
border-radius: 3px; padding: 0.08rem 0.5rem; margin-right: 0.4rem; vertical-align: 1px; }
.card-link { font-weight: 600; font-size: 0.95rem; margin-top: auto; }
/* ---- detail page ---- */
.detail-hero { border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden;
background: var(--bg2); padding: 0; display: block; width: 100%; cursor: zoom-in; line-height: 0; }
.detail-hero img { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; }
.zoom-hint { color: var(--text-dim); font-size: 0.78rem; margin-top: 0.4rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0);
white-space: nowrap; }
.callout { border: 1px solid color-mix(in srgb, var(--select) 45%, var(--border));
border-left: 3px solid var(--select); border-radius: var(--radius);
background: color-mix(in srgb, var(--select) 7%, var(--surface));
padding: 0.85rem 1.1rem; margin: 1.5rem 0; font-size: 0.95rem; }
.runline { display: flex; align-items: stretch; gap: 0.5rem; margin: 1.5rem 0; }
.runline pre { flex: 1 1 auto; background: var(--surface-2); border: 1px solid var(--border);
border-radius: var(--radius); padding: 0.7rem 0.9rem; overflow-x: auto;
font-family: var(--font-mono); font-size: 0.83rem; line-height: 1.5; }
.copy-btn { flex: 0 0 auto; background: var(--surface-2); border: 1px solid var(--border);
color: var(--text-dim); border-radius: var(--radius); padding: 0 0.85rem; cursor: pointer;
font-family: var(--font-sans); font-size: 0.82rem; font-weight: 500; transition: color 0.15s, border-color 0.15s; }
.copy-btn:hover { color: var(--select); border-color: var(--select); }
.detail-section { margin-top: 2.25rem; }
.detail-section > h2 { font-family: var(--font-display); font-weight: 600; text-transform: uppercase;
font-size: 1.45rem; letter-spacing: 0.005em; padding-bottom: 0.5rem;
border-bottom: 1px solid var(--border); margin-bottom: 1rem; }
.md h1, .md h2, .md h3 { letter-spacing: -0.01em; margin: 1.4rem 0 0.6rem; line-height: 1.25; }
.md h1 { font-size: 1.35rem; } .md h2 { font-size: 1.15rem; } .md h3 { font-size: 1rem; }
.md p { margin: 0.7rem 0; }
.md ul, .md ol { margin: 0.7rem 0 0.7rem 1.4rem; }
.md li { margin: 0.3rem 0; }
.md .table-wrap { overflow-x: auto; margin: 0.9rem 0; }
.md table { border-collapse: collapse; font-size: 0.86rem; min-width: 100%; }
.md th, .md td { text-align: left; vertical-align: top; padding: 0.4rem 0.75rem 0.4rem 0;
border-bottom: 1px solid var(--border); }
.md th { color: var(--text-dim); font-weight: 600; white-space: nowrap; }
.md code { background: var(--surface-2); border: 1px solid var(--border); padding: 0.08rem 0.35rem;
border-radius: 4px; font-family: var(--font-mono); font-size: 0.84em; }
.md pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
padding: 0.85rem 1rem; overflow-x: auto; margin: 0.9rem 0; }
.md pre code { background: none; border: none; padding: 0; font-size: 0.83rem; line-height: 1.55; }
.src pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
padding: 1rem 1.1rem; overflow-x: auto; font-family: var(--font-mono);
font-size: 0.82rem; line-height: 1.55; }
.src .k { color: var(--code-k); } .src .s { color: var(--code-s); }
.src .c { color: var(--code-c); font-style: italic; } .src .n { color: var(--code-n); }
.src-meta { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem;
flex-wrap: wrap; margin-bottom: 0.6rem; color: var(--text-dim); font-size: 0.85rem; }
.src-meta code { font-family: var(--font-mono); font-size: 0.82rem; }
.lightbox { border: 0; margin: 0; padding: 2rem; width: 100%; height: 100%; max-width: none;
max-height: none; background: rgba(0,0,0,0.85); cursor: zoom-out; }
.lightbox[open] { display: flex; align-items: center; justify-content: center; }
.lightbox::backdrop { background: transparent; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: var(--radius); }
.lightbox-close { position: absolute; top: 0.9rem; right: 0.9rem; background: var(--surface-2);
color: var(--text); border: 1px solid var(--border); border-radius: var(--radius);
font: 500 0.8rem var(--font-sans); padding: 0.4rem 0.75rem; cursor: pointer; }
.lightbox-close:hover { border-color: var(--select); color: var(--select); }
footer { border-top: 1px solid var(--border); background: var(--surface); margin-top: 2rem; }
footer .statusbar { max-width: var(--maxw); margin: 0 auto; padding: 0.55rem 1.25rem;
display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
font-family: var(--font-mono); font-size: 0.6875rem; letter-spacing: 0.04em;
text-transform: uppercase; color: var(--text-dim); }
footer .statusbar code { font-family: inherit; text-transform: none; }
@media (min-width: 720px) { .grid { grid-template-columns: 1fr 1fr; gap: 1.75rem; } }
@media (min-width: 560px) { html.density-compact .grid { grid-template-columns: 1fr 1fr; gap: 1rem; } }
@media (min-width: 900px) { html.density-compact .grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1560px) {
html.density-compact .controls-inner,
html.density-compact main { max-width: 1400px; }
html.density-compact .grid { grid-template-columns: repeat(4, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
html { scroll-behavior: auto; }
.card { transition: none; }
.card:hover { transform: none; }
.to-top { transition: none; }
}
</style>
</head>
<body>
<a class="skip" href="#main">Skip to content</a>
<div class="topbar">
<a class="back" href="../"><span aria-hidden="true">←</span> Examples and Showcase</a>
<div class="topbar-right">
<a class="ghlink" href="https://github.com/TMHSDigital/Blender-Developer-Tools">GitHub</a>
</div>
</div>
<header class="hero">
<h1>swatch-grid</h1>
<p>Procedural Principled materials — metal and dielectric, the emission pattern, and the cross-version set_specular shim.</p>
</header>
<main id="main">
<button class="detail-hero" id="heroZoom" type="button" aria-label="View full size: Six material spheres in two rows against a dark backdrop: mirror gold, brushed copper, red, blue, flat orange emission and white.">
<img src="../assets/swatch-grid-hero.webp" alt="Six material spheres in two rows against a dark backdrop: mirror gold, brushed copper, red, blue, flat orange emission and white." width="1280" height="720" />
</button>
<p class="zoom-hint">Rendered headless by the example itself — click to zoom.</p>
<div class="callout"><span class="tag">witnesses</span> EEVEE engine-id mapping: BLENDER_EEVEE on 5.x, BLENDER_EEVEE_NEXT on 4.2–4.5.</div>
<div class="runline">
<pre id="runCmd">blender --background --python examples/swatch-grid/swatch_grid.py --</pre>
<button class="copy-btn" id="copyRun" type="button">Copy</button>
</div>
<section class="detail-section md">
<p>A runnable example that renders a 3×2 grid of spheres — one material per cell — to a single PNG. It demonstrates the <a href="https://github.com/TMHSDigital/Blender-Developer-Tools/tree/main/skills/procedural-materials-and-shaders/SKILL.md"><code>procedural-materials-and-shaders</code></a> patterns end to end:</p>
<ul><li><strong>Principled BSDF</strong> metals (gold, copper: high metallic, low roughness) and dielectrics (red/blue plastic, white rough), configured with <strong>string socket lookups</strong> and <strong>4-tuple colors</strong>.</li><li>The <strong>emission</strong> pattern (an emissive orange swatch).</li><li>The cross-version <strong><code>set_specular</code> shim</strong> (<code>Specular</code> → <code>Specular IOR Level</code>, renamed in Blender 4.0).</li></ul>
<p>It doubles as a live proof of the <strong>EEVEE engine-id</strong> behavior: the version-branch helper resolves <code>BLENDER_EEVEE</code> on Blender 5.x and <code>BLENDER_EEVEE_NEXT</code> on 4.2–4.5, and the check witnesses the inversion for real — the <em>other</em> era's id must be <strong>rejected</strong> by the running build (assignment raises <code>TypeError</code>) and the helper's id accepted — so a regression in that mapping fails the example, not just the docs.</p>
<h2>Run</h2>
<pre><code># Cheap correctness check (materials + engine-id witness, no render):
blender --background --python swatch_grid.py --
# Falsifier: same RGB on every swatch. Must exit non-zero.
blender --background --python swatch_grid.py -- --same-base
# Render and pixel-verify with the build's EEVEE engine (needs a GPU/display):
blender --background --python swatch_grid.py -- --output swatch.png
# GPU-less / CI hosts: render the pixels with Cycles (CPU). The EEVEE id is still
# asserted; only the final pixels use Cycles.
blender --background --python swatch_grid.py -- --output swatch.png --engine cycles --samples 16 --width 960</code></pre>
<h2>Staging</h2>
<p>The backdrop stands 0.16 behind the spheres, so each casts a soft contact shadow. It used to stand 1.58 behind them, and the grid floated. The world is a reflection-only sky: glossy rays see a warm overhead gradient above a dark horizon, and camera and diffuse rays see the dark stage. The mirror-finish gold otherwise reflected the near-black world and rendered as a black ball with two light-card glints. Sphere positions, materials, the camera and the six-region pixel check are unchanged; <code>verify_png</code> still reads six distinct regions on 4.5.11, 5.1.2 and 5.2.1.</p>
<h2>Exit codes</h2>
<p>Per-script sequential checks. <code>9</code> is a valid check code; there is no rule against it. <code>10</code> is the shared framing helper.</p>
<div class="table-wrap"><table><thead><tr><th scope="col">Code</th><th scope="col">Meaning</th></tr></thead><tbody><tr><td>0</td><td>Success</td></tr><tr><td>1</td><td>Uncaught exception (FATAL wrapper)</td></tr><tr><td>2</td><td>argparse / usage</td></tr><tr><td>3</td><td>Distinct swatch colors ≠ 6 (<code>--same-base</code> lands here); also render not six distinct regions</td></tr><tr><td>4</td><td><code>--output</code> produced no file</td></tr><tr><td>5</td><td>Wrong-era EEVEE engine id was accepted</td></tr><tr><td>10</td><td>Gallery framing violation</td></tr></tbody></table></div>
<p><code>--no-verify</code> was a skip-flag and has been removed. Pixel verification always runs when <code>--output</code> is passed.</p>
<p>The <code>blender-smoke</code> workflow runs the check on Blender 5.2 LTS and 4.5 LTS (5.1 on the weekly cron, the <code>needs-5.1</code> PR label, or manual dispatch). Smoke does not pass <code>--output</code> or <code>--same-base</code>.</p>
<h2>Verified</h2>
<p>Runs headless on <strong>Blender 4.5.10 LTS</strong> and <strong>5.1.1</strong>; exercised on both by the <code>blender-smoke</code> workflow on every PR and weekly schedule. The <code>--output</code> render path additionally measures framing against the Layer 1 band via <code>examples/gallery_framing.py</code> (exit 10 on violation) before writing the still.</p>
</section>
<section class="detail-section src">
<h2>Source</h2>
<div class="src-meta">
<code>examples/swatch-grid/swatch_grid.py</code>
<a href="https://github.com/TMHSDigital/Blender-Developer-Tools/tree/main/examples/swatch-grid/swatch_grid.py">View on GitHub →</a>
</div>
<pre><span class="s">"""Procedural-materials swatch grid -- a runnable BDT example.
Renders a 3x2 grid of spheres, one per material, demonstrating the
`procedural-materials-and-shaders` patterns end to end: Principled BSDF (metal +
dielectric), the emission pattern, the cross-version `set_specular` shim, string socket
lookups, and 4-tuple colors. It also doubles as a live proof of the EEVEE engine-id fix:
the version-branch helper resolves `BLENDER_EEVEE` on Blender 5.x and `BLENDER_EEVEE_NEXT`
on 4.2-4.5, and the chosen id is asserted against the build before rendering.
By default it runs only the correctness check (no render) — the CI smoke check.
Pass --output to also render and pixel-verify a still. ``--same-base`` writes
the same RGB to every swatch and still asserts six distinct colors, so the
count fails. That is the falsifier (``--same-axis`` in export-preset-axis).
blender --background --python swatch_grid.py -- # check only
blender --background --python swatch_grid.py -- --same-base # must fail
blender --background --python swatch_grid.py -- --output swatch.png
blender --background --python swatch_grid.py -- --output s.png --engine cycles --samples 8 --width 640
Dependency-light and deterministic (fixed camera/layout, no HDRI, no network). Exits
non-zero on any failure, including a render that comes out black or without the expected
number of distinct swatch regions.
"""</span>
<span class="k">import</span> bpy
<span class="k">import</span> bmesh
<span class="c"># Shared Layer 1 framing measurement (render path only) — see gallery_framing.py</span>
<span class="k">import</span> os <span class="k">as</span> _os, sys <span class="k">as</span> _sys
_sys.path.insert(<span class="n">0</span>, _os.path.join(_os.path.dirname(_os.path.abspath(__file__)), _os.pardir))
_sys.dont_write_bytecode = <span class="k">True</span> <span class="c"># keep examples/__pycache__ out of the repo tree</span>
<span class="k">import</span> gallery_framing
<span class="k">import</span> sys
<span class="k">import</span> os
<span class="k">import</span> math
<span class="k">import</span> argparse
<span class="k">import</span> numpy <span class="k">as</span> np
GRID_COLS, GRID_ROWS = <span class="n">3</span>, <span class="n">2</span>
MATERIAL_COUNT = GRID_COLS * GRID_ROWS <span class="c"># 6</span>
<span class="c"># --- patterns copied from the procedural-materials-and-shaders skill ---</span>
<span class="k">def</span> get_eevee_engine_id():
<span class="s">"""EEVEE id: 'BLENDER_EEVEE' on 5.0+, 'BLENDER_EEVEE_NEXT' on 4.2-4.5."""</span>
<span class="k">return</span> <span class="s">'BLENDER_EEVEE'</span> <span class="k">if</span> bpy.app.version >= (<span class="n">5</span>, <span class="n">0</span>, <span class="n">0</span>) <span class="k">else</span> <span class="s">'BLENDER_EEVEE_NEXT'</span>
<span class="k">def</span> set_specular(bsdf, value):
<span class="s">"""'Specular' was renamed to 'Specular IOR Level' in Blender 4.0; support both."""</span>
<span class="k">if</span> <span class="s">'Specular IOR Level'</span> <span class="k">in</span> bsdf.inputs:
bsdf.inputs[<span class="s">'Specular IOR Level'</span>].default_value = value
<span class="k">return</span> <span class="s">'Specular IOR Level'</span>
<span class="k">if</span> <span class="s">'Specular'</span> <span class="k">in</span> bsdf.inputs:
bsdf.inputs[<span class="s">'Specular'</span>].default_value = value
<span class="k">return</span> <span class="s">'Specular'</span>
<span class="k">return</span> <span class="k">None</span>
<span class="k">def</span> make_principled(name, base_color, metallic, roughness, specular=<span class="k">None</span>):
mat = bpy.data.materials.new(name)
mat.use_nodes = <span class="k">True</span>
nt = mat.node_tree
nt.nodes.clear()
bsdf = nt.nodes.new(<span class="s">'ShaderNodeBsdfPrincipled'</span>)
bsdf.inputs[<span class="s">'Base Color'</span>].default_value = base_color
bsdf.inputs[<span class="s">'Metallic'</span>].default_value = metallic
bsdf.inputs[<span class="s">'Roughness'</span>].default_value = roughness
resolved = set_specular(bsdf, specular) <span class="k">if</span> specular <span class="k">is</span> <span class="k">not</span> <span class="k">None</span> <span class="k">else</span> <span class="k">None</span>
out = nt.nodes.new(<span class="s">'ShaderNodeOutputMaterial'</span>)
nt.links.new(bsdf.outputs[<span class="s">'BSDF'</span>], out.inputs[<span class="s">'Surface'</span>])
<span class="k">return</span> mat, resolved
<span class="k">def</span> make_emissive(name, color, strength):
mat = bpy.data.materials.new(name)
mat.use_nodes = <span class="k">True</span>
nt = mat.node_tree
nt.nodes.clear()
emis = nt.nodes.new(<span class="s">'ShaderNodeEmission'</span>)
emis.inputs[<span class="s">'Color'</span>].default_value = color
emis.inputs[<span class="s">'Strength'</span>].default_value = strength
out = nt.nodes.new(<span class="s">'ShaderNodeOutputMaterial'</span>)
nt.links.new(emis.outputs[<span class="s">'Emission'</span>], out.inputs[<span class="s">'Surface'</span>])
<span class="k">return</span> mat
<span class="k">def</span> build_materials():
<span class="s">"""Return a list of (material, label) covering metal, dielectric, emissive, and the
set_specular shim. The list order maps left-to-right, top-to-bottom across the grid."""</span>
mats, specular_socket = [], <span class="k">None</span>
<span class="c"># polished vs brushed: the roughness gap is what separates the two metals</span>
<span class="c"># on the dark stage -- their sampled patch means must stay > 0.10 apart</span>
<span class="c"># for verify_png, and a mirror finish vs a broad soft highlight does it</span>
m, specular_socket = make_principled(<span class="s">"Gold"</span>, (<span class="n">1.00</span>, <span class="n">0.77</span>, <span class="n">0.34</span>, <span class="n">1</span>), <span class="n">1.0</span>, <span class="n">0.08</span>)
mats.append(m)
m, _ = make_principled(<span class="s">"Copper"</span>, (<span class="n">0.92</span>, <span class="n">0.47</span>, <span class="n">0.36</span>, <span class="n">1</span>), <span class="n">1.0</span>, <span class="n">0.55</span>)
mats.append(m)
m, sr = make_principled(<span class="s">"RedPlastic"</span>, (<span class="n">0.80</span>, <span class="n">0.05</span>, <span class="n">0.05</span>, <span class="n">1</span>), <span class="n">0.0</span>, <span class="n">0.40</span>, specular=<span class="n">0.5</span>)
mats.append(m)
specular_socket = specular_socket <span class="k">or</span> sr
m, _ = make_principled(<span class="s">"BluePlastic"</span>, (<span class="n">0.05</span>, <span class="n">0.20</span>, <span class="n">0.80</span>, <span class="n">1</span>), <span class="n">0.0</span>, <span class="n">0.30</span>, specular=<span class="n">0.5</span>)
mats.append(m)
<span class="c"># strength stays low enough that the Standard view transform keeps the</span>
<span class="c"># hue: at 6.0 every channel clips and the swatch reads white-yellow</span>
mats.append(make_emissive(<span class="s">"EmissiveOrange"</span>, (<span class="n">1.0</span>, <span class="n">0.35</span>, <span class="n">0.05</span>, <span class="n">1</span>), <span class="n">1.4</span>))
m, _ = make_principled(<span class="s">"WhiteRough"</span>, (<span class="n">0.90</span>, <span class="n">0.90</span>, <span class="n">0.92</span>, <span class="n">1</span>), <span class="n">0.0</span>, <span class="n">0.70</span>, specular=<span class="n">0.3</span>)
mats.append(m)
<span class="k">return</span> mats, specular_socket
<span class="k">def</span> build_scene(mats):
xs = [-<span class="n">2.3</span>, <span class="n">0.0</span>, <span class="n">2.3</span>]
zs = [<span class="n">1.15</span>, -<span class="n">1.15</span>]
i = <span class="n">0</span>
<span class="k">for</span> r <span class="k">in</span> range(GRID_ROWS):
<span class="k">for</span> c <span class="k">in</span> range(GRID_COLS):
me = bpy.data.meshes.new(<span class="s">f"</span><span class="s">S</span>{i}<span class="s">"</span>)
bm = bmesh.new()
<span class="k">try</span>:
bmesh.ops.create_uvsphere(bm, u_segments=<span class="n">48</span>, v_segments=<span class="n">24</span>, radius=<span class="n">0.92</span>)
bm.to_mesh(me)
<span class="k">finally</span>:
bm.free()
<span class="k">for</span> poly <span class="k">in</span> me.polygons:
poly.use_smooth = <span class="k">True</span>
ob = bpy.data.objects.new(<span class="s">f"</span><span class="s">S</span>{i}<span class="s">"</span>, me)
ob.location = (xs[c], <span class="n">0.0</span>, zs[r])
bpy.context.collection.objects.link(ob)
ob.data.materials.append(mats[i])
i += <span class="n">1</span>
<span class="c"># ortho camera framed on the grid cells: verify_png() samples the image at</span>
<span class="c"># each cell center, so every sphere must stay inside its third/half of the</span>
<span class="c"># frame. ortho height = ortho_scale * 9/16 = 4.73 units for a grid that</span>
<span class="c"># spans 4.14 -- nothing clips, nothing drifts out of its cell, and the</span>
<span class="c"># grid fills 0.876 of the frame height (inside the Layer 1 band).</span>
cam_d = bpy.data.cameras.new(<span class="s">"cam"</span>)
cam_d.type = <span class="s">'ORTHO'</span>
cam_d.ortho_scale = <span class="n">8.4</span>
cam = bpy.data.objects.new(<span class="s">"cam"</span>, cam_d)
cam.location = (<span class="n">0.0</span>, -<span class="n">10.0</span>, <span class="n">0.0</span>)
cam.rotation_euler = (math.radians(<span class="n">90</span>), <span class="n">0</span>, <span class="n">0</span>)
bpy.context.collection.objects.link(cam)
bpy.context.scene.camera = cam
<span class="c"># dark staged backdrop behind the grid (docs/VISUAL-STYLE.md)</span>
wall_me = bpy.data.meshes.new(<span class="s">"Wall"</span>)
bm = bmesh.new()
<span class="k">try</span>:
bmesh.ops.create_grid(bm, x_segments=<span class="n">1</span>, y_segments=<span class="n">1</span>, size=<span class="n">30.0</span>)
bm.to_mesh(wall_me)
<span class="k">finally</span>:
bm.free()
wmat, _ = make_principled(<span class="s">"Studio"</span>, (<span class="n">0.03</span>, <span class="n">0.032</span>, <span class="n">0.037</span>, <span class="n">1</span>), <span class="n">0.0</span>, <span class="n">0.7</span>)
wall_me.materials.append(wmat)
wall = bpy.data.objects.new(<span class="s">"Wall"</span>, wall_me)
<span class="c"># just behind the spheres (0.16 clear of their backs) so each casts a</span>
<span class="c"># soft contact shadow and reads as mounted; at y=2.5 they hung 1.58 in</span>
<span class="c"># front of the backdrop with nothing under them</span>
wall.location = (<span class="n">0.0</span>, <span class="n">1.08</span>, <span class="n">0.0</span>)
wall.rotation_euler = (math.radians(<span class="n">90</span>), <span class="n">0.0</span>, <span class="n">0.0</span>)
bpy.context.collection.objects.link(wall)
aim = bpy.data.objects.new(<span class="s">"Aim"</span>, <span class="k">None</span>)
bpy.context.collection.objects.link(aim)
<span class="c"># warm shaped key, faint cool fill, and a warm wedge pooling on the</span>
<span class="c"># backdrop -- the gallery's staged look</span>
<span class="k">for</span> lname, loc, energy, size, col <span class="k">in</span> [
(<span class="s">"KeyL"</span>, (-<span class="n">5</span>, -<span class="n">6</span>, <span class="n">4</span>), <span class="n">900</span>, <span class="n">5.0</span>, (<span class="n">1.0</span>, <span class="n">0.96</span>, <span class="n">0.9</span>)),
(<span class="s">"FillL"</span>, (<span class="n">5</span>, -<span class="n">6</span>, -<span class="n">2</span>), <span class="n">220</span>, <span class="n">6.0</span>, (<span class="n">0.75</span>, <span class="n">0.85</span>, <span class="n">1.0</span>)),
(<span class="s">"WedgeL"</span>, (<span class="n">2.6</span>, <span class="n">1.3</span>, <span class="n">4.4</span>), <span class="n">260</span>, <span class="n">5.0</span>, (<span class="n">1.0</span>, <span class="n">0.76</span>, <span class="n">0.5</span>)),
]:
ld = bpy.data.lights.new(lname, <span class="s">'AREA'</span>)
ld.energy = energy
ld.size = size
ld.color = col
lo = bpy.data.objects.new(lname, ld)
lo.location = loc
bpy.context.collection.objects.link(lo)
con = lo.constraints.new(<span class="s">'TRACK_TO'</span>)
con.target = aim
con.track_axis = <span class="s">'TRACK_NEGATIVE_Z'</span>
con.up_axis = <span class="s">'UP_Y'</span>
<span class="c"># the wedge aims past the spheres at the wall, not at the grid</span>
bpy.data.objects[<span class="s">"WedgeL"</span>].constraints.clear()
bpy.data.objects[<span class="s">"WedgeL"</span>].rotation_euler = (math.radians(-<span class="n">56</span>), <span class="n">0.0</span>, math.radians(<span class="n">190</span>))
world = bpy.data.worlds.new(<span class="s">"W"</span>)
world.use_nodes = <span class="k">True</span>
nt = world.node_tree
bg = nt.nodes[<span class="s">"Background"</span>]
bg.inputs[<span class="n">0</span>].default_value = (<span class="n">0.02</span>, <span class="n">0.021</span>, <span class="n">0.025</span>, <span class="n">1</span>)
<span class="c"># A reflection-only sky: glossy rays see a warm overhead gradient over a</span>
<span class="c"># dark horizon, every other ray the dark stage. The mirror-finish gold</span>
<span class="c"># otherwise reflected the near-black world and rendered as a black ball</span>
<span class="c"># with two light-card glints. Diffuse and camera rays are unchanged, so</span>
<span class="c"># the stage stays dark.</span>
path = nt.nodes.new(<span class="s">"ShaderNodeLightPath"</span>)
coord = nt.nodes.new(<span class="s">"ShaderNodeTexCoord"</span>)
sep = nt.nodes.new(<span class="s">"ShaderNodeSeparateXYZ"</span>)
nt.links.new(coord.outputs[<span class="s">"Generated"</span>], sep.inputs[<span class="n">0</span>])
sky = nt.nodes.new(<span class="s">"ShaderNodeValToRGB"</span>)
sky.color_ramp.elements[<span class="n">0</span>].position = <span class="n">0.0</span>
sky.color_ramp.elements[<span class="n">0</span>].color = (<span class="n">0.02</span>, <span class="n">0.021</span>, <span class="n">0.025</span>, <span class="n">1</span>)
sky.color_ramp.elements[<span class="n">1</span>].position = <span class="n">0.7</span>
sky.color_ramp.elements[<span class="n">1</span>].color = (<span class="n">0.70</span>, <span class="n">0.63</span>, <span class="n">0.55</span>, <span class="n">1</span>)
nt.links.new(sep.outputs[<span class="s">"Z"</span>], sky.inputs[<span class="s">"Fac"</span>])
pick = nt.nodes.new(<span class="s">"ShaderNodeMixRGB"</span>)
pick.inputs[<span class="n">1</span>].default_value = (<span class="n">0.02</span>, <span class="n">0.021</span>, <span class="n">0.025</span>, <span class="n">1</span>)
nt.links.new(sky.outputs[<span class="s">"Color"</span>], pick.inputs[<span class="n">2</span>])
nt.links.new(path.outputs[<span class="s">"Is Glossy Ray"</span>], pick.inputs[<span class="n">0</span>])
nt.links.new(pick.outputs[<span class="n">0</span>], bg.inputs[<span class="n">0</span>])
bpy.context.scene.world = world
<span class="k">def</span> swatch_rgb(mat):
<span class="k">for</span> node <span class="k">in</span> mat.node_tree.nodes:
<span class="k">if</span> node.type == <span class="s">"BSDF_PRINCIPLED"</span>:
c = node.inputs[<span class="s">"Base Color"</span>].default_value
<span class="k">return</span> (round(c[<span class="n">0</span>], <span class="n">4</span>), round(c[<span class="n">1</span>], <span class="n">4</span>), round(c[<span class="n">2</span>], <span class="n">4</span>))
<span class="k">if</span> node.type == <span class="s">"EMISSION"</span>:
c = node.inputs[<span class="s">"Color"</span>].default_value
<span class="k">return</span> (round(c[<span class="n">0</span>], <span class="n">4</span>), round(c[<span class="n">1</span>], <span class="n">4</span>), round(c[<span class="n">2</span>], <span class="n">4</span>))
<span class="k">return</span> <span class="k">None</span>
<span class="k">def</span> flatten_swatch_colors(mats):
gray = (<span class="n">0.5</span>, <span class="n">0.5</span>, <span class="n">0.5</span>, <span class="n">1.0</span>)
<span class="k">for</span> mat <span class="k">in</span> mats:
<span class="k">for</span> node <span class="k">in</span> mat.node_tree.nodes:
<span class="k">if</span> node.type == <span class="s">"BSDF_PRINCIPLED"</span>:
node.inputs[<span class="s">"Base Color"</span>].default_value = gray
<span class="k">elif</span> node.type == <span class="s">"EMISSION"</span>:
node.inputs[<span class="s">"Color"</span>].default_value = gray
<span class="k">def</span> check_distinct_swatches(mats):
colors = [swatch_rgb(m) <span class="k">for</span> m <span class="k">in</span> mats]
<span class="k">if</span> len(set(colors)) != MATERIAL_COUNT:
print(
<span class="s">f"</span><span class="s">ERROR: distinct swatch colors </span>{len(set(colors))}<span class="s"> != </span><span class="s">"</span>
<span class="s">f"</span>{MATERIAL_COUNT}<span class="s"> (got </span>{colors}<span class="s">)</span><span class="s">"</span>,
file=sys.stderr,
)
<span class="k">return</span> <span class="n">3</span>
<span class="k">return</span> <span class="n">0</span>
<span class="k">def</span> verify_png(path):
<span class="s">"""Honest capture: not uniformly black AND distinct swatch regions == MATERIAL_COUNT."""</span>
img = bpy.data.images.load(path)
w, h = img.size
arr = np.array(img.pixels[:], dtype=np.float32).reshape(h, w, <span class="n">4</span>)[..., :<span class="n">3</span>]
gmax = float(arr.max())
cw, ch, ph = w // GRID_COLS, h // GRID_ROWS, <span class="n">24</span>
means = []
<span class="k">for</span> r <span class="k">in</span> range(GRID_ROWS):
<span class="k">for</span> c <span class="k">in</span> range(GRID_COLS):
cx, cy = c * cw + cw // <span class="n">2</span>, r * ch + ch // <span class="n">2</span>
means.append(arr[cy - ph:cy + ph, cx - ph:cx + ph, :].reshape(-<span class="n">1</span>, <span class="n">3</span>).mean(axis=<span class="n">0</span>))
kept = []
<span class="k">for</span> cm <span class="k">in</span> means:
<span class="k">if</span> all(np.linalg.norm(cm - k) > <span class="n">0.10</span> <span class="k">for</span> k <span class="k">in</span> kept):
kept.append(cm)
<span class="k">return</span> gmax, len(kept)
<span class="k">def</span> main():
argv = sys.argv[sys.argv.index(<span class="s">"--"</span>) + <span class="n">1</span>:] <span class="k">if</span> <span class="s">"--"</span> <span class="k">in</span> sys.argv <span class="k">else</span> []
p = argparse.ArgumentParser(description=<span class="s">"Render a procedural-materials swatch grid."</span>)
p.add_argument(<span class="s">"--output"</span>, default=<span class="k">None</span>, help=<span class="s">"optional: render a still PNG here"</span>)
p.add_argument(<span class="s">"--engine"</span>, choices=[<span class="s">"auto"</span>, <span class="s">"eevee"</span>, <span class="s">"cycles"</span>], default=<span class="s">"auto"</span>,
help=<span class="s">"auto/eevee use the version-correct EEVEE id; cycles for GPU-less hosts"</span>)
p.add_argument(<span class="s">"--samples"</span>, type=int, default=<span class="n">32</span>)
p.add_argument(<span class="s">"--width"</span>, type=int, default=<span class="n">1280</span>)
p.add_argument(<span class="s">"--same-base"</span>, action=<span class="s">"store_true"</span>,
help=<span class="s">"write the same RGB to every swatch (must fail)"</span>)
args = p.parse_args(argv)
<span class="c"># Empty the factory file FIRST so the materials we create below survive.</span>
bpy.ops.wm.read_factory_settings(use_empty=<span class="k">True</span>)
mats, specular_socket = build_materials()
<span class="k">if</span> args.same_base:
flatten_swatch_colors(mats)
dcode = check_distinct_swatches(mats)
<span class="k">if</span> dcode:
<span class="k">return</span> dcode
build_scene(mats)
sc = bpy.context.scene
<span class="c"># EEVEE engine-id proof: frame-independent, must hold even when we render with</span>
<span class="c"># Cycles. Witness the inversion for real: the OTHER era's id must be rejected</span>
<span class="c"># by this build, and the helper's id must be accepted.</span>
eid = get_eevee_engine_id()
wrong = <span class="s">'BLENDER_EEVEE_NEXT'</span> <span class="k">if</span> bpy.app.version >= (<span class="n">5</span>, <span class="n">0</span>, <span class="n">0</span>) <span class="k">else</span> <span class="s">'BLENDER_EEVEE'</span> <span class="c"># engine-id-exempt: the wrong-era id this example asserts is rejected</span>
<span class="k">try</span>:
sc.render.engine = wrong
print(<span class="s">f"</span><span class="s">ERROR: wrong-era EEVEE id '</span>{wrong}<span class="s">' was accepted by this build — </span><span class="s">"</span>
<span class="s">"the engine-id inversion this example witnesses is gone"</span>, file=sys.stderr)
<span class="k">return</span> <span class="n">5</span>
<span class="k">except</span> TypeError:
<span class="k">pass</span> <span class="c"># correctly rejected</span>
sc.render.engine = eid <span class="c"># the helper's id must exist (raises TypeError if not)</span>
print(<span class="s">f"</span><span class="s">eevee_engine_id=</span>{eid}<span class="s"> accepted, '</span>{wrong}<span class="s">' rejected OK; </span><span class="s">"</span>
<span class="s">f"</span><span class="s">set_specular resolved '</span>{specular_socket}<span class="s">'</span><span class="s">"</span>)
<span class="k">if</span> <span class="k">not</span> args.output:
print(<span class="s">"swatch-grid OK"</span>)
<span class="k">return</span> <span class="n">0</span>
render_engine = <span class="s">'CYCLES'</span> <span class="k">if</span> args.engine == <span class="s">'cycles'</span> <span class="k">else</span> eid
sc.render.engine = render_engine
<span class="k">if</span> render_engine == <span class="s">'CYCLES'</span>:
sc.cycles.samples = args.samples
<span class="k">else</span>:
sc.eevee.taa_render_samples = args.samples
sc.render.resolution_x = args.width
sc.render.resolution_y = int(args.width * <span class="n">9</span> / <span class="n">16</span>)
sc.render.image_settings.file_format = <span class="s">'PNG'</span>
sc.render.filepath = args.output
<span class="c"># AgX would desaturate the swatches toward pastel -- exactly the material</span>
<span class="c"># colors this example exists to show (docs/VISUAL-STYLE.md)</span>
sc.view_settings.view_transform = <span class="s">'Standard'</span>
<span class="c"># Layer 1 framing gate (silhouette matte) — exit 10 on violation, before</span>
<span class="c"># the beauty render so a defective composition ships no artifact.</span>
spheres = [o <span class="k">for</span> o <span class="k">in</span> sc.objects <span class="k">if</span> o.type == <span class="s">"MESH"</span> <span class="k">and</span> o.name.startswith(<span class="s">"S"</span>)]
stage = [o <span class="k">for</span> o <span class="k">in</span> sc.objects <span class="k">if</span> o.name == <span class="s">"Wall"</span>]
fcode = gallery_framing.check_framing(
sc, sc.camera,
hero=spheres,
elements=spheres,
stage=stage,
)
<span class="k">if</span> fcode:
<span class="k">return</span> fcode
os.makedirs(os.path.dirname(os.path.abspath(args.output)) <span class="k">or</span> <span class="s">"."</span>, exist_ok=<span class="k">True</span>)
bpy.ops.render.render(write_still=<span class="k">True</span>)
<span class="k">if</span> <span class="k">not</span> (os.path.exists(args.output) <span class="k">and</span> os.path.getsize(args.output) > <span class="n">0</span>):
print(<span class="s">"ERROR: no output written"</span>, file=sys.stderr)
<span class="k">return</span> <span class="n">4</span>
print(<span class="s">f"</span><span class="s">rendered </span>{args.output}<span class="s"> with </span>{render_engine}<span class="s"> (</span>{os.path.getsize(args.output)}<span class="s"> bytes)</span><span class="s">"</span>)
gmax, regions = verify_png(args.output)
non_black = gmax > <span class="n">0.05</span>
regions_ok = regions == MATERIAL_COUNT
print(<span class="s">f"</span><span class="s">verify: max_pixel=</span>{gmax:<span class="s">.3f</span>}<span class="s"> non_black=</span>{non_black}<span class="s"> </span><span class="s">"</span>
<span class="s">f"</span><span class="s">distinct_regions=</span>{regions}<span class="s"> materials=</span>{MATERIAL_COUNT}<span class="s"> ok=</span>{regions_ok}<span class="s">"</span>)
<span class="k">if</span> <span class="k">not</span> (non_black <span class="k">and</span> regions_ok):
print(<span class="s">"ERROR: render failed verification (black or wrong region count)"</span>, file=sys.stderr)
<span class="k">return</span> <span class="n">3</span>
print(<span class="s">"swatch-grid OK"</span>)
<span class="k">return</span> <span class="n">0</span>
<span class="k">if</span> __name__ == <span class="s">"__main__"</span>:
<span class="k">try</span>:
sys.exit(main())
<span class="k">except</span> Exception <span class="k">as</span> exc: <span class="c"># blender exits 0 on an uncaught traceback; force non-zero</span>
<span class="k">import</span> traceback
traceback.print_exc()
print(<span class="s">f"</span><span class="s">FATAL: </span>{type(exc).__name__}<span class="s">: </span>{exc}<span class="s">"</span>, file=sys.stderr)
sys.exit(<span class="n">1</span>)
</pre>
</section>
</main>
<dialog class="lightbox" id="lightbox" aria-label="Full-size render">
<button class="lightbox-close" type="button" autofocus>Close</button>
<img src="../assets/swatch-grid-hero.webp" alt="Six material spheres in two rows against a dark backdrop: mirror gold, brushed copper, red, blue, flat orange emission and white." />
</dialog>
<footer>
<div class="statusbar">
<span>generated from <code>examples/gallery.json</code></span>
<span>CC-BY-NC-ND-4.0</span>
<span style="color: var(--ok);">exit 0</span>
</div>
</footer>
<script>
(function () {
var hero = document.getElementById('heroZoom');
var box = document.getElementById('lightbox');
if (hero && box) {
// <dialog>.showModal() traps focus, closes on Escape, and returns
// focus to the hero button on close. Any click inside closes it.
hero.addEventListener('click', function () { box.showModal(); });
box.addEventListener('click', function () { box.close(); });
}
var copy = document.getElementById('copyRun');
if (copy) {
copy.addEventListener('click', function () {
var cmd = document.getElementById('runCmd').textContent;
navigator.clipboard.writeText(cmd).then(function () {
copy.textContent = 'Copied!';
setTimeout(function () { copy.textContent = 'Copy'; }, 1500);
});
});
}
})();
</script>
</body>
</html>