Introduction to Visualization and Computer Graphics
DH2320, Fall 2015
Prof. Dr. Tino Weinkauf
Introduction to Visualization and
Computer Graphics
Visibility
Shading
Local Illumination
Smooth Shading Simple Shadows Global Illumination
3D Rendering
Visibility Perspective
Geometric Model Color
Visibility Algorithms
Two Rendering Pipelines
Rasterization
Project all triangles to the screen
Rasterize them (convert to pixels)
Determine visibility
Apply shading (compute color)
Raytracing
Iterate over all pixels
Determine visible triangle
Compute shading, color pixel
next lecture
Triangle / Polygon Rasterization
After Perspective Projection
Observations
Straight lines
remain straight!
Triangles mapped
to triangles
Polygons
to polyogns
Rasterization
3D Scene
Projection Visibility Rasterization
Visiblity
โข preprocessing
or
โข during rasterization
Rasterization
Two main algorithms
Painterโs algorithm (old)
Simple version
Correct version
z-Buffer algorithm
Dominant real-time method today
Painterโs Algorithm
Painterโs Algorithm
Painters Algorithm
Sort primitives back-to-front
Draw with overwrite
Drawbacks
Slowish
๐ช(๐ โ log ๐) for ๐ primitives
โMillions per secondโ
Wrong
Not guaranteed to always work
Counter Example
Correct Algorithm
Need to cut primitives
Several strategies
Notable: BSP Algorithm in Quake
Old graphics textbooks list many variants
No need for us to go deeper
z-Buffer Algorithm
z-Buffer Algorithm
Algorithm
Store depth value for each pixel
Initialize to MAX_FLOAT
Rasterize all primitives
Compute fragment depth & color
Do not overwrite if fragment is farer away than the one stored the one in the buffer
color depth
Discussion: z-Buffer
Advantages
Extremely simple
Versatile โ only primitive rasterization required
Very fast
GeForce 2 Ultra: 2GPixel /sec (release year: 2000)
GeForce 700 GTX Titan: 35 GPixel / sec (release year: 2013)
Discussion: z-Buffer
Disadvantages
Extra memory required
This was a serious in obstacle back then...
Invented 39 years ago (1974; Catmull / Straรer)
Only pixel resolution
Need painterโs algorithm for certain vector graphics computations
No transparency
This is a real problem for 3D games / interactive media
Often fall-back to sorting
Solution: A-Buffer, but no hardware support
Rasterization and Clipping
Rasterization
How to rasterize Primitives?
Two problems
Rasterization
Clipping
color depth
Rasterization
Assumption
Triangles only
Triangle not outside screen
No clipping required
Triangle Rasterization
Several Algorithms...
Triangle Rasterization
Example: two slabs
Triangle Rasterization
Incremental rasterization
ฮ๐ฅ constant
precompute and
add in each step
Incremental Rasterization
Precompute steps in x, y-direction
For boundary lines
For linear interpolation within triangle
Colors
Texture coordinates (more later)
Inner loop
Only one addition (โDDAโ algorithm)
Floating point value
Strategies
โ Fixed-point arithmetics
โ Bresenham / midpoint algorithm (requires if; problematic on modern CPUs)
Rasterization
How to rasterize Primitives?
Two problems
Rasterization
Clipping
color depth
Why Clipping?
Crashes โ write to off-screen memory!
Clipping Strategies
Pixel Rejection
โif (x,y โ screen) continue;โ
Can be arbitrarily slow (large triangles)
Nope. Not a good idea.
Screen space clipping
Modify rasterizer to jump to visible pixels
See tutorial 5
Efficient
Still problems with when crossing camera plane (๐ค = 0) โ a semi-good idea
Smart Slab Renderer
Does not crash, optimal complexity
๐(๐) for ๐ output fragments
Problem
Problem:
Triangles crossing camera plane!
Wrong results
Need object space clipping
๐ ๐ง1
๐ฆโฒ = ๐๐ฆ
๐ง
๐ง2
๐ฆ1
๐ฆ2
camera plane
image plane
View Frustum Clipping
near clipping
plane
far clipping
plane
four side
planes
six planes
clip triangles
against all
six planes
Incremental Algorithm
Incremental Algorithm
Incremental Algorithm
Output: Multiple Triangles
Further Optimization
View Frustum Culling
Complex shapes (whole bunnies)
Coarse bounding volume (superset)
Cube, Sphere
Often: Axis-aligned bounding box
Reject all triangles inside if bounding volume outside view frustrum
Smooth Shading Simple Shadows Global Illumination
3D Rendering
Visibility Perspective
Geometric Model
Local Illumination
Color
Shading Models
mirror
diffuse surface
Reflectance Models
glossy surface
Interaction with Surfaces
Local Shading Model
Single point light source
Shading model / material model
Input: light vector ๐ฅ = ๐ฉ๐จ๐ฌ๐๐๐โ๐ก โ ๐ฉ๐จ๐ฌ๐๐๐๐๐๐ก
Input: view vector ๐ฏ = ๐ฉ๐จ๐ฌ๐๐๐๐๐๐ โ ๐ฉ๐จ๐ฌ๐๐๐๐๐๐ก
Input: surface normal ๐ง (orthogonal to surface)
Output: color (RGB)
Viewer
Light
object surface
๐ฏ ๐ฅ ๐ง
Interaction with Surfaces
General scenario
Multiple light sources?
Light is linear
Multiple light sources: add up contributions
Double light strength โ double light output
Viewer
Light
object surface
๐ฏ ๐ฅ ๐ง
Remark
Simplify notation
Define component-wise vector product
๐ฑ โ ๐ฒ =
๐ฅ1
๐ฅ2
๐ฅ3
โ
๐ฆ1
๐ฆ2
๐ฆ3
โ
๐ฅ1 โ ๐ฆ1
๐ฅ2 โ ๐ฆ2
๐ฅ3 โ ๐ฆ3
No fixed convention in literature
The symbol โโโ only used in these lecture slides!
Remark
Lighting Calculations
Need to perform calculations for ๐, ๐, ๐-channels
Often: ๐๐ข๐ก๐๐ข๐ก๐ = ๐๐๐โ๐ก๐ โ ๐๐๐ก๐๐๐๐๐๐ โ ๐๐ข๐๐๐ก๐๐๐ ๐ฏ, ๐ฅ, ๐ง ๐๐ข๐ก๐๐ข๐ก๐ = ๐๐๐โ๐ก๐ โ ๐๐๐ก๐๐๐๐๐๐ โ ๐๐ข๐๐๐ก๐๐๐(๐ฏ, ๐ฅ, ๐ง)
๐๐ข๐ก๐๐ข๐ก๐ = ๐๐๐โ๐ก๐ โ ๐๐๐ก๐๐๐๐๐๐ โ ๐๐ข๐๐๐ก๐๐๐(๐ฏ, ๐ฅ, ๐ง)
Shorter ๐จ๐ฎ๐ญ๐ฉ๐ฎ๐ญ = ๐ฅ๐ข๐ ๐ก๐ญ_๐ฌ๐ญ๐ซ๐๐ง๐ ๐ญ๐ก โ ๐ฆ๐๐ญ๐๐ซ๐ข๐๐ฅ โ ๐๐ข๐๐๐ก๐๐๐ ๐ฏ, ๐ฅ, ๐ง
Shading Effects
Shading effects
Diffuse reflection
โAmbient reflectionโ
Perfect mirrors
Glossy reflection
Phong / Blinn-Phong
(Cook Torrance)
Transparency & refraction
Shading Effects
Shading effects
Diffuse reflection
โAmbient reflectionโ
Perfect mirrors
Glossy reflection
Phong / Blinn-Phong
(Cook Torrance)
Transparency & refraction
Diffuse (โLambertianโ) Surfaces
Equation ๐ ~ cos ๐
Less light received at flat angles
๐ = ๐๐ โ ๐๐ โ cos ๐
๐ ๐ง
๐
๐ง ๐ง surface normal
light color surface color
๐ โ intensity (scalar)
๐ โ color (RGB, โ3)
๐๐ โ surface color (RGB)
๐๐ โ light color (RGB)
(set to zero if negative)
Diffuse (โLambertianโ) Surfaces
Equation ๐ ~ cos ๐
Less light received at flat angles
๐ = ๐๐ โ ๐๐ โ cos ๐ โ light color surface color
๐ โ intensity (scalar)
๐ โ color (RGB, โ3)
๐๐ โ surface color (RGB)
๐๐ โ light color (RGB)
Attenuation: 1
๐๐๐ ๐ก2
(point lights)
1
๐๐๐ ๐ก2
1
๐๐๐ ๐ก2
๐ ๐ง
๐
๐ง ๐ง surface normal
Diffuse Reflection
Diffuse Reflection
Very rough surface microstructure
Incoming light is scattered in all directions uniformly
โDiffuseโ surface (material)
โLambertianโ surface (material)
Surface Normal?
What is a surface normal?
Tangent space:
Plane approximation at a point ๐ฑ โ ๐ฎ
Normal vector:
Perpendicular to that plane
Oriented surfaces:
Pointing outwards (by convention)
Orientation defined only for closed solids
point ๐ฑ
surface normal ๐ง ๐ฑ โ โ3
tangent space
๐ฎ
Triangles
Single Triangle
Parametric equation
๐ฉ1 + ๐ ๐ฉ2 โ ๐ฉ1 + ๐ ๐ฉ3 โ ๐ฉ1 |๐, ๐ โ โ
Tangent space: the plane itself
Normal vector ๐ฉ2 โ ๐ฉ1 ร ๐ฉ3 โ ๐ฉ1
Orientation convention: ๐ฉ1, ๐ฉ2, ๐ฉ3 oriented counter-clockwise
Length: Any positive multiple works (often ๐ง = 1)
๐ฉ1
๐ฉ3
๐ฉ2
๐ง
Triangle Meshes
Smooth Triangle Meshes
Store three different โvertex normalsโ
E.g., from original surface (if known)
Heuristic: Average neighboring triangle normals
Lambertian Surfaces
Equation
๐ = ๐๐ โ ๐๐ โ cos ๐ = ๐๐ โ ๐๐ โ ๐ง, ๐ฅ
light direction normal vector
๐ง ๐ฅ
(assuming: ๐ง = ๐ฅ = 1)
๐ ๐ง
๐
๐ง ๐ง surface normal
๐
Lambertian Bunny
Face Normals Interpolated Normals
Shading Effects
Shading effects
Diffuse reflection
โAmbient reflectionโ
Perfect mirrors
Glossy reflection
Phong / Blinn-Phong
(Cook Torrance)
Transparency & refraction
โAmbient Reflectionโ
Problem
Shadows are pure black
Realistically, they should be gray
Some light should bounce around...
Solution: Add constant ๐ = ๐๐ โ ๐๐
Not very realistic
Need global light transport simulation for realistic results
ambient light color surface color
Ambient Bunny
Pure Lambertian Mixed with Ambient Light
Shading Effects
Shading effects
Diffuse reflection
โAmbient reflectionโ
Perfect mirrors
Glossy reflection
Phong / Blinn-Phong
(Cook Torrance)
Transparency & refraction
Perfect Reflection
Perfect Reflection
Rays are perfectly reflected on surface
Reflection about surface normal
๐ซ = 2 ๐ง, ๐ฅ ๐ง โ ๐ฅ
๐ง
๐ฅ ๐ซ
Silver Bunny
Perfect Reflection
Difficult to compute
Need to match camera and light emitter
More later:
Recursive raytracing
Right image: Environment mapping
Reflective Bunny (Interpolated Normals)
Shading Effects
Shading effects
Diffuse reflection
โAmbient reflectionโ
Perfect mirrors
Glossy reflection
Phong / Blinn-Phong
(Cook Torrance)
Transparency & refraction
Glossy Reflection
Glossy Reflection
Imperfect mirror
Semi-rough surface
Various models
Phong Illumination Model
Traditional Model: Phong Model
Physically incorrect
(e.g.: energy conservation not guaranteed)
But โlooks okโ
Always looks like plastic
On the other hand, our world is full of plastic...
0
0,2
0,4
0,6
0,8
1
1,2
-90 -60 -30 0 30 60 90
p=1 p=2 p=5 p=10 p=50 p=100
How does it work?
Phong Model:
โSpecularโ (glossy) part:
๐ = ๐๐ โ ๐๐ โ ๐ซ
๐ซ,
๐ฏ
๐ฏ
๐
Ambient part: ๐ = ๐๐ โ ๐๐
Diffuse part: ๐ = ๐๐ โ ๐๐ โ ๐ง, ๐ฅ
Add all terms together
cos โ ๐ซ,๐ฏ
๐ฅ
๐ฏ ๐ซ
(high-) light color
Phong Exponents
๐ง
Blinn-Phong
Blinn-Phong Model:
โSpecularโ (glossy) part:
๐ = ๐๐ โ ๐๐ โ ๐ก
๐ก,
๐ง
๐ง
๐
Half-angle direction
๐ก =๐
๐
๐ฅ
๐ฅ+
๐ฏ
๐ฏ
cos โ ๐ก,๐ง
๐ฅ
๐ฏ ๐ก ๐ง
In the plane: โ ๐ก
๐ก,
๐ง
๐ง=
1
2โ
๐ซ
๐ซ,
๐ฏ
๐ฏ
Approximation in 3D
Phong+Diffuse+Ambient Bunny
Blinn-Phong Bunny Interpolated Normals
Phong+Diffuse+Ambient Bunny
Blinn-Phong Bunny Interpolated Normals
Better Models
Phong Bunny Cook-Torrance Model
Shading Effects
Shading effects
Diffuse reflection
โAmbient reflectionโ
Perfect mirrors
Glossy reflection
Phong / Blinn-Phong
(Cook Torrance)
Transparency & refraction
Transparency
Transparency
โAlpha-blendingโ
๐ผ = โopacityโ
Color + opacity: RGB๐ผ
Blending
Mix in ๐ผ of front color, keep 1 โ ๐ผ of back color
๐ = ๐ผ โ ๐๐๐๐๐๐ก + 1 โ ๐ผ โ ๐๐๐๐๐
Not commutative! (order matters)
unless monochrome
50% red, 50% green
0.01.00.00.5
1.00.00.00.5
back
front
Refraction: Snellโs Law
Refraction
Materials of different โindex of refractionโ
Light rays change direction at interfaces
Snellโs Law sin ๐1
sin ๐2=
๐2
๐1
๐1, ๐2: indices of refraction
vacuum: 1.0, air: 1.000293
water: 1.33, glass: 1.45-1.6
๐ง
โ๐ง
๐1
๐2
๐2 ๐1
Refraction
Implementation
Not a local shading model
Global algorithms: mostly raytracing
Various โfakeโ approximations for local shading
Refraction
Reflection
(raytraced)
Simple Shadows Global Illumination
3D Rendering
Visibility Perspective
Geometric Model
Local Illumination
Smooth Shading
Color
Shading Algorithms
Flat Shading
Flat Shading
constant color per triangle
Flat Shading
โGouraud Shadingโ Algorithm
compute color at vertices, interpolate color for pixels
Flat Shading
โPhong Shadingโ Algorithm
interpolate normals for each pixel
Simple Shadows
Geometric Model
Perspective Visibility Local Illumination
Smooth Shading
3D Rendering
Global Illumination
Global Illumination: next lecture
Color