Extensions/Krea2-UniDepth
ComfyUI Extension

Krea2-UniDepth

Krea2-UniDepth native functional depth and image-reference conditioning.

By cicalooo·Created 18 days ago·Updated 17 days ago· 1
cicalooo/ComfyUI-Krea2-UniDepth
Nodes
On cloudLocal install
Stars1
Updated17 days ago
Readme

Krea2-UniDepth

Krea2-UniDepth provides native functional depth and image-reference conditioning for Krea2 in ComfyUI. It consumes ready-made depth maps, provides exact reference geometry, adjustable LoRA sections, and reference-image editing without replacing Krea2's model forward.

Depth model download

Download the Krea2-UniDepth depth model from Hugging Face

Place the downloaded .safetensors file in your configured ComfyUI LoRA directory, for example:

ComfyUI/models/loras/krea2/

Select any LoRA in the Krea2-UniDepth Functional LoRA Loader. For depth generation, use a LoRA trained on depth. The loader does not enforce a filename or reject an incompatible selection; its patch report will show when zero adapters mapped.

Requirements

  • ComfyUI 0.29.2 or newer with native Krea2 reference-latent support.
  • Krea2 FP8 base weights are recommended.
  • Native Krea2 INT8 base weights are the supported minimum for depth and edit functions.
  • Krea2 CLIP loaded with type krea2 and a complete Qwen3-VL 4B text encoder.
  • Qwen Image VAE.
  • A functional LoRA trained on depth (the linked model is the tested option).

No additional Python packages are required.

Installation

Copy this repository to:

ComfyUI/custom_nodes/ComfyUI-Krea2-UniDepth

Restart ComfyUI. Five nodes appear in the Krea2-UniDepth category.

Recommended depth workflow

UNETLoader (Krea2 FP8 recommended)
  -> Krea2-UniDepth Functional LoRA Loader
  -> KSampler.model

Depth Anything or another depth preprocessor
  -> Krea2-UniDepth Conditioning.depth_image

CLIPLoader (type: krea2)
  -> CLIP Text Encode (positive and negative)
  -> Krea2-UniDepth Conditioning
  -> KSampler positive / negative / latent_image

Feed the completed depth map directly to Conditioning. It is preserved as supplied except for the selected geometry fit, then VAE-encoded and attached as clean timestep-zero reference tokens. If a map needs correction, enable the advanced built-in calibration controls; no extra node is required.

Conditioning also accepts an optional source image and an ordered references stack. These are fitted to the target, VAE-encoded, and appended after the depth map in Krea2's native clean-reference path. This can retain source composition and appearance while normal CLIP Text Encode supplies the prompt. The direct image is the convenient single-reference input; use Reference Stack for multiple images or per-image fit settings.

Recommended starting settings

  • 8 steps, CFG 1, Euler, simple scheduler.
  • LoRA base and every section/component strength at 1.0.
  • Built-in calibration off for an already prepared map.
  • Reference range 0.0-1.0.

Prompt-led depth outpainting

Krea2-UniDepth can produce useful prompt-led outpainting without a dedicated positional outpainting path:

  • set the UniDepth LoRA strength to 0.9;
  • add padding around the depth guide to create unconstrained canvas - letterbox is one convenient option, but other padding methods may also work;
  • prompt the complete intended scene and make the continuation spatially coherent with the known composition.

The padded area gives the model unconstrained canvas beyond the preserved depth composition, while the reduced LoRA strength leaves more freedom for prompt-driven continuation. This is empirical rather than registered or mask-aware outpainting, so consistency still depends on the source composition, padding, prompt, and seed.

Example workflows

  • workflows/krea2_unidepth_depth.json
  • workflows/krea2_unidepth_edit.json

The depth workflow is pre-wired through the section-aware LoRA loader. Select equivalent model, encoder, VAE, and LoRA filenames if your configured names differ.

