扑杀的技术渲染大量的立方体 [英] Culling techniques for rendering lots of cubes

查看:103
本文介绍了扑杀的技术渲染大量的立方体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个个人学习项目,使一个的Minecraft 克隆。它工作得很好除了一件事。类似的Minecraft,我的地形有很多立方体堆放在Y这样你就可以挖下来的。虽然我做的视锥剔除,这仍然意味着我白白给我画低于立方体的所有图层。立方体为X,Y和Z排序(虽然只在1个方向,所以它不是技术上Ž下令相机)。我基本上是从玩家的位置只指针添加到周围的玩家立方体。然后我做域剔除反对这些。我不这样做十月树的细分。我认为根本就没有呈现播放器下方的层,除了这,如果玩家看不起成洞不起作用。鉴于此,我怎么能避免渲染立方体我下面,我看不到,或者也被隐藏在其他多维数据集的多维数据集。

感谢

 无效CCubeGame :: SetPlayerPosition()
{
PlayerPosition.x = Camera.x / 3;
PlayerPosition.y =((Camera.y  -  2.9)/ 3) -  1;
PlayerPosition.z = Camera.z / 3;
}

无效CCubeGame :: SetCollids()
{

SetPlayerPosition();

INT xamount = 70;
INT zamount = 70;
INT yamount = 17;

INT xamountd = xamount * 2;
INT zamountd = zamount * 2;
INT yamountd = yamount * 2;
PlayerPosition.x  -  = xamount;

PlayerPosition.y  -  = yamount;

PlayerPosition.z  -  = zamount;


collids.clear();
的CBox * TMP;

    的for(int i = 0; I< xamountd ++ I)
    {
        对于(INT J = yamountd; J> 0; --j)
        {
            对于(INT K = zamountd; K> 0; --k)
            {

                TMP = GetCube(PlayerPosition.x + I,PlayerPosition.y + J,PlayerPosition.z + K);



                如果(TMP!= 0)
                {
                    如果(frustum.sphereInFrustum(tmp->中心,25)!= NULL)
                    {
                        collids.push_back(TMP);
                    }
                }

            }
        }

}
 

解决方案

渲染前后。要做到这一点,你就不需要排序,使用八叉树。叶子会不会是单独的立方体,这些相当大的群体。

一个网格,每个这样的叶片应在显示列表缓存(如Bobmitch建议),甚至更好的顶点缓冲区(便宜更新)。当你生成这个网格的的产生一个强力的方式对所有的立方体。相反,每个立方体表面是否有相同的叶子中不透明的邻居,如果是这样,你不需要生成这张脸的。也可以统一相邻的面具有相同的材料成一个单一的长的长方形。您也可以单独网格六组,分别用于一个主方向:+/- XYZ面孔。画中可能遇到的摄像头面部只有那些套。

渲染从前到后本身不提供帮助。但是,您可以使用遮挡剔除的提供的现代化的硬件,从这个排序中受益。在渲染八叉树的叶,检查其BBOX经过遮挡查询。如果没有通过,你不需要画出来的。

替代的方法来遮挡查询可能是光线跟踪。光线追踪是好,使此种环境。你可以放个组光线的稀疏逼近什么叶子是可见的,只画那些叶子。然而,这会低估能见度集。

I am working on a personal learning project to make a Minecraft clone. It is working very well aside from one thing. Similar to Minecraft, my terrain has lots of cubes stacked on the Y so you can dig down. Although I do frustum culling, this still means that I uselessly draw all the layers of cubes below me. The cubes are X, Y and Z ordered (although only in 1 direction, so its not technically Z ordered to the camera). I basically from the player's position only add pointers to cubes around the player. I then do frustum culling against these. I do not do oct tree subdivision. I thought of simply not rendering the layers below the player, except this does not work if the player looks down into a hole. Given this, how could I avoid rendering cubes below me that I cannot see, or also cubes that are hidden by other cubes.

Thanks

void CCubeGame::SetPlayerPosition()
{
PlayerPosition.x = Camera.x / 3;
PlayerPosition.y = ((Camera.y - 2.9) / 3) - 1;
PlayerPosition.z = Camera.z / 3;
}

void CCubeGame::SetCollids()
{

SetPlayerPosition();

int xamount = 70;
int zamount = 70;
int yamount = 17;

int xamountd = xamount * 2;
int zamountd = zamount * 2;
int yamountd = yamount * 2;
PlayerPosition.x -= xamount;

PlayerPosition.y -= yamount;

PlayerPosition.z -= zamount;


collids.clear();
CBox* tmp;

    for(int i = 0; i < xamountd; ++i)
    {
        for(int j = yamountd; j > 0; --j)
        {
            for(int k = zamountd; k > 0; --k)
            {

                tmp = GetCube(PlayerPosition.x + i, PlayerPosition.y + j, PlayerPosition.z + k);



                if(tmp != 0)
                {
                    if(frustum.sphereInFrustum(tmp->center,25) != NULL)
                    {
                        collids.push_back(tmp);
                    }
                }

            }
        }

}

解决方案

Render front to back. To do so you don't need sorting, use octrees. The leaves won't be individual cubes, rather larger groups of those.

A mesh for each such leaf should be cached in a display list (as Bobmitch suggested) or even better in a vertex buffer (cheaper to update). When you generate this mesh don't generate all the cubes in a brute-force manner. Instead, for each cube face check if it has an opaque neighbor within the same leaf, if so you don't need to generate this face at all. You can also unify neighboring faces with the same material into a single long rectangle. You can also separate the mesh to six sets, one set for each principal direction: +/-XYZ faces. Draw only those sets of faces that may face the camera.

Rendering front to back doesn't help by itself. However you can use occlusion culling offered by modern hardware to benefit from this ordering. Before rendering an octree leaf, check if its bbox passes the occlusion query. If it doesn't pass you don't need to draw it at all.

Alternative approach to occlusion query may be ray-tracing. Ray tracing is good for rendering such environment. You can cast a sparse set of rays to approximate what leaves are visible and draw those leaves only. However this will underestimate the visibility set.

这篇关于扑杀的技术渲染大量的立方体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