Hi,
there are a few reasons the TLAS is invalid:
- the API for getting the TLAS has changed since 5.3, instead of getting it with RayTracingScene.GetLayerView(ERayTracingSceneLayer::Base), you now have to call GetRHI on the LayerView: please see https://forums.unrealengine.com/t/community-tutorial-how-to-create-a-custom-ray-tracing-shader-as-a-plugin/1139396/5 and https://forums.unrealengine.com/t/how-to-get-the-scene-accelerate-structure-tlas-for-custom-ray-tracing/696723/5
- after starting BeginPlay, a delay is required before accessing the TLAS as it may not be ready yet: please see https://forums.unrealengine.com/t/community-tutorial-how-to-create-a-custom-ray-tracing-shader-as-a-plugin/1139396/14. The community tutorial also adds a delay using TranscurredTime in ATestRunner::Tick() for this reason:
// we want a slight delay before we start, otherwise some resources such as the accelerated structure will not be ready
if(RenderTarget != nullptr && TranscurredTime>1.0f)
I’m not sure if a delay of one second is required, the duration probably depends on the complexity of the scene and its accompanying acceleration structure that needs to be build. There might also be a better way to know when the TLAS is ready to be used as SceneRendering.cpp has a few helper methods for this:
bool FViewInfo::HasRayTracingScene() const
{
check(Family);
FScene* Scene = Family->Scene ? Family->Scene->GetRenderScene() : nullptr;
if (Scene)
{
return Scene->RayTracingScene.IsCreated();
}
return false;
}
FRHIRayTracingScene* FViewInfo::GetRayTracingSceneChecked(ERayTracingSceneLayer Layer) const
{
check(Family);
if (Family->Scene)
{
if (FScene* Scene = Family->Scene->GetRenderScene())
{
FRHIRayTracingScene* Result = Scene->RayTracingScene.GetRHIRayTracingScene(Layer);
checkf(Result, TEXT("Ray tracing scene is expected to be created at this point."));
return Result;
}
}
return nullptr;
}
FRDGBufferSRVRef FViewInfo::GetRayTracingSceneLayerViewChecked(ERayTracingSceneLayer Layer) const
{
FRDGBufferSRVRef Result = nullptr;
check(Family);
if (Family->Scene)
{
if (FScene* Scene = Family->Scene->GetRenderScene())
{
Result = Scene->RayTracingScene.GetLayerView(Layer);
}
}
checkf(Result, TEXT("Ray tracing scene SRV is expected to be created at this point."));
return Result;
}
I hope this helps, but let me know if you have more questions.
Thanks,
Sam
[Attachment Removed]