作为一个在中国生活十几年,在游戏行业工作八九年的歪果仁,我从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?
https://www. youtube.com/watch? v=hDJQXzajiPg
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