if (FuncAsTexture)
A ternary operator for images — pick between two textures with a threshold
- imga
- imgb
- imgc
- IMAGE
Every programming language has an if/else, and this node is the image version: if imga ≥ a threshold, output imgb; otherwise output imgc. The display name is literally if (FuncAsTexture), in the same spirit as Unreal's material node that shares the name. It's a per-pixel conditional, which means the "decision" happens independently at every pixel - a mask-driven switch between two images.
The mechanism is a two-way blend computed with weights that are never fractional. The formula:
lessweight = np.floor(1 - imga + pfloat1)
largeweight = np.ceil(imga - pfloat1)
result = imgb * largeweight + imgc * lessweight
np.floor and np.ceil snap the weights to 0 or 1, so there's no smooth gradient at the boundary - each pixel takes fully from one image or the other. imga is the decision image (bright = take imgb, dark = take imgc), and pfloat1 is the threshold it's compared against, default 0.5. The tooltips spell it out: imgb is "Output 1, when imga ≥ pfloat1," imgc is "Output 2, when imga < pfloat1."
Where you'll use it
- Mask-driven compositing. You have a mask and two content images. Feed the mask into
imga, set the threshold, and the output is whichever content the mask selects, per pixel. This is a hard-edged (mask-based) switch - the pack's Lerp would do the soft version, but this one is crisp by design. - Thresholding anything. Take a distance map, set the threshold, and turn it into a binary region selector.
- Chained conditionals. Since the output is an image, you can feed one ifFunction's output into another's
imga- building nested if/else ladders that would be a nightmare in any other UI.
Inputs and outputs
formula- the conditional script, pre-filled and editable.imga- the decision image (reference for output resolution).imgb- chosen whereimga ≥ pfloat1.imgc- chosen whereimga < pfloat1.pfloat1- the threshold, 0–1, default 0.5.
One IMAGE output.
Install
ComfyUI Manager → search "FuncAsTexture", or:
cd ComfyUI/custom_nodes
git clone https://github.com/CoiiChan/ComfyUI-FuncAsTexture-CoiiNode
# restart ComfyUI
No models, no requirements.txt. Category: FunctionAsTexture.
Gotchas
- The switch is per-pixel and hard. There's no anti-aliasing at the boundary - the transition is a one-pixel step. If you want a feathered edge, soften the decision image (or use a lerp formula instead).
- The threshold compares against
imga's value at each pixel, including its color channels separately ifimgais RGB. A gray decision image behaves as you expect; a colored one will make different channels switch at different times. Feed it grayscale unless you want that. imgadefines the output resolution - make sure your two content images match it, or NumPy will complain.
It's the pack's decision node, and it's the one that makes "mask selects content" a single node instead of a graph. For anything where the output needs to be one of two things at every pixel - not a blend - this is the tool.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| formula | STRING | #if function info: if imga < constant pfloat1: use imgc else: use imgb #equalthreshold = 0.01 #lessweight = np.floor(1- imga + pfloat1- equalthreshold) lessweight = np.floor(1- imga + pfloat1) largeweight = np.ceil(imga - pfloat1) result = imgb*largeweight + imgc*lessweight | — |
| imgaopt | IMAGE | Optional ,Reference size ,Default =(1,512,512,3) | |
| imgbopt | IMAGE | Defined OutPut1,When imga >= constant pfloat1 | |
| imgcopt | IMAGE | Defined OutPut2,When imga < constant pfloat1 | |
| pfloat1opt | FLOAT | 0.500–1 | imga compare with constant pfloat1. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |