|
发表于 2009-11-24 16:35:00
|
显示全部楼层
Re: 着色语言(Shader Language),以及HLSL VS GLSL VS CG
我刚才又认真的看了楼主的原帖,楼主的帖子是摘除书“GPU Programming And Cg Language Primer 1rd Edition”,上面有这么一句话:
我在OGRE官方论坛上,搜索过有关使用Cg和GLSL的讨论帖子,套用其中一个帖子的结尾语来结束本章:
In the last year I have never had to write a single HLSL/GLSL shader. Bottom line, I can’t think of any reason NOT to use CG.
于是我到OGRE的官方论坛上去搜索证据,果然让我找到了。帖子的地址是:
http://www.ogre3d.org/forums/viewtopic.php?f=1&t=48781
这里面讲了glsl VS hlsl VS cg。不是咱们迷信国外人,但是OGRE是世界排名第一的开源图形引擎,其官方论坛中不少都是大牛,这里面的讨论帖子是有一定的参考价值的。请看从该帖子中摘录的两句话:
1:It is highly unlikely you will notice a performance difference between shader languages, so I would suggest you learn CG. The benefit of only having to write/maintain ONE shader for both DirectX and OpenGL is why CG is king in my book.
In the past (pre CG 2.0) there were some minor limitations on CG (running out of registers) which forced me to write a couple things in HLSL. But since 2.0 all those problems seem to have been solved. In the last year I have never had to write a single HLSL/GLSL shader. Bottom line, I cant think of any reason NOT to use CG.
2:If you decide to write native GLSL you'll find that not all video card drivers are equal when it comes to compiling the GLSL code down to assembly for the video card. The ATI cards especially have some annoying bugs and missing features. Some other cards just do not support very high revisions of the GLSL language (some Intel chipsets). You might end up managing shader code for each of these hardware configs, which is tedious and annoying.
The good news is that you can use Nvidia's Cg compiler to compile your GLSL code into code targeted for the hardware beforehand. The bad news is that Cg might not produce the most optimized code for complex effects. If you're going to do that though, and you're not going to even use OpenGL directly, just use Cg shader code!
Anyway, since you're asking these types of questions I hardly think you need to worry about which shader language is faster/more effective. Just use Cg.
oz01同学,我刚才去看了你引为自豪的那个飞行模拟游戏,你是用opengl+glsl写的?我很佩服你这种学习精神,不过我猜测,你还是一个学生。因为目前国内的公司基本都是用DX+cg和dx+hlsl得组合,并且使用这样组合通常都是底层图形引擎的设计者;大部分的图形工作者是使用图形引擎开发,开源的有OGRE,OSG和IRRLICT等。
游戏行业首要注重的是跨平台性,不是单单指操作系统,还指不同年代的显卡。所以通常都会使用cg的(这是事实,尤其在国外),不信你可以下载siggraph08年星际的开发人员写的一篇文章。glsl的地位非常尴尬,在仿真中用的比较多,但也被cg占据了半壁江山。
说这么多,只是感觉你不是太虚心,在你自豪的那个帖子中,说人家是“乱喷”,我不知道是不是如此,但是不喜欢你的作风。我们做学术的,或者专业人士要讲证据。我列出了我的证据,你拿出你的证据,谁说的对,说有理,大家都清楚。
|
|