10/13/16
CS482:InteractiveComputer
Graphics
MinH.Kim
KAISTSchoolofComputing
MinH.Kim(KAIST)
CS482:InteractiveComputerGraphics
Chapter13
MATERIALS
MinH.Kim(KAIST)
CS482:InteractiveComputerGraphics
2
1
10/13/16
MaterialAppearance
• Richvarietyofmaterials:characterizedby
surfacereflectanceandscattering
MinH.Kim(KAIST)
CS482:InteractiveComputerGraphics
Materials
• Wecansimulatelightbouncingoffofamaterial
• Bestdoneinthefragmentshaderifpossible.
• Uniform variablesareoftenusedtodescribe
thinglikethepositionsofsomelightsourcesin
thescene,whichdonotchangefromvertexto
vertex.
• Varyingvariablesareoftenusedtodescribethe
coordinatesvectorofthepoint(withrespectto,
say,theeyeframe),anormalforthepoint.
MinH.Kim(KAIST)
CS482:InteractiveComputerGraphics
4
2
10/13/16
Materials
• Parametersdescribingthematerialpropertiesat
thepointmightbeuniformsorvarying.
• Thefragmentshaderthentypicallytakesthis
dataandsimulateshowlightwouldbounceoff
ofthismaterial,producingacolorintheimage.
MinH.Kim(KAIST)
CS482:InteractiveComputerGraphics
5
Basicidea
• Whenlighthitsaphysicalmaterial,itisscatteredin
variousoutgoingdirections.
• Differentkindsofmaterialsscatterlightindifferent
patternsandthisresultsindifferentappearances
whenobservedbytheeyeoracamera.
– Somematerialsmayappearglossywhileothersmatte.
• Bysimulatingthisscatteringprocess,wecangivea
realisticphysicalappearancetoa3Drendered
object.
– Wewilltakeapragmaticapproachhereinsteadofa
scientificone.
MinH.Kim(KAIST)
CS482:InteractiveComputerGraphics
6
3
10/13/16
LightblobfromPVCplastic
• PVCblob
– Notethatthisfigurejustdescribestheresultoflight
l
thatcomesinfromthespecificshowndirection.
Forotherincomingdirectionswewouldneeda
differentblobtovisualizetheresultingscattering.
• Theplasticwillappearbrightestwhenobserved
inthedirectionsclusteredaboutthe‘bounce’
directionofthelight:B(l )
MinH.Kim(KAIST)
CS482:InteractiveComputerGraphics
7
LightblobfromPVCplastic
• Recall:Givenanyvector(notnecessarilyof
w
unitnorm)andaunitnormalvector,wecan
n
computethebouncevector(mirror
reflection)ofas
w
B(w) = 2(w ⋅ n)n − w
MinH.Kim(KAIST)
CS482:InteractiveComputerGraphics
8
4
10/13/16
Basicsetup
• Weassumethatalllightcomesfromasingle
pointlightsourcethatispointedtobythelight
vector,.
l
– Inreallife,therearesomesmalllightsources(sun,
candle),therearesomebiglightsources(sky,
fluorescentbulbs).
– Additionally,everysurface
inthescenereflectslight
towardsthepointinquestion.
• Thelighthitsthepointon
p
sometrianglewithnormal.
n
MinH.Kim(KAIST)
CS482:InteractiveComputerGraphics
9
Basicsetup
• Theanglebetweenthesurfacenormalandthe
vectorpointingtowardsthelightisdenotedas θ
• Wewanttocomputetheamountoflight
reflectedtowardtheeyealongtheviewvector, v
• Tohandlecolor,wejust
computethreereflected
quantitiesforRGB.
• Wetypicallyrepresent
theincominglightinRGB
(oftenwhite).
MinH.Kim(KAIST)
CS482:InteractiveComputerGraphics
10
5
10/13/16
Basicsetup
• AnduseRGBcoefficientsforthematerial
propertyrepresentation.
• Andjustdo3independentcalculations
– NotethatthisuseofRGBisnotphysicallyaccurate.
• Thesequantitiesarethen
directlyusedastheRGB
valuesforthepixel.
• Wewilloftenassumehere
thatallcoordinatesofpoints
andvectorsarewrittenwith
respecttotheeyeframe.
MinH.Kim(KAIST)
CS482:InteractiveComputerGraphics
11
Basicsetup
• Notethatthenormaldoesnothavetobethe
“truenormal”oftheflattriangulargeometry.
MinH.Kim(KAIST)
CS482:InteractiveComputerGraphics
12
6
10/13/16
Diffusereflectancemodel
• “Diffuse”materials,likeroughwood,appear
equallybrightwhenobservedfromalldirection v
– Thus,whencalculatingthecolorofapointonadiffuse
surface,wedonotneedtousethevectoratall.
v
fr = const. =
©Szymon Rusinkiewicz (Princeton)
MinH.Kim(KAIST)
ρ
π
CS482:InteractiveComputerGraphics
13
Diffusereflectance
• Diffusematerialsappearbrighterwhenlighthits
them“fromabove”,andappeardimmerwhen
lighthitsthemfromagrazingangle.
• Thisisbecausetheamountofincomingphotons
hittingasmall,fixedsized,patchofmaterialis
proportionalto.
cos(θ ) = n ⋅ l
MinH.Kim(KAIST)
CS482:InteractiveComputerGraphics
14
7
10/13/16
Diffuseshader
#version130
• Thenormalize callis
usedtomakesurethe
uniformvec3uLight,uColor;
interpolatedvectorshave
invec3nNormal;
unitnorm.
invec3vPosition;
• Themax callisusedsothat
wedonottrytoproduce outvec4fragColor;
negativecolorsatpoints voidmain(){
thatfaceawayfromthe
vec3tolight =normalize(uLight - vPosition);
vec3normal=normalize(vNormal);
light.
• Thecalculatedvalueof
floatdiffuse=max(0.0,dot(normal,tonight));
diffuse isusedtomodulate vec3intensity=uColor *diffuse;
theintrinsicsurfacecolor fragColor =vec4(intensity,1.0);
passedinasuColor.
}
MinH.Kim(KAIST)
CS482:InteractiveComputerGraphics
15
Extensions
• Thelightitselfhasnotbeengivenacolorofitsown.
Thistoocanbeeasilymodeledwiththeadditionof
anotheruniformvariable.
• Multiplelightscanalsobeeasilyaddedtothiscode.
• Indirectlightcanbeverycrudelymodeledinour
computationbysimplyaddingsomeconstant
ambient color(NBphysicallywrong)valueto
intensity.
• Sometimes,itmaybemoreconvenienttomodel
thelightascomingfromadirection,describedbya
vector,insteadofavectorfromapoint.Inthiscase,
whenmodelingsuchadirectionallight,thevector
toLight wouldbepassedinasauniformvariable.
MinH.Kim(KAIST)
CS482:InteractiveComputerGraphics
16
8
10/13/16
Shinymaterials(specularity)
• Manymaterials,suchasplastics,arenotdiffuse;
• Forafixedincominglightdistribution,theyappear
brighterwhenobservedfromsomedirectionsand
dimmerwhenobservedfromothers.
• Roundobjectsmadeupofsuchmaterialshave
brighthighlightswhereverthesurface-normal
points“justright”.
• Asimple,somewhatplausiblecomputationthatis
oftenusedinpractice,istosimply
calculatethelight’sbouncevector,
B(l )
andthencomputeitsanglewith.
v
MinH.Kim(KAIST)
CS482:InteractiveComputerGraphics
17
Shinymaterials(specularity)
• Halfwayvector
– Asimplerwaytogetthesameeffectistocompute
thehalfwayvector
h = normalize(v + l )
– Andthenitsangle.
φ
with
n
h
and
n
– Thevectorsarewellalignedonlywhen
v and B(l ) arethesame.
– Wecomputethecosineof φ
usingadotproductthatfalls
offasdiverge.
h and n
MinH.Kim(KAIST)
CS482:InteractiveComputerGraphics
18
9
10/13/16
Shinymaterials(specularity)
• Whenthebounceandviewvectorsarewell
aligned,wedrawaverybrightpixel.Whenthey
arenotwellaligned,wedrawadimmerpixel.
– Donewithadotproduct.
• Tomodelshinymaterials,wewantthe
brightnesstofalloffveryquicklyinangle,sowe
thenraisethedotproducttoapositivepower.
MinH.Kim(KAIST)
CS482:InteractiveComputerGraphics
19
Shinymaterials(specularity)
• Suchspecularreflectioncanbeexplainedby
“micro-facet”theory.
– RobertL.CookandKennethE.Torrance.1981.A
reflectancemodelforcomputergraphics.SIGGRAPH
Comput.Graph.15,3(August1981),307-316.
– Specularityismadeupofreflectiononlotsof
microscopictruemirrors
interactinginsome
statisticalmanner.
– Cook-Torrance
reflectancemodel.
MinH.Kim(KAIST)
CS482:InteractiveComputerGraphics
20
10
10/13/16
Blinn-Phong reflectancemodel
• SimpleBRDFdescribingspecularreflection,
modeledinOpenGL
n is normal
h is halfway between I and v
fr =
ρ
+ ks (n ⋅ h)α
π
©Szymon Rusinkiewicz (Princeton)
MinH.Kim(KAIST)
CS482:InteractiveComputerGraphics
Blinn-Phong vs.Phong BRDF
• Phong (1973)
!
! ! ! !
B(l ) = 2(l ⋅ n)n − l
! !
cosθ = B(l )⋅ v
MinH.Kim(KAIST)
• Blinn-Phong (1977)
! ! ! ! !
h = (l + v) / l + v
! !
cosθ = h ⋅ v
CS482:InteractiveComputerGraphics
22
11
10/13/16
Specularshader
uniformvec3uLight,uColor;
• Thecoordinatesofthe
invec3vNormal;
invec3vPosition;
vector,since,ineye
v
coordinates,theeye’s
outvec4fragColor;
positioncoincideswiththe
voidmain(){
origin.
vec3normal=normalize(vNormal);
vec3viewDir =normalize(-vPosition);
• Alsonoticethat,inthis
vec3lighter=normalize(uLight - vPosition);
code,thespecular
floatnDotL =dot(normal,lightDir);
componentiswhiteandis vec3reflection=normalize(2.0*normal*
unrelatedtoanymaterial nDotL - lightDir);
floatrDotV =max(0.0,dot(reflection,
color.Thisisquitetypical viewDir));
forplasticmaterials,where floatspecular=pow(rDotV,64.0);
floatdiffuse=max(nDotL,0.0);
thehighlightsmatchthe
coloroftheincominglight, vec3intensity=
uColor *
regardlessofthematerial
(diffuse+0.2)+
color.
vec3(0.4,0.4,0.4)*specular;
MinH.Kim(KAIST)
fragColor =vec4(intensity.x,intensity.y,
intensity.z,1);
}
CS482:InteractiveComputerGraphics
23
CS482:InteractiveComputerGraphics
24
Materials
MinH.Kim(KAIST)
12
10/13/16
Anisotropy
• Thetwopreviousmaterialmodels,aswellas
manyothers,havethepropertyofisotropy.
• Thismeansthatthereisnopreferred“grain”to
thesurface.
• Somematerials,likebrushedmetal,behavein
ananisotropicmanner.
– Ifonetakesaflatsampleof
suchamaterialandspinsit
arounditsnormal,the
material’sappearancechanges.
MinH.Kim(KAIST)
CS482:InteractiveComputerGraphics
25
Anisotropicshader
• Whenmodelingsucha
material,wewillassume
thatapreferredtangent
t
vector,,issomehow
includedinthemodeland
giventotheshader.
• Kajiya andKaymadeupa
modelbasedonthe
assumptionthatthe
surfaceismadeupoftiny
cylinders.
uniformvec3uLight;
invec3vColor;
invec3vNormal;
invec4vPosition;
invec4vTangent;
outvec4fragColor;
voidmain(){
vec3toLight =normalize(uLight - vec3(vPosition));
vec3toV =-normalize(vec3(vPosition));
vec3h=normalize(toV +toLight);
vec3normal=normalize(vNormal);
vec3vTangent3=vec3(pTangent);
vTangent3=normalize(cross(vNormal,vTangent3));
– J.T.Kajiya andT.L.Kay.
1989.Renderingfurwith
threedimensionaltextures.
SIGGRAPHComput.Graph.
23,3,271-280.
MinH.Kim(KAIST)
floatnl =dot(normal,toLight);
floatdif =max(0,0.75*nl +0.25);
floatv=dot(vTangent3,h);
v=pow(1.0- v*v,16);
floatr=pColor.r *dif +0.3*v;
floatg=pColor.g *dif +0.3*v;
floatb=pColor.b *dif +0.3*v;
fragColor =vec4(r,g,b,1);
CS482:InteractiveComputerGraphics
}
26
13
10/13/16
Diffuseonly
MinH.Kim(KAIST)
CS482:InteractiveComputerGraphics
27
Diffuse+Specular
MinH.Kim(KAIST)
CS482:InteractiveComputerGraphics
28
14
10/13/16
Diffuse+Specular+Anisotropy
MinH.Kim(KAIST)
CS482:InteractiveComputerGraphics
29
Anisotropicshader
J.T.Kajiya andT.L.Kay.1989.Renderingfurwith
threedimensionaltextures.SIGGRAPHComput.
Graph.23,3,271-280.
MinH.Kim(KAIST)
CS482:InteractiveComputerGraphics
30
15
© Copyright 2026 Paperzz