RapidRAW Logo RapidRAW
Verified in v1.6.7
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. They run on the CPU in linear light, after geometry corrections and before crop and the GPU adjustments:

Order CPU, then GPU
Geometry→Relight→Fog→Lens Blur→Crop→GPU adjustments

Because they come before the GPU adjustments, your exposure, color and tone edits apply to the result, just as if the light or fog 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, 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. All three tools upsample their maps with a guided filter, using the square root of the photo's luminance as the guide. Where the photo has an edge, the map gets the same edge; in smooth areas, the map stays smooth.

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, which prevents halos around subjects.

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 the 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).
  • Light types:
  • Directional (like the sun) uses angle and elevation, with no falloff.
  • Point has a position and radius, with falloff r² / (r² + distance²).
  • Spot is a point light with a cone (5° to 85°) and a soft edge (feather).
  • The light color is normalized by its luminance, so changing color doesn't change brightness. Negative Ambient darkens the scene, so the light stands out.
  • Shadows (optional) are ray-marched in screen space: from each pixel, 64 steps toward the light; a step that goes behind the depth surface counts as blocked. The shadow map is blurred (Shadow Softness) 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, Radius 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.
  2. Ground fog: density is multiplied by exp(−height · up), so fog gets thicker toward the bottom of the frame.
  3. Variation: 4 octaves of value noise, stretched horizontally, create uneven fog banks.
  4. Extinction: the fog amount follows Beer–Lambert (formula below). It's normalized so Amount is exactly the fog strength at the farthest point.
  5. Fog color from the scene: RapidRAW averages the color of the far parts of the image, desaturates it by 40%, and uses that as the fog color (tinted by Temperature and Tint). 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), and bright areas add a large soft halo, controlled by Glow.

Extinction and the final mix:

optical depth = density · distance · ground term · variation
fog           = amount · (1 − e^(−optical depth)) / (1 − e^(−density))
out           = image · (1 − fog) + (fog color + scattering + glow) · fog
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 depth. 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 is 1.2% of the long side at Amount 100.

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. Splits the image into 5 layers by blur radius, separately for background and foreground.
  2. Blurs each layer with a real aperture shape (circle, hexagon, octagon or ring/mirror lens), drawn with up to 128 samples on a golden-angle spiral. The aperture is slightly brighter at the rim, like real lenses.
  3. Does the blurring in an energy domain (squared values), so bright highlights dominate and turn into proper bokeh balls instead of greyish blobs.
  4. Adds cat's-eye bokeh: toward the edges of the frame, the aperture is clipped, as in real lenses with optical vignetting.
  5. Composites back to front: the blurred background, then the sharp original where it's in focus (at full resolution), then the blurred foreground over everything.

Diffusion softens the aperture shape and adds a gentle glow to out-of-focus highlights.

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.

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.

See also