10 Graphics
Transcript of 10 Graphics
-
8/13/2019 10 Graphics
1/373
Chapter 10:
Mathematical Topics from 3DGraphics
Ian ParberryUniversity of NorthTexas
Fletcher DunnValve Software
3D Math Primer for Graphics & Game Development
-
8/13/2019 10 Graphics
2/373
What ou!ll "ee in This Chapter
This chapter #iscusses a number of mathematical issues that arise $hen creatin% 3D%raphics on a computer& It is #i'i#e# into ele'en sections& "ection 10&1 #iscusses the ren#erin% e(uation& "ection 10&) intro#uces the math of 'ie$in% in 3D& "ection 10&3 re'ie$s coor#inate spaces an# transforms& "ection 10&* loo+s at representin% %eometry& "ection 10&, is about material properties& "ection 10&- #iscusses the stan#ar# li%htin% mo#el& "ection 10&. loo+s at some common li%ht sources& "ection 10&/ e amines s+eletal animation& "ection 10& intro#uces bump mappin%& "ection 10&10 is on the %raphics pipeline& "ection 10&11 %i'es some e amples of pi el an# 'erte sha#ers that implement some of
the techni(ues co'ere# in this chapter&
Chapter 10 2otes 3D Math Primer forGraphics Game De'
)
-
8/13/2019 10 Graphics
3/373
Wor# Clou#
Chapter 10 2otes 3D Math Primer forGraphics Game De'
3
-
8/13/2019 10 Graphics
4/373
"ection 10&1:
4o$ Graphics Wor+s
Chapter 10 2otes 3D Math Primer forGraphics Game De'
*
-
8/13/2019 10 Graphics
5/373
The 5en#erin% 6(uation 5en#erin% ans$ers the (uestion: 7For each pi el on the screen8 $hat is its
color9 That is8 7What color of li%ht is approachin% the camera from the #irection
correspon#in% to this pi el9
There are t$o cases to consi#er&1& 6ither $e are loo+in% #irectly at a li%ht source8 an# li%ht tra'ele# #irectly from it to
our eye8 or ;more commonlyor reflecte# off of this surface in the#irection of the eye&
Chapter 10 2otes 3D Math Primer forGraphics Game De'
,
-
8/13/2019 10 Graphics
6/373
?isible "urface Determination
There are ) common solutions to thisproblem&
1 !ay tracin" : Follo$ li%ht rays bac+$ar#s& # Depth $%fferin" : @lso +no$n as '$%fferin"
More ne tA
Chapter 10 2otes 3D Math Primer forGraphics Game De'
-
-
8/13/2019 10 Graphics
7/373
5ay Tracin% 5ather than follo$in% li%ht rays in the #irection that they tra'el from
the emissi'e surfaces8 $e trace the rays bac+$ar#s8 so that $e can#eal only $ith the li%ht rays that matter: the ones that enter our eyefrom the %i'en #irection&
We sen# a ray out from the eye in the #irection throu%h the centerof each pi el to see the first obBect in the scene this ray stri+es& Then $e compute the color that is bein% emitte#>reflecte# from that
surface bac+ in the #irection of the ray&
Chapter 10 2otes 3D Math Primer forGraphics Game De'
.
-
8/13/2019 10 Graphics
8/373
Depth uffer
Depth buffer is a solution to the occl%sion pro$lem : fi%urin% $hich trian%les are in front of $hich&
Depth buffer has the same resolution as thescreen&
For each pi el x y E8 the correspon#in% #epth
buffer entry x E y E stores the #epth of the pi el& sually the ( coor#inate in clip space is use# H
hence the name ('$%ffer &
Chapter 10 2otes 3D Math Primer forGraphics Game De'
/
-
8/13/2019 10 Graphics
9/373
Depth uffer sa%e
@t the start of each frame8 initiali e the#epth buffer to some far #istance ;in clipspace this is 1&0
-
8/13/2019 10 Graphics
10/373
For$ar# an# Deferre#5en#erin% @t this point $e mi%ht also procee# to step ) of the ren#erin% al%orithm ;at least for this pi el< an#
up#ate the frame buffer $ith the color of the li%ht bein% emitte# or reflecte# from the surface thatpoint& This is +no$n as forwar) ren)erin" &
Deferre) ren)erin" is an ol# techni(ue that is becomin% popular a%ain #ue to the current locationof bottlenec+s in the types of ima%es $e are pro#ucin% an# the har#$are $e are usin% to pro#ucethem&
@ #eferre# ren#erer uses8 in a##ition to the frame buffer an# the #epth buffer8 a##itional buffers8collecti'ely +no$n as the G'$%ffer ;short for "eometry $%ffer
-
8/13/2019 10 Graphics
11/373
=i%htin%
What Color is That NbBect9 It #epen#s on the color of the reflecte# li%ht& More e actly8 it #epen#s on the fre(uency #istribution
of the reflecte# li%ht& It is calle# the $i)irectional reflectance )istri$%tion
f%nction8 or 5DF for short8 %i'en by:
Chapter 10 2otes 3D Math Primer forGraphics Game De'
11
-
8/13/2019 10 Graphics
12/373
5DF
The 'alue of this function tells $hat fraction of the li%ht inci#ent atthe point x from #irection is reflecte# in the out%oin% #irection
@s in#icate# by the boldface an# hat8 O mi%ht be a unit 'ector8but more %enerally it can be any $ay of specifyin% a #irectionK
polar an%les mi%ht be another choice& Different colors of li%ht are usually reflecte# #ifferently8 hence the
#epen#ence on Q8 $hich is the color ;actually8 the $a'elen%th Rmore on this in a moment< of the li%ht&
Chapter 10 2otes 3D Math Primer forGraphics Game De'
1)
-
8/13/2019 10 Graphics
13/373
-
8/13/2019 10 Graphics
14/373
""DF
@ shiny surface reflects inci#ent li%ht much more stron%ly in one particular #irection compare#to others8 $hereas a #iffuse surface scatters li%ht more e'enly across all out%oin% #irections&
@ perfect reflector $oul# reflect all the li%ht from one incomin% #irection in a sin%le out%oin%
#irection8 $hereas a perfectly #iffuse surface $oul# reflect li%ht e(ually in all out%oin%#irections8 re%ar#less of the #irection of inci#ence& More complicate# phenomena can be e presse# by %enerali in% the 5DF sli%htly& Translucence an# li%ht refraction can be easily incorporate#8 simply by allo$in% the #irection
'ectors to point bac+ into the surface& We mi%ht call this mathematical %enerali ation a bi#irectional s%rface scatterin% #istribution
function ; ""DF
-
8/13/2019 10 Graphics
15/373
The 2ormali ation Constraintan# 4elmholt 5eciprocity There are criteria that a 5DF must satisfy in or#er to be physically plausible& For
e ample8 it #oesn!t ma+e sense for a ne%ati'e amount of li%ht to be reflecte# in any#irection&
@lso8 it!s not possible for more li%ht to be reflecte# than is inci#ent8 althou%h thesurface may absorb some ener%y so less li%ht may be reflecte# than is inci#ent& Thisis usually calle# the normali(ation constraint &
@ less ob'ious principle obeye# by physical surfaces is *elmholt( reciprocity : if $epic+ t$o arbitrary #irections8 the same fraction of li%ht shoul# be reflecte#8 no matter
$hich is the inci#ent #irection an# $hich is the out%oin% #irection& In other $or#s8
In some boo+s an# papers you may see 5DF!s $here the t$o #irections are notlabele# as 7in an# 7out 8 assumin% 4elmholt reciprocity&
Chapter 10 2otes 3D Math Primer forGraphics Game De'
1,
-
8/13/2019 10 Graphics
16/373
The =i%htin% 6(uation
More #etail on the ne t sli#eA
Chapter 10 2otes 3D Math Primer forGraphics Game De'
1-
-
8/13/2019 10 Graphics
17/373
The =i%htin% 6(uation
Chapter 10 2otes 3D Math Primer forGraphics Game De'
1.
-
8/13/2019 10 Graphics
18/373
More on the Tric+y Inte%ral
"ymbol
appears $here $e normally $oul# $rite the limits of inte%ration& Thisis inten#e# to mean 7sum o'er the hemisphere of possible incomin% #irections& For each incomin% #irection 8 $e #etermine ho$ much ra#iance $as inci#ent
in this incomin% #irection an# %ot scattere# in the out%oin% #irection The sum of all these contributions from all the #ifferent inci#ent #irections %i'es
the total ra#iance reflecte# in the #irection In the real ;continuous< $orl# this is an inte%ral& In the 'irtual ;#iscrete< $orl#8 this $ill be a summation&
Chapter 10 2otes 3D Math Primer forGraphics Game De'
1/
-
8/13/2019 10 Graphics
19/373
More on the Tric+y Inte%ral
Chapter 10 2otes 3D Math Primer forGraphics Game De'
1
-
8/13/2019 10 Graphics
20/373
More on the Tric+y Inte%ral
The first term #enotes the ra#iance inci#ent from the #irection of The next term is simply the 5DF8 $hich tells us ho$ much of the ra#iance inci#ent
from this particular #irection $ill be reflecte# in the out%oin% #irection $e care about& Finally8 $e ha'e the Lambert term 8 $hich accounts for the fact that more inci#ent
li%ht is a'ailable to be reflecte#8 per unit surface area8 $hen is perpen#icular tothe surface than $hen at a %lancin% an%le to the surface& The 'ector is the out$ar# facin% surface normal8 an# the #ot pro#uct
pea+s at 1 in the perpen#icular #irection8 an# trails off to ero as the an%le ofinci#ence becomes more %lancin%& More about this term later&
Chapter 10 2otes 3D Math Primer forGraphics Game De'
)0
-
8/13/2019 10 Graphics
21/373
5en#erin% as an Inte%ral6(uation The #ifficulty of ren#erin% comes from the fact the ren#erin% e(uation is an
inte%ral e(uation: it states a relationship bet$een some un+no$n function+out the #istribution of li%ht on the surfaces in the scene8 in terms of itso$n inte%ral&
It mi%ht not be apparent that the ren#erin% e(uation is recursi'e8 but +outactually appears on both si#es of the L!&
It appears in the e'aluation of +in8 $hich is precisely the e pression $e setout to sol'e for each pi el: What is the ra#iance inci#ent on a point8 from a%i'en #irection9
Thus to fin# the ra#iance e itin% a point x8 $e nee# to +no$ all thera#iance inci#ent at from all #irections&
ut the ra#iance inci#ent on x is the same as the ra#iance lea'in% from allother surfaces 'isible to x8 in the #irection pointin% from the other surfaceto$ar#s x&
Chapter 10 2otes 3D Math Primer forGraphics Game De'
)1
-
8/13/2019 10 Graphics
22/373
5en#erin% as an @ppro imation
To ren#er a scene realistically8 $e must sol'e the ren#erin%e(uation8 $hich re(uires us to +no$ ;in theory< not only thera#iance arri'in% at the camera8 but the entire #istribution ofra#iance in the scene in e'ery #irection at e'ery point&
Clearly this is too much to as+ for a finite8 #i%ital computer8 sinceboth the set of surface locations an# the set of potential inci#entan# e itin% #irections are infinite&
The real art in creatin% soft$are for #i%ital ima%e synthesis is toallocate the limite# processor time an# memory most efficiently8 inor#er to ma+e the best possible appro imation&
Chapter 10 2otes 3D Math Primer forGraphics Game De'
))
-
8/13/2019 10 Graphics
23/373
-
8/13/2019 10 Graphics
24/373
"ection 10&):
?ie$in% in 3D
Chapter 10 2otes 3D Math Primer forGraphics Game De' )*
-
8/13/2019 10 Graphics
25/373
"pecifyin% the Nutput Win#o$
We #on!t ha'e to ren#er to the entire screen& For e ample8 in split screen multiplayer %ames8
each player is %i'en a portion of the screen& Can ren#er to a file or to a te ture& The o%tp%t win)ow is the portion of the output
#e'ice $here our ima%e $ill be ren#ere#&
Chapter 10 2otes 3D Math Primer forGraphics Game De' ),
-
8/13/2019 10 Graphics
26/373
"creen Coor#inates
5ecall that coor#inates start $ith ;08 0< at thetop left of the screen8 U y %oes #o$n8 U x %oesacross&
;winPosx 8winPosy < is the top left corner of theoutput screen in screen coor#inates&
)ev!esx an# )ev!esy are the #imensions of the
#e'ice in pi els& win!esx an# win!esy are the #imensions of the
$in#o$ in pi els&
Chapter 10 2otes 3D Math Primer forGraphics Game De' )-
-
8/13/2019 10 Graphics
27/373
Chapter 10 2otes 3D Math Primer forGraphics Game De' ).
-
8/13/2019 10 Graphics
28/373
Pi el @spect 5atio
The ratio of a pi el!s hei%ht to its $i#th& Function of the #e'ice physical si e resolution & "i e #oesn!t matter H it!s the ratio that matters&
Chapter 10 2otes 3D Math Primer forGraphics Game De' )/
-
8/13/2019 10 Graphics
29/373
Physical "i e of the De'ice
The 'ie$able area on most monitors has aratio of *:3&
@nother common ratio is 1-: on hi%h#efinition tele'isions an# D?Ds&
For e ample8 on a stan#ar# *:3 monitor8many common resolutions ha'e s(uarepi el ratiosK 3)0 )*08 -*0 */08 /00 -008 10)* .-/8 an# 1-00 1)00&
Chapter 10 2otes 3D Math Primer forGraphics Game De' )
-
8/13/2019 10 Graphics
30/373
The Frustum
The view fr%st%m is the 'olume of space that is'isible to the camera&
"hape# li+e pyrami# $ith tip snippe# off& The 'ie$ frustum is boun#e# by si planes8
+no$n as the clip planes & top 8left 8$ottom 8 an# ri"ht planes
near clip plane : pre'ents obBects from %ettin% too closeto the camera far clip plane : far obBects e'entually %et too small to
ren#er effecti'ely an# can be clippe# entirely&
Chapter 10 2otes 3D Math Primer forGraphics Game De' 30
-
8/13/2019 10 Graphics
31/373
Chapter 10 2otes 3D Math Primer forGraphics Game De' 31
-
8/13/2019 10 Graphics
32/373
Camera Properties
Position Nrientation Fiel# of 'ie$ oom @ctually8 the last t$o are interrelate#&
Chapter 10 2otes 3D Math Primer forGraphics Game De' 3)
-
8/13/2019 10 Graphics
33/373
Fiel# of ?ie$
The fiel# of 'ie$ is thean%le intercepte# by the'ie$ frustum&
@bbre'iation: fov & @ctually8 $e nee# both
a hori ontal an# a
'ertical fo' an%le& 6%& 4ori ontal fo' is
sho$n here&
Chapter 10 2otes 3D Math Primer forGraphics Game De' 33
-
8/13/2019 10 Graphics
34/373
oom
oom measures the ratio of the apparent si e ofthe obBect relati'e to a 0 fo'&
=ar%er numbers oom in& "maller numbers oomout&
For e ample8 a oom of )&0 means that the obBect $ill appear t$ice as bi% on screen as $ith a 0
fo'& @ oom of 1&0 means a fo' of 0 & Fo' oom e(uation:
Chapter 10 2otes 3D Math Primer forGraphics Game De' 3*
-
8/13/2019 10 Graphics
35/373
Chapter 10 2otes 3D Math Primer forGraphics Game De' 3,
-
8/13/2019 10 Graphics
36/373
3D ooms
In 3D8 $e nee# t$o #ifferent oom 'alues8one for the hori ontal an# one for the'ertical&
We can choose any t$o arbitrary 'alues8but if $e #o not maintain a properrelationship bet$een the hori ontal an#'ertical oom8 then the ren#ere# ima%e
$ill appear stretche#&
Chapter 10 2otes 3D Math Primer forGraphics Game De' 3-
-
8/13/2019 10 Graphics
37/373
oom 5atio
In the formula on the ne t sli#e: (oom refers to the cameraVs oom 'alues& winPhys refers to the physical $in#o$ si e& win!es refers to the resolution of the $in#o$8 in pi els& pixPhys refers to the physical #imensions of a pi el& )evPhys refers to the physical #imensions of the output
#e'ice& 5emember that $e usually #onVt +no$ thein#i'i#ual si es8 but $e #o +no$ the ratio&
)ev!es refers to the resolution of the output #e'ice&
Chapter 10 2otes 3D Math Primer forGraphics Game De' 3.
-
8/13/2019 10 Graphics
38/373
Chapter 10 2otes 3D Math Primer forGraphics Game De' 3/
-
8/13/2019 10 Graphics
39/373
"pecifyin% FN? or ooms
Many ren#erin% pac+a%es allo$ you to specifythe camera usin% only one fiel# of 'ie$ an%le ;oroom 'alue
-
8/13/2019 10 Graphics
40/373
Nrtho%raphic ProBection
We intro#uce# ortho%raphic proBection in Chapter ,8 but tobriefly re'ie$8 in ortho%raphic proBection8 the lines of proBectionare parallel8 rather than intersectin% at a sin%le point&
There is no perspecti'e foreshortenin% in ortho%raphic
proBectionK an obBect $ill appear the same si e on the screen nomatter ho$ far a$ay it is8 an# mo'in% the camera for$ar# orbac+$ar#s alon% the 'ie$in% #irection has no apparent effectso lon% as the obBects remain in front of the near clip plane&
Chapter 10 2otes 3D Math Primer forGraphics Game De' *0
-
8/13/2019 10 Graphics
41/373
Perspecti'e ProBection
2otice that $ithperspecti'eproBection8 parallellines #o not remainparallel8 an# thecloser %ri# s(uares
are lar%er than theones in the #istance&
Chapter 10 2otes 3D Math Primer forGraphics Game De' *1
-
8/13/2019 10 Graphics
42/373
Nrtho%raphic ProBection
Chapter 10 2otes 3D Math Primer forGraphics Game De' *)
With ortho%raphicproBection8 the %ri#lines remain parallelan# the %ri# s(uaresare all the samesi e &
-
8/13/2019 10 Graphics
43/373
Nrtho%raphic Fo'
For an ortho%raphic proBection8 it ma+es no sense to spea+ ofthe fiel# of 'ie$ as an an%le8 since the 'ie$ frustum is shape#li+e a bo 8 not a pyrami#&
5ather than #efinin% the x an# y #imensions of the 'ie$frustum usin% t$o an%les8 $e instea# %i'e t$o si es: thephysical $i#th an# hei%ht of the bo &
The oom 'alue has a #ifferent meanin% in ortho%raphicproBection compare# to perspecti'e&
It is relate# to the physical si e of the frustum bo : (oom L )>si(e
si(e L )> (oom
Chapter 10 2otes 3D Math Primer forGraphics Game De' *3
-
8/13/2019 10 Graphics
44/373
-
8/13/2019 10 Graphics
45/373
"ection 10&3:
Coor#inate "paces
Chapter 10 2otes 3D Math Primer forGraphics Game De' *,
-
8/13/2019 10 Graphics
46/373
-
8/13/2019 10 Graphics
47/373
@ 2e$ Coor#inate "pace
Clip space& @ @ canonical view vol%me space & The matri that transforms 'ertices from camera
space into clip space is +no$n as the clip matrix & The clip matri ser'es t$o primary functions:
Copy ( into w so that the homo%enous #i'ision by w
performs a perspecti'e proBection& & "cale x 8 y 8 an# ( so that they can be compare# a%ainst
w for clippin%&
Chapter 10 2otes 3D Math Primer forGraphics Game De' *.
-
8/13/2019 10 Graphics
48/373
4omo%enous ?ectors @%ain
5ecall that a *D homo%enous 'ector ismappe# to the correspon#in% physical 3D'ector by #i'i#in% by w :
Chapter 10 2otes 3D Math Primer forGraphics Game De' */
-
8/13/2019 10 Graphics
49/373
ProBection 5e'isite#
Nne %oal of the clip matri is to %et the ri%ht'alue into w so that the proper proBection occurs&
We +no$ ho$ to proBect onto a planeperpen#icular to the ( a is an# ) units a$ayfrom the ori%in ;the plane ( L ) &w ta+es on the 'alues H1 an# U1 at the nearan# far clip planes8 respecti'ely&
Chapter 10 2otes 3D Math Primer forGraphics Game De' -)
-
8/13/2019 10 Graphics
63/373
Nrtho%raphic Clip Matrices
The clip matri is as follo$s8 $ith the DirectZ'ersion on the ri%ht:
Chapter 10 2otes 3D Math Primer forGraphics Game De' -3
-
8/13/2019 10 Graphics
64/373
NpenG= ?ersions
NpenG= has a left han#e# coor#inatesystem an# column 'ectors& 4ence the clipmatrices are a follo$s8 perspecti'e on theleft an# ortho%raphic on the ri%ht&
Chapter 10 2otes 3D Math Primer forGraphics Game De' -*
-
8/13/2019 10 Graphics
65/373
The 2ear Clip Plane
2o$ that $e +no$ a bit about clip space8 $e can un#erstan#the nee# for the near clip plane&
There is a sin%ularity precisely at the ori%in8 $here aperspecti'e proBection is not #efine#8 correspon#in% to a#i'ision by ero in the perspecti'e #i'i#e&
In practice8 this sin%ularity $oul# be e tremely rare an# $ecan +lu%e it by arbitrarily proBectin% the point to the center ofthe screen8 since puttin% the camera #irectly in a poly%on
isnVt often nee#e# in practice&
Chapter 10 2otes 3D Math Primer forGraphics Game De' -,
-
8/13/2019 10 Graphics
66/373
N'erflo$ 5is+ $ith w ut Bust proBectin% poly%ons onto pi els isnVt the only issue& @llo$in%
for arbitrarily small ;but positi'e< 'alues of ( $ill result in arbitrarilylar%e 'alues for w &
Depen#in% on the har#$are8 this can cause problems $ithperspecti'e correct rasteri ation&
@nother potential problem area is #epth bufferin%& For practical reasons it is necessary to restrict the ran%e of the (
'alues so that there is a +no$n minimum 'alue8 an# $e mustaccept the rather unpleasant necessity of a near clip plane&
Chapter 10 2otes 3D Math Primer forGraphics Game De' --
-
8/13/2019 10 Graphics
67/373
"creen "pace
Nnce $e ha'e clippe# the %eometry to the 'ie$frustum8 it is proBecte# into screen space8 $hichcorrespon#s to actual pi els in the frame buffer&
5emember that $e are ren#erin% into an output $in#o$ that #oes not necessarily occupy the entire#isplay #e'ice&
4o$e'er8 $e usually $ant our screen spacecoor#inates to be specifie# usin% coor#inates thatare absolute to the ren#erin% #e'ice&
Chapter 10 2otes 3D Math Primer forGraphics Game De' -.
-
8/13/2019 10 Graphics
68/373
ProBectin% to "creen "pace We must proBect the points from clip space to screen space to %enerate
the correct )D coor#inates& The first thin% that happens is the homo%enous #i'ision by w & ;NpenG=
calls the result of this #i'ision the normali(e) )evice coor)inates &< Then8 the x an# y coor#inates must be scale# to map into the output
$in#o$ as follo$s ;see ne t sli#e for #efinitions&
Chapter 10 2otes 3D Math Primer forGraphics Game De' -/
-
8/13/2019 10 Graphics
69/373
Chapter 10 2otes 3D Math Primer forGraphics Game De' -
-
8/13/2019 10 Graphics
70/373
ut screeny has a Minus "i%n @ (uic+ $or# about the ne%ation of the y component in the math ) sli#es a%o& This reflects a DirectZ style
coor#inate con'ention $here ;080< is in the upper left corner& n#er these con'entions8 U y points up in clip space8 but #o$n in screen space& In fact8 if $e continue to
thin+ about U ( pointin% into the screen8 then screen space actually becomes a ri%ht han#e# coor#inatespace8 e'en thou%h itVs left han#e# e'ery$here else in DirectZ&
In NpenG=8 the ori%in is in the lo$er left corner8 an# the ne%ation of the y coor#inate #oes not occur& @s $as alrea#y #iscusse#8 in NpenG=8 they choose a #ifferent place to intro#uce confusion8 by flippin% the
( a is bet$een eye space $here H points into the screen8 to clip space $here U ( points into the screen&
Chapter 10 2otes 3D Math Primer forGraphics Game De' .0
-
8/13/2019 10 Graphics
71/373
w bufferin% "pea+in% of ( 8 $hat happens to clip( 9 The precise #etails can 'ary8 but in
%eneral itVs use# in some $ay for #epth bufferin%& @ tra#itional metho# is to ta+e the normali e# #epth 'alue clip( >clipw an# store
this 'alue in the #epth buffer& @n alternati'e strate%y8 +no$n as w bufferin% is to use clipw as the #epth 'alue&
In most situations clipw is simply a scale# 'ersion of the camera space ( 'alue8an# thus by usin% clipw in the #epth buffer8 each 'alue has a linear relationshipto the 'ie$in% #epth of the correspon#in% pi el&
This metho# can be attracti'e if the #epth buffer is fi e# point $ith limite#precision8 because it sprea#s out the a'ailable precision more e'enly&
Chapter 10 2otes 3D Math Primer forGraphics Game De' .1
-
8/13/2019 10 Graphics
72/373
w bufferin% The tra#itional metho# of storin% clip( >clipw in the #epth buffer results in %reatly
increase# precision up close8 at the e pense of ;sometimes #rastically< re#uce# precisionnear the far clip plane&
The precise #etails $ill #epen# on e actly $hat sort of clip 'alues are use# for clippin%8an# $hat sort of #epth 'alues %o into the #epth buffer& For e ample8 in NpenG=8 theconceptual con'ention is for the 'ie$ frustum to contain H1 Y clip( >clipw Y 18 but this
mi%ht not be optimal for #epth bufferin%& Dri'er 'en#ors must con'ert from the @PIVsconceptual con'entions to $hate'er is optimal for the har#$are& If the #epth buffer 'alues are store# in floatin% point8 this issue is much less important& @lso note that this #oesnVt $or+ for ortho%raphic proBection8 since an ortho%raphic
proBection matri al$ays outputs w L 1&
Chapter 10 2otes 3D Math Primer forGraphics Game De' .)
-
8/13/2019 10 Graphics
73/373
Nther ses for clipw The clipw 'alue is usually not #iscar#e#& It ser'es the important purpose as the #enominator in the
homo%enous #i'ision to normali e# #e'ice coor#inates& It is also nee#e# for proper perspecti'e correct interpolation of te ture
coor#inates8 colors8 an# other 'erte le'el 'alues #urin% rasteri ation& Nn mo#ern %raphics @PIs at the time of this $ritin%8 the con'ersion of
'erte coor#inates from clip space to screen space is #one for you&our 'erte sha#er $ill output coor#inates in clip space& The @PI $illclip the trian%les to the 'ie$ frustum8 an# then proBect the coor#inates
to screen space& ut that #oesnVt mean that you $ill ne'er use the e(uations in your
co#e& [uite often $e nee# to perform these calculations in soft$arefor 'isibility testin%8 le'el of #etail selection8 etc&
Chapter 10 2otes 3D Math Primer forGraphics Game De' .3
-
8/13/2019 10 Graphics
74/373
More Coor#inate "paces
There are more spaces that are use# in computer %raphics& For e ample8 a proBecte# li%ht mi%ht ha'e its o$n space8
$hich is essentially the same as camera space8 only it isfrom the perspecti'e that the li%ht loo+s onto the scene&
This space is important $hen the li%ht proBects an ima%e;sometimes calle# a "o$o 8 $e!ll return to this later
-
8/13/2019 10 Graphics
75/373
Tan%ent "pace Tan"ent space is a local space on the surface of an obBect8 $ith one
basis 'ector the surface normal8 an# the other t$o basis 'ectorslocally tan%ent to the surface&
This establishes a )D coor#inate space that is flat on the surface at a%i'en spot&
y far the most common reason to establish such a coor#inate spaceis for bump mappin% an# relate# techni(ues&
More on this $hen $e co'er te ture mappin% later& Tan%ent space is sometimes calle# s%rface'local space &
Chapter 10 2otes 3D Math Primer forGraphics Game De' .,
-
8/13/2019 10 Graphics
76/373
Chapter 10 2otes 3D Math Primer forGraphics Game De'
.-
-
8/13/2019 10 Graphics
77/373
"ection 10&*:
Trian%le Meshes
Chapter 10 2otes 3D Math Primer forGraphics Game De'
..
-
8/13/2019 10 Graphics
78/373
C"G
Constructi'e soli# %eometry ;C"G< is asystem for #escribin% an obBects shapeusin% oolean operators ;union8
intersection8 subtraction< on primiti'es& Within 'i#eo %ames8 C"G can be
especially useful for rapi# prototypin%tools8 $ith the nreal en%ine bein% anotable e ample&
Chapter 10 2otes 3D Math Primer forGraphics Game De'
./
-
8/13/2019 10 Graphics
79/373
Metaballs Meta$alls are use# to mo#el or%anic shapes an# flui#s& @ three #imensional scalar #ensity function is #efine# surroun#in% each
ball base# on the #istance to the center& y summin% the #ensity o'er all the balls8 $e can #efine an a%%re%ate
#ensity function for any arbitrary point in space& The tric+ to metaballs is that the 'olume of the obBect is #efine# to be
the re%ion $here the #ensity e cee#s some non ero threshol#& Thus balls ha'e a fu y re%ion aroun# them that e ten#s outsi#e of
the 'olume $hen the ball is in isolation& When t$o or more balls come to%ether8 the fu y re%ions interfere
constructi'ely8 causin% a %raceful bon# of soli# 'olume to materiali e inthe re%ion in bet$een the balls8 $here no such soli# $oul# e ist ifeither ball $ere there alone&
Chapter 10 2otes 3D Math Primer forGraphics Game De'
.
-
8/13/2019 10 Graphics
80/373
Trian%le Meshes C"G8 metaballs8 an# other 'olumetric #escriptions are 'ery useful in particular realms8 but for
ren#erin% ;especially real time ren#erin%< $e are intereste# in a #escription of the surface of theobBect8 an# sel#om nee# to #etermine $hether a %i'en point is insi#e or outsi#e this surface&In#ee#8 the surface nee# not be close# or e'en #efine a coherent 'olume&
The most common surface #escription is the poly"on mesh & In certain circumstances itVs useful to allo$ the poly%ons that form the surface of the obBect to
ha'e an arbitrary number of 'erticesK this is often the case in importin% an# e#itin% tools& For real time ren#erin%8 ho$e'er8 mo#ern har#$are is optimi e# for trian"le meshes 8 $hich are
poly%on meshes $here e'ery poly%on is a trian%le&
Chapter 10 2otes 3D Math Primer forGraphics Game De'
/0
-
8/13/2019 10 Graphics
81/373
-
8/13/2019 10 Graphics
82/373
Trian%le Mesh Information
For some applications this tri'ial representation mi%htbe a#e(uate&
4o$e'er8 the term mesh implies connecti'ity bet$eena#Bacent trian%les8 an# this connecti'ity is note presse# in our tri'ial representation&
There are three basic types of information in a trian%lemesh:
1& ?ertices)& 6#%es
3& Faces
Chapter 10 2otes 3D Math Primer forGraphics Game De'
/)
f
-
8/13/2019 10 Graphics
83/373
Trian%le Mesh Information
1. Vertices & 6ach trian%le has e actly three 'ertices& 6ach 'erte may beshare# by multiple trian%les& The valence of a 'erte refers to ho$many faces are connecte# to the 'erte &
2. Edges & @n e#%e connects t$o 'ertices& 6ach trian%le has three e#%es&In many cases8 each e#%e is share# by e actly t$o faces8 but thereare certainly e ceptions& If the obBect is not close#8 an open e#%e $ithonly one nei%hborin% face can e ist&
3. aces & These are the surfaces of the trian%les& We can store a face aseither a list of three 'ertices8 or a list of three e#%es&
Chapter 10 2otes 3D Math Primer forGraphics Game De'
/3
l h
-
8/13/2019 10 Graphics
84/373
Trian%le Mesh
@nin)exe) trian"le mesh consists of t$o lists: a list of 'ertices8 an# a listof trian%les& 6ach 'erte contains a position in 3D& We may also store other information at the 'erte le'el8 such te ture
mappin% coor#inates8 surface normals8 or li%htin% 'alues& @ trian%le is represente# usin% three in#ices into the 'erte list& sually
the or#er that these 'ertices are liste# is si%nificant8 since $e mayconsi#er faces to ha'e a front an# a bac+ si#es&
We $ill a#opt the con'ention that the 'ertices are liste# in cloc+$ise
or#er $hen 'ie$e# from the front si#e& Nther information may also be store# at the trian%le le'el8 such as a
precompute# normal of the plane containin% the trian%le8 surfaceproperties ;such as a te ture map
-
8/13/2019 10 Graphics
85/373
?erte "tructure
Chapter 10 2otes 3D Math Primer forGraphics Game De'
/,
-
8/13/2019 10 Graphics
86/373
T i %l M h "
-
8/13/2019 10 Graphics
87/373
Trian%le Mesh "tructure
Chapter 10 2otes 3D Math Primer forGraphics Game De'
/.
6 l
-
8/13/2019 10 Graphics
88/373
6 ample
4ere is ho$ a cube an# a pyrami# mi%ht be represente# as apoly%on mesh or a trian%le mesh& 2ote that in either case8 it is a
sin%le mesh $ith 13 'ertices& The li%hter8 thic+er $ires sho$ theoutlines of poly%ons8 an# the %reen $ires sho$ one $ay to a##a##itional e#%es to trian%ulate the poly%on mesh&
Chapter 10 2otes 3D Math Primer forGraphics Game De'
//
6 l ? C #i
-
8/13/2019 10 Graphics
89/373
6 ample: ?erte Coor#inates
@ssumin% the ori%in is on the %roun##irectly in bet$een the t$o obBects8these mi%ht be the 'erte coor#inates&
Chapter 10 2otes 3D Math Primer forGraphics Game De'
/
6 l M h T bl
-
8/13/2019 10 Graphics
90/373
6 ample Mesh Table
The table on the ne t sli#e sho$s the 'erte in#ices that $oul# form faces of this mesh8 either as a poly%on mesh8 oras a trian%le mesh&
2ote that the or#er of the 'ertices is si%nificant& While the 'ertices must be liste# in cloc+$ise or#er aroun#
a face8 it #oesnVt matter $hich one is consi#ere# first 'erte Kthey can be cycle# $ithout chan%in% the lo%ical structure ofthe mesh&
For e ample8 the (ua# formin% the cube top coul#e(ui'alently been %i'en as:
\18 )8 38 0]8 \)8 38 08 1]8 or \38 08 18 )]&
Chapter 10 2otes 3D Math Primer forGraphics Game De'
0
-
8/13/2019 10 Graphics
91/373
Chapter 10 2otes 3D Math Primer forGraphics Game De'
1
I l t ti 2 t
-
8/13/2019 10 Graphics
92/373
Implementation 2otes
@##itional #ata is almost al$ays store# per 'erte 8 such as te ture coor#inates8surface normals8 basis 'ectors8 colors8 s+innin% #ata8 etc&
@##itional #ata can also be store# at the trian%le le'el8 such as an in#e that tells $hich material to use for that face8 or the plane e(uation for the face& This is hi%hlyuseful for e#itin% purposes or in other tools that perform mesh manipulations&
For real time ren#erin%8 ho$e'er8 $e sel#om store a##itional #ata at the trian%lele'el& In fact8 its 'ery common to not ha'e a struct Triangle at all8 an# simplyrepresent the entire list of trian%les as an array li+e unsigned short [] 8 $herethe len%th of the array is the number of trian%les times three&
Trian%les $ith i#entical properties are %roupe# into batches so that an entire batchcan be fe# to the GP in this optimal format&
We recommen# that you #on!t try to use the same mesh class for both ren#erin%an# e#itin%& The re(uirements are 'ery #ifferent8 an# a bul+ier #ata structure $ithmore fle ibility is best for use in tools etc&
Chapter 10 2otes 3D Math Primer forGraphics Game De'
)
I l t ti 2 t
-
8/13/2019 10 Graphics
93/373
Implementation 2otes
2ote that in an in#e e# trian%le mesh8 the e#%es are not store# e plicitly8 but ratherthe a#Bacency information containe# in an in#e e# trian%le list is store# implicitly: tolocate share# e#%es bet$een trian%les8 $e must search the trian%le list&
Nur ori%inal tri'ial 7array of trian%les format #i# not ha'e any lo%ical connecti'ityinformation&
Chapter 10 2otes 3D Math Primer forGraphics Game De'
3
4o$e'er8 $hat!s surprisin% is that the 7e tra connecti'ity informationcontaine# in the in#e e# representation actually results in a re#uction ofmemory usa%e in most cases8 compare# to the flat metho#&
The reason for this is that the information store# at the 'erte le'el8 $hich is#uplicate# in the tri'ial flat format8 is relati'ely lar%e compare# to a sin%leinte%er in#e & ;@t the minimum8 $e most store a 3D 'ector position&
-
8/13/2019 10 Graphics
94/373
Implementation 2otes
The simple in#e e# trian%le mesh scheme is appropriate for many simple applications8inclu#in% the 'ery important one of ren#erin%&
4o$e'er8 some operations on trian%le meshes re(uire a more a#'ance# #ata structure inor#er to be implemente# more efficiently&
The basic problem is that the a#Bacency bet$een trian%les is not e presse# e plicitly an#must be e tracte# by searchin% the trian%le list&
Nther representation techni(ues ma+e this information a'ailable in constant time& Nne i#ea is to maintain an e#%e list e plicitly&
6ach e#%e is #efine# by listin% the t$o 'ertices on the en#s& We also maintain a list of trian%les that share the e#%e& Then the trian%les can be 'ie$e# as a list of three e#%es rather than a list of three 'ertices8 so that
they are store# as three in#ices into the e#%e list rather than the 'erte list& @n e tension of this i#ea is +no$n as the win"e) e)"e mo)el 8 $hich also stores8 for each
'erte 8 a reference to one e#%e that uses the 'erte & The e#%es an# trian%les may betra'erse# intelli%ently to (uic+ly locate all e#%es an# trian%les that use the 'erte &
Chapter 10 2otes 3D Math Primer forGraphics Game De'
*
" f # ? t 2 l
-
8/13/2019 10 Graphics
95/373
"urface an# ?erte 2ormals
@s%rface normal is a unit 'ector that is perpen#icular to a surface& We mi%ht be intereste# in the normal of a %i'en face8 in $hich case the surface $e
are intereste# in is the plane that contains the face& The surface normals for poly%ons can be compute# easily usin% cross pro#uct of
t$o si#es& Care must be ta+en to %et the #irection ri%ht&
?erte le'el normals are a bit tric+ier& First8 it shoul# be note# that strictly spea+in% there is not a true surface normal at
a 'erte ;or an e#%e for that matter< since these locations mar+ #iscontinuities inthe surface of the poly%on mesh&
5ather8 for ren#erin% purposes $e typically interpret a poly%on mesh as anappro imation to some smooth surface&
Chapter 10 2otes 3D Math Primer forGraphics Game De'
,
-
8/13/2019 10 Graphics
96/373
What to Do9
-
8/13/2019 10 Graphics
97/373
What to Do9
If har#$are resources permit8 then $e can appro imate the normal of thecontinuous surface correspon#in% to any point on a %i'en face by interpolatin%'erte normals an# renormali in% the result&
This is illustrate# belo$: a cross section of a cylin#er ;blac+ circle< is bein%appro imate# by a he a%onal prism ; blue
-
8/13/2019 10 Graphics
98/373
Gourau# an# Phon% "ha#in%
Nnce $e ha'e a normal at a %i'en point8 $e can performthe full li%htin% e(uation per pi el&
This is +no$n as per'pixel sha)in" 8 orPhon" sha)in" & @n alternate strate%y to per pi el sha#in%8 +no$n as
Go%ra%) sha)in" 8 is to only perform li%htin% calculationsat the 'erte le'el8 an# then interpolate the resultsthemsel'es8 rather than the normal8 across the face&
This re(uires less computation8 an# is still #one on somesystems such as the 2inten#o Wii&
Chapter 10 2otes 3D Math Primer forGraphics Game De'
/
Phon% "ha#in%
-
8/13/2019 10 Graphics
99/373
Phon% ha#in%
4ere is per pi el li%htin% of cylin#ers $ith #ifferent numbers of si#es& @lthou%h the illusion brea+s #o$n on the en#s of the cylin#er8 this metho# of appro imatin% a
smooth surface can ma+e e'en a 'ery lo$ resolution mesh loo+ smooth& Co'er up the en#s of the cylin#er8 an# e'en the , si#e# cylin#er is remar+ably con'incin%&
Chapter 10 2otes 3D Math Primer forGraphics Game De'
ac+ to ?erte 2ormals
-
8/13/2019 10 Graphics
100/373
ac+ to ?erte 2ormals
If the mesh is %enerate# proce#urally8 for e ample from aparametric cur'e# surface8 then the 'erte normals can besupplie#&
Nr you may simply be han#e# the 'erte normals from the
mo#elin% pac+a%e as part of the mesh& 4o$e'er8 sometimes the surface normals are not pro'i#e#8
an# $e must appro imate them by interpretin% the onlyinformation a'ailable to us: the 'erte positions an# thetrian%les&
Nne tric+ that $or+s is to a'era%e the normals of the a#Bacenttrian%les8 an# then re normali e the result8 as follo$s&&
Chapter 10 2otes 3D Math Primer forGraphics Game De'
100
-
8/13/2019 10 Graphics
101/373
Chapter 10 2otes 3D Math Primer forGraphics Game De'
101
-
8/13/2019 10 Graphics
102/373
Chapter 10 2otes 3D Math Primer forGraphics Game De'
10)
-
8/13/2019 10 Graphics
103/373
Chapter 10 2otes 3D Math Primer forGraphics Game De'
103
@ Gotcha
-
8/13/2019 10 Graphics
104/373
@ Gotcha
@'era%in% face normals to compute 'erte normals is a trie#an# true techni(ue that $or+s $ell in most cases& 4o$e'er8 there are a fe$ thin%s to $atch out for8 as this
picture sho$s&
Chapter 10 2otes 3D Math Primer forGraphics Game De'
10*
"ometimes the mesh is suppose# to ha'e a #iscontinuity8 an# if $e!re not careful8 this #iscontinuity coul# %et smoothe# out&
Ta+e the 'ery simple e ample of a bo & There shoul# be a sharp
li%htin% #iscontinuity at its e#%es& 4o$e'er8 if $e use 'erte normals compute# from the a'era%e of thesurface normals8 then there is no li%htin% #iscontinuity&
Detachin% Faces
-
8/13/2019 10 Graphics
105/373
Detachin% Faces
The basic problem is that the surface #iscontinuity at the bo e#%es cannot beproperly represente# because there is only one normal store# per 'erte & The solution to this problem is to )etach the facesK in other $or#s8 #uplicate the
'ertices alon% the e#%e $here there is a true %eometric #iscontinuity& In #oin% so8 $e create a #iscontinuity to pre'ent the 'erte normals from bein%
a'era%e#& @t this point8 the faces are no lon%er lo%ically connecte#8 but this seamin the topolo%y of the mesh #oesn!t cause a problem for many important tas+ssuch as ren#erin% an# ray tracin%&
2e t8 cubes $ith $el#e# 's& #etache# facesA
Chapter 10 2otes 3D Math Primer forGraphics Game De'
10,
Cube $ith Wel#e# Faces
-
8/13/2019 10 Graphics
106/373
Cube $ith Wel#e# Faces
Chapter 10 2otes 3D Math Primer forGraphics Game De'
10-
Cube $ithDetache#
-
8/13/2019 10 Graphics
107/373
Chapter 10 2otes 3D Math Primer forGraphics Game De'
10.
Detache#Faces
illboar#s
-
8/13/2019 10 Graphics
108/373
illboar#s
@n e treme 'ersion of this situation occurs $hen t$o faces are place# bac+ tobac+8 $hich is calle# a $ill$oar) & "uch infinitely thin #ouble si#e# %eometry can arise $ith folia%e an# cloth& In this case8 since the normals are e actly opposite8 a'era%in% them pro#uces the
ero 'ector8 $hich cannot be normali e#&
The simplest solution is to #etach the faces so that the 'erte normals $ill nota'era%e to%ether& Nr if the front an# bac+ si#es are mirror ima%es8 the t$o sin%le si#e# poly%ons can
be replace# by one #ouble si#e# one& This re(uires special treatment #urin% ren#erin% to #isable bac+face cullin% ;more
later< an# #ealin% $ith the normal intelli%ently in the li%htin% e(uation&
Chapter 10 2otes 3D Math Primer forGraphics Game De'
10/
When n$ei%hte# @'era%in% is Wron%
-
8/13/2019 10 Graphics
109/373
When n$ei%hte# @ era%in% is Wron% @ more subtle problem is that un$ei%hte# a'era%in% is biase# to$ar#s lar%e
numbers of trian%les $ith the same normal& For e ample8 consi#er 'erte at in#e 1 in the leftmost picture& This 'erte is a#Bacent to t$o trian%les on the top of the cube ;secon# picture8 re#
an# yello$ trian%les
-
8/13/2019 10 Graphics
110/373
6#%e Turnin%
ut this topolo%y is the result of an arbitrary #ecision as to $here to #ra$the e#%es to trian%ulate the faces of the cube& For e ample8 if $e $ere to trian%ulate the top face by #ra$in% an e#%e
bet$een 'ertices 0 an# ) ;this is +no$n as t%rnin" the e#%e8 see picturesat ri%ht
-
8/13/2019 10 Graphics
111/373
?ectors
"urface normals cannot be transforme# usin% the same matri that is use# totransform positions& This is an entirely separate issue from the fact that normals shoul# not be translate#
li+e positions& The reason for this is that normals are covariant vectors &
?ectors such as position an# 'elocity are sai# to be contravariant : If $e scale thecoor#inate space use# to #escribe the 'ector8 the coor#inates $ill respon# in theopposite #irection&
If $e use a coor#inate space $ith a lar%er scale ;for e ample8 usin% meters instea#of feet< the coor#inates of a contra'ariant 'ector respon# to the contrary bybecomin% smaller&
2otice that this is all about scaleK translation an# rotation are not part of the#iscussion&
2ormals an# other types of %ra#ients8 +no$n as #ual 'ectors8 #o not beha'e li+ethis&
Chapter 10 2otes 3D Math Primer forGraphics Game De'
111
6 ample of Contra'ariance
-
8/13/2019 10 Graphics
112/373
6 ample of Contra ariance Ima%ine $e stretch a )D obBect such as a circle hori ontally& 2otice that the normals be%in to turn to point more 'erticallyRthe
hori ontal coor#inates of the normals are #ecreasin% in absolute 'alue8as the hori ontal coor#inates of the positions are increasin%&
@ stretchin% of the obBect ;obBect %ettin% bi%%er $hile coor#inates spacestays the same< has the same effect as scalin% #o$n the coor#inatespace $hile hol#in% the obBect at the same si e&
The coor#inates of the normal chan%e in the same #irection as the scaleof the coor#inate space8 $hich is $hy they are calle# co'ariant 'ectors&
Chapter 10 2otes 3D Math Primer forGraphics Game De'
11)
Transformin% "urface 2ormals
-
8/13/2019 10 Graphics
113/373
Transformin% urface 2ormals
To properly transform surface normals $e must use the in'erse transposeof the matri use# to transform positionsK that is8 the result of transposin%an# in'ertin% the matri &
This is sometimes #enote# MHT 8 since it #oesn!t matter if $e transposefirst8 or in'ert first8 that is8 ;MH1
-
8/13/2019 10 Graphics
114/373
"ection 10&,:
Te ture Mappin%
Chapter 10 2otes 3D Math Primer forGraphics Game De'
11*
Te ture Mappin%
-
8/13/2019 10 Graphics
115/373
Te ture Mappin%
@ te ture map is a bitmap ima%e that is paste# onto the surface of anobBect& @texel is a sin%le pi el in a te ture map& Planar mappin" proBects the te ture ortho%raphically onto the mesh&
Spherical 8cylin)rical 8 an# c%$ic mappin% are 'arious metho#s of $rappin% the te ture aroun# the obBect&
The +ey point is that8 at each point on the surface of the mesh8 $e canobtain te ture mappin% coor#inates8 $hich #efine the )D location inthe te ture map that correspon#s to this 3D location&
Tra#itionally8 these coor#inates are assi%ne# the 'ariables ; %8v
-
8/13/2019 10 Graphics
116/373
? Coor#inates
@lthou%h bitmaps come in #ifferent si es8 ?coor#inates are normali e# such that the mappin%space ran%es from 0 to 1 o'er the entire $i#th ; % )
Chapter 10 2otes 3D Math Primer for
G hi G D '
The =i%ht @ttenuation Formula
-
8/13/2019 10 Graphics
196/373
1 -
The li%ht intensity at #istance ) 8 #enote# i ;)
-
8/13/2019 10 Graphics
197/373
Chapter 10 2otes 3D Math Primer for
G hi G D '
1 .
Doom "tyle ?olumetric =i%hts
-
8/13/2019 10 Graphics
198/373
oth in the theoretical frame$or+ of the ren#erin% e(uation8 an# 4="= sha#ers #oin%li%htin% e(uations usin% the stan#ar# linn Phon% mo#el8 all that is re(uire# of a li%htsource in or#er for it to be use# in sha#in% calculations at a particular point x is a li"htintensity an# inci)ent )irection &
2o$ $e $ill #iscuss a type of 'olumetric li%ht populari e# by the Doom 3 en%ine ;also+no$n as i) Tech < aroun# )0038 that specifies these 'alues in a no'el $ay&
2ot only are these types of li%hts interestin% to un#erstan# from a practical stan#point;they are still useful to#ay
-
8/13/2019 10 Graphics
199/373
The most creati'e aspect of Doom style 'olumetric li%hts is ho$ they#etermine the intensity at a %i'en point&
It is controlle# throu%h t$o te ture maps& Nne map is essentially a%obo8 $hich can be proBecte# usin% either ortho%raphic or perspecti'eproBection8 similar to a spot or #irectional li%ht&
The other map is a one #imensional map8 +no$n as the falloff map 8 $hich controls the falloff& The proce#ure for #eterminin% the li%ht intensity at point x is as
follo$s: x is multiplie# by a *_* matri 8 an# the resultin% coor#inatesare use# to in#e into the t$o maps& The )D %obo is in#e e# usin%
; x4w 8 y4w
-
8/13/2019 10 Graphics
200/373
The Nmni =i%ht Matri
-
8/13/2019 10 Graphics
201/373
Chapter 10 2otes 3D Math Primer for
G hi G D '
)01
This matri operates on points in the obBect space of the li%ht8 $here theposition of the li%ht is in the center of the bo 8 so for the matri that operateson $orl# space coor#inates8 $e $oul# nee# to left multiply this matri by a*_* $orl# to obBect matri &
The ri%htmost column is 08 08 08 1ET8 since $e use an ortho%raphic proBectiononto the %obo&
The translation of 1>) is to a#Bust the coor#inates from the 1>) to U1>) ran%e
into the 0 to 1 ran%e of the te ture& The y a is is flippe# since U y points up8 but Uv points #o$n in the te ture&
The "pot =i%ht
-
8/13/2019 10 Graphics
202/373
The spot li%ht uses a perspecti'e proBection8 $here the center of proBection is at one en# of the bo &
The position of the li%ht use# for calculatin% the l 'ector is at this same location8 but that isn!t al$ays the case
Chapter 10 2otes 3D Math Primer for
G hi G D '
)0)
The "pot =i%ht Matri
Th i l % b i # th i8 b t # t th ti' B ti it f
-
8/13/2019 10 Graphics
203/373
The same circular %obo is use# as the omni8 but #ue to the perspecti'e proBection it forms a
cone shape& The falloff map is bri%htest at the en# of the bo nearest the center of proBection an# falls
off linearly alon% the U ( a is8 $hich is the #irection of proBection of the %obo in all cases& 2otice that the 'ery first pi el of the spot li%ht %obo is blac+8 to pre'ent obBects behin# the
li%ht from %ettin% lit& In fact all of the %obos an# falloff maps ha'e blac+ pi els at their e#%es8 since these pi els
$ill be use# for any %eometry outsi#e the bo & The a##ressin% mo#e must be set to clamp to a'oi# the %obo an# falloff map tilin% across
3D space& The te ture %eneration matri for perspecti'e spots is:
Chapter 10 2otes 3D Math Primer for
G hi G D '
)03
The Fa+e "pot
-
8/13/2019 10 Graphics
204/373
4ere8 proBection is ortho%raphic an# si#e$ays& The conical nature of the li%ht as $ell as $hat $e or#inarily thin+ of as the falloff are both enco#e# in the %obo& The falloff map use# for this li%ht is the same as the omni li%ht& It is bri%htest in the center of the bo 8 an# causes the
li%ht to fa#e out as $e approach the ( an# U ( faces of the bo & The te ture coor#inate matri in this case is actually the same as the omni& The entire chan%e comes from usin% a #ifferent %obo8 an# orientin% the li%ht properly
Chapter 10 2otes 3D Math Primer for
G hi G
)0*
@#'anta%es of ?olumetric =i%hts
D t l ' l t i li%ht b tt ti' f l ti % hi f ' l &
-
8/13/2019 10 Graphics
205/373
Doom style 'olumetric li%hts can be attracti'e for real time %raphics for se'eral reasons&
1& They are simple an# efficient8 re(uirin% only the basic functionality of te ture coor#inate%eneration8 an# t$o te ture loo+ups& These are fle ible operations that are easilyhar#$ire# into fi e# function har#$are li+e the 2inten#o Wii&
)& Many #ifferent li%ht types an# effects can be represente# in the same frame$or+& This canbe helpful to limit the number of #ifferent sha#ers that are nee#e#& =i%htin% mo#els8 li%httypes8 material properties8 an# li%htin% passes8 can all be #imensions in the matri of
sha#ers8 an# the si e of this matri can %ro$ (uite (uic+ly& It can also be useful to re#ucethe amount of s$itchin% of ren#er states&
Chapter 10 2otes 3D Math Primer for
h
)0,
-
8/13/2019 10 Graphics
206/373
?olumetric =i%hts in Doom 3
Thi i h th t i t t f t b hi # th i t # ti
-
8/13/2019 10 Graphics
207/373
This is perhaps the most important feature behin# the intro#uctionof these sorts of li%hts in Doom 38 $hich use# a accumulate#ren#erin% techni(ue $ith no li%htmaps or precompute# li%htin%Ke'ery obBect $as fully lit in real time&
6ach li%ht $as a##e# into the scene by re ren#erin% the
%eometry $ithin the 'olume of the li%ht an# a##in% the li%ht!scontribution into the frame buffer& =imitin% the amount of %eometry that ha# to be re#ra$n ;as $ell
as the %eometry that ha# to be processe# for stencil sha#o$s< $as a hu%e performance $in&
Chapter 10 2otes 3D Math Primer for
h
)0.
-
8/13/2019 10 Graphics
208/373
"ection 10&/:
"+eletal @nimation
Chapter 10 2otes 3D Math Primer for
h
)0/
Character @nimation
-
8/13/2019 10 Graphics
209/373
@rticulate# mo#els are bro+en up into ahierarchy of parts8 for e ample8 torso8hea#8 left arm8 ri%ht arm8 etc&
In ol# school Play"tation ) %ames8 thesearticulate# parts are ri%i#8 that is8 they #onot fle or ben#&
"o the characters loo+ li+e robots& @ better $ay: s+eletal animation&Chapter 10 2otes 3D Math Primer for )0
"+eletal @nimation The i#ea behin# s+eletal animation is to replace the hierarchy of
-
8/13/2019 10 Graphics
210/373
The i#ea behin# s+eletal animation is to replace the hierarchy ofparts $ith an ima%inary hierarchy of bones&
Then each 'erte of the mo#el is associate# $ith one or morebones8 each of $hich e ert influence o'er the 'erte but #o nottotally #etermine its position&
@n artist nee#s to specify $hich bones influence $hich 'ertices8 an#by ho$ much& This process is +no$n as s0innin" & "+innin% can be 'ery labor intensi'e& @lthou%h automate# tools
e ist $hich can pro'i#e a (uic+ first pass at the s+innin%8 a $ells+inne# character re(uires e pertise an# time&
Chapter 10 2otes 3D Math Primer for )10
6 ample
tV l + t l & Th t fi%
-
8/13/2019 10 Graphics
211/373
=etVs loo+ at an e ample& The ne t fi%uresho$s t$o e ample s+inne# 'ertices near theelbo$ of a robot&
The blue an# %reen #ots sho$ $hat a 'erte $oul# loo+ li+e if it $ere ri%i# to thecorrespon#in% bone&
The cyan #ot is the s+inne# 'erte K notice thatit stays attache# to the surface of the mesh&
Chapter 10 2otes 3D Math Primer forGraphics Game De'
)11
-
8/13/2019 10 Graphics
212/373
Chapter 10 2otes 3D Math Primer forGraphics Game De'
)1)
The 'erte on the left appears to be influence#about /0S by the forearm bone an# )0S by theupper arm bone8 an# thus it stays close to its green ri%i# 'erte &
-
8/13/2019 10 Graphics
213/373
Chapter 10 2otes 3D Math Primer forGraphics Game De'
)13
The 'erte on the ri%ht appears to be influence#about *0S by the forearm bone an# -0S by theupper arm bone8 an# thus it stays close to its blue ri%i# 'erte &
@ "imple "trate%y For each 'erte 8 +eep a list of bones that influence it& Typically $e set
-
8/13/2019 10 Graphics
214/373
For each erte 8 +eep a list of bones that influence it& Typically $e seta limit on the number of bones that may influence any one 'erte &;Four is common&