CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
Unreal
CarlaUnreal
Plugins
Carla
Source
Carla
Sensor
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
9
#include "
Carla/Actor/ActorDefinition.h
"
10
#include "
Carla/Sensor/SceneCaptureSensor.h
"
11
#include "
Carla/Util/CameraModelUtil.h
"
12
13
#include <util/ue-header-guard-begin.h>
14
#include "
Actor/ActorBlueprintFunctionLibrary.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.
32
UCLASS()
33
class CARLA_API
ASceneCaptureCamera_RayTracedLens
: public
ASceneCaptureSensor
34
{
35
GENERATED_BODY()
36
37
public
:
38
39
static
FActorDefinition
GetSensorDefinition
();
40
41
ASceneCaptureCamera_RayTracedLens
(
const
FObjectInitializer &ObjectInitializer);
42
43
void
Set
(
const
FActorDescription
&ActorDescription)
override
;
44
45
protected
:
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.
112
FLensModelDescriptor
LensModel
;
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
121
private
:
122
123
/// Capture metadata for what is currently in the render target (see
124
/// TickCaptureAndReadback).
125
FSensorCaptureContext
PendingReadbackContext
;
126
bool
bHasPendingReadbackContext
=
false
;
127
};
ActorBlueprintFunctionLibrary.h
CameraModelUtil.h
SceneCaptureSensor.h
ActorDefinition.h
ASceneCaptureCamera_RayTracedLens::ASceneCaptureCamera_RayTracedLens
ASceneCaptureCamera_RayTracedLens(const FObjectInitializer &ObjectInitializer)
Definition
SceneCaptureCamera_RayTracedLens.cpp:156
ASceneCaptureCamera_RayTracedLens::UpdatePostProcessConfig
void UpdatePostProcessConfig(FPostProcessConfig &InOutPostProcessConfig) override
Forces path-tracing view mode for this sensor's capture.
Definition
SceneCaptureCamera_RayTracedLens.cpp:351
ASceneCaptureCamera_RayTracedLens::EndPlay
void EndPlay(const EEndPlayReason::Type EndPlayReason) override
Restores r.RayTracing.NonBlockingPipelineCreation if this sensor left it at 0 (synchronous mode,...
Definition
SceneCaptureCamera_RayTracedLens.cpp:365
ASceneCaptureCamera_RayTracedLens::PostPhysTick
void PostPhysTick(UWorld *World, ELevelTick TickType, float DeltaSeconds) override
Definition
SceneCaptureCamera_RayTracedLens.cpp:374
ASceneCaptureCamera_RayTracedLens::LensModel
FLensModelDescriptor LensModel
Resolved lens-model parameters, rebuilt in Set() from the camera_model / distortion_coeffs / lut / fx...
Definition
SceneCaptureCamera_RayTracedLens.h:112
ASceneCaptureCamera_RayTracedLens::SamplesPerPixel
int32 SamplesPerPixel
Path-tracer quality knobs.
Definition
SceneCaptureCamera_RayTracedLens.h:118
ASceneCaptureCamera_RayTracedLens::PendingReadbackContext
FSensorCaptureContext PendingReadbackContext
Capture metadata for what is currently in the render target (see TickCaptureAndReadback).
Definition
SceneCaptureCamera_RayTracedLens.h:125
ASceneCaptureCamera_RayTracedLens::GetSensorDefinition
static FActorDefinition GetSensorDefinition()
Definition
SceneCaptureCamera_RayTracedLens.cpp:148
ASceneCaptureCamera_RayTracedLens::bEnableDenoiser
bool bEnableDenoiser
Definition
SceneCaptureCamera_RayTracedLens.h:119
ASceneCaptureCamera_RayTracedLens::bHasPendingReadbackContext
bool bHasPendingReadbackContext
Definition
SceneCaptureCamera_RayTracedLens.h:126
ASceneCaptureCamera_RayTracedLens::RequiresRayTracing
bool RequiresRayTracing() const override
True for sensors that cannot render without hardware ray tracing (path-traced lens cameras); the tier...
Definition
SceneCaptureCamera_RayTracedLens.h:61
ASceneCaptureCamera_RayTracedLens::Set
void Set(const FActorDescription &ActorDescription) override
Definition
SceneCaptureCamera_RayTracedLens.cpp:194
ASceneCaptureSensor::ASceneCaptureSensor
ASceneCaptureSensor(const FObjectInitializer &ObjectInitializer)
Definition
SceneCaptureSensor.cpp:135
FPostProcessConfig
Definition
PostProcessConfig.h:7
FActorDefinition
A definition of a Carla Actor with all the variation and attributes.
Definition
Unreal/CarlaUnreal/Plugins/Carla/Source/Carla/Actor/ActorDefinition.h:20
FActorDescription
A description of a Carla Actor with all its variation.
Definition
Unreal/CarlaUnreal/Plugins/Carla/Source/Carla/Actor/ActorDescription.h:21
FLensModelDescriptor
Definition
CameraModelUtil.h:60
FSensorCaptureContext
Sensor frame metadata snapshotted at capture time, carried by value through async delivery instead of...
Definition
Unreal/CarlaUnreal/Plugins/Carla/Source/Carla/Sensor/Sensor.h:33
Generated by
1.18.0