CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
Unreal
CarlaUnreal
Plugins
Carla
Source
Carla
Sensor
ShaderBasedSensor.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/Sensor/SceneCaptureSensor.h
"
10
11
#include "ShaderBasedSensor.generated.h"
12
13
14
15
/* @CARLA_UE5
16
17
The FPixelReader class has been deprecated, as its functionality
18
is now split between ImageUtil::ReadImageDataAsync (see Sensor/ImageUtil.h)
19
and ASensor::SendDataToClient.
20
Here's a brief example of how to use both:
21
22
if (!AreClientsListening()) // Ideally, check whether there are any clients.
23
return;
24
25
auto CaptureContext = MakeCaptureContext(*this);
26
ImageUtil::ReadImageDataAsync(
27
*GetCaptureRenderTarget(),
28
[this, CaptureContext](
29
const void* MappedPtr,
30
size_t RowPitch,
31
size_t BufferHeight,
32
EPixelFormat Format,
33
FIntPoint Extent)
34
{
35
TArray<FColor> ImageData;
36
// Parse the raw data into ImageData...
37
SendDataToClient(
38
*this,
39
ImageData,
40
CaptureContext);
41
return true;
42
});
43
44
Alternatively, if you just want to retrieve the pixels as
45
FColor/FLinearColor, you can just use ReadImageDataAsyncFColor
46
or ReadImageDataAsyncFLinearColor.
47
48
*/
49
50
51
52
/// A shader parameter value to change when the material
53
/// instance is available.
54
USTRUCT(BlueprintType)
55
struct CARLA_API
FShaderFloatParameterValue
56
{
57
GENERATED_BODY()
58
59
UPROPERTY(EditAnywhere, BlueprintReadWrite)
60
int
ShaderIndex
= -1;
61
62
UPROPERTY(EditAnywhere, BlueprintReadWrite)
63
FName
ParameterName
;
64
65
UPROPERTY(EditAnywhere, BlueprintReadWrite)
66
float
Value
= 0.0f;
67
};
68
69
70
71
/// A shader in AShaderBasedSensor.
72
USTRUCT(BlueprintType)
73
struct CARLA_API
FSensorShader
74
{
75
GENERATED_BODY()
76
77
UPROPERTY(EditAnywhere, BlueprintReadWrite)
78
UMaterialInstanceDynamic *
PostProcessMaterial
=
nullptr
;
79
80
UPROPERTY(EditAnywhere, BlueprintReadWrite)
81
float
Weight
= 1.0f;
82
};
83
84
85
86
/// A sensor that produces data by applying post-process materials (shaders) to
87
/// a scene capture image.
88
///
89
/// @warning Shaders must be added before BeginPlay.
90
UCLASS(Abstract)
91
class CARLA_API
AShaderBasedSensor
: public
ASceneCaptureSensor
92
{
93
GENERATED_BODY()
94
95
public
:
96
97
AShaderBasedSensor
(
const
FObjectInitializer &ObjectInitializer);
98
99
void
Set
(
const
FActorDescription
&ActorDescription)
override
;
100
101
/// Load the UMaterialInstanceDynamic at the given @a Path and
102
/// append it to the list of shaders with @a Weight.
103
///
104
/// @return Whether it succeeded.
105
UFUNCTION(BlueprintCallable)
106
// bool LoadPostProcessingMaterial(const FString &Path, float Weight = 1.0f);
107
bool
AddPostProcessingMaterial
(
const
FString &Path);
108
109
/// Add a post-processing shader.
110
UFUNCTION(BlueprintCallable)
111
void
AddShader
(const
FSensorShader
&Shader)
112
{
113
Shaders
.Add(Shader);
114
}
115
116
void
SetFloatShaderParameter(uint8_t ShaderIndex,
const
FName &ParameterName,
float
Value);
117
118
protected
:
119
120
void
SetUpSceneCaptureComponent(
USceneCaptureComponent2D
&SceneCapture)
override
;
121
122
private
:
123
124
UPROPERTY()
125
TArray<TObjectPtr<UMaterial>>
MaterialsFound
;
126
127
UPROPERTY()
128
TArray<
FSensorShader
>
Shaders
;
129
130
UPROPERTY()
131
TArray<
FShaderFloatParameterValue
>
FloatShaderParams
;
132
};
SceneCaptureSensor.h
ASceneCaptureSensor::ASceneCaptureSensor
ASceneCaptureSensor(const FObjectInitializer &ObjectInitializer)
Definition
SceneCaptureSensor.cpp:135
AShaderBasedSensor::Set
void Set(const FActorDescription &ActorDescription) override
Definition
ShaderBasedSensor.cpp:65
AShaderBasedSensor::Shaders
TArray< FSensorShader > Shaders
Definition
ShaderBasedSensor.h:128
AShaderBasedSensor::AShaderBasedSensor
AShaderBasedSensor(const FObjectInitializer &ObjectInitializer)
Definition
ShaderBasedSensor.cpp:17
AShaderBasedSensor::MaterialsFound
TArray< TObjectPtr< UMaterial > > MaterialsFound
Definition
ShaderBasedSensor.h:125
AShaderBasedSensor::AddShader
void AddShader(const FSensorShader &Shader)
Add a post-processing shader.
Definition
ShaderBasedSensor.h:111
AShaderBasedSensor::FloatShaderParams
TArray< FShaderFloatParameterValue > FloatShaderParams
Definition
ShaderBasedSensor.h:131
AShaderBasedSensor::AddPostProcessingMaterial
bool AddPostProcessingMaterial(const FString &Path)
Load the UMaterialInstanceDynamic at the given Path and append it to the list of shaders with Weight.
Definition
ShaderBasedSensor.cpp:23
USceneCaptureComponent2D
FActorDescription
A description of a Carla Actor with all its variation.
Definition
Unreal/CarlaUnreal/Plugins/Carla/Source/Carla/Actor/ActorDescription.h:21
FSensorShader
A shader in AShaderBasedSensor.
Definition
ShaderBasedSensor.h:74
FSensorShader::Weight
float Weight
Definition
ShaderBasedSensor.h:81
FSensorShader::PostProcessMaterial
UMaterialInstanceDynamic * PostProcessMaterial
Definition
ShaderBasedSensor.h:78
FShaderFloatParameterValue
A shader parameter value to change when the material instance is available.
Definition
ShaderBasedSensor.h:56
FShaderFloatParameterValue::ParameterName
FName ParameterName
Definition
ShaderBasedSensor.h:63
FShaderFloatParameterValue::Value
float Value
Definition
ShaderBasedSensor.h:66
FShaderFloatParameterValue::ShaderIndex
int ShaderIndex
Definition
ShaderBasedSensor.h:60
Generated by
1.18.0