Set Default quality to Epic (not apply changes on level start - beginplay).

Separate function for non-blocking async screen capture.
Minor changes in settings
This commit is contained in:
CVC\jbelon 2018-03-15 17:21:39 +01:00
parent b775308d8c
commit 5dd83f321e
5 changed files with 79 additions and 57 deletions

View File

@ -131,14 +131,25 @@ void ASceneCaptureCamera::BeginPlay()
void ASceneCaptureCamera::Tick(const float DeltaSeconds)
{
Super::Tick(DeltaSeconds);
auto fn = [=](FRHICommandListImmediate& RHICmdList){WritePixels(DeltaSeconds,RHICmdList);};
ENQUEUE_UNIQUE_RENDER_COMMAND_ONEPARAMETER(
FWritePixels,
decltype(fn),write_function,fn,
{
write_function(RHICmdList);
});
if(IsVulkanPlatform(GMaxRHIShaderPlatform))
{
auto fn = [=](FRHICommandListImmediate& RHICmdList){WritePixelsNonBlocking(DeltaSeconds,RHICmdList);};
ENQUEUE_UNIQUE_RENDER_COMMAND_ONEPARAMETER(
FWritePixelsNonBlocking,
decltype(fn),write_function_vulkan,fn,
{
write_function_vulkan(RHICmdList);
});
} else
{
auto fn = [=](){WritePixels(DeltaSeconds);};
ENQUEUE_UNIQUE_RENDER_COMMAND_ONEPARAMETER(
FWritePixels,
decltype(fn),write_function,fn,
{
write_function();
});
}
}
float ASceneCaptureCamera::GetFOVAngle() const
@ -215,7 +226,7 @@ bool ASceneCaptureCamera::ReadPixels(TArray<FColor> &BitMap) const
return RTResource->ReadPixels(BitMap, ReadPixelFlags);
}
void ASceneCaptureCamera::WritePixels(float DeltaTime, FRHICommandListImmediate& rhi_cmd_list) const
void ASceneCaptureCamera::WritePixelsNonBlocking(float DeltaTime, FRHICommandListImmediate& rhi_cmd_list) const
{
check(IsInRenderingThread());
if(!CaptureRenderTarget)
@ -224,7 +235,12 @@ void ASceneCaptureCamera::WritePixels(float DeltaTime, FRHICommandListImmediate&
return ;
}
FTextureRenderTarget2DResource* RenderResource = (FTextureRenderTarget2DResource*)CaptureRenderTarget->Resource;
FTextureRHIParamRef texture = RenderResource->GetRenderTargetTexture();
if(!texture)
{
UE_LOG(LogCarla, Error, TEXT("SceneCaptureCamera: Missing render target texture"));
return;
}
struct {
uint32 Width;
uint32 Height;
@ -236,56 +252,61 @@ void ASceneCaptureCamera::WritePixels(float DeltaTime, FRHICommandListImmediate&
PostProcessEffect::ToUInt(PostProcessEffect),
CaptureComponent2D->FOVAngle
};
if(IsVulkanPlatform(GMaxRHIShaderPlatform))
struct FReadSurfaceContext
{
FTextureRHIParamRef texture = RenderResource->GetRenderTargetTexture();
if(!texture)
{
UE_LOG(LogCarla, Error, TEXT("SceneCaptureCamera: Missing render target texture"));
return;
}
struct FReadSurfaceContext
{
FRenderTarget* SrcRenderTarget;
TArray<FColor>* OutData;
FIntRect Rect;
FReadSurfaceDataFlags Flags;
};
TArray<FColor> Pixels;
rhi_cmd_list.ReadSurfaceData(
texture,
FIntRect(0, 0, RenderResource->GetSizeXY().X, RenderResource->GetSizeXY().Y),
Pixels,
FReadSurfaceDataFlags(RCM_UNorm, CubeFace_MAX)
);
FSensorDataView DataView(
FRenderTarget* SrcRenderTarget;
TArray<FColor>* OutData;
FIntRect Rect;
FReadSurfaceDataFlags Flags;
};
TArray<FColor> Pixels;
rhi_cmd_list.ReadSurfaceData(
texture,
FIntRect(0, 0, RenderResource->GetSizeXY().X, RenderResource->GetSizeXY().Y),
Pixels,
FReadSurfaceDataFlags(RCM_UNorm, CubeFace_MAX)
);
FSensorDataView DataView(
GetId(),
FReadOnlyBufferView{reinterpret_cast<const void *>(&ImageHeader), sizeof(ImageHeader)},
FReadOnlyBufferView{Pixels}
);
WriteSensorData(DataView);
} else
}
void ASceneCaptureCamera::WritePixels(float DeltaTime) const
{
FRHITexture2D *texture = CaptureRenderTarget->GetRenderTargetResource()->GetRenderTargetTexture();
if(!texture)
{
//if it's not vulkan we can lock the render target texture resource
FRHITexture2D *texture = CaptureRenderTarget->GetRenderTargetResource()->GetRenderTargetTexture();
if(!texture)
{
UE_LOG(LogCarla, Error, TEXT("SceneCaptureCamera: Missing render texture"));
return ;
}
const uint32 height = texture->GetSizeY();
uint32 stride;
uint8 *src = reinterpret_cast<uint8*>(RHILockTexture2D(texture, 0, RLM_ReadOnly, stride, false));
const FSensorDataView DataView(
GetId(),
FReadOnlyBufferView{reinterpret_cast<const void *>(&ImageHeader), sizeof(ImageHeader)},
FReadOnlyBufferView{src,stride*height}
);
WriteSensorData(DataView);
RHIUnlockTexture2D(texture, 0, false);
}
const uint32 width = texture->GetSizeX();
uint32 height = texture->GetSizeY();
uint32 stride;
uint8 *src = reinterpret_cast<uint8*>(RHILockTexture2D(texture, 0, RLM_ReadOnly, stride, false));
struct {
uint32 Width;
uint32 Height;
uint32 Type;
float FOV;
} ImageHeader = {
SizeX,
SizeY,
PostProcessEffect::ToUInt(PostProcessEffect),
CaptureComponent2D->FOVAngle
};
FSensorDataView DataView(
GetId(),
FReadOnlyBufferView{reinterpret_cast<const void *>(&ImageHeader), sizeof(ImageHeader)},
FReadOnlyBufferView{src,stride*height}
);
WriteSensorData(DataView);
RHIUnlockTexture2D(texture, 0, false);
}

View File

@ -71,9 +71,10 @@ public:
private:
///Read the camera buffer and write it to a color array
void WritePixels(float DeltaTime,FRHICommandListImmediate& rhi_cmd_list) const;
///Read the camera buffer and write it to the client with no lock of the resources (for Vulkan API)
void WritePixelsNonBlocking(float DeltaTime,FRHICommandListImmediate& rhi_cmd_list) const;
///Read the camera buffer and write it to the client with opengl or direct3d
void WritePixels(float DeltaTime) const;
/// Used to synchronize the DrawFrustumComponent with the
/// SceneCaptureComponent2D settings.
void UpdateDrawFrustum();

View File

@ -195,7 +195,7 @@ public:
private:
/** Quality Settings level. */
UPROPERTY(Category = "Quality Settings", VisibleAnywhere, meta =(AllowPrivateAccess="true"))
EQualitySettingsLevel QualitySettingsLevel = EQualitySettingsLevel::None;
EQualitySettingsLevel QualitySettingsLevel = EQualitySettingsLevel::Epic;
public:
/** @TODO : Move Low quality vars to a generic map of structs with the quality level as key*/

View File

@ -148,7 +148,7 @@ void UCarlaSettingsDelegate::LaunchLowQualityCommands(UWorld * world) const
GEngine->Exec(world,TEXT("r.FastBlurThreshold 0"));
GEngine->Exec(world,TEXT("r.SSR.MaxRoughness 0.1"));
GEngine->Exec(world,TEXT("r.AllowOcclusionQueries 1"));
//GEngine->Exec(world,TEXT("r.SSR 0"));
GEngine->Exec(world,TEXT("r.SSR 0"));
//GEngine->Exec(world,TEXT("r.StencilForLODDither 1")); //readonly
GEngine->Exec(world,TEXT("r.EarlyZPass 2")); //transparent before opaque
GEngine->Exec(world,TEXT("r.EarlyZPassMovable 1"));
@ -166,7 +166,7 @@ void UCarlaSettingsDelegate::LaunchLowQualityCommands(UWorld * world) const
GEngine->Exec(world,TEXT("r.LightShaftDownSampleFactor 4"));
GEngine->Exec(world,TEXT("r.OcclusionQueryLocation 1"));
//GEngine->Exec(world,TEXT("r.BasePassOutputsVelocity 0")); //--> readonly
//world->Exec(world,TEXT("r.DetailMode 0")); //-->will change to lods 0
//GEngine->Exec(world,TEXT("r.DetailMode 0")); //-->will change to lods 0
}

View File

@ -65,7 +65,7 @@ private:
private:
/** currently applied settings level after level is restarted */
EQualitySettingsLevel AppliedLowPostResetQualitySettingsLevel = EQualitySettingsLevel::None;
EQualitySettingsLevel AppliedLowPostResetQualitySettingsLevel = EQualitySettingsLevel::Epic;
/** */
UCarlaSettings* CarlaSettings = nullptr;