RLS Studios
ProjectsPatreonCommunityDocsAbout
Join Patreon
BeamNG Modding Docs

Guides

Reference

Server CommandsGE UtilitiesGame Engine MainNavigation GraphScreenshot CaptureServerServer ConnectionSpawnpoint ManagerSimulation TimeVehicle SpawningSuspension Frequency Tester
Client CanvasCaustics PostFXChromatic Lens PostFXClient CoreDepth of Field PostFXEdge AA PostFXPostFx Flash EffectPostFx Fog EffectsPostFx FXAA Anti-AliasingGamma PostFXPostFx Glow EffectShadow Maps InitClient LightingPostFx Light Ray EffectAdvanced Lighting - Light VisualizationPostFx Masked Screen BlurMotion Blur PostFXObjects Required for StartupClient Parse ArgsClient PostFX ManagerRender ManagerAdvanced Lighting - ShadersBasic Lighting - Shadow FilterAdvanced Lighting - Shadow VisualizationPostFx SMAA Anti-AliasingPostFx SSAO (Screen-Space Ambient Occlusion)PostFx Turbulence EffectPostFx Utilities

UI

Resources

BeamNG Game Engine Lua Cheat SheetGE Developer RecipesMCP Server Setup

// RLS.STUDIOS=true

Premium Mods for BeamNG.drive. Career systems, custom vehicles, and immersive gameplay experiences.

Index

HomeProjectsPatreon

Socials

DiscordPatreon (RLS)Patreon (Vehicles)

© 2026 RLS Studios. All rights reserved.

Modding since 2024

API ReferenceGE ExtensionsClient

Depth of Field PostFX

Multi-pass depth-of-field post-processing effect with auto-focus support (vehicle tracking or center raycast) and configurable near/far blur equations.

Multi-pass depth-of-field post-processing effect with auto-focus support (vehicle tracking or center raycast) and configurable near/far blur equations.


Module Overview

PropertyValue
Sourcelua/ge/client/postFx/dof.lua
ReturnsModule table M
DependenciesPFX_DefaultStateBlock, camera system, vehicle system

Public Functions

FunctionArgsReturnsDescription
M.updateDOFSettings--Reads $DOFPostFx::* vars, applies to PostEffect, enables/disables

Local API Functions (on PostEffect object)

FunctionArgsDescription
setFocalDistdof, distSet manual focal distance (ignored if auto-focus on)
setAutoFocusdof, enabledToggle auto-focus mode
setDebugModedof, enabledToggle debug visualization
setFocusParamsdof, nearBlurMax, farBlurMax, minRange, maxRange, nearSlope, farSlopeConfigure blur curve parameters
setLerpDistdof, d0, d1, d2Set CoC distribution weights (small/medium/large blur)

PostEffect Chain (5 Passes)

PassPostEffectShaderInputOutput
1. DownsampleDOFPostEffectPFX_DOFDownSampleShader$backBuffer + prepass#shrunk (40%)
2. Blur YDOFBlurYPFX_DOFBlurYShader#shrunk$outTex
3. Blur XDOFBlurXPFX_DOFBlurXShader$inTex#largeBlur
4. Calc CoCDOFCalcCoCPFX_DOFCalcCoCShader#shrunk + #largeBlur$outTex
5. Small blurDOFSmallBlurPFX_DOFSmallBlurShader$inTex$outTex
6. Final compositeDOFFinalPFXPFX_DOFFinalShader$backBuffer + blurs + prepass$backBuffer

All intermediate targets use GFXFormatR16G16B16A16F (half-float).


Auto-Focus System

Focus Distance Calculation

  1. Vehicle tracking: If player vehicle exists and is in camera frustum, focus on vehicle distance
  2. Center raycast: Fallback - raycast from camera center against static/terrain/vehicle/dynamic masks
  3. Far distance: If nothing hit, use $Param::FarDist

Temporal Smoothing

  • Uses newTemporalSmoothing() with rate 150 for smooth focus transitions
  • Applied via viewSmoother:getWithRateUncapped()

Blur Curve Model

Bluriness (0-1)
|   __(ns,nb)                         (fe,fb)__
|       \  ←near eq    far eq→  /
|        \                     /
|         \(ne,0)------(fs,0)/
Depth (0-1)

ns = near blur start     nb = near blur max
ne = near blur end        fs = far blur start
fe = far blur end         fb = far blur max

Near and far blur equations are linear: y = slope * x + bias, evaluated per-pixel.


Shader Constants (DOFFinalPFX)

ConstantTypeDescription
$dofEqWorldfloat3Near blur equation (slope, bias, 0)
$dofEqFarfloat3Far blur equation (slope, bias, 1)
$maxWorldCoCfloatMax near blur amount
$maxFarCoCfloatMax far blur amount
$dofLerpScalefloat4CoC distribution weights
$dofLerpBiasfloat4CoC distribution biases
$isDebugModestring"1" or "0"

Console Variables

VariablePurpose
$DOFPostFx::EnableEnable/disable DOF
$DOFPostFx::EnableAutoFocusAuto-focus toggle
$DOFPostFx::EnableDebugModeDebug visualization
$DOFPostFx::BlurMin / BlurMaxNear/far max blur
$DOFPostFx::FocusRangeMin / FocusRangeMaxFocus range extents
$DOFPostFx::BlurCurveNear / BlurCurveFarSlope of blur curves

Globals Set

GlobalTypeDescription
DOFPostEffectCallbackstableonAdd and setShaderConsts callbacks

State Blocks

ObjectPurpose
PFX_DefaultDOFStateBlockPoint sampling, z-disabled
PFX_DOFCalcCoCStateBlockLinear sampling for CoC calculation
PFX_DOFDownSampleStateBlockMixed linear/point for downsample
PFX_DOFBlurStateBlockLinear clamped for blur
PFX_DOFFinalStateBlockAlpha blend (One, InvSrcAlpha) for composite

Usage Example

-- Enable DOF with auto-focus
local dof = scenetree.findObject("DOFPostEffect")
if dof then
  setFocusParams(dof, 0.3, 0.3, 50, 500, -5, 5)
  setAutoFocus(dof, true)
  dof:enable()
end

-- Update from preset
local dofModule = require("client/postFx/dof")
dofModule.updateDOFSettings()

Notes

  • Based on GPU Gems 3, Chapter 28 (DOF technique).
  • Disabled by default.
  • Focus range expands with distance (min/maxRange lerped by normalized focal depth).
  • The downsample target is 40% resolution (targetScale = "0.4 0.4").
  • Reference paper: http://developer.nvidia.com/GPUGems3/gpugems3_ch28.html

See Also

  • client/postFx - PostFX manager (applies DOF presets)

Client Core

Initializes core rendering resources: materials, shaders, state blocks, and sampler states required by the engine's rendering pipeline.

Edge AA PostFX

Two-pass edge-detect anti-aliasing: first pass detects edges from the prepass buffer, second pass smooths them.

On this page

Module OverviewPublic FunctionsLocal API Functions (on PostEffect object)PostEffect Chain (5 Passes)Auto-Focus SystemFocus Distance CalculationTemporal SmoothingBlur Curve ModelShader Constants (DOFFinalPFX)Console VariablesGlobals SetState BlocksUsage ExampleNotesSee Also