【轉(zhuǎn)】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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市君珠,隨后出現(xiàn)的幾起案子寝志,更是在濱河造成了極大的恐慌,老刑警劉巖策添,帶你破解...
    沈念sama閱讀 216,372評論 6 498
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件材部,死亡現(xiàn)場離奇詭異,居然都是意外死亡舰攒,警方通過查閱死者的電腦和手機败富,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,368評論 3 392
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來摩窃,“玉大人兽叮,你說我怎么就攤上這事』福” “怎么了鹦聪?”我有些...
    開封第一講書人閱讀 162,415評論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長蒂秘。 經(jīng)常有香客問我泽本,道長,這世上最難降的妖魔是什么姻僧? 我笑而不...
    開封第一講書人閱讀 58,157評論 1 292
  • 正文 為了忘掉前任规丽,我火速辦了婚禮,結(jié)果婚禮上撇贺,老公的妹妹穿的比我還像新娘赌莺。我一直安慰自己,他們只是感情好松嘶,可當我...
    茶點故事閱讀 67,171評論 6 388
  • 文/花漫 我一把揭開白布艘狭。 她就那樣靜靜地躺著,像睡著了一般翠订。 火紅的嫁衣襯著肌膚如雪巢音。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,125評論 1 297
  • 那天尽超,我揣著相機與錄音官撼,去河邊找鬼。 笑死橙弱,一個胖子當著我的面吹牛歧寺,可吹牛的內(nèi)容都是我干的燥狰。 我是一名探鬼主播,決...
    沈念sama閱讀 40,028評論 3 417
  • 文/蒼蘭香墨 我猛地睜開眼斜筐,長吁一口氣:“原來是場噩夢啊……” “哼龙致!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起顷链,我...
    開封第一講書人閱讀 38,887評論 0 274
  • 序言:老撾萬榮一對情侶失蹤目代,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后嗤练,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體榛了,經(jīng)...
    沈念sama閱讀 45,310評論 1 310
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,533評論 2 332
  • 正文 我和宋清朗相戀三年煞抬,在試婚紗的時候發(fā)現(xiàn)自己被綠了霜大。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,690評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡革答,死狀恐怖战坤,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情残拐,我是刑警寧澤途茫,帶...
    沈念sama閱讀 35,411評論 5 343
  • 正文 年R本政府宣布,位于F島的核電站溪食,受9級特大地震影響囊卜,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜错沃,卻給世界環(huán)境...
    茶點故事閱讀 41,004評論 3 325
  • 文/蒙蒙 一栅组、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧枢析,春花似錦笑窜、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,659評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽嫌蚤。三九已至辐益,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間脱吱,已是汗流浹背智政。 一陣腳步聲響...
    開封第一講書人閱讀 32,812評論 1 268
  • 我被黑心中介騙來泰國打工箱蝠, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留垦垂,地道東北人。 一個月前我還...
    沈念sama閱讀 47,693評論 2 368
  • 正文 我出身青樓劫拗,卻偏偏與公主長得像,于是被迫代替她去往敵國和親页慷。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 44,577評論 2 353

推薦閱讀更多精彩內(nèi)容

  • PLEASE READ THE FOLLOWING APPLE DEVELOPER PROGRAM LICENSE...
    念念不忘的閱讀 13,470評論 5 6
  • **2014真題Directions:Read the following text. Choose the be...
    又是夜半驚坐起閱讀 9,475評論 0 23
  • 來一遍我的前半生胁附,回憶一下過去我是怎么生活酒繁、學(xué)習(xí)控妻、工作州袒、家庭的,值得期待哦弓候。 小學(xué)前幾乎沒什么印象哦郎哭,...
    美美_bdc7閱讀 136評論 0 0
  • 若我老了,渾身病了 不要忘了弓叛,給我買骨灰盒 若我老了彰居,身體廢了 不要忘了,讓我安心的走 若我老了撰筷,瀕臨死亡 不要忘...
    Lqrs閱讀 314評論 3 2
  • 常常有人強調(diào)因果陈惰,現(xiàn)在的狀態(tài)是之前做某個決定的果,就像蝴蝶效應(yīng)一樣毕籽,如果當初選擇不一樣的就會有另外一個結(jié)果抬闯。所以常...
    蘋果14閱讀 195評論 1 0