I have multiple runtime PCG volumes in my scene, which uses HLSL point processor and GPU static mesh spawners.
When I walk around the map, the runtime cells gets culled in and out, depending on my camera angle.
After investigating, I’ve got to the solution below.
I really just want to ask if you think that’s a reasonable fix or wasn’t actually a bug (is it has a real reason to not accumulate the dirty flags?).
The bug
MarkCellBoundsDirty (SceneCulling.cpp:1911) keeps two “needs a bounds rebuild” flags per cell, one for static chunks and one for dynamic chunks. Stock UE assigns them instead of combining them. If a cell gets marked twice in the same frame:
- A static change marks it, for example a grass’s instance update (line 2116).
- Something else in the same cell marks it dynamic-only (line 2032 or line 1595). That call writes
falseinto the static flag.
The cell stays in the dirty list, but the rebuild step (line 2535) only recomputes static chunks when the static flag is set. The grass’s chunk bounds keep their old data, and the GPU culls against those as the camera moves.
The fix
OR the dirty flags into the masks instead of overwriting them. A cell that already has a static mark keeps it until the bounds rebuild runs.
SC_FORCEINLINE void MarkCellBoundsDirty(int32 CellIndex, bool bStaticChanged, bool bDynamicChanged)
{
if (ExplicitBoundsMode == EExplicitBoundsUpdateMode::Incremental)
{
if (!(DirtyCellBoundsMaskStatic[CellIndex] || DirtyCellBoundsMaskDynamic[CellIndex]))
{
DirtyCellBoundsIndices.Add(CellIndex);
}
//BEGIN MAGIC SOUP - rmartinez - Accumulate dirty flags; assigning let a later dynamic-only mark clear a static mark from the same frame, leaving static chunk bounds stale
if (bStaticChanged)
{
DirtyCellBoundsMaskStatic[CellIndex] = true;
}
if (bDynamicChanged)
{
DirtyCellBoundsMaskDynamic[CellIndex] = true;
}
//END MAGIC SOUP
}
}
[Attachment Removed]