CARLA
 
载入中...
搜索中...
未找到
ShaderBasedSensor.cpp
浏览该文件的文档.
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}
void Set(const FActorDescription &ActorDescription) override
TArray< UMaterial * > MaterialsFound
TArray< FSensorShader > Shaders
void AddShader(const FSensorShader &Shader)
Add a post-processing shader.
void SetUpSceneCaptureComponent(USceneCaptureComponent2D &SceneCapture) override
TArray< FShaderFloatParameterValue > FloatShaderParams
bool AddPostProcessingMaterial(const FString &Path)
Load the UMaterialInstanceDynamic at the given Path and append it to the list of shaders with Weight.
void SetFloatShaderParameter(uint8_t ShaderIndex, const FName &ParameterName, float Value)
static void SetCamera(const FActorDescription &Description, ASceneCaptureSensor *Camera)
A description of a Carla Actor with all its variation.