Nodes/ComfyUI-Optical-Realism/Optical Realism & Physics
ComfyUI Node

Optical Realism & Physics

Depth-aware camera physics

By skatardude10·Created 8 months ago·Updated 4 months ago· 29
Optical Realism & Physics
  • image
  • depth_map
  • IMAGE
lens_distortion-0.010
color_temperature0.05
tint-0.05
atmosphere_enabledtrue
haze_strength0.60
lift_blacks0.05
depth_offset0.00
f_stopManual
dof_intensity0.30
dof_auto_focustrue
dof_sharpness_radius0.35
dof_focus_point0.00
light_wrap_strength0.70
promist_strength0.10
halation_strength0.15
chromatic_aberration0.002
vignette_intensity0.15
grain_power0.012
monochrome_graintrue
highlight_rolloff0.05

The author calls the thing this fixes the "uniform entropy" look: background noise as sharp as the foreground, a subject that sits on the backdrop like a sticker, every line geometrically perfect. It's the tell that gives AI generations away - the same list of fails the photorealism crowd keeps repeating: sharp everywhere, hard backlit edges, dead-black shadows, straight lines.

Optical Realism & Physics is a single post-process node that throws a whole photography pipeline at your image in one pass. Feed it a normal RGB image plus a depth map, and it acts as a virtual camera: lens geometry, real bokeh, atmospheric haze, film grain. What most people stitch together from five nodes, this does in one.

How it works

The whole thing runs locally as pure PyTorch math - no API, no key, no model downloads. It runs roughly twelve passes over the image:

  • Lens distortion - barrel or pincushion warp via a radial sampling grid, with reflection padding so you don't get black borders. Positive values bulge, negative pincushion.
  • Color temperature & tint - shifts white balance while renormalizing to preserve luminance, so highlights don't blow out. The README's tip for a warm "Kodak" look that flatters skin: Temp 0.10, Tint -0.05.
  • Depth of field - this is the good part. Instead of a Gaussian smudge it does a circular disc convolution, so out-of-focus highlights actually turn into bokeh circles. Auto-focus looks at the center 60% of the depth map and locks onto the 10th-percentile (nearest-ish) subject.
  • Atmospherics - haze and "lift blacks" based on depth, so distant shadows go dark grey-blue instead of pure black. That single thing separates the subject from the background.
  • Light wrap - bleeds bright background light over foreground edges, killing the cutout-sticker look.
  • Pro-Mist, halation, chromatic aberration, vignette - a glass-diffusion bloom, that red/orange film glow, sub-pixel color fringing, darkened corners.
  • Film grain - driven by a photographic emulsion curve: grain peaks in the mid-tones, fades in highlights and shadows, and it's clumped to look like silver halide rather than TV static. Monochrome on = film stock, off = digital sensor noise.
  • Highlight roll-off - a soft logarithmic shoulder so bright lights stop clipping to harsh white.

The inputs that matter

You wire in exactly two things - image and depth_map, both IMAGE tensors. Everything else is a slider, and the defaults are sensible enough to run it once before touching anything.

The ones you'll actually reach for:

  • f_stop - picks from real apertures (f/1.2 to f/22). Selecting anything other than Manual overrides the manual dof_intensity and dof_sharpness_radius sliders. Lower f-stops = heavy background blur, higher = wide scene in focus. The author flags it as TESTING, so don't be precious about it.
  • dof_intensity, dof_auto_focus, dof_focus_point - manual DoF control if you leave f_stop on Manual. Auto focus on, the node finds the subject for you; off, you set the focal plane with dof_focus_point.
  • haze_strength and lift_blacks - your atmospheric separation. Crank these when the subject melts into the background.
  • grain_power - keep it low. The default 0.012 is subtle; push it and you get visible film, not texture.

The output is a single IMAGE, ready for Save Image or to feed an upscaler.

Depth map gotchas

This node is only as good as your depth map. The README recommends Depth Anything V2 (the vit_l model); the author also found Apple's ComfyUI Depth Pro works great. The script assumes black = near, white = far - if your depth model outputs the opposite, throw an Invert Image node in between. That's the most common way haze and DoF come out backwards.

Install

It's a plain custom node: no extra Python dependencies - the code only needs torch and torchvision, which ComfyUI already ships - and no model files to download.

cd ComfyUI/custom_nodes
git clone https://github.com/skatardude10/ComfyUI-Optical-Realism.git

Then restart ComfyUI. Or search "ComfyUI-Optical-Realism" in ComfyUI Manager and hit install.

Troubleshooting

The README documents a RuntimeError: The size of tensor a (4) must match... when an RGBA image hits a node expecting three channels; its fix is the bundled Remove Alpha node (same pack). One nuance: the current source already strips the alpha defensively on its own input, so if you still see the error it's a different node in your chain.

Otherwise the failure mode is boring: bad or inverted depth maps make DoF and haze land wrong. The author is upfront that this is his own scratch-itched node ("maybe this is newb work," he says in the launch thread) - fewer guards, but a genuinely distinctive take that most packs don't attempt.

CategoryPostProcessing/Physics

Inputs (22)

NameTypeDefaultDescription
imageIMAGE
depth_mapIMAGE
lens_distortionFLOAT-0.010-0.5–0.5
color_temperatureFLOAT0.05-1–1
tintFLOAT-0.05-1–1
atmosphere_enabledBOOLEANtrue
haze_strengthFLOAT0.600–1
lift_blacksFLOAT0.050–1
depth_offsetFLOAT0.00-1–1
f_stopCOMBOManual12 options: Manual, f/1.2, f/1.4, f/1.8, f/2.0, f/2.8, +6
dof_intensityFLOAT0.300–1
dof_auto_focusBOOLEANtrue
dof_sharpness_radiusFLOAT0.350–1
dof_focus_pointFLOAT0.000–1
light_wrap_strengthFLOAT0.700–1
promist_strengthFLOAT0.100–1
halation_strengthFLOAT0.150–1
chromatic_aberrationFLOAT0.0020–0.05
vignette_intensityFLOAT0.150–1
grain_powerFLOAT0.0120–0.5
monochrome_grainBOOLEANtrue
highlight_rolloffFLOAT0.050–1

Outputs (1)

NameTypeDescription
IMAGEIMAGE