diff --git a/Config/DefaultGame.ini b/Config/DefaultGame.ini index 948ae0f2..468d9104 100644 --- a/Config/DefaultGame.ini +++ b/Config/DefaultGame.ini @@ -218,3 +218,8 @@ VoiceChatVolumeControlBus=/Game/Audio/Modulation/ControlBuses/CB_VoiceChat.CB_Vo LoadingScreenControlBusMix=/Game/Audio/Modulation/ControlBusMixes/CBM_LoadingScreenMix.CBM_LoadingScreenMix +[/Script/StyleTransfer.StyleTransferSettings] +StyleTransferNetwork=/StyleTransfer/NN_TransferWithWeights.NN_TransferWithWeights +StylePredictionNetwork=/StyleTransfer/NN_StylePredictorWithWeights.NN_StylePredictorWithWeights +StyleTexture=/StyleTransfer/T_StyleImage.T_StyleImage + diff --git a/Plugins/StyleTransfer/Content/NN_StylePredictor.uasset b/Plugins/StyleTransfer/Content/NN_StylePredictor.uasset deleted file mode 100644 index 668c7c07..00000000 --- a/Plugins/StyleTransfer/Content/NN_StylePredictor.uasset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:e4ed7196066ce72fc937861610095380a4d89be933b99f82db22ec1d96696347 -size 4092063 diff --git a/Plugins/StyleTransfer/Content/NN_StylePredictorWithWeights.uasset b/Plugins/StyleTransfer/Content/NN_StylePredictorWithWeights.uasset new file mode 100644 index 00000000..7fe71ed2 --- /dev/null +++ b/Plugins/StyleTransfer/Content/NN_StylePredictorWithWeights.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:64f9e1681b1389565fc4950e8df6570dcfeb484b580ec002be8f3a6343c357c3 +size 4092069 diff --git a/Plugins/StyleTransfer/Content/NN_StyleTransfer.uasset b/Plugins/StyleTransfer/Content/NN_StyleTransfer.uasset deleted file mode 100644 index 0556bbbe..00000000 --- a/Plugins/StyleTransfer/Content/NN_StyleTransfer.uasset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:1682560d011ef8c769ea03bc18f2b95849edb2e0e7deab9b62f786ddfbf2d2bc -size 6699914 diff --git a/Plugins/StyleTransfer/Content/NN_TransferWithWeights.uasset b/Plugins/StyleTransfer/Content/NN_TransferWithWeights.uasset new file mode 100644 index 00000000..db8dd6da --- /dev/null +++ b/Plugins/StyleTransfer/Content/NN_TransferWithWeights.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9700667d22f96f40fc7ef7c49e5380485eacf070b8736f4d7c0f3174c907f260 +size 6731903 diff --git a/Plugins/StyleTransfer/Source/StyleTransfer/Private/StyleTransferSettings.cpp b/Plugins/StyleTransfer/Source/StyleTransfer/Private/StyleTransferSettings.cpp new file mode 100644 index 00000000..5850cdd6 --- /dev/null +++ b/Plugins/StyleTransfer/Source/StyleTransfer/Private/StyleTransferSettings.cpp @@ -0,0 +1,9 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "StyleTransferSettings.h" + +UStyleTransferSettings::UStyleTransferSettings() +{ + this->CategoryName = NAME_Game; +} diff --git a/Plugins/StyleTransfer/Source/StyleTransfer/Private/StyleTransferSettings.h b/Plugins/StyleTransfer/Source/StyleTransfer/Private/StyleTransferSettings.h new file mode 100644 index 00000000..bc30c3aa --- /dev/null +++ b/Plugins/StyleTransfer/Source/StyleTransfer/Private/StyleTransferSettings.h @@ -0,0 +1,28 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "NeuralNetwork.h" +#include "UObject/Object.h" +#include "StyleTransferSettings.generated.h" + +/** + * + */ +UCLASS(Config=Game, defaultconfig, meta=(DisplayName="Style Transfer")) +class STYLETRANSFER_API UStyleTransferSettings : public UDeveloperSettings +{ + GENERATED_BODY() +public: + UStyleTransferSettings(); + + UPROPERTY(EditAnywhere, Config) + TSoftObjectPtr StyleTransferNetwork = nullptr; + + UPROPERTY(EditAnywhere, Config) + TSoftObjectPtr StylePredictionNetwork = nullptr; + + UPROPERTY(EditAnywhere, Config) + TSoftObjectPtr StyleTexture = nullptr; +}; diff --git a/Plugins/StyleTransfer/Source/StyleTransfer/Private/StyleTransferSubsystem.cpp b/Plugins/StyleTransfer/Source/StyleTransfer/Private/StyleTransferSubsystem.cpp index 8d947493..dd2d234e 100644 --- a/Plugins/StyleTransfer/Source/StyleTransfer/Private/StyleTransferSubsystem.cpp +++ b/Plugins/StyleTransfer/Source/StyleTransfer/Private/StyleTransferSubsystem.cpp @@ -9,6 +9,7 @@ #include "ScreenPass.h" #include "StyleTransferModule.h" #include "StyleTransferSceneViewExtension.h" +#include "StyleTransferSettings.h" #include "TextureCompiler.h" #include "Rendering/Texture2DResource.h" @@ -43,20 +44,21 @@ void UStyleTransferSubsystem::StartStylizingViewport(FViewportClient* ViewportCl if (!StyleTransferSceneViewExtension) { + const UStyleTransferSettings* StyleTransferSettings = GetDefault(); StylePredictionInferenceContext = StylePredictionNetwork->CreateInferenceContext(); checkf(StylePredictionInferenceContext != INDEX_NONE, TEXT("Could not create inference context for StylePredictionNetwork")); StyleTransferInferenceContext = MakeShared(StyleTransferNetwork->CreateInferenceContext()); checkf(*StyleTransferInferenceContext != INDEX_NONE, TEXT("Could not create inference context for StyleTransferNetwork")); - UTexture2D* StyleTexture = LoadObject(this, TEXT("/Script/Engine.Texture2D'/StyleTransfer/T_StyleImage.T_StyleImage'")); + UTexture2D* StyleTexture = StyleTransferSettings->StyleTexture.LoadSynchronous(); + //UTexture2D* StyleTexture = LoadObject(this, TEXT("/Script/Engine.Texture2D'/StyleTransfer/T_StyleImage.T_StyleImage'")); FTextureCompilingManager::Get().FinishCompilation({StyleTexture}); - //UpdateStyle(StyleTexture); - UpdateStyle(FPaths::GetPath("C:\\projects\\realtime-style-transfer\\temp\\style_params_tensor.bin")); + UpdateStyle(StyleTexture); + //UpdateStyle(FPaths::GetPath("C:\\projects\\realtime-style-transfer\\temp\\style_params_tensor.bin")); StyleTransferSceneViewExtension = FSceneViewExtensions::NewExtension(ViewportClient, StyleTransferNetwork, StyleTransferInferenceContext.ToSharedRef()); } StyleTransferSceneViewExtension->SetEnabled(true); - ViewportClient->GetWorld()->GetWorldSettings()->SetPauserPlayerState(ViewportClient->GetWorld()->GetFirstPlayerController()->PlayerState); } void UStyleTransferSubsystem::StopStylizingViewport() @@ -166,8 +168,9 @@ void UStyleTransferSubsystem::HandleConsoleVariableChanged(IConsoleVariable* Con void UStyleTransferSubsystem::LoadNetworks() { - StyleTransferNetwork = LoadObject(this, TEXT("/StyleTransfer/NN_StyleTransfer.NN_StyleTransfer")); - StylePredictionNetwork = LoadObject(this, TEXT("/StyleTransfer/NN_StylePredictor.NN_StylePredictor")); + const UStyleTransferSettings* StyleTransferSettings = GetDefault(); + StyleTransferNetwork = StyleTransferSettings->StyleTransferNetwork.LoadSynchronous(); + StylePredictionNetwork = StyleTransferSettings->StylePredictionNetwork.LoadSynchronous(); if (StyleTransferNetwork->IsLoaded()) { diff --git a/Plugins/StyleTransfer/Source/StyleTransfer/StyleTransfer.Build.cs b/Plugins/StyleTransfer/Source/StyleTransfer/StyleTransfer.Build.cs index 1593a211..495abe44 100644 --- a/Plugins/StyleTransfer/Source/StyleTransfer/StyleTransfer.Build.cs +++ b/Plugins/StyleTransfer/Source/StyleTransfer/StyleTransfer.Build.cs @@ -45,13 +45,7 @@ public class StyleTransfer : ModuleRules "StyleTransferShaders", "PixWinPlugin", "InputDevice", - } - ); - - - DynamicallyLoadedModuleNames.AddRange( - new string[] - { + "DeveloperSettings", } ); }