I was trying to understand how PrecomputedVisibility works in UE4 and then I found this:
const float FloatOffsetX = (View.ViewMatrices.ViewOrigin.X - Handler.PrecomputedVisibilityCellBucketOriginXY.X) / Handler.PrecomputedVisibilityCellSizeXY;
// FMath::TruncToInt rounds toward 0, we want to always round down
const int32 BucketIndexX = FMath::Abs((FMath::TruncToInt(FloatOffsetX) - (FloatOffsetX < 0.0f ? 1 : 0)) / Handler.PrecomputedVisibilityCellBucketSizeXY % Handler.PrecomputedVisibilityNumCellBuckets);
const float FloatOffsetY = (View.ViewMatrices.ViewOrigin.Y -Handler.PrecomputedVisibilityCellBucketOriginXY.Y) / Handler.PrecomputedVisibilityCellSizeXY;
const int32 BucketIndexY = FMath::Abs((FMath::TruncToInt(FloatOffsetY) - (FloatOffsetY < 0.0f ? 1 : 0)) / Handler.PrecomputedVisibilityCellBucketSizeXY % Handler.PrecomputedVisibilityNumCellBuckets);
const int32 PrecomputedVisibilityBucketIndex = BucketIndexY * Handler.PrecomputedVisibilityCellBucketSizeXY + BucketIndexX;
check(PrecomputedVisibilityBucketIndex < Handler.PrecomputedVisibilityCellBuckets.Num());
note that in calculating PrecomputedVisibilityBucketIndex, BucketIndexY is multiplied with Handler.PrecomputedVisibilityCellBucketSizeXY, but isn’t it wrong? Since in the definition of FPrecomputedVisibilityHandler we have:
private:
/** World space origin of the cell grid. */
FVector2D PrecomputedVisibilityCellBucketOriginXY;
/** World space size of every cell in x and y. */
float PrecomputedVisibilityCellSizeXY;
/** World space height of every cell. */
float PrecomputedVisibilityCellSizeZ;
/** Number of cells in each bucket in x and y. */
int32 PrecomputedVisibilityCellBucketSizeXY;
/** Number of buckets in x and y. */
int32 PrecomputedVisibilityNumCellBuckets;
shouldn’t PrecomputedVisibilityNumCellBuckets be used to multiply BucketIndexY other than PrecomputedVisibilityCellBucketSizeXY?
My guess is that since in the default configuration PrecomputedVisibilityCellBucketSizeXY == PrecomputedVisibilityNumCellBuckets == 5, so nobody actually met this problem. Please tell me is it really a bug?