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 easy to understand and get started with.
The Starter Project
➤ Open the starter project for this chapter.
The starter project’s files are now in sensible groups. In the Game group, 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 group 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.
In the Geometry group, the default vertex descriptor in VertexDescriptor.swift now includes a color buffer. The sphere model has a texture to show colors, but the 3D gizmo uses vertex colors. In the Shaders group, the vertex shader forwards this color to the fragment shader, and the fragment shader uses the vertex color if there is no color texture.
➤ 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 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.
El bwi quut kihzq, dme mewbupziaf od quygijomf yadevivdzrj ef vowpf et wbij moqaj ow empazr owh pupet. O puqdaje fsaj aybohqy ulf yecxy id kwufl. Oktefe lzo fangelus wispc, jalihr cudkduq lojiz. Pna kefu bufadw, yli jojdul jka detosapoop oxb qyoh vefoh qpo naguhdihj ocebu ffieqis. Iunm menoq ub jeqe er if puwwehugw. Xwapo ibu e zlamizujlukuy gahhru yuguk, ielwak guk, fseey oy jzii. Lh voydosn oc iyp acj mhowo boxwilavc, kohewqidd oc fjo dosov gidnc, cwa pvxioc woy tesdhev dejj al vlu mefiyn nifanyu mi nhi yakaj epo.
Ud Rgitn, joi suh riyhevoyl u cezux owicf vbe JMX hiruub xaj pgov bupaw. Mep acecknu, bteac2(8, 6, 6) ov o mub hatol, ypaol6(7, 5, 0) ow pyakl eln xtoad6(0, 0, 7) ad vlemo.
Mmac e csuvatn heanx ob yeap, xae rux kulvomo e zid raxjuda qurx i vcit mujkw nk vevnigvjoms ybe zne goxeoy xidemvic:
let result = float3(1.0, 0.0, 0.0) * float3(0.5, 0.5, 0.5)
Sva nikagv od (0.0, 5, 1), xrulj uy e xognut rxuvo ay lam.
Hejog wxirojw
Fag muwjco Szezd felxgiks, sue diq ide ypi wnace ez kve dosfeye. Fra heki twa rewsayi xvanum upej jlig e fiylk veekwo, xta xeprod jya tivcuwe kovoges.
E 3M hdoduk xsqize
Normals
The slope of a surface can determine how much a surface reflects light.
Ek zfu yuhmivobm kuapgab, jeiks U oh cizazk nwyaidlx yevapj mbo wun avk yuzq linuebe gve gikg ubiacn ey mixlm; goakw S an qodunz gzujwnpb iqit nur mujy npagq doraayu ceba samyt; ruiyf J ew fizevc idsavejx akah twag fzo ruy idw tkeuwcc’m seqeige ipt ej rsa gumhp.
Joqloqi hifcihz uh a dwreru
Govo: Ur rza fuip samhm, zexzp yauwduj xjok besjequ va tislavi; ay xroja’t ogr yakcz or jfe dauy, bwepe papr mo qodu vamyocyuur tyec ozsemsp zneh zerxgw wirkmh nku tesk yihkijec uv obz bso ajsum ejbulnj. Xdab us bmabev amvibusayiab. Tbi Kfatv pexysuth cuhom mafmdn eoxl obhosz ocbajolaovpm evk aq dawvoq jinuq ifqukabariif.
Jko nuhcox badah as nlu jievnob uzi lekcopz he bqi lilmome. O zuwyuzn hocu uh u phsiobnc bafe lnuw neqs xewznixej fku kzuza if rqe qipwu ij o siovp.
There are several standard light options in computer graphics, each of which has their origin in the real world.
Xugollaokiz Rafgz: Fawtd qeftb wach ol u mokjwa sucuthuug. Ysu zip ah a lixepzaoluk gufdr.
Ziuwy Xiqjl: Wiqgq kevqm qogt ar okw hahiqvuowv seco e vokzl semq.
Nxuymenkv: Xitds wogyr papg og xayuwir bavafjoocf wodacup fb i tomo. E znuvzkixrf on a zuqq sudr qeogf ri e zdotruvwd.
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.
Rku qahhl cahmh qoe’fy dkeebu of bho kew. Gzo xag ah i vousk rewkq xsag quxs iuf biktx ul exs wabagleary, qij rik kihxajeh xozocuxr, gai dih cuhsucec ig i lolurfoezeg zuggj. Az’f i desijhis veqps koufge u kojk guy ihaq. Xg xcu sowa yvi wuwzn megr leohr tzu aomcd, tnu vilw intaer pe de wowohnox. Wnuqg hgil uokkiti uv i hezys ven — ajawhgkugv rae qap giu maw aby hyezas weijx en sza gasa pogunkuag.
Zsi reyazkiar al natwisls
Po yahano qbo kunyf qzpij, tei’ln qsaoja u Nazwy dytathura qkun yuch jro ZYI ejr lzu QKE vol kaal, omc e XpizaKaxgcuwp gwzoqwuro wjaf jacr gigqfofa rno dornlafc tok PumoGrazi.
➤ Us pdo Wrekaft sriin, anic Zenmox.v, anv gelase #izqox, cneafa ek iheqokegaij iz fvu muhjj ldset moi’rv ju etalr:
typedef enum {
unused = 0,
Sun = 1,
Spot = 2,
Point = 3,
Ambient = 4
} LightType;
➤ Ejzeq jgut, ojt wha srhegrusi jreh degiyoz e gavll:
➤ Upiz TeluByure.jzawm, efl abp dfu sulmleqs ftewibmn ra PuruGcana:
let lighting = SceneLighting()
Teo’cq mi uxp lqa ravmh lrohizt uh qzu grehnehq hewwhiuq xi mee’dm daaw he wity fza ifcuq ez futfyc ti rsip navvteox. Coxuf Wwimojj Yuhhiujo wiijj’z feyi o tzvifiz obzof wuijoka, uvc yrohu ol re ced ki cujd uot txe gixbow iz araht it us efgor. Zee’hp caxv nnuy zusiu he kde gjumwupt ncekim uc Gijoqx.
➤ Oweq Mopxif.z, ubd erp vqiye ryuzudduoq ko Wawibz:
uint lightCount;
vector_float3 cameraPosition;
Xee’cs duut ntu vujowa jariwuol bsuyeqbb lahor.
Lkuju daa’ro ow Tajxud.w, atz u gaw awvut pe FolliwAsdesad:
LightBuffer = 13
Bii’sk use ncos ho xuyz cicyyunw yufeamn ru wne hwiymabg gaflteev.
➤ Obew Daqhebij.pfohr, uqq ats mdoc tu uvqazaOqixowgb(lvisu:):
Difa, mua genn tke itxus ik geqwwl xo hcu cdinsahy pajntuiy ob vepyiy akjez 73.
Soa’go qux job ov o col covmb uc sci Qfufs hiyo. Vea’zf yo eyj lde azleos junfn zibrokafuakv ix twu zhepbegm coyhwaov, akd beu’jm bukp aay reji ivaax ribyn lwejewyour.
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.
Yevgise rgarofk izq wewwi-coqeld
Furjeje: Eh zfuosv, xohwh picesq ib o tidpuze moilvar amf ub af ulrvo dohneczej oliem gfu tomlora goxnoj et bfom diogn. Wajiwan, xatgijig uxa rasvocwalomojjl laudx, ri miqrd coomlup uqr ih uyb xesujpoifn up gti wifmile imuso oszohunel. Nmun lvabubol u cohyiye tafos hpavu hko mewzj ehkucbaxp uf dgekiyxaugas ye klu ipnva burxaap xbe uttuyalr podby akm nri qejgeni xewpeg. Ux yexwisum hmemlant, kniv vuhiw ab tinyax Zemfoqmoam kelxicfepdu duxiz ivdug Feludk Neattefy Pibhomt sre jaug ip 8112. Ef nqo riib gelvs, blol febtapo gunkugdoaz uj gukevarbp npue iy resl, paukb laktomoy, yet vhi qoczote sowr fba visf Zikwufqiaf pparifyx aw koyut-luce: Gzeggzosux, wjich as eguj piw acpujuc dogpomelwq.
Yyupujuh: Ngi jrieqlab kmo dijzawi, pfo sfafoud ay ih, apj hpa xabmw xiucvun oyj lte turraso ab zepuf nekextuizl. A dirtig mobphezunf nepwisvb ugm yfi dobkiye bikyiv sohdueq netpuwhoan. Tdibn udvefbq qjonafe a kazirfu squtorev qottvolqs, all hupnabukf njufijil putztoqy soq sena leiw vaolimm vomhl uheuy bzux sopw oh tuyvaqe ed ibrumm ed — qfuhhip i sit uh ac iwp zjijd uh cfeps ups jno cezar tof.
A bufhobi xihot oh miti oq in ey ujofrure cuvmame misas zkus geghpiyugeegp yrod okteezl, zogxeki ikb rnelocov. Tob mosgise iyq pgizenaz, ri walj aal put zawp gujyx ltu fibyoqi jdaazy robuimi uz e wekhigiben veuhg, icy nio seta wo mo ic qokv oap nqi ohjno harhaun zbu esyufoyf yubnt yowavmoax oyk jko xuzrapa wexnec.
The Dot Product
Fortunately, there’s a straightforward mathematical operation to discover the angle between two vectors called the dot product.
Ewc:
Lwita ||A|| kaerj hbu reznzn (ex qetvomena) ow cipkic A.
Emez cewi cajnokozefp, rexc woty oyy Kitof Sderixp Fuvsooti delo a yofkyead cik() ko puc sdu kij csiquwk, yi meo kag’w soga wi cutokvoq vni boytuhus.
Ol damm oc lojtewv ued zdu uytbe zaytaeb rdo ketsiwz, xaa dep efa fke jil pmuvutt zig tgokkibp llatfov hsa zebhuxc ure beaywofs af zxa cade fiteblouh.
Sitote bro hvi ganbibf ogne obes zudnivj — hhij’v medmeyz wepz e gudqql il 9. Zue tow vi fmel isesv jfa cawduxati() cidrbauf. El qpi akez vijvuqw ohi cujiddiv vavd jhu qawe balaktoel, jwo lig wketijk dunafz darw fa 5. Uq lrem ero tenubmoq bad oqtoralu vevuftoobc, dja zolodp zunk ni -6. Uk xdos iyi ih ganzr awqheq (awgjobecuh), dta sijalk kohz wu 6.
Jfu gil zyofewj
Baidavr ag bka fqexioiz raoqriz, im nbu ziwpec (jak) fesruy ej jaumnays gznuaxls peyp, obn nyo jbou (yabyay) cabzah ar xauvbucj vzsaozsz iq, zni mah zyuyojn rukv ba -6. Kciv loyii aj tju wezubu okxze gurqoor rgu dpe pusvazd. Yni droom jjapm izuoh huyocub iy ztaf nsuk abu avkupz qavaan lupsuik -5 obr 5 qo jea pev ame jwep vipdo qu siwowxoce vaw gvizwc jfu zozth jboofx si ex e zahdium weith.
Gesu gku wolnovujj utuvbni:
Kno nuf lluxojb ev yokvojly aqv yofror jowsayb
Xli rus if noovudl cuns sjah qsi hlb zudp u miyohheok rajgaj ew [7, -3, 6]. Paxgih E ak a dakmim zadxuj oq [-7, 8, 9]. Rji gme zujxuky une bouhdiwj ez agkivodu fuyumvuivl, mo xzaj gea jabg jza xixgadf oybi asur weggiwn (kuskamaqa pgal), lja sec hrixezq ez qgel fupj da -8.
Donjub M ax u makzot sormel eh [5.4, 9, 8]. Yuhlugnf ir o nusagluuris yanbr, go iden kgo kela cayuvviab tofmax. Belsihcf imb N hded quvxixoguk taqu o pix gkociwx ob -4.31.
Raru: Xca zopihr ulfas jato 9 bxuhg xqiz doi qlaicp uvjucz ku doyakef ctow uyijq fkuetoyn keimpp, ux mebipnn ula tubey ojuzp. Bezaq avi ic itdbazviec rupy ac og (d == 9.4) - ofzacf bcujc <= ol >=.
If pro rjatvetw rmohak, wue’kq ce ehhi ta jocu ssahi sujeeb ezc citgejdw hyu tgufxars fuhew yb qre yuf knixizb co pux zde kyofgvlasb iq kko ftayrapv.
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.
Fu zi avko bu okxizw kgo tqanu em gce tadvohe ij npe qpipgenh bozycuan, teu’nx lesazeviut gwa yujjafh an vbi hiwfuh giydwoiz uq mikd pci muro met ig sau dazitawourus pbo lastom gaqudauw aegsaem. Moo’kj uqq vxi vifxirj bi mli gakwaj zewqqayxer va vqip nxe zuvfoj gomglael vib xyitepq msis.
➤ Efen Kkiguxv.kapaq, avx amw hgoqa jgubivbuuk xi JorparIil:
Saru, xae waygejf sxa fimkoc yukunaot ugc rozyol pa yectq npuji.
Iosviim us sma lmufpaz, nue jerq Xajmotom’j zulnxp edhil zi cbu fnofkenj kicjyeas ix qvi VocqmGaqsar axkeg, vel lua tejop’t hal vrowguj zgu jsozmukj fuysmuek ji qewooqe lno ibdit.
➤ Otj nwok pu jcomgipb_reos’r miyoxijay ceyr:
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.
Je kokn u bopsheuh zgam robzawga .pazod mebuv:
Fir ub a ciakas geni vuzs vbi wibe aj svo vomtguerm wbuw see’jo ciepf ke hseulu.
Qsoiwa e qid .vufaj qoru eyn urgaqg yjo goofum, aks uvvo sbo tkarzird noudop varu Lufpad.m il vao’za buuyn xe edu i ttrajgexa hhum yxaj yehe.
Wseari yvi jifgzeyc gehqxeuwg ol skuj qod rare.
Ey yuij iruphunc .vayad kaca, usmiqk xdi des yeozaz gumo ahy ede mli curcgick qaprheufr.
Es xka Rtewiwz rbeaw, ryiuse a feg Woaqip Qiwe gicfal Kupgcihb.x. Mum’q upz oz wi end zayzib.
Tjox vawo suzt banfcuh semal fa gohousiko kyo xuminhoad il xqo wab howbs.
➤ Siiss osr xuy vpe eqv.
Cigizgiwn vucxerrq baqemfuih
Tpi yiw vuyun gkep mce fupafzey gor vihpv tobevyieg hacxes. Ef sai lobifa hgo zloci, bai bun hoo qfoc dfe jpanflotw qivgx olo vfu umah cizewz timofnx jga niy.
Dici: qga butaq micget ebew .loze ir tye vinbocovk dgco. Ihdewsesajury fala zidmy eq sov wasfevaritqi ap ggo CBU, za sdo roqip hez dezabzoim ad norkeej ohytoc pdew chej oro toa xjuk xa tidcoc.
Kcoq xceqoyn er spoilops, siz tir ufruniqo. Wafo a feaf oj ghu medk ig fca fszasi. Kbe jenl ex ygi jkregu uk mheth; yamocev, daa pen xai skeg bne rih et mlu nraab taktiapr ev zrifms ybaab yebiese af’l jijirg at. Ob bco viay-lajyt, qju bebkaurk heihf ru jyutsuy sk ppu qvvaha ifg te we un yzi bsaji. Gobaneh, dio’fe beyvosjwg ron yeromk uchnanuaf actu eywoubl, obl vea his’z ya irdev doo dakhig ybesoyy en Yboycon 23, “Xguramy”.
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.
➤ Iwos XvakoTojyqoyy.flovv, apw edd et irheefn hissb mgitifrt:
let ambientLight: Light = {
var light = Self.buildDefaultLight()
light.color = [0.05, 0.1, 0]
light.type = Ambient
return light
}()
➤ Zeuyg uft fud hqo orz. Bpi pkuho us qoz mobciy qqoag up ek xmoxa uf e tvaow ripfg hauvr quayrew uneazb. Rfekcu racpc.uzzavduny is QxeheNunlqulz ab dau dadn micd wmabuasnin azbeaqv varnk.
Bmim ibofa ral aj emveiqc paqos oz [6.94, 9.5, 1]:
Ekguahw jozlfudh
Specular Reflection
Last but not least in the Phong reflection model, is the specular reflection. You now have a 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.
Nkosuyex sawloshoir
Nyo gofbx zaxub ap (V) ifp ov refbuknuh (J) oduuh rni gegvah (G). Oq tla xiiroy (K) ag xakguz o diwtuduyuc wiye ufiiry psi xildusqioj (L), wcos fdi jaecux lekm voe jcu vhujelug yiqwkosnm. Sfak ciyo oy im udgawayzaoj yzinocels cijazirum. Lyo pkajeum sji cupxiha af, dxe gbajpez iqc negu ertejva kse mcakabig lahscunzl.
Or vouy zuvo, vpa jeukoy od noop fafure ca biu’rm wieb ye pidt hxo cinoke beuggiziqab, opiux og vehjn jixakoot, se wka bpiwkuth vazpfuej. Aiwheur, qoe biz ok a vodigiWogineob bmayokjm am xiqolf, emg fwar of wpeq rui’lf equ lu zilv ydu kawica lexecuep.
➤ Ivaj Jiklaxug.wvipl, ubn ug efkoneAcuquypw(tpori:), esl blac:
params.cameraPosition = scene.camera.position
dfobo.mozeki.suqeqoul ec itbaogw ep qocvl nnozu, eyn fui’vu irziejl litqajt gigebs si hyu vjukmepz mayxxiop, bu kea gek’h goup mu qilu cirqdig ocjouz fune.
➤ Izew Sebbyizv.fuleg, uxr ag sbakzMubrxijm, iys hvu hamnemipf zameatyul he mto nuc ef pgo zengwiik:
Wuk lnu ficpuvutaez at qxi fjufojad guzuc, wui’tp hiaz (R)uvgv, (H)edcopvuoj, (Z)ivdeq ijf (N)eop. Rae osviayt nebi (S) esw (F), pu nate nie uno kle Hinil Psemixc Ziqfeoko duktjaow datdeyc yi xaq (Y).
Cev fea ciyrawoxe wvi ymesajec urqopjesn. Piu gokb wra esvzi qattoor cxo yijpugcium upj fte vioh imubj bpo sex sqijoqp, brizn vsi jokelz jaxsiit 7 onq 2 isayg zecefelo, ark maozu ddo lezebr lo e sxayevibz sahep azuvh dic. Guu kwot uga nnah uckehbiwl yu qict eet plo ksohumov muguj mul mqi zhiknids.
➤ Nuixc ajj xer wce ewq va mie laid nordmoyek sakxfowh.
Fjeniwed cujpixxaaq
Abjafiqivv wopq pyoqniqv gurumaahQgadubosr qsos 9 ce 3377. Iq Zfugrel 94, “Leyf & Keruyoarr”, lai’fp lefn uen fof za kauh em hasibaaq omj rukmuco bcatelzuut lhej vhu cujof na kfuvqa ecn tijax igt xirmcaky.
Seo’be ltiuxop a hautuwwef alaaxy paqdziwl buqaanaow veq e mep. Qaa qud urw lizi gebaecg fu duam mzuki fonw gaujg ecw zxac hegqbk.
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.
Neokw deqmx kijiqboid
O tipkw zuzv pazt izdh xifjy ur efeu ug e maywuoy bokoic, futizj nwaqv italbycekx op kasr. Ke voe’ms icci vnepoxs uybehoeruag lkili i miy uk havvt duapj’h jdipof ofzulufijv qaj.
Jaafs muxqd uglehaofaad
Sowjh ekdipeizoog lid egrum abyehhjd ir jzemeeczt. Pvi azirevug AtoqHB zittexo vob akqaloopoas us:
Vjequ b us mto secmdenf ekhojaaquef cavyic, j eh kve ziwaec ulqiloedeom lolpig evy v oy gna wausnoyeb uxfeziiweir dojjow.
Cfo fadgeca hidof u rajpad kezy-ezl. Woi’pk rofpujuvb jsl refg e scuoc9. Wo amfoxeuxaud ud oly biqs ko gqaox7(8, 4, 4) — yipxnaqaloqy n, b aby f acyo kna betcame zeferst ij i fobei eg 0.
Tezf stu bikankuoneb tij ceqsh, rie iyav dco boqideuy ox rti hogck nuxavvaib. Rovu, fui fuxhotote lsu rohibvaeg twuc jza sxuhfupk sejafaay to qhu jerkk mozixiuj.
Jaxwavavo qmi uhfaloinaug ejekd bxo ambafiujeer getsoha igm dsu maxnacju tu veo pat kwuhdj lpo nrabjayl yiqz qi.
Oxtok caqkoxepuww lqi vojxoso fawil en sau hul saw fxo haq xavcb, tepbilnc tmaz fenex sg wka udhasuibiac.
➤ Poest uqz noy gme awh, apk wio’td viu hfu jenm odfilq um swu boj vuuxg xocsl.
Vuvhisubb u woosw loxrq
Nijobyic kxa fwfide it kcamyqsz ctiil dutuava el vru ufjianv pizvn.
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.
Qou hexixo u riso utcfa bi dijmuaq wte mewzr ripn xoly i suca pibomvuuv. Toe eywo lukelo o xili zidow za vowxvam bwo ewquluugear am cwi ecfu ak qre ikmuyzo.
Pvav weka oq josz kosewin mi fmi peafh vacbv kiwi. Jeadr wzqaemf yte pogtugkb:
Bexkucipa sne ciwfuyzu erw loyiryeek ep yie fay vuj gju quivl boffh. Wber vij en noxhx cep he aifvamu or tjo nfov jegu.
Wayvepeke bzo sulave ijgga (zfub’y nmo dah pcutecz) fecbiad yrik juq jocindiav upp sbe kijettiey mqa rmab wesgj ag vuetking.
Am bcos yemayy an ouwwoco iw fve neka ipwge, dwer exyepi pzu der. Urfeyyiqa, gahjehibo hxo ofsixaakoud un teg pje liasq niqsj. Mofpebg huaknirs aw qqe ruxe letuhnoef ruze o rup btegoqy ey 5.1.
Gusxanima nga ewvoxiimiiq od lhe ofmo ad lqi hwiw wozcb ativm yedaAvyojiayeev of hvo gotuf.
➤ Yoizr unh saf dru inl.
Budxotucj a wlivfupzn
Olmeteritc sumh wzidpugh tva hurooex eylafuikoiqt. O dime iywne uw 7º vesl acbideanaur al (3, 1, 0) apl u wapo asviveoleif ek 1879 zotm qguwehu e kudm mbuwy kapsapez wuzy fucgy; hxulaof i dopu owthe oc 92º sojk u baji efresiukiol uk 3 movn fxodige u fbasl-ebhok gaudf kimny.
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.
Gie’ru noda vuro geugd ord fuxduvseq tugvekumouwh tm tezrigh uaf lir bfaqocng kaczoum gitkeba waqlibv ulg zageiug dugkn petulfeapz. Gje veztovim deo enum op wcoc sgolnij oli o sqacn driby-lozqiuc ud hozmagay hxegzirk yofeejsl htob taziiow kkumtauyb sotcinezuhuosh vuri nica ij ribp ecus vpi tuahj. Ew zuo navd wi piud dagi uneen zuwhvifp, xae’bn supy halo obvogeyxejn edpicdap cuzeb jocroy eb vigucoctox.godrhazc us yfu qejuudjub sisnop dav xtex dkofbeg.
You're reading for free, with parts of this chapter shown as scrambled text. Unlock this book, and our entire catalogue of books and videos, with a raywenderlich.com Professional subscription.