Segmented Skeletal Mesh Ray tracing Issue

When a skeletal mesh has segments with no vertex buffers it is possible for the mesh to be removed from the raytracing world and readded constantly. This manifests as a flickering mesh in the raytracing views.

In `void FSkeletalMeshObjectGPUSkin::UpdateRayTracingGeometry_Internal` there are two code paths.

* One for when bRequireRecreatingRayTracingGeometry is true

* And an else for when !bAnySegmentUsesWorldPositionOffset

The creation path has some code to catch when vertex buffers are null (with some nice TODO’s).

else if (Segment.VertexBuffer == nullptr) // TODO: Consider always doing this when !Segment.bEnabled
{
    // TODO: RHIs should accept NULL VertexBuffer when Segment is disabled.
    // For now use the static PositionVertexBuffer as placeholder.
    // TODO: Consider also setting Segment.NumPrimitives = 0; in this case
    Segment.VertexBuffer = LODModel.StaticVertexBuffers.PositionVertexBuffer.GetRHI();
}

This just sets a value so things play nicer later in the flow.

The else if case has an issue, it does not do this default buffer setting and instead leaves these values as NULL. Later in the frame this RayTracingGeometry is considered invalid due to the NULL stream and removed from the raytracing world.

What this means is that every other frame the object is added (the recreate path executes), then then next frame since it’s already created the update path runs and sets these fields to null and the object is removed. This leads to the object being valid for raytracing every second frame.

The fix I have added locally is to add the default streams in the else case just like in the main case:

else if (!bAnySegmentUsesWorldPositionOffset)
{
    check(LODModel.RenderSections.Num() == RayTracingGeometry.Initializer.Segments.Num());

    // Refit BLAS with new vertex buffer data
    for (int32 SectionIndex = 0; SectionIndex < LODModel.RenderSections.Num(); ++SectionIndex)
    {
       FRayTracingGeometrySegment& Segment = RayTracingGeometry.Initializer.Segments[SectionIndex];
       Segment.VertexBuffer = VertexBuffers[SectionIndex];
       Segment.VertexBufferOffset = 0;

       // ADDED CODE
       if (Segment.VertexBuffer == nullptr)
       {
          Segment.VertexBuffer = LODModel.StaticVertexBuffers.PositionVertexBuffer.GetRHI();
       }
       // END ADDED CODE
    }
}

We are on 5.7.1 so maybe this is already fixed in main :slight_smile:

[Attachment Removed]

Steps to Reproduce[Attachment Removed]

Hello,

Thank you for reaching out.

I’ve been assigned this issue, and we will be looking into these flickering skeletal meshes for you.

Can you please send us a minimal test project that demonstrates this flickering, and include a video of the issue?

The guide for test projects:

[Content removed]

[Attachment Removed]