A custom ComfyUI node that intelligently preserves HDR data from VAE models for professional VFX workflows.
- Overview
- Problem Statement
- Technical Innovation
- Installation
- Usage
- Example Workflow
- Built-in HDR Export
- Results & Performance
- Technical Achievements
- Compatibility
- Troubleshooting
- Development Notes
- Contributing
- License
After extensive research and development, I've created a node that solves the fundamental HDR preservation problem in VAE decoding. Instead of blindly bypassing layers, this implementation uses a scientific approach to understand and work with the VAE's natural behavior:
Professional HDR workflow: HDR VAE Decode β Linear EXR Export for true HDR preservation
π― Important: This HDR VAE Decode is specifically built and tested for Flux.1 VAE models. While it may work with other VAE architectures, it has been optimized for Flux.1's specific decoder structure and may not perform as expected with different models.
- Intelligent Analysis: Automatically analyzes the VAE's
conv_outtransformation to understand how HDR data is processed - Smart HDR Expansion: Preserves the VAE's excellent tone mapping while selectively expanding highlight regions
- Multiple HDR Modes: Conservative, Moderate, Exposure, and Aggressive modes for different workflows
- Professional Quality: Maintains perceptual image quality while extending dynamic range where needed
- VFX Ready: 32-bit float pipeline with proper HDR preservation for compositing workflows
ComfyUI's default image processing pipeline has several HDR-breaking limitations that result in significant quality loss:
β Standard Processing: Clipped highlights, limited color range, lost detail in bright areas
- Range Clamping: VAE outputs are constrained to 0-1 pixel values
- Lost Dynamic Range: High and low luminance information is compressed/clipped
- 8-bit Pipeline: Effective output is 8-bit despite higher precision formats
- Color Space Constraints: Limited to sRGB-like color spaces
- π¨ Critical: ComfyUI's built-in Save Image node normalizes ALL pixel values to 0-1 range
- HDR Data Destruction: Even if you preserve HDR in processing, Save Image destroys it during export
- False EXR Support: Claims to save EXR but actually saves 8-bit data in EXR container
- VFX Incompatible: Produces files that appear HDR but contain no extended range data
The result: Beautiful AI-generated content gets degraded during processing, losing the very highlight details and color richness that make images compelling for professional use.
Through systematic analysis, I discovered that the VAE's conv_out layer applies sigmoid-like normalization that clamps HDR values to [0,1]. Rather than simply bypassing this layer, I developed an intelligent approach that:
- Analyzes the transformation using forward hooks to capture pre/post conv_out data
- Detects the normalization pattern (sigmoid, tanh, or custom)
- Preserves base image quality by using the VAE's excellent tone mapping as foundation
- Selectively expands highlights only in regions that exceed the standard range
- Scientific Analysis: Real-time conv_out transformation analysis with statistical profiling
- MAX Pooling Channel Conversion: Preserves HDR peaks when converting 128β3 channels (vs averaging which destroys brightness)
- Smart Device Management: Automatic CUDA/CPU synchronization across all processing stages
- Multiple HDR Modes:
- Conservative: Gentle 1.5x expansion, safest for general use (default)
- Moderate: 3x smart expansion, balanced quality/range
- Exposure: Natural exposure-based HDR for compositing workflows
- Aggressive: Full mathematical recovery for maximum range
- Robust Fallback System: Smart bypass β Simple bypass if intelligent methods fail
- Professional Pipeline: Float32 throughout with proper tensor formatting for ComfyUI

