尝试进行灵活/通用的最小距离详细距离范围系统
好吧,我想为我的游戏创建一个详细系统来加载地形。
这里的重点是我想将最小表达式用于距离,因此我在拐角处加载的所有块,但没有冗余部分,例如:
此:
此处的目的是具有最大渲染距离,而GameObject的最小计数要加载。
我有两个主要问题的问题,对于非基数的初始最小距离,系统不灵活。
浏览了类似的内容:
另一件事是必须修补距离:
//// If the number is even, then we must do this patch
if (currentDistanceLevel == 128)
sum += currentDistanceLevel / 2; // TODO, why?
我不明白为什么...
这就是发生的情况:
这是我的代码:
/// <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.sstatic.net/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
}
}
}
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.sstatic.net/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
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论