Documente Academic
Documente Profesional
Documente Cultură
Shading
http://www.cse.ohio-state.edu/~somasund/GRAPHICS/TeapotPhongOUT.jpg
What is Shading?
Calculating how a 3D object should look, taking lighting
into account
Depends on:
mesh data
vertices, colors, textures, etc.
lighting properties
type of light, position of light, etc.
How is it done?
basically by running a script on your graphics card
Whats a Shader?
A good definition from Wikipedia:
a program used to determine the final surface
properties of an object or image
this can include arbitrarily complex descriptions of:
light absorption
light diffusion
texture mapping
reflection
refraction
shadowing
surface displacement
post-processing effects
Shader Languages
HLSL, GLSL, Cg (C for Graphics)
Compile to Assembly
Shader compilers are on the GPU
Compiling is done at runtime
Shading Languages
Shader programs may be written for different platforms
can operate on GPU
Nvidia Cg
uses assembly-like code
Pixars RenderMan
the pioneer among shaders
Shader Types
Vertex Shader
Pixel Shader (Fragment Shader in GLSL)
Geometry Shader
Compute Shader
Vertex Shader
Job is to process vertices and send them to pixel
shader
Process?
Transformation & lighting
Shading Techniques
Flat shading
Smooth Shading
Gouraud shading
Phong shading
Additional techniques:
bump mapping
cel shading
and many more
Flat Shading
Assigns a single color to a
polygon
Simple & fast
Color based on:
Material color
the polygon's normal
the position and intensity
of a light source.
Gouraud Shading
invented by Henri Gouraud in 1971
simulates smoothly shaded surfaces
How?
computes vertex colors using normals & lighting
interpolates vertex colors across a polygon's surface
done linearly
Phong Shading
invented by Bui Tuong Phong
a smooth shading technique
approximates curved-surface
lighting
How?
interpolates the vertex normals
of a polygon across the surface
Bump Mapping
Cel Shading
also called toon shading
technique of making computer generated graphics
appear to look hand drawn
How?
objects have black outlines (as though done with
pencil)
done via inversing back-face culling with black vertices &
slight translation
Texture Shading
Textures can be lit as well
weve already seen this
How?
make polygon white & light normally
when laying texture, calculate texel brightness using polygon
colors before texture
Rendering Pipeline
Ordered operations involved in transforming a
scene to a screen
transformations, hiding, lighting, shading, projection
Rendering Options:
Fixed-function pipeline
actually emulated these days
Programmable pipeline
Types of Shaders
Vertex Shaders
allows programmer to control transformation &
lighting operations (T&L)
Pixel Shading
the output of a vertex shader provides input to a pixel
shader
allows programmer to ultimately decide final pixel
colors before rasterization
Shader Models
standardized support for shader programs
ex: Microsofts Shader Model 3.0
Shader Tools
Most modeling tools provide shader support
WYSIWYG use of algorithms
generation of shader code
shader work encapsulated in effects
Ex:
Maya
3D Studio Max,
NVIDIAs Effects Browser, Shader City, & Shader
Studio
Next Time
Shader Examples
GLSL & HLSL
Resources
GameDev.net
http://www.gamedev.net/columns/hardcore/dxshader1/
http://www.gamedev.net/reference/programming/features/celshading/
HowStuffWorks
http://computer.howstuffworks.com/question484.htm
MSDN
http://msdn.microsoft.com/library/default.asp?url=/library/enus/directx9_c/directx/graphics/programmingguide/gettingstarted/architecture.
asp
Wikipedia
http://en.wikipedia.org/wiki/Computer_graphics#Shading
http://en.wikipedia.org/wiki/Cel-shaded_animation