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
15// 添加后处理材质
17{
18 // 使用路径加载材质
19 ConstructorHelpers::FObjectFinder<UMaterial> Loader(*Path);
20 if (Loader.Succeeded())
21 {
22 // 如果加载成功,将材质添加到已找到的材质列表中
23 MaterialsFound.Add(Loader.Object);
24 }
25 return Loader.Succeeded(); // 返回是否加载成功
26}
27
28// 配置场景捕捉组件
30{
31 for (const auto &MaterialFound : MaterialsFound)
32 {
33 // 创建材质(着色器)的动态实例
34 AddShader({UMaterialInstanceDynamic::Create(MaterialFound, this), 1.0});
35 }
36
37 for (const auto &Shader : Shaders)
38 {
39 // 将动态实例附加到后期处理的混合设置中
40 SceneCapture.PostProcessSettings.AddBlendable(Shader.PostProcessMaterial, Shader.Weight);
41 }
42
43 // 设置着色器中每个浮点参数的值
44 for (const auto &ParameterValue : FloatShaderParams)
45 {
46 Shaders[ParameterValue.ShaderIndex].PostProcessMaterial->SetScalarParameterValue(
47 ParameterValue.ParameterName,
48 ParameterValue.Value);
49 }
50}
51
52// 设置实体属性
54{
55 Super::Set(Description); // 调用父类的 Set 方法
56 // 设置摄像机属性
58}
59
60// 设置浮点类型的着色器参数
62 uint8_t ShaderIndex,
63 const FName &ParameterName,
64 float Value)
65{
66 // 将参数添加到浮点着色器参数列表中
67 FloatShaderParams.Add({ShaderIndex, ParameterName, Value});
68}
69
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)