ComfyUI-FuncAsTexture-CoiiNode Introduction
ComfyUI-FuncAsTexture-CoiiNode gives you a way to process images with mathematical rules inside a ComfyUI workflow. You can blend images by exact amounts, work with individual red, green, and blue channels, create masks, and build texture effects. Its main node lets you write a short NumPy formula; a collection of ready-to-use nodes provides common operations without requiring you to start with a blank formula.
The extension is useful when a blending mode does not make its calculation clear, or when you need an operation such as taking the brighter value from two images at each position. Instead of repeatedly adjusting a blend until it looks close, you can state the rule directly. For example, imga * 0.7 + imgb * 0.3 combines two images using 70% of the first and 30% of the second.
The author drew inspiration for the main node from the Custom node in the Unreal Engine Material Editor. You do not need to know Unreal Engine to use it; the connection is the idea of expressing an image effect as a calculation.
How ComfyUI-FuncAsTexture-CoiiNode Works
Think of an image as a grid of small color values. The extension applies a rule to those values and turns the result back into an image. A rule can combine two images, adjust a color channel, compare values against a threshold, or move the positions from which colors are sampled.
The main node accepts a multiline formula. In that formula, imga is the main image, while imgb and imgc are additional images you can use in calculations. You can also use number inputs named pfloat1 through pfloat3 and pint1 through pint2 to adjust a formula without rewriting it. The formula must assign its final output to result.
For example, this averages two images:
result = (imga + imgb) * 0.5
Changing the numbers changes the mix:
result = imga * 0.7 + imgb * 0.3
The first image is also split into imga_r, imga_g, and imga_b, so you can work on its red, green, and blue channels separately. The supplied makergb(r, g, b) function combines three channels into an image. This example creates a grayscale image using a different weight for each channel:
gray = 0.299 * imga_r + 0.587 * imga_g + 0.114 * imga_b
result = makergb(gray, gray, gray)
NumPy is available as np by default; you do not need to add import numpy as np to a formula. This makes functions such as np.where available for conditional effects. For instance, the following rule turns values above a threshold white and the rest black:
threshold = 0.5
result = np.where(imga > threshold, 1.0, 0.0)
The node converts the result into the image tensor format used for its output. By default, the output height and width follow imga. If imga is not connected, the default dimensions are 512 × 512. When combining images, check that their resolutions are compatible.
ComfyUI-FuncAsTexture-CoiiNode Features
Main Formula Node
The main node is the flexible starting point for custom effects:
| Input | What it does |
|---|---|
imga | Main image. It supplies imga_r, imga_g, and imga_b and normally determines the output size. |
imgb, imgc | Additional images for comparisons, blends, and conditional effects. If either is absent, the node uses zero-filled data for that input. |
pfloat1–pfloat3 | Optional decimal-number controls. They accept negative values and default to 0.0. |
pint1–pint2 | Optional whole-number controls. They accept negative values and default to 0. |
formula | Required multiline calculation. Assign the image or values you want to output to result. |
You can use the number controls as adjustable settings for an effect. A formula that uses pfloat1 as a blend weight, for example, can be tuned from the node input instead of edited each time. More advanced formulas can use NumPy mathematical functions, matrix calculations, and conditional expressions.
Ready-to-Use Calculation Nodes
These derived nodes provide examples of the main node’s calculations. They expose only the inputs and parameter ranges needed for their particular effect, making them simpler to use directly. You can also copy their formula text into the main node to study or adapt it.
| Node | What it does and when it may help |
|---|---|
| Subtraction | Subtracts one image from another, useful for revealing differences. |
| Multiply | Multiplies corresponding image values, useful for combining an image with another image or mask. |
| Divided | Divides corresponding values of two images. |
| Max | Keeps the larger value at each corresponding position in two images. |
| Min | Keeps the smaller value at each corresponding position. |
| Dot | Calculates a dot product along the last image axis, combining channel values in a different way from an ordinary blend. |
| Distance | Calculates the Euclidean distance between corresponding image values, useful for measuring how different they are. |
| Power | Raises values in imga to the exponent set by pfloat1. Changing the exponent changes how the values are distributed. |
| HueShift | Shifts the hue of imga by the angle set with pfloat1. |
| Panner | Translates imga horizontally and vertically using pint1 and pint2. |
| Outline | Shifts imga left, right, up, and down by pint1 pixels, averages those shifted images, and subtracts the original to produce an outline effect. |
| Lerp | Interpolates between imga and imgb using pfloat1 as the blend control. |
| Clamp | Restricts image values to the range set by pfloat1 and pfloat2. |
| Ceil | Rounds each image value upward. |
| 1 - x | Subtracts each value in imga from one, producing an inverted-value effect. |
| Sine | Applies the sine function to each value in imga. |
| DDX | Calculates a difference in the horizontal direction, which can help emphasize horizontal changes in an image. |
| Contant3Vector(Color) | Creates a solid RGB color image from constant values. |
| if (FuncAsTexture) | Compares imga with pfloat1, then selects values from imgb or imgc according to the comparison. |
| Chroma_Key_Alpha | Creates a green-screen keying effect using an HSV green range and a softened mask. |
| Desaturation | Desaturates imga using the mean of its three color channels. |
Texture Expansion Nodes
These nodes focus on texture coordinates and transformations. UV coordinates are a way of describing where to look on a texture: instead of changing a color directly, a UV-based effect changes which position supplies that color.
| Node | What it does |
|---|---|
| UV Coordinate Generator | Creates a UV texture that can guide coordinate-based effects. |
| Texture Sampler | Samples a texture according to UV coordinates, allowing a coordinate map to guide a transformation. |
| Inverse UV Map Generator | Attempts to derive an inverse-transformed UV map from an input UV map. It is a beta feature and is not suitable for images with too many pixels. |
| Rotator | Rotates a texture map. |
Troubleshooting ComfyUI-FuncAsTexture-CoiiNode
A formula does not produce the expected output
- Check that the formula assigns its final value to
result. - Check that every image or parameter name in the formula matches an available input, such as
imga,pfloat1, orimga_r. - Test a short formula, such as
result = imga, before adding more calculations. This helps identify which step causes the problem.
A calculation using two images fails
- Compare the resolutions of the connected images.
- Make the resolutions compatible before applying an operation that combines their values.
- Try the calculation again with a simple formula, such as
result = (imga + imgb) * 0.5.
The output size is not what you expected
Check whether imga is connected. The output normally follows its height and width; without it, the default dimensions are 512 × 512.
An unconnected image changes the result
An absent imgb or imgc is replaced with zero-filled data. Connect an image if the intended calculation depends on its colors. For example, averaging imga with an unconnected imgb will not give the same result as averaging two connected images.
A derived node is close to the effect you want, but not quite right
Use its existing controls first. If you need a different rule, copy the derived node’s formula into the main node and adjust the calculation there.
Frequently Asked Questions
Do I need to write Python to use the extension?
No. The derived nodes offer ready-to-use operations. The main formula node is available when you want a more specific effect.
Do I need to import NumPy in a formula?
No. It is already available as np.
Can I edit individual color channels?
Yes. Use imga_r, imga_g, and imga_b, then combine channels with makergb(r, g, b) when needed.
Is the Inverse UV Map Generator appropriate for large images?
The original documentation describes it as a beta feature and says it is not suitable for images with too many pixels. Start with a smaller image when exploring it.
Learn More about ComfyUI-FuncAsTexture-CoiiNode
- Extension repository and English README: See the source documentation and examples.
- Chinese README: An alternative-language reference.
- NumPy mathematical functions (https://numpy.org/doc/stable/reference/routines.math.html): Explore operations you can use when building formulas.
- NumPy statistical functions (https://numpy.org/doc/stable/reference/routines.statistics.html): Learn about calculations that summarize groups of values.
- NumPy linear algebra (https://numpy.org/doc/stable/reference/routines.linalg.html): A reference for more advanced array and matrix operations.
- OpenCV image-processing tutorials (https://docs.opencv.org/4.x/d2/d96/tutorial_py_table_of_contents_imgproc.html): Background reading on image-processing ideas and effects.
