Realtime neural style transfer sample updated to Unreal Engine 5.5 and the Neural Network Engine (NNE) Render Dependency Graph (RDG) runtime. The project keeps all tensors on the GPU – camera input is encoded with a compute shader, inference runs through INNERuntimeRDG::EnqueueRDG, and the stylised frame is decoded and composited as a post-tonemap pass.
- Works out of the box on UE 5.5 with Direct3D 12 (fallback to D3D11 for debugging only).
- Uses the NNE
NNERuntimeRDGorNNERuntimeORTDmlbackends – no CPU staging buffers. - Custom RDG pipeline (
StyleTransferShaders.usf) to encode the scene into model input tensors and decode the inference output back to an HDR buffer. - Sample Blueprint (
Content/FirstPerson/Blueprints/StyleTransferConfig) that exposes style switching and hotkeys. - Utility script to tidy exported ONNX models before import (
Scripts/clean_onnx_initializers.py).
->
- Windows 10/11 with a D3D12 capable GPU.
- Unreal Engine 5.5 (tested with the launcher build).
- Visual Studio 2022 with the Game development with C++ workload if you intend to build from source.
- Python 3.8+ with
onnxinstalled (pip install onnx) to run the cleaning script.
git clone https://github.com/DeadMorose777/OnnxRuntime-UnrealEngine.git
cd OnnxRuntime-UnrealEngine/FPStyleTransferInside the Unreal Editor open Edit ▸ Plugins and make sure the following are enabled:
- Neural Network Engine
- Neural Rendering (ships with UE; provides useful examples)
Restart the editor when prompted.
You can build either from Visual Studio or the command line:
"C:\Program Files\Epic Games\UE_5.5\Engine\Build\BatchFiles\Build.bat" ^
FPStyleTransferEditor Win64 Development -Project="%CD%\FPStyleTransfer.uproject" -WaitMutexOnce the Editor target compiles, double-click FPStyleTransfer.uproject to open the sample map (Content/FirstPerson/Maps/FirstPersonMap).
- Export your model to ONNX. The sample network expects NCHW input shaped
1 x 3 x 224 x 224. - Remove initialiser tensors from the graph inputs – this keeps weights on the GPU and avoids const-folding issues:
The script emits
cd Scripts py clean_onnx_initializers.py ..\FPStyleTransfer\Content\Models\your_model.onnx
your_model.cleaned.onnxalongside the original. - Import the cleaned ONNX file into Unreal:
- In the Content Browser choose Add ▸ Import to… and pick the
.cleaned.onnx. - When prompted, create an NNE Model Data asset (leave precision at FP32).
- Update the Runtime property of the asset if you know you will target a specific backend (e.g.
NNERuntimeORTDmlon Windows).
- In the Content Browser choose Add ▸ Import to… and pick the
- (Optional) Move the asset into
Content/Modelsto mirror the existing samples.
Content/FirstPerson/Blueprints/StyleTransferConfig demonstrates how to:
-
Call
UStyleTransferBlueprintLibrary::SetStyle(ModelData, RuntimeName)on Begin Play to choose the default style. -
Use the 'Model Data' variable to easily swap between different UNNEModelData assets.

-
Disable the pass by calling
SetStylewith aNonereference (this also forcesr.RealtimeStyleTransfer.Enable = 0).
Feel free to duplicate the blueprint and customise the bindings or UI.
- Enable or disable the pass manually:
r.RealtimeStyleTransfer.Enable 1/0. - Switch log detail while debugging:
Log LogRealtimeStyleTransfer VeryVerbose Log LogStyleTransferNNE Verbose
SetStyle accepts an optional runtime name. Pass NNERuntimeRDGHlsl to force the HLSL backend or NNERuntimeORTDml to use the DirectML implementation. When no name is provided, the runtime configured on the UNNEModelData asset is used.
| Path | Purpose |
|---|---|
Source/FPStyleTransfer/RealtimeStyleTransferViewExtension.* |
Registers the RDG post-processing extension and drives encode/inference/decode. |
Source/FPStyleTransfer/StyleTransferShaders.* & Shaders/StyleTransfer.usf |
Custom compute shaders that convert between render targets and tensors. |
Source/FPStyleTransfer/MyNeuralNetwork.* |
Thin wrapper that creates an IModelInstanceRDG and stores tensor metadata on the game thread. |
Source/FPStyleTransfer/StyleTransferBlueprintLibrary.* |
Exposes SetStyle to Blueprints and the console. |
Scripts/clean_onnx_initializers.py |
Helper for sanitising exported ONNX graphs. |
Content/Models/*.cleaned.onnx |
Cleaned models used by the sample. |
- No visual change – ensure the runtime console variable is enabled (
r.RealtimeStyleTransfer.Enable 1) and that a model is assigned viaSetStyle. Check logs for the “Style transfer enabled…” message. - Enqueue failures – the log reports the RDG status code. Verify the runtime being requested is available (Plugins window) and that you are running with D3D12.
- Model import warnings – run the cleaning script. NNE expects initialiser tensors to live in
graph.initializer, not in the input list. - Performance – the sample runs at 224×224. Increase the tensor resolution in
RealtimeStyleTransferViewExtension.cppto trade speed for quality.
- Neural Post Processing with Unreal Engine NNE
- Epic’s
NeuralRenderingplugin (located inEngine/Plugins/Experimental/NeuralRendering/) contains additional examples that inspired this project.
The original FPStyleTransfer sample is distributed by Microsoft. Refer to the repository licence file for details.