• About
    • Resume
A Game Developer also plays some guitar

Author Archives: Benny Chen

A game developer, a music lover, and a partisan fan of F.C. Barcelona

复习了一下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

生活

June 25, 2009 2:48 pm / Leave a Comment / Benny Chen

韩寒:我们的生活依然像跳楼一样往下延续,他是最先接触到地面的人。所有的力量只能决定我们在空中的姿态,成功失败就是好看难看的区别,新生活只是将朝着地的脸仰望向天空。

Posted in: Quotations

indexed triangle lists最快

June 16, 2009 5:30 pm / Leave a Comment / Benny Chen

一直以为,因为一条三角形带(triangle strip)会把处理与传输m个三角形的代价从3m个顶点降到(m+2)个顶点,所以它是最高效的。今天从Gamedev的一篇帖子才知道,索引三角形列表(indexed triangle lists)才是最快的。

确实,三角形带减少了输入显卡的顶点数,但对于现今的显卡来说,带宽早就不是问题了!

至于为什么三角形带是最快的,因为在处理顶点时它可以最大化显卡缓存的使用率(cache hit ratio)。

下面这段话摘自Tom Forsyth的论文Linear-Speed Vertex Cache Optimisation,如何分配三角形的序列,以使的cache得到最好的利用。算法是贪心性质的,速度可以达到O(N),有兴趣可以研究研究。

Indexed primitives have replaced strips and fans as the most common rendering primitive in graphics hardware today. When rendering each triangle, the vertices it uses must be processed (for example, transformed to screen space and lit in various ways) before rendering. Indexed rendering hardware typically uses a small cache of vertices to avoid re-processing vertices that are shared between recently-rendered triangles. Using a moderately-sized cache (anywhere between 12 and 24 vertices is common) reduces the load on the vertex processing pipeline far more than the older non-indexed strips and fans model – often halving the amount of work required per triangle.

Posted in: Computer Graphics / Tagged: 三角形列, 三角形带

ID3D10EffectPass::Apply

June 15, 2009 5:13 pm / Leave a Comment / Benny Chen

因为没有很好的理解这个函数的作用,而导致被一个Bug纠缠了半天。

这个Bug是这样的:渲染一个人物模型和一个地板模型,它们分别有不同的纹理,但渲染出来的结果却是——人物的纹理贴到了地板上,地板的纹理贴到了人物上,纹理错位了!

我明明在渲染前都分别将各自的纹理视图(ID3D10ShaderResourceView)设置到shader的纹理接口(ID3D10EffectShaderResource)上了啊,怎么会出现如此诡异的现象。

调的很崩溃,freaking me out…对于bug源的推理,我磨了好久,才想到了去打破我的思维定势——真正启动Shader开始执行的是Draw函数,所以对于渲染状态的设置只需要在Draw函数前设置就是有效的。

前半句没错,后半句,非也!

我忽视了Apply函数的作用,它不仅仅只是挑选某个pass而已。

这是DirectX SDK Document对ID3D10EffectPass::Apply的描述:

Set the state contained in a pass to the device.

将状态提交到设备。马上我就恍然大悟,我设置纹理的语句是在Apply之后进行的。把设置纹理的语句提到Apply函数之前,于是,纹理物归原主。

调试BUG,除了需要很好的逻辑推理排错能力,还要勇于去怀疑一些思维定势(当然也没必要怀疑一切),有时,或许越是深信不疑的某些东西就是错误的根源,打破它,错误也便迎刃而解。

before bug was fixed
before bug was fixed

after bug was fixed
after bug was fixed

Posted in: Computer Graphics / Tagged: Apply, DX10, ID3D10EffectPass

托朋友从美国买的书拿到了

June 4, 2009 12:05 am / 1 Comment / Benny Chen

托朋友从美国带东西,估计就是书最不划算了,太贵鸟。

而我就是如此的stupid.

托朋友从美国带了两本书,价格总共40多美元,还是从amazon上经过打折的,加上运费后差不多有50刀,按6.85的汇率折合成人民币后是330,我的天哪,I am broke.

今天总算拿到书了,书当然是很不错了,赞一个。

一本”Lennon Remembers”,这本还不算太贵,而另一本关于DX编程的的书,超级的贵…

lennon_remembersadvanced_3dgame_programming_with_dx10

Posted in: Something In The Way

relegation

June 2, 2009 11:41 pm / Leave a Comment / Benny Chen

08到09赛季的欧洲各大联赛都已硝烟散去。对于联赛,大家一般比较关注的是最后的冠军,但其实还有一个很重要的关注点,就是最后不幸降级的球队。

在今年的降级球队名单中,赫然出现了一些昔日老牌强队的名字,比如英超,黑喜鹊纽卡斯尔居然不幸降级,而西甲,传统强队皇家贝蒂斯的降级也是令人大感震惊!

今天,就学习“降级”的英文——relegation。动词形式是relegate,意思就是使(某只球队)降级,一般用作be relegated.

比如看今天的这则新闻:

Almeria’s promising right-back, Bruno had an agreement to sign for Real Betis for next season, but the Verdiblancos’ shock relegation from the Primera Division has scuppered the deal.

阿尔梅里亚的前途无量的右后卫布鲁诺原本已经达成协定下赛季签约到皇家贝蒂斯,但是贝蒂斯在联赛中令人震惊的降级毁掉了这份交易。

