CARLA
ShaderBasedSensor.h
Go to the documentation of this file.
1 // Copyright (c) 2017 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 /// A shader parameter value to change when the material
14 /// instance is available.
15 USTRUCT(BlueprintType)
17 {
18  GENERATED_BODY()
19 
20  UPROPERTY(EditAnywhere, BlueprintReadWrite)
21  int ShaderIndex;
22 
23  UPROPERTY(EditAnywhere, BlueprintReadWrite)
24  FName ParameterName;
25 
26  UPROPERTY(EditAnywhere, BlueprintReadWrite)
27  float Value = 0.0f;
28 };
29 
30 /// A shader in AShaderBasedSensor.
31 USTRUCT(BlueprintType)
32 struct CARLA_API FSensorShader
33 {
34  GENERATED_BODY()
35 
36  UPROPERTY(EditAnywhere, BlueprintReadWrite)
37  UMaterialInstanceDynamic *PostProcessMaterial = nullptr;
38 
39  UPROPERTY(EditAnywhere, BlueprintReadWrite)
40  float Weight = 1.0f;
41 };
42 
43 /// A sensor that produces data by applying post-process materials (shaders) to
44 /// a scene capture image.
45 ///
46 /// @warning Shaders must be added before BeginPlay.
47 UCLASS(Abstract)
48 class CARLA_API AShaderBasedSensor : public ASceneCaptureSensor
49 {
50  GENERATED_BODY()
51 
52 public:
53 
54  AShaderBasedSensor(const FObjectInitializer &ObjectInitializer)
55  : Super(ObjectInitializer)
56  {
57  EnablePostProcessingEffects(false);
58  }
59 
60  void Set(const FActorDescription &ActorDescription) override;
61 
62  /// Load the UMaterialInstanceDynamic at the given @a Path and
63  /// append it to the list of shaders with @a Weight.
64  ///
65  /// @return Whether it succeeded.
66  UFUNCTION(BlueprintCallable)
67  // bool LoadPostProcessingMaterial(const FString &Path, float Weight = 1.0f);
68  bool AddPostProcessingMaterial(const FString &Path);
69 
70  /// Add a post-processing shader.
71  UFUNCTION(BlueprintCallable)
72  void AddShader(const FSensorShader &Shader)
73  {
74  Shaders.Add(Shader);
75  }
76 
77  void SetFloatShaderParameter(uint8_t ShaderIndex, const FName &ParameterName, float Value);
78 
79 protected:
80 
81  void SetUpSceneCaptureComponent(USceneCaptureComponent2D &SceneCapture) override;
82 
83 private:
84 
85  UPROPERTY()
86  TArray<UMaterial*> MaterialsFound;
87 
88  UPROPERTY()
89  TArray<FSensorShader> Shaders;
90 
91  UPROPERTY()
92  TArray<FShaderFloatParameterValue> FloatShaderParams;
93 };
std::vector< cg::Location > Path
A shader parameter value to change when the material instance is available.
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.
Base class for sensors using a USceneCaptureComponent2D for rendering the scene.
AShaderBasedSensor(const FObjectInitializer &ObjectInitializer)
A shader in AShaderBasedSensor.