Nodes/comfyui-anima-toolkit/TK Latent 选择/合成
ComfyUI Node

TK Latent 选择/合成

Bounce between text2img, img2img and reference stacks without rewiring

By Ararararararaki·Created 3 months ago·Updated about 21 hours ago· 22
TK Latent 选择/合成
  • latent_1
  • latent_2
  • latent_3
  • latent_4
  • latent_5
  • latent_6
  • latent
  • denoise
  • index
  • summary
mode选择一路
select1
base1
layout
denoise_11.00
denoise_20.60
denoise_31.00
denoise_41.00
denoise_51.00
denoise_61.00

Here's the annoyance this node kills. You have one Anima graph. Sometimes it starts from an empty latent at denoise 1.0, sometimes from a VAEEncoded image at 0.6, sometimes from a reference you're compositing behind a subject. Switching between those normally means dragging a wire to the sampler's latent input and remembering that denoise is a widget, not a wire - so the first time you forget, you re-roll your source image from pure noise and wonder why img2img turned into txt2img with extra steps.

TK Latent 选择/合成 (AnimaTKLatentSwitch) puts six latent inputs behind one selector and ships the matching denoise out with the chosen latent, so the two always change together. The mode also lives inside the node, so the whole switch is one dropdown instead of a group of muted branches.

Why this isn't just core LatentComposite

Because core LatentComposite is broken on Anima latents. It treats shape[2] and shape[3] as height and width - correct for SD 1.5/SDXL's 4D [B, C, H, W], wrong for Anima, which rides Cosmos-Predict2 and uses 5D [B, C, T, H, W] with T=1. So the composite reads the frame axis as your height axis and slices the wrong dimensions or throws a shape mismatch. This node implements its own paste against the last two dimensions, so it works on both 4D and 5D latents. That's the whole reason it exists rather than a couple of core nodes.

How it works

Two modes, chosen with the required mode dropdown. 选择一路 outputs one of the six routed latents. 合成叠加 takes one route as the background and pastes the other connected routes on top of it, with optional per-layer offsets and edge feathering - a background plus a subject works with zero configuration, because any layer you don't describe in the layout is centred for you.

The denoise side is the useful trick. Each route has its own denoise_1denoise_6, and whichever route wins, its value comes out of the denoise output. The shipped defaults already encode the obvious pairing: route 1 is 1.0 (empty latent, text2img), route 2 is 0.6 (VAEEncode, img2img), routes 3–6 are 1.0. Range is 0–1, step 0.05.

Four outputs: latent, denoise, index (which route actually won, 1–6) and summary (a human-readable line telling you exactly what happened). Wire latent to the sampler's latent input, and wire denoise after right-clicking the sampler's denoise widget and choosing Convert widget to input - that's the step people skip. index and summary are for logging, filename patterns, or just a note node you can read when the graph does something you didn't expect.

For composite mode, base picks the background route and layout takes one line per layer:

2 = 0, -128, 8

That's route = x, y, feather in pixels, the same units native LatentComposite uses. Negative values and off-canvas positions are fine - anything out of frame is clipped, and a layer that lands entirely outside returns the background untouched. Feather is a linear ramp on all four edges. If you skip a layer it gets centred automatically, which is what makes the "background + one subject" case configurable in zero keystrokes.

Batch sizes are reconciled for you: a single-image layer is repeated up to the background's batch, extras are truncated or cycled.

What to watch out for

There is no lazy evaluation. All six routes that have something wired into them get executed, even the ones you didn't select. If route 4 is fed by a second sampler, that sampler runs anyway - this is the one real trap, and it's in the node's own documentation. Keep the expensive branches on a muted group (Ctrl+B) or unplug them; don't expect the selector to skip work.

Selection falls back silently. If select points at an empty socket, the node uses the first connected route instead of erroring, and tells you so in summary. Only six empty sockets raise an error. Read the summary before you assume the selector is broken.

Layout units are pixels, not latent cells. The node divides by 8 internally for the VAE's spatial compression, same as the core node, so paste pixel numbers you'd use elsewhere and don't pre-divide.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/Ararararararaki/comfyui-anima-toolkit

Restart ComfyUI. In ComfyUI Manager search TK Toolkit (registry id anima-toolkit). The node lands under TKTK/latent. No models, no extra Python packages - it uses the torch and numpy that ComfyUI already ships, and the pack's aiohttp/requests requirements are for its web panel rather than this node.

Where it earns its place on Anima

Anima's default output is soft, and the fix the community actually converged on is a latent upscale between two samplers - 1.25× with denoise in the 0.25–0.35 range is the most-quoted version, and it beat doing the same thing on a decoded image in both quality and speed. Once you're running two passes you're running two latents, and the moment you also want an img2img branch or a composited reference you're at three or four. A selector that carries the denoise with it is a fairly small thing to ask of a graph like that.

CategoryTK/latent

Inputs (16)

NameTypeDefaultDescription
modeCOMBO选择一路选择一路:六路选一输出;合成叠加:以 base 为背景,其余已连接的路叠上去。
selectINT11–6选择模式:输出第几路 latent(该路没接线时回落到第一个已连接的)。
baseINT11–6合成模式:第几路当背景(其余已连接的路叠在它上面)。
layoutSTRING合成模式的层偏移,例如 `2 = 0, -128, 8`。没写的层居中叠加。
latent_1optLATENT第 1 路 latent(可留空)。
latent_2optLATENT第 2 路 latent(可留空)。
latent_3optLATENT第 3 路 latent(可留空)。
latent_4optLATENT第 4 路 latent(可留空)。
latent_5optLATENT第 5 路 latent(可留空)。
latent_6optLATENT第 6 路 latent(可留空)。
denoise_1optFLOAT1.000–1选中/作为背景的是第 1 路时,denoise 输出这个值。
denoise_2optFLOAT0.600–1选中/作为背景的是第 2 路时,denoise 输出这个值。
denoise_3optFLOAT1.000–1选中/作为背景的是第 3 路时,denoise 输出这个值。
denoise_4optFLOAT1.000–1选中/作为背景的是第 4 路时,denoise 输出这个值。
denoise_5optFLOAT1.000–1选中/作为背景的是第 5 路时,denoise 输出这个值。
denoise_6optFLOAT1.000–1选中/作为背景的是第 6 路时,denoise 输出这个值。

Outputs (4)

NameTypeDescription
latentLATENT
denoiseFLOAT
indexINT
summarySTRING