CARLA
Loading...
Searching...
No Matches
SceneCaptureCamera_RayTracedLens.h
Go to the documentation of this file.
1// Copyright (c) 2026 Computer Vision Center (CVC) at the Universitat Autonoma
2// de Barcelona (UAB).
3//
4// This work is licensed under the terms of the MIT license.
5// For a copy, see <https://opensource.org/licenses/MIT>.
6
7#pragma once
8
12
13#include <util/ue-header-guard-begin.h>
15#include <util/ue-header-guard-end.h>
16
17#include "SceneCaptureCamera_RayTracedLens.generated.h"
18
19/// A path-traced camera sensor ("sensor.camera.rt_lens") that renders through
20/// a configurable lens model (see Util/CameraModelUtil.h for the model
21/// contract) instead of the stock linear pinhole projection.
22///
23/// Unlike ASceneCaptureCamera_WideAngleLens, the lens distortion here is not
24/// a 2D post-process warp applied to a rasterized cubemap: the lens model is
25/// evaluated per-ray inside the path tracer itself, via genuine per-view
26/// FPostProcessSettings fields (see RTLensEngineAdapter.h), so multiple
27/// simultaneous rt_lens cameras with different lens models do not interfere
28/// with each other. Consequently this sensor captures through a single
29/// USceneCaptureComponent2D, exactly like ASceneCaptureCamera, and reuses the
30/// same standard RGB readback path instead of the WideAngleLens family's
31/// 6-face cubemap + compute-shader resample pipeline.
32UCLASS()
34{
35 GENERATED_BODY()
36
37public:
38
39 static FActorDefinition GetSensorDefinition();
40
41 ASceneCaptureCamera_RayTracedLens(const FObjectInitializer &ObjectInitializer);
42
43 void Set(const FActorDescription &ActorDescription) override;
44
45protected:
46
47 void PostPhysTick(UWorld *World, ELevelTick TickType, float DeltaSeconds) override;
48
49 /// Restores r.RayTracing.NonBlockingPipelineCreation if this sensor left it
50 /// at 0 (synchronous mode, see PostPhysTick): the override is process-wide
51 /// and would otherwise outlive the sensor, making every other ray tracing
52 /// pipeline in the process (Lumen, reflections) block on compiles. Another
53 /// live rt_lens sensor re-applies it on its next tick.
54 void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
55
56 /// Forces path-tracing view mode for this sensor's capture. Hooked through
57 /// the same extension point ASceneCaptureSensor::BeginPlay already calls
58 /// for every subclass, so no BeginPlay override is needed here.
59 void UpdatePostProcessConfig(FPostProcessConfig &InOutPostProcessConfig) override;
60
61 bool RequiresRayTracing() const override
62 {
63 return true;
64 }
65
66 virtual void OnFirstClientConnected() override;
67 virtual void OnLastClientDisconnected() override;
68
69 /// Runs this tick's capture and this tick's readback in the order the world's
70 /// synchronization mode requires, then returns. Every path-traced lens sensor
71 /// must go through here so colour and AOV cameras stay on the same frame.
72 ///
73 /// EnqueueReadback is invoked at most once, only when clients are listening,
74 /// with the bNonBlocking flag to hand to the ImageUtil::ReadImageData*
75 /// overload; the callee just issues its own read of GetCaptureRenderTarget().
76 ///
77 /// Synchronous mode: capture first, then a BLOCKING readback of what was just
78 /// rendered, delivered by FSensorManager's single per-tick
79 /// ImageUtil::FlushBatchedReadbacks() GPU sync -- the frame the client gets
80 /// for tick k is tick k's render and cannot be dropped.
81 /// Asynchronous mode: readback first (of the previous tick's pixels), then
82 /// capture, never waiting on the render thread -- one tick of latency and
83 /// frames may drop under load, but the server cannot stall.
84 ///
85 /// Context is the capture metadata matching the pixels this readback will
86 /// pull: this tick's in synchronous mode, the PREVIOUS tick's in async mode.
87 void TickCaptureAndReadback(
88 UWorld *World,
89 ELevelTick TickType,
90 float DeltaSeconds,
91 TFunctionRef<void(bool bNonBlocking, const FSensorCaptureContext &Context)> EnqueueReadback);
92
93 // Protected rather than private so subclasses that render the same lens into
94 // a different output (ASceneCaptureCamera_RayTracedLensDistance,
95 // ASceneCaptureCamera_RayTracedLensInstance) can reuse this class's
96 // Set()/TickCaptureAndReadback() wholesale and only adjust these knobs --
97 // PostPhysTick reasserts them every tick, so a subclass cannot override them
98 // by writing PostProcessSettings directly.
99
100 /// Pins the capture's auto exposure to the daylight histogram window
101 /// (EV100 10-12, same as the viewport). Without this the path-traced
102 /// view's eye adaptation can meter the raw sun-disk radiance and adapt
103 /// far past the clamp the world volumes intend, blacking out the image.
104 void SetRayTracedLensExposure();
105
106 /// Resolved lens-model parameters, rebuilt in Set() from the
107 /// camera_model / distortion_coeffs / lut / fx / fy / cx / cy /
108 /// theta_max_deg / ca_shift_r / ca_shift_b Blueprint attributes and pushed
109 /// into CaptureComponent2D->PostProcessSettings there via
110 /// RTLensEngineAdapter::ApplyLensModel. Kept as a member (rather than a
111 /// Set()-local) purely for inspection/debugging.
113
114 /// Path-tracer quality knobs. These map directly onto genuine per-view
115 /// engine fields (FPostProcessSettings::PathTracingSamplesPerPixel /
116 /// PathTracingEnableDenoiser, see Engine/Classes/Engine/Scene.h), so unlike
117 /// LensModel they do not need the RTLensEngineAdapter seam.
118 int32 SamplesPerPixel = 16;
119 bool bEnableDenoiser = true;
120
121private:
122
123 /// Capture metadata for what is currently in the render target (see
124 /// TickCaptureAndReadback).
126 bool bHasPendingReadbackContext = false;
127};
A path-traced camera sensor ("sensor.camera.rt_lens") that renders through a configurable lens model ...
FLensModelDescriptor LensModel
Resolved lens-model parameters, rebuilt in Set() from the camera_model / distortion_coeffs / lut / fx...
FSensorCaptureContext PendingReadbackContext
Capture metadata for what is currently in the render target (see TickCaptureAndReadback).
bool RequiresRayTracing() const override
True for sensors that cannot render without hardware ray tracing (path-traced lens cameras); the tier...
Base class for sensors using a USceneCaptureComponent2D for rendering the scene.
A definition of a Carla Actor with all the variation and attributes.
A description of a Carla Actor with all its variation.
Sensor frame metadata snapshotted at capture time, carried by value through async delivery instead of...