Nodes/ComfyUI_RaykoStudio/๐ŸฆŠ RS Ref Encode
ComfyUI Node

๐ŸฆŠ RS Ref Encode

Stop hand-wiring reference latents into your edit-model workflows

By RaykosanยทCreated about a year agoยทUpdated about 20 hours agoยท 79
๐ŸฆŠ RS Ref Encode
  • positive
  • negative
  • pixels
  • vae
  • positive
  • negative

The name does honest work here: RS Ref Encode is "VAE Encode plus the reference-latent wiring" folded into one box. If you've ever built a Kontext, Klein, or Wan character-swap workflow by hand, you know the drill - encode your reference image to a latent, inject it into both the positive and negative conditioning under the reference_latents key, and only then does the model know who or what it's supposed to be editing. This node collapses that whole chain into a single drop-in, and it's a genuinely nice one.

Why you'd reach for it

Reference-latent conditioning is how in-context edit models work. Flux Kontext, Klein 9B, and the Wan 2.2 character-swap crowd all take a reference image this way, and people describe feeding references as a latent as "essentially a mini-LoRA without any training" - one clean way to hold identity or a scene across generations without training a thing. The older way to get an image into your conditioning is IP-Adapter, which uses a separate adapter model; reference latents skip the adapter entirely and hand the encoder output straight to the model. The manual equivalent is a three-step chain (VAE Encode, then set the latent into positive, then into negative). RS Ref Encode replaces all of it, and because it encodes your pixels exactly once and reuses that latent for both streams, it's also a bit kinder to your VRAM and your queue time than chaining nodes by hand.

How it works

It's refreshingly small, and the source backs up the README. The node takes your pixels, runs them through vae.encode, and - here's a detail worth knowing - if your image has an alpha channel it silently drops the 4th channel before encoding. It also handles the two return formats vae.encode() has produced across ComfyUI builds (a dict or a bare tensor), which is the kind of compatibility shim that usually comes from an author who's actually been burned by it. Then it uses ComfyUI's own conditioning_set_values(..., append=True) to stamp the latent into both conditioning streams under reference_latents and hands them back. No widgets, no presets, no config - it's deliberately a pure plumbing node.

The inputs and outputs that matter

All four inputs are required, and there's nothing else to touch:

  • positive (CONDITIONING) - your text conditioning, straight from CLIP Text Encode.
  • negative (CONDITIONING) - same, the negative side.
  • pixels (IMAGE) - the reference image. Feed it an RGBA PNG if you like; the alpha is stripped.
  • vae (VAE) - the VAE that matches your model.

Outputs are positive and negative (both CONDITIONING), which you wire into your sampler exactly like normal conditioning. Note there's no latent output here - if a workflow graph needs the reference latent as a separate input, grab the sibling RS Ref 2 Latent instead, which does the same job but also upscales your image to clean multiples of 64 and exposes the latent.

Installing it

Standard RaykoStudio fare. Via ComfyUI Manager, search ComfyUI_RaykoStudio, or:

cd ComfyUI/custom_nodes
git clone https://github.com/Raykosan/ComfyUI_RaykoStudio.git

then restart ComfyUI. No model files to download - your VAE comes from your checkpoint or VAE loader. The one thing to know: this is a dependency-heavy pack (opencv-python, pycairo, freetype-py, scipy, Pillow, torch), so Manager will pull those in even though this particular node only really needs torch. The heavy C-backed deps are there for the pack's image-editing nodes, not this one.

Where people get burned

The big one: reference_latents only does anything if the model you're feeding actually consumes it. On a plain SD 1.5 / SDXL / Flux txt2img graph this node is a silent no-op - it's for Kontext/Klein-class edit models and reference-based generation, not a general "make my output look like this image" tool. Expect IP-Adapter behavior here and you'll be confused.

Second, unlike Ref 2 Latent, this node does no resizing - it encodes at native resolution. Feed it a 1234ร—987 oddball and you're relying on the VAE to cope; keep references at model-friendly multiples of 8 (ideally 16 or 64) and watch VRAM on huge images. It's a newcomer to the pack (v0.41.0), so treat first-run behavior on your ComfyUI build with a touch of skepticism - but the encode-once design and the compatibility handling make it the one I reach for over hand-wiring the chain.

Category๐ŸฆŠ RaykoStudio

Inputs (4)

NameTypeDefaultDescription
positiveCONDITIONINGโ€”
negativeCONDITIONINGโ€”
pixelsIMAGEโ€”
vaeVAEโ€”

Outputs (2)

NameTypeDescription
positiveCONDITIONINGโ€”
negativeCONDITIONINGโ€”