Nodes/ComfyUI-TextureAlchemy/Composite Mask Extractor
ComfyUI Node

Composite Mask Extractor

Turning Marigold's shading passes into usable masks

By amtarr·Created 9 months ago·Updated 4 months ago· 58
Composite Mask Extractor
  • albedo
  • shading
  • residual
  • mask
extract_fromShading
methodLuminance
threshold0.50
range_min0.00
range_max1.00
feather0.00
gamma1.00

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.

CategoryTexture Alchemist/Materials

Inputs (10)

NameTypeDefaultDescription
extract_fromCOMBOShadingWhich pass to extract mask from
methodCOMBOLuminanceMethod for mask extraction
thresholdFLOAT0.500–1Threshold value for Threshold method
range_minFLOAT0.000–1Minimum value for Range method
range_maxFLOAT1.000–1Maximum value for Range method
featherFLOAT0.000–0.5Soften mask edges (0 = hard edges)
gammaFLOAT1.000.1–3Gamma adjustment for mask
albedooptIMAGE
shadingoptIMAGE
residualoptIMAGE

Outputs (1)

NameTypeDescription
maskIMAGE