comfyui_pcg docs

Image: Compositing & Masks#

Blending images and building masks.

10 nodes.

Back to the reference index

Contents#

  • COP Combine Normals (PCG) — Combines a base normal map and a detail normal map into one normal map.
  • COP Compare Mask (PCG) — Compares two layers (or a layer and a constant) per pixel and outputs a 0..1 mask.
  • COP Composite (PCG) — Composites the foreground input over the background input with a choice of blend modes.
  • COP Drop Shadow (PCG) — Builds a drop shadow from an alpha mask by offsetting, blurring and tinting it behind the original image.
  • COP Layer Combine (PCG) — Combines the same layer from up to six inputs into one image, pixel by pixel.
  • COP Logic (PCG) — Compares layers or combines them with boolean operations, producing a 0/1 mask.
  • COP Mask Combine (PCG) — Combines several masks into one, using a simple operation or a Houdini-style stack of blend modes.
  • COP Premultiply (PCG) — Multiplies RGB by alpha, or divides it back out.
  • COP Select (PCG) — Compares two layers per pixel and picks one, or blends them smoothly by the difference.
  • COP Wipe (PCG) — Transitions from image A to image B with a linear, radial, dissolve or crossfade wipe.

Nodes#

COP Combine Normals (PCG)#

PCG_COPCombineNormals · category PCG/cop · Houdini: Combine Normals (COP)

Combines a base normal map and a detail normal map into one normal map.

COP Combine Normals (PCG): input and result

Both inputs must be signed normals (-1..1). The base layer is read from cop; the detail layer from the detail input, or from the same image if detail is not connected. Methods:

  • rnm (default): Reoriented Normal Mapping. Rotates the detail into the base's frame, so detail on steep slopes follows the slope instead of being flattened.
  • whiteout: adds xy, multiplies z. Cheap, but detail is weaker on steep slopes.
  • udn: adds xy, takes z from the base. Even cheaper.
  • linear: adds and renormalizes. Kept for comparison only: even flat detail tilts the base towards +z and weakens slopes.

With flat detail, rnm, whiteout and udn return the base unchanged (linear does not); with a flat base, rnm returns the detail unchanged. The result is always unit length. Amount scales the detail (0 means no detail).

Inputs

InputTypeDescription
copCOPIMAGEImage holding the base (large-scale) normal layer.
detail (optional)COPIMAGEOptional image holding the detail normal layer. If not connected, the detail layer is taken from cop.

Outputs

OutputTypeDescription
copCOPIMAGEImage with the combined normal layer.

Parameters

ParameterTypeDefaultDescription
Base Layer base_layerstringNName of the base normal layer in cop.
Detail Layer detail_layerstringNName of the detail normal layer. Taken from the detail input if it is connected, otherwise from cop.
Method methodmenuReoriented Normal MappingBlend method; see the description. rnm is the most accurate, linear the least. Options: Reoriented Normal Mapping (rnm), Whiteout (whiteout), UDN (udn), Linear (linear).
Detail Amount amountfloat [0.0..16.0]1Strength of the detail normal. 0 removes the detail, 1 uses it fully, larger values exaggerate it.
Output Layer out_layerstringNName of the output layer.
Keep Input Layers keep_layerstoggleonKeep the other layers of the input in the output.

COP Compare Mask (PCG)#

PCG_COPCompareMask · category PCG/cop · Houdini: Compare (COP)

Compares two layers (or a layer and a constant) per pixel and outputs a 0..1 mask.

Compares A with B per pixel using the True If condition and writes a single-channel 0..1 mask. B is Layer B, or the Comparison Value when Layer B is empty. For multi-channel layers, Components decides whether all channels (minimum) or any channel (maximum) must pass.

Tolerance is two-sided for the equality tests (equal, not_equal) and one-sided for the strict and non-strict inequalities. Pixels that pass the comparison are always 1; Falloff shapes the pixels that fail it but lie within the tolerance: none cuts hard at the tolerance edge, linear ramps from 1 down to 0, elendt uses a smooth S-shaped curve (implemented here as smoothstep, so intermediate values differ slightly from Houdini). not_equal is the complement of equal.

To measure how different two images are (SSIM, PSNR) use COP Compare.

Inputs

InputTypeDescription
copCOPIMAGEImage containing the layers to compare.

Outputs

OutputTypeDescription
copCOPIMAGEImage with the mask layer added.

Parameters