Posted in: Learn a Word / Tagged: relegate, relegation, 降级

巴萨队歌摇滚版

June 2, 2009 4:23 pm / Leave a Comment / Benny Chen

HIMNE DEL BARCELONA

Tot el camp

es un clam

som la gent Blau Grana

Tan se val d’on venim

Si del sud o del nord

ara estem d’acord

estem d’acord

una bandera ens agermana.

Blau Grana al vent

un crit valent

tenim un nom

el sap tothom

BARÇA, BARÇA, BARÇA.

Jugadors

Seguidors

tots unit fem força

son molts d’anys plens d’afanys

son molts gols que hem cridat

i s’ha demostrat

s’ha demostrat

que mai ningú no ens podrà tòrcer

Blau Grana al vent

un crit valent

tenim un nom

el sap tothom

BARÇA, BARÇA, BARÇA

在听到这首歌之前,我就在一直想象着让一支摇滚乐队去演奏巴萨的队歌会是怎么样,那不断的三声鼓的重击声一直在我的脑海中盘旋。

真的听到了摇滚版的队歌,太帅了,令我热血澎湃。

我一直有一个梦想,就是组一支乐队。后来又继续幻想,找一帮巴萨的铁杆来组队,乐队的名称叫“我们爱巴萨”,乐队的口号是“不仅仅是一支乐队”(mes que un band),然后演奏巴萨的队歌!

当然幻想毕竟只是幻想,我的演奏技术还需要太多的练习,加泰罗尼亚语更是一个字都不会,不过照着歌词硬模仿还是有可以有的。

先来个现实点的,我要找人扒谱,听着觉得应该不是很复杂!

Posted in: Visca Barça / Tagged: 巴萨, 摇滚, 队歌

三冠后的踢球

May 30, 2009 1:22 pm / Leave a Comment / Benny Chen

北京的天气真不错,是个踢球的好日子,带着巴萨三冠后的好心情,穿着巴萨的球衣,我们都觉得特别自豪。趁热打铁,我们再次在民大踢球。

去踢之前我还先跑到中关村买了球袜和护腿板,就是为了怕受伤。但还是伤了,因为刚开始懒得戴护腿板,结果一次对脚,左小腿就惨遭重创。休息了一个晚上到现在还疼,不过还好,能走路。

每次踢球都是当后卫,没办法,进攻的人太多了。而且今天是分拨踢,踢5分钟休息20分钟,断断续续的,状态也一点都不好,踢得一点都不爽。

不过能够认识这一群朋友就足够了,以后争取每个星期能踢一次球。

Posted in: FCB BJ / Tagged: 踢球

Confederations Cup

May 30, 2009 10:16 am / Leave a Comment / Benny Chen

冠军杯结束了,巴萨取得了西班牙史无前例的三冠伟业,夺冠的兴奋和激情还将持续一段时间。

欧洲各国的联赛也已基本收官了,足球快要进入一段暂停期。

不过今年6月份,在南非还将有一项国际赛事——联合会杯。

今天Learn a Word就学习这个联合会杯的英文怎么说 — Confederations Cup

Confederation这个单词的意思也是“同盟;联盟;联邦”,跟federation很相近,不过还是有差别的,google了一下,他们之间的区别大概是这样的:

federation – a union comprising of partially self-governing states/regions united by a central government. In a federation, the self-governing status of the component states is typically constitutionally entrenched and may not be altered by a unilateral decision of the central government.

confederation – an assocaition of sovereign states/communities usually created by a treaty, but after later adopting a common constitution.

federation由一个central government联合,并且自治政府会有自己一套独立的宪法,并且不会因中央政府的单方决定而改变。美国各大州政府和美国政府的关系应该就是这样,所以美国政府是一个federal government,而confederation是为了同一个目的而结成联盟的州或国家,并且他们会遵守一套共同的宪法。

再回到联合会杯。

Spain Star Andres Iniesta Doubtful For Confederations Cup

西班牙球星伊涅斯塔参加联合会杯成疑

Iniesta could miss the Confederations Cup this summer as he fights off a leg injury…

伊涅斯塔可能会错过今年夏天的联合会杯,他正在竭力恢复他的腿伤…

哎,可怜的伊涅斯塔,最近伤病不断,只能祝福他了。至于Confederations Cup, 还是算了吧。

Posted in: Learn a Word / Tagged: confederation, confederations cup, federation, iniesta

Barça complete historic treble in Rome

May 29, 2009 12:07 pm / Leave a Comment / Benny Chen

09cp-final

FC Barcelona created history on Wednesday evening as they won the UEFA Champions League in Rome to add to the domestic title and Copa del Rey thanks to goals from Samuel Eto’o and Lionel Messi.

伟大的巴塞罗那在周三的夜晚创造了历史!通过埃托奥和梅西的进球,他们在罗马夺取了欧洲冠军联赛的冠军!继国内联赛冠军和国王杯冠军后,他们成就了三冠王的伟业!

这真是一个伟大而完美的赛季!

banner_central-eng1

Treble! Treble! Treble!

Visca Barca!

Posted in: Visca Barça / Tagged: barca, treble

Post Navigation

← Older Posts
Newer Posts →

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