and inference works now
Resampling scenecolor to inputTensor format Integrated the system into the game Crashes due to TDR timeout Adjusted ThreadGroups to be 64 in size.
This commit is contained in:
parent
d91173c3ae
commit
7ec56a0475
BIN
Plugins/GameFeatures/ShooterCore/Content/Experiences/B_ShooterGame_Elimination.uasset (Stored with Git LFS)
BIN
Plugins/GameFeatures/ShooterCore/Content/Experiences/B_ShooterGame_Elimination.uasset (Stored with Git LFS)
Binary file not shown.
|
@ -6,26 +6,27 @@
|
|||
RWTexture2D<float4> OutputTexture;
|
||||
Buffer<float> InputTensor;
|
||||
|
||||
[numthreads(1, 1, 1)]
|
||||
[numthreads(THREADGROUP_SIZE_X, THREADGROUP_SIZE_Y, THREADGROUP_SIZE_Z)]
|
||||
void OutputTensorToSceneColorCS(in const uint3 DispatchThreadID : SV_DispatchThreadID)
|
||||
{
|
||||
const uint GlobalIndex = DispatchThreadID.x;
|
||||
|
||||
uint TensorVolume;
|
||||
InputTensor.GetDimensions(TensorVolume);
|
||||
|
||||
uint2 TextureSize = 0;
|
||||
OutputTexture.GetDimensions(TextureSize.x, TextureSize.y);
|
||||
|
||||
// note that the input tensor has shape (1, Y, X, C)
|
||||
// which is why we need to flip the indexing
|
||||
const uint PixelIndex = DispatchThreadID.x * TextureSize.y + DispatchThreadID.x;
|
||||
const uint GlobalIndex = PixelIndex * 3;
|
||||
|
||||
if (GlobalIndex >= TensorVolume)
|
||||
{
|
||||
return;
|
||||
}
|
||||
uint2 TextureSize = 0;
|
||||
OutputTexture.GetDimensions(TextureSize.x, TextureSize.y);
|
||||
const uint PixelIndex = GlobalIndex / 3;
|
||||
const uint ChannelIndex = GlobalIndex % 3;
|
||||
const uint MajorIndex = PixelIndex / TextureSize.x;
|
||||
const uint MinorIndex = PixelIndex % TextureSize.x;
|
||||
const uint2 TextureCoords = uint2(MajorIndex, MinorIndex);
|
||||
|
||||
const uint2 TextureCoords = uint2(DispatchThreadID.y, DispatchThreadID.x);
|
||||
OutputTexture[TextureCoords] = float4(
|
||||
InputTensor[GlobalIndex + 0],
|
||||
InputTensor[GlobalIndex + 1],
|
||||
|
|
|
@ -3,24 +3,28 @@
|
|||
#include "/Engine/Public/Platform.ush"
|
||||
|
||||
Texture2D<float4> InputTexture;
|
||||
SamplerState InputTextureSampler;
|
||||
RWBuffer<float> OutputUAV;
|
||||
uint2 OutputDimensions; // X = InputTensor.GetSize(1), Y = InputTensor.GetSize(2) -> this does not correspond to input texture XY
|
||||
float2 HalfPixelUV;
|
||||
|
||||
[numthreads(THREADGROUP_SIZE_X, THREADGROUP_SIZE_Y, THREADGROUP_SIZE_Z)]
|
||||
void SceneColorToInputTensorCS(in const uint3 DispatchThreadID : SV_DispatchThreadID)
|
||||
{
|
||||
uint2 TexelCoordinate = DispatchThreadID.xy;
|
||||
|
||||
const uint GlobalIndex = TexelCoordinate.x * TexelCoordinate.y * 3;
|
||||
|
||||
uint TensorVolume;
|
||||
OutputUAV.GetDimensions(TensorVolume);
|
||||
|
||||
if (GlobalIndex >= TensorVolume)
|
||||
const uint2 OutputUAVTexelCoordinate = DispatchThreadID.xy;
|
||||
if(any(OutputUAVTexelCoordinate > OutputDimensions))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
float4 TextureValue = InputTexture[DispatchThreadID.xy];
|
||||
const uint GlobalIndex = (OutputUAVTexelCoordinate.x * OutputDimensions.x + OutputUAVTexelCoordinate.y) * 3;
|
||||
|
||||
// note that the input tensor has shape (1, Y, X, C)
|
||||
// which is why we need to flip the indexing
|
||||
const float2 UV = OutputUAVTexelCoordinate.yx / OutputDimensions.yx + HalfPixelUV;
|
||||
|
||||
const float4 TextureValue = InputTexture.SampleLevel(InputTextureSampler, UV, 0);
|
||||
|
||||
OutputUAV[GlobalIndex + 0] = TextureValue.r;
|
||||
OutputUAV[GlobalIndex + 1] = TextureValue.g;
|
||||
OutputUAV[GlobalIndex + 2] = TextureValue.b;
|
||||
|
|
|
@ -35,17 +35,17 @@ OutType CastNarrowingSafe(InType InValue)
|
|||
}
|
||||
|
||||
|
||||
FStyleTransferSceneViewExtension::FStyleTransferSceneViewExtension(const FAutoRegister& AutoRegister, FViewportClient* AssociatedViewportClient, UNeuralNetwork* InStyleTransferNetwork)
|
||||
FStyleTransferSceneViewExtension::FStyleTransferSceneViewExtension(const FAutoRegister& AutoRegister, FViewportClient* AssociatedViewportClient, UNeuralNetwork* InStyleTransferNetwork, int32 InInferenceContext)
|
||||
: FSceneViewExtensionBase(AutoRegister)
|
||||
, StyleTransferNetwork(InStyleTransferNetwork)
|
||||
, LinkedViewportClient(AssociatedViewportClient)
|
||||
, InferenceContext(InInferenceContext)
|
||||
{
|
||||
ensure(InStyleTransferNetwork->GetDeviceType() == ENeuralDeviceType::GPU);
|
||||
}
|
||||
|
||||
void FStyleTransferSceneViewExtension::SetupViewFamily(FSceneViewFamily& InViewFamily)
|
||||
{
|
||||
InferenceContext = StyleTransferNetwork->CreateInferenceContext();
|
||||
}
|
||||
|
||||
void FStyleTransferSceneViewExtension::SubscribeToPostProcessingPass(EPostProcessingPass PassId,
|
||||
|
@ -79,30 +79,8 @@ FScreenPassTexture FStyleTransferSceneViewExtension::PostProcessPassAfterTonemap
|
|||
|
||||
RDG_EVENT_SCOPE(GraphBuilder, "StyleTransfer");
|
||||
|
||||
FScreenPassRenderTarget BackBufferRenderTarget;
|
||||
|
||||
// If the override output is provided it means that this is the last pass in post processing.
|
||||
if (InOutInputs.OverrideOutput.IsValid())
|
||||
{
|
||||
BackBufferRenderTarget = InOutInputs.OverrideOutput;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Reusing the same output description for our back buffer as SceneColor when it's not overriden
|
||||
FRDGTextureDesc OutputDesc = SceneColor.Texture->Desc;
|
||||
OutputDesc.Flags |= TexCreate_RenderTargetable;
|
||||
FLinearColor ClearColor(0., 0., 0., 0.);
|
||||
OutputDesc.ClearValue = FClearValueBinding(ClearColor);
|
||||
|
||||
FRDGTexture* BackBufferRenderTargetTexture = GraphBuilder.CreateTexture(
|
||||
OutputDesc, TEXT("BackBufferRenderTargetTexture"));
|
||||
BackBufferRenderTarget = FScreenPassRenderTarget(BackBufferRenderTargetTexture, SceneColor.ViewRect,
|
||||
ERenderTargetLoadAction::EClear);
|
||||
}
|
||||
|
||||
//Get input and output viewports. Backbuffer could be targeting a different region than input viewport
|
||||
const FScreenPassTextureViewport SceneColorViewport(SceneColor);
|
||||
const FScreenPassTextureViewport BackBufferViewport(BackBufferRenderTarget);
|
||||
|
||||
FScreenPassRenderTarget SceneColorRenderTarget(SceneColor, ERenderTargetLoadAction::ELoad);
|
||||
|
||||
|
@ -112,15 +90,29 @@ FScreenPassTexture FStyleTransferSceneViewExtension::PostProcessPassAfterTonemap
|
|||
/*AddDrawScreenPass(GraphBuilder, RDG_EVENT_NAME("ProcessOCIOColorSpaceXfrm"), ViewInfo, BackBufferViewport,
|
||||
SceneColorViewport, OCIOPixelShader, Parameters);*/
|
||||
|
||||
const FNeuralTensor& StyleTransferContentInputTensor = StyleTransferNetwork->GetInputTensorForContext(InferenceContext, 0);
|
||||
|
||||
const FIntVector InputTensorDimensions = {
|
||||
CastNarrowingSafe<int32>(StyleTransferContentInputTensor.GetSize(1)),
|
||||
CastNarrowingSafe<int32>(StyleTransferContentInputTensor.GetSize(2)),
|
||||
CastNarrowingSafe<int32>(StyleTransferContentInputTensor.GetSize(3)),
|
||||
};
|
||||
const FIntPoint SceneColorRenderTargetDimensions = SceneColorRenderTarget.Texture->Desc.Extent;
|
||||
|
||||
FRDGBufferRef StyleTransferContentInputBuffer = GraphBuilder.RegisterExternalBuffer(StyleTransferContentInputTensor.GetPooledBuffer());
|
||||
auto SceneColorToInputTensorParameters = GraphBuilder.AllocParameters<FSceneColorToInputTensorCS::FParameters>();
|
||||
FNeuralTensor InputTensor = StyleTransferNetwork->GetInputTensor();
|
||||
SceneColorToInputTensorParameters->TensorVolume = CastNarrowingSafe<uint32>(InputTensor.Num());
|
||||
SceneColorToInputTensorParameters->TensorVolume = CastNarrowingSafe<uint32>(StyleTransferContentInputTensor.Num());
|
||||
SceneColorToInputTensorParameters->InputTexture = SceneColorRenderTarget.Texture;
|
||||
SceneColorToInputTensorParameters->OutputUAV = InputTensor.GetBufferUAVRef();
|
||||
FIntVector SceneColorToInputTensorGroupCount;
|
||||
SceneColorToInputTensorParameters->InputTextureSampler = TStaticSamplerState<SF_Bilinear>::GetRHI();
|
||||
SceneColorToInputTensorParameters->OutputUAV = GraphBuilder.CreateUAV(StyleTransferContentInputBuffer);
|
||||
SceneColorToInputTensorParameters->OutputDimensions = {InputTensorDimensions.X, InputTensorDimensions.Y};
|
||||
SceneColorToInputTensorParameters->HalfPixelUV = FVector2f(0.5f / SceneColorRenderTargetDimensions.X, 0.5 / SceneColorRenderTargetDimensions.Y);
|
||||
FIntVector SceneColorToInputTensorGroupCount = FComputeShaderUtils::GetGroupCount(
|
||||
{InputTensorDimensions.X, InputTensorDimensions.Y, 1},
|
||||
FSceneColorToInputTensorCS::ThreadGroupSize
|
||||
);
|
||||
|
||||
TShaderMapRef<FSceneColorToInputTensorCS> SceneColorToInputTensorCS(GetGlobalShaderMap(GMaxRHIFeatureLevel));
|
||||
ClearUnusedGraphResources(SceneColorToInputTensorCS, SceneColorToInputTensorParameters);
|
||||
GraphBuilder.AddPass(
|
||||
RDG_EVENT_NAME("SceneColorToInputTensor"),
|
||||
SceneColorToInputTensorParameters,
|
||||
|
@ -132,17 +124,39 @@ FScreenPassTexture FStyleTransferSceneViewExtension::PostProcessPassAfterTonemap
|
|||
}
|
||||
);
|
||||
|
||||
StyleTransferNetwork->GetInputDataPointerMutableForContext(InferenceContext, 0);
|
||||
|
||||
const FNeuralTensor& StyleTransferOutputTensor = StyleTransferNetwork->GetOutputTensorForContext(InferenceContext, 0);
|
||||
FIntVector OutputTensorDimensions = {
|
||||
CastNarrowingSafe<int32>(StyleTransferOutputTensor.GetSize(1)),
|
||||
CastNarrowingSafe<int32>(StyleTransferOutputTensor.GetSize(2)),
|
||||
CastNarrowingSafe<int32>(StyleTransferOutputTensor.GetSize(3)),
|
||||
};
|
||||
// Reusing the same output description for our back buffer as SceneColor
|
||||
FRDGTextureDesc OutputDesc = SceneColor.Texture->Desc;
|
||||
// this is flipped because the Output tensor has the vertical dimension first
|
||||
// while unreal has the horizontal dimension first
|
||||
OutputDesc.Extent = {OutputTensorDimensions[1], OutputTensorDimensions[0]};
|
||||
OutputDesc.Flags |= TexCreate_RenderTargetable | TexCreate_UAV;
|
||||
FLinearColor ClearColor(0., 0., 0., 0.);
|
||||
OutputDesc.ClearValue = FClearValueBinding(ClearColor);
|
||||
FRDGTexture* StyleTransferRenderTargetTexture = GraphBuilder.CreateTexture(
|
||||
OutputDesc, TEXT("StyleTransferRenderTargetTexture"));
|
||||
TSharedPtr<FScreenPassRenderTarget> StyleTransferOutputTarget = MakeShared<FScreenPassRenderTarget>(StyleTransferRenderTargetTexture, SceneColor.ViewRect,
|
||||
ERenderTargetLoadAction::EClear);
|
||||
|
||||
StyleTransferNetwork->Run(GraphBuilder, InferenceContext);
|
||||
|
||||
FRDGBufferRef StyleTransferOutputBuffer = GraphBuilder.RegisterExternalBuffer(StyleTransferContentInputTensor.GetPooledBuffer());
|
||||
|
||||
auto OutputTensorToSceneColorParameters = GraphBuilder.AllocParameters<FOutputTensorToSceneColorCS::FParameters>();
|
||||
FNeuralTensor OutputTensor = StyleTransferNetwork->GetOutputTensor(0);
|
||||
OutputTensorToSceneColorParameters->InputTensor = OutputTensor.GetBufferSRVRef();
|
||||
OutputTensorToSceneColorParameters->OutputTexture = GraphBuilder.CreateUAV(SceneColorRenderTarget.Texture);
|
||||
FIntVector OutputTensorToSceneColorGroupCount;
|
||||
OutputTensorToSceneColorParameters->InputTensor = GraphBuilder.CreateSRV(StyleTransferOutputBuffer, EPixelFormat::PF_FloatRGB);
|
||||
OutputTensorToSceneColorParameters->OutputTexture = GraphBuilder.CreateUAV(StyleTransferRenderTargetTexture);
|
||||
FIntVector OutputTensorToSceneColorGroupCount = FComputeShaderUtils::GetGroupCount(
|
||||
{OutputTensorDimensions.X, OutputTensorDimensions.Y, 1},
|
||||
FOutputTensorToSceneColorCS::ThreadGroupSize
|
||||
);
|
||||
|
||||
TShaderMapRef<FOutputTensorToSceneColorCS> OutputTensorToSceneColorCS(GetGlobalShaderMap(GMaxRHIFeatureLevel));
|
||||
ClearUnusedGraphResources(OutputTensorToSceneColorCS, OutputTensorToSceneColorParameters);
|
||||
GraphBuilder.AddPass(
|
||||
RDG_EVENT_NAME("OutputTensorToSceneColor"),
|
||||
OutputTensorToSceneColorParameters,
|
||||
|
@ -154,5 +168,19 @@ FScreenPassTexture FStyleTransferSceneViewExtension::PostProcessPassAfterTonemap
|
|||
}
|
||||
);
|
||||
|
||||
return MoveTemp(BackBufferRenderTarget);
|
||||
|
||||
TSharedPtr<FScreenPassRenderTarget> BackBufferRenderTarget;
|
||||
// If the override output is provided it means that this is the last pass in post processing.
|
||||
if (InOutInputs.OverrideOutput.IsValid())
|
||||
{
|
||||
BackBufferRenderTarget = MakeShared<FScreenPassRenderTarget>(InOutInputs.OverrideOutput);
|
||||
// @todo: do not use copy. Resample the styled 1920x960 texture to the fullscreen texture by drawing into the texture
|
||||
AddCopyTexturePass(GraphBuilder, StyleTransferRenderTargetTexture, BackBufferRenderTarget->Texture);
|
||||
}
|
||||
else
|
||||
{
|
||||
BackBufferRenderTarget = StyleTransferOutputTarget;
|
||||
}
|
||||
|
||||
return MoveTemp(*BackBufferRenderTarget);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "StyleTransferSubsystem.h"
|
||||
|
||||
#include "NeuralNetwork.h"
|
||||
#include "RenderGraphUtils.h"
|
||||
#include "StyleTransferSceneViewExtension.h"
|
||||
|
||||
void UStyleTransferSubsystem::Initialize(FSubsystemCollectionBase& Collection)
|
||||
|
@ -15,14 +16,16 @@ void UStyleTransferSubsystem::Initialize(FSubsystemCollectionBase& Collection)
|
|||
|
||||
if (StyleTransferNetwork->IsLoaded())
|
||||
{
|
||||
if (StyleTransferNetwork->IsGPUSupported())
|
||||
for (int32 i = 0; i < StyleTransferNetwork->GetInputTensorNumber(); ++i)
|
||||
{
|
||||
StyleTransferNetwork->SetDeviceType(ENeuralDeviceType::GPU);
|
||||
}
|
||||
else
|
||||
{
|
||||
StyleTransferNetwork->SetDeviceType(ENeuralDeviceType::CPU);
|
||||
const FNeuralTensor& InputTensor = StyleTransferNetwork->GetInputTensor(i);
|
||||
if (InputTensor.GetName() != "style_params")
|
||||
continue;
|
||||
|
||||
StyleTransferStyleParamsInputIndex = i;
|
||||
break;
|
||||
}
|
||||
StyleTransferNetwork->SetDeviceType(ENeuralDeviceType::GPU, ENeuralDeviceType::GPU, ENeuralDeviceType::GPU);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -32,14 +35,7 @@ void UStyleTransferSubsystem::Initialize(FSubsystemCollectionBase& Collection)
|
|||
|
||||
if (StylePredictionNetwork->IsLoaded())
|
||||
{
|
||||
if (StylePredictionNetwork->IsGPUSupported())
|
||||
{
|
||||
StylePredictionNetwork->SetDeviceType(ENeuralDeviceType::GPU);
|
||||
}
|
||||
else
|
||||
{
|
||||
StylePredictionNetwork->SetDeviceType(ENeuralDeviceType::CPU);
|
||||
}
|
||||
StyleTransferNetwork->SetDeviceType(ENeuralDeviceType::GPU, ENeuralDeviceType::GPU, ENeuralDeviceType::GPU);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -50,19 +46,32 @@ void UStyleTransferSubsystem::Initialize(FSubsystemCollectionBase& Collection)
|
|||
void UStyleTransferSubsystem::Deinitialize()
|
||||
{
|
||||
StyleTransferSceneViewExtension.Reset();
|
||||
StylePredictionNetwork->DestroyInferenceContext(StylePredictionInferenceContext);
|
||||
if(StylePredictionInferenceContext != INDEX_NONE)
|
||||
{
|
||||
StylePredictionNetwork->DestroyInferenceContext(StylePredictionInferenceContext);
|
||||
}
|
||||
if(StyleTransferInferenceContext != INDEX_NONE)
|
||||
{
|
||||
StyleTransferNetwork->DestroyInferenceContext(StyleTransferInferenceContext);
|
||||
}
|
||||
|
||||
Super::Deinitialize();
|
||||
}
|
||||
|
||||
void UStyleTransferSubsystem::StartStylizingViewport(FViewportClient* ViewportClient)
|
||||
{
|
||||
StyleTransferSceneViewExtension = FSceneViewExtensions::NewExtension<FStyleTransferSceneViewExtension>(ViewportClient, StyleTransferNetwork);
|
||||
StylePredictionInferenceContext = StylePredictionNetwork->CreateInferenceContext();
|
||||
checkf(StylePredictionInferenceContext != INDEX_NONE, TEXT("Could not create inference context for StylePredictionNetwork"));
|
||||
StyleTransferInferenceContext = StyleTransferNetwork->CreateInferenceContext();
|
||||
checkf(StyleTransferInferenceContext != INDEX_NONE, TEXT("Could not create inference context for StyleTransferNetwork"));
|
||||
|
||||
StyleTransferSceneViewExtension = FSceneViewExtensions::NewExtension<FStyleTransferSceneViewExtension>(ViewportClient, StyleTransferNetwork, StyleTransferInferenceContext);
|
||||
}
|
||||
|
||||
void UStyleTransferSubsystem::UpdateStyle(FNeuralTensor StyleImage)
|
||||
void UStyleTransferSubsystem::UpdateStyle(const FNeuralTensor& StyleImage)
|
||||
{
|
||||
checkf(StyleTransferSceneViewExtension.IsValid(), TEXT("Can not update style while not stylizing"));
|
||||
|
||||
StylePredictionNetwork->SetInputFromArrayCopy(StyleImage.GetArrayCopy<float>());
|
||||
|
||||
ENQUEUE_RENDER_COMMAND(StylePrediction)([this](FRHICommandListImmediate& RHICommandList)
|
||||
|
@ -71,7 +80,17 @@ void UStyleTransferSubsystem::UpdateStyle(FNeuralTensor StyleImage)
|
|||
|
||||
StylePredictionNetwork->Run(GraphBuilder, StylePredictionInferenceContext);
|
||||
|
||||
// @todo: copy output of style prediction network to input of style transfer network
|
||||
const FNeuralTensor& OutputStyleParams = StylePredictionNetwork->GetOutputTensorForContext(StylePredictionInferenceContext, 0);
|
||||
const FNeuralTensor& InputStyleParams = StyleTransferNetwork->GetInputTensorForContext(StyleTransferInferenceContext, StyleTransferStyleParamsInputIndex);
|
||||
|
||||
FRDGBufferRef OutputStyleParamsBuffer = GraphBuilder.RegisterExternalBuffer(OutputStyleParams.GetPooledBuffer());
|
||||
FRDGBufferRef InputStyleParamsBuffer = GraphBuilder.RegisterExternalBuffer(InputStyleParams.GetPooledBuffer());
|
||||
const uint64 NumBytes = OutputStyleParams.NumInBytes();
|
||||
check(OutputStyleParamsBuffer->GetSize() == InputStyleParamsBuffer->GetSize());
|
||||
check(OutputStyleParamsBuffer->GetSize() == OutputStyleParams.NumInBytes());
|
||||
check(InputStyleParamsBuffer->GetSize() == InputStyleParams.NumInBytes());
|
||||
|
||||
AddCopyBufferPass(GraphBuilder, InputStyleParamsBuffer, OutputStyleParamsBuffer);
|
||||
|
||||
GraphBuilder.Execute();
|
||||
});
|
||||
|
|
|
@ -9,7 +9,7 @@ public:
|
|||
using Ptr = TSharedPtr<FStyleTransferSceneViewExtension, ESPMode::ThreadSafe>;
|
||||
using Ref = TSharedRef<FStyleTransferSceneViewExtension, ESPMode::ThreadSafe>;
|
||||
|
||||
FStyleTransferSceneViewExtension(const FAutoRegister& AutoRegister, FViewportClient* AssociatedViewportClient, UNeuralNetwork* InStyleTransferNetwork);
|
||||
FStyleTransferSceneViewExtension(const FAutoRegister& AutoRegister, FViewportClient* AssociatedViewportClient, UNeuralNetwork* InStyleTransferNetwork, int32 InInferenceContext);
|
||||
|
||||
// - ISceneViewExtension
|
||||
virtual void SubscribeToPostProcessingPass(EPostProcessingPass Pass, FAfterPassCallbackDelegateArray& InOutPassCallbacks, bool bIsPassEnabled) override;
|
||||
|
|
|
@ -25,7 +25,7 @@ public:
|
|||
|
||||
void StartStylizingViewport(FViewportClient* ViewportClient);
|
||||
|
||||
void UpdateStyle(FNeuralTensor StyleImage);
|
||||
void UpdateStyle(const FNeuralTensor& StyleImage);
|
||||
|
||||
private:
|
||||
FStyleTransferSceneViewExtension::Ptr StyleTransferSceneViewExtension;
|
||||
|
@ -36,5 +36,8 @@ private:
|
|||
UPROPERTY()
|
||||
TObjectPtr<UNeuralNetwork> StylePredictionNetwork;
|
||||
|
||||
int32 StylePredictionInferenceContext = -1;
|
||||
int32 StylePredictionInferenceContext = INDEX_NONE;
|
||||
int32 StyleTransferInferenceContext = INDEX_NONE;
|
||||
|
||||
int32 StyleTransferStyleParamsInputIndex = INDEX_NONE;
|
||||
};
|
||||
|
|
|
@ -3,11 +3,15 @@
|
|||
#include "OutputTensorToSceneColorCS.h"
|
||||
#include "Utils.h"
|
||||
|
||||
|
||||
const FIntVector FOutputTensorToSceneColorCS::ThreadGroupSize{8, 8, 1};
|
||||
|
||||
void FOutputTensorToSceneColorCS::ModifyCompilationEnvironment(const FGlobalShaderPermutationParameters& Parameters, FShaderCompilerEnvironment& OutEnvironment)
|
||||
{
|
||||
FGlobalShader::ModifyCompilationEnvironment(Parameters, OutEnvironment);
|
||||
|
||||
OutEnvironment.SetDefine(TEXT("THREADGROUP_SIZE_X"), ThreadGroupSize.X);
|
||||
OutEnvironment.SetDefine(TEXT("THREADGROUP_SIZE_Y"), ThreadGroupSize.Y);
|
||||
OutEnvironment.SetDefine(TEXT("THREADGROUP_SIZE_Z"), ThreadGroupSize.Z);
|
||||
}
|
||||
|
||||
IMPLEMENT_GLOBAL_SHADER(FOutputTensorToSceneColorCS, "/Plugins/StyleTransfer/Shaders/Private/OutputTensorToSceneColor.usf", "OutputTensorToSceneColorCS", SF_Compute); // Path defined in StyleTransferModule.cpp
|
|
@ -3,15 +3,16 @@
|
|||
#include "SceneColorToInputTensorCS.h"
|
||||
#include "Utils.h"
|
||||
|
||||
const FIntVector FSceneColorToInputTensorCS::ThreadGroupSize{8, 8, 1};
|
||||
|
||||
|
||||
void FSceneColorToInputTensorCS::ModifyCompilationEnvironment(const FGlobalShaderPermutationParameters& Parameters, FShaderCompilerEnvironment& OutEnvironment)
|
||||
{
|
||||
FGlobalShader::ModifyCompilationEnvironment(Parameters, OutEnvironment);
|
||||
|
||||
OutEnvironment.SetDefine(TEXT("THREADGROUP_SIZE_X"), THREADGROUP_SIZE_X);
|
||||
OutEnvironment.SetDefine(TEXT("THREADGROUP_SIZE_Y"), THREADGROUP_SIZE_Y);
|
||||
OutEnvironment.SetDefine(TEXT("THREADGROUP_SIZE_Z"), 1);
|
||||
OutEnvironment.SetDefine(TEXT("THREADGROUP_SIZE_X"), ThreadGroupSize.X);
|
||||
OutEnvironment.SetDefine(TEXT("THREADGROUP_SIZE_Y"), ThreadGroupSize.Y);
|
||||
OutEnvironment.SetDefine(TEXT("THREADGROUP_SIZE_Z"), ThreadGroupSize.Z);
|
||||
}
|
||||
|
||||
IMPLEMENT_GLOBAL_SHADER(FSceneColorToInputTensorCS,
|
||||
|
|
|
@ -16,9 +16,11 @@ class STYLETRANSFERSHADERS_API FOutputTensorToSceneColorCS : public FGlobalShade
|
|||
DECLARE_GLOBAL_SHADER(FOutputTensorToSceneColorCS);
|
||||
SHADER_USE_PARAMETER_STRUCT(FOutputTensorToSceneColorCS, FGlobalShader)
|
||||
|
||||
static const FIntVector ThreadGroupSize;
|
||||
|
||||
BEGIN_SHADER_PARAMETER_STRUCT(FParameters, )
|
||||
SHADER_PARAMETER(uint32, TensorVolume)
|
||||
SHADER_PARAMETER_RDG_BUFFER_SRV(Buffer<float>, InputTensor)
|
||||
SHADER_PARAMETER_RDG_BUFFER_SRV(Buffer<float3>, InputTensor)
|
||||
SHADER_PARAMETER_RDG_TEXTURE_UAV(RWTexture2D, OutputTexture)
|
||||
END_SHADER_PARAMETER_STRUCT()
|
||||
|
||||
|
|
|
@ -16,8 +16,9 @@ class STYLETRANSFERSHADERS_API FSceneColorToInputTensorCS : public FGlobalShader
|
|||
DECLARE_GLOBAL_SHADER(FSceneColorToInputTensorCS);
|
||||
SHADER_USE_PARAMETER_STRUCT(FSceneColorToInputTensorCS, FGlobalShader)
|
||||
|
||||
static const uint32 THREADGROUP_SIZE_X = 8;
|
||||
static const uint32 THREADGROUP_SIZE_Y = 8;
|
||||
|
||||
static const FIntVector ThreadGroupSize;
|
||||
|
||||
|
||||
BEGIN_SHADER_PARAMETER_STRUCT(FParameters, )
|
||||
// Input variables
|
||||
|
@ -26,6 +27,9 @@ class STYLETRANSFERSHADERS_API FSceneColorToInputTensorCS : public FGlobalShader
|
|||
SHADER_PARAMETER_RDG_BUFFER_UAV(RWBuffer<float>, OutputUAV)
|
||||
// Optional SRV/UAV variables
|
||||
SHADER_PARAMETER_RDG_TEXTURE(Texture2D, InputTexture)
|
||||
SHADER_PARAMETER_SAMPLER(SamplerState, InputTextureSampler)
|
||||
SHADER_PARAMETER(FIntPoint, OutputDimensions)
|
||||
SHADER_PARAMETER(FVector2f, HalfPixelUV)
|
||||
END_SHADER_PARAMETER_STRUCT()
|
||||
|
||||
// - FShader
|
||||
|
|
|
@ -16,5 +16,7 @@ public class LyraEditorTarget : TargetRules
|
|||
|
||||
// This is used for touch screen development along with the "Unreal Remote 2" app
|
||||
EnablePlugins.Add("RemoteSession");
|
||||
|
||||
IncludeOrderVersion = EngineIncludeOrderVersion.Latest;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||
|
||||
#include "EditorValidator.h"
|
||||
#include "AssetRegistry/AssetData.h"
|
||||
#include "AssetRegistry/AssetRegistryModule.h"
|
||||
#include "AssetData.h"
|
||||
#include "AssetRegistryModule.h"
|
||||
#include "Logging/MessageLog.h"
|
||||
#include "MessageLogModule.h"
|
||||
#include "Misc/ConfigCacheIni.h"
|
||||
|
@ -435,16 +435,16 @@ void UEditorValidator::GetChangedAssetsForCode(IAssetRegistry& AssetRegistry, co
|
|||
if (UClass* ModifiedClass = ModifiedClassPtr.Get())
|
||||
{
|
||||
// This finds all native derived blueprints, both direct subclasses, or subclasses of subclasses.
|
||||
TSet<FTopLevelAssetPath> DerivedClassNames;
|
||||
TArray<FTopLevelAssetPath> ClassNames;
|
||||
ClassNames.Add(ModifiedClass->GetClassPathName());
|
||||
AssetRegistry.GetDerivedClassNames(ClassNames, TSet<FTopLevelAssetPath>(), DerivedClassNames);
|
||||
TSet<FName> DerivedClassNames;
|
||||
TArray<FName> ClassNames;
|
||||
ClassNames.Add(ModifiedClass->GetFName());
|
||||
AssetRegistry.GetDerivedClassNames(ClassNames, TSet<FName>(), DerivedClassNames);
|
||||
|
||||
UE_LOG(LogLyraEditor, Display, TEXT("Validating Subclasses of %s in %s + %s"), *ModifiedClass->GetName(), *ChangedHeaderModule, *ChangedHeaderReleativeToModule);
|
||||
|
||||
FARFilter Filter;
|
||||
Filter.bRecursiveClasses = true;
|
||||
Filter.ClassPaths.Add(UBlueprintCore::StaticClass()->GetClassPathName());
|
||||
Filter.ClassNames.Add(UBlueprintCore::StaticClass()->GetFName());
|
||||
|
||||
// We enumerate all assets to find any blueprints who inherit from native classes directly - or
|
||||
// from other blueprints.
|
||||
|
@ -460,7 +460,7 @@ void UEditorValidator::GetChangedAssetsForCode(IAssetRegistry& AssetRegistry, co
|
|||
{
|
||||
const FString ClassObjectPath = FPackageName::ExportTextPathToObjectPath(ClassFromData);
|
||||
const FString ClassName = FPackageName::ObjectPathToObjectName(ClassObjectPath);
|
||||
if (DerivedClassNames.Contains(FTopLevelAssetPath(ClassName)))
|
||||
if (DerivedClassNames.Contains(FName(*ClassName)))
|
||||
{
|
||||
UE_LOG(LogLyraEditor, Display, TEXT("\tAdding %s To Validate"), *PackageName);
|
||||
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
|
||||
|
||||
#include "GameFeatureAction_StyleTransfer.h"
|
||||
|
||||
#include "StyleTransferSubsystem.h"
|
||||
|
||||
void UGameFeatureAction_StyleTransfer::OnGameFeatureActivating(FGameFeatureActivatingContext& Context)
|
||||
{
|
||||
Super::OnGameFeatureActivating(Context);
|
||||
}
|
||||
|
||||
void UGameFeatureAction_StyleTransfer::OnGameFeatureDeactivating(FGameFeatureDeactivatingContext& Context)
|
||||
{
|
||||
Super::OnGameFeatureDeactivating(Context);
|
||||
|
||||
// @todo shutdown cleanly
|
||||
}
|
||||
|
||||
void UGameFeatureAction_StyleTransfer::AddToWorld(const FWorldContext& WorldContext, const FGameFeatureStateChangeContext& ChangeContext)
|
||||
{
|
||||
auto* StyleTransferSubsystem = WorldContext.OwningGameInstance->GetSubsystem<UStyleTransferSubsystem>();
|
||||
|
||||
UGameViewportClient* GameViewportClient = WorldContext.GameViewport;
|
||||
StyleTransferSubsystem->StartStylizingViewport(GameViewportClient);
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameFeatureAction_WorldActionBase.h"
|
||||
#include "UObject/Object.h"
|
||||
#include "GameFeatureAction_StyleTransfer.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class LYRAGAME_API UGameFeatureAction_StyleTransfer : public UGameFeatureAction_WorldActionBase
|
||||
{
|
||||
GENERATED_BODY()
|
||||
public:
|
||||
virtual void OnGameFeatureActivating(FGameFeatureActivatingContext& Context) override;
|
||||
virtual void OnGameFeatureDeactivating(FGameFeatureDeactivatingContext& Context) override;
|
||||
private:
|
||||
virtual void AddToWorld(const FWorldContext& WorldContext, const FGameFeatureStateChangeContext& ChangeContext) override;
|
||||
};
|
Loading…
Reference in New Issue