β
HDR VAE Decode: Extended highlights preserved, natural color depth, professional VFX quality
Dramatic improvements achieved:
- Highlight Detail Recovery: Bright bokeh retains structure instead of clipping to pure white
- Color Richness: Full spectrum preservation with enhanced vibrancy and depth
- Natural Light Falloff: Smooth gradients in bright areas maintain photographic realism
- VFX Compositing Ready: Extended range enables professional color grading and exposure control
- Clone this repository into your ComfyUI custom_nodes directory:
cd ComfyUI/custom_nodes
git clone https://github.com/sumitchatterjee13/vae-decode-hdr.git- Install minimal additional dependencies (ComfyUI already provides torch, torchvision, numpy):
cd vae-decode-hdr
pip install -r requirements.txtpip install OpenImageIOOpenImageIO provides professional-grade EXR support with true 32-bit/16-bit float precision and full compression options. If not installed, the node will automatically fall back to OpenCV (which still preserves HDR data, but with limited bit depth control).
- Restart ComfyUI
- Download ZIP from GitHub
- Extract to
ComfyUI/custom_nodes/vae-decode-hdr/ - Install dependencies:
pip install -r requirements.txt - (Optional but recommended) Install OpenImageIO for professional EXR support:
pip install OpenImageIO - Restart ComfyUI
The nodes should appear in the latent category as "HDR VAE Decode" and in the image category as "Linear EXR Export".
What you'll create: HDR VAE Decode (latent category) β Linear EXR Export (image category)
The HDR VAE Decode node will appear in the "latent" category in ComfyUI.
- samples: Latent samples from your pipeline
- vae: The VAE model (tested with Flux.1 Dev, compatible with other VAE models)
- hdr_mode (optional): HDR processing mode:
conservative: Gentle 1.5x expansion, maintains natural appearance (default)moderate: 3x smart expansion, balanced for most VFX workexposure: Natural exposure-based HDR using exposure stopsaggressive: Full mathematical recovery, maximum dynamic range
- max_range (optional): Final output clamp range (1-1000, default: 50)
- scale_factor (optional): Additional scaling multiplier (0.1-10x, default: 1.0)
- enable_negatives (optional): Allow negative values for advanced workflows (default: false)
The node first attempts intelligent HDR decode using scientific analysis of the VAE's behavior. If this succeeds, you'll get natural-looking images with selectively expanded highlights. If it fails, the system falls back to the robust bypass method that directly processes VAE decoder layers.
- image: Professional-quality HDR image tensor with preserved dynamic range, ready for EXR export or further processing
Example ComfyUI workflow showing HDR VAE Decode connected to Linear EXR Export
For typical VFX work:
- Connect your Flux.1 latents to the HDR VAE Decode node
- Use default "conservative" mode for natural results, or choose "moderate" for higher dynamic range
- Leave other parameters default for most use cases
β οΈ CRITICAL: Connect output to the Linear EXR Export node - DO NOT use ComfyUI's built-in Save Image node- Configure output path (e.g.,
/Testforoutput/Test/subfolder) - Use in your compositing software (Nuke, After Effects, etc.) with proper HDR handling
β ComfyUI's Built-in Save Image Node:
- Automatically normalizes all pixel values to 0-1 range
- Destroys HDR data above 1.0
- Clips highlights and bright regions
- Converts to 8-bit even when saving as EXR
- Completely defeats the purpose of HDR processing
β Our Linear EXR Export Node:
- Preserves full HDR range (values above 1.0)
- True 32-bit float precision
- Linear color space maintained
- Professional VFX quality output
- Smart path handling (
/Testβoutput/Test/)
The HDR VAE Decode node will automatically:
- Analyze the VAE's behavior
- Apply intelligent HDR expansion to highlight regions
- Preserve natural image appearance
- Output HDR data for professional workflows
This package now includes a Linear EXR Export node for professional HDR output:
| Feature | ComfyUI Save Image | Our Linear EXR Export |
|---|---|---|
| HDR Values | β Normalizes to 0-1 | β Preserves >1.0 values |
| Bit Depth | β 8-bit effective | β True 32-bit float |
| Color Space | β sRGB/Gamma | β Linear maintained |
| VFX Ready | β No | β Professional quality |
| HDR Workflow | β Destroys HDR data | β Preserves all HDR data |
- OpenImageIO-powered: Uses industry-standard VFX library for professional-grade EXR writing
- True 32-bit EXR export with preserved HDR values above 1.0
- Professional VFX quality - maintains linear color space with full OpenEXR specification compliance
- Smart path handling:
- Empty path β saves to
ComfyUI/output/ /subfolderβ saves toComfyUI/output/subfolder/- Full path β uses custom absolute/relative path
- Empty path β saves to
- Multiple bit depths: 32-bit float or 16-bit half precision (smaller files)
- Compression options: ZIP, PIZ, RLE, PXR24, or none (via OpenImageIO)
- Auto-incrementing filenames: Never overwrites existing files - perfect for image sequences
- Clean file naming with customizable prefixes and counters
- HDR verification: Automatically verifies HDR values are preserved in saved files
- Seamless integration: Designed specifically for HDR VAE Decode output
- Automatic fallback: Uses OpenCV if OpenImageIO is not installed (still preserves HDR data)
The Linear EXR Export node now includes intelligent filename management that prevents accidental overwrites:
How it works:
- If
Test_00001.exrexists, automatically saves asTest_00002.exr - If
HDR_VAE_00005.exrexists, automatically saves asHDR_VAE_00006.exr - Perfect for image sequences: Generate multiple variations without losing previous outputs
- Safe iterations: Experiment with different settings without fear of overwriting good results
Examples:
Generation 1: MyScene_00001.exr
Generation 2: MyScene_00002.exr (automatically incremented)
Generation 3: MyScene_00003.exr (automatically incremented)
...and so on
HDR VAE Decode β Linear EXR Export β Professional EXR files ready for compositing in Nuke, After Effects, or other VFX software.
Correct node setup: Both nodes are essential for professional HDR output
The Linear EXR Export node will appear in the image category in ComfyUI.
β οΈ Warning: Do NOT use ComfyUI's built-in Save Image node with HDR data - it will destroy all values above 1.0!
For advanced HDR processing workflows with multi-exposure fusion, you can also use the HDR Export node from the Luminance Stack Processor package available through ComfyUI Manager.
The intelligent HDR approach successfully preserves HDR data while maintaining professional image quality:
- HDR Preservation: Maintains hundreds of thousands of HDR pixels (>1.0 values) through the entire pipeline
- Dynamic Range: Conservative mode (default): 1.5x range, Moderate: up to 9.0x, Exposure/Aggressive: 10+ range
- Image Quality: Natural appearance with selective highlight expansion, not false color artifacts
- Processing Speed: ~40-42 seconds for 752Γ1328 images (similar to standard VAE decode)
- Memory Efficiency: Float32 pipeline with smart device management (CUDA/CPU synchronization)
The HDR VAE Decode delivers dramatically superior results with preserved highlight details and enhanced color reproduction:
Standard VAE decode: Limited dynamic range, clipped highlights, reduced color vibrancy

