68
An Introduction to Writing Custom Unity Shaders!

An Introduction to Writing Custom Unity Shaders!

Embed Size (px)

Citation preview

Page 1: An Introduction to Writing  Custom Unity Shaders!

An Introduction toWriting Custom Unity Shaders!

Page 2: An Introduction to Writing  Custom Unity Shaders!

Andy Touch@andytouch

Content EvangelistEurope, Middle East, Africa & Russia

Page 3: An Introduction to Writing  Custom Unity Shaders!

Shaders

Page 4: An Introduction to Writing  Custom Unity Shaders!

Shaders

Page 5: An Introduction to Writing  Custom Unity Shaders!

“Shaders Are Scary!!”

Page 6: An Introduction to Writing  Custom Unity Shaders!

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!

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!

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!

Unity Shaders Written using NVidia’s CG

But wrapped in Unity’s ShaderLab!

Page 10: An Introduction to Writing  Custom Unity Shaders!

ShaderLab

ShaderLab

CG

ExampleShader.shader

Page 11: An Introduction to Writing  Custom Unity Shaders!

Vertex And Fragment ShadersSurface Shader

Page 12: An Introduction to Writing  Custom Unity Shaders!

Vertex And Fragment Shaders Surface Shader

Page 13: An Introduction to Writing  Custom Unity Shaders!

Vertex And Fragment ShadersSurface Shader

Page 14: An Introduction to Writing  Custom Unity Shaders!

Shader FlowStep 1) Gather the Information to Use

Page 15: An Introduction to Writing  Custom Unity Shaders!

Shader FlowStep 2) Vertex Function (Build the Object in the World)

Page 16: An Introduction to Writing  Custom Unity Shaders!

Shader FlowStep 3) Vertex to Fragment (Send it to the screen!)

Page 17: An Introduction to Writing  Custom Unity Shaders!

Shader FlowStep 4) Fragment Function (Color in it’s screen pixels!)

Page 18: An Introduction to Writing  Custom Unity Shaders!

Shader FlowStep 5) Done! Object is rendered. :)

Page 19: An Introduction to Writing  Custom Unity Shaders!

Shader FlowStep 1) Gather the Information to Use

Page 20: An Introduction to Writing  Custom Unity Shaders!

Shader FlowStep 2) Vertex Function (Build the Object in the World)

Page 21: An Introduction to Writing  Custom Unity Shaders!

Shader FlowStep 3) Vertex to Fragment (Send it to the screen!)

Page 22: An Introduction to Writing  Custom Unity Shaders!

Shader FlowStep 4) Fragment Function (Color in it’s screen pixels!)

Page 23: An Introduction to Writing  Custom Unity Shaders!

Shader FlowStep 5) Done! Object is rendered. :)

Page 24: An Introduction to Writing  Custom Unity Shaders!

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!

Demo Time!(Because PowerPoint is boring…)

Page 26: An Introduction to Writing  Custom Unity Shaders!

Vertex And Fragment ShaderSurface Shader

Page 27: An Introduction to Writing  Custom Unity Shaders!

Surface Shaders do lots Automagically

Object Lighting (Directional, Point etc)Shadows

Ambient LightingReflections

LightmappingPBR Workflow

Page 28: An Introduction to Writing  Custom Unity Shaders!

Final Drawing to the ScreenSurface Vertex/Fragment

Page 29: An Introduction to Writing  Custom Unity Shaders!

Default Surface V/F: Texture + Reflections

Page 30: An Introduction to Writing  Custom Unity Shaders!

Default Surface V/F: 1 Light and Shadows

Page 31: An Introduction to Writing  Custom Unity Shaders!

Default Surface V/F: Simple Lightmapping

Page 32: An Introduction to Writing  Custom Unity Shaders!

Default Surface V/F Combined…

Page 33: An Introduction to Writing  Custom Unity Shaders!

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!

BUT…They make Custom Lighting creation easier!

Page 35: An Introduction to Writing  Custom Unity Shaders!

Color Ramp

Page 36: An Introduction to Writing  Custom Unity Shaders!

Demo Time!(Because PowerPoint is boring…)

Page 37: An Introduction to Writing  Custom Unity Shaders!

Diffuse Light = dot(Normal, LightDirection)

Page 38: An Introduction to Writing  Custom Unity Shaders!

Diffuse Light = dot(Normal, LightDirection)

Page 39: An Introduction to Writing  Custom Unity Shaders!

So… What Now?Shader Documentation

docs.unity3d.com/Manual/SL-Reference.html

Page 40: An Introduction to Writing  Custom Unity Shaders!

So… What Now?Built-In Unity Shader Package:

unity3d.com/get-unity/download/archive

Page 41: An Introduction to Writing  Custom Unity Shaders!

So… What Now?

Nvidia’s CG Documentationdeveloper.nvidia.com/Cg

Page 42: An Introduction to Writing  Custom Unity Shaders!

So… What Now?

Unity CommunityAsset StoreUnify Wiki

Unity Forums (Shaders)Community Blogs

Page 43: An Introduction to Writing  Custom Unity Shaders!

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!

So… What Now?

Go and Experiment!It’s the best way to learn. :)

Page 45: An Introduction to Writing  Custom Unity Shaders!

Thank You!

Andy Touch

@[email protected]

Page 46: An Introduction to Writing  Custom Unity Shaders!
Page 47: An Introduction to Writing  Custom Unity Shaders!

John SmithTITLE

Page 48: An Introduction to Writing  Custom Unity Shaders!

Key headline text roughly6-10 words long

Page 49: An Introduction to Writing  Custom Unity Shaders!

Key headline text roughly6-10 words long

Page 50: An Introduction to Writing  Custom Unity Shaders!

Key headline text roughly6-10 words long

Page 51: An Introduction to Writing  Custom Unity Shaders!

Key headline text roughly6-10 words long

Page 52: An Introduction to Writing  Custom Unity Shaders!

Key headline text roughly6-10 words long

Page 53: An Introduction to Writing  Custom Unity Shaders!

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!

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!

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!

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!

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!

Sample short explanatory text50%100K

Sample short explanatory text

Page 59: An Introduction to Writing  Custom Unity Shaders!

Sample short explanatory text50%100K

Sample short explanatory text

Page 60: An Introduction to Writing  Custom Unity Shaders!

Sample short explanatory text50%100K

Sample short explanatory text

Page 61: An Introduction to Writing  Custom Unity Shaders!

Sample short explanatory text50%100K

Sample short explanatory text

Page 62: An Introduction to Writing  Custom Unity Shaders!

Sample short explanatory text50%100K

Sample short explanatory text

Page 63: An Introduction to Writing  Custom Unity Shaders!

Sample short explanatory text100,000

Page 64: An Introduction to Writing  Custom Unity Shaders!

Sample short explanatory text100,000

Page 65: An Introduction to Writing  Custom Unity Shaders!

Sample short explanatory text100,000

Page 66: An Introduction to Writing  Custom Unity Shaders!

Sample short explanatory text100,000

Page 67: An Introduction to Writing  Custom Unity Shaders!

Sample short explanatory text100,000

Page 68: An Introduction to Writing  Custom Unity Shaders!

Samples