Nodes/ComfyUI-FuncAsTexture-CoiiNode/Inverse UV Map Generator
ComfyUI Node

Inverse UV Map Generator

Invert a UV map in ComfyUI — if you can wait for it

By CoiiChan·Created about a year ago·Updated about a year ago· 2
Inverse UV Map Generator
  • uvmap
  • IMAGE
  • MASK
fill_methodnone

This is the pack's weirdest node and probably the reason you googled it: it takes a UV map and computes its inverse. If you're not doing texture work, that sentence means nothing - here's what's actually going on.

A UV map is an image where the red channel holds a U coordinate (0–1 across width) and green holds a V coordinate (0–1 down height). It tells a sampler "for each output pixel, which source pixel should I show?" That's a forward mapping. The inverse question - "which output pixel wants to sample this source pixel?" - is harder, and that's the problem this node solves. In 3D texturing you meet it constantly: you've warped a UV layout, and you need the unwarped version back so you can bake or reproject.

How it works

The node reads the R and G channels of your uvmap, scales them to pixel coordinates, and writes the original x / (width-1) and y / (height-1) values into the inverse image at the mapped location. Read the source and you'll see the honest cost of that: it's a plain Python double loop over every pixel (for y in range(height): for x in range(width):). No vectorization, no GPU trickery. The author flags this as beta and warns it's "not suitable for images with too many pixels" - that's not modesty, that's a 1024×1024 map meaning roughly a million Python iterations.

The fill_method enum gives you two ways to handle the holes that inverse mapping leaves behind:

  • none - sparse write, and unassigned pixels keep a default value (R and G set to 1).
  • sparse - also writes a 2×2 block of neighboring pixels per source, then runs a nearest-neighbor fill that propagates values outward with a 3×3 convolution until no zeros remain. Slower, but you get a mostly-solid map instead of a dotted one.

Inputs and outputs

  • uvmap - an IMAGE where the R/G channels are your U/V coordinates. It's the same kind of output the pack's UV Coordinate Generator produces, so you can feed one into this node.
  • fill_method - none or sparse.

Outputs are the interesting part: it returns IMAGE and MASK. The mask is built from the red channel of the filled map, so it tells you which regions actually got a valid inverse coordinate and which stayed at the default. If you're compositing the inverted map onto something, mask out the holes rather than letting default values leak in.

Install

ComfyUI Manager → search "FuncAsTexture", or:

cd ComfyUI/custom_nodes
git clone https://github.com/CoiiChan/ComfyUI-FuncAsTexture-CoiiNode
# restart ComfyUI

No models, no extra dependencies - just NumPy/PyTorch/Pillow, which ComfyUI already has.

Realistic expectations

  • Keep it small. 256×256 is comfortable; 512×512 starts to feel like a coffee break; the author explicitly tells you not to push it. Use sparse only if you need the coverage, because it does more work per pixel plus the conv-fill loop.
  • You won't perfectly undo a resample. If your UV map came out of a bilinear/bicubic sampler, the coordinates got rounded to integers on the way in - a few pixels will be off by one and you'll see thin seams. That's an inherent quantization loss, not a bug you can tune away.
  • The default-filled regions read as [1, 1, 0] (that bright magenta-ish R=G=1). If you preview the output and see flat solid areas, those aren't valid coordinates - they're the unmapped background, which is exactly what the MASK output is for.

The inverse-UV use case is niche, and the reference implementation's slowness keeps it niche. But if you're building texture-mapping workflows in ComfyUI rather than exporting to a real DCC tool, this is the only node that does the inverse step at all - and it does it with a mask you can actually use.

CategoryFunctionAsTexture

Inputs (2)

NameTypeDefaultDescription
uvmapIMAGE
fill_methodCOMBOnone2 options: none, sparse

Outputs (2)

NameTypeDescription
IMAGEIMAGE
MASKMASK