Tải bản đầy đủ (.doc) (49 trang)

1 introduction to the theory of 3d computer graphics tủ tài liệu bách khoa

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (2.89 MB, 49 trang )

Dr. Manuel Carcenac - European University of Lefke

Introduction to the theory of
3D Computer Graphics
Geometric modeling of 3D objects
wireframe modeling
surface modeling: assembling surface primitives, parametric/implicit surfaces
volume modeling: assembling volume primitives, matrix of voxels

In depth: polynomial parametric curves and surfaces
Principle
Bezier curves and surfaces
B-spline curves and surfaces, NURBS

Light modeling
light representation
physical phenomena: reflection and refraction
estimating light intensities with Phong model
normal vector of a polygonal surface - Lambert, Gouraud, Phong methods

Rendering
Z buffer algorithm
ray tracing algorithm
ray marching algorithm for an implicit surface

Advanced rendering
global illumination problem
backward ray tracing
radiosity

Textures


2D textures, mapping, aliasing, anti-aliasing
3D textures

Procedural modeling
fractal landscape

Animation
principle - degrees of freedom of a scene
kinematic animation
dynamic animation
animation of articulated structures
1


Dr. Manuel Carcenac - European University of Lefke

References:
Advanced Animation and Rendering Techniques – Theory and Practice
Alan Watt, Mark Watt; Addison-Wesley, ACM press
/>
(for NURBS)

Numerical Recipes in C: The Art of Scientific Computing
William H. Press, Saul A. Teukolsky, William T. Vetterling, Brian P. Flannery;
Cambridge University Press (for Runge Kutta method)

2


Dr. Manuel Carcenac - European University of Lefke


Geometric modeling of 3D objects
how to represent an object ?
by a grid of lines

 wireframe modeling

by the surface which delimits it  surface modeling
by the volume it occupies

 volume modeling

Wireframe modeling
shared vertices
set of joined facets 
lines representing the facets' borders

only the lines are drawn  should we draw the lines corresponding
to the hidden parts of the surface ?

3


Dr. Manuel Carcenac - European University of Lefke

Surface modeling
surface primitive: = basic surface:

polygon (triangle, quadrangle)
sphere, spherical cap

disc, conical surface, cylindrical surface
polynomial parametric surface (Bezier, spline)

assembling surface primitives:
the actual surface of an object is an assembly of several surface primitives
 continuity constraints:


the resulting surface must be entirely closed
= C0 continuity at the edge between two joining primitives

if smooth surface requested, continuity of the surface normal
= C1 continuity at the edge between two joining primitives


eventually continuity of the curvature
= C2 continuity at the edge between two joining primitives


examples:
cube = assembly of 6 quadrangles  C0

half-sphere = spherical cap closed with a disk  C0

capsule: cylindrical surface closed with two spherical caps  C1

4


Dr. Manuel Carcenac - European University of Lefke


parametric representation of a surface primitive:
by varying parameters u and v, we cover the whole extent of the surface primitive:
1
v

V

N
v0
P

0

U
u0

0
u

1
 x  u, v  


coordinates of point P (u , v) of surface: P  u, v   y  u, v   ; u  I u , v  I v

 z  u, v  


tangent vectors to the surface at point P(u0 , v0):


normal vector at point P(u0 , v0) :

P  u 0 , v 0 



U
u
,
v

0
0

u

P  u 0 , v0 
 V  u 0 , v0  
v


N  u 0 , v0   U  u 0 , v0  V  u 0 , v0 
 N x  U x  V x  U y V z  U z V y 
 N   U  V   U V  U V 
x
z 
 y  y  y  z x
 N z  U z  V z  U x V y  U y V x 


N is used to compute the light intensity at point P
N is normalized at 1  N becomes a unit vector:

N 

N
N
5


Dr. Manuel Carcenac - European University of Lefke

parametric representation of a triangle:

P2
N

 P  u, v   P0  u  P1  P0   v  P2  P0 

u, v   0,1


u  v 1


V

v

U


P

P0

u
P1

data structures for a surface defined by a set of triangles:
array of vertices:

vertex[i] = { x , y , z }

