以此纪念我的伯父,数学教育家钟载硕

  IT博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  4 随笔 :: 0 文章 :: 1 评论 :: 0 Trackbacks
下面的建议都是为大型3D系统准备的,不是为了一个小demo准备的,所以这些建议不一定适合小demo。
首先是来自于gamedev论坛的建议:
There are a fair few things that can be done to optimise a particle engine. Off the top of my head I would recommend some of these...

Calculate a bounding volume (bounding box or sphere) for your particle system so that you can then cull this against your view frustum. If outside your view then simply don't render the particle system - although you still may (or maybe not) wish to update those particles in that system.

Use a fixed array size for the particles in a given system. (As IndirectX hints at in the post above). Alternatively a method whereby you use two linked lists to keep track of the particles can be used - one tracking live particles, the other tracking 'dead' particles. Whichever method you use you do not want to be creating and deleting particles on the fly too often (i.e. using, say, new and delete operators) as this can seriously dent performance. Easy solution? Use a fixed array and flag particles as dead or alive.

Do you use quads (two triangles) for rendering your particles? If you do then try using triangles and mapping your particle texture onto a single triangle. You will need to modify the uv's to display the texture correcly, but you immediately decrease the number of triangles you need to render by two.

Ensure you do not call SetTexture for *each* and every particle. Group particles by texture. It is usually common for a particle system to produce particles that utilise only one texture (for example, a snowflake within a snowflake particle system). This way you set the texture once for the system then proceed to render the individual particles contained within that system.

Maybe consider enabling alpha testing - this can then reject fragments of your particles before the final rasterisation stage.

If you are calculating the inverse view matrix for billboarding then ensure you only do this once per frame (or, if your implementation suggests so, less than once per frame). This matrix need not be calculated per particle per frame - although a lot of implementations I have seen in the past calculate this per particle!

Ok - there are several more things you can do to optimise, but at least the above gives an idea as to what to look for, or be aware of. Hopefully this will help you out a bit!

Sharky

这个Sharky看来是个老手,一口气写了那么多优良的建议。

还有一句建议:当粒子大小大于一半屏幕面积的时候,就不要渲染这个粒子。
这句话也出自gamedev,原文我找不到了。WOW就有很多这种情况,例如你把人物特意靠近某个粒子系统,例如一个冒烟的小锅。当你把镜头拉近那些烟的时候,游戏的FPS会突然大跌,非常卡。原因就是单个粒子遮盖了屏幕很多象素,渲染粒子时候要做的alpha_blend突然大大增多,而且不是1个粒子,是很多个粒子重重复复在大块区域进行alpha_blend,导致FPS暴跌。

WOW早期粒子效果比较好,合理的画面效果,高效的速度,但是到了现在(TBC 2.x)后,可能换了粒子效果美工,对粒子效果掌握的很不好,过于花巧,对游戏FPS影响过大。例如,粒子速度过快,数量过多。猎人的箭雨多了20倍的箭,法师的暴风雪多了3倍的雪箭,然后速度都加快了2倍,特别猎人那个箭雨,什么都看不到,一顿卡就结束了。
posted on 2008-02-13 18:54 昆达 阅读(316) 评论(1)  编辑 收藏 引用

评论

# 说的真好~~~~ 2008-10-10 09:19 菠菜
说的真不错~~~~,学习了~~~  回复  更多评论
  

只有注册用户登录后才能发表评论。