【转】50 Shaders of Forge - Prototyping with Shader Forge

ART

I'm the type of person who is always advocating that artists should have versatile skills and be useful beyond the call of duty. I'm not that much of a believer in narrow expertise and long titles, and I'm not telling that you shouldn't focus your career path but I do think that wider skilled people are more useful — especially in iterative environments and agile teams. Now, that's me — I might be right, I might be wrong. I might be in quantum superposition but that's not the point.

My goal is to show you that you can easily master a tool that'll expand you and arm you with iteration speed and the visual quality of shaders. This is not for everyone, of course, but artists working on production/prototype assets can benefit from this, and therefore, so will the rest of their team.

Let's jump into it! I'm talking about Shader Forge, a node based shader editor for Unity. It's a commercial plugin that you can get from Unity's asset store.

General Overview

If you ever used any node based software before then you already know how to use Shader Forge. Nodes are connected and evaluated from left to right, and they usually don't have any individual settings. Even if they do, they are located directly on the node so it's easy to read the entire graph at once. With just some basic tech art knowledge, most of the nodes' names are self-explanatory but I suggest that you start with the official node list, then the tutorials and maybe some light wiki reading at the end. I admit that their documentation is not the best and online information is also limited but it's more than enough to get you started. For more community info, you can check their forum or the polycount thread.

The way I do things for prototyping is to build the shader with a focus on hitting the visual target. Once the team has that signed off, we can then release the shader to a developer for optimization. As developers will testify, this really speeds up the process and removes a lot of ping-pong. Shader Forge is not good at optimization because it compiles more for compatibility. Having said that, it's more than likely that everything you make will work on mobile as is (for testing purposes) — just don't go wild as you can easily go overboard. You can even check with your developer forehand on what is more/less expensive, but again — the visual target first!

I will go through some of the shaders I made, explaining and showcasing them along the way. I ordered them from low to high complexity so there is some gradation and learning curve to it. Don't get intimidated with those complex node graphs; once you start to analyze them, you'll see that everything is approachable.

You can download all the shaders here if you want to play around or build on top of them.

Water Foam

Let's start with something fairly simple. All the magic here is done with the Panner node that slides the UVs in the desired direction. You supply it with the UV channel and the direction speed, and then you get the animated UVs for your texture to move. Since this material is unlit, I used the white color for emission and the foam texture for opacity. The texture itself is multiplied with vertex alpha (from the VertexColor node) so it will fade off at the edges. Side note: the green colored nodes (in this case, Texture2D and Color ) are the exposed parameters that you can tweak externally.

But since the foam next to the shore line needs overlapping waves, I extended the shader by adding a value of 0.9 in the V direction of the UVs and then Appended it back so it'd be a Float2 again. This way, I could use that value to offset the initial position of the UVs and adjust the timing. In the end, I subtracted a value 0.4 to reduce the global opacity of the material since we have two of them overlapping. As you can see, it's easy to build on top of a shader and improve its functionality.

Caustics

But you can also get very creative with Panner and UV nodes, such as by making a deformable caustics shader. In this case, we are not panning the texture itself but the "deformation". I used a noise texture (different noises packed in channels), Panned and Added over the caustic texture UVs. The Remap node is used to tone down and control the amount of distortion and by Multiplying the UVs with a value, you can control the tiling of the texture. I also added additional controls like Thickness (Subtract) and Opacity (Multiply) for more finesse. Since this shader is set to the additive mode, I just plugged everything into Emission.

img

Water

Following the same principles, we can try something even more advanced, such as pool water. This uses the full PBR lightning model so we define the Base Color, Gloss and Metallic first. Then we Pan the normal texture and just Lerp it with a simple up Vector3 so we that can adjust the strength of the normal. Lerp stands for 'linear interpolation' and it works as a mask; you can blend two inputs with a value/texture/etc. I Normalized the normal just in case and used the same panned normal map for the Refraction input of the shader. Since that input expects a Vector2 value, you have to use the Component Mask node to separate out only the red and green channels of the normal map. Refraction works as an offset in screen space so some additional Distortion control was more than useful. Also, for the Refraction to work, you need to have some Opacity on the shader and set it to be alpha blended.

img

Here is how water and caustics look in the engine, and I suggest you watch it in full screen. Btw, those sparkles are a particle effect:

Sea

Following the proven M.O., you can easily level up that shader and build a sea surface. Here, I'm taking two normal maps: one for the general waves and the other for surface turbulence. Each has its own tilting and panning, and then mixing them with the Normal Blend node that does exactly that. I also introduced the Fresnel node to adjust the color at the glancing angles based on the normal map.

