CARLA
Loading...
Searching...
No Matches
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
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.
54USTRUCT(BlueprintType)
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.
72USTRUCT(BlueprintType)
73struct 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.
90UCLASS(Abstract)
92{
93 GENERATED_BODY()
94
95public:
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
118protected:
119
120 void SetUpSceneCaptureComponent(USceneCaptureComponent2D &SceneCapture) override;
121
122private:
123
124 UPROPERTY()
125 TArray<TObjectPtr<UMaterial>> MaterialsFound;
126
127 UPROPERTY()
128 TArray<FSensorShader> Shaders;
129
130 UPROPERTY()
131 TArray<FShaderFloatParameterValue> FloatShaderParams;
132};
Base class for sensors using a USceneCaptureComponent2D for rendering the scene.
A sensor that produces data by applying post-process materials (shaders) to a scene capture image.
A description of a Carla Actor with all its variation.
A shader in AShaderBasedSensor.
A shader parameter value to change when the material instance is available.