Download

Rendering in UE4

Hello,
I have a question on rendering with directx11 in unreal engine 4. There are many different direct3d libraries included in Unreal Engine 4’s source code that I can’t pick apart for rendering. There is the standalone renderer, the slate renderer, slate3d renderer and the d3d11rhi libraries. Which one should be used to utilize directcompute?

RHI is where most of the magic happens for gameplay. Slate and Slate3D are for rendering menu and UI elements. The standalone is for other things.

But the RHI is how UE4’s independent rendering code interfaces with platform-dependent rendering libraries, such as DirectX, OpenGL, Android Renderer, etc.

Great, thank you shigan5!
I had another question, if RHI interfaces with platform-dependent rendering libraries, would you happen to know if I were to be performing directx programming would I use d3dRHI functions to retrieve my depth stencil and my render target view?

And would you happen to know how to reference the current device being used direct3d device under the d3dRHI api, or where the device is created in the code?

Hello v1X3Q0!

I created a tutorial plugin project a while back that illustrates how to create custom shaders (vertex, pixel, compute) shaders on the project level.
If you’re still interested in creating a compute shader, you’re welcome to check it out :slight_smile:

I’ve also created a plugin for more easily using renderdoc in UE4 if you would like to debug the shaders you’re working on as well :slight_smile:

Hope this helps!

Best regards,
Temaran

Thank you Temaran,
I have already seen at least your shaderPluginDemo I thought that much was very helpful. I was actually wondering if it was possible to somewhat assume that the device is already a Direct 3d device and to use the D3D11 RHI libraries in the UE4 source code to perform actions such as retrieving the direct3d device, or perform any other direct3d functions. The reason I was wondering this was because I already have code written in terms of direct3d11 and I didn’t want to convert the entire thing to the standard RHI format it seems that UE4 requires.

Hello again v1X3Q0!

I’m sure you are already aware that if you get the pointer and manipulate it directly you will lose support for anything but certain windows platforms, but I feel awkward not mentioning it, so sorry about that :frowning:
Anyways! Searching a bit in the solution, it seems very possible to access the device directly, even without Cpp haxx.

One thing I found was a global in DynamicRHI.h:51 (GDynamicRHI).
You will of course have to include the RHI module in your build scripts and include the proper header file in the place you want to access it, but you can then cast and get the device like this:

Your build script:



		PublicDependencyModuleNames.AddRange(new string] { 
                //Other stuff
                , "RHI"
	}); 


Your code:



FD3D11DynamicRHI* D3D11RHIPtr = Cast<FD3D11DynamicRHI>(GDynamicRHI);
ID3D11Device* DevicePtr = D3D11RHIPtr->GetDevice();


I’m pretty sure you will need to schedule any operations you want to do with the device on the render thread to avoid problems, but you can check out my plugin for how to do that.
And you would also of course need to include the D3D11.h header for the interface. :smiley:

I didn’t actually try this, so there might be some other stuff you need to do, but it seems like it would work :slight_smile:

I would still strongly recommend converting your code to the general RHI format though. Not only because doing direct access like this is fragile, but also because it might mess with the renderer and give unexpected results or slowdowns. If this is just for a test, I guess it doesn’t matter, but I really strongly suggest your just port your code :smiley:

Best regards,
Temaran