ParameterTypeDefaultDescription
Layer A layer_astringCFirst layer (A).
Layer B layer_bstring(empty)Second layer (B). Empty compares A with Comparison Value instead.
Comparison Value valuefloat0Constant that A is compared against when Layer B is empty. Disabled when layer_b ≠ "".
Tolerance tolerancefloat [0..]0Allowed difference within which the Falloff applies. Used for every comparison, including with Falloff none (a hard cut at the tolerance edge). Disabled when tolerance_layer ≠ "".
Tolerance Layer tolerance_layerstring(empty)Optional single-channel layer providing a per-pixel tolerance. When set it replaces Tolerance.
True If true_ifmenuEqual to each other (==)Condition under which the mask is 1: A equal to, not equal to, greater than, greater or equal to, less than or less or equal to B. Options: Equal to each other (==) (equal), Not equal to each other (!=) (not_equal), A greater than B (>) (greater), A greater than or equal to B (>=) (greater_equal), B greater than A (<) (less), B greater than or equal to A (<=) (less_equal).
Components componentsmenuTrue if AllFor multi-channel layers: all requires every channel to pass, any requires at least one. Options: True if All (all), True if Any (any).
Falloff falloffmenuNoneTransition for pixels that fail the comparison but are within the tolerance: none is a hard cut, linear a linear ramp, elendt a smooth S curve. Options: None (none), Linear (linear), Elendt (elendt).
Output Layer out_layerstringmaskName of the mask layer.

Compared with Houdini

Corresponds to Houdini's Compare node.


COP Composite (PCG)#

PCG_COPComposite · category PCG/cop · Houdini: Blend (COP)

Composites the foreground input over the background input with a choice of blend modes.

COP Composite (PCG): input and result

over, atop, xor and under are Porter-Duff operators and compute a new alpha: C = (Cf*af + Cb*ab*(1-af)) / a, a = af + ab*(1-af) for over. They work on non-premultiplied alpha, like ComfyUI images. All other modes (add, multiply, screen and so on) are component-wise functions of foreground and background; opacity and mask then interpolate between the background and the blended result. Treating over as an alpha interpolation would give the wrong alpha when both layers are semi-transparent.

If resolutions differ, the foreground is resampled to the background. Only single-channel layers are broadcast automatically (for example a mask onto RGB); a 3- versus 4-channel mismatch is not guessed. Values are never clamped, so add can give 1.7 and HDR, SDF and normal data survive; clamping only happens at COP Export.

The mask input is multiplied with Opacity when connected.

Inputs

InputTypeDescription
backgroundCOPIMAGEBase image. Defines the output resolution.
foregroundCOPIMAGEImage composited on top of the background.
mask (optional)COPIMAGEOptional mask image. Its Mask Layer is multiplied with Opacity.

Outputs

OutputTypeDescription
copCOPIMAGEThe composite.

Parameters

