Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add setting for overriding pixel format in capture component #4372

Merged
merged 5 commits into from
Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions AirLib/include/common/AirSimSettings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,17 @@ namespace airlib
float update_interval_secs = 60;
bool move_sun = true;
};

struct PixelFormatOverrideSetting
{
int image_type = 0;
int pixel_format = 0;
};

struct UnrealEngineSetting
{
std::map<int, PixelFormatOverrideSetting> pixel_format_override_settings;
};

private: //fields
float settings_version_actual;
Expand All @@ -374,6 +385,7 @@ namespace airlib
RecordingSetting recording_setting;
SegmentationSetting segmentation_setting;
TimeOfDaySetting tod_setting;
UnrealEngineSetting ue_setting;

std::vector<std::string> warning_messages;
std::vector<std::string> error_messages;
Expand Down Expand Up @@ -1147,6 +1159,33 @@ namespace airlib
tod_setting.move_sun = tod_settings_json.getBool("MoveSun", tod_setting.move_sun);
}
}

{ //unreal engine settings
Settings ue_settings_json;
if (settings_json.getChild("UnrealEngine", ue_settings_json)) {
Settings pixel_format_override_settings_json;
ue_setting.pixel_format_override_settings.clear();

for (int i = 0; i < 10; i++) {
zimmy87 marked this conversation as resolved.
Show resolved Hide resolved
PixelFormatOverrideSetting pixel_format_setting;
pixel_format_setting.image_type = i;
pixel_format_setting.pixel_format = 0;
ue_setting.pixel_format_override_settings[i] = pixel_format_setting;
zimmy87 marked this conversation as resolved.
Show resolved Hide resolved
}

if (ue_settings_json.getChild("PixelFormatOverride", pixel_format_override_settings_json)) {
for (size_t child_index = 0; child_index < pixel_format_override_settings_json.size(); ++child_index) {
Settings pixel_format_child_json;
if (pixel_format_override_settings_json.getChild(child_index, pixel_format_child_json)) {
int image_type = pixel_format_child_json.getInt("ImageType", 0);
PixelFormatOverrideSetting& pixel_format_setting = ue_setting.pixel_format_override_settings.at(image_type);
pixel_format_setting.image_type = image_type;
pixel_format_setting.pixel_format = pixel_format_child_json.getInt("PixelFormat", 0);
}
}
}
}
}

{
// Wind Settings
Expand Down
25 changes: 16 additions & 9 deletions Unreal/Plugins/AirSim/Source/PIPCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ APIPCamera::APIPCamera(const FObjectInitializer& ObjectInitializer)

PrimaryActorTick.bCanEverTick = true;

image_type_to_pixel_format_map_.Add(0, EPixelFormat::PF_FloatRGBA);
image_type_to_pixel_format_map_.Add(0, EPixelFormat::PF_B8G8R8A8);
zimmy87 marked this conversation as resolved.
Show resolved Hide resolved
image_type_to_pixel_format_map_.Add(1, EPixelFormat::PF_DepthStencil); // not used. init_auto_format is called in setupCameraFromSettings()
image_type_to_pixel_format_map_.Add(2, EPixelFormat::PF_DepthStencil); // not used for same reason as above
image_type_to_pixel_format_map_.Add(3, EPixelFormat::PF_DepthStencil); // not used for same reason as above
image_type_to_pixel_format_map_.Add(4, EPixelFormat::PF_DepthStencil); // not used for same reason as above
image_type_to_pixel_format_map_.Add(5, EPixelFormat::PF_FloatRGBA);
image_type_to_pixel_format_map_.Add(6, EPixelFormat::PF_FloatRGBA);
image_type_to_pixel_format_map_.Add(7, EPixelFormat::PF_FloatRGBA);
image_type_to_pixel_format_map_.Add(8, EPixelFormat::PF_FloatRGBA);
image_type_to_pixel_format_map_.Add(9, EPixelFormat::PF_FloatRGBA);
image_type_to_pixel_format_map_.Add(5, EPixelFormat::PF_B8G8R8A8);
image_type_to_pixel_format_map_.Add(6, EPixelFormat::PF_B8G8R8A8);
image_type_to_pixel_format_map_.Add(7, EPixelFormat::PF_B8G8R8A8);
image_type_to_pixel_format_map_.Add(8, EPixelFormat::PF_B8G8R8A8);
image_type_to_pixel_format_map_.Add(9, EPixelFormat::PF_B8G8R8A8);

object_filter_ = FObjectFilter();
}
Expand Down Expand Up @@ -382,19 +382,26 @@ void APIPCamera::setupCameraFromSettings(const APIPCamera::CameraSetting& camera
const auto& noise_setting = camera_setting.noise_settings.at(image_type);

if (image_type >= 0) { //scene capture components
auto pixel_format_override = AirSimSettings::singleton().ue_setting.pixel_format_override_settings.find(image_type);
EPixelFormat pixel_format = EPixelFormat::PF_Unknown;
if (pixel_format_override != AirSimSettings::singleton().ue_setting.pixel_format_override_settings.end()) {
pixel_format = static_cast<EPixelFormat>(pixel_format_override->second.pixel_format);
}
pixel_format = (pixel_format == EPixelFormat::PF_Unknown ? image_type_to_pixel_format_map_[image_type] : pixel_format);

switch (Utils::toEnum<ImageType>(image_type)) {
case ImageType::Scene:
case ImageType::Infrared:
updateCaptureComponentSetting(captures_[image_type], render_targets_[image_type], false, image_type_to_pixel_format_map_[image_type], capture_setting, ned_transform, false);
updateCaptureComponentSetting(captures_[image_type], render_targets_[image_type], false, pixel_format, capture_setting, ned_transform, false);
break;

case ImageType::Segmentation:
case ImageType::SurfaceNormals:
updateCaptureComponentSetting(captures_[image_type], render_targets_[image_type], true, image_type_to_pixel_format_map_[image_type], capture_setting, ned_transform, true);
updateCaptureComponentSetting(captures_[image_type], render_targets_[image_type], true, pixel_format, capture_setting, ned_transform, true);
break;

default:
updateCaptureComponentSetting(captures_[image_type], render_targets_[image_type], true, image_type_to_pixel_format_map_[image_type], capture_setting, ned_transform, false);
updateCaptureComponentSetting(captures_[image_type], render_targets_[image_type], true, pixel_format, capture_setting, ned_transform, false);
break;
}
setDistortionMaterial(image_type, captures_[image_type], captures_[image_type]->PostProcessSettings);
Expand Down