How to get the scene Accelerate Structure (TLAS) for custom Ray Tracing

I want to cast custom rays in order to compute something specific. I will be casting 1 ray per texture pixel, probably 1024X1024.
I’ve set up everything I need in order to do so; shader, parameters, buffers, render thread function and even the actual call for RayTrace().

I’m missing only 1 thing: the Accelerated Structure (AKA TLAS).

I’ve been searching high and low and there is a severe lack of documentation for that. I’ve found example on how to create your own TLAS, but that means using my own geometry, and not the scene’s (See RayTracingTestbed.cpp).

All the actual usages in UE get their TLAS injected as input. and when I trace it back it leads to hard coded calls and private APIs which I don’t have any access to via my plugin.

I would appreciate any help on how to find access to it.
Thanks!

1 Like
GetWorld()->Scene->GetRenderScene()->RayTracingScene->GetLayerSRVChecked(ERayTracingSceneLayer::Base);
1 Like

Made it work
here’s a full tutorial

1 Like

Do you know if this feature is available on linux? I tried to run it on linux but I have the same issue of this topic: Help needed: have a problem with custom RTX shader plugin

Off course I enabled Ray Traced Shadows and Ray Traced Skylight but on linux is still failing on GetLayerSRVChecked.

1 Like

This works in UE 5.1 & 5.2.

GetWorld()->Scene->GetRenderScene()->RayTracingScene->GetLayerSRVChecked(ERayTracingSceneLayer::Base);

In 5.3, it was replaced with GetLayerView which does not return a FRHIShaderResourceView. Instead, it returns a FRDGBufferSRVRef.

GetWorld()->Scene->GetRenderScene()->RayTracingScene->GetLayerView(ERayTracingSceneLayer::Base);

Does anyone know how to get the TLAS from the FRDGBufferSRVRef without it failing an assert? I tried using GetRHI(), but it fails on an assert:

checkf(DebugData->bAllowRHIAccess || GRDGAllowRHIAccess,
	TEXT("Accessing the RHI resource of %s at this time is not allowed. If you hit this check in pass, ")
	TEXT("that is due to this resource not being referenced in the parameters of your pass."),
	Name);

UPDATE: I was able to get it to work in 5.3. GetRHI() must be called inside the render pass, otherwise it fails the assert.

FRDGBufferSRVRef layerView = GetWorld()->Scene->GetRenderScene()->RayTracingScene->GetLayerView(ERayTracingSceneLayer::Base);

if (layerView)
{
    GraphBuilder->AddPass(...,
        [PassParameters, layerView](FRHIRayTracingCommandList& RHICmdList)
        {
            // Must call GetRHI() inside the render pass like this!
            PassParameters->TLAS = layerView->GetRHI();

            // ..
        }

}
2 Likes

with 5.4 it should be possible to run on Linux with Vulkan, or its still missing something? The shader should be written with vulkan API?

Hey could you show the includes for this by any chance?
I have a similar setup and in 5.6 I’m now getting the following error when including Runtime/Renderer/Private/ScenePrivate.h

MeshDrawCommands.h(10,1): Error C1083 : Cannot open include file: ‘TranslucentPassResource.h’: No such file or directory

This worked fine in 5.5