• About
    • Resume
A Game Developer also plays some guitar

Tag Archives: Frustum Culling

Some Tests

July 8, 2009 9:30 pm / Leave a Comment / Benny Chen

在最近的项目中,尝试进行了一些小实验,并记录了数据作为比较。实验机器的显卡是NVidia Geforce 8800 GT。

1. Skinning

skinning on CPU

                          skinning on CPU

skinning on GPU

                          skinning on GPU

从图中可以清晰的看出,对于骨骼蒙皮计算,CPU和GPU的差距可见一斑,GPU比CPU要快上10倍之多!这就是GPU并行计算的魅力!

2. Instancing & Stream Output

人物模型延用上面的这个模型(该模型差不多有1300个面),采用instancing技术渲染上千人(所有的Instance的动画在每一帧保持一致),并且实现了SO的版本,对它们的FPS进行比较。

Instancing without SO

   

     1,000 Instances              2,000 Instances             3,000 Instances

Instancing with SO

   

     1,000 Instances              2,000 Instances             3,000 Instances

因为所有的Instance的动画在每一帧都是一致的,所以如果不使用SO技术,则不得不对每个instance都需要进行一次蒙皮动画,这显然是一种浪费。Stream Output技术使得所有的Instance的蒙皮动画只需要执行一次,所以在效率上得到了一定的提高,如下表。

Number of Instances

FPS(Without SO)

FPS(With SO)

1,000

40

56

2,000

19

36

3,000

13

24

 3. Frustum Culling

换了一个低质量的模型(只有不到200个面),基本上万人级别是没有问题了,加上了Frustum Culling,则可以跑得更快!

使用3种方法实现了Frustum Culling,前两个都是基于CPU的,最后一个是基于GPU

  1. 顺序执行(最简单的对所有Instance遍历执行Frustum Culling算法)
  2. 四叉树(四叉树裁剪,我这里用四叉树用得有点牵强,因为人物不能移动且必须保持边长为2的N次方的阵型。这么简单的处理四叉树,只是为了做实验比较而已)
  3. GPU上的Frustum Culling(算法基本上跟1是一致的,只不过是在GPU上执行)

三个方法在同一个视角,使得它们截取和渲染的数量是一致的。总共65536个Instance,当前绘制都是15485个。

   

           顺序执行                              四叉树                             在GPU

效率比较如下表。

Current Rendering / Number of Instances
FPS
(Sequential Frustum Culling)
FPS
(Frustum Culling With Quad-tree)
FPS
(Frustum Culling on the GPU)
4388/16384 61 143 102
15485/65536 16 43 32

发现最快的是使用四叉树,而GPU的算法反而相对比较慢。原因很有可能是后者需要处理GPU和CPU的同步问题,在GPU进行Frustum Culling需要CPU从GPU读取Frustum Culling执行的结果(为了知道有多少个instance需要被渲染),在DX10的SDK文档里可清楚的写着,从GPU向CPU进行Map读取操作,是比较严重影响效率的,因为总有一方要停下来去等待另外一方的数据。

Posted in: Computer Graphics / Tagged: frustum culling, instancing, skinning

复习了一下Frustum Culling

June 25, 2009 6:17 pm / Leave a Comment / Benny Chen

上次跟frustum culling的亲密接触还是两年前的事情,那时的一个游戏Demo里实现了quad-tree地形,并使用frustum culling显著减少三角形面的渲染。

catcher-in-the-rye两年前的游戏Demo:麦田里的守望者

这一丢就是两年了,最近的大规模人群渲染项目,逼得我再次对frustum culling发出了呼唤,凭着模糊的记忆,再把frustum的一些原理复习了一下,不用1个小时,我就重拾了frustum culling的相关核心概念和技术,并获得了新的理解。

这是我从两年前就开始膜拜的Chad Vernon(www.chadvernon.com)大大的一段话:

When we tell DirectX to render geometry, it will perform a culling test to see if a vertex is within the view frustum before rendering the vertex. DirectX will only render a vertex if it is within the view frustum. However, this test occurs after the geometry has been transformed and lit by the world and view matrices. In more complex scenes, thousands of vertices would be transformed just to be rejected by the frustum test in DirectX. We can speed up performance quite a bit if we implement a view frustum culling test prior to our render calls.

