Creating a Foliage Shader in Unity URP! Grass, Trees, Flowers, Hedges and More | Game Dev Tutorial

preview_player
Показать описание

✔️ Tutorial tested in Unity URP 2020.3 & 2021.3

Plants, foliage and vegetation are really challenging to get right! It requires a custom made shader to tackle issues like translucency and wind. In this tutorial, I show how to create a foliage shader in the Unity URP (Universal Render Pipeline) Shader Graph. It supports all light types, shadows, and baked lighting, and includes several strategies for translucency, like separate normals for diffuse lighting and subsurface scattering. I also implement programmable wind animation and show a simple method to reconstruct normals. For grass billboards and tree leaf cards, I also demonstrate how to create double sided materials with normal map support.

📚 If you prefer reading, check out the written version of this tutorial here:

✏️ Text-only shader version coming soon!

🌟Previous videos:

🌞 Interactive lighting math explorer:

👋 Subscribe for weekly game development videos!

👑 Join my Patreon to watch videos early, download all project files, vote on future topics, and more! Thank you so much!

🔗 Visit my website for a searchable list of tutorials!

💻 Script reference:

⏲️ Timestamps:
0:00 Intro
0:26 Core ad
1:58 Tutorial info
3:35 Project set up
6:41 Two sided rendering
9:27 Shape normals
15:54 Translucent lighting
21:12 Data maps
25:23 Wind
34:14 Normal reconstruction
40:25 Examples
41:23 Wrap up and credits

🎖️ Credits, references and further reading:

Neon Laser Horizon by Kevin MacLeod

#GameDev #IndieDev #Unity
Рекомендации по теме
Комментарии
Автор

The editor is fun to play around with, great for practicing level design! Thanks again Core for sponsoring this video!

But, back to Unity! You can dive really deep into foliage shaders. Would you like to see a tutorial about any specific type of vegetation or technique to render them? How are you planning to use this shader?

NedMakesGames
Автор

ned, been following your vids for about a year now, gotta say, thank goodness there are brains like you to help out guys like me. I'd never understand any of this without these tutorials. You da man

dreamscheme
Автор

No time to work with this right now, but i'm pretty sure i will appreciate this some day. Well done, Ned!

sealsharp
Автор

Fun to watch, and easy to follow! Well done, as always! Thanks so much.

stephapie
Автор

Just a heads-up at 5:35, the foliage shader needs to remain an "Opaque" mode shader, even though we enable alpha clipping and alpha on the fragment master node. Easy mistake to think you need a "Transparent" shader. In Unity, anything using a "Transparent" shader will end up not writing to depth buffers and you'll see odd z-ordering artifacts especially on geometry like the test sphere.

ed_halley
Автор

Wow, already judging by the runtime seems like a lot... Given that 15 minute tutorial of yours takes a couple of hours for me to run through and follow with comprehension... This one will take a week I think :D

adamodimattia
Автор

Amazing tutorial by the way! I wanted to ask, can these Shadergraph Shaders be used with compute-shader generated geometry?

mmmbackwheelbates
Автор

GAH! NED!! You can't just put out awesome tutorials and take me away from work for a couple of hours! ...I mean... clearly you CAN... but, personally, I'd REALLY appreciate it if you could just schedule things with my secretary from now on.
... I should probably get a secretary....

paladinrose
Автор

Maybe I'm missing something but why do we need to make an entire shader for lighting when shader graph has lighting, shadows, baked gi lighting, built in? Seems like a waste of resources.

NeonTheCoder
Автор

This is a very educational tutorial, thanks! But is there any way to read Unity's built-in terrain wind so the custom objects sync with the other vegetation?

zackblack
Автор

Hi, when will the Text-only shader version come out? :D I'm a bit stuck on the shadow problem ... Thank you!

MsMartyrock
Автор

Do you know if you can use Shader Graph (HDRP for me) to create branch and leaf shaders for the Unity tree builder? I upgraded to HDRP, but the old shaders don't work (pink). I was trying to understand if I have to throw out all my trees and start again. Tree Builder keeps setting the material shader to Nature/Tree Creator Leaves Fast (which is not supported in HDRP), so I was trying to replace it with shader graph.

XOrdinary
Автор

Hi, after defining the ShapeNormal Enum keyword (12:50) may you will getting error that in Unity 2020.3.12f1 LTS or some other versions (2020.3.21f1 LTS) if you use, please update Shader Variant Limit To ~400-500 or more from Preferences->Shader Graph.
Still getting errors, If so, to fix this, delete FoliageLighting custom node from TestFoliage Graph, try to define ShapeNormal Enum, and, check still getting some errors, if not, add your deleted FoliageLighting custom node and connect them.

[TR] hey, eğer ShapeNormal Enum'dan sonra hata alırsanız, Preferences->Shader Graph altında Shader Variant Limit'i 400-500 üstüne yükseltin. Eğer hata geçmezse, FoliageLighting düğümünü silin, sonrasında ShapeNormal Enum tanımlamasını yapın. Eğer hata almazsanız sildiğiniz FoliageLihgting düğümünü ekleyin ve bağlantılarını yapın. Bu sorun 2020.3.12f1 LTS, 2020.3.21f1 LTS ve bazı sürümlerde alınabiliyor.


kolsuzgame
Автор

Hey Ned, could you help me understand my mistake?
It seems my double sided materials do not have shade on their back side after I completed the two sided rendering part.
It seems that the back face takes the same light as the front face despite the branch, any ideas?

orfeasrodopoulos
Автор

make a new one man one that has sub surface scattering to let light pass through

My_In-Ear_Monitor_Fetish
Автор

Will this work in unity 2022.3 i have tried everything but using vertex color as albedo input keeps showing just plain white but on other meshes it shows the reds and greens idk how to fix.

inhabitantwapsqs