CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
Unreal
CarlaUnreal
Plugins
Carla
Source
Carla
Sensor
ShaderBasedSensor_WideAngleLens.cpp
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
#include "
Carla/Sensor/ShaderBasedSensor_WideAngleLens.h
"
8
#include "
Carla.h
"
9
#include "
Actor/ActorBlueprintFunctionLibrary.h
"
10
11
#include <util/ue-header-guard-begin.h>
12
#include "Materials/Material.h"
13
#include "Materials/MaterialInstanceDynamic.h"
14
#include <util/ue-header-guard-end.h>
15
16
AShaderBasedSensor_WideAngleLens::AShaderBasedSensor_WideAngleLens
(
const
FObjectInitializer& ObjectInitializer) :
17
Super(ObjectInitializer)
18
{
19
EnablePostProcessingEffects
(
false
);
20
}
21
22
bool
AShaderBasedSensor_WideAngleLens::AddPostProcessingMaterial
(
const
FString& Path)
23
{
24
// ConstructorHelpers::FObjectFinder is documented as constructor-only and
25
// has undefined behavior when used from runtime functions. FSoftObjectPath
26
// is the runtime-safe path resolver; it accepts both plain object paths
27
// and the class-prefixed export-text form ("Material'/Game/.../Foo'") that
28
// FObjectFinder previously normalised internally.
29
UMaterial* Material = Cast<UMaterial>(FSoftObjectPath(Path).TryLoad());
30
if
(Material !=
nullptr
)
31
{
32
MaterialsFound
.Add(Material);
33
return
true
;
34
}
35
UE_LOG(LogCarla, Error,
36
TEXT(
"AShaderBasedSensor_WideAngleLens::AddPostProcessingMaterial: failed to load material '%s'"
),
37
*Path);
38
return
false
;
39
}
40
41
void
AShaderBasedSensor_WideAngleLens::SetUpSceneCaptureComponents
(TArrayView<USceneCaptureComponent2D_CARLA*> SceneCaptures)
42
{
43
// Create one dynamic instance per post-processing material. The six face
44
// captures of a wide-angle sensor must share an identical post-process
45
// chain, so the instances are created once and reused across all faces.
46
// Creating them inside the per-face loop would append 6x the materials to
47
// the shared Shaders array and give each face a different blendable set.
48
for
(
const
auto
& MaterialFound :
MaterialsFound
)
49
{
50
// Create a dynamic instance of the Material (Shader)
51
AddShader
({ UMaterialInstanceDynamic::Create(MaterialFound,
this
), 1.0 });
52
}
53
54
for
(
auto
SceneCapture : SceneCaptures)
55
{
56
for
(
const
auto
& Shader :
Shaders
)
57
{
58
// Attach the instance into the blendables
59
SceneCapture->PostProcessSettings.AddBlendable(Shader.PostProcessMaterial, Shader.Weight);
60
}
61
}
62
63
// Set the value for each Float parameter in the shader. The dynamic
64
// material instances are shared across faces, so each parameter only
65
// needs to be applied once.
66
if
(
Shaders
.Num() != 0)
67
{
68
for
(
const
auto
& ParameterValue :
FloatShaderParams
)
69
{
70
Shaders
[ParameterValue.ShaderIndex].PostProcessMaterial->SetScalarParameterValue(
71
ParameterValue.ParameterName,
72
ParameterValue.Value);
73
}
74
}
75
}
76
77
void
AShaderBasedSensor_WideAngleLens::Set
(
const
FActorDescription
& Description)
78
{
79
Super::Set(Description);
80
UActorBlueprintFunctionLibrary::SetCamera
(Description,
this
);
81
}
82
83
void
AShaderBasedSensor_WideAngleLens::SetFloatShaderParameter
(
84
uint8_t ShaderIndex,
85
const
FName& ParameterName,
86
float
Value)
87
{
88
FloatShaderParams
.Add({ ShaderIndex, ParameterName, Value });
89
}
ActorBlueprintFunctionLibrary.h
Carla.h
ShaderBasedSensor_WideAngleLens.h
ASceneCaptureSensor_WideAngleLens::EnablePostProcessingEffects
void EnablePostProcessingEffects(bool Enable=true)
Definition
SceneCaptureSensor_WideAngleLens.h:81
AShaderBasedSensor_WideAngleLens::Set
void Set(const FActorDescription &ActorDescription) override
Definition
ShaderBasedSensor_WideAngleLens.cpp:77
AShaderBasedSensor_WideAngleLens::Shaders
TArray< FSensorShader > Shaders
Definition
ShaderBasedSensor_WideAngleLens.h:47
AShaderBasedSensor_WideAngleLens::FloatShaderParams
TArray< FShaderFloatParameterValue > FloatShaderParams
Definition
ShaderBasedSensor_WideAngleLens.h:50
AShaderBasedSensor_WideAngleLens::MaterialsFound
TArray< TObjectPtr< UMaterial > > MaterialsFound
Definition
ShaderBasedSensor_WideAngleLens.h:44
AShaderBasedSensor_WideAngleLens::AShaderBasedSensor_WideAngleLens
AShaderBasedSensor_WideAngleLens(const FObjectInitializer &ObjectInitializer)
Definition
ShaderBasedSensor_WideAngleLens.cpp:16
AShaderBasedSensor_WideAngleLens::AddPostProcessingMaterial
bool AddPostProcessingMaterial(const FString &Path)
Definition
ShaderBasedSensor_WideAngleLens.cpp:22
AShaderBasedSensor_WideAngleLens::SetUpSceneCaptureComponents
void SetUpSceneCaptureComponents(TArrayView< USceneCaptureComponent2D_CARLA * > SceneCaptures) override
Definition
ShaderBasedSensor_WideAngleLens.cpp:41
AShaderBasedSensor_WideAngleLens::SetFloatShaderParameter
void SetFloatShaderParameter(uint8_t ShaderIndex, const FName &ParameterName, float Value)
Definition
ShaderBasedSensor_WideAngleLens.cpp:83
AShaderBasedSensor_WideAngleLens::AddShader
void AddShader(const FSensorShader &Shader)
Add a post-processing shader.
Definition
ShaderBasedSensor_WideAngleLens.h:30
UActorBlueprintFunctionLibrary::SetCamera
static void SetCamera(const FActorDescription &Description, ASceneCaptureSensor *Camera)
Definition
ActorBlueprintFunctionLibrary.cpp:2299
FActorDescription
A description of a Carla Actor with all its variation.
Definition
Unreal/CarlaUnreal/Plugins/Carla/Source/Carla/Actor/ActorDescription.h:21
Generated by
1.18.0