Trying to Kill the "Uncanny Valley" of uniform entropy?
Applies a combination of chromatic aberration, depth aware grain and background desaturation, curves to the black/white floor/ceiling, vignette and screen effects.
This node is an attempt at physics-based post-processing that uses a Depth Map to simulate Atmospheric Perspective, Light Transport, and Physical Lens Imperfections. It trys to turns a "generation" into a "photograph."
AI images often suffer from the Frequency Distribution Problem. High-frequency details (noise, texture) are distributed equally across the image. In real photography, physics dictates that:
- Distant objects have lower contrast and lifted blacks (Atmosphere).
- Bright background light bleeds over foreground edges (Light Wrap).
- Lenses are not mathematically perfect (Chromatic Aberration & Vignette).
- Film grain lives in the emulsion, not floating on top of the image (Depth-Aware Grain).
This node does some shit to address all that. Play with it or don't.
- Clone this repo into your
custom_nodesfolder:git clone https://github.com/skatardude10/ComfyUI-Optical-Realism.git
- Restart ComfyUI.
Crucial: This node requires a Depth Map to work its magic.
I highly recommend using Depth Anything V2 (specifically the vit_l model for best edge detection).
Wiring it up:
-
Input Image
$\rightarrow$ Remove Alpha (included utility)$\rightarrow$ Optical Realism(Image Input) -
Input Image
$\rightarrow$ Depth Anything V2$\rightarrow$ Invert Image$\rightarrow$ Optical Realism(Depth Input)- Note: My script assumes Black = Near, White = Far. If your depth model outputs the opposite, use an Invert Image node.
Here is exactly what the sliders do.
- Atmosphere Enabled: The master switch. Turns on the depth-based physics.
- Haze Strength: How "thick" is the air? Low values = clear winter day. High values = humid rainforest or foggy street.
- Lift Blacks: The secret sauce. Real shadows in the distance aren't pure black (
#000000); they are dark atmospheric grey-blue. This lifts the background shadows to separate the subject from the environment. - Depth Offset: Pushes the "fog curtain" forward or backward. Negative values push it back (clearer foreground), positive values pull it close (macro feel).
- Light Wrap Strength: Simulates "Bloom" or "Halation." It takes bright background light and bleeds it over the edges of the foreground subject. Kills the "cutout sticker" look.
- Chromatic Aberration: Uses Sub-Pixel Sampling (not just resizing) to create a mathematically smooth, infinite-resolution lens fringing effect. Keep this low (
0.001-0.003) for realism. - Vignette Intensity: Darkens the corners to mimic a physical lens barrel. Subtle framing that guides the eye to the center.
- Grain Power: Adds texture. Crucially, this is Depth-Aware. The grain is sharp on the focused subject but gets softer/mushier in the blurred background, just like real film.
- Monochrome Grain:
True(Default): Simulates Film Stock. Noise affects luminance only.False: Simulates Digital Sensors. Independent RGB noise (Color noise).
- Highlight Roll-off: AI likes to clip bright lights to pure white instantly. This adds a "shoulder" to the highlights, compressing them softly so they look creamy instead of harsh.
I am too lazy to get side by side for all of the subtle things this does. I tried to pick sane defaults that make a solid improvement. Play with the sliders... again, or don't! I tried it with the standard plastic skin AI generated images and I will be using this so I share... it takes depth into account to focus on the subject so it's whatever.
"RuntimeError: The size of tensor a (4) must match..."
- Your image has an Alpha channel (RGBA).
- Fix: I included a helper node called
Remove Alpha (RGBA to RGB). Put this before the Optical Realism node and the Depth node.
Obvious