Passing data from GameThread to Render thread.

Alex196
Sat, 21 Jun 2025 00:48:04 +0000
Programming & Scripting

Hello, i am looking for a way to transfer a FVector2f variable from the GameThread to the RenderThread every frame and making the variable visible/usable by a post processing material without (or with minimal) frame delay. Common options like Material Parameter Collection and creating a Dynamic Material Instance and updating values in it via EventTick are too slow and have very noticeable lag.

The 2 main ways that i am being bounced between are:

1. Using either FSceneViewExtensionBase or ISceneViewExtension to pass the data in the form of a Global Shader Parameter Struct.

2. Using ENQUEUE_RENDER_COMMAND with the same general idea.

Despite my best efforts i’ve barely been able to find any good information or tutorials on the subject and i am now growing desperate. The closest to success that i think i’ve gotten is the following code.

.h file

#pragma once

#include "CoreMinimal.h"
#include "SceneViewExtension.h"
#include "UniformBuffer.h"
#include "ShaderParameterUtils.h"
#include "SceneView.h"

BEGIN_GLOBAL_SHADER_PARAMETER_STRUCT(FMouseUVUniformParameters, )
SHADER_PARAMETER(FVector2f, MouseUV)
END_GLOBAL_SHADER_PARAMETER_STRUCT()

typedef TUniformBufferRef<FMouseUVUniformParameters> FMouseUVUniformBufferRef;

class MYPROJECT_API FCursorUVViewExtension : public FSceneViewExtensionBase

public:
	FCursorUVViewExtension(const FAutoRegister& AutoRegister) : FSceneViewExtensionBase(AutoRegister){}


  virtual void SetupView(FSceneViewFamily& InViewFamily, FSceneView& InView) override
{
    FMouseUVUniformParameters Params;
    Params.MouseUV = CurrentMouseUV.Load();


  FMouseUVUniformBufferRef UBRef =
FMouseUVUniformBufferRef::CreateUniformBufferImmediate(
        Params, UniformBuffer_SingleFrame
    );
}

static void SetMouseUV(const FVector2f& InUV)
{
    CurrentMouseUV.Store(InUV);
}

private
static TAtomic<FVector2f>CurrentMouseUV;
}

If i understand correctly, i am successfully creating the buffer and filling it with the variable. However i have no idea how to correctly use now.

As i’ve said i am now almost completely stuck and would be incredibly grateful for any help or any good reading material/tutorials on the topic.

4 posts - 2 participants