Shader programming is typically an esoteric technological area for those that have started off programming game clients using Unity. Since Unity abstracts out the graphics pipeline into an easy to use visual editor, we rarely delve into the inner workings of the programmable GPU
4. Well some parts are
programmable & others can be
configured with fixed function calls
OpenGL
API
OpenGL Pipeline
Vertex Buffer
Objects
Vertex
Shader
Primitive
Assembly
Rasterization
Texture
Memory
Fragment
Shader
Fragment
Operations
Frame Buffer
EGL
API
5. Vertex Buffer Objects
You store Vertex properties in these:
Positions,
Texture Coordinates,
and so on…
Op
en
GL
Pip
elin
e
19. Therefore EVERY vertex has
to go through…
Model Coordinates
World Coordinates
Camera Coordinates
Projection Coordinates
[Model Matrix]
[View Matrix]
[Projection Matrix]
20. For model vertices to become
screen vertices,
we must transform them via
complex matrix multiplications…
The bad news is that for OpenGL
we have to
calculate the MVP matrix manually…
21. But Unity makes it very very easy for us
with a built in matrix variable we can use…
UNITY_MATRIX_MVP
24. In order to appreciate that, it is
important to look at what it takes
to render a cube if there was no Unity…
Fire up Xcode on your MacBooks!
25. So Unity takes care of all this complexity
plus gives us ShaderLab: Any easy
interface to write shaders with…
Op
en
GL
Pip
elin
e
Vertex
Shader
Fragment
Shader
ShaderLab
Surface
Shader
26. ShaderLab is a meta language that
wraps around a Cg program
Vertex
Shader
Fragment
Shader
ShaderLab
Cg Code
ShaderLab
Code
Surface
Shader
27. A ‘Shader Program’ requires both a
Vertex Shader + Fragment Shader
Vertex
Shader
Fragment
Shader+ =
Shader
Program
28. Shader Core Inputs & Outputs
Vertex
Shader
Runs for each Vertex
Fragment
Shader
Runs for each Fragment
Vertices Fragments
Colored FragmentsUniforms
29. Let’s get going with
writing Shaders…
Fire up Unity!
The rest of this presentation is a hands-on shader writing workshop…