Composite Mask Extractor
Turning Marigold's shading passes into usable masks
- albedo
- shading
- residual
- mask
The star node of this pack - the PBR Extractor - works by feeding a single image through Marigold twice, once with an "appearance" model and once with a "lighting" model, then splitting the results into albedo, shading, and residual passes. Those passes are gold for material extraction, but they're not directly useful as masks. This node is the bridge: it takes one or more of those passes and squeezes a clean, editable mask out of them.
What you're actually doing is isolating a property. Say the shading pass - which captures the light/shadow structure of the scene - has bright areas and dark areas. With the default extract_from="Shading" and method="Luminance", you get a mask where bright shading becomes white. Flip to Inverse Luminance and you've selected the shadows. Add Threshold and now only pixels above a cutoff count. Range lets you isolate a band of values between range_min and range_max, which is the one you want when you're picking out a specific brightness slice.
The other half of the trick is extract_from, which picks the source pass: Albedo, Shading, Residual, or Combined (averages whatever passes you connected). The optional inputs albedo, shading, and residual map to those names, and if you ask for a pass you didn't wire up, it raises a clear error rather than silently outputting garbage - a small touch that saves real debugging time.
Two post-process knobs make the mask actually usable. feather softens edges (0 = hard, up to 0.5 for a diffuse falloff) - invaluable when the mask is going into a blend rather than a hard selection. gamma reshapes the response curve, so you can push the midtones around without touching the threshold. For most extraction you'll set these once and forget them.
Why bother? In the material pipeline, these masks drive targeted adjustments: use a shading-based mask to darken AO only where shadows actually fall, or a residual-based mask to isolate what Marigold couldn't explain with lighting - usually texture detail - and then selectively sharpen or smooth just those regions. It's the node that turns "I have a lighting breakdown" into "I have a selection."
One input to keep an eye on: the output is a single mask IMAGE, and it's an RGB image, so it plugs straight into blend masks, the Detail Map Blender, or a compositing chain without any channel gymnastics.
Install is the pack standard: ComfyUI Manager → "Texture Alchemy", or:
cd ComfyUI/custom_nodes
git clone https://github.com/amtarr/ComfyUI-TextureAlchemy
Restart, then Texture Alchemist/Materials → Composite Mask Extractor. No extra requirements. One note: this node only shines if you're already running the Marigold-based PBR Extractor, which does need kijai's ComfyUI-Marigold with the appearance and lighting models - the node itself, though, is pure tensor math and needs nothing.
Inputs (10)
| Name | Type | Default | Description |
|---|---|---|---|
| extract_from | COMBO | Shading | Which pass to extract mask from |
| method | COMBO | Luminance | Method for mask extraction |
| threshold | FLOAT | 0.500–1 | Threshold value for Threshold method |
| range_min | FLOAT | 0.000–1 | Minimum value for Range method |
| range_max | FLOAT | 1.000–1 | Maximum value for Range method |
| feather | FLOAT | 0.000–0.5 | Soften mask edges (0 = hard edges) |
| gamma | FLOAT | 1.000.1–3 | Gamma adjustment for mask |
| albedoopt | IMAGE | — | |
| shadingopt | IMAGE | — | |
| residualopt | IMAGE | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| mask | IMAGE | — |