<details> <summary><strong>What Krea2-UniDepth adds</strong></summary>
  • Robust per-image percentile calibration so outliers do not flatten the useful depth range.
  • Gamma and explicit near/far polarity control.
  • Optional edge-preserving denoising before VAE encoding.
  • Exact target-size fitting in pixel space with no latent interpolation.
  • Independent LoRA strengths for early, middle, late, and text-fusion sections.
  • Independent attention and MLP adapter strengths.
  • Exact conditioning start/end ranges.
  • Optional direct and stacked image-reference inputs on the main Conditioning node.
  • Ordered multi-reference edit conditioning.

All LoRA controls at 1.0 reproduce ordinary native model-only LoRA application and are the correct baseline before tuning.

</details> <details> <summary><strong>Depth calibration and tuning</strong></summary>

Change one family at a time on a fixed seed:

  1. Confirm polarity. If depth appears reversed, use invert.
  2. Adjust percentile clipping. Try 0.5/99.5 for gentle calibration or 2/98 for stronger contrast recovery.
  3. Adjust gamma. Below 1.0 lifts darker depth levels; above 1.0 suppresses them.
  4. For noisy or banded maps, try smoothing radius 2-4, strength 0.25-0.5, epsilon 0.005-0.02.
  5. Adjust end_percent. Approximately 0.65-0.85 can preserve structure while allowing more late texture freedom.
  6. Only then tune LoRA sections in small increments, normally 0.05-0.15.

Layer controls are multipliers:

effective strength = base strength x section strength x component strength

For example, base 1.0, early 1.1, and attention 0.9 applies early attention adapters at 0.99.

</details> <details> <summary><strong>Geometry options</strong></summary>
  • center_crop: preserves aspect ratio, fills the target, then crops centrally.
  • letterbox: preserves the full map and pads to the target aspect ratio.
  • stretch: forces the map to target geometry; best reserved for closely matched aspect ratios or intentional distortion.

If target_latent is connected, it determines output geometry. Otherwise Krea2-UniDepth creates a native image-like Krea2 latent shaped B,C,1,H,W. Connected 4D latents are promoted automatically.

</details> <details> <summary><strong>Reference-image edit mode</strong></summary>
LoadImage -> Krea2-UniDepth Reference Stack
          -> Krea2-UniDepth Apply References

CLIP Text Encode -------------> Apply References
EmptySD3LatentImage -----------> Apply References.target_latent
VAELoader ---------------------> Apply References.vae

Select edit / shared timestep when an edit LoRA was trained with its source reference on the live diffusion timestep. Select depth / clean t=0 for functional LoRAs trained with clean reference tokens.

The reference stack is ordered and chainable. Each reference is fitted and encoded independently at the final target geometry.

</details> <details> <summary><strong>Node reference</strong></summary>
  • Krea2-UniDepth Functional LoRA Loader - native ComfyUI model cloning and patching with section/component multipliers and a patch report.
  • Krea2-UniDepth Calibrate Guide - legacy/standalone calibration; the same controls are built into Conditioning.
  • Krea2-UniDepth Conditioning - exact geometry, VAE encoding, clean timestep-zero reference conditioning, and target latent creation.
  • Krea2-UniDepth Reference Stack - typed ordered references for edit workflows.
  • Krea2-UniDepth Apply References - native clean- or shared-timestep reference application.
</details> <details> <summary><strong>Implementation notes</strong></summary>

The project leaves model execution, quantized operations, attention, memory management, LoRA patching, and offloading with ComfyUI. Its LoRA cache is module-scoped for compatibility with locked V3 node clones.

The validated functional depth adapter contains 512 BF16 tensors at rank 128 and covers all 28 Krea2 image-transformer blocks plus both layerwise and both refiner text-fusion blocks.

</details>

License

Krea2-UniDepth code, documentation, tests, and workflows are licensed under the Apache License 2.0. Model weights are distributed separately and retain their respective licenses.