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:
Using either FSceneViewExtensionBase or ISceneViewExtension to pass the data in the form of a Global Shader Parameter Struct.
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.
Hi, I know this is not quite what you are asking for, but if you just want get the mouse position inside the material, you can use hlsl code ResolvedView.CursorPosition inside a custom node.
I’ve used a dynamic material to send a 100x1 texture and never noticed a delay that big. There is a small delay, but I would never describe it as “noticeable”. The delay you might see when sending the mouse cursor position on event tick to the material is due to a software limitation. See the following discussion: Mouse cursor lag (very noticable).
In the UnrealEngine bug tracker, the developers responded to this issue as follows:
In my previous answer here I mentioned using ResolvedView.CursorPosition in the custom node expression, right inside the material. I find this to be the fastest way since you just get the cursor position from the buffer directly without having to pass the data yourself at all. You most likely won’t be able to have a faster approach.
Comment: I’ve also had some issues in the past that I wanted to solve by passing parameters to the shader directly. To be honest, I haven’t come anywhere close. I’ve come to the conclusion that you’d probably have to modify the source code or write a hell of a lot of code to make it possible. What you’ve done doesn’t seem wrong as a first step, but then you’d need to pass those parameters to the correct “pass” which is done in some source code file. You could try looking at how it’s done in the “…\Runtime\Renderer\Private\BasePassRendering.cpp” file, I believe the function “AddPass” is used to send the parameters to the rendering thread, but I’m not 100% sure that’s the right file for the post-processing pass. So… Before you try to continue doing what you’re doing, check what the actual problem is first. Because I don’t think you want to do all that hard work to get something other than what you originally wanted.
Thank you very much, hiding the hardware mouse and using the software one does seem to provide the final result that i was aiming for. Though i am still curious about passing data between threads because it seems like something that could be very useful, so i will keep looking.