Shader的編寫到底應該是美術的事情還是程序的事情?

矛盾在於,程序沒有太多美術的素養,寫出的Shader感覺比較死板藝術氣息。而對於美術,在中國幾乎很難找到一個會寫Shader的美術,和我們公司美術交流,跟他們說顏色相加,顏色相乘,他們完全不知道是什麼意思,要他們將rgb的分量的格式寫成0到1的範圍,還要給他們介紹半天該怎麼轉換。

在中國是不是會自己寫Shader的美術是不是很少?如果不會寫shader也就算了,為什麼連顏色相加(Add), 顏色調製相乘(Modulate)都很難理解呢?

外國的情況是怎麼樣的?


作為一個在中國生活十幾年,在遊戲行業工作八九年的歪果仁,我從09年就開始使用Unity 3d,並對技術美術做了還算深的研究。由於中文水平不夠完美,我還是用英文來和大家分享一下技術美術的經驗。PS:我申請了一個QQ群,有關Shader, Level Design, Game Music都可以加進來198647854


My name is David and I am a founder of Mechanist Games(夢加網路). Our company made City of Steam(蒸汽之城) and Dream Raiders(盜夢英雄),
and of course have projects in development too.


Shader coding is still a new field in the world, and even
younger in China, so I』ll make this article more about advice, not technical
details. The hardest thing is just knowing how to begin. And that』s all I can
briefly cover here.


Who should do shader
coding, art or coder?


Last San Francisco GDC at the tech-artist round table, this
same question came up.

Neither. A tech artist should do shader coding. But don』t
worry both artists and coders can become tech artists.


Remember that tech artists in the west are a complete mixed
group, specializing in complex animation rigging, performance optimization,
creating tools for a large art pipeline and coding shaders. In China, the
amount of human resources gaming companies can use usually means that some of
these things be solved by basically just hiring more people or making them work
harder. Western companies have to achieve more with less people, so tech
artists are more than Chinese.


A tech artist needs both sound logic and artistic knowledge
to code good shaders. These are both things you can learn the same way I did
(see below).


How do western
companies do shaders?


Shaders are a core technology of a game. They have a huge
impact on the visual style of a game. The kind of shaders that need to be used
would be decided very early, when determining the art style of a game.


A tech artist would find out how to achieve the art style,
develop prototype shaders and other assets to realize the desired look and feel
with the art director.


Then, if the game prototype passes a company evaluation, the
tech artist would then begin creating tools and pipeline workflow documents to
teach the other artists in the team how to make the assets required for this
style.


Toward the end of the project, the tech artist would be
mainly focused on optimizing GPU performance and trying to solve compatibility
issues for rendering on different types of target platform.


Even giant European companies like CD Projekt Red only have
a few tech artists, so not all their time can be focused on shaders. Other US
companies like Volition are known to have more tech artists compared to their
size, but these people are still incredibly rare. Many people with tech artist
knowledge go on to develop game engines too.


How do you study how
to write shaders?

Firstly, have you got what it takes?

There are two core abilities needed to make shaders: Logic
and creativity. If you have these in any amount, it』s possible for you to learn
shader coding.


There is an experience requirement, too. I』d say it』s about
3 years, but it may vary greatly. You really need to know the engine you are
going to use very deeply.


And lastly, there is an English language requirement. If
your English is excellent, you will have access to more study materials and lots
of experienced professionals through the unity asset store.


What language should you learn?


In China, learn Cg (not CG).
That is Nvidia』s 「C for graphics」 language. It doesn』t stand for 「Computer
Graphics」. It is supposed to be like other C languages, but I don』t really
think it is.


If you learn unity』s shaderlab
or GLSL shader languages, you』re always going to limit yourself. Unity
can compile your Cg shaders for any platform you like, anyway.


Since China is mobile
dominated, Cg is the best choice because it is the most efficient for OpenGL
platforms like Androids or iOS devices. The advantages of getting into GLSL to
benefit from Apple』s Metal API are barely worth it right now, and you』d have to
be doing something really advanced to even need it.


In the future, if mobile
devices become powerful enough that we can start using surface shaders, then
learning will be really easy if you are already a master of Cg shaders.


盜夢英雄』s
shaders are all in Cg, and the performance is excellent. I built all the levels
myself to benefit from the optimized shaders and the results are pretty
satisfactory. I had a good teacher, which helped. Most scenes are ~40k-100k
vertices, which is high for a mobile game. Plus, I learned some good tricks we
are using in our next game too.

What tools do I need?

You need to be proficient in Photoshop,
3dsMax, and Unity3d. There are many alternative programs like Blender and Maya
too.


There are visual tools like
shaderforge that can be used to create shader code, but unfortunately, these
are useless for mobile devices. The code they produce is likely to be many times
less efficient than Cg, and usually result in thermal issues and poor FPS on
the target device.

