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) void ASceneCaptureCamera::Tick(const float DeltaSeconds)
{ {
Super::Tick(DeltaSeconds); Super::Tick(DeltaSeconds);
auto fn = [=](FRHICommandListImmediate& RHICmdList){WritePixels(DeltaSeconds,RHICmdList);}; if(IsVulkanPlatform(GMaxRHIShaderPlatform))
ENQUEUE_UNIQUE_RENDER_COMMAND_ONEPARAMETER( {
FWritePixels, auto fn = [=](FRHICommandListImmediate& RHICmdList){WritePixelsNonBlocking(DeltaSeconds,RHICmdList);};
decltype(fn),write_function,fn, ENQUEUE_UNIQUE_RENDER_COMMAND_ONEPARAMETER(
{ FWritePixelsNonBlocking,
write_function(RHICmdList); 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 float ASceneCaptureCamera::GetFOVAngle() const
@ -215,7 +226,7 @@ bool ASceneCaptureCamera::ReadPixels(TArray<FColor> &BitMap) const
return RTResource->ReadPixels(BitMap, ReadPixelFlags); 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()); check(IsInRenderingThread());
if(!CaptureRenderTarget) if(!CaptureRenderTarget)
@ -224,7 +235,12 @@ void ASceneCaptureCamera::WritePixels(float DeltaTime, FRHICommandListImmediate&
return ; return ;
} }
FTextureRenderTarget2DResource* RenderResource = (FTextureRenderTarget2DResource*)CaptureRenderTarget->Resource; FTextureRenderTarget2DResource* RenderResource = (FTextureRenderTarget2DResource*)CaptureRenderTarget->Resource;
FTextureRHIParamRef texture = RenderResource->GetRenderTargetTexture();
if(!texture)
{
UE_LOG(LogCarla, Error, TEXT("SceneCaptureCamera: Missing render target texture"));
return;
}
struct { struct {
uint32 Width; uint32 Width;
uint32 Height; uint32 Height;
@ -237,55 +253,60 @@ void ASceneCaptureCamera::WritePixels(float DeltaTime, FRHICommandListImmediate&
CaptureComponent2D->FOVAngle CaptureComponent2D->FOVAngle
}; };
if(IsVulkanPlatform(GMaxRHIShaderPlatform)) struct FReadSurfaceContext
{ {
FTextureRHIParamRef texture = RenderResource->GetRenderTargetTexture(); FRenderTarget* SrcRenderTarget;
if(!texture) TArray<FColor>* OutData;
{ FIntRect Rect;
UE_LOG(LogCarla, Error, TEXT("SceneCaptureCamera: Missing render target texture")); FReadSurfaceDataFlags Flags;
return; };
} TArray<FColor> Pixels;
struct FReadSurfaceContext rhi_cmd_list.ReadSurfaceData(
{ texture,
FRenderTarget* SrcRenderTarget; FIntRect(0, 0, RenderResource->GetSizeXY().X, RenderResource->GetSizeXY().Y),
TArray<FColor>* OutData; Pixels,
FIntRect Rect; FReadSurfaceDataFlags(RCM_UNorm, CubeFace_MAX)
FReadSurfaceDataFlags Flags; );
}; FSensorDataView DataView(
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(), GetId(),
FReadOnlyBufferView{reinterpret_cast<const void *>(&ImageHeader), sizeof(ImageHeader)}, FReadOnlyBufferView{reinterpret_cast<const void *>(&ImageHeader), sizeof(ImageHeader)},
FReadOnlyBufferView{Pixels} FReadOnlyBufferView{Pixels}
); );
WriteSensorData(DataView); 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")); UE_LOG(LogCarla, Error, TEXT("SceneCaptureCamera: Missing render texture"));
return ; 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: private:
///Read the camera buffer and write it to a color array ///Read the camera buffer and write it to the client with no lock of the resources (for Vulkan API)
void WritePixels(float DeltaTime,FRHICommandListImmediate& rhi_cmd_list) const; 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 /// Used to synchronize the DrawFrustumComponent with the
/// SceneCaptureComponent2D settings. /// SceneCaptureComponent2D settings.
void UpdateDrawFrustum(); void UpdateDrawFrustum();

View File

@ -195,7 +195,7 @@ public:
private: private:
/** Quality Settings level. */ /** Quality Settings level. */
UPROPERTY(Category = "Quality Settings", VisibleAnywhere, meta =(AllowPrivateAccess="true")) UPROPERTY(Category = "Quality Settings", VisibleAnywhere, meta =(AllowPrivateAccess="true"))
EQualitySettingsLevel QualitySettingsLevel = EQualitySettingsLevel::None; EQualitySettingsLevel QualitySettingsLevel = EQualitySettingsLevel::Epic;
public: public:
/** @TODO : Move Low quality vars to a generic map of structs with the quality level as key*/ /** @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.FastBlurThreshold 0"));
GEngine->Exec(world,TEXT("r.SSR.MaxRoughness 0.1")); GEngine->Exec(world,TEXT("r.SSR.MaxRoughness 0.1"));
GEngine->Exec(world,TEXT("r.AllowOcclusionQueries 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.StencilForLODDither 1")); //readonly
GEngine->Exec(world,TEXT("r.EarlyZPass 2")); //transparent before opaque GEngine->Exec(world,TEXT("r.EarlyZPass 2")); //transparent before opaque
GEngine->Exec(world,TEXT("r.EarlyZPassMovable 1")); 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.LightShaftDownSampleFactor 4"));
GEngine->Exec(world,TEXT("r.OcclusionQueryLocation 1")); GEngine->Exec(world,TEXT("r.OcclusionQueryLocation 1"));
//GEngine->Exec(world,TEXT("r.BasePassOutputsVelocity 0")); //--> readonly //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: private:
/** currently applied settings level after level is restarted */ /** currently applied settings level after level is restarted */
EQualitySettingsLevel AppliedLowPostResetQualitySettingsLevel = EQualitySettingsLevel::None; EQualitySettingsLevel AppliedLowPostResetQualitySettingsLevel = EQualitySettingsLevel::Epic;
/** */ /** */
UCarlaSettings* CarlaSettings = nullptr; UCarlaSettings* CarlaSettings = nullptr;