ComfyUI Extension: WAS Affine
Apply AFFINE noise transforms to latent space to improve image quality, especially with light loras.
Custom Nodes (0)
README

AFFINE
Adaptive Field Filtering by Intermittent Noise Enhancement
AFFINE is a comprehensive ComfyUI node suite that performs sparse Adaptive Field Filtering by Intermittent Noise Enhancement in latent space to steer diffusion results during sampling.
It works by applying controlled scale and bias (z' = scale * z + bias) to masked regions of the latent tensor, enabling precise control over brightness, contrast, and detail enhancement without collapsing noise structure.
The suite includes:
- Core Affine Nodes - Basic latent space transformations
- Integrated Samplers - KSampler and Custom Sampling with built-in affine scheduling
- Ultimate SD Upscaler Ports - Tiled upscaling with affine enhancement
- Pattern Noise Generation - AFFINE augmented random noise for custom sampling
- Modular Options System - Granular control over all parameters (also a super options node for the adventurous)
Examples
[โถ๏ธ] WAN Example
[โถ๏ธ] 720p -> 2k Example
Things to take note of:
- The background rock quality is improved.
- The trees and brush look more naturally dispersed.
- Roads are more realistic
- The foreground detail is essentially better preserved.
- The overall contrast is reduced.
๐ง How it works (ELI5)
- Controlled enhancement: Apply scale and bias transforms to specific regions defined by procedural masks.
- Pattern-based masking: Choose from 20+ patterns including Perlin noise, spectral noise types, geometric patterns, and content-aware masks.
- Temporal consistency: Static or per-frame mask generation for stable video processing.
- External gating: Use custom mask images to limit where effects are applied.
- Modular configuration: Mix and match common options with pattern-specific parameters.
- Integrated workflows: Built-in samplers handle scheduling automatically, or use manual latent transforms between sampling passes.
The core transformation: z' = scale * z + bias where the mask determines the blend between original and transformed values.
โจ Why AFFINE?
- Improves Quality โ Enhance detail in light LoRA outputs or tame overly contrasted/burned results from speed-boosting LoRAs.
- Works in latent space โ Avoids costly VAE decode/encode cycles and raster-space artifacts.
- Sparse control โ Apply adjustments selectively using sophisticated mask patterns.
- Stable video โ Temporal modes maintain consistency or controlled variation across frames.
- Flexible integration โ Use standalone transforms, integrated samplers, or tiled upscaling workflows.
- Advanced patterns โ 20+ mask types from simple geometric to complex spectral and content-aware patterns.
- Ultimate SD Upscaler compatibility โ Tiled processing with world-aligned noise and affine enhancement.
๐ง Workflow Options
Option 1: Manual Latent Transform (Classic)
- Run KSampler Advanced or Custom Sampling for high-noise steps
- Apply Latent Affine or Latent Affine Simple
- Resume with second sampler for low-noise steps
Option 2: Integrated Samplers
- Use KSampler Affine or KSampler Affine Advanced for automatic scheduling
- Use Custom Sampler Affine Advanced for custom sampling workflows
- Configure affine schedule, interval, and pattern parameters directly
Option 3: Tiled Upscaling
- Use Ultimate Affine KSampler - USDU nodes for large image processing
- Combines upscaling, tiling, and affine enhancement in one step
- Supports custom samplers and sigma schedules
๐ Node Reference
Core Affine Nodes
Latent Affine
The main affine transformation node with full configurability.
Inputs:
latentโ Input latent tensorscaleโ Multiplicative factor (1.0 = no change, <1 darkens, >1 brightens)biasโ Additive offset (-2.0 to 2.0)patternโ Mask pattern (20+ options including procedural, spectral, and content-aware)temporal_modeโstaticorper_framefor videoseedโ Random seed for procedural patternsexternal_maskโ Optional IMAGE input for custom maskingoptionsโ Base options DICT (use WASLatentAffineCommonOptions)noise_optionsโ Pattern-specific options DICT
Returns:
latentโ Transformed latentmaskโ Generated mask for visualization
Latent Affine Simple
Streamlined version with auto-tuned parameters for quick results.
Inputs:
latentโ Input latentscaleโ Multiplicative gain (0.95-0.98 for subtle darkening)noise_patternโ Auto-tuned mask patternseedโ Random seedtemporal_modeโstaticorper_frameframe_seed_strideโ Seed increment per frame
Returns:
latentโ Adjusted latentmaskโ Generated mask
Integrated Samplers
KSampler Affine / KSampler Affine Advanced
Drop-in replacements for standard KSamplers with built-in affine scheduling.
Key Parameters:
affine_intervalโ Apply affine every N stepsmax_scale/max_biasโ Peak transformation valuesaffine_scheduleโ WASAffineScheduleOptions DICT for timing curveaffine_seed/affine_seed_incrementโ Seed management- All standard KSampler parameters
Custom Sampler Affine Advanced
Advanced custom sampling with affine integration.
Inputs:
noise/guider/sampler/sigmasโ Standard custom sampling inputslatent_imageโ Input latent- Affine parameters (same as KSampler variants)
Returns:
outputโ Final latentdenoised_outputโ Denoised latent
Ultimate SD Upscaler Ports
Ultimate Affine KSampler - USDU
Full upscaling with model-based upscaling and affine enhancement.
Key Features:
upscale_model/upscale_factorโ Pre-upscale configuration before tiling.- Tiling parameters โ
tile_width,tile_height,tile_padding,mask_blur. tiled_decodeโ Uses ComfyUI's built-in VAE tiled decode (compression-aware) to reduce VRAM peaks for large images/videos.- Batching controls โ
batch_sizefor processing the IMAGE batch in chunks;merge_frames_in_batchto merge [B,F,H,W,C] decodes into [B*F,H,W,C] for safe concatenation. - Noise determinism โ
deterministic_noiseandglobal_noise_modeto make outputs batching-invariant and ignore NOISE input if desired. - Cross-batch blending โ
overlap_blend_countandoverlap_blend_curveto softly crossfade at batch boundaries without dropping frames. - Full affine parameter set โ
affine_interval,max_scale,max_bias,pattern,affine_seed,affine_seed_increment,affine_schedule, and optionalexternal_maskgating withoptions/noise_options.
Ultimate Affine KSampler (No Upscale) - USDU
Tiled processing without pre-upscaling.
Ultimate Affine KSampler (Custom) - USDU
Supports custom samplers and sigma schedules via custom_sampler and custom_sigmas while keeping the same tiling/affine controls.
Advanced: Tiled Decode Parameters
When tiled_decode is enabled, you can fine-tune the VAE tiled decode behavior:
tiled_tile_sizeโ Target output tile size (in pixels, pre-compression). Larger is fewer tiles (faster) but higher VRAM peaks.tiled_overlapโ Output-space overlap (in pixels, pre-compression). Higher overlap improves tile blending but increases work.tiled_temporal_sizeโ Temporal window for video decode (frames, pre-compression). 0 disables temporal tiling.tiled_temporal_overlapโ Temporal overlap in frames (pre-compression). Helps blend across temporal windows.
Notes:
- Parameters are adjusted automatically using the VAEโs spatial/temporal compression so the decode receives latent-space
tile_x,tile_y, andoverlap. - Sanity checks ensure
overlap <= tile_size/4andtemporal_overlap <= temporal_size/2.
Batch Join Smoothing and Determinism
merge_frames_in_batchโ ComfyUI IMAGE tensors are 4D[B,H,W,C]by convention. This option only applies when a decoder returns a temporal IMAGE tensor[B,F,H,W,C](e.g., some tiled temporal VAE decodes). In that case, frames are flattened to[B*F,H,W,C]so batches with different frame counts can be concatenated safely. Has no effect for standard 4D images.overlap_blend_count/overlap_blend_curveโ Crossfade the last K images of a batch into the first K of the next batch at concatenation time (no frame drops). Curves:cosine(smooth) orlinear.deterministic_noiseโ Generate local noise with per-item seeds to make results independent of batch size.global_noise_modeโ Force deterministic noise for the entire run (ignores NOISE input) for strict batching invariance.
Pattern Noise Generation
Affine Pattern Noise
Generates structured noise by augmenting base ComfyUI noise with procedural patterns.
Inputs:
patternโ Noise pattern typeseedโ Random seedaffine_scaleโ Pattern amplitude multipliernormalizeโ Center and scale patternaffine_biasโ Additive biasoptions/noise_optionsโ Pattern parameters
Returns:
noiseโ Structured noise generator
๐จ Available Patterns
Spectral Noise Types
- white_noise โ Uniform frequency spectrum
- pink_noise โ 1/f frequency falloff (natural)
- brown_noise / red_noise โ 1/fยฒ falloff (warmer)
- blue_noise โ High-frequency emphasis
- violet_noise / purple_noise โ fยฒ emphasis (harsh)
- green_noise โ Mid-frequency band-pass
- black_noise โ Sparse narrowband spectrum
Geometric Patterns
- checker โ Checkerboard tiles
- bayer โ Ordered dithering matrix
- solid โ Constant alpha mask
Procedural Patterns
- perlin โ Smooth fractal noise (organic)
- worley_edges โ Cellular noise emphasizing edges
- poisson_blue_mask โ Blue-noise Poisson-disk distance field
- cross_hatch โ Oriented gratings and cross-hatch
- tile_oriented_lines โ Per-tile oriented lines
- dot_screen_jitter โ Halftone dots with jitter
- velvet_noise โ Sparse high-frequency impulses
Frequency Domain
- ring_noise โ Narrow annulus in frequency domain
- highpass_white โ High-pass filtered white noise
Content-Aware (from latent)
- detail_region โ High texture/variance areas
- smooth_region โ Low detail areas
- edges_sobel โ Sobel edge detection
- edges_laplacian โ Laplacian edge detection
External
- external_mask โ Use provided IMAGE directly
๐ง Options System
Common Options (WASLatentAffineCommonOptions)
Base parameters that apply to all patterns:
- mask_strength โ Scales mask intensity (0.0-2.0)
- threshold โ Binarize mask if > 0 (0.0-1.0)
- invert_mask โ Invert after threshold/blur
- blur_ksize / blur_sigma โ Gaussian blur for soft edges
- clamp / clamp_min / clamp_max โ Output value clamping
- frame_seed_stride โ Seed increment per frame (temporal mode)
- compute_device โ Where to generate masks (auto/cuda/cpu)
- sharpen_enable / sharpen_sigma / sharpen_amount โ Unsharp masking
Pattern-Specific Options
Each pattern type has dedicated option nodes:
WASPerlinOptions
perlin_scaleโ Base feature size (larger = smoother)perlin_octavesโ Number of octaves (1-8)perlin_persistenceโ Amplitude falloff per octaveperlin_lacunarityโ Frequency multiplier per octave
WASWorleyEdgesOptions
worley_points_per_kpxโ Cell density per 1000 pixelsworley_metricโ Distance metric (L2/L1)worley_edge_sharpnessโ Edge emphasis exponent
WASPoissonBlueOptions
poisson_radius_pxโ Minimum dot spacingpoisson_softnessโ Distance field smoothing
WASCrossHatchOptions
hatch_freq_cyc_pxโ Line frequencyhatch_angle1_deg/hatch_angle2_degโ Hatch angleshatch_squareโ Square wave vs sinehatch_phase_jitterโ Random phase variationhatch_supersampleโ Anti-aliasing factor
WASRingNoiseOptions
ring_center_fracโ Ring center (fraction of Nyquist)ring_bandwidth_fracโ Ring thickness
WASHighpassWhiteOptions
highpass_cutoff_fracโ Butterworth cutoffhighpass_orderโ Filter steepness
WASTileLinesOptions
tile_line_tile_sizeโ Tile dimensionstile_line_freq_cyc_pxโ Line frequency per tiletile_line_jitterโ Orientation randomness
WASDotScreenOptions
dot_cell_sizeโ Halftone cell sizedot_jitter_pxโ Dot center randomnessdot_fill_ratioโ Coverage per cell
WASGreenNoiseOptions / WASBlackNoiseOptions / WASVelvetOptions
- Spectral and impulse noise parameters
- See node tooltips for detailed ranges
WASCheckerOptions / WASBayerOptions
checker_size/bayer_sizeโ Pattern scale
WASDetailRegionOptions / WASSmoothRegionOptions
content_windowโ Kernel size for content analysis
Affine Schedule Options (WASAffineScheduleOptions)
Controls timing and intensity curves for integrated samplers:
- start / end โ Active range (0.0-1.0 of total steps)
- bias โ Curve bias toward start/end
- exponent โ Power curve shaping
- curve โ Easing function (linear, sine, cubic, etc.)
- start_offset / end_offset โ Value adjustments
Returns: Schedule DICT + visualization plot
๐๏ธ External Mask Gating
Use external masks to limit where affine effects are applied:
- Connect a grayscale IMAGE to
external_maskinput - Set
patternto any procedural pattern (notexternal_mask) - The generated pattern mask is multiplied by your external mask
- Affine transforms only apply where both masks are bright
Use Cases:
- Apply effects only to specific objects or regions
- Combine with segmentation masks for targeted enhancement
- Create complex composite effects with multiple mask layers
๐ Installation
Manual
- Clone the repository to your
ComfyUI/custom_nodesdirectory:cd ComfyUI/custom_nodes git clone https://github.com/WASasquatch/was_affine.git - Restart ComfyUI via Manager or console
Manager
- Open Manager and click "Install Custom Nodes"
- Search "WAS Affine" and click install on the custom node by author WAS.
- Restart ComfyUI via Manager's main menu.
Dependencies: Standard ComfyUI installation (torch, numpy). Note: Doesn't requires UltimateSDUpscale nodes.
๐งช Tips & Best Practices
General Guidelines
- Start subtle: Latent space is sensitive -
scale=0.95can be quite strong - Model sensitivity varies: Some models respond more dramatically than others
- Flux/Krea models: May need positive scale values (inverted behavior)
- Lightning LoRAs: Combine with lower CFG (1-2) for best results
Pattern Selection
- Organic content: perlin, worley_edges work naturally
- Architectural/geometric: checker, bayer, cross_hatch
- Fine detail work: velvet_noise, highpass_white, ring_noise
- Content-aware: detail_region for textures, smooth_region for skies
๐ License
MIT โ Free to use, modify, and share with attribution.
๐ Acknowledgments
- ComfyUI team for the excellent software
- Ultimate SD Upscaler and ComfyUI wrapper developers
- Community feedback and testing contributions like "Ansel" and "Lucifer".

