What language
should I study for making shaders in Unity3d?
Yesterday I said Cg/HLSL was the best choice for writing
shaders in Unity. A couple of other interesting opinions came out so I did a
bit of reading before making this reply.
Metal API:
Others said that Metal API is the future for iOS. That’s great for you if you
don’t care about Android, PC, Xbox, PS, etc, etc. Anyway, Unity3d doesn’t
support writing in Metal and they said they have no intention to support it in
the near future. They only have support for automatic compiling into Metal API,
so you don’t really get much control over it. So it’s not a choice for a Unity
developer to start learning.
Vulkan:
Somebody said this is the future. Maybe. It’s made from a dead language called
Mantle developed by AMD, which only had a few games ever using it. They took
some ideas from Apple’s Metal and improved it, so people say. Apparently Vulkan
was announced in GDC 2015, but I didn’t see or hear it anywhere. Even if it is
the future, it is a far and distant uncertain future. Vulkan sounds nice, like
a dream come true in some ways, but it isn’t even released yet. Only Valve company
has used it. Do you work at Valve? Does your boss want to support this
technology yet? Too many questions. Plus, John Carmack hinted that Android
might have a similar kinda of Metal API of their own soon, so GPUs of Android
devices might not even need to adopt it. Well, when you consider everything
there is just too much questions surrounding this, too much unknown. In any
case, it’s not a choice for Unity at the moment.
GLSL: You can
write in GLSL in Unity now. Unity will compile this code to whatever platform
you like, though you may have to “-force-opengl” on a PC (or any non iOS/Apple)
device to get it to work properly. That will cause the Unity Profiler to be
unable to profile correctly on some GPUs of certain video cards. I’d love to
know if it’s possible to get around this. So, if you use a Mac and everyone in
your team uses a Mac, then sure you should probably use GLSL –it’s the logical
choice.
Surface Shaders:
You can use Unity shaderlab to do some cool stuff, but it won’t be very
efficient for mobile. Shaderlab is like a simplified and more humanly-readable
markup language, but you lose the control and performance options that you need
for mobile games. Since most of the jobs in China will be for making mobile
games, I don’t recommend it.
Cg/HLSL: Some
people said that Cg was a dead language. Well, the fact is that Cg and HLSL are
the same language which is maintained by two different companies, NVidia and
Microsoft. Now Nividia has stopped supporting Cg because there is no need since
Microsoft supports HLSL. People still use the name Cg, but hope nobody gets
confused about it. Cg/HLSL is certainly not dead, and after talking to several
high ups and forum veterans over at Unity, they all think that HLSL is the
future of shader writing in Unity because the company is doing a lot of console
and AAA promotion. Just look at Unity5 features and you will get my meaning.
Cg/HLSL can be compiled to any device you need and since Unity and Microsoft
seem like great friends now, I don’t think this is going to change.
Conclusion:
If you want to use Unity3d and make games for Windows,
Consoles, Android, and iOS, with decent performance on all platforms, you
should use Cg/HLSL.
If you want to use Unity3d and make games for mobile only
(don’t need to support Windows or Consoles), GLSL is a good choice, especially
if you work on Apple Macs.
If you don’t want to use Unity3d and only want to develop
for the newest iOS devices, then Metal is the best, though very few people in
China are using it right now.
If you want to use cocos2d, I am not the expert for
advice, but friends say GLSL is your best choice.
However, also, but, maybe…. In China, the dominant art
style is hand-painted stuff. This doesn’t require very deep shader knowledge,
and is very little work for an experienced guy to achieve. Shader coding is
mainly for trying to go beyond current gen graphics, or create specific
effects, or to get around some graphical issues. So you have to think about if
it’s worth to study, because many kinds of games may not need this.
非常感谢知友@王邢敏 的翻译,他的微博:One Double(http://weibo.com/laowangba)
昨天我说过,在Unity里写shader,Cg/ HLSL是最佳选择。后来冒出了几个很有意思的观点,所以我特意查阅了一下资料再来回复。
Metal API:有人说,Metal API是iOS的未来。如果你完全不关心Android,PC,Xbox,PS等平台,那么你的确可以奉之为圭臬。反正,Unity3d 是不支持用Metal写的,而且他们说近期也没有要去支持Metal的打算。他们只支持自动编译成Metal API,但这样你能控制的就很少。因此,这不是一个Unity开发者入门的选择。
Vulkan:有人说这才是未来。大概吧。AMD开发过一个叫做Mantle 的语言,只有很少的几个游戏用过它,然后它还死了,现在有人用它搞出了这个。人们说他们从苹果公司的Metal借鉴了一些理念,用之以完善Vulkan。很显然,Vulkan是在2015年GDC公布的,但我没有在其他任何地方听说或看到。即使它真是未来,那也是一个远到不着边际的未来。Vulkan 听起来不错,像是某种方式的梦想成真,但它甚至没有发行。只有Valve公司用过它。什么?你在Valve工作?你的上司是要支持这个技术了吗?太多问题了。此外,约翰·卡马克暗示Android可能不久会有一个类似Metal API的东西,所以Android设备的GPU甚至不需要接受它。那么,当你考虑所有事情时,就是有太多的问题围绕着它,太多的未知。无论如何,它不是Unity当下的选择。
GLSL:现在你可以在Unity里写GLSL了。Unity会将这段代码编译到任何平台,虽然你可能要在PC(或任何非iOS / Apple设备)上执行“-force-opengl”,以使之正常工作。那会导致在某些显卡GPU上,Unity Profiler不能正确地执行配置。我很想知道,是否有可能解决这问题。所以,如果你用着Mac,团队里人人用着Mac,那么相信你应该使用GLSL- 绝对是明智之选。
Surface Shaders:你可以用Unity shader库做些很酷的东西,但它不一定会在移动设备上有效果。 Shader库就像一个简化的,更易于阅读的标记语言,但你失去了你手机游戏需要的控制和性能选项。鉴于大多数在中国的工作是做手游,我不推荐这样做。
Cg/HLSL:有人说,Cg是死的语言。那么,事实是,Cg和HLSL是同一个语言,只是由两个不同的公司,NVIDIA 和Microsoft分别维护。现在NIVIDIA已停止支持Cg,没有必要啊是不,反正Microsoft在维护HLSL。人们仍然使用着Cg的名字,但愿没有人对此困惑了。 Cg/ HLSL当然没有死,在跟几个大牛以及论坛老兵聊过Unity,他们都认为HLSL是Unity shader的未来,因为公司为游戏机做了很多,为3A级提升了许多。只要看看Unity5的特性,你会懂我意思了。Cg/HLSL可以被编译到你需要的任何设备,同时Unity和微软已经亲密得像兄弟一样,并且将一直亲密下去直到地老天荒。