Aside from unity MonoDevelop
for writing the shaders, there are lots of choices. And it really is just
preference. Unlike other coding language tools (Visual Studio for example),
shaders don』t have error catching helpers. When there is a mistake in your
code, you won』t get warnings –it will just fail to compile, or compile with
visual errors. There are so many ways to do things in a shader, and different language
syntaxes, so there still isn』t any good solution for this. You just have to
hunt the bugs down with your own eyes, or hope Unity』s console can point you to
the offending line of code (it often does not, though).


One thing you will probably
need soon if you plan to get really serious about doing shader animation or
special effects is a vertex painting tool. Vertices of a model can have color
properties. These colors are not visible in the game (unless you specifically
make them), and are used behind the scenes to do things like moving plants,
wind blowing hair, rolling waves in the sea, and so on. Use the asset store to
get one.


Buy things in the asset store.
The developers of these little tools and plugins are so helpful. This is how
you get introduced to pros who are really experienced and specialized. All of
my teachers were people I purchased tools and plug-ins and assets from. And
many are now my friends too.


Shader theory

You need to understand the
basic theory first, otherwise you won』t make it very far. Let me make a really
simple breakdown. For Unity3d vertex+fragment shaders (Cg, like you asked for)…

Of course, this is not a
complete shader yet. But it』s how every shader you write will be structured,
and understanding how it works is fundamentally important. You need to know how
these bits work. And you can just read the internet to work this out.

Copy some shaders

When collecting shader code,
the best thing to do is buy shader packages on the unity asset store. Make sure
you get Cg and not surface shaders –one or two reviews will tell you if it』s
worth buying. If somebody says it』s slow on mobile, don』t buy it.


Look at the shader code. Start
with really simple ones, 50 lines or less. Edit things, change things, see the
results. Experiment.


Make small goals for yourself. For
example, add a slider that can make the object lighter or darker. Add a tint
color. Remove a property. Change small things to build up your confidence.


Write your own shaders


Trying to write your own
shaders needs to start with small steps. The best guides I had were these, in
English. I can understand these might be daunting to a Chinese native. Does
anyone know a Chinese translation of them?


Cg Programming/Unity/Minimal Shader


Aside from these two, my
knowledge came from a hundred tiny details and facts that I found all over the
net, and as advice from friends and teachers. Everything you can read will be
useful, as long as you can apply it to practice.


When you start, avoid copy
pasting stuff. It will be harder to remember how to do it if you copy paste.
You』re going to copy paste lots of your own code later, so it』s good to know
what you』re actually reproducing. If you』re in the habit of assembling stuff
from different sources online, you are going to have a very hard time making
all the pieces fit.

Once you can write your own
basic shader, your journey to become a shader coder has begun.

Honestly, the rest is downhill,
and gets increasingly more interesting and cooler as you go. You can start
adding more and more things to shaders like lighting, shadows, bumpmaps,
outlines, colors and other things.


Training under someone skilled
is certainly the best situation. That』s how I learned. If you are lucky enough
to have a tech artist in your company, then try to apprentice yourself. If not,
you either have to change company or try to learn on your own. It』s very
uncommon for companies to give people time during work to study new tools or
skills, so you will have to be creative about it or very busy after hours.


I hope that China GDC can also
have a tech artist round table some time soon.


By the way, I』m hiring both
experienced and intern positions to study under me right now in Xiamen, so if
you are interested you can add QQ group198647854. 我申請了一個QQ群,有關Shader, Level Design, Game Music都可以加進來198647854


作為一個在國外混生活的技術美術,覺得有必要來回答一下:D
寫shader這個事情,有兩類人應該會:1,技術美術。2,圖形程序員。

技術美術應該從審美角度,寫出最漂亮的效果,當然也要留意效率。

圖形程序員主要是從效率的角度,把技美寫的shader優化到最快,當然也要兼顧效果盡量不要打折扣。

國內來說,我是美術科班出身的。程序員朋友也很多,據我的了解,中國的教育制度是完全沒有同時培養美術和程序的課程的。國外的大學,說實話這方面沒有比國內好很多,只是資源更豐富一點,想學得好,還是靠自學。

這裡突然想到一個事情,為什麼國內的美術學編程障礙大:英語! 反正我高考那會,英語都不算成績就是了。我英語也是出國之後重頭學的。

總之國外呢,比國內好點,因為AAA的大公司有成熟的流水線和人員培訓,加上老外讀代碼沒有語言障礙,所以美術轉技美比較容易。所以技美絕對數量多。

你抱怨的,美術沒有程序素養,這個,咳~ 實在,沒辦法,人家是美術,為什麼要有程序素養。。。。 美術跟程序解釋補色,估計也會遇到同樣的問題。。。。


