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 
14 {
15  ConstructorHelpers::FObjectFinder<UMaterial> Loader(*Path);
16  if (Loader.Succeeded())
17  {
18  MaterialsFound.Add(Loader.Object);
19  }
20  return Loader.Succeeded();
21 }
22 
23 void AShaderBasedSensor::SetUpSceneCaptureComponent(USceneCaptureComponent2D &SceneCapture)
24 {
25  for (const auto &MaterialFound : MaterialsFound)
26  {
27  // Create a dynamic instance of the Material (Shader)
28  AddShader({UMaterialInstanceDynamic::Create(MaterialFound, this), 1.0});
29  }
30 
31  for (const auto &Shader : Shaders)
32  {
33  // Attach the instance into the blendables
34  SceneCapture.PostProcessSettings.AddBlendable(Shader.PostProcessMaterial, Shader.Weight);
35  }
36 
37  // Set the value for each Float parameter in the shader
38  for (const auto &ParameterValue : FloatShaderParams)
39  {
40  Shaders[ParameterValue.ShaderIndex].PostProcessMaterial->SetScalarParameterValue(
41  ParameterValue.ParameterName,
42  ParameterValue.Value);
43  }
44 }
45 
47 {
48  Super::Set(Description);
50 }
51 
53  uint8_t ShaderIndex,
54  const FName &ParameterName,
55  float Value)
56 {
57  FloatShaderParams.Add({ShaderIndex, ParameterName, Value});
58 }
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