array of triangles: triangle[j] = { iv0 , iv1 , iv2 }

P3

P2

parametric representation of a quadrangle:
N

V

v
P
P0

U


u
P1

 P  u, v  1  u  1  v  P0  u 1  v  P1  v 1  u  P2  u v P3

u, v   0,1


this surface may be twisted!

6


Dr. Manuel Carcenac - European University of Lefke

z

parametric representation of a cylinder:


 r cos u 

P  u, v   r sin u 




v




 u   0,2  v   hmin , hmax 

V
U

P
N
v

r

y

u

x
parametric representation of a sphere:

z
N


 r cos v cos u 

 r cos v sin u 


P
u

,
v





 r sin v 

 
 u   0,2  v    , 

 2 2

V

U

P
v

r

u

y

x

parametric representation of a disk:


z


 v cos u 

 P  u, v   v sin u 



 0 

 u   0,2  v   0, r 

N
u

v

U

P
x

V
7

y



Dr. Manuel Carcenac - European University of Lefke

implicit representation of a surface primitive:
a more compact mathematical definition than parametric representation:
P(x,y,z)  surface  implicit equation over position x,y,z:

f(x,y,z)=0

N
implicit representation of an unlimited plane:

C

P

CP N 0   x  xC  N x   y  yC  N y   z  zC  N z 0

implicit representation of a sphere:

dist  C , P  r   x  xC    y  yC    z  zC  r 2
2

2

implicit representation of an unlimited cylinder:

2

(axis: point C, unit vector K)


dist  axis, P  r  CP   CP K  K r

CP   CP K  K
r

P
N

K
C

8


Dr. Manuel Carcenac - European University of Lefke

Volume modeling
assembling volume primitives - Constructive Solid Geometry:
volume primitive: sphere, cylinder, conic, cube...
union, intersection and cut operators:





hierarchical combination of the operators:



9



Dr. Manuel Carcenac - European University of Lefke

volume modeling with 3D density field:
generalization of implicit equation f ( x , y , z ) = 0 for implicit surface:
0 < f(x,y,z)  1

 object with a partially transparent border:

1
0.9
0.4
0.1
0

10


Dr. Manuel Carcenac - European University of Lefke

volume modeling with matrix of voxels:
voxel = volume element

(pixel = picture element)

z

y


x

drawbacks:


huge memory required



totally impractical for the operator to initialize the voxels himself

 in general, the voxels are directly filled by raw data obtained from a sensing device
or resulting from a numerical simulation (fluid dynamics)

example: Medical Imagery

11


Dr. Manuel Carcenac - European University of Lefke

In depth: polynomial parametric curves
and surfaces
Principle
a set of control points is used to define the curve / surface
the curve or surface passes through a control point or is simply "attracted" by it

coordinates of a point of the curve / surface = weighted sum of the control points' coordinates
the weighting coefficients are polynomial functions of parameter u
or of parameters u, v (for a surface)


curve:

(for a curve)

n + 1 control points

i n

 P  u   Pi Fi  u 

i 0

u   0,1

surface: = patch

(n + 1)  (n + 1) control points

i n j n

 P  u, v    Pij Fi  u  F j  v 

i 0 j 0

u   0,1 v   0,1

if Fi (u) , Fj (v) polynomials are of degree m, the patches compounding a complex surface
can be adjusted so that continuity between them is Cm-1
in general, m = 3  continuity C2 = continuity of surface, normal and curvature


12


Dr. Manuel Carcenac - European University of Lefke

Bezier curves and surfaces
Bezier curves:
n+1 control points
the functions are of degree m = n
 a Bezier curve undergoes the global influence of all its control points
 the number of control points is very limited because
polynomials whose degree is too high are too cumbersome

i n

n


u
P
u

P

B

i
i


i 0

 0,1
u


 B n  u  C n u i 1  u  n  i
i
 i


example:

n
with Ci 

n!
i ! n  i  !

m = n = 3  4 control points
P1

 B03  u  1  u  3
 3
2
 B1  u  3u 1  u 
 3
2
 B2  u  3u 1  u 


B33  u  u 3

P2

P1-P0
P0

P3
P3-P2

