CARLA
ShaderBasedSensor.cpp
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 #include "Carla.h"
9 
10 #include "ConstructorHelpers.h"
11 #include "Materials/MaterialInstanceDynamic.h"
12 #include "Components/SceneCaptureComponent2D.h"
14 
16 {
17  ConstructorHelpers::FObjectFinder<UMaterial> Loader(*Path);
18  if (Loader.Succeeded())
19  {
20  MaterialsFound.Add(Loader.Object);
21  }
22  return Loader.Succeeded();
23 }
24 
26 {
27  for (const auto &MaterialFound : MaterialsFound)
28  {
29  // Create a dynamic instance of the Material (Shader)
30  AddShader({UMaterialInstanceDynamic::Create(MaterialFound, this), 1.0});
31  }
32 
33  for (const auto &Shader : Shaders)
34  {
35  // Attach the instance into the blendables
36  SceneCapture.PostProcessSettings.AddBlendable(Shader.PostProcessMaterial, Shader.Weight);
37  }
38 
39  // Set the value for each Float parameter in the shader
40  for (const auto &ParameterValue : FloatShaderParams)
41  {
42  Shaders[ParameterValue.ShaderIndex].PostProcessMaterial->SetScalarParameterValue(
43  ParameterValue.ParameterName,
44  ParameterValue.Value);
45  }
46 }
47 
49 {
50  Super::Set(Description);
52 }
53 
55  uint8_t ShaderIndex,
56  const FName &ParameterName,
57  float Value)
58 {
59  FloatShaderParams.Add({ShaderIndex, ParameterName, Value});
60 }
TArray< FShaderFloatParameterValue > FloatShaderParams
void SetFloatShaderParameter(uint8_t ShaderIndex, const FName &ParameterName, float Value)
std::vector< cg::Location > Path
TArray< UMaterial * > MaterialsFound
bool AddPostProcessingMaterial(const FString &Path)
Load the UMaterialInstanceDynamic at the given Path and append it to the list of shaders with Weight...
static void SetCamera(const FActorDescription &Description, ASceneCaptureSensor *Camera)
void Set(const FActorDescription &ActorDescription) override
A description of a Carla Actor with all its variation.
void AddShader(const FSensorShader &Shader)
Add a post-processing shader.
TArray< FSensorShader > Shaders
void SetUpSceneCaptureComponent(USceneCaptureComponent2D &SceneCapture) override