v2.0 zbrush

Transcription

v2.0 zbrush
Parametric Surfaces &
Tessellation
EDA 221
Michael Doggett
2016
Slides by Jacob Munkberg 2012-13
Today
• Parametric Surfaces
• Tessellation
• Interpolation
• Animation
EDA 221 - Computer graphics: Introduction to 3D
2
Parametric Surfaces
Creating objects
The xy-plane
y
• Implicit form
-
Defined by normal n = (0,0,1) and point
on plane Po = (0,0,0)
x
z
Point P on plane if
(P
Po ) · n
=
0
=
0
Pz
=
0
P · (0, 0, 1)
i.e., all points of the form
P = (x, y, 0)
EDA 221 - Computer graphics: Introduction to 3D
The xy-plane
y
• Explicit form
-
Map from R2 to R3
x
2
p(u, v) : R ! R
3
z
p(u, v) = (u, v, 0)
2
3
2
3
x(u, v)
u
4 y(u, v) 5 = 4 v 5
z(u, v)
0
EDA 221 - Computer graphics: Introduction to 3D
5
The xy-plane
y
p(u, v) = (u, v, 0)
• Tangent:
t=
@p
= (1, 0, 0)
@u
• Binormal:
b=
•
@p @p
n=
⇥
= (0, 0, 1)
@u
@v
Normal
direction
x
z
@p
= (0, 1, 0)
@v
EDA 221 - Computer graphics: Introduction to 3D
6
Height field - Zoneplate
• Explicit form
-
2
3
Map from R2 to R3
Defines a height value
for each (x,z) point
2
y
3
x(u, v)
u
4 y(u, v) 5 = 4 A(1 + cos(2⇡(u2 + v 2 ))) 5
z(u, v)
v
z
EDA 221 - Computer graphics: Introduction to 3D
x
7
Height field - Zoneplate
y
2
3
2
3
x(u, v)
u
4 y(u, v) 5 = 4 A(1 + cos(2⇡(u2 + v 2 ))) 5
z(u, v)
v
z
@p
= (1, 4A⇡u sin(2⇡(u2 + v 2 )), 0)
@u
@p
2
2
= (0, 4A⇡v sin(2⇡(u + v )), 1)
@v
2
3
4A⇡u sin(2⇡(u2 + v 2 ))
@p @p 4
5
1
n=
⇥
=
@u
@v
2
2
A4⇡v sin(2⇡(u + v ))
EDA 221 - Computer graphics: Introduction to 3D
x
8
Sphere
y
• Defined by a radius, r and
origin o = (ox, oy, oz)
-
Implicit form: Point P on sphere if
|P o| = r
Example: Unit sphere (r=1), centered at origin (o=(0,0,0)).
Let P = (x,y,z), then:
|P
z
x
o|
=
r
|P |
=
1
=
1
2
=
1
p
x2 + y 2 + z 2
2
2
x +y +z
EDA 221 - Computer graphics: Introduction to 3D
9
Sphere
• Defined by a radius, r and
origin o = (ox, oy, oz)
-
y
Sphe
(
Surface(
Implicit form: Point P on sphere if
|P o| = r
(
Tangent,(binormal(
Parametric definition:
z
2
3
r sin ✓ sin '
r cos ' 5
s(✓, ') = 4
r cos ✓ sin '
EDA 221 - Computer graphics: Introduction to 3D
x
10
Tessellation
• Construction of polygon meshes
-
From parametric representations
Example: Tessellating the zoneplate.
Evaluate parametric surface at many
positions
i j
(u, v) = ( , ), i = 0 . . . m, j = 0 . . . n
m n
EDA 221 - Computer graphics: Introduction to 3D
11
Mesh Topology
• Topology of the mesh
-
Vertices, faces and edges
defined by a grid
• Grid parameterization
-
Location of grid vertices
• Position of vertices
-
v
Evaluate parametric surface
function at each parametric
location of the grid
EDA 221 - Computer graphics: Introduction to 3D
u
12
s(⌅, ⇥) = (sin ⌅ cos ⇥, sin ⌅ sin ⇥, cos ⌅)
GridTopologies
topologies
Grid
•
⌅ ⇤ [0, ⇤], ⇥ ⇤ [0, 2⇤]
• The
simplest
topologyisisaa quad
quad (n x m)
The
simplest
topology
⇥
sin(⇤v) cos(2⇤u)
f (u, v) = ⇤ sin(⇤v) sin(2⇤u) ⌅
cos(⇤v)
•
i j
(u, v) = u
( ⇤
, [0,
), i1],
= 0v. . .⇤
m,[0,
j =1]0 . . . n
m n
Parameterization
i j
(u, v) = ( , ) : i = 0...n, j = 0...m
n m
Increasing m & n
EDA 2212
- Computer graphics: Introduction to 3D
13
Other
grid
topologies
Other grid topologies
web
Web
tube
Tube
capsule
Capsule
EDA 221 - Computer graphics: Introduction to 3D
14
An example
tessellating
a
An
example
tessellating
a
Tessellating
a
Sphere
An example
- tessellating a
sphere
sphere
sphere
x = 3y
x = 3y
2
x = 3y
2
2
a+b+c
a+b+c
a+b+c
xx=
3y
= 3y
capsule
capsule
grid grid
psule grid
x = 3y
22
mesh
mesh
f : R ⇥ R , f (u, v) = (u, v, 0)
mesh
⇥ R3 , f (u, v) = (u, v, 0)
2
f :2R2
2
3
3
f : R ⇥ R , f (u, v) = (u, v, 0)
s(⌅, ⇥) = (sin ⌅ cos ⇥, sin ⌅ sin ⇥, cos
s(⌅, ⇥) = (sin ⌅ cos ⇥, sin ⌅ sin ⇥, cos ⌅)
⌅⌅⇤sin
[0,⇥,
⇤],cos
⇥ ⇤⌅)
[0, 2⇤]
s(⌅, ⇥) = (sin
⌅ ⇤⌅
[0,cos
⇤], ⇥⇥,
⇤ sin
[0, 2⇤]
⌅ ⇤2[0, ⇤], ⇥ ⇤ [0, 2⇤] ⇥
parameterization
parameterization
parameterization
ameterization
EDA 221 - Computer graphics:
3
sin(⇤v) cos(2⇤u)
r sin(⇤v)
sin(2⇡u)
sin(⇡v)
cos(2⇤u)
⇤
sin(2⇤u)
f (u, v)4
f (u,
v) = ⇤ ⌅sin(⇤v)5sin(2⇤u)
r
cos(⇡v)
s(u, v)
= = sin(⇤v)
⇥
cos(⇤v)
cos(⇤v)
sin(⇤v)
cos(2⇤u)
r cos(2⇡u) sin(⇡v)
sin(⇤v)
f (u, v) =u ⇤
⇤ [0,
1], v ⇤ [0,sin(2⇤u)
1]u ⇤ [0, 1], v⌅⇤ [0, 1]
cos(⇤v)
position
position
position function
⇥
⌅
i j
(u, v) = ( , ) : i = 0...n, ji = j0...m
m 1],
(u,vv)⇤=[0,
( 1]
, ) : i = 0...n, j = 0...
u ⇤n [0,
functionnfunction
m
position
nfunction
m
x2
a+b
3
2
2
a +15
b
ix +j2x x x23
2
(u, v) = ( x2n
, ) : i = 0...n,
x
+j2x= 0...m
x
214
Introduction
to 3D
2n
3
23
Polygon Mesh
•
meshes
A mesh is a set ofPolygon
topologically
related
• A mesh is
a set of topologically
related planar
planar polygons.
Often
triangles.
polygons. Often triangles.
• Represented as:
-
List of vertices
Set of indices into vertex list
Vertices
0
v0=(0,0,0)
1
v1=(1,0,0)
2
v2=(0,1,0)
3
v3=(1,1,0)
• Represented as
Indices
– List of vertices
v2into vertex list v3
– Set of triplets of indices
Tri 0 : {0,1,2}
Tri 1 : {2,1,3}
v0
EDA 221 - Computer graphics: Introduction to 3D
v1
16
In practice : OBJ format
mtllib elephant.mtl
g default
v -1.809173 8.068286
v -1.711079 8.213382
v -1.687598 8.087677
v -1.742430 7.929831
...
vn
vn
vn
vn
....
-0.896939
-0.877770
-0.913599
-0.935617
vertex positions
-6.605641
-6.732996
-6.827210
-6.708415
-0.062018 -0.437782
-0.046475 -0.476823
0.085210 -0.397587
-0.033324 -0.351440
normals
faces
f 1/1/1 2/2/2 3/3/3 4/4/4
f 2/2/2 5/5/5 6/6/6 3/3/3
index to f 3/3/3 6/6/6 7/7/7 8/8/8
(vertex/texcoords/normal)
f 4/4/4 3/3/3 8/8/8 9/9/9
f 10/10/10 11/11/11 12/12/12 13/13/13
f 11/11/11 14/14/14 15/15/15 12/12/12
f 12/12/12 15/15/15 1/1/1 16/16/16
f 13/13/13 12/12/12 16/16/16 17/17/17
....
f 2541/2501/2541 11092/10988/11092 11422/11318/11422 11372/11268/11372
f 11092/10988/11092 1590/1570/1590 7674/7573/7674 11422/11318/11422
f 11422/11318/11422 7674/7573/7674 7673/7572/7673 11421/11317/11421
f 11372/11268/11372 11422/11318/11422 11421/11317/11421 2562/2522/2562
EDA 221 - Computer graphics: Introduction to 3D
17
•
Construction
of
polygo
How to create meshes?
– From point clouds - i.e.
• Modeling packages
-
Maya, 3D Studio Max, ZBrush, MudBox
-
i.e., 3D scan data
• From point clouds,
• This course only covers mesh
construction from simple parametric
– From abstract represen
surfaces
-
Feel free to import your own meshes in Labs!
center: (5,2,3)
radius: 14
EDA 221 - Computer graphics: Introduction to 3D
18
llatingTriangulation
a
faces
• Create triangles from mesh
c
d
x = 3y
2
a+b+c
a
b
Tri[i] = {a,b,c}, Tri[i+1] : {b,d,c}
x = 3y
2
Counter clock-wise by convention
Winding order determines front and back faces
f :R
2
mesh
⇥ R , f (u, v) = (u, v, 0)
3
EDA 221 - Computer graphics: Introduction to 3D
19
Backface Culling
• Remove triangles facing away from
the camera
Backface
culled
EDA 221 - Computer graphics: Introduction to 3D
Occlusion
culled
20
Backface Culling
• Remove triangles facing away from
the camera
• Saves computations
Backfacing if
n
v
n·v <0
EDA 221 - Computer graphics: Introduction to 3D
21
Transforming Normals
• Can’t transform normals as
other vectors and points
-
Example: Non-uniform scaling
0
v =

3 0
0 1
v
0
v = Mv
EDA 221 - Computer graphics: Introduction to 3D
22
Transforming Normals
• Exploit that the tangent and normal
should be perpendicular before and
after transform, i.e., n · t = 0
n·t=0
0
0
n ·t =0
Tangent is difference between two points on
surface - transforms as surface points
EDA 221 - Computer graphics: Introduction to 3D
23
Transforming Normals
• Tangent
-
Transformed with the
matrix M same as used for points and vectors
0
t = Mt
• Normal
-
Transformed with an
unknown matrix Q
0
0
n = Qn
0
Exploit n · t = 0
EDA 221 - Computer graphics: Introduction to 3D
24
Transforming Normals
• Exploit
0
=
0
0T 0
n t
=
0
T
(Qn) (Mt)
=
0
nT (QT M)t
=
0
n·t = 0
QT M = I , Q = (M
Use (M
= Mt
n = Qn
n·t=0
n 0 · t0 = 0
0
n ·t
0
t
0
1 T
)
1 T
) to transform normals!
EDA 221 - Computer graphics: Introduction to 3D
25
Transforming Normals
• Return to our non-uniform
0
v =
scaling example:
0
n =
M=

3 0
0 1
M
1
= (M
1 T
) =

EDA 221 - Computer graphics: Introduction to 3D
1
3


0
3 0
0 1
1
3
0
0
1
0
1
26
v
n
Animating Objects
• We know how to position objects
• We know how to move objects
• How to move objects smoothly from A
to B over time?
EDA 221 - Computer graphics: Introduction to 3D
27
Key-frame Animation
• The animator positions the object at a
set of times - the key frames, then the
software interpolates between frames
EDA 221 - Computer graphics: Introduction to 3D
28
Path Following
• Define path by a point list
• Interpolate points in-between
Linear
interpolation
Cubic
interpolation
EDA 221 - Computer graphics: Introduction to 3D
29
Linear Interpolation
pi+1
pi-1
pt
t
pi+2
pi
t)pi + tpi+1 , t 2 [0, 1]


1 0
pi
pt = [1 t]
1 1
pi+1
pt = (1
EDA 221 - Computer graphics: Introduction to 3D
30
Example (Linear)
pi+1
pi-1
pi+2
pi
EDA 221 - Computer graphics: Introduction to 3D
31
Example (Cubic)
pi+1
pi-1
pi+2
pi
EDA 221 - Computer graphics: Introduction to 3D
32
Example (Cubic)
pi+1
pi-1
pi+2
pi
Use tangent information
to specify curve segment
EDA 221 - Computer graphics: Introduction to 3D
33
Cubic Hermite Interpolation
•
Given two points and
corresponding tangents:
0
0
p
,
p
and
p
,
p
0
1
0
1
we want to find a cubic
curve
2
p(t) = c0 + c1 t + c2 t + c3 t
p’0
p0
y
p1
p’1
x
z
3
• Task at hand: Find
coefficients ci.
EDA 221 - Computer graphics: Introduction to 3D
34
Cubic Hermite Interpolation
•
Create system of
equations
2
p(t) = c0 + c1 t + c2 t + c3 t
p’0
3
p0
y
p1
p’1
x
p0
=
p(0) = c0
p1
=
p(1) = c0 + c1 + c2 + c3
p00
=
p0 (0) = c1
0
p1
=
z
0
p (1) = c1 + 2c2 + 3c3
EDA 221 - Computer graphics: Introduction to 3D
35
Cubic Hermite Interpolation
•
Write in matrix form
2
2
6
6
4
p’0
3
p(t) = c0 + c1 t + c2 t + c3 t
3 2
32
1 0 0 0
c0
p0
6 1 1 1 1 7 6 c1
p1 7
7
6
7
6
=
0 5
4 0 1 0 0 5 4 c2
p0
0 1 2 3
c3
p01
q = Mc
y
p0
3
7
7
5
p’1
p1
x
z
q = Mc , c = M
EDA 221 - Computer graphics: Introduction to 3D
1
q
36
Cubic Hermite Interpolation
•
2
6
6
4
2
Write on matrix form
p(t) = c0 + c1 t + c2 t2 + c3 t3
3 2
32
1 0 0 0
c0
p0
6 1 1 1 1 7 6 c1
p1 7
7
6
7
6
=
p00 5 4 0 1 0 0 5 4 c2
0 1 2 3
c3
p01
3
2
c0
1
6 c1 7 6 1
6
7=6
4 c2 5 4 0
c3
0
0
1
1
1
0
1
0
2
3
0
1 7
7
0 5
3
1
2
3
2
y
p’0
3
7
7
5
p0
1
6 p1 7 6 0
6 0 7=6
4 p0 5 4 3
p01
2
p1
p0
p’1
x
z
0
0
3
2
0
1
2
1
EDA 221 - Computer graphics: Introduction to 3D
32
3
0
p0
6 p1 7
0 7
76 0 7
1 5 4 p0 5
1
p01
37
Cubic Hermite Interpolation
2
p(t) = c0 + c1 t + c2 t
2
c0
6
2 3 6 c1
p(t) = [1 t t t ] 4
c2
c3
+ c3 t
3
1
6
2 3 6 0
p(t) = [1 t t t ] 4
3
2
0
0
3
2
2
T
p(t) = t M
1
q
3
p’0
7
7
5
y
p1
p0
p’1
x
0
1
2
1
z
32
3
0
p0
6 p1 7
0 7
76 0 7
1 5 4 p0 5
1
p01
EDA 221 - Computer graphics: Introduction to 3D
38
Linear vs Cubic
Linear
interpolation
pt = [1 t]

1 0
1 1

pi
pi+1
Cubic
interpolation
2
1
6
2 3 6 0
p(t) = [1 t t t ] 4
3
2
0
0
3
2
0
1
2
1
32
3
0
p0
6 p1 7
0 7
76 0 7
1 5 4 p0 5
1
p01
EDA 221 - Computer graphics: Introduction to 3D
39
Smoothstep
• Useful special (1D) case of cubic
interpolation
-
performs smooth Hermite interpolation between
0 and 1 when a < x < b.
-
Useful in cases where a threshold function with a
smooth transition is desired.
-
Tangents : 0 at x=a and 0 at x=b
x
a
b
EDA 221 - Computer graphics: Introduction to 3D
40
Smoothstep
float smoothstep(float x, float a, float b)
{
float t = clamp((x-a)/(b-a),0,1);
return t*t*(3-2*t);
}
Derive formula!
x
a
b
EDA 221 - Computer graphics: Introduction to 3D
41
How to specify tangents?
•
One simple solution:
pi-1
pi
0
pi
⇡
pi+1
pi
1
2
0
pi
pi-2
pi+1
EDA 221 - Computer graphics: Introduction to 3D
pi+2
42
Catmull-Rom Splines
of points, define tangents
• Given a set
p
p
as:
-
0
pi
⇡
i+1
i 1
2
Curve segment between pi and pi+1 completely
defined by pi-1, pi, pi+1 and pi+2
pi-1
pi
0
pi
pi-2
pi+1
EDA 221 - Computer graphics: Introduction to 3D
pi+2
43
Catmull-Rom Splines
p0
p1
0
p1
=
p2
p0
2
p(t)
p2
0
p2
Four conditions:
2
3
2
p(0)
6 p(1) 7 6
6 0
7=6
4 p (0) 5 4
p0 (1)
0
0
1/2
0
1
0
0
1/2
=
p3
p1
p3
2
32
3
0
0
p0
6 p1 7
1
0 7
76
7
1/2 0 5 4 p2 5
0 1/2
p3
EDA 221 - Computer graphics: Introduction to 3D
44
Catmull-Rom Splines
• Tangent def. gives four conditions
2
3
2
p(0)
6 p(1) 7 6
6 0
7=6
4 p (0) 5 4
p0 (1)
-
0
0
1/2
0
32
1
0
0
1/2
3
0
0
p0
6 p1 7
1
0 7
76
7
1/2 0 5 4 p2 5
0 1/2
p3
q = Np
Insert in Hermite formula:
T
p(t) = t M
2
0
6
1
1
1
6
M N= 4
2
2
1
1
T
q=t M
2
0
5
3
0
1
4
3
1
3
Np
0
0 7
7 Wrong in book!!!
1 5
1
EDA 221 - Computer graphics: Introduction to 3D
45
Catmull-Rom Splines
parameter 𝜏:
• If we addp a=tension
⌧ (p
p ), ⌧ 2 [0, 1]
0
i
i+1
i 1
the Catmull-Rom spline can be
generalized to:
2
0
6 ⌧
2 3 6
p(t) = [1 t t t ] 4
2⌧
⌧
1
0
⌧ 3 3
Tension(
2 ⌧ ⌧
0
⌧
2⌧
2
32
3
0
pi 1
6 pi 7
0 7
76
7
⌧ 5 4 pi+1 5
⌧
pi+2
low(
high(
EDA 221 - Computer graphics: Introduction to 3D
46
Animate Colors
• Other attributes than position can be
animated
-
Example: animate green color channel, G = 255*t
R=255
G=0
B=0
R=255
G=255
B=0
t=0
t=1
EDA 221 - Computer graphics: Introduction to 3D
47