ParameterTypeDefaultDescription
Mode modemenuOverBlend mode. over, atop, xor and under are alpha compositing operators; replace returns the foreground (Houdini's Blend); darken / lighten are minimum / maximum; hypot combines values as sqrt(a^2 + b^2); the remaining modes are the usual formulas. Options: Over (over), Add (add), Subtract (subtract), Difference (difference), Multiply (multiply), Divide (divide), Screen (screen), Overlay (overlay), SoftLight (softlight), Minimum (darken), Maximum (lighten), Atop (atop), Xor (xor), Blend (replace), Under (under), Hypot (hypot), Exclusion (exclusion), HardLight (hardlight), Dodge (dodge), Burn (burn).
Mask opacityfloat [-10000.0..10000.0]1Amount of the blended result mixed in. When the mask input is connected, multiplied by the mask.
Swap FG and BG swaptoggleoffSwaps the values of foreground and background before blending (the resolution still follows the first input).
Compare Lengths compare_lengthstoggleoffFor darken and lighten: choose the whole pixel with the smaller / larger vector length instead of comparing channel by channel. Disabled when mode ≠ darken mode ≠ lighten.
Red channel_rtoggleonProcess the red channel. A disabled channel keeps the background value.
Green channel_gtoggleonProcess the green channel. A disabled channel keeps the background value.
Blue channel_btoggleonProcess the blue channel. A disabled channel keeps the background value.
Alpha channel_atoggleonProcess the alpha channel. A disabled channel keeps the background value.
Background Layer layerstringCBackground layer to composite onto.
Foreground Layer foreground_layerstring(empty)Layer of the foreground image to use. Empty uses the same name as Layer.
Mask Layer mask_layerstringmaskLayer of the mask input to read. Only used when mask is connected.
Output Layer output_layerstring(empty)Name of the result layer. Empty overwrites Layer.
Keep Other Layers keep_other_layerstoggleonCopy the other layers of the background to the output. When off, only the result layer is output.

Compared with Houdini

Compared with Houdini's Blend, Under, Hypot, Exclusion, HardLight, Dodge and Burn were added; Houdini's Blend is replace here, and Maximum / Minimum are lighten / darken. The Sharpen mode and the Hue, Saturation, Luminosity and Color modes are not implemented. Space, Border, Filter, Clip by Data Window and Crop to Content are not offered because images have no data window.

Tips

  • Keep HDR data in the chain and clamp only at the end (COP Export or COP Clamp).

COP Drop Shadow (PCG)#

PCG_COPDropShadow · category PCG/cop · Houdini: Drop Shadow (COP)

Builds a drop shadow from an alpha mask by offsetting, blurring and tinting it behind the original image.

Takes the alpha (the 4th channel of layer, or a separate alpha layer), shifts it by an offset, blurs it, colors it and places it underneath the original image. The result is RGBA.

The node errors out if there is no alpha at all; it does not guess one.

Inputs

InputTypeDescription
copCOPIMAGEImage containing the layer that casts the shadow.

Outputs

OutputTypeDescription
copCOPIMAGERGBA image: the original with the shadow composited underneath.

Parameters

ParameterTypeDefaultDescription
Layer layerstringCColor layer to cast the shadow from and composite over.
Alpha Layer alpha_layerstring(empty)Layer whose first channel is the shadow alpha. Empty uses the 4th channel of layer, and errors if there is none.
Offset (Pixels) offsetstring8 -8Shadow offset as two numbers x y in pixels. Positive y points up.
Blur blurfloat [0..512]6Blur radius of the shadow in pixels.
Shadow Color colorstring0 0 0Shadow color as space-separated RGB values.
Opacity opacityfloat [0..1]0.7Overall opacity of the shadow, 0 to 1.

COP Layer Combine (PCG)#

PCG_COPLayerCombine · category PCG/cop · Houdini: Layer Merge (COP)

Combines the same layer from up to six inputs into one image, pixel by pixel.

Reads the chosen layer from every connected input and combines them per pixel with Add, Average, Multiply, Min, Max or Over. Resolution follows the first connected input and the others are resampled to it; single-channel layers are broadcast to the channel count of the others.

Over places earlier inputs on top of later ones and only makes sense for RGBA; for non-RGBA layers the last input is copied. Houdini accepts any number of inputs; here there are six sockets, so chain two nodes if you need more.

This is not COP Layer Merge (PCG), which moves layers from one image into another without doing any pixel math.

Inputs

InputTypeDescription
source1 (optional)COPIMAGEFirst image to combine. Defines the output resolution when connected.
source2 (optional)COPIMAGESecond image to combine.
source3 (optional)COPIMAGEThird image to combine.
source4 (optional)COPIMAGEFourth image to combine.
source5 (optional)COPIMAGEFifth image to combine.
source6 (optional)COPIMAGESixth image to combine.

Outputs

OutputTypeDescription
copCOPIMAGECopy of the first connected input with the combined result written to the output layer.

Parameters

ParameterTypeDefaultDescription
Layer layerstringCLayer read from every input.
Operation operationmenuAddHow the inputs are combined. Over layers the inputs front to back in socket order (source1 on top). Options: Add (add), Average (average), Multiply (multiply), Min (min), Max (max), Over (over).
Output Layer out_layerstring(empty)Name of the result layer. Empty overwrites Layer.

Compared with Houdini

Corresponds to Houdini's Layer Merge COP (the one documented as cop/average). Space, Border, Filter, Clip by Data Window and Crop to Content are not implemented because they depend on data windows.


COP Logic (PCG)#

PCG_COPLogic · category PCG/cop · Houdini: Logic (COP)

Compares layers or combines them with boolean operations, producing a 0/1 mask.

Input A is a layer name; Input B is either a layer name or a constant number. Comparison operations (A > B, A >= B, A < B, A <= B, A = B, A != B) give 1 where true. Boolean operations (AND, OR, XOR, NOT A) treat any value above 0.5 as true. Equality uses Tolerance, since exact float equality almost never holds. For multichannel layers the result is 1 only where all channels satisfy the test. The output is a single channel.

Inputs

InputTypeDescription
copCOPIMAGEImage containing the layers to compare.

Outputs

OutputTypeDescription
copCOPIMAGEImage with the 0/1 mask added.

Parameters

ParameterTypeDefaultDescription
Input A astringCName of the layer used as operand A.
Operation opmenuA > BComparison or boolean operation. Options: A > B (greater), A ≥ B (greater_equal), A < B (less), A ≤ B (less_equal), A = B (equal), A ≠ B (not_equal), A AND B (and), A OR B (or), A XOR B (xor), NOT A (not).
Input B bstring0.5Operand B: a layer name or a constant number. Ignored by NOT A. Disabled when op = not.
Tolerance tolerancefloat [0..]1e-06Allowed difference for equality tests (and the margin for >= and <=). Hidden when op = greater } { op = less } { op = and } { op = or } { op = xor } { op = not.
Output Layer out_layerstringmaskName of the mask layer.

COP Mask Combine (PCG)#

PCG_COPMaskCombine · category PCG/cop · Houdini: Mask Combine (COP)

Combines several masks into one, using a simple operation or a Houdini-style stack of blend modes.

Only the first channel of each layer is used. Simple operations on the listed Mask Layers: Union is the maximum, Intersect the minimum, Add sums, Multiply multiplies, Subtract takes the first minus all others, Difference accumulates |a - b|, Screen is the soft union 1 - prod(1 - m), and Average takes the mean.

Per-Layer Blend Modes (Houdini) works like Houdini's node: the result starts at Starting Value and the rows of the Mask Layers stack are applied from top to bottom, each as result = lerp(result, blend(result, layer), amount). Each row has the form layer[.channel] mode amount; the channel is r g b a or x y z w (default first channel), mode defaults to blend and amount to 1, and a row starting with # is disabled. Rows may also be separated with ;. This mode ignores the simple Mask Layers list.

Post-processing is applied in this order: Fold (absolute value), Complement (1 - x), Clamp Minimum, Clamp Maximum, then Clamp 0-1.

Inputs

InputTypeDescription
copCOPIMAGEImage containing the mask layers.

Outputs

OutputTypeDescription
copCOPIMAGEImage with the combined mask in the output layer.

Parameters

ParameterTypeDefaultDescription
Operation opmenuUnion (Max)How the masks are combined. Options: Union (Max) (union), Intersect (Min) (intersect), Add (add), Multiply (multiply), Subtract (subtract), Difference (difference), Screen (screen), Average (average), Per-Layer Blend Modes (Houdini) (layer_stack).
Mask Layers layersstringCSpace-separated mask layers for the simple operations (first channel only). Not used by the stack mode. Hidden when op = layer_stack.
Starting Value starting_valuefloat0Per-Layer Blend Modes only: value the result starts from before the first row. Hidden when op ≠ layer_stack.
Mask Layers stackstringmask add 1Per-Layer Blend Modes only: one row per layer, applied top to bottom as layer[.channel] mode amount. Modes: blend, add, subtract, multiply, divide, screen, hypot, difference, exclusion, maximum, minimum, overlay, softlight, hardlight, dodge, burn. A leading # disables the row. Hidden when op ≠ layer_stack.

Post Processing

ParameterTypeDefaultDescription
Fold foldtoggleoffTake the absolute value of the result.
Complement complementtoggleoffReplace the result with 1 - x.
Clamp Minimum clamp_minfloat0Lower limit used when Use Clamp Min is on.
Use Clamp Min use_clamp_mintoggleoffApply Clamp Minimum.
Clamp Maximum clamp_maxfloat1Upper limit used when Use Clamp Max is on.
Use Clamp Max use_clamp_maxtoggleoffApply Clamp Maximum.
Clamp 0-1 clamptoggleonClamp the final result to 0-1.
ParameterTypeDefaultDescription
Output Layer out_layerstringmaskName of the result layer.

Compared with Houdini

The Per-Layer Blend Modes option follows Houdini's multiparm; here it is written as multi-line text. Per-layer Channel Mix, Light Direction, Blur and Layer Remap, and the post-process Remap, Amplitude, Center, Contrast, Bias, Gain and Gamma are not implemented; add separate COP nodes before or after if needed.


COP Premultiply (PCG)#

PCG_COPPremultiply · category PCG/cop · Houdini: Premultiply (COP)

Multiplies RGB by alpha, or divides it back out.

Premultiply scales the colour channels by alpha. Unpremultiply divides them back; where alpha is 0 the result is 0 instead of NaN.

Inputs

InputTypeDescription
copCOPIMAGEImage to convert.

Outputs

OutputTypeDescription
copCOPIMAGEConverted image.

Parameters

ParameterTypeDefaultDescription
Layer layerstringCLayer whose colour is converted.
Operation modemenuPremultiplyMultiply by alpha or divide by alpha. Options: Premultiply (premultiply), Unpremultiply (unpremultiply).
Alpha Layer alpha_layerstring(empty)Layer providing alpha. Empty uses the fourth channel of the layer itself.

COP Select (PCG)#

PCG_COPSelect · category PCG/cop · Houdini: Compare and Blend (COP)

Compares two layers per pixel and picks one, or blends them smoothly by the difference.

For each pixel, chooses A or B based on the comparison: A greater, A less, brighter or darker by luminance, closer to a Value, or a key layer exceeding a Value. With Softness above 0 the choice becomes a smooth blend based on the difference. Optionally the selection mask is also written.

Inputs

InputTypeDescription
copCOPIMAGEImage containing the A and B layers.

Outputs

OutputTypeDescription
copCOPIMAGEImage with the result layer and optional selection mask.

Parameters

ParameterTypeDefaultDescription
A Layer a_layerstringAFirst layer.
B Layer b_layerstringBSecond layer.
Compare opmenuA > BComparison used to choose between A and B. Options: A > B (a_greater), A < B (a_less), Brighter (Luminance) (brighter), Darker (Luminance) (darker), Closer to Value (closer_to_value), Key Layer > Value (mask).
Value valuefloat0.5Reference value for Closer to Value and Key Layer > Value. Hidden when op ≠ closer_to_value op ≠ mask.
Key Layer key_layerstring(empty)Layer compared against Value in Key Layer mode. Hidden when op ≠ mask.
Softness softnessfloat [0..]00 gives a hard switch; larger values blend smoothly according to the difference.
Output Layer out_layerstringresultName of the result layer.
Mask Output Layer mask_layerstringselect_maskName of the layer receiving the selection mask. Empty skips the mask.

COP Wipe (PCG)#

PCG_COPWipe · category PCG/cop · Houdini: Wipe (COP)

Transitions from image A to image B with a linear, radial, dissolve or crossfade wipe.

The transition amount T runs from 0 (only A) to 1 (only B). At exactly 0 and 1 the result is bit-identical to A and B. The modes:

  • Linear: a soft edge sweeps across the image in the direction of Angle.
  • Radial: a circle grows from Center.
  • Dissolve: each pixel switches at its own random threshold (seeded); larger softness blurs the threshold.
  • Crossfade: a plain blend.

If B has a different resolution than A it is resampled to A first; only the first channels shared by both layers are used. The result takes the resolution and other layers of A.

Inputs

InputTypeDescription
aCOPIMAGEImage shown at T = 0. Also defines the resolution of the result.
bCOPIMAGEImage shown at T = 1.

Outputs

OutputTypeDescription
copCOPIMAGEThe transitioned image.

Parameters

ParameterTypeDefaultDescription
Layer layerstringCLayer to transition, taken from both inputs.
Wipe Type modemenuLinearWipe pattern: Linear edge, Radial circle, Dissolve noise threshold, or Crossfade. Options: Linear (linear), Radial (radial), Dissolve (dissolve), Crossfade (crossfade).
Transition tfloat [0..1]0.5Transition amount. 0 gives A, 1 gives B.
Angle anglefloat [-360..360]0Linear mode: direction in degrees in which the edge moves. Hidden when mode ≠ linear.
Center centerstring0.5 0.5Radial mode: centre of the circle in UV (U and V, 0-1). Hidden when mode ≠ radial.
Softness softnessfloat [0..1]0.05Width of the soft transition (in UV for Linear and Radial; for Dissolve it controls how blurry the threshold is). Hidden when mode = crossfade.
Seed rand_seedint [0..]0Dissolve mode: seed of the random thresholds. Hidden when mode ≠ dissolve.
Output Layer out_layerstring(empty)Destination layer. Empty writes the result back to Layer.