HDR VAE Decode: Extended highlights preserved, enhanced color depth, natural bokeh detail
Key Improvements Visible:
- β Highlight Preservation: Bright bokeh elements retain detail instead of clipping to white
- β Enhanced Color Range: Richer, more vibrant colors throughout the image
- β Natural Gradients: Smooth transitions in bright areas instead of hard clipping
- β Professional Quality: VFX-ready output suitable for compositing and grading
For direct comparison of output quality, reference examples are also provided in the /images folder:
Sample_builtin_vae_decode.png- Output from ComfyUI's built-in VAE decode (0-1 range, limited dynamic range)Sample_hdr_vae_decode.exr- Output from HDR VAE Decode (extended range, preserved highlights and shadows)
Through this project, I solved several challenging problems:
- Identified the root cause: VAE's
conv_outlayer applies sigmoid normalization, not simple clamping - Developed MAX pooling: Preserves HDR peaks during 128β3 channel conversion (vs averaging)
- Created intelligent expansion: Uses VAE's tone mapping + selective highlight extension
- Solved device synchronization: Proper CUDA/CPU tensor management across processing stages
- Built robust fallbacks: Multiple processing paths ensure reliability
- β Fully Supported: Flux.1 Dev VAE model (primary target)
β οΈ Experimental: Other VAE architectures (may work but not guaranteed)- β Not Recommended: SD 1.5, SDXL, or other non-Flux VAE models without testing
Important: This node was specifically engineered for Flux.1's VAE architecture. The intelligent analysis, bypass methods, and channel reduction logic are optimized for Flux.1's specific:
- 128-channel intermediate representations
- Up-block structure with ResNet + transposed convolution
conv_outsigmoid normalization behavior
While the fallback methods may work with other models, optimal HDR preservation is only guaranteed with Flux.1.
- ComfyUI: Stable versions (tested with latest releases)
- Python: 3.8+ required
- Hardware: CUDA-capable GPU strongly recommended for performance
- Memory: Sufficient VRAM for your target resolution + model
- Formats: Professional EXR with Linear EXR Export node
- Software: Nuke, After Effects, DaVinci Resolve, Blender
- Workflow: VFX compositing and color grading pipelines
β
Correct workflow: HDR VAE Decode connected to Linear EXR Export
- Check Node Connection: HDR VAE Decode β Linear EXR Export (not Save Image)
- Look for Console Output: Should show "HDR pixels: [number] >0" in Linear EXR Export logs
- Verify File Size: True HDR EXR files are typically 2-5MB+ for 1K images (vs <1MB for fake HDR)
- Test in VFX Software: Load in Nuke/After Effects and adjust exposure - should see extended highlights
- Compare with Examples: Check
/images/Sample_builtin_vae_decode.pngvs/images/Sample_hdr_vae_decode.exrto see the quality difference
Windows Users:
pip install OpenImageIOIf you encounter build errors, you can try:
- Download pre-built wheels from PyPI
- Use conda:
conda install -c conda-forge openimageio
Linux Users:
pip install OpenImageIO
# Or use your package manager:
sudo apt-get install python3-openimageio # Debian/Ubuntu
sudo yum install python3-OpenImageIO # RHEL/CentOSMac Users:
pip install OpenImageIO
# Or use Homebrew:
brew install openimageio
pip install OpenImageIOIf OpenImageIO fails to install:
- The node will automatically fall back to OpenCV for EXR writing
- HDR data is still preserved with the OpenCV fallback
- You just won't have access to advanced compression options and precise bit depth control
- Check console logs for fallback messages
Problem: "OpenImageIO not available" warning in console
Solution: Install OpenImageIO using the commands above, or ignore if using OpenCV fallback
Problem: EXR files don't show HDR values in Nuke/After Effects
Solution: Make sure you're using the Linear EXR Export node, not ComfyUI's built-in Save Image node
Problem: Memory errors during processing
Solution: Reduce resolution or adjust batch size, HDR processing requires more VRAM
Problem: Colors look different than standard output
Solution: This is expected - the node preserves linear color space. Apply proper color management in your compositing software
This project represents months of research into VAE architecture and HDR processing. The approach evolved from simple layer bypassing to sophisticated analysis-based processing. While the current implementation works well with Flux.1 Dev, different VAE models may require adjustments to the analysis logic.
Key learnings:
- Simple bypassing often breaks image quality - the VAE's processing pipeline exists for good reasons
- Averaging destroys HDR data - MAX pooling is essential for preserving brightness peaks
- Device synchronization is critical - mixed CPU/CUDA operations cause subtle failures
- Multiple fallback paths improve reliability - complex pipelines need robust error handling
This project welcomes contributions! If you encounter issues or have improvements:
- π Report bugs: Open an issue
- π‘ Feature requests: Suggest enhancements
- π§ Code contributions: Submit a pull request
- π Documentation: Help improve docs and examples
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This is an experimental node that pushes the boundaries of what's possible with VAE decoding - your contributions help advance HDR processing in ComfyUI!
This project is licensed under the MIT License - see the LICENSE file for details.
β
Commercial use
β
Modification
β
Distribution
β
Private use
Repository: https://github.com/sumitchatterjee13/vae-decode-hdr
Author: Sumit Chatterjee
Created: 2025
β If this project helps you, please consider giving it a star on GitHub!