Programatically set camera post-processing, fixes #6

This commit is contained in:
nsubiron 2017-04-05 16:59:03 +02:00
parent e03b97aa9c
commit 714fec71ac
4 changed files with 29 additions and 13 deletions

View File

@ -129,7 +129,7 @@ void ACarlaGameMode::AttachCaptureCamerasToPlayer(AController &Player)
Settings.Mono_CameraRotation,
Settings.Mono_ImageSizeX,
Settings.Mono_ImageSizeY,
EPostProcessEffect::None);
EPostProcessEffect::SceneFinal);
RegisterCaptureCamera(*TheCamera, Player);
} else if (Settings.SceneCaptureMode == ESceneCaptureMode::Stereo) {
auto RGBCamera0 =
@ -139,7 +139,7 @@ void ACarlaGameMode::AttachCaptureCamerasToPlayer(AController &Player)
Settings.Stereo_Camera0Rotation,
Settings.Stereo_ImageSizeX,
Settings.Stereo_ImageSizeY,
EPostProcessEffect::None);
EPostProcessEffect::SceneFinal);
auto DepthCamera0 =
SpawnAndAttachCamera(
Player,
@ -155,7 +155,7 @@ void ACarlaGameMode::AttachCaptureCamerasToPlayer(AController &Player)
Settings.Stereo_Camera1Rotation,
Settings.Stereo_ImageSizeX,
Settings.Stereo_ImageSizeY,
EPostProcessEffect::None);
EPostProcessEffect::SceneFinal);
auto DepthCamera1 =
SpawnAndAttachCamera(
Player,

View File

@ -170,8 +170,7 @@ void ACarlaVehicleController::RegisterCaptureCamera(ASceneCaptureCamera &Capture
{
AddTickPrerequisiteActor(&CaptureCamera);
const auto Effect = CaptureCamera.GetPostProcessEffect();
check((Effect == EPostProcessEffect::None) || (Effect == EPostProcessEffect::Depth))
auto &Cameras = (Effect == EPostProcessEffect::None ? RGBCameras : DepthCameras);
auto &Cameras = (Effect == EPostProcessEffect::Depth ? DepthCameras : RGBCameras);
for (auto i = 0u; i < Cameras.size(); ++i) {
if (Cameras[i] == nullptr) {

View File

@ -9,15 +9,18 @@
#include "Engine/CollisionProfile.h"
#include "Engine/TextureRenderTarget2D.h"
#include "HighResScreenshot.h"
#include "Materials/Material.h"
#include "Paths.h"
#include "StaticMeshResources.h"
#include "TextureResource.h"
static constexpr auto DEPTH_MAT_PATH = TEXT("Material'/Carla/PostProcessingMaterials/DepthEffectMaterial.DepthEffectMaterial'");
ASceneCaptureCamera::ASceneCaptureCamera(const FObjectInitializer& ObjectInitializer) :
Super(ObjectInitializer),
SizeX(200u),
SizeY(200u),
PostProcessEffect(EPostProcessEffect::None)
SizeX(720u),
SizeY(512u),
PostProcessEffect(EPostProcessEffect::SceneFinal)
{
PrimaryActorTick.bCanEverTick = true; /// @todo Does it need to tick?
PrimaryActorTick.TickGroup = TG_PrePhysics;
@ -39,6 +42,10 @@ ASceneCaptureCamera::ASceneCaptureCamera(const FObjectInitializer& ObjectInitial
CaptureComponent2D = CreateDefaultSubobject<USceneCaptureComponent2D>(TEXT("SceneCaptureComponent2D"));
CaptureComponent2D->SetupAttachment(MeshComp);
// Load post-processing materials.
static ConstructorHelpers::FObjectFinder<UMaterial> DEPTH(DEPTH_MAT_PATH);
PostProcessDepth = DEPTH.Object;
}
void ASceneCaptureCamera::PostActorCreated()
@ -73,6 +80,11 @@ void ASceneCaptureCamera::BeginPlay()
CaptureComponent2D->Deactivate();
CaptureComponent2D->TextureTarget = CaptureRenderTarget;
if (PostProcessEffect == EPostProcessEffect::SceneFinal) {
CaptureComponent2D->CaptureSource = ESceneCaptureSource::SCS_FinalColorLDR;
} else if (PostProcessEffect == EPostProcessEffect::Depth) {
CaptureComponent2D->PostProcessSettings.AddBlendable(PostProcessDepth, 1.0f);
}
CaptureComponent2D->UpdateContent();
CaptureComponent2D->Activate();
}

View File

@ -14,11 +14,13 @@
class UDrawFrustumComponent;
class USceneCaptureComponent2D;
class UStaticMeshComponent;
class UTextureRenderTarget2D;
UENUM(BlueprintType)
enum class EPostProcessEffect : uint8
{
None UMETA(DisplayName = "RGB"),
None UMETA(DisplayName = "RGB without any post-processing"),
SceneFinal UMETA(DisplayName = "RGB with post-processing present at the scene"),
Depth UMETA(DisplayName = "Depth Map"),
SIZE UMETA(Hidden)
@ -81,17 +83,20 @@ private:
/** To display the 3d camera in the editor. */
UPROPERTY()
class UStaticMeshComponent* MeshComp;
UStaticMeshComponent* MeshComp;
/** To allow drawing the camera frustum in the editor. */
UPROPERTY()
class UDrawFrustumComponent* DrawFrustum;
UDrawFrustumComponent* DrawFrustum;
/** Render target necessary for scene capture */
UPROPERTY(Transient)
class UTextureRenderTarget2D* CaptureRenderTarget;
UTextureRenderTarget2D* CaptureRenderTarget;
/** Scene capture component. */
UPROPERTY(EditAnywhere)
class USceneCaptureComponent2D* CaptureComponent2D;
USceneCaptureComponent2D* CaptureComponent2D;
UPROPERTY()
UMaterial *PostProcessDepth;
};