Community Tutorial: How to Create a Custom Ray Tracing Shader as a Plugin

It turns out, getting the material parameters is not too complicated as Unreal can do most of the heavy lifting. This plugin on GitHub is an excellent example, although some changes need to be made for it to work in 5.6.

See the file RTXLidarComponent.cpp. Here are the key points that make it work:

  • They use two delegates FGlobalIlluminationPluginDelegates::PrepareRayTracing() and FGlobalIlluminationPluginDelegates::RenderDiffuseIndirectLight(), registered in URTXLidarComponent::Startup()
    • PrepareRayTracing registers the ray gen shader in Unreal’s material ray tracing pipeline.
    • RenderDiffuseIndirectLight is the actual render pass. After registering the RGS in PrepareRayTracing, View.MaterialRayTracingData will contain the pipeline state and SBT that need to be passed to RayTraceDispatch in order for the RGS to be invoked in Unreal’s material ray tracing pipeline.

Some more notes:

  • For these delegates to be invoked at all, Dynamic Global Illumination needs to be set to “Plugin” in the project settings.
  • The PostOpaqueRenderDelegate used in the tutorial does not work with this. Use RenderDiffuseIndirectLight instead.
  • A lot of the manual setup done in the tutorial is not actually necessary. What really needs to be done in the render pass is setting the shader parameters, calling the dispatch function and writing the result to a render target.
1 Like