![Page 1: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/1.jpg)
An Introduction toWriting Custom Unity Shaders!
![Page 2: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/2.jpg)
Andy Touch@andytouch
Content EvangelistEurope, Middle East, Africa & Russia
![Page 3: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/3.jpg)
Shaders
![Page 4: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/4.jpg)
Shaders
![Page 5: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/5.jpg)
“Shaders Are Scary!!”
![Page 6: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/6.jpg)
Before This Talk:“WTF is a Shader? Some sort of wizardry?!”
After This Talk:“Ah, I get it now! I want to experiment!”
![Page 7: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/7.jpg)
Wikipedia on Shaders“A Program That Tells A Computer
To Draw Something In A Specific and Unique Way”
Wow! Wikipedia got it right! :O
![Page 8: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/8.jpg)
But why learn Shader Programming?!Built-In Shaders are for ‘generic’ use-
casesUnique and Custom Visuals!
You can do some Really Weird Stuff.Optimization!
Shader Skills are ‘Gold Dust’They aren’t THAT scary
They are fun to play with. :)
![Page 9: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/9.jpg)
Unity Shaders Written using NVidia’s CG
But wrapped in Unity’s ShaderLab!
![Page 10: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/10.jpg)
ShaderLab
ShaderLab
CG
ExampleShader.shader
![Page 11: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/11.jpg)
Vertex And Fragment ShadersSurface Shader
![Page 12: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/12.jpg)
Vertex And Fragment Shaders Surface Shader
![Page 13: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/13.jpg)
Vertex And Fragment ShadersSurface Shader
![Page 14: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/14.jpg)
Shader FlowStep 1) Gather the Information to Use
![Page 15: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/15.jpg)
Shader FlowStep 2) Vertex Function (Build the Object in the World)
![Page 16: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/16.jpg)
Shader FlowStep 3) Vertex to Fragment (Send it to the screen!)
![Page 17: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/17.jpg)
Shader FlowStep 4) Fragment Function (Color in it’s screen pixels!)
![Page 18: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/18.jpg)
Shader FlowStep 5) Done! Object is rendered. :)
![Page 19: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/19.jpg)
Shader FlowStep 1) Gather the Information to Use
![Page 20: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/20.jpg)
Shader FlowStep 2) Vertex Function (Build the Object in the World)
![Page 21: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/21.jpg)
Shader FlowStep 3) Vertex to Fragment (Send it to the screen!)
![Page 22: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/22.jpg)
Shader FlowStep 4) Fragment Function (Color in it’s screen pixels!)
![Page 23: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/23.jpg)
Shader FlowStep 5) Done! Object is rendered. :)
![Page 24: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/24.jpg)
Vertex And Fragment Shader Flow
Object Data Custom Data
Vertex Function V2F Struct Fragment Function
Object Drawn On Screen!
Shad
er
![Page 25: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/25.jpg)
Demo Time!(Because PowerPoint is boring…)
![Page 26: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/26.jpg)
Vertex And Fragment ShaderSurface Shader
![Page 27: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/27.jpg)
Surface Shaders do lots Automagically
Object Lighting (Directional, Point etc)Shadows
Ambient LightingReflections
LightmappingPBR Workflow
![Page 28: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/28.jpg)
Final Drawing to the ScreenSurface Vertex/Fragment
![Page 29: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/29.jpg)
Default Surface V/F: Texture + Reflections
![Page 30: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/30.jpg)
Default Surface V/F: 1 Light and Shadows
![Page 31: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/31.jpg)
Default Surface V/F: Simple Lightmapping
![Page 32: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/32.jpg)
Default Surface V/F Combined…
![Page 33: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/33.jpg)
Surface Shaders do lots Automagically
But this makes them Overkill!
NO for Mobile/Low-EndSometimes tricky to manipulate
Kind-of Unity specific…“Do you need all those PBR outputs?”
![Page 34: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/34.jpg)
BUT…They make Custom Lighting creation easier!
![Page 35: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/35.jpg)
Color Ramp
![Page 36: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/36.jpg)
Demo Time!(Because PowerPoint is boring…)
![Page 37: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/37.jpg)
Diffuse Light = dot(Normal, LightDirection)
![Page 38: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/38.jpg)
Diffuse Light = dot(Normal, LightDirection)
![Page 39: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/39.jpg)
So… What Now?Shader Documentation
docs.unity3d.com/Manual/SL-Reference.html
![Page 40: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/40.jpg)
So… What Now?Built-In Unity Shader Package:
unity3d.com/get-unity/download/archive
![Page 41: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/41.jpg)
So… What Now?
Nvidia’s CG Documentationdeveloper.nvidia.com/Cg
![Page 42: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/42.jpg)
So… What Now?
Unity CommunityAsset StoreUnify Wiki
Unity Forums (Shaders)Community Blogs
![Page 43: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/43.jpg)
So… What Now?Google search:
“[insert game name] rendering techniques”
GDC TalksSiggraph Papers
Dev Blogs…More!
![Page 44: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/44.jpg)
So… What Now?
Go and Experiment!It’s the best way to learn. :)
![Page 46: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/46.jpg)
![Page 47: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/47.jpg)
John SmithTITLE
![Page 48: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/48.jpg)
Key headline text roughly6-10 words long
![Page 49: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/49.jpg)
Key headline text roughly6-10 words long
![Page 50: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/50.jpg)
Key headline text roughly6-10 words long
![Page 51: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/51.jpg)
Key headline text roughly6-10 words long
![Page 52: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/52.jpg)
Key headline text roughly6-10 words long
![Page 53: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/53.jpg)
Short headline goes here• Sample short explanatory text• Sample short explanatory text• Sample short explanatory text• Sample short explanatory text• Sample short explanatory text
![Page 54: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/54.jpg)
Short headline goes here• Sample short explanatory text• Sample short explanatory text• Sample short explanatory text• Sample short explanatory text• Sample short explanatory text
![Page 55: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/55.jpg)
Short headline goes here• Sample short explanatory text• Sample short explanatory text• Sample short explanatory text• Sample short explanatory text• Sample short explanatory text
![Page 56: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/56.jpg)
Short headline goes here• Sample short explanatory text• Sample short explanatory text• Sample short explanatory text• Sample short explanatory text• Sample short explanatory text
![Page 57: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/57.jpg)
Short headline goes here • Sample short explanatory text• Sample short explanatory text• Sample short explanatory text• Sample short explanatory text• Sample short explanatory text
![Page 58: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/58.jpg)
Sample short explanatory text50%100K
Sample short explanatory text
![Page 59: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/59.jpg)
Sample short explanatory text50%100K
Sample short explanatory text
![Page 60: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/60.jpg)
Sample short explanatory text50%100K
Sample short explanatory text
![Page 61: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/61.jpg)
Sample short explanatory text50%100K
Sample short explanatory text
![Page 62: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/62.jpg)
Sample short explanatory text50%100K
Sample short explanatory text
![Page 63: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/63.jpg)
Sample short explanatory text100,000
![Page 64: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/64.jpg)
Sample short explanatory text100,000
![Page 65: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/65.jpg)
Sample short explanatory text100,000
![Page 66: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/66.jpg)
Sample short explanatory text100,000
![Page 67: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/67.jpg)
Sample short explanatory text100,000
![Page 68: An Introduction to Writing Custom Unity Shaders!](https://reader035.vdocuments.us/reader035/viewer/2022062904/587b3a541a28ab9c0e8b4875/html5/thumbnails/68.jpg)
Samples