Let There Be Light (And Shadow) | Writing Unity URP Code Shaders Tutorial [2/9] ✔️ 2021.3

preview_player
Показать описание
✔️ Tutorial tested in 2020.3 and 2021.3

Have you ever wondered how lighting and shadows work in Unity? Or, do you want to write your own shaders for the Universal Render Pipeline, but without Shader Graph? Either because you need some special feature or just prefer writing code, this tutorial has you covered.

In fact, this is the second part in a series about writing HLSL shaders for URP. In this video, I will show how to add lighting to a shader. This includes a simple explanation of shadow mapping - how objects cast and receive shadows in URP - as well as an introduction to keywords and shader variants - an important concept when writing shaders!

Tutorial series:
2️⃣ Lighting and Shadows ► You're watching it!
5️⃣ Advanced Lighting ► Coming soon
6️⃣ Advanced URP Features ► Coming soon
7️⃣ Custom Lighting Models ► Coming soon
8️⃣ Vertex Animation ► Coming soon
9️⃣ Interacting with C# ► Coming soon

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

🔗 Check out my website for a searchable list of tutorials!

📚 Reference scripts

⏲️ Timestamps:
0:00 Intro
1:10 Blinn-Phong
2:53 Hash-if statements
4:56 Albedo
5:20 Normals
8:26 Specular highlights
9:52 Keywords
10:43 Smoothness
11:45 Shadow mapping
13:58 Shadowcoords
14:30 Multi compiles
15:58 Cascades and soft shadows
18:17 The frame debugger
19:32 The shadow caster pass
21:35 The depth buffer
22:37 Shadow acne
25:12 ColorMask
25:40 Wrap up and credits

🎖️ Credits, references and further reading:

Music provided by Epidemic Sound

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

Hi everyone! I hope you enjoyed this tutorial. Check out the video description for links to the rest of the series!

I recorded the audio for this video while recovering from a sinus infection, and my voice barely held strong 😆Thank you for putting up with the occasional crackle!

NedMakesGames
Автор

Though I have conquered many shader challenges the past months, most of it was more of a "making physics and math that looks cool". This video is the first one I have seen that tackles such a large range of technicalities, like hash-ifs, multicompiling, differences between passes, varients and the likes. Such a comprehensive and pleasant overview of the "less fun stuff" is something I really needed, thank you for this!

molgeraxproductions
Автор

I have waited too long for this. Thanks, Ned.

abraiyan
Автор

Damn, this is the single most useful tutorial series on PBR shading out there. You explained in this video what took me multiple weeks to gather from all over the place.
Incredibly well done, I hope you finish this tutorial series as I've got a lot to learn still too!

maxvandoorn
Автор

Really impressed with the level of quality and depth you go in with urp shaders! Easily the best source for how to write shaders in urp and how the graphics pipeline works. I have been wanting to learn more about the graphics pipeline and trying to find more advanced shader tutorials that go more in depth. This is AMAZING!

bots_op
Автор

This was great as always! Can’t wait for the next one!

jeffbulljr
Автор

(Unity version 2022.3.5)
I'm not sure isn't my misunderstanding or some version different

when I add
lightingInput.shadowCoord =
and
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS

it would't see the shadow on my obj.
(i don't see the option to close cascade)

it must be add
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
(didn't need #pragma multi_compile _ _MAIN_LIGHT_SHADOWS)
that shadows will show up


( If someone know what happen on that, please tell me)

賀客
Автор

I see you've only gotten 3 of 9 videos done for this. I'm a source-code $10 patron of yours now, and what you've gotten done so far is well worth a few more months of patronage -- but I'd like to remain your long term patron if you can deliver at least one new tutorial per month. Your videos here are very useful! Thank you for existing, and for choosing to help out everyone else!

brianknox
Автор

Ohh man, awesome stuff. Everything was explained clearly. Can't wait for next episode :)

MarekNijaki
Автор

these tutorials are honestly great as there is hardly any documentation on urp.

LeehamsonTheThird
Автор

Can't wait to see your next tutorial. Quality content!

franciszekbarszcz
Автор

Echoing all the comments below this is really good stuff ... looking forward to more and more and more videos ... we need more videos ... explanations are clear and to the point ... it seems incredible to me that Unity does not produce anything like this at all ... their documentation is really horrible ... for a game engine that likes to have noob customers they are not doing a good job... looks like this is where you come in .. it is mainly because of talents like you that I chose Unity as my main platform ... I wish Unity would take better care of us .. the community is fantastic ...

jussirautiainen
Автор

Hello, I am using Unity 2022.3.8 and I saw another comment using #pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE in order to get the shadows to show up, however even when I do this, I have no shadows. How do I fix this? My code up until that point is the exact same as the tutorial.

y-su
Автор

Hi! I've been looking for an answer in this video, but didn't find it here either, I'm using UniversalFragmentBlinnPhong for my compute shader generated grass, and when I've recently added a day-night cycle, I noticed it's not affected at all by ambient light, how do I make it work?

NineSins
Автор

Have replicated your code for specular and all works fine except for the camera movement. Seems like cam position does not affect where the specular highlight is.
Tried looking around if I could find a fix but got stuck on it, I'll get back to it next time but in the meanwhile if you have some suggestion of why the same code might not work shout! Thx
It definitely sounds like I made a mistake somewhere, but I get no unity console errors or warnings and everything apart from that seems to work ok.

borzonstudios
Автор

This is so COOL!! Thx so much for sharing.

RenaissanceWen
Автор

Awsome tutorial that explains things in great details.

carlwong
Автор

This ShadowCaster pass is incompatible with SPR Batcher, right?
Any solution?

wagnerdesouza
Автор

Hey Ned. Implemented Lit material according to this lesson of yours. In general, everything is fine, but the shadows that fall on this material are very dark. As if in deep space, where the only source of light is the sun and everything that is obscured from it is in absolute darkness. Can you advise how to solve this problem? Regular URP materials in the same situation are also affected by global illumination, how to make it affect your material as well?

aleksandrburykh
Автор

im getting a
> unrecgonized identifier SurfaceData surfaceInput

Purpbatboi