img

And here is that sea shader with the water foam in action. It has two layers of foam at the coastline and the defining color of the sea comes from the vertex colored underlying geometry. Watch in fullscreen.

Mossy Rock

This one is a one-trick pony, but at least it's a nice trick. All the magic happens in the Dot Product node that combines the world space up vector and the Normal Direction of the object. The Dot node is set to a positive result so you only get the moss on the top side of the rocks. After, I just used some Multiply, Power and Clamp nodes to control the amount, falloff and contrast of the effect. Use that as a mask for the Lerp node and you will have a rock that has moss on top of it no matter how you place it — pretty useful for environment prototyping. And it's versatile as well; use it for moss, sand, snow or inverse it and make the stone part in the water darker.

img

A practical usage demonstration with some parameters tweaking:

Growing Tree

Short and sweet, just to show you what you can do with Vertex Offset. The idea is to manipulate vertex positions with the shader, which then opens up many possibilities, this being just one of them. This is where vector math comes in handy. The Vertex Offset node accepts a XYZ coordinate for how much every vertex should be offset. In order to get the needed control, I used some vertex data that you can see on the image below. The alpha channel of the vertex color was used as an intensity mask for the general tree trunk animation and the red channel as the same thing but for the leaves (secondary) animation. To animate the tree growth, I combined the vertex World Position and the Object Position to make them move down towards the pivot by controlling the amount of movement with the Multiply nodes and a Grow slider. Something similar was used for the leaves but here I used the Normal Direction node for movement. Once that's done, you use the Add node to layer and combine all those animations. Now that I had external control via Grow and Leaves sliders, I made simple Unity animation clips of a tree growing up and going down and then triggered specific clips based on a tree entering or exiting a collider.

img

img

A mandatory and probably the coolest video in this post:

Wind

This shader looks intimidating but it follows the same principles as the previous one. The big difference here is that it uses the Time node to control the animation. This means it's loopable and keeps on going. The rest of it is just a bunch of Sin and Cos nodes combined to make a more complex and interesting animation graph. I used this online tool to plot out something I thought would be a nice representation of the wind movement and then just transferred that into nodes — something along the lines of 2*sin(3x)+sin(10x)-cos(5x).

img

img

And the video:

Splat Shader

And let us end this with something that has a wider usage. As you may know, Unity does not have a splat shader out of the box, but we can recreate one in Shader Forge quite easily. It takes just two nodes: Vertex Color to access the data and Lerp to blend all the textures together. By chaining the Lerp nodes, you actually blend multiple sources on top of each other.

img

After that, your options are pretty open. For testing purposes, I used a tile texture with two variations (dirty and mossy) and the free Ikari Vertex Painter for Unity to paint in texture variations.

img

Conclusion

Going back to my opening statement, I hope the power of this approach is obvious. If you take these shaders further or have anything of your own, please share. And, of course, I'm here if you have any questions.

https://youtu.be/UcqCfHalxDo

http://blog.nordeus.com/art/50-shaders-of-forge-prototyping-with-shader-forge.htm

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 220,192评论 6 511
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 93,858评论 3 396
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 166,517评论 0 357
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 59,148评论 1 295
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 68,162评论 6 397
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,905评论 1 308
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,537评论 3 420
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,439评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,956评论 1 319
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 38,083评论 3 340
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 40,218评论 1 352
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,899评论 5 347
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,565评论 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 32,093评论 0 23
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,201评论 1 272
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,539评论 3 375
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 45,215评论 2 358

推荐阅读更多精彩内容

  • PLEASE READ THE FOLLOWING APPLE DEVELOPER PROGRAM LICENSE...
    念念不忘的阅读 13,480评论 5 6
  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 9,524评论 0 23
  • 来一遍我的前半生,回忆一下过去我是怎么生活、学习、工作、家庭的,值得期待哦。 小学前几乎没什么印象哦,...
    美美_bdc7阅读 137评论 0 0
  • 若我老了,浑身病了 不要忘了,给我买骨灰盒 若我老了,身体废了 不要忘了,让我安心的走 若我老了,濒临死亡 不要忘...
    Lqrs阅读 316评论 3 2
  • 常常有人强调因果,现在的状态是之前做某个决定的果,就像蝴蝶效应一样,如果当初选择不一样的就会有另外一个结果。所以常...
    苹果14阅读 196评论 1 0