Skip to content

Commit

Permalink
Noise and capture settings working on captures as well as external ca…
Browse files Browse the repository at this point in the history
…mera
  • Loading branch information
sytelus committed Jan 12, 2018
1 parent 71c99cf commit 86e02f1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 18 deletions.
25 changes: 15 additions & 10 deletions AirLib/include/common/AirSimSettings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,24 @@ struct AirSimSettings {
int ImageType = 0;

bool Enabled = false;
float HorzWaveStrength = 0.01f;
float RandSpeed = 10.0f;
float RandSize = 300.0f;

float RandContrib = 0.2f;
float RandSpeed = 100000.0f;
float RandSize = 500.0f;
float RandDensity = 2.0f;
float RandContrib = 0.1f;
float HorzWaveContrib = 0.8f;
float HorzWaveVertSize = 100.0f;
float HorzWaveScreenSize = 50.0f;

float HorzWaveContrib = 0.03f;
float HorzWaveStrength = 0.08f;
float HorzWaveVertSize = 1.0f;
float HorzWaveScreenSize = 1.0f;

float HorzNoiseLinesContrib = 1.0f;
float HorzNoiseLinesDensityY = 0.01f;
float HorzNoiseLinesDensityXY = 0.1f;
float HorzDistortionStrength = 0.01f;
float HorzDistortionContrib = 0.5f;
float HorzNoiseLinesDensityXY = 0.5f;

float HorzDistortionContrib = 1.0f;
float HorzDistortionStrength = 0.002f;

};

private: //fields
Expand Down
21 changes: 16 additions & 5 deletions Unreal/Plugins/AirSim/Source/PIPCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ APIPCamera::APIPCamera()
else
UAirBlueprintLib::LogMessageString("Cannot create noise material for the PIPCamera",
"", LogDebugLevel::Failure);

noise_materials_.AddZeroed(imageTypeCount() + 1);
}

void APIPCamera::PostInitializeComponents()
Expand Down Expand Up @@ -62,8 +64,15 @@ void APIPCamera::BeginPlay()

void APIPCamera::EndPlay(const EEndPlayReason::Type EndPlayReason)
{
for (unsigned int image_type = 0; image_type < imageTypeCount(); ++image_type) {
if (noise_materials_[image_type + 1])
captures_[image_type]->PostProcessSettings.RemoveBlendable(noise_materials_[image_type + 1]);
}
if (noise_materials_[0])
camera_->PostProcessSettings.RemoveBlendable(noise_materials_[0]);

noise_material_static_ = nullptr;
noise_material_ = nullptr;
noise_materials_.Reset();

for (unsigned int image_type = 0; image_type < imageTypeCount(); ++image_type) {
//use final color for all calculations
Expand Down Expand Up @@ -109,12 +118,12 @@ void APIPCamera::setImageTypeSettings(int image_type, const APIPCamera::CaptureS
updateCaptureComponentSetting(captures_[image_type], render_targets_[image_type],
capture_setting);

setNoiseMaterial(captures_[image_type]->PostProcessSettings, noise_setting);
setNoiseMaterial(image_type, captures_[image_type], captures_[image_type]->PostProcessSettings, noise_setting);
}
else { //camera component
updateCameraSetting(camera_, capture_setting);

setNoiseMaterial(camera_->PostProcessSettings, noise_setting);
setNoiseMaterial(image_type, camera_, camera_->PostProcessSettings, noise_setting);
}


Expand Down Expand Up @@ -169,12 +178,14 @@ void APIPCamera::updateCameraPostProcessingSetting(FPostProcessSettings& obj, co
obj.HistogramLogMax = setting.auto_exposure_histogram_log_max;
}

void APIPCamera::setNoiseMaterial(FPostProcessSettings& obj, const NoiseSetting& settings)
void APIPCamera::setNoiseMaterial(int image_type, UObject* outer, FPostProcessSettings& obj, const NoiseSetting& settings)
{
if (!settings.Enabled)
return;

noise_material_ = UMaterialInstanceDynamic::Create(noise_material_static_, GetWorld());
UMaterialInstanceDynamic* noise_material_ = UMaterialInstanceDynamic::Create(noise_material_static_, outer);
noise_materials_[image_type + 1] = noise_material_;


noise_material_->SetScalarParameterValue("HorzWaveStrength", settings.HorzWaveStrength);
noise_material_->SetScalarParameterValue("RandSpeed", settings.RandSpeed);
Expand Down
8 changes: 5 additions & 3 deletions Unreal/Plugins/AirSim/Source/PIPCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ class AIRSIM_API APIPCamera : public ACameraActor
UPROPERTY() TArray<UTextureRenderTarget2D*> render_targets_;

UPROPERTY() UCameraComponent* camera_;
UPROPERTY() UMaterialInstanceDynamic* noise_material_ = nullptr;
UPROPERTY() UMaterial* noise_material_static_ = nullptr;
//TMap<int, UMaterialInstanceDynamic*> noise_materials_;
//below is needed because TMap doesn't work with UPROPERTY, but we do have -ve index
UPROPERTY() TArray<UMaterialInstanceDynamic*> noise_materials_;
UPROPERTY() UMaterial* noise_material_static_;

std::vector<bool> camera_type_enabled_;

Expand All @@ -60,7 +62,7 @@ class AIRSIM_API APIPCamera : public ACameraActor
static unsigned int imageTypeCount();
void enableCaptureComponent(const ImageType type, bool is_enabled);
static void updateCaptureComponentSetting(USceneCaptureComponent2D* capture, UTextureRenderTarget2D* render_target, const CaptureSetting& setting);
void setNoiseMaterial(FPostProcessSettings& obj, const NoiseSetting& settings);
void setNoiseMaterial(int image_type, UObject* outer, FPostProcessSettings& obj, const NoiseSetting& settings);
static void updateCameraPostProcessingSetting(FPostProcessSettings& obj, const CaptureSetting& setting);
static void updateCameraSetting(UCameraComponent* camera, const CaptureSetting& setting);

Expand Down

0 comments on commit 86e02f1

Please sign in to comment.