u

the curve passes through P0 and P3
P1 and P2 help adjust the curve by warping it
P1 and P2 help define the curve tangents at P0 and P3

13


Dr. Manuel Carcenac - European University of Lefke

Bezier surfaces:
i n j n

 P  u, v   Pij Bin  u  B nj  v 

i 0 j 0

u   0,1 v   0,1


example:

m = n = 3  4  4 control points
P13
v

P02
P01

P03
P11

P12

P23
P22
P32

P21

P33

P31
P10

P20

P00
u


P30

it is difficult in practice to join together several Bezier patches
because of the continuity constraints

14


Dr. Manuel Carcenac - European University of Lefke

B-spline curves and surfaces, NURBS
B-spline curves:

Basis spline

n+1 control points
the functions are of degree m << n
 we can easily afford a huge number of control points
 a given point of the curve undergoes only the local influence
of the m+1 closest control points

i n

 P  u   Pi N im  u 

i 0

u   0,1

we want Cm-1 = C2 continuity constraint all along the curve

even though the polynomials are of limited degree
the B-spline curve is subdivided into n curve segments:
0 = u0 < u1 < ... < un-1 < un = 1
if values ui equally spaced 
else non-uniform B-spline

uniform B-spline

different weights associated to the control points 
else non-rational B-spline

rational B-spline

NURBS = Non-Uniform Rational Basis-Spline

15


Dr. Manuel Carcenac - European University of Lefke

m
the N i  u  polynomials are defined recursively:

N i0  u  1 if u   ui , ui 1  , 0 else

N im  u  

u  ui
u
 u

N im  1  u   i m 1
N im1 1  u 
ui  m  ui
ui m 1  ui 1

N im  u  is non null only within m + 1 segments

example:

cubic uniform B-spline (m = 3)

N i3  u 
1

u

i

u

i+1

u

i+2

u

i+3


u

u

i+4

B-spline surfaces:
i n j n

 P u , v    Pi j N im  u  N mj  v 

i 0 j 0

u   0,1 v   0,1

a point of the surface is influenced only by the (m + 1)  (m + 1) closest control points
16


Dr. Manuel Carcenac - European University of Lefke

Light modeling
Light representation
monochromatic

= only one wavelength

= one sinusoid function

in general, sum of many sinusoid functions with different wavelengths

in practice, only 3 wavelengths considered (the eye has only 3 types of photoreceptor cells)
 colors Red, Green, Blue

= 3 fundamental colors

computer screens usually display only the 3 fundamental colors
 3 parameters are needed to describe light
RGB space:
light intensities for Red , Green , Blue colors
= between 0 (no intensity) and 1 (maximal intensity that the screen can display)
R
 
light intensity: I G 
 B 

green scale
full green

 0
 1
 0




red  0 green  1 blue 0
 
 
 
0

1
 0

 0
1


black  0 white 1

 
1
0
 x
gray  x 
 
 x 

white
gray scale

full red
red scale

black
full blue
blue scale

with 0  x  1 (gray scale)

17



Dr. Manuel Carcenac - European University of Lefke

HLS space:
Hue:

color on the chromatic circle

Lightness:
Saturation:

dark to clear
gray to full color

= fraction (0 to 1) of pure color relative to gray

white

lightness
clear

gray scale
green

red
dull

saturation
hue


shiny

blue chromatic circle

dark

black

HLS space is a very convenient tool for the manual modeling of optical properties of surfaces
RGB space is used in computations

18


Dr. Manuel Carcenac - European University of Lefke

Physical phenomena: reflection and refraction
light travels through space undisturbed (if no fog ...)
but, when light touches an object, it can be either reflected or refracted
specular reflection:
one incident ray  only one reflected ray: reflection angle = incidence angle
ray

incident

normal




ray

reflected



we have a perfect specular reflection only with a mirror
diffuse reflection:
in practice, surfaces are not as flat and smooth as a mirror
many microscopic defaults (surface roughness) which scatter the reflected ray

one incident ray  infinity of reflected rays, in all directions of the semi-space
19


Dr. Manuel Carcenac - European University of Lefke

diverse types of reflecting surfaces:
unpolished surface:

