Shading
Ming Ouhyoung 歐陽明 Professor Dept. of CSIE and GINM
NTU
Illumination model
1) Ambient light (漫射)(or 環境反射) I = la * ka * Obj(r, g, b)
la : intensity of ambient light
ka : 0.0 ~ 1.0, Obj(r, g, b): object color 2) Diffuse reflection (散射)(or 漫反射)
I = Ip (r, g, b) * Kd * Obj(r, g, b) * COS(θ ) Ip (r, g, b): light color
3) Light source attenuation
Specular reflection
(似鏡面反射)• I = Ks * Ip(r, g, b) * COSn(α), Ks = specular-reflection coef.
• Phong illumination model
color of object = Obj (R, G, B)
= (Or, Og, Ob) or (light frequency) where 0.0 =< Od =< 1.0
Faster specular reflection calculation:
Halfway vector approximation
• halfway vector
Polygon shading : linear interpolation
a. flat shading : constant surface shading.
b. Gouraud shading: color interpolation shading.
c. Phong shading: vertex normal interpolation shading
Phong Shading
• Use a big triangle, light shot in the center, as an example!
• The function is really an approximation to Gaussian distribution
macroscopic
• The distribution of microfacets is Gaussian. [Torrance, 1967]
(Beckmann distribution func.)
• Given normal direction Na and Nb, Nm = ?
• interpolation in world or screen coordinate?
• in practice
Bi-linear interpolation
. Linear interpolation:
A (x1, y1, z1) with color (r1, g1, b1); B (x2, y2, z2) with color (r2, g2, b2)
What is the color of point C (x3, y3, z3) located on the line AB.
C = color of A + t * (color of B- color of A), where t is | (C-A) |/ |(B-A)|
Similarly, we can process Bi-linear interpolation
Gouraud Shading with Bilinear Interpolation
• Gouraud shading (smooth shading): color interpolation, for example,
Triangle with three vertices (x1, y1), (x2, y2), (x3, y3), each with red components R1, R2, R3
color is represented as (Red, Green , Blue)
Assuming a plane (in 3D) with vertices (x1, y1, R1), (X2, Y2, R2), and (X3, y3, R3)
Henri Gouraud
(at 2018 Siggraph)English pronunciation: /ger’raud/
French pronunciation: /’gu:hu:/
Gouraud shading
• Vector equation of the plane is
(x,y) = s (x2-x1, y2 – y1) + t(x3-x1, y3-y1) + (x1, y1) solved for (s, t) , then
s = A1x + B1y +C1, t = A2x + B2y +C2
So, given point (x,y) in this plane, what is its color?
Answer: color of (x,y) = R1+ s (R2-R1) + t (R3-R1), or color = Ax + By +C, where
A = A1 (R2-R1)+ A2 (R3-R1) B = B1(R2-R1) + B2 (R3-R1)
C = C1(R2-R1) + C2(R3-R1) + R1
How is the color calculated?
Since, (x,y) = s (x2-x1, y2 – y1) + t(x3-x1, y3-y1) + (x1, y1)
Therefore
, (x,y, R) = s (x2-x1, y2 – y1, R2-R1) + t(x3-x1, y3- y1, R3-R1) + (x1, y1, R1)
or, color R = s (R2-R1) + t (R3-R1) + R1
Complexity of shading
Phong: under Ivan Sutherland
• Bùi Tường Phong (Vietnamese: Bùi Tường Phong, December 14, 1942–1975) was a Vietnamese-born computer graphics researcher and pioneer.
• He came to the University of Utah College of
Engineering in September 1971 as a research assistant in Computer Science and he received his Ph.D. from the University of Utah in 1973.
• Phong knew that he was terminally ill with leukemia while he was a student. In 1975, after his tenure at the University of Utah, Phong joined Stanford as a
professor. He died not long after finishing his dissertation
What is the color of copper?
• Reflection of copper
– drastic change as a function of incidence angle [Cook, 82"]
New method: BRDF:Bi-directional Reflectance Density Function
• Use a camera to get the reflection of materials from many angles
• Light is also from many angles
The Rendering Equation: Jim Kajiya
BRDF
• BRDF: a four-dimensional function that defines how light is reflected at an opaque surface.
• The BRDF was first defined by Edward Nicodemus around 1965[1]. The modern definition is:
F(ωi, ωo) = dL(ωo)/dE(ωi ) = dL(ωo)/L(ωi )cos θi dωi
– where L is the radiance, E is the irradiance, and θi is the angle made between ωi and the surface normal, n.
BSSRDF
• The Bidirectional Surface Scattering Reflectance Distribution Function (BSSRDF), is a further
generalized 8-dimensional function S(Xi,ωi,Xo,ωo), in which light entering the surface may scatter
internally and exit at another location. X
describes a 2D location over an object's surface.
• non-local scattering effects like shadowing,
masking, interreflections or subsurface scattering.
SSBRDF, BSDF (Bidirectional scattering
distribution function)
3D face scan
Statute of Obama, US president
Statute of Obama (Plaster), US president
Homework #1
• Input : a file of polygons (triangles)
• test image : a teapot, a tube
• input format :
Triangle fr, fg, fb, br, bg, bb x y z nx ny nz
x1, y1, z1, …. , ,X2, y2, z2 …….,
/* where (fr, fg, fb) contains front face colors, (br, bg, bb) are background colors (x,y,z): 3D vertex position
(nx,ny,nz) : vertex normal
Hw#1 requirements
• Deadline: to be announced
• Output: shaded objects with at least two lights
• Rotation, Scaling, Translation, Shear
• Clipping (front and back, left and right, top and bottom)
• Camera: two different views
– Object view and camera view
• C, C++, Java, etc.
– Limited WebGL library calls
Polygon file format used
• e.q.
Triangle fr fg fb br bg bb x1 y1 z1 nx1 ny1 nz1
x2 y2 z2 nx2 ny2 nz2 x3 y3 z3 nx3 ny3 nz3 Triangle
– Where
fr, fg, fb are foreground colors (Red Green Blue) nx, ny, nz are vertex normal
Other formats (more efficient): winged-edge representation
• Vertices 1, (x, y, z)
2, (x1, y1, z1) 3, …
23, … 890, ….
1010
• Triangle 1010, 23, 890
• Triangle 1, 2, 800
Winged –edge: in which each edge points to two vertices, two faces, and the four (clockwise and counterclockwise) edges that touch them. Winged-edge meshes allow constant time traversal of the surface, but with higher storage requirements.
HW#1: expected results
Visible-Surface Determination
• The painter's algorithm
• The Z-buffer algorithm (chap 5.8, textbook)
– The point nearest to the eye is visible,...
– Very easy both for software and hardware.
– Hardware Implementation: Parallel ---> fast display
• Scan-line algorithms
– One scan line at a time
• Area-subdivision algorithm
– Divide and conquer strategy
• Visible-surface ray tracing
List-priority algorithms
• Depth-sort algorithm
sort by Z coord.(distance to the eye),
resolve conflicts(splitting polygons), scan convert·
---v.s.---painter's algorithm Binary Space PartitionTrees(BSP tree) (Chap 9.10, p505,
textbook)
Determine the depth order!
1. Mountain, 2. bridge, 3. people 4. Hat
Depth Sort: Easy Cases
• A lies behind all other polygons
– Can render
• Polygons overlap in z but not in either x or y
– Can render independently
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-
Wesley 2012
31
Hard Cases
Overlap in all directions but can one is fully on one side of the other
cyclic overlap
penetration
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-
Wesley 2012
32
BSP: Binary Space PartitionTrees(BSP tree)
The Display Order of Binary Space Partition Trees(BSP tree)
if Viewer is in front of root, then
• Begin {display back child, root, and front child}
• BSP_displayTree(tree->backchild)
• displayPolygon(Tree->root)
• BSP_displayTree(tree->frontchild)
• end else
• Begin
• BSP_displayTree(tree->frontchild)
• displayPolygon(Tree->root)
• BSP_displayTree(tree->backchild)
• end
Test: please give the BSP binary tree, and display order of this diagram. (Choose
smaller number as the new root)
Visibility determination(2): Z-buffer algorithm
Initialize a Z-buffer to infinity (depth_very_far) {
Get a Triangle, calculate one point's depth from three vertices by linear interpolation
If the one point's depth depth_P(x,y) is smaller than Z- Buffer(x,y)
Z-Buffer (x,y) = depth_P(x,y), Color_at(x,y) = Color_of_P(x,y) else
DO_NOTHING }
Complexity of shading
Homework #2 (could be) Unity 3D games
• Modify an exisiting game
• Change the way a canon ball is fired (weapon system), tank motion control etc.
HW#1: expected results
HW#1: formula
•
– Ia is object color
– Ip is the color of light, and can have multiple lights
• Note
– color overflow problem (integer color up to 255) – MAX = max(R, G, B) = 255 etc.
• Output format
– RGBx RGBx.... 256*256 pixels
– better results: 32<=R,G,B<=230, each 1 byte binary data
Visible line determination
1. Assume that visible surface determination can be done fast (by hardware Z-buffer or software BSP tree)
– This method is used in most high performance systems now!
(hollow triangle, mesh)
2. Depth cueing is more effective in showing 3D (in vector graphics machine, e.g. PS300). see sec.
14.3.4
– depth cueing: intensity interpolation
Visible - line determination:
Appel's algorithm
• quantitative invisibility of a point=0 --> visible
• quantitative invisibility changes when it passes
"contour line".
• contour line:(define)
• vertex traversing
– EF: contour line
– AB: whether this line
segment is partially visible?
Standard Graphics Pipeline
How to transform a plane? a surface normal?
plane equation Ax + By + Cz + D = 0 NT*P=0 since p is transformed by M, How should we transform N?
find Q, such that (Q*N)T*M*P=0 (N')T.(P')=0 i.e. NT*QT*M*P=0, i.e. QT*M=I
∴QT=M-1 Q=(M-1)T
similar, the surface normal is transformed by Q, not M!!
Aliasing, anti-aliasing
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012
Aliasing
• Ideal rasterized line should be 1 pixel wide
• Choosing best y for each x (or visa versa) produces aliased raster lines
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012
Antialiasing by Area Averaging
• Color multiple pixels for each x depending on coverage by ideal line
original antialiased
magnified
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012
Polygon Aliasing
• Aliasing problems can be serious for polygons
- Jaggedness of edges
- Small polygons neglected - Need compositing so color of one polygon does not
totally determine color of pixel
All three polygons should contribute to color
Anti-aliasing results:
sharp lines and triangles
What is Volume Rendering?
• The term volume rendering is used to describe techniques which allow the visualization of
three-dimensional data. Volume rendering is a technique for visualizing sampled functions of three spatial dimensions by computing 2-D
projections of a colored semitransparent volume.
• There are many example images to be found which illustrate the capabilities of ray casting.
These images were produced using IBM's Data Explorer: (left) Liver, (right) Vessels
Volume Rendering: result images
Ming’s brain vessels, MRI
How to calculate surface normal for scalar field?
• gradient vector
• D(i, j, k) is the density at voxel(i, j, k) in slice k
Marching cubes (squares)
Surface normal calculation for cube corners
• Gx (i, j, k) = ( D(i+1, j, k) – D(i-1, j, k))/2
• Gy (I, j, k) = (D (I, j+1, k) –D(I, j-1,k))/2
• Gz(I, j, k) = ((D(I, j, k+1) –D (I, j, k-1))/2
Marching Cubes Algorithm
Ray casting for volume rendering
• Theory
– Currently, most volume rendering that uses ray casting is based on the Blinn/Kajiya model. In this model we have a volume which has a density
D(x,y,z), penetrated by a ray R.
• Rays are cast from the eye to the voxel, and
the values of C(X) and (X) are "combined" into single values to provide a final pixel intensity.
Transparency formula
• For a single voxel along a ray, the standard transparency formula is:
where:
– Cout is the outgoing intensity/color for voxel X along the ray – Cinis the incoming intensity for the voxel
• Splatting for transparent objects: back to front rendering
– Eye Destination Voxel Source Voxel – Cd’= (1-αs) Cd +αs Cs
αd’= (1-αs) αd + αs
Cs : Color of source (background object color)
αs: Opaque index (opaque = 1.0, transparency = 0.0)
when background αs= 1.0, destination αd= 0.0, Cd’ = Cs, αd’ =αs,
similarly, when foreground (destination) is NOT transparent, αd= 1.0, Cd’ = Cd (color of itself)
i i i
in
out C x c x x
C 1
More details on transparency
Texture mapping
1. What is texture?
2. How to map a texture to an object surface?
<- : direction of mapping
pixel value = sum of weighted texels within the four corners mapped from a pixel
3. See pictures
3D Modeling Methods
• Creation of 3D objects
– Revolving – 3D polygon
– 3D mesh, 3D curves
– Extrusion from 2D primitives (set elevation in Z-axis) An example (new CS building construction)
(step bye step demo) of AutoCAD – Features that are useful
• VPOINT, LIMITS, LINE, BREAK, Elevation, SNAP, GRID, etc
– 3D digitizers
Driverless Car (LiDar etc.)
Curves and surfaces
• Used in airplanes, cars, boats
• Patch (補片)
How to model a teapot?
• How to get all the triangles for a teapot?
• What kind of curved surfaces?
• How to display (scan convert) these surfaces?
• What's the surface normal?
• Discuss ways to "define" a curved surfaces.
• Can we show an implicit surface equation easily?
e.g. f(x,y,z) = ax2 + by2 + cz2 + 2dxy + 2eyz + 2fxz + 2gx + 2hy + 2jz + k = 0
• Given (x,y), find z value
• Double roots, no real roots?
Curves and Surfaces
(Textbook Chap 11)• Topics
– Polygon meshes
– Parametric cubic curves
– Parametric bicubic surfaces – Quadric surfaces
Parametric cubic curves x(t) = axt3 + bxt2 + cxt + dx y(t) = ayt3 + byt2 + cyt + dy z(t) = azt3 + bzt2 + czt + dz
• Continuity conditions
– Geometric continuity (G0): join together – Parametric continuity (C1) (see below) – Cncontinuity: dn / dtn[Q(t)]continuous
(Curves) Geometry and drag equation
• In fluid dynamics, the drag equation is a formula used to calculate the force of drag experienced by an object due to movement through a fully enclosing fluid. The equation is:
• This equation is attributed to Lord Rayleigh, who originally used L2 in place of A (with L being some linear dimension).[2]
Form Drag
• Form drag or pressure drag arises because of
the shape of the object. The general size and shape of the body are the most important factors in form drag;
bodies with a larger presented cross-section will have a higher drag than thinner bodies; sleek ("streamlined") objects have lower form drag. Form drag follows
the drag equation, meaning that it increases with velocity, and thus becomes more important for high- speed aircraft.
• Form drag depends on the longitudinal section of the body. A prudent choice of body profile is essential for a low drag coefficient. Streamlines should be continuous, and separation of the boundary layer with its
attendant vortices should be avoided.
B'ezier Curve
Q'(0) = 3 (p1-p0) Q'(1) = 3 (p3-p2)
Why choosing "3" ?
Q(t) = (1-t)3p0 + 3t(1-t)2p1 + 3t2(1- t)p2 + t3p3 ...e.q.11.29
Bezier curve(2)
in matrix form T*MB*GB
Note: Q'(0) = -3(1-t)2p0 + 3(1-t)2p1|t=0 =3(p1-p0) if p1 - p4 is equally spaced, the curve Q(t) has
constant velocity! (that's why to choose 3)
Subdividing B'ezier curves
Advantage of B'ezier curves
1. explicit control of tangent vectors -->interactive design
2. easy subdivision
-->decompose into flat (line) segments
Subdividing B'ezier curves(2)
• new control points: pa, pb, pc, pe, pf,
• in addition to p1, p2, p3, p4
74
Splitting a Cubic Bezier
p0, p1 , p2 , p3 determine a cubic Bezier polynomial and its convex hull
Consider left half l(u) and right half r(u)
Angel and Shreiner: Interactive Computer Graphics 7E © Addison-
Wesley 2015
75
l(u) and r(u)
Since l(u) and r(u) are Bezier curves, we should be able to find two sets of control points {l0, l1, l2, l3} and {r0, r1, r2, r3} that determine them
Angel and Shreiner: Interactive Computer Graphics 7E © Addison-
Wesley 2015
76
Efficient Form
l0 = p0 r3 = p3
l1 = ½ (p0 + p1) r1 = ½ (p2 + p3)
l2 = ½ (l1 + ½ ( p1 + p2)) r1 = ½ (r2 + ½ ( p1 + p2)) l3 = r0 = ½ (l2 + r1)
Requires only shifts and adds!
Angel and Shreiner: Interactive Computer Graphics 7E © Addison-
Wesley 2015
77
Convex Hulls
{l0, l1, l2, l3} and {r0, r1, r2, r3}each have a convex hull that that is closer to p(u) than the convex hull of {p0, p1, p2, p3} This is known as the variation diminishing property.
The polyline from l0 to l3 (= r0) to r3 is an approximation
to p(u). Repeating recursively we get better approximations.
Angel and Shreiner: Interactive Computer Graphics 7E © Addison-
Wesley 2015
78
Every Curve is a Bezier Curve
• We can render a given polynomial using the recursive method if we find control points for its representation as a Bezier curve
• Suppose that p(u) is given as an interpolating curve with control points q
• There exist Bezier control points p such that
• Equating and solving, we find p=MB-1MA
p(u)=uTMAq
p(u)=uTMBp
Angel and Shreiner: Interactive Computer Graphics 7E © Addison-
Wesley 2015
Bezier
Pierre Etienne B’ezier Introduction
• Pierre Etienne Bezier was born on September 1, 1910 in Paris. Son and grandson of engineers, he chose this profession too and enrolled to study mechanical engineering at the Ecole des Arts et Metiers and received his degree in 1930. In the same year he entered the Ecole Superieure
d'Electricite and earnt a second degree in
electrical engineering in 1931. In 1977, 46 years later, he received his DSc degree in mathematics from the University of Paris.
In 1933, aged 23, Bezier entered Renault and worked for this company for 42 years
• Bezier's academic career began in 1968 when he became Professor of Production Engineering at the Conservatoire National des Arts et Metiers. He held this position until 1979. He wrote four books,
numerous papers and received several distinctions including the "Steven Anson Coons" of the
Association for Computing Machinery and the
"Doctor Honoris Causa" of the Technical University Berlin. He is an honorary member of the American Society of Mechanical Engineers and of the Societe Belge des Mecaniciens, ex-president of the Societe
des Ingenieurs et Scientifiques de France, Societe des Ingenieurs Arts et Metiers, and he was one of the first Advisory Editors of "Computer-Aided Design".
Parametric bicubic surfaces
Parametric bicubic surfaces
• First consider parametric cubic curve Q(t) = T*M*G
∴Q(s) = S*M*G
• To add the second dimension, G becomes G(t) Gi(t) = T*M*Gi, where Gi = [gi1, gi2, gi3, gi4]T
∴Parametric bicubic surfaces => S*M*G*MT*TT where S = [1, s, s2, s3]
T = [1, t, t2, t3]
Parametric bicubic surfaces (cont.)
• Therefore
– X(s, t) = S*M*Gx*MT*TT – Y(s, t) = S*M*Gy*MT*TT – Z(s, t) = S*M*Gz*MT*TT
• Normals to surfaces
How to calculate?
B'ezier surfaces
– X(s, t) = S*MB*GBx*MBT*TT – Y(s, t) = S*MB*GBy*MBT*TT – Z(s, t) = S*MB*GBz*MBT*TT
A typical Bezier Patch: with control points
ctrl_pts = [
[[0, 0, 20], [60, 0, -35], [90, 0, 60], [200, 0, 5]], [[0, 50, 30], [100, 60, -25], [120, 50, 120], [200, 50, 5]], [[0, 100, 0], [60, 120, 35], [90, 100, 60], [200, 100, 45]], [[0, 150, 0], [60, 150, -35], [90, 180, 60], [200, 150, 45]] ];
B'ezier patches display
• How to display B'ezier patches efficiently?
– Brute force iterative evaluation is very expensive Why? elaborate
– Subdivide into smaller polygons
need flatness test to stop subdivision – Adaptive subdivision is more practical
• How to avoid it?
Splines (
平滑曲線,樣條)
• A B-spline is a
generalization of the Bézier curve. Let a vector known as the knot vector be defined
where T is a nondecreasing sequence with ti [0, 1]
and define control points P0, ..., Pn . Define the degree as
The "knots" tp+1, ..., tm-p-1 are called internal knots.
t t tm
T 0, 1,...,
.
1
m n p
(1)
(2)
Splines
• Define the basis functions as
• Then the curve defined by is a B-spline.
N t
t t
t t t
t N t
t t t
N
otherwise
t t and t
t t t if
N
p i i
p i
p i p
i i p i
i p
i
i i i
i i
1 , 1 1
1 1 1
, ,
1 1
0
, 0
1
n
i
p i
iN t
P t
C
0
,
89
Every Curve is a Bezier Curve
• We can render a given polynomial using the recursive method if we find control points for its representation as a Bezier curve
• Suppose that p(u) is given as an interpolating curve with control points q
• There exist Bezier control points p such that
• Equating and solving, we find p=MB-1MI
q
p(u)=uTMIq
p(u)=uTMBp
Angel and Shreiner: Interactive Computer Graphics 7E © Addison-
Wesley 2015
Every segment of a curve (B-spline, etc.) can be defined as a Bezier curve: II
P(u) = uT Ms p (p is the control point vector of B-Spline)
P(u) = uT Mb q (q is the control point vector of Bezier curve)
Therefore q = Mb -1 Ms p (so the conversion is done)
Comparison of Bezier and B-spline curves
Bezier B-spline
About the difference between Bezier and cubic B-spline curve
1. Bezier curve will pass through the two end control points, while B spline does not.
2. Each B spline curve has a small segment defined, almost between the second and the third control points, and of course, will usually NOT pass through them.
3. Because of the limitation of 1 above, in order to have the specific starting point and end points, we let the first 4 control points the same.
Similarly, the last 4 control points are the same.
About the difference between Bezier and cubic B-spline curve II
4. The Bezier curve is C1 continuous, since the limitation of 1 above.
5. B-spline is designed to be C2 continuous, since it does not need to pass any control points.
6. However, one small segment of B-spline can be “simulated” by a Bezier curve, given new 4 control points, as proved below.
B-spline ( basis spline) :
for 4 control points, given B0, B1, B2, and B3 as the weighting function0 <= U <= 1.0
B-spline matrix: Bs,
with 4 control points PiCubic B-Spline Curve
• Cubic B-Spline Curve, C2 continuous
• P(u) = uTM p, where P is control points [pi-2, pi-1, pi, pi+1]T
• At first define it to be C2continuous, set up boundary conditions, and we can get
if u is defined as [1,u, u2, u3] in this order, P(u) = uTMS p
basis function = MsTu = (1/6) [ (1-u)3, 4-6u2+3u3, 1+3u+3u2-3u3, u3]T
1 3 3
1
0 3 6 3
0 3 0
3
0 1 4
1
6 Ms 1
Curve DEMO
• DEMO 1: Bezier curve
http://math.hws.edu/eck/cs424/notes2013/canvas/bezier.ht ml (connected curve)
http://blogs.sitepointstatic.com/examples/tech/canvas- curves/bezier-curve.html (basic curve)
DEMO 2: B-spline curve demo
https://www.cs.utexas.edu/~teammco/research/bsplines/
DEMO 3: Bezier , Bsline, NURBS DEMO
(note: manually add more control points)
Bezier Patch demo
• DEMO 3:
Youtube video:
https://www.youtube.com/watch?v=2tLC0oIbKS 0
DEMO 4: Bezier Surfaces (patch) http://www.ibiblio.org/e-
notes/Splines/bezier3d.html Fighter plane demo:
http://www.ibiblio.org/e-
notes/webgl/deflate/yf23.html
WebGL Interactive models
• http://www.ibiblio.org/e-
notes/webgl/models.htm#spline
• (including animated horse, fox, eagle, shark,
human elbow bones, and more static 3D models, such as bike, etc.)
DEMO 5: more control points for B-spline curve http://nurbscalculator.in/ (need to add more control points)(Q1: make the first three control
points to be at the same position, what happens?)
Ray tracing: Turner Whitted
• Key to success, from light to eye or from eye to screen?
Concept: how to win? (shooting ball game below)
The Rendering Equation: Jim Kajiya, 1986
(渲染方程式)
I(x, x’): light (intensity) from patch x’ to patch x g(x,x’): visibility geometry, o: invisible, 1: visible
e(x, x’): the rate at which light is emitted from patch x’ to x, when x’ is an emitter.
ρ (x, x’, x’’): patch’s reflectivity,
Definitions
• where
I(x, x’): light (intensity) from patch x’ to patch x g(x,x’): visibility geometry, o: invisible, 1: visible e(x, x’): the rate at which light is emitted from patch x’ to x, when x’ is an emitter.
ρ (x, x’, x’’): patch’s reflectivity, light from x’’ to x’
and the ratio reflected to x
Another detailed definition of the Rendering Equation
The rendering equation describes the total amount of light emitted from a point x along a particular viewing direction, given a function for incoming light and a BRDF.
Explanation
1. Conservation of energy.
2. Assuming that L denotes radiance, we have that at each particular position and direction, the outgoing light (Lo) is the sum of the emitted light (Le) and the reflected light.
3. The reflected light itself is the sum from all
directions of the incoming light (Li) multiplied by the surface reflection and cosine of the incident angle.
The Rendering Equation
Terminology
Radiance: 輻射, 光芒, light or heat that comes from something.
Illumination, 照明, light
Illuminance: 照度: 單位面積上的光通量,
單位: LUX, 1 LUX = 1 流明/平方米, Lumen (lm) :流明, luminous flux, 1 lm = 1 cd.sr,
1 cd: Candela, 燭光 (一瓦的白燈光, 約等於一燭光),
1 sr: steradian, 球面度, 立體角 (半徑 , 若張開的面積為 r2, 則角度為 1立體角, 1 sr)
Ray tracing(1)
Simple recursive ray tracing
Li: shadow ray Ri: reflected ray Ni: normal
Ti: transmitted ray whether
1. L1=R1+T1? or
2. f1(L1)=f(R1)+f(T1)? or 3. Color=f(L1,R1,T1 )
Shadow in ray tracing
Faster: ray tracing
• halfway vector
From known data to unknown
Ray Tracing Algorithm
Trace(ray)
For each object in scene Intersect(ray, object) If no intersections
return BackgroundColor For each light
For the object in scene
Intersect(ShadowRay, object) Accumulate local illumination Trace(ReflectionRay)
Trace(TransmissionRay)
Accumulate global illumination
Ray Tracing Algorithm
Code example: A simple ray tracer
• Author: Turner Whitted
– famous for his implementation of recursive ray tracer.
• Simplified version:
– input: quadric surfaces only
i.e. f(x,y,z)=ax2 + by2 + cz2 + 2dxy + 2eyz + 2fxz + 2gx + 2hy + 2jz + k = 0
– Shading calculation: as simple as possible
• Surface normal
[df/dx, df/dy, df/dz]
= [ 2ax+2dy+2fz+2g, 2by+2dx+2ez+2h, 2cz+2ey+2fx+2j ]
Sample program
Color trace_ray( Ray original_ray ) {
Color point_color, reflect_color, refract_color Object obj
obj = get_first_intersection( original_ray ) point_color = get_point_color( obj )
if ( object is reflective )
reflect_color = trace_ray( get_reflected_ray( original_ray, obj ) ) if ( object is refractive )
refract_color = trace_ray( get_refracted_ray( original_ray, obj ) ) return ( combine_colors( point_color, reflect_color, refract_color )) }
Code example: A simple ray tracer
• The simple ray tracer is complete and free to copy [need modification to be term project]
• Input surface properties
– r, g, b, relative_index_of_refraction, reflection_coef, transmission_coef, object_type
– number_of_objects, number_of_surfaces, number_of_properties
• How to calculate the intersection of a ray and a quadric surface?
Ray to quadric surface intersection
• intersection calculation:
– let direction=(Dx, Dy, Dz), origin=(Ox, Oy, Oz) line ==> (x,y,z)=(Ox, Oy, Oz) + t*(Dx, Dy, Dz) – quadric surface
f(x,y,z) = ax2 + by2 + cz2 + 2dxy + 2eyz + 2fxz + 2gx + 2hy + 2jz + k = 0
– replace (x,y,z) in (2) by (1),
acoef*t2 + bcoef*t + ccoef = 0, solve for t
• for example:
acoef = a*Dx2 + b*Dx*Dy + c*Dx*Dz + e*Dy2 + f*Dy*Dz + h*Dz2
(1)
(2)
Special notice:
1. Avoid to intersect a surface twice within a tiny triange
– e.g. t1=100, t2=100.001
– This may happen because of numeric percision
2. If a ray doesn't hit anything, give it a non-offensive background color, (20,92,192).
– This is the sky color(assume it is day time, of course).
– Otherwise, choose twilight or dark sky color.
3. How to modify this program to accept triangles?
Grid methods?
– Each grid center contains a pointer to the list of triangles which are(partly) contained in the grid.
Special notice:
4. Shading model
5. I I
N L
KS S KT T nj
j
a
1
• Ultimately, this yields the following pseudo code:
• For more info, please see my document Ray_Tracing.bw
Ray-object intersection acceleration
More about Ray-Tracing: Photon Mapping
• Photon mapping is a two-pass global
illumination rendering algorithm developed by Henrik Wann Jensen between 1995 and 2001[1] that approximately solves the rendering equation for integrating light radiance at a given point in space. Rays from the light source (like photons) and rays from the camera are traced independently until some termination criterion is met, then they are connected in a second step to
produce a radiance value.
• Progressive photon mapping (PPM) starts with ray tracing and then adds more and more photon mapping passes to provide a progressively more accurate render.
Photon Mapping: result
Global illumination using photon maps, EuroRendering 1996, by Henrik Wann Jensen
•
More about Ray-Tracing: Photon Mapping
Photon: A Modular, Research-Oriented Rendering System, Siggraph 2019 poster
Figure 1: Several visualization techniques implemented using the building blocks provided by our system. In the center, the buddha features Belcour’s BSDF model [Belcour 2018], while the left one, the glass brick induces caustics that can be rendered efficiently using particle tracing methods.
Radiosity (熱輻射法)
Donald Greenberg and Tomoyuki Nishita (1985)
What is Radiosity in Computer Graphics?
(DEMO)
Turner Whitted (
upper middle, ray tracing), Donald Greenberg(
lower right,radiosity)
129
Tomoyuki Nishita,
Rendering, 2011/11Steven Coons Award 2005, major Asian CG researcher
130
What is still missing in ray-traced images?
• Diffuse to diffuse reflection?
The Rendering Equation: Jim Kajiya, 1986
(渲染方程式)
I(x, x’): light (intensity) from patch x’ to patch x g(x,x’): visibility geometry, o: invisible, 1: visible
e(x, x’): the rate at which light is emitted from patch x’ to x, when x’ is an emitter.
ρ (x, x’, x’’): patch’s reflectivity,
134
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-
Wesley 2012
Rendering Equation: Another version
Consider light at a point p arriving from p’
i(p, p’) = υ(p, p’)(ε(p,p’)+ ∫ ρ(p, p’, p’’)i(p’, p’’)dp’’
occlusion = 0 or 1/d2 emission from p’ to p
light reflected at p’ from all points p’’ towards p
135
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-
Wesley 2012
Radiosity
• Consider objects to be broken up into flat patches (which may correspond to the
polygons in the model)
• Assume that patches are perfectly diffuse reflectors
• Radiosity = flux = energy/unit area/ unit time leaving patch
136
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-
Wesley 2012
Patches
Radiosity
A
kDefinitions
• where
Bi: B are the radiosity of patches i and j Ei: the rate at which light is emitted from patch i
Pi: patch i's reflectivity
Fji:formfactor (configuration factor ) , which specifies the fraction of energy leaving the patch j that arrives at patch i.
Ai, Aj areas of patch i and j.
Reciprocity in radiosity
(互換, 互惠)Total energy
passing through Ai and Aj should be the same!
(2)
(3)Simplified Eq from (1)
互惠 互惠
A
iA
j140
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-
Wesley 2012
Radiosity Equation
energy balance
b
ia
i= e
ia
i+ ρ
i∑ f
jib
ja
jreciprocity
f
ija
i= f
jia
jradiosity equation