边界框平截头体渲染 - 距离渲染 - OpenGL

发布于 2024-11-14 11:12:37 字数 319 浏览 9 评论 0原文

我正在渲染一个旧的游戏格式,其中有一个网格物体列表,这些网格物体构成了您所在的位置。我终于让 PVS(从另一个区域可见的区域)工作了,并且剪掉了很多我不知道的网格物体需要渲染,但渲染不多。所以现在,我应该渲染的网格列表仅包括我可以看到的其他网格。但它并不完美。仍然有大量的网格,包括超出剪辑的非常远的网格。

现在,首先,我尝试剔除不在我的视锥体中的网格。我听说边界框是执行此操作的最佳方法。有谁知道我该怎么做?我知道我需要最大点 (x, yz) 和最小点 (x, yz),以便盒子包含所有顶点。

然后,我是否检查这些点中的任何一个是否在我的视锥体中?真有这么简单吗?

谢谢你!

I am rendering an old game format where I have a list of meshes that make up the are you are in. I have finally gotten the PVS (regions visible from another region) working and that cuts out a lot of the meshes I don't need to render but not by much. So now, my list of meshes I should render only includes the other meshes I can see. But it isn't perfect. There are still a ton of meshes include really far away ones that are past the clip.

Now first, I am trying to cull out meshes that aren't in my view frustum. I have heard that a bounding box is the best way to go about doing this. Does anyone have an idea about how I can go about this? I know I need the maximum point (x, y z) and the minimum point (x, y z) so that a box encompasses all of the verticies.

Then, do I check and see if either of those points are in my view frustum? Is it that simple?

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

醉态萌生 2024-11-21 11:12:37

AABB 或轴对齐边界框是一个非常简单且快速的对象,用于测试两个 3D 区域的相交/包含。

正如您所建议的,您正在计算要比较的两个区域的最小和最大 x,y,z,例如,描述平截头体的区域和描述网格的区域。它是轴对齐的,因为后续立方体的边与坐标系的每个轴平行。显然,这可能稍微不准确(相交/包含的误报,但绝不会漏报),因​​此一旦您使用 AABB 测试过滤列表,您可能会考虑对剩余的网格执行更准确的测试。

您可以按如下方式测试相交/包含:

F = 平截头体的 AABB

M = 网格的 AABB

bool is_mesh_in_frustum(const AABB& F, const AABB& M)
{
    if( F.min.x > M.max.x || M.min.x > F.max.x || F.min.y > M.max.y || M.min.y > F.max.y || F.min.z > M.max.z || M.min.z > F.max.z )
    {
        return false;
    }
    return true;
}

您还可以查找边界球、定向边界框 (OBB) 和其他类型的边界体积的算法。根据渲染的网格数量,您可能需要也可能不需要更准确的方法。

要首先创建 AABB,您可以简单地遍历网格的顶点并记录您遇到的最小/最大 x、y 和 z 值。

还要考虑到,如果网格不变形,则网格坐标空间中的边界框将是静态的,因此只要获得顶点数据,就可以计算所有网格的 AABB。

然后,您只需确保在测试每个渲染通道之前将预先计算的 AABB 最小和最大顶点转换到平截头体坐标空间中。

编辑(供评论):

AABB 可能会提供误报,因为它最多是您所包围的区域的确切形状,但通常比您所包围的区域大。

考虑一个球体,如果你使用 AABB,就像把一个篮球放入一个盒子里,盒子的角落里有所有这些间隙,球无法到达。

或者,在平截头体的情况下,平截头体向内朝向相机倾斜,AABB 将简单地继续沿轴笔直朝向相机,有效地界定出比相机可以看到的区域更大的区域。

这是不准确的根源,但它永远不会导致您剔除稍微位于视锥体内部的对象,因此最坏的情况是您仍然会绘制一些靠近相机但仍在视锥体外部的网格。

您可以通过首先执行 AABB 测试并生成返回 true 的较小网格列表来纠正此问题,然后在该较小列表上执行更准确的测试,并为平截头体和/或网格提供更准确的边界体积。

AABB or Axis Aligned Bounding Box is a very simple and fast object for testing intersection/containment of two 3D regions.

As you suggest, you are calculating a min and max x,y,z for the two regions you want to compare, for example, the region that describes a frustum and the region that describes a mesh. It is axis aligned because the subsequent cube has edges parallel with each of the axis of the coordinate system. Obviously this can be slightly inaccurate (false positives of intersection/containment, but never false negatives), and so once you filter your list with the AABB test, you might consider performing a more accurate test for the remaining meshes.

You test for intersection/containment as follows:

F = AABB of frustum

M = AABB of mesh

bool is_mesh_in_frustum(const AABB& F, const AABB& M)
{
    if( F.min.x > M.max.x || M.min.x > F.max.x || F.min.y > M.max.y || M.min.y > F.max.y || F.min.z > M.max.z || M.min.z > F.max.z )
    {
        return false;
    }
    return true;
}

You can also look up algorithms for bounding spheres, oriented bounding box (OBB), and other types of bounding volumes. Depending on how many meshes you are rendering, you may or may not need a more accurate method.

To create an AABB in the first place, you could simply walk the vertices of the mesh and record the minimum/maximum x and y and z values you encounter.

Also consider, if the meshes dont deform, then the bounding box in the meshes coordinate space are going to be static, so you can calculate the AABB for all the meshes as soon as you have the vertex data.

Then you just have to make sure you transform the precalculated AABB min and max vertices into the frustum coordinate space before you do the test each render pass.

EDIT (for comment):

The AABB can provide false positives because it is at best the exact shape of the region you are bounding, but is more typically larger than the region you are bounding.

Consider a sphere, if you use AABB, its like putting a basket ball into a box, you have all these gaps at the corners of the box where the ball cant reach.

Or in the case of a frustum where the frustum angles inwards towards the camera, the AABB for it will simply continue straight along the axis towards the camera, effectively bounding a region larger than the camera can see.

This is a source of inaccuracy, but it should never result in you culling an object that is even slightly inside the frustum, so at worst you will still be drawing some meshes that are close to the camera but still outside the frustum.

You can rectify this by first doing a AABB test, and producing a smaller list of meshes that return true and then performing a more accurate test on that smaller list with a more accurate bounding volume for the frustum and/or meshes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文