程序寫,然後留夠參數,讓美術調


shader除了可以用來做特效之外,還能用來加速計算啊,像骨骼動畫,sm的各種衍生等,美工完全不需要接觸這些吧。效果方面的調校確實是美工來做會比較好,曾經做過一個海洋模擬的模塊,在海水的顏色調整上花了很多功夫,吃力不討好。理想的做法是又程序員寫代碼,抽離出來一些關鍵的效果參數,交給美工去調整,程序員專註於實現和效率。


shader 編寫是 介於美術和程序之間的工作,如果從小有比較好的藝術教育,長大會寫一些程序,就能比較好的理解如何寫shader了。處理圖像,圖形的 shader本質其實就是一種繪畫手段,當然shader也可以用來做通用計算,例如並行模擬等,不單單是繪畫。
書寫shader之前,通常都是先在photoshop 中,通過圖層處理,得到自己想要的效果,因此ps也要比較熟悉才能比較快速的開發shader。
可以看下這個視頻中,有關於shader的比較系統的介紹:
Unity shader 從0到1


你為什麼要用程序語言去解釋呢,你打開一個photoshop,告訴美術相加就是圖層模式的疊加,相乘就是正片疊底不就懂了么。如果美術跟你說某個物體結構不對你也無法理解吧。還有如果沒有材質編輯器的話,shader一般是TA或者程序寫。


現在 shader 已經不僅僅是材質渲染那麼簡單了,隨著 compute shader 的出現,渲染管線的一些部分已經可以在 GPU 端實現,效率更加高。這意味著今後對渲染程序的要求也會越來越高。

但是比較悲劇的是國內不要說 compute shader 編寫能力的普及,就是用 DX11 開發遊戲的也不多。


說明你們公司工具很落後,連個節點化的材質編輯器都沒有(如果用了u3d就不要埋怨這個)。
美術水平也一般,連材質編輯器的一般概念都不懂。
寫shader要求略高,一般美術都是依賴於工具做這個事情。
外國會寫shader美術的也不多。國外做遊戲畫面好是依賴於產業健全,人才齊備,積累多。
正常情況下一個優秀的技術美術或一個優秀的圖形程序員的刷新幾率是很低的。


給技術美術(TA)啊


一個好shader寫出來還要知道GPU的工作原理才能做優化,你讓美術寫……?


美術用可視化工具拉好效果後開發理解優化必要時完全重寫咯。


要美術寫程序太強人所難了吧


學了兩天shader。我覺得這玩意肯定是程序寫。要想寫shader,入門要會點計算機組成吧,會點物理線性代數吧。感覺程序開始學會很快的,美術出身的入門不容易吧


我倒是覺得很快就不是個大問題了。隨著延遲著色管線帶來的大一統shader會完成90%以上的工作需要。美術只要會調參數就好。美術同學要相信,用不了多久遊戲材質設定就會和離線渲染差不多了,不會和用vray什麼的有太大區別。

至於最後的一些特殊場合,特事特辦吧


美術部主程
或者程序部主美
嗯 就是這樣


要的是會美術的程序


很大一部分shader屬於3d引擎基礎設施,和引擎底層結合的很緊密,這種必須是程序寫的。
另外的一部分shader被打包成了參數編輯或是材質樹編輯的形式。這部分如果工具比較好用,可以提供給美術編輯。
結論: 都得寫,只是編輯形式不同。


shader哪有什麼藝術氣息,就是純演算法。

藝術氣息取決於怎麼用這個shader。
即便有節點式工具,也沒什麼卵用。國內的美術基本都只管自己眼前看到的,自己做的資源在遊戲中什麼樣就和他無關。

中國遊戲扯後腿的,美術怕是最嚴重的。


工具寫好了,誰都可以!


Shader 很多遊戲程序員都不會,美術看都不會,還說寫? 國內的美術 就是流水線作業的,一個角色8個工時,10個角色,兩個月,什麼? 你說跑在設備上怎麼樣? 美術哪裡知道,他們沒有安裝測試設備的好不好(除非是PC)。

Shder coding 應不應該由專職的美術寫?當然應該。樓上的TA不是說了,國外就是這麼乾的!因為shader 是 Rendering 的基礎技能,Rendering 你看這個詞 渲染,你敢說它跟美術無關? 遊戲是Rendering出來的, 不是用筆畫出來的。


推薦閱讀:

請別人來做一個電影網站模板需要多少錢?
如何才能真正的提高自己,成為一名出色的架構師?
暴風影音因 「肥胖症」 公開道歉,中國客戶端軟體面臨囚徒困境,說明了什麼?

TAG:互聯網 | 遊戲設計 | 軟體開發 | 遊戲開發 | 遊戲引擎 |