wood, concrete, cloth, …

reflected light is constant in all directions

ray

incident

quasi mirror:


ray

incident

ray

reflected rays very close to specular reflection

incident

metallic surface:

mixture of diffuse and quasi specular reflection

20


Dr. Manuel Carcenac - European University of Lefke

refraction:
an incident ray enters a more or less transparent object and is transformed into a refracted ray
in practise, only specular refraction:

one incident ray  only one refracted ray

ray
refraction angle follows law ofincident
refraction:

sin r  ni


sin i  nr

normal



i

n

i

n
with ni , nr refraction indexes
(n=1 for air, n>1 inside object)

r



r

ray

refracted

if refraction index constant inside the object:
what matters are the entry and exit points of the ray (between them the ray does not vary)


if the two frontiers of the object are parallel:
the direction of light propagation remains globally unchanged (but there is a shift):

21


Dr. Manuel Carcenac - European University of Lefke

Estimating light intensities with Phong model
Phong model:

total light =

ambiant light
+ direct diffuse reflection light
+ direct specular reflection light

Figure courtesy
of Brad Smith, Wikipedia

important simplifications to allow fast light calculations:




only direct reflections  ambiant light is constant all over the scene
light source is punctual (eventually several punctual light sources)
no refraction (will be modeled with ray tracing)

diffuse reflection:

direct diffuse reflection:

the incident ray comes directly from the light source

direct reflection
Note: all indirect reflections globally yield the ambient light
= many interactions between surfaces (difficult to compute, requires radiosity)
light
 ambient light
is source
assumed constant over the whole scene…
indirect reflection
specular reflection:
direct specular reflection:

the incident ray comes directly from the light source

= simple reflection of the image of the light source over the surface
we must render the image of a light source that is not exactly punctual (else source not visible)
22


Dr. Manuel Carcenac - European University of Lefke

computing direct diffuse reflection light:
n

l direction to light source
n , l unit vectors




I d  K drefl cos   K drefl  n l 

l

 R K drefl qd 


I d   G K drefl qd  with qd n x l x  n y l y  n z l z
 B K drefl qd 



Note:

maximal when lighting normal to the surface
null when lighting tangent to the surface

computing direct specular reflection:
l direction to light source
e direction to virtual eye
ls dir. of specular reflection of light source
ls , e unit vectors

n

l

s



if light source were really punctual :
e eye
if e l s : total specular reflection
l


if e l s (even very slightly): no specular reflection at all  nothing visible
in practice, the light source to has a small size:
the more e is close to ls  the higher the specular reflection

 empirical formula:

I s  K srefl cos p     K srefl  e l s 

 R K srefl qs 


 I s   G K srefl qs  with q s  e x l sx  e y l sy  e z l sz
 B K srefl qs 







p


with p very big...

p

23


Dr. Manuel Carcenac - European University of Lefke

ambient light is constant:

I a  K amb

 R K amb 


  G K amb 
 B K amb 



computing total light:

I  K amb  K drefl  n l   K srefl  e l s 

p

 R K amb  RK drefl qd  RK srefl qs 
 G amb G refl


G
refl
 I   K  K d qd  K s qs 
 B K amb  BK drefl qd  BK srefl qs 


with

qd n x l x  n y l y  n z l z



q s  e x l sx  e y l sy  e z l sz

if several light sources (index i):



p



I K amb  K drefl   n l i   K srefl  e l si
i

i

24




p


Dr. Manuel Carcenac - European University of Lefke

Normal vector of a polygonal surface
- Lambert, Gouraud, Phong methods
surface made up of joined polygons
 how to give the illusion of a smooth surface?
Lambert method:
the normal is assumed constant over each polygon
very fast but crude: the polygons are clearly visible

Gouraud method:
the normal is given at each vertex between the polygons
 light intensity computed at the vertices
and interpolated over each point of the polygons
decent quality but costly because of the interpolations

Phong method:
the normal is given at each vertex between the polygons
 3 coordinates of normal directly interpolated
over each point of the polygons,
then light intensity computed at each point
excellent quality but very costly...
and the borders of the object still remain crude:

25



×