Well, I'll like to create a level of detail system for my game to load the terrain.
The point here is that I'll like to use the minimum expression for distances, so all the chunks that I load match at the corners but there are no redundant parts, like here:
So, more something like this:
The purpose here is to have the maximum render distance with the minimum count of gameobjects to load.
I have two main concerns the system is not flexible for initial minimum distances that are non-base of 2.
As something like this is browsed:
Another thing is that distance must be patched:
//// If the number is even, then we must do this patch
if (currentDistanceLevel == 128)
sum += currentDistanceLevel / 2; // TODO, why?
I don't understand why...
This is what happens:
This is my code:
/// <summary>
/// Calculate the the minimum distances between level of detail chunks.
/// </summary>
/// <param name="lodLevels">The number of lod levels to go into.</param>
/// <param name="numberOfChunks">The number of chunks after the view distance from the ChunkGenerator system finishes.</param>
/// <returns>A list of distances to use on a grid of level of detail. (See https://i.gyazo.com/0ceb8ff3a4ebab8391532892fc8b6f82.png)</returns>
public static IEnumerable<float> CalculateOptimumLoDValues(int lodLevels, int numberOfChunks, int chunkSize)
{
var back = false;
var sum = 0;
var currentDistanceLevel = chunkSize;
for (var l = 1; l < lodLevels; l++)
{
// The last step is give the previous sum
yield return sum;
// At the second step, if we didn't went to the previous level
if (!back)
{
// We half the number of chunks of the previous level
numberOfChunks /= 2;
// And we double distance for the next level
currentDistanceLevel *= 2;
}
else
back = false;
numberOfChunks += 2;
// First, if we want to avoid this effect, we must do the following step.
// https://i.stack.imgur.com/1nfgd.png
// at https://stackoverflow.com/questions/72636128/trying-to-position-all-chunks-for-distinct-lod-levels
// ----------------
// If the following distance level has an odd number of elements then I try to match the current row/column by doubling it, in that way non of the following corner will be half of the previous one.
// The number of chunk on the rows goes, 16-10(8+2)-12(10+2)-8(12/2+2)-6(8/2+2)-8(12/2+2)-6(12/2+2)....
if (numberOfChunks / 2 % 2 != 0)
{
// Then, if the number is odd after summing the two corners and dividing it,
// we must go into he back level, set the flag to true and sum the distance
l--;
back = true;
sum += currentDistanceLevel * 3 / 4;
}
else
{
//// If the number is even, then we must do this patch
if (currentDistanceLevel == 128)
sum += currentDistanceLevel / 2; // TODO, why?
else
sum += currentDistanceLevel; // For the rest of the levels we sum it
}
}
}