DirectX本身在其pipeline中就会对顶点进行culling test的,但这要在顶点被”顶点变换与光照”(Transform&Lighting)之后。Vernon在写这段话的时候,应该还是DX9的时代。在DX10的文档里也赫然写着:(Rasterizer Stage)the stage clips vertices to the view frustum,是在VS,GS这些之后才进行。

而自己手工实现frustum culling的好处,就是可以将大量的非可视的顶点在送进渲染管线之前就被拒掉~

下面的这条链接对frustum culling有比较基础而详细的介绍(这哥们爆了好多粗口……),同时进行了一系列的优化,这也让我对frustum culling有了更深的理解。里面所链接的那篇讲解如何构造frustum的文章,当我再次翻开它的时候,马上就从我大脑中的碎片中搜索并意识到,我两年前曾经读过这篇文章。记忆总是在某个似曾相识的环境下被突然的激活。

http://www.flipcode.com/archives/Frustum_Culling.shtml

另外DX10的时代早已来临,AMD的那篇March of Froblins的论文里,Frustum Culling和LOD已经全部是在GPU里进行了,通过了Geometry Shader的帮忙。在如今这个时代,貌似把任何运算转移到GPU,一切皆有可能。

打算最近把frustum culling相对于我目前所进行的人群渲染项目,在CPU和GPU都实现一个版本,并进行一些性能的比较。在我现在的项目里,估计实现后GPU的版本不一定就比CPU的跑的快,因为我的GPU已经承载了大量的人群渲染任务,而CPU到目前为止还基本是空闲的。

Posted in: Computer Graphics / Tagged: frustum culling

LinkedIn

Milan Petrovic

Categories

  • In My Life (25)
    • A Day in the Life (8)
    • English Learning (2)
    • Learn a Word (7)
    • Something In The Way (8)
  • Music Heaven (8)
    • Guitar (1)
    • In Concert (1)
    • Lyrics (3)
  • OK Computer (54)
    • 3D (3)
    • C++ (10)
    • Computer Graphics (15)
    • Game Programming (23)
    • iOS (6)
    • Linux (1)
    • Lua (9)
    • My Projects (3)
    • Some Experiences (9)
    • Talking in Code (2)
    • Unity (2)
  • Quotations (2)
  • Uncategorized (1)
  • Visca Barça (24)
    • FCB BJ (5)

Recent Posts

  • [译]优化你的手机游戏(没有延迟的,才是健康的)- 一篇给游戏美术设计师读的文章
  • 新浪微博API for MOAI
  • 稍后继续
  • Unity Developer ++
  • Another Thread @ Moai Forum
  • 1st Day of Golden Week
  • 为SyntaxHighlighter添加新语言
  • 基于Lua的State Pattern
  • Class Diagram of Pacman
  • 基于Moai的Pacman

Recent Comments

  • 约修亚_RK on 为SyntaxHighlighter添加新语言
  • 爱装的小男孩 on 小心DLL链接静态库时的内存错误
  • happyfire on Game Loop的几种实现方式
  • William on 新浪微博API for MOAI
  • Benny Chen on 新浪微博API for MOAI
  • your man on 新浪微博API for MOAI
  • 你家男人 on 稍后继续
  • 逍遥 on 关于对std::vector的遍历
  • papa on Unity Developer ++
  • T客网 ︱ Techpot » Blog Archive » iOS开发与OpenGL ES相关问题整理(1) on iOS开发与OpenGL ES相关问题整理(1)

Tags

2d 3D 3dsmax 3ds max air Apply architecture Asia tour barca Beijing bilbao binary search blocked bob boost bruce springsteen C++ capo CGContextDrawImage Champions League Change DLL DX10 eval exporter flash framework frustum culling game game engine iniesta ios linux lua Moai opengles pacman plug-in plugin 北京 导出插件 崩溃 巴萨 游戏引擎 踢球
© Copyright 2026 - A Game Developer
Infinity Theme by DesignCoral / WordPress