Programatically set camera post-processing, fixes #6
This commit is contained in:
parent
e03b97aa9c
commit
714fec71ac
|
@ -129,7 +129,7 @@ void ACarlaGameMode::AttachCaptureCamerasToPlayer(AController &Player)
|
||||||
Settings.Mono_CameraRotation,
|
Settings.Mono_CameraRotation,
|
||||||
Settings.Mono_ImageSizeX,
|
Settings.Mono_ImageSizeX,
|
||||||
Settings.Mono_ImageSizeY,
|
Settings.Mono_ImageSizeY,
|
||||||
EPostProcessEffect::None);
|
EPostProcessEffect::SceneFinal);
|
||||||
RegisterCaptureCamera(*TheCamera, Player);
|
RegisterCaptureCamera(*TheCamera, Player);
|
||||||
} else if (Settings.SceneCaptureMode == ESceneCaptureMode::Stereo) {
|
} else if (Settings.SceneCaptureMode == ESceneCaptureMode::Stereo) {
|
||||||
auto RGBCamera0 =
|
auto RGBCamera0 =
|
||||||
|
@ -139,7 +139,7 @@ void ACarlaGameMode::AttachCaptureCamerasToPlayer(AController &Player)
|
||||||
Settings.Stereo_Camera0Rotation,
|
Settings.Stereo_Camera0Rotation,
|
||||||
Settings.Stereo_ImageSizeX,
|
Settings.Stereo_ImageSizeX,
|
||||||
Settings.Stereo_ImageSizeY,
|
Settings.Stereo_ImageSizeY,
|
||||||
EPostProcessEffect::None);
|
EPostProcessEffect::SceneFinal);
|
||||||
auto DepthCamera0 =
|
auto DepthCamera0 =
|
||||||
SpawnAndAttachCamera(
|
SpawnAndAttachCamera(
|
||||||
Player,
|
Player,
|
||||||
|
@ -155,7 +155,7 @@ void ACarlaGameMode::AttachCaptureCamerasToPlayer(AController &Player)
|
||||||
Settings.Stereo_Camera1Rotation,
|
Settings.Stereo_Camera1Rotation,
|
||||||
Settings.Stereo_ImageSizeX,
|
Settings.Stereo_ImageSizeX,
|
||||||
Settings.Stereo_ImageSizeY,
|
Settings.Stereo_ImageSizeY,
|
||||||
EPostProcessEffect::None);
|
EPostProcessEffect::SceneFinal);
|
||||||
auto DepthCamera1 =
|
auto DepthCamera1 =
|
||||||
SpawnAndAttachCamera(
|
SpawnAndAttachCamera(
|
||||||
Player,
|
Player,
|
||||||
|
|
|
@ -170,8 +170,7 @@ void ACarlaVehicleController::RegisterCaptureCamera(ASceneCaptureCamera &Capture
|
||||||
{
|
{
|
||||||
AddTickPrerequisiteActor(&CaptureCamera);
|
AddTickPrerequisiteActor(&CaptureCamera);
|
||||||
const auto Effect = CaptureCamera.GetPostProcessEffect();
|
const auto Effect = CaptureCamera.GetPostProcessEffect();
|
||||||
check((Effect == EPostProcessEffect::None) || (Effect == EPostProcessEffect::Depth))
|
auto &Cameras = (Effect == EPostProcessEffect::Depth ? DepthCameras : RGBCameras);
|
||||||
auto &Cameras = (Effect == EPostProcessEffect::None ? RGBCameras : DepthCameras);
|
|
||||||
|
|
||||||
for (auto i = 0u; i < Cameras.size(); ++i) {
|
for (auto i = 0u; i < Cameras.size(); ++i) {
|
||||||
if (Cameras[i] == nullptr) {
|
if (Cameras[i] == nullptr) {
|
||||||
|
|
|
@ -9,15 +9,18 @@
|
||||||
#include "Engine/CollisionProfile.h"
|
#include "Engine/CollisionProfile.h"
|
||||||
#include "Engine/TextureRenderTarget2D.h"
|
#include "Engine/TextureRenderTarget2D.h"
|
||||||
#include "HighResScreenshot.h"
|
#include "HighResScreenshot.h"
|
||||||
|
#include "Materials/Material.h"
|
||||||
#include "Paths.h"
|
#include "Paths.h"
|
||||||
#include "StaticMeshResources.h"
|
#include "StaticMeshResources.h"
|
||||||
#include "TextureResource.h"
|
#include "TextureResource.h"
|
||||||
|
|
||||||
|
static constexpr auto DEPTH_MAT_PATH = TEXT("Material'/Carla/PostProcessingMaterials/DepthEffectMaterial.DepthEffectMaterial'");
|
||||||
|
|
||||||
ASceneCaptureCamera::ASceneCaptureCamera(const FObjectInitializer& ObjectInitializer) :
|
ASceneCaptureCamera::ASceneCaptureCamera(const FObjectInitializer& ObjectInitializer) :
|
||||||
Super(ObjectInitializer),
|
Super(ObjectInitializer),
|
||||||
SizeX(200u),
|
SizeX(720u),
|
||||||
SizeY(200u),
|
SizeY(512u),
|
||||||
PostProcessEffect(EPostProcessEffect::None)
|
PostProcessEffect(EPostProcessEffect::SceneFinal)
|
||||||
{
|
{
|
||||||
PrimaryActorTick.bCanEverTick = true; /// @todo Does it need to tick?
|
PrimaryActorTick.bCanEverTick = true; /// @todo Does it need to tick?
|
||||||
PrimaryActorTick.TickGroup = TG_PrePhysics;
|
PrimaryActorTick.TickGroup = TG_PrePhysics;
|
||||||
|
@ -39,6 +42,10 @@ ASceneCaptureCamera::ASceneCaptureCamera(const FObjectInitializer& ObjectInitial
|
||||||
|
|
||||||
CaptureComponent2D = CreateDefaultSubobject<USceneCaptureComponent2D>(TEXT("SceneCaptureComponent2D"));
|
CaptureComponent2D = CreateDefaultSubobject<USceneCaptureComponent2D>(TEXT("SceneCaptureComponent2D"));
|
||||||
CaptureComponent2D->SetupAttachment(MeshComp);
|
CaptureComponent2D->SetupAttachment(MeshComp);
|
||||||
|
|
||||||
|
// Load post-processing materials.
|
||||||
|
static ConstructorHelpers::FObjectFinder<UMaterial> DEPTH(DEPTH_MAT_PATH);
|
||||||
|
PostProcessDepth = DEPTH.Object;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ASceneCaptureCamera::PostActorCreated()
|
void ASceneCaptureCamera::PostActorCreated()
|
||||||
|
@ -73,6 +80,11 @@ void ASceneCaptureCamera::BeginPlay()
|
||||||
|
|
||||||
CaptureComponent2D->Deactivate();
|
CaptureComponent2D->Deactivate();
|
||||||
CaptureComponent2D->TextureTarget = CaptureRenderTarget;
|
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->UpdateContent();
|
||||||
CaptureComponent2D->Activate();
|
CaptureComponent2D->Activate();
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,11 +14,13 @@
|
||||||
class UDrawFrustumComponent;
|
class UDrawFrustumComponent;
|
||||||
class USceneCaptureComponent2D;
|
class USceneCaptureComponent2D;
|
||||||
class UStaticMeshComponent;
|
class UStaticMeshComponent;
|
||||||
|
class UTextureRenderTarget2D;
|
||||||
|
|
||||||
UENUM(BlueprintType)
|
UENUM(BlueprintType)
|
||||||
enum class EPostProcessEffect : uint8
|
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"),
|
Depth UMETA(DisplayName = "Depth Map"),
|
||||||
|
|
||||||
SIZE UMETA(Hidden)
|
SIZE UMETA(Hidden)
|
||||||
|
@ -81,17 +83,20 @@ private:
|
||||||
|
|
||||||
/** To display the 3d camera in the editor. */
|
/** To display the 3d camera in the editor. */
|
||||||
UPROPERTY()
|
UPROPERTY()
|
||||||
class UStaticMeshComponent* MeshComp;
|
UStaticMeshComponent* MeshComp;
|
||||||
|
|
||||||
/** To allow drawing the camera frustum in the editor. */
|
/** To allow drawing the camera frustum in the editor. */
|
||||||
UPROPERTY()
|
UPROPERTY()
|
||||||
class UDrawFrustumComponent* DrawFrustum;
|
UDrawFrustumComponent* DrawFrustum;
|
||||||
|
|
||||||
/** Render target necessary for scene capture */
|
/** Render target necessary for scene capture */
|
||||||
UPROPERTY(Transient)
|
UPROPERTY(Transient)
|
||||||
class UTextureRenderTarget2D* CaptureRenderTarget;
|
UTextureRenderTarget2D* CaptureRenderTarget;
|
||||||
|
|
||||||
/** Scene capture component. */
|
/** Scene capture component. */
|
||||||
UPROPERTY(EditAnywhere)
|
UPROPERTY(EditAnywhere)
|
||||||
class USceneCaptureComponent2D* CaptureComponent2D;
|
USceneCaptureComponent2D* CaptureComponent2D;
|
||||||
|
|
||||||
|
UPROPERTY()
|
||||||
|
UMaterial *PostProcessDepth;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue