Upload
devgamm-conference
View
256
Download
2
Embed Size (px)
Citation preview
An Introduction toWriting Custom Unity Shaders!
Andy Touch@andytouch
Content EvangelistEurope, Middle East, Africa & Russia
Shaders
Shaders
“Shaders Are Scary!!”
Before This Talk:“WTF is a Shader? Some sort of wizardry?!”
After This Talk:“Ah, I get it now! I want to experiment!”
Wikipedia on Shaders“A Program That Tells A Computer
To Draw Something In A Specific and Unique Way”
Wow! Wikipedia got it right! :O
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. :)
Unity Shaders Written using NVidia’s CG
But wrapped in Unity’s ShaderLab!
ShaderLab
ShaderLab
CG
ExampleShader.shader
Vertex And Fragment ShadersSurface Shader
Vertex And Fragment Shaders Surface Shader
Vertex And Fragment ShadersSurface Shader
Shader FlowStep 1) Gather the Information to Use
Shader FlowStep 2) Vertex Function (Build the Object in the World)
Shader FlowStep 3) Vertex to Fragment (Send it to the screen!)
Shader FlowStep 4) Fragment Function (Color in it’s screen pixels!)
Shader FlowStep 5) Done! Object is rendered. :)
Shader FlowStep 1) Gather the Information to Use
Shader FlowStep 2) Vertex Function (Build the Object in the World)
Shader FlowStep 3) Vertex to Fragment (Send it to the screen!)
Shader FlowStep 4) Fragment Function (Color in it’s screen pixels!)
Shader FlowStep 5) Done! Object is rendered. :)
Vertex And Fragment Shader Flow
Object Data Custom Data
Vertex Function V2F Struct Fragment Function
Object Drawn On Screen!
Shad
er
Demo Time!(Because PowerPoint is boring…)
Vertex And Fragment ShaderSurface Shader
Surface Shaders do lots Automagically
Object Lighting (Directional, Point etc)Shadows
Ambient LightingReflections
LightmappingPBR Workflow
Final Drawing to the ScreenSurface Vertex/Fragment
Default Surface V/F: Texture + Reflections
Default Surface V/F: 1 Light and Shadows
Default Surface V/F: Simple Lightmapping
Default Surface V/F Combined…
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?”
BUT…They make Custom Lighting creation easier!
Color Ramp
Demo Time!(Because PowerPoint is boring…)
Diffuse Light = dot(Normal, LightDirection)
Diffuse Light = dot(Normal, LightDirection)
So… What Now?Shader Documentation
docs.unity3d.com/Manual/SL-Reference.html
So… What Now?Built-In Unity Shader Package:
unity3d.com/get-unity/download/archive
So… What Now?
Nvidia’s CG Documentationdeveloper.nvidia.com/Cg
So… What Now?
Unity CommunityAsset StoreUnify Wiki
Unity Forums (Shaders)Community Blogs
So… What Now?Google search:
“[insert game name] rendering techniques”
GDC TalksSiggraph Papers
Dev Blogs…More!
So… What Now?
Go and Experiment!It’s the best way to learn. :)
John SmithTITLE
Key headline text roughly6-10 words long
Key headline text roughly6-10 words long
Key headline text roughly6-10 words long
Key headline text roughly6-10 words long
Key headline text roughly6-10 words long
Short headline goes here• Sample short explanatory text• Sample short explanatory text• Sample short explanatory text• Sample short explanatory text• Sample short explanatory text
Short headline goes here• Sample short explanatory text• Sample short explanatory text• Sample short explanatory text• Sample short explanatory text• Sample short explanatory text
Short headline goes here• Sample short explanatory text• Sample short explanatory text• Sample short explanatory text• Sample short explanatory text• Sample short explanatory text
Short headline goes here• Sample short explanatory text• Sample short explanatory text• Sample short explanatory text• Sample short explanatory text• Sample short explanatory text
Short headline goes here • Sample short explanatory text• Sample short explanatory text• Sample short explanatory text• Sample short explanatory text• Sample short explanatory text
Sample short explanatory text50%100K
Sample short explanatory text
Sample short explanatory text50%100K
Sample short explanatory text
Sample short explanatory text50%100K
Sample short explanatory text
Sample short explanatory text50%100K
Sample short explanatory text
Sample short explanatory text50%100K
Sample short explanatory text
Sample short explanatory text100,000
Sample short explanatory text100,000
Sample short explanatory text100,000
Sample short explanatory text100,000
Sample short explanatory text100,000
Samples