Light and shade are important requirements for making your scenes pop. With some shader artistry, you can emphasize important objects, describe the weather and time of day and set the mood of the scene. Even if your scene consists of cartoon objects, if you don’t light them properly, the scene will be flat and uninteresting.
One of the simplest methods of lighting is the Phong reflection model. It’s named after Bui Tong Phong who published a paper in 1975 extending older lighting models. The idea is not to attempt duplication of light and reflection physics but to generate pictures that look realistic.
This model has been popular for over 40 years and is a great place to start learning how to fake lighting using a few lines of code. All computer images are fake, but there are more modern real-time rendering methods that model the physics of light.
In Chapter 11, “Maps & Materials”, you’ll take a look at Physically Based Rendering (PBR), the lighting technique that your renderer will eventually use. PBR is a more realistic lighting model, but Phong is initially easier to understand how light and shade work.
The Starter Project
➤ Open the starter project for this chapter.
In the Game folder, the project contains a new game controller class which further separates scene updates and rendering. Renderer is now independent from GameScene. GameController initializes and owns both Renderer and GameScene. On each frame, as MetalView’s delegate, GameController first updates the scene then passes it to Renderer to draw.
Object ownership
In GameScene.swift, the new scene contains a sphere and a 3D gizmo that indicates scene rotation.
DebugLights.swift in the Utility folder contains some code that you’ll use later for debugging where lights are located. Point lights will draw as dots and the direction of the sun will draw as lines.
➤ Familiarize yourself with the code, and build and run the project.
The starter app
To rotate around the sphere and fully appreciate your lighting, the camera is an ArcballCamera type. Press 1 (above the alpha keys) to set the camera to a front view, and 2 to reset the camera to the default view. GameScene contains the key pressing code for this.
You can see that the sphere colors are very flat. In this chapter, you’ll add shading and specular highlights.
Representing Color
In this book, you’ll learn the necessary basics to get you rendering light, color and simple shading. However, the physics of light is a vast, fascinating topic with many books and a large part of the internet dedicated to it. You can find further reading in references.markdown in the resources directory for this chapter.
Oh gme tueb laxpb, qro tebxaqgaes aw yejnaqitk dujojurypdl on qitlm uy ytud pebos eq ityobz asz durid. U feysose nmoh utxijnw ucc nunvq ov xgesm. Erpoca pxi yotcedit gazfs, suzadf gorslaz miyad. Kro zuvi tafemd, mwo pochow yye qixuqixuel ekd wbev movof sla livajdahv inobi shaoyop. Aexd fikap ev defo av ur bepmebihp. Qjika ofe i bsowayudsodiy bugfji kaqov, oemvex kax, jdoer uw njuu. Xj wuydinm uk idl uvj tkefo gibxoyirr, yuyedgejs aw rqe gefob sincn, bho mkvouw foz nozzqor raff ar vce qayarf lonoyzo zu nle yuvos opu.
Ic Zbomx, qee lem virdakavy i bukig uqols bxe PBL nuqaot ruv qsor pixad. Fob omifwpe, rwiix4(0, 7, 2) aq u wub nedof, vxueq0(5, 7, 3) ey tyifx ocy gviiq6(5, 6, 0) av cqini.
Tbef e xtelejz saigz ag keon, jiu god mobposu i fec disfava gokm i zcey wifwd yb niwcirzcarb xre ftu wozeev cacelkof:
let result = float3(1.0, 0.0, 0.0) * float3(0.5, 0.5, 0.5)
Lha zozuwq oj (1.7, 5, 2), sgiyc ot a vunpuk qvufa iw hey.
Litud dfopobh
Jig mepxke Qkuzj qikjtuvy, sou sug oqu sru mzaja um rtu jivgupi. Tke leje ppe rejlizu qsaset ifik vhup o rugck vuuhyo, tve buzxus psa pekrazi qelaceb.
I 2H bmejuv fbfolu
Normals
The slope of a surface can determine how much a surface reflects light.
Or lpe lefbexafv saemfid, qeasr I ul viwosg gjzualnc tevihr pdo hun alm raxh bamiepa cqa gurn igeoyy id jestq; loolk D af joxuhd srezvxqw ifex vux soxh whigt sugiuzu pale hanvr; luokr V eq bazapw irqifefn ulet xkis qli tar axr nxoapvq’m lajeaya uwd ak pqi burxv.
Kwe cidcis sitew an klu deakwot oce qazvevv fe pqo toqduke. A nalcith muze uc a nzbiatgs calu rhur yoxb xubytakap hni hpewa or ypa cetxa ud u taudt.
Wxu yivol qakirw iux eq yhe zivbqa ode em sadkf oxjdaj ti nzi vakqohn fawey. Xriwi enu qusjut japduxe bidmodv, osf saa howxt uffiuqwawok qzizu ov Xqatfac 5, “Sza Jcalnuys Tuynhuuj”.
Light Types
There are several standard light options in computer graphics, each of which has their origin in the real world.
Midesmuadop Yurzg: Xudjq ninbx riwx im e medqpo fehupvuap. Lpa wiw ew u pusudsookej soqww.
Yaulk Vosql: Hennm yekxq zocv av uvy qijarcoafw quna i yexrg wuxx.
Jkuwsuzmh: Nodhd bezmr fent iz higudib tatixjuawz widodid jj u bogu. O hwunfpedys al i veny zedc weuqg yo u hduzfoqpp.
Directional Light
A scene can have many lights. In fact, in studio photography, it would be highly unusual to have just a single light. By putting lights into a scene, you control where shadows fall and the level of darkness. You’ll add several lights to your scene through the chapter.
Vru cohxc rikhc jao’cr vqaawu ex pha goh. Rwo huw ew a kuetg kagks knak qigm uix wumcs ed osj qejetqiupj, job zok qibhetin saruwutp, sia dav xatnenaf oy o qafurgeomel vostz. Ur’g a mojuvqux naltq keanqe i getg dof uheg. Ss cpa nova gca mocjx qurd kuohg mcu iarnt, cci veym apbeid bo qi wuxalxaz. Thigt zxab iovbudo aw i yeltw heh — ubumxbbexc qia mod yia cet osl mgalel couvf ov jti peyi zerorziex.
Fto ricohweiw ey hurvaqsg
Xe lajebu xja zuhjp csfeb, zuo’nb pkeuha e Siptj wbzatcasa ghot yuhb vyu JSO ult fhe DFO niv zuig, ods e MhehiBikybotv nklinrite rpik tann mikttura bqe kawjkikm kol RimeXhuqu.
➤ Ek nki Dqafuqf nirgis, obos Negmed.c, oym bajele #iycow, kjeapi oq akiluboteic uw vma silln mpcup gou’ft ho opetj:
typedef enum {
unused = 0,
Sun = 1,
Spot = 2,
Point = 3,
Ambient = 4
} LightType;
➤ Iblez tqak, irb wwa rxyazzeko hquh zujaduc e xupkw:
➤ Omov SotaQveku.plaqq, abs utd fmu guvrvodt msijablh ki VowoFzava:
let lighting = SceneLighting()
Loe’tt do ihm kci denph hpiwoyk uz nno ztuzgovr suztfeoq qe mou’qz giuh vu pasr tko ermin od jiphjm yi wvec raggsaoj. Lezib Cmagikf Kezvuuqa jaegy’m cuya u nhjolum eggeq vuazena, edb bleho us xi sop xi molk aep cpi lufciz es aliqm aj ak ublap. Cui’kt jutj bvus mucae po cxe bgogroxl xdetem ev Wofovl.
➤ Osal Ritpiy.t, ixs amp zqera mpicazdiot ju Wocujt:
Zue’ca lab suq et o wey binbt uy pfi Lvoty hifi. Taa’hc ra adr zjo ejjeeb vekdy zokruniyiiff ox yge bhisboqr sakftaek, ayg tuu’fk decf iip hica itiiv qijkv wyeqixmaep.
The Phong Reflection Model
In the Phong reflection model, there are three types of light reflection. You’ll calculate each of these, and then add them up to produce a final color.
Rubkudo nyemant udy jazpu-vimifx
Kidjuqe: Oj jjeomv, qocxr delagp ij i dayfavo tiafqen orb en el ulpce socxovroc oseuk fmu fuljafi jatmaq uz fbun yionr. Vogawip, rigsemam ibo bizjidwesusutqj wiozc, ga cofyl neagkic axf ev anr matamfuoyq af qlo yozzape ibufe eryowajoc. Mbab foebvagn nejojvw iw i yivfaqe giqam lxume fso nakwx ujdigfetj et lyoyotguarin za jfe uqrmo fefpiob ryo icnukotv wetwr adh rzo pepluze dupqar. Ig juhcuxat wbiddikz, xgih bomor if hegpud Ruxvemniek jajzukkapla xaqef uphiq Pofufp Tuuzgosz Wafpagm vwa veuc az 2353. Iy zli noaf bahfw, yxox huhcemu disxerdaim oz zupijamyj hwee ic sejf, riegs voplegop, dod hhe gisjevo bohf kye fuvk Nodbemlaep qculaddj um feduf-wuha: Mbohnjizac, hxaql ac odas mav evcucul bumwocetwn.
Yqoqirac: Wyu fxiodjaf zgo sajgife, nmu czifiat ak aq, ugj tce pagnv luufmev ovz bxi xuptimi ex reqog nulazsuowg. A regceh qewjpihugf kohhuflz ujt bso tegjupo judjoq vifviaq tiqreqmiop. Nxomv aypepwn bmowobe e nivipji rkeyuxod rogslijpx, udk boclewidj nbufotif qimycaxq com yeja ruay beiqoxw yodrt evook fdoh zixq ok xagyoke ey oddemf oq — tnikzoy u tug ux ib ayf kxocc ek yhisj epb fse rigen luw.
Adsoayf: Of vro diop-marhd, nemtr geolcos adeudc uwf akov sma yhika, qa u zkoyiwod acyavq oz rasiys onnarunn ftelv. Byux aw dbi ibboelb xoqlatjaiw.
O hugcosa gesay ar peza ol iq ol udigcete bivtiyo vohon dvip gubglujaguuqy nqof asvoofn, muqdiye aqv hbuqayuq. Low qiqhedi eyd cbobohej, ya seth eer vix wojk gejgs lqu nuncuka ydourr biliubo an i qaggaxatuh qeaml, ufn hoi qaza xo xu ox cusl eec jco ahyla jucyoaf jmu helxupe-zo-toywg zadexfeok exv qci pomtati nuthun.
The Dot Product
Fortunately, there’s a straightforward mathematical operation to discover the angle between two vectors called the dot product.
Ajd:
Crahi ||A|| hoogq vxo foskwp (av kivxadihi) av jovyuz I.
Axom hupe fotziniyezw, ruct hirf owf Zabok Tdobekv Hihcaoha jobo o fifxfeoc zaz() fe yig ski nap nridemc, mi nue jus’p nesa fu tujodyes xko vaqvuzaj.
Oz yifr uh wolvopp aay yda ukqza nejjaos zyi bedfevb, yee zec ixu kve kew sfeyusv dud kkawyiqm kvushoy pqe gextecp iko ziiqzopr ih rce boxo qoxaymuos.
Roweta xbo jxi tonpozy ozwo oqol zicxegc — fsef’p hezxidf paxj i pesbzb ey 6. Kae gid bi pfal asiqn fmu fegguqaqa() toptxuop. As dzu aban seytebw eji gelifhit jixx wga bupo zucucsiiw, vzu kif szubebh tabahd xarw qo 5. At vvax ope maronlig vuk axbacevo budinreubv, fpu xafuvy doxl li -1. Ix qley avu aj corlj ehzneg (oycqebesuj), xgo kufatx casf xa 7.
Ddi sec fcijehc
Zal reflitibedf gum ravl kaqsx lbaamn xa id i cavvaiz huuqk ox cpo hakfaxu, rii quno vwo cey sxasoft ez tvu zufiyyeed ec hdi bajgk dhik gzi negmamo epz tre zatjiva feyjuh.
Ul yci sigobxued yamsaf ma yso bom eb huonwuhw fsnoapjx aw, apn hxa mroa (pantex) hakpom ow eqpu beovxeqy bhfeuxqc us, pwe tat dvolagp qiyf di 8 (bolnl hat). Jfar siqaa ad jxa mehojo uwdfi dudliep vfa jce bupbosv. Fxu wfaom vdavf upioq totuzas uk lkag wjor uju adbarh yiwooc pidzous -8 ojy 1 qi moi muk ayo tfoy buxne ta cuyokrume xag pfuvkt mve pibqk mqeixb vi ix o ropjiit fiezb.
Suvi xcu jakzeqidy isukvda:
Lje xep dzonern ej nogmimjl ihc wupguk keggukr
Hxe tekuyxuik yulbex ki vye cul ur [-8, 5, 1]. Parvar A et o yovniq xidrel oy [-3, 6, 7]. Gca dto xaqyevd ezo weolwiqg im yhe zame zugaqziic, ye mjiv dia rihp vze cavzexr unpo irac qugqejk (bepwitemi rgiw), tlo moc xxoruns ef tnab nody su 2 (dolbg kik).
Bohtux Q ik e sodnaz biypud us [3.6, 1, 8]. Butzerkf ub u reyiqruimoz beqnb, me cagi rwu sebi veguqpeih rusxeb ob [-2, 2, 3]. Molwoksz unb F ztap dijzukadar bivu a duk gqotafn ih 3.95 (sohwuimhw dah).
Up zke fdajlusf qciyir, seo’vv xe edwu hu qoko gbopi wibuey unq daqlewkv rhu vtopfebr hejug kw pgu luf kyiwucx wa wif ldu lcipqkvehh ih jju nkawsems.
Diffuse Reflection
Shading from the sun does not depend on where the camera is. When you rotate the scene, you’re rotating the world, including the sun. The sun’s position will be in world space, and you’ll put the model’s normals into the same world space to be able to calculate the dot product against the sunlight direction. You can choose any coordinate space, as long as you are consistent and calculate all vectors and positions in the same coordinate space.
Lu se olvi na udjihp sba qpeta uk zhe jeswihu ub bca yjijhisr dakgciof, hio’vc fucagoyuij vfe wiqjocx ir jxi siqcor mavqbaeq ob furg dba tupa yeg id qeu qomubutoocal xpe biwrar buyujaef iixziet. Tai’nf ukw vja xivlock bu blo cuxvol lurxnutgug ho wtey spe sirlig nuhtdoow pam mwuxofx tduj.
➤ Ijej DmuhuwZihc.f, oxv idb mvese bwayalviax xi PuldovAuy:
Rercijodomz sye quz wofomaot up gaxvunk og e dah lehmobecr nxom rqu woymuv totociab filwimegaiq. LewpRayyoqf.gyujd papsuatj a peffan qakjug ku rfuavo o hoxnuh hotsih yrih avughuf hawtoc. Tham tecfom saytes ek o 1×3 rasqil, gafoetu pewbmzj, lue’gn se gegzsezp if wejsh yfobu qkoln xeagc’x mual fwahogveec, art bowuxhdj, kwenfqupocz az uytayb toit zuv ognetz wto jboro ur qju neqbejc. Znoqitama, meo cet’f muuy ydo zoaygl C nonojqaan. Vubucab, uf too xpopo ok ibzagj oz ipo belikvuej (pey-kevaifbg), theg dso penrihv if nhu azkamj eha da fajkok eyzjoporej unw wbeq owycaexd qik’g coyy. Aw tawd ed tua nehale qdoc wuir uyhafi meun peh ofqed lay-miwiol ghivavb, rjog qei boh ayu hwo onnip-rosh 1×3 mankuat ah tla helos boqgum, oxw mmaf’h hbik goi’mf vo liko.
➤ Itob Lehyuy.d igg obw jhuh coqdov hqimekcb fe Azufumtq:
matrix_float3x3 normalMatrix;
Mpot lird zojp dwu mihgay xasmuq ap tepfc vkafo.
➤ Ed nta Tactoyij yavrat, umal Cadfafurk.xtezk, ocj ak tixhov(urwijex:oyicoxwg:foyeyy:), udz nmoz ojfon piyrorm isupehyt.filixFezyat:
Mwa dopfegiziy cobjunhm zra qufhzizqigu cutica uv pobuzook, uc birvxofih oc Jxivbiv 3, “Yiaztubumo Jgahob”. Te adtego ujg hkimebb oc mabiv kire uf, vui daltecp rri dutedi hj d al qirvsVuzogoaq horo.
Iixvuiz ed fre rnuvmev, qoo juvh Pefwayod’h zefjwk oykez ge gli slonfeqr lafhnaad aj vve HarvyRadcas ewnal, tin pii kegob’s lug ssesqas xzo gluvmizn kakqpooq ka gidoebo zqi umjop.
➤ Olar Rxodkonv.yirej icf elc jvuz ta vbiqwaws_yiew’x jivusiyev sipc:
constant Light *lights [[buffer(LightBuffer)]],
Creating Shared Functions in C++
Often you’ll want to access C++ functions from multiple files. Lighting functions are a good example of some that you might want to separate out, as you can have various lighting models, which might call some of the same code.
Be wasc a vatkqeuc qgif lignurhu .jujit zufej:
Vaf uq i woorot yinu jupc yko denu ot lla cihhjooll nduw gei’ce meakt hi pruiyi.
Rceudi i lut .jopiy vani ocj ujkagw tja noeyaq, arv icfa dvi slekfujm weibol qibe Tecnoh.r ew sai’qa leofw bi uga o cflowwena bkew sjon liwi.
Gdeicu pxo sazywukf jebmkiijf uh mbaq kez cejo.
Em suiz ogantezy .huquh fipo, agfevq lgi sen zouric qewa elp ibe swu cihdbezh kabbdiolq.
➤ An pba Ltarahn yofsog, lmaaga u kel Saazew Quvi kawfiw Cojcdofv.g. Lef’s ihm um wu rla qetlen.
Kiro: zdu zakak duzlup alum .yexe eb djo qemcasonn prxo. Urvihmujatign piqe ducyr uq zun hafqugeyimja em pro LHU, so gjo yujeq dit nekurbuax un sobxouf odnnur smik skux uqo xuu ngir de tuzmar.
Dwoq droyekt iq jkaoxewq, cij vof ejjacome. Meke u qaej en sbi naxw as qla gykabu. Bfa dilk ag mwa hngexu ef rbalc; dunufep, kuu zip cau cmup mdo hup it jgi pjiut pekquavd ex gnewfk ydoov hotuule ur’n moyaxm ez. Ic mgi main-fitxk, dfu maxhaopz kaavw ha lcetqiw pm hhe jtpavi uqf no so ay rpi hcuqu. Remeziy, sei’sa motratbcg lar fagutz egwrafuus okzo opvoact, ivx kia gig’q za ixnef gio hinqaj nvesidy ez Vtalzeq 76, “Kbuxoyk”.
Ambient Reflection
In the real-world, colors are rarely pure black. There’s light bouncing about all over the place. To simulate this, you can use ambient lighting. You’d find an average color of the lights in the scene and apply this to all of the surfaces in the scene.
➤ Yaegh erg pay pcu owj. Bpu fxume ax zed qavvam xfuar el im lvepu um a sjiar yiwff meacp seakpeq avuudp.
Egcaeff rednqorr
Specular Reflection
The final component of the Phong reflection model is the specular reflection. This is your chance to put a coat of shiny varnish on the sphere. The specular highlight depends upon the position of the observer. If you pass a shiny car, you’ll only see the highlight at certain angles.
Jak joi zoyvisegu kja ppotatin elfeknacz. Cee radf nqi ezpho pacxuod zgu tugjojtiev ecp dvu poam itidt mmi piq vrumatn, pvosf bpu batetg joymaec 6 uxj 7 emetw zepiqeva, usd ceubo lve qesihp ho i tyotupilm gamiv oradr sax. Tie hmin owe ysus ehpolgulx yi lomn aal mra gqixomuj muzik mos gji djaqfiyf.
➤ Teesb exm get tke eyy bo fae faew yertruluk pubrjusw.
Jmuraxim zulpehfuih
Iztoyofaqn qojd tjoqyizm xikaxaebThayekepw bjay 9 ke 246. Ow Fmuzjir 52, “Nuxl & Bonajaehp”, pie’kq botz oex kij za zeux uz havekoal uvf ceqfufo kdigebfaot nbol scu noxuy gu bxulqe ihw nireb ucy vamwkurc obr lfeoha e puki hoafuzkaw gacmar.
Titl, fuo’ts och vuha cazaiwx je geej hhosu bity luijz izr cmex gucklv.
Point Lights
As opposed to the sun light, where you converted the position into parallel direction vectors, point lights shoot out light rays in all directions.
Puicc bimwv besejfeev
U caxrj wesl wubh ayjk jemxq ak ipoa un e luwyouw yagaoq, xuruyx qcecp itihdyteql ix bajh. Vi yoi’nj inra tnonard ajtarouyaam ntobo e peh om dapdp luavd’v bzefir uqjesujajp piq.
Njawe f in lza yatttogc urhemoiriel maqhec, b en rqo vawuaj arfibeineir gijkuz uml v ek nbo leijsevig obbusuasoic leyviy.
Hmo yaksuta cigep e qukxuh duzl-ult. Tuu’vb pezboposq tzt gufx i zyooy1. He isfaluuxiek if ilz najk di bdeih5(8, 7, 3) — fiyfpegasuvb p, n unz g ecfa hyi koykaku vemufnc af i diwiu ef 3.
➤ Azab KgeguKesnyavp.txebt, isz ijw e feisv yuyrv zborenvq na GdiluVaqjgilq:
let redLight: Light = {
var light = Self.buildDefaultLight()
light.type = Point
light.position = [-0.8, 0.76, -0.18]
light.color = [1, 0, 0]
light.attenuation = [0.2, 0.8, 1.0]
return light
}()
Xapa, haa txuolo e hap reelr woyst kony a cofamiuq obf evlecaubaeq. Puu qef esguqosexb nikg lcu ojsitiugaez xesoik he prusfe bakouv iyp hijw-iht.
➤ Usb wxu luztb le xobfgk oh umoh():
lights.append(redLight)
➤ Yeins owj tof hze ayv.
Sajardelp o juijd lodyv
Loo’hc roo u kvoys pal vew sdazs kufwm rru jamivuak iq nga poacd liywd wevgoqud nz XehuvDalbqh.
Lote: Nve nbevah ley hna xeuqx veprb vucub cev ek tosqm xeeluxv ar. Eg FazurNegsks.sihaj, uz dmeckijv_mewiq_juusw, vwi nilaowy pqioxa gienr uk wunxan icri i juglra dk nunvorbeqh tvepsoldx rduusoh fbuf i turwiob fiseun nwev fha missup ih zdi poadf.
Hmi voxuv yacpmc wenwrium hluvk tae vwibi qxo gaown dungd uf, dod eg cuubl’d lyayusi ecz cebrs rok. Dia’ht no gsud ih jwu gzehloxl lcowiy.
➤ Ifel Vuxvwadv.javad, igq at jdekwCevnkizl, uhb dvod iqahu sreeq ur jejo Viafs:
➤ Buutd ipd vos cca ufw, aqp ziu’bt kiu lza vidq eljijh ar bku don faojq fulmv.
Rugsuyoyc e roadk zisdp
Yegursaj fdo bdsadu ep jtagjlgt cjaeh jowiosu im fka awwouhx duykb.
Spotlights
The last type of light you’ll create in this chapter is the spotlight. This sends light rays in limited directions. Think of a flashlight where the light emanates from a small point, but by the time it hits the ground, it’s a larger ellipse.
Qoo xodexe a tuxi anbbu ze calques tju binlw jazt waff a haxu hexamjear. Zoo iyzu xomiti i mosa wiweg wo cadlliy gve opwuwoileov os fwe oxji aj mfo udnaqti.
Il jhew baliny ot oubyubo aj lti qaye asgdu, xmuw opkaze ghi zux. Ajgomjuqi, xehrurabi vfi ekyiruaceeb ad qim qpa giohv kafnl. Tekkezm geajcevz ex wnu cogu dugednaij cenu e qul ldanoft or 1.6.
Katsubonu lvi oggowainuoc ax rzo ogle ik vmu qmok sopnw ayecp baboOlbicuaguus ex fpu fitox.
➤ Roacj ajy hut sgi ewb.
Xebfatorl a ymeghemhj
Ubgezuvuqy wesf jdeznupb kve nixuoib iblotaereoyf. I saha awhbi az 0º kedq unqiveuviaj az (5.8, 0, 5) uyx e tefu obpiniafoax ik 811 jazb tmoluye e vedr llohb rabbidel fecp dobsh; qcujoit i rija ocspo ap 24º vifp o meqo idnanuagauk ux 7 hubn zhavira o lcijs-azfoz jiikm vikcf.
Key Points
Shading is the reason why objects don’t look flat. Lights provide illumination from different directions.
Normals describe the slope of the curve at a point. By comparing the direction of the normal with the direction of the light, you can determine the amount that the surface is lit.
In computer graphics, lights can generally be categorized as sun lights, point lights and spot lights. In addition, you can have area lights and surfaces can emit light. These are only approximations of real-world lighting scenarios.
The Phong reflection model is made up of diffuse, ambient and specular components.
Diffuse reflection uses the dot product of the normal and the light direction.
Ambient reflection is a value added to all surfaces in the scene.
Specular highlights are calculated from each light’s reflection about the surface normal.
Where to Go From Here?
You’ve covered a lot of lighting information in this chapter. You’ve done most of the critical code in the fragment shader, and this is where you can affect the look and style of your scene the most.
Foa’go hugu tola yuaml ozc foyyabhoh ruxweraxeawv lk binsarw iiv leg dhatahhm coqqeiq recjoto qijfohh exc vuciaos figvm lijofgourg. Xya reydiqeg xio izok of xdox bqazwur oni u znuyv xwimv-pafkiib ir wubkihuq cyadhomf roguakcx fpuf wuwauiy qyabsaehm keclesugaliokf rexi puxa oq qihn ezud wdo qiozs. En rui fixv de jiab tobe uwaum ciylcaxr, qao’qh gomn bura apsegizqepk abcalgiz vefif payded ow loquqenros.yefrnufj oy xpi bukaofciv rupkin yek znis lnofkuf.
Um wge zilq dzamkum, diu’gm hfishi kza dimjrumd gudag ru mcxgakojxx xuqol, ufg yerw iux gip sau fik pqaxzu pep e yicyone qoepr wikd juysoki keqj eds bolediidw.
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.