RapidRAW Logo RapidRAW
Verified in v1.6.8
Documentation Menu

Depth Effects

Three results from RapidRAW: a beach portrait lit by a warm added point light, a railway at sunset with light fog toward the distance, and a hotel with the hills behind it blurred by Lens Blur

Relight, Fog and Lens Blur add light, atmosphere and depth of field using AI estimates of the scene's 3D shape. Motion Blur adds movement and can use the same depth map. Since version 1.6.8, all four run as compute shaders on the GPU, in linear light, so the image never has to be copied back to the CPU:

Order all on the GPU
Geometry→Relight→Fog→Lens Blur→Crop→Motion Blur→Main adjustments

Geometry includes lens corrections, perspective and rotation. Relight, Fog and Lens Blur work on the uncropped image, at the working resolution (the preview size in the editor, full size in an export). All their sizes are relative to the image, so the preview matches the export. Motion Blur runs after the crop. The results of these stages are cached on the GPU, so changing Exposure or a color slider doesn't recalculate them.

Because they come before the main adjustments, your exposure, color and tone edits apply to the result, just as if the light, fog or movement had been there when you took the photo.

Depth and normal maps

Map Model Resolution Used by
Depth Depth Anything V2 (small) long side 518 px Fog, Lens Blur, Motion Blur, Depth mask
Normals + depth MoGe-2 (small) long side up to 768 px Relight
  • Depth Anything gives relative inverse depth: bright is near, dark is far, normalized per photo. It doesn't know real distances, only the order of things.
  • MoGe-2 estimates the direction each surface faces (a normal map) and a 3D point map, from which RapidRAW also derives a depth channel.
  • Maps are computed once per file from the unedited image, saved in the AI map cache on disk (4 GB by default) and warped to match your current geometry corrections. For normals, the direction is also rotated to follow rotations and perspective corrections.

Edge-aware upsampling

The maps are small, but the effects need edges that match the full-resolution photo. Relight, Fog and Lens Blur upsample their maps with a guided filter, using the square root of the photo's luminance as the guide. The filter's linear model (map ≈ a · guide + b) is fitted on a copy of the photo at the map's size, then evaluated at every full-resolution pixel with that pixel's own luminance. Where the photo has an edge, the map gets the same edge; in smooth areas, the map stays smooth.

Effect Fitted at Window radius ε
Relight normal map size 0.6% of its long side 0.002
Fog depth map size 1% of its long side 0.002
Lens Blur long side 1024 px 1.5% (about 15 px) 0.004

Lens Blur uses a stricter version: it only lets the depth follow the photo where the photo has clear structure, and clamps each value to a range based on its neighbours (the local mean ± 1.1 standard deviations), which prevents halos around subjects.

Motion Blur doesn't need exact edges from the depth map, because its masks already define the edges. It samples the depth map with plain bilinear filtering.

3D depth view

When one of these effects is on, the panel shows an interactive 3D view of its map. RapidRAW renders a small preview of the depth (long side up to 192 px, with the same geometry warp as the photo, plus the normals for Relight) and the app draws it with WebGL as a point cloud: each point has the photo's color and is pushed back by its distance. You can rotate, zoom (up to 4x) and pan the view.

The view previews each effect with the same formulas as the GPU shaders, simplified:

  • Lens Blur: the circle of confusion below. Out-of-focus points are drawn larger, paler and more transparent, and the in-focus range is shown as draggable planes.
  • Fog: the Beer–Lambert fog below, tinting points with the fog color. The Start plane is draggable.
  • Relight: the wrapped Lambert shading below for every light, with the light as a draggable handle.
  • Motion Blur: each point is drawn again as faint copies along the blur direction, scaled by the same depth factor as the real blur.

AI Depth masks use the same view with their own depth range.

Relight

Relight treats each pixel as a small surface with the normal from the map, and lights it with a virtual light:

gain = 2^(ambient/50)                                          start with the ambient level
for each light:
    diffuse  = max(0, (N·L + softness) / (1 + softness))       wrapped Lambert
    specular = (N·H)^(8 + 56·(1 − softness)) · shine · 2       Blinn
    gain    += light color · (diffuse + specular) · attenuation · shadow
rgb = rgb · gain
  • Wrapped Lambert lets light wrap a little around edges, so the falloff is soft like a large light source rather than a hard terminator. Softness controls how much (see the chart below).
  • Ambient starts at −50, so gain starts at 0.5: the scene is darkened by one stop and your lights stand out.
  • Light types:
  • Directional (like the sun) uses angle and elevation, with no falloff.
  • Point has a position and a radius r = 0.05 + 1.45 · Falloff (in units of the long side), with falloff r² / (r² + distance²). Depth moves it from slightly in front of the scene (0) to the back (100).
  • Spot is a point light with a cone (half angle 5° to 85°) and a soft edge (Feather).
  • The light color is decoded from sRGB, shifted by Temperature and Tint, and normalized by its luminance, so changing color doesn't change brightness. At Intensity 100, a surface facing the light (before falloff) gets +4 added to its gain; the default of 40 adds +1.6.
  • All four channels of the map (normal XYZ and depth) go through the guided filter, then the shading runs per pixel at full resolution.
  • Shadows (optional) are ray-marched in screen space on a depth map of up to 2048 px (long side). From each pixel, 64 jittered steps go toward the light. A step that is 0.01 to 0.3 behind the depth surface counts as blocked (with smooth edges), so thin foreground objects cast shadows without everything behind them going dark. Each light's shadow map is box-blurred (Shadow Softness, radius up to 2% of the long side) and upsampled with the guided filter.
Four panels of the beach portrait: the AI normal map, the AI depth map, the light-only shading of one point light, and the final relit photo
What Relight works with. The normal map and depth come from MoGe-2. "Light only" is diffuse · attenuation for one warm point light at the left edge (Softness 28, Falloff 36), computed from RapidRAW's normal map with the formula above, since the app doesn't output this pass on its own. The final image is RapidRAW's render with Ambient −79.
Line chart of light received against the angle between a surface and the light, for Softness 0, 25, 50 and 100. At Softness 0 the light drops to zero at 90 degrees; higher values let the light reach further around
max(0, (cos θ + softness) / (1 + softness)) plotted for four Softness values. At 0 it is plain Lambert lighting with a hard cut-off at 90°; at 100 light reaches all the way to surfaces facing away.
Portrait original, its color-coded normal map, and the relit result with a warm point light
Original, the MoGe-2 normal map (colors show the direction surfaces face) and the result with a warm point light and darker ambient. Photo by Coco on Unsplash.
Relight panel with a spot light aimed at the dress, its cone and handles drawn on the photo, and Ambient at -80
A spot light with Ambient −80. Drag the round handle on the image to move the light; the small dot aims the cone.
An interior with white architectural blocks and a chandelier: the original, and the relit version where a warm point light in the chandelier casts shadows of the pillar and blocks onto the walls
Shadows on. A warm point light placed in the chandelier: the pillar and the blocks cast shadows onto the walls behind them, found by ray marching the depth map toward the light. The small circle marks the light's position.

Fog

Fog uses the Beer–Lambert law: light passing through fog decays exponentially with distance.

  1. Distance from depth: distance = (1/(d + 0.1) − 1/1.1) / (1/0.1 − 1/1.1), which turns relative inverse depth back into a 0 (near) to 1 (far) distance. Start moves where the fog begins: t = (distance − start) / (1 − start).
  2. Ground fog: density is multiplied by exp(−6 · ground · up), where up is 0 at the bottom of the frame and 1 at the top, so fog gets thicker toward the bottom.
  3. Variation: 4 octaves of value noise, stretched horizontally, create uneven fog banks: patches = max(1 + 1.6 · variation · (2·noise − 1), 0).
  4. Extinction: the fog amount follows Beer–Lambert (formula below), with density = 0.5 + 7.5 · Density. It's normalized so Amount is exactly the fog strength at the farthest point.
  5. Fog color from the scene: on a small copy of the image (long side 384 px), RapidRAW averages the color of the far parts (depth below 0.3), desaturates it by 40%, and uses that as the fog color (tinted by Temperature and Tint). Its brightness is the brighter of the far average and the whole-image average. So fog in a sunset is warm and fog in a blue hour is blue, without any setting.
  6. Scattering and glow: the fog is mixed 35% with a blurred copy of the image (light scattering inside the fog). Areas brighter than about 0.8x the fog brightness add a large soft halo (blur radius 6% of the long side), scaled by 1.5 · Glow.

Extinction and the final mix:

optical depth = density · t · ground term · patches
fog           = amount · (1 − e^(−optical depth)) / (1 − e^(−density))
out           = image · (1 − fog) + (fog color + scattering + glow) · fog

The color statistics are gathered in one GPU pass with a parallel reduction, and the final mix runs per pixel at full resolution.

Railway tracks at sunset: original, the depth map, light fog and strong fog that thickens toward the distance
Original, the Depth Anything map, light fog and strong fog. The fog gets thicker toward the far end of the tracks, and its color comes from the sunset sky.

Lens Blur

Lens Blur simulates a shallow depth of field.

Circle of confusion. Each pixel gets a blur radius from its guided depth d (1 = near). Pixels inside the in-focus range stay sharp; pixels farther away get a positive radius (background blur) and nearer ones a negative radius (foreground blur). The maximum radius R is 1.2% of the long side at Amount 100. A 3x3 median filter then removes single-pixel speckles from the radius map.

far  = 1 − smoothstep(min − min_fade, min, d)
near = smoothstep(max, max + max_fade, d)
CoC  = (s(far) − s(near)) · R,      s(x) = x · (0.8 + 0.2x)

Rendering in layers. Real bokeh can't be made with a single variable blur, because blurred foreground objects must spread over sharp edges behind them, while blurred background must not leak over sharp foreground. RapidRAW:

  1. Works at a reduced resolution for speed: the image is shrunk so the largest blur is at most about 18 px at that size, and further (up to 6x) if the number of samples would still be too high.
  2. Defines 5 blur levels with radii R · (k/4)^1.7 for k = 0 to 4. Level 0 is sharp. Each pixel is shared between its two nearest levels with tent weights, separately for background and foreground.
  3. Blurs each level with a real aperture shape: circle, hexagon, octagon or ring (mirror lens), drawn with up to 128 samples on a golden-angle spiral (an exact disc for very small radii). The circular aperture is 12% brighter at the rim, like real lenses; the ring is dark in the middle and bright at the edge. Empty 8x8 tiles are skipped.
  4. Does the blurring in an energy domain (squared values, softly capped for extreme highlights), so bright highlights dominate and turn into proper bokeh balls instead of greyish blobs.
  5. Adds cat's-eye bokeh: toward the edges of the frame, the aperture is clipped by a second disc of the same size, shifted by up to 0.38 of its radius depending on the position in the frame, as in real lenses with optical vignetting.
  6. Composites back to front: the blurred background (largest level first), then the sharp original where it's in focus (at full resolution), then the blurred foreground over everything.

If fewer than 1 in 400 pixels gets a blur radius above 0.4 px (and Diffusion is 0), the image is passed through unchanged.

Diffusion blends the aperture toward a soft Gaussian-like profile, rounds polygon shapes by up to 60%, enlarges the blur by up to 30% and weakens the cat's eye. It also adds a gentle glow: the out-of-focus areas are blurred twice more and mixed back as a veil (up to 75%), while the base there is dimmed by up to 55%.

Hotel building: original, depth map, and with lens blur on the road in front and the hills behind
Original, the depth map, and Lens Blur at 70 focused on the building. The road in front and the hills behind are blurred.

Motion Blur

A white sports car in an autumn valley, before and after a Linear motion blur on the background
A Linear blur on the background only: the valley streaks, the car stays sharp.

Motion Blur runs after the crop, on the image the main shader is about to process, in linear light (non-RAW images are converted from sRGB first). It can be applied to the whole image and inside any number of masks. The mask blurs run first, in mask order, then the global blur. The result is cached until a motion setting, a mask or the image changes.

Blur paths

The slider is shaped first: s = (Amount/100)^1.5, so low values give fine control.

Type Path of each sample Size at Amount 100
Linear p + axis · t along Angle 15% of the image diagonal
Smooth (masks) three linear blurs at 0°, 60° and 120° 5% of the diagonal
Zoom c + (p − c) · e^t around a center c t spans 0.5, a scale of about 0.78x to 1.28x
Spin rotation by t around a center 45° (whole image), 180° (mask)
  • The Zoom center is the frame center for the whole image. In a mask it is the centroid of the mask, or of the unmasked area for Panning.
  • For Spin in a mask, the mask is thresholded at 50% on a coarse grid (256 cells on the long side) and split into connected areas. Up to 8 areas, each at least 5% of the largest, spin around their own centers. Each one uses an ellipse fitted to its bounding box, so a wheel seen at an angle spins along its oval outline.

Cascaded taps. A long blur would need hundreds of samples per pixel. Instead, each blur is a cascade of 8-tap passes. Pass k spaces its taps length / 8^(passes − k) apart, so every pass makes the blur 8x longer, and passes = ⌈ln(length) / ln 8⌉. A 1000 px streak needs 4 passes of 8 taps.

Tapered streaks. Linear, Zoom and Spin use two cascades of 70% and 30% of the length. Together they give a streak that fades out at both ends instead of stopping hard, like a real exposure where the motion starts and stops. Linear also adds a 3% cascade across the motion, a slight sideways softness that keeps the streak from looking machine-made.

Highlights

Before blurring, values above 0.75 (linear) are boosted, and the boost is undone after:

e   = v + g · max(v − 0.75, 0)² / 0.25          g = 16 · Highlights / 100
out = inverse of the same curve, applied to the blurred e

Unblurred pixels come back unchanged. But when a bright light is spread along a streak, its boosted energy keeps the streak bright, so street lights become light trails instead of grey smears.

Depth

With Depth on, each pixel's tap spacing is scaled by its nearness d from Depth Anything:

factor = clamp(mix(1, d / d_ref, depth), 0, 4)

d_ref is the average nearness of the subject: the masked area for Moving Subject and Uniform, the unmasked area for Panning, and the whole frame without a mask. Things at the subject's distance keep the normal length, nearer things blur up to 4x more, farther things less. Spin ignores depth.

Masks: Moving Subject, Panning and Uniform

The Motion setting decides how the mask is used. Auto resolves to:

  • Uniform if the mask has no AI component (Subject, Foreground, Sky, Face, Text or Quick Eraser), or covers more than 98% of the image;
  • Panning if more than half of the image border is masked (for example an inverted subject mask);
  • Moving Subject otherwise.

Spin and Smooth always use Uniform.

Uniform blurs the image weighted by the mask (premultiplied by the mask value) and mixes the result back by the mask.

Moving Subject and Panning need what is behind the subject, which the photo doesn't have. RapidRAW fills it with a pull-push fill on a quarter-resolution pyramid: pixels well away from the subject (a guard of 0.05% of the diagonal around the mask edge) are averaged down level by level, then pushed back up to fill the hole smoothly from its surroundings.

  • Moving Subject: the subject is blurred on its own (premultiplied by the mask) and laid over the filled background: out = blurred + (1 − α) · background. Its streak can extend past the mask outline. The mask itself is blurred the same way, so other adjustments in that mask follow the streak.
  • Panning: the background is blurred with the subject area replaced by the fill, so the subject's colors don't smear into the background. The blurred background is then put back only where the mask is: out = image + mask · (blurred − background).

For AI masks, and for Moving Subject and Panning, the mask edge is first refined into a clean matte: its soft edge is sharpened to about 1.5 px, smoothed with a small box blur (radius 0.04% of the diagonal) and sharpened again. This keeps the edge crisp without stair steps.

Noise matching

A blurred area loses the photo's noise and grain, so it would look too clean. RapidRAW measures the image's noise once per photo: on a sparse grid of about 4000 blocks of 8x8 pixels, it takes the difference between each pixel's luminance and the average of its four neighbours, computes the RMS per block, and uses the quietest 10% (corrected for the filter's gain of 1.118) as the noise level. Quiet blocks are flat areas, where this difference is almost pure noise. After blurring, it adds Gaussian noise of that strength in sRGB space, scaled by how much of each pixel the blur replaced.

Whole image with masks

When the global blur is on and the photo has masks, the mask bitmaps are blurred with the same kernel. Their edges still line up with the blurred photo, so a mask adjustment doesn't leave a sharp outline.

Limits

  • Depth is relative and estimated from one image, so it can be wrong on glass, reflections, fine hair and unusual scenes. The guided upsampling hides small errors but not large ones.
  • The models only see one image, so there's no information about what's hidden behind objects. Motion Blur's fill for Moving Subject and Panning is a smooth guess from the surroundings, not real detail.

See also