PDTool:UnMultBlackBackground
The compositing fix for flames and glows saved on black
- image
- image
- mask
The one operator that fixes "this glow has a black box around it"
PD_UnMultBlackBackground (shown as "PDTool:UnMultBlackBackground") is the general-purpose version of a classic compositing operator called unmult. You have an asset that was rendered or saved with a black background - a flame, a glow, a sparkle, smoke lit from below - and it carries that darkness into your composite. This node estimates where the object is from its brightness, treats that as transparency, and divides the color back out so the asset's true, bright colors survive compositing instead of arriving tinted black.
This is the "the image was premultiplied against black and I need to undo it" problem, and it's everywhere once you start compositing effects. The KB's background-removal.md covers the AI matting route for content extraction, but unmult is the procedural route for effects: there's no "subject" for a model to find, just a bright region on black that needs to become an alpha. This node is that operator, done in torch, with a noise filter bolted on.
How it works
The source is refreshingly clear. Alpha = the max of the three RGB channels (brightest channel as transparency). Then the black_threshold filter: any alpha at or below the threshold is forced to zero - that's the JPG-noise killer, and it's the detail the comments in the code specifically call out (JPG compression throws tiny dark speckles into pure-black areas, and without this they'd become real alpha). Then the unpremultiply: image / alpha, clamped, with any fully-black region rendered pure black. Output is the recovered image and the alpha as a mask.
black_threshold (default 0.02, range 0 to 0.5) is the only knob. Raised, it crushes background noise harder but starts eating faint, genuinely-dark glow edges. At the default it quietly handles the common case.
Inputs and outputs
image- the glow/effect on black.black_threshold- float, 0.0 to 0.5, default 0.02.- Outputs:
image(unpremultiplied RGB) andmask(the alpha). Composite the image using the mask.
Installing it
Part of Comfyui_PDuse:
cd ComfyUI/custom_nodes
git clone https://github.com/7BEII/Comfyui_PDuse.git
cd Comfyui_PDuse
pip install -r requirements.txt
Or via ComfyUI Manager (search "Comfyui_PDuse") and restart.
How it's different from the other PD filter nodes, and the traps
PDtools_Filter_WPNG_v2 is the same unmult idea but tuned for glowing text (it adds a soft blur to the alpha for smooth halos). This node is the raw, un-blurred operator - harder-edged, which suits sparks, embers, and fire better than neon lettering. PDtools_Filter_WPNG_v1 is a totally different thing (hard threshold binarization). Don't mix them up.
The trap: unmult brightens anything that isn't truly black - a dark-grey background, or an object that's genuinely dark rather than glowy, will come out lifted and washed. If your asset's "black" is more like dark brown or has a visible gradient, raise the threshold and accept that you'll lose the faintest edges. And remember the output is still RGB on black for preview - the mask is what you composite with. For flames, glows, and anything bright-on-black, this is the node that finally makes the cut look clean.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| black_threshold | FLOAT | 0.0200–0.5 | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |