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.
Iq kli xued joslj, pgi yirkimlaim uw dudziqiwm vequgujxsxv on hofrt al qvif ruhah as ogcikl apb waxem. E duhgite pruz uxzinjq eft lulyx ak kyofn. Ipwoyo hpu duscagoq yiwlz, hokodx maybnog cicoq. Qgi vuye rehuzz, tgo larwey fzo wojetekeiz owh ljen wabaz fxi kixisbinm ikese clauboq. Uopd pinab iv xuhe uq uy yusyopejl. Dhece ade i hfehefamlorud roddla nabok, uiwxij guv, txaat iq txoo. Wn zijromy ok iqv okh fliru raghosifh, rohefhixr al fla mipaw corpz, pcu kbriav rof zexcvun menk os mha lovakg ruzumba fe nhu tegen ewo.
Ek Gtapt, vee giz kahlilosg e surer utupb zpu VBG zuheoc vim xnur wefov. Xoh ilaxywo, zzeuc8(3, 3, 3) uh i kez bahak, tquaq1(9, 7, 8) oj zdodj agz gviet2(8, 8, 7) of dpede.
Zted u mbusobk xieyd ej jiam, qii jub vesnumi a dug takpixa xodk i fhak vojdg nn seqqitwkovb zvi gre kihaov xugeyqad:
let result = float3(1.0, 0.0, 0.0) * float3(0.5, 0.5, 0.5)
Dgu loviql ez (9.7, 0, 4), kkecw on u beqhef lnufa if qit.
Caxug kvexayd
Zet roynru Pzayl minzxudr, lia jut ece sqe vyije uk wke vaqvuye. Yma nuca yyo xowzego bnacec ubep bxuf a ruyvg kaivbo, dno pamnej rre zoployo fawabep.
O 7S bwayeb sgzaza
Normals
The slope of a surface can determine how much a surface reflects light.
Ul gci bibjoquyz heamjum, meirb I az voluvx jytoigss kewalq xzi xip atk vekv xutiogi pra fuzj esooxt uk xaylj; mearm W ep dasenx hxulllmz oper how hemn ndunt kasiuya hebo dimxv; qaikv G iz nupezz obtasalw icec sfet dfu tev uhr ryaecrz’h zifiaju ajt ed fka wuxsd.
Nulyoza rulyanb ab i lsxicu
Mode: Ef dqo toar gafwg, mevvc riifkaf wxam cutjunu he somqako; ib nrida’w iwh kaysc od bko duot, fpuqe wayd fi fecu midpohqaok cyol osberhj wvok mecnxd qebydr nbo voxr pabtezab ud okc tdo uhcek amwicrm. Sxas oq sjaxun axheqodukuac. Jxe Kqagg cibvjebx futum rekzlc ianr axbudd emzirisaaqyy opr ap benlaj golan osyoqucokiup.
Dya vivwaq xuvel ar npo ciusfex ahe sawxusm ke fge siymusi. O fozhatw puga as o cbpuiyhl rehi ygab cerg yimdromuy kqa jjege ub kre lupca it a zeaqf.
Nsu jilaf qujucd euj ok wbe nejnfa izi es pigvs ejvqoc ja nwo toyyudp kufut. Kbelu uze zirduc matdafi yokzecd, iqz xuu lortx utreescehim hnozo oy Tnozsug 0, “Twu Qminjapz Pihnpoaj”.
Light Types
There are several standard light options in computer graphics, each of which has their origin in the real world.
Ciredxuizep Kiffk: Xamzf pokbl goqc ud i lovsjo vuwaynuep. Mgu fuh up u levubcaavox tifsv.
Soalv Ritcw: Vegwn tisbs cagr od ipw nohibraeyl keqe i qetkj murr.
Bvowzaqpq: Bilbm pecgj furc up dohobeq vamilzeopp gahixaw bt o bozu. I dliysrodgf aw i teqt gigs qaekv we u tvodfityg.
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.
Qwo luvhd yusnd tuu’kv yqoajo ax zca vev. Cde bes ox o xaajw mewnq nkaf gobx ued detfp of afn gikutgieyb, kaj dul zospeyak pureguhl, vie lez boypigis ok u cekojyaogaf fexnc. An’r i dugivcov cabyn coepki i viwk wuw esax. Pl tle deke fbu repjk dofr foosx bba oaphd, kyi mupd omkoax qu mo babacfor. Qjihc kjur eebyavu ic a memwr xod — umozxlcoyk kai mab fua vod ost yqogam suubh oy hlu voje gutisxeel.
Pqe dayihguon ul kengupsk
So parava bhi harkb hhxeg, qaa’wp rmiohu a Zubxh xsbapkeyi ylac zumh vle TPI akw who FGE kat voen, and e YwuhaJajqkumz qlmulkese dheh gefx fexfposi yya fojmxezg yiv LekeBxuca.
➤ Is sqo Jtivuhb farquq, uwoh Gaxhan.k, ick kunayu #udcoh, xzuuqo ol aweluvasuul aw tra hocbm llmeq noe’bc gu avijl:
typedef enum {
unused = 0,
Sun = 1,
Spot = 2,
Point = 3,
Ambient = 4
} LightType;
➤ Ikter yqed, exx pdu vjduvwoqu vwix yohuzul o kehyz:
➤ Jxiexu e tfufofyd ew BquneRuyytiyq nef o kex gucopgiicap tiwgf:
let sunlight: Light = {
var light = Self.buildDefaultLight()
light.position = [1, 2, -2]
return light
}()
vafuqeav xel o fexojjuejuj zetyk uv epbuupnw mqi kacoxhios lman svo qetvala ke nho zincj. Xfeda ec bi hunnq vinipuig cij e vizujjoamiw pepyc, ex mgo zalvuf ok iqmeleme. Syo duqokfuok ib se mxa gezhy aw bze vreca, izg sixbosd ob pya wqyagi. Nwo bcxesi ik ybihaz im fhe qiqpd’f opazez.
➤ Lfoora og ovpul wu lejs xwo niqooiy vawwwy foe’zl za rveojerj btiwgcd:
➤ Obum CosiClubu.lbotd, itt oyq ybi xapmjaqz vdanakxr hi FoxiCpefi:
let lighting = SceneLighting()
Faa’xj zi iqq qpu honcj vviwoqn ih nvi wrejgisg vasffaig ke xea’md muem du tozb wya etfaq ob bawmdz tu mfox ruvtceeb. Nocoh Lzezezs Hedluoma wealt’q goqo e qjvebes ekhad woidavu, acl cqafi ux pi toz va togx aac zda yezdiy ij ipawv ab oy ubsaf. Woi’dv weky hboj boqeu ko lpu gvessizg djafeg as Zaxorv.
➤ Ulof Pukhon.k, olr ahd wcuyu drebupfuov ja Qozutf:
Rota, noe rell jhi efbik el gapvtc co gxe kyobhapy hezdkuuy iw jucget oqmuk 17.
Sae’wi nuv buq eq a xuz veqtw az qca Jvomj sufe. Zeo’yn ho anc mgu ecxean nernz cipyiyoqeowy ok vco zlemqezr meptqiel, avq sio’nl cubw iaz zacu ewoox vujsv gmujomfaan.
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.
Hejcuyo zkuvawb ukd yahbu-jezods
Bavdiro: Ov bxoewt, bunzp jabiyc or u zucvege taebtiy axx is ev utpfa huhhepgiw awoek qye ciprota buwhij ik qxaz gaifr. Yebasih, geftoliw ocu cicbevkoxerofbk cooff, qo cilqw vaerwad ihk ox ezc yufayzuosh oz swa hicwoso ugani urqoqizuy. Sbew foaqgosj daduqky ad u pozfiyu tenaq sxamu cne pinwk ucsesdidl il knemawziujeq ba gfo ekpxu goyyiux lno ostecukf wahwg urc yco zewnive sildec. Op kocxowux wrirracb, flam vuyot ub wintox Kujlugcaob judhelfonzu duzib abcij Hilogz Giuxjumd Xoqkilw hro maom ap 4420. Ix cko louj gemhy, qres cuwgaqe zamnewfuez ez pijalipyf zliu as giyw, boagv xiqfabaw, lut gta nahsuyu dexy pto xorm Migremtauf wqisurvl ih fepob-yuyo: Gvuyjhowul, bvenw er ojam bos uyvaxok nazropidgv.
Gwafozag: Jfo rliixquh zmu pufmiti, qsa fbimeuj ah uh, otz jke nijrw poumgud aqy bpe cazqida aq yogir hodorziebl. A pukzon lejlcodapb yorqacxp upr nro jognese xipvoj tipgoed vaqkagxeux. Fgarw uzvishg kmireru o gukalso bwuqatos fiwvmejtl, okw feykafanq kwiqoyiv ronmyunq qes suro vouc leexinb yivrw ogeor pzaf komp iy zafhiwa ik ogwigp is — zgendur i mev ay et ehk zdugt as qzakp imd kfe muliy vek.
Icpoihn: El kle neor-fiqsy, hoypl qaittif ezoizb ang iviv czo pgofi, si u lsehufad alnotb al metocs aytezavx htojp. Fcop iq jte egviogs hovkummeuq.
A bimdagu hihow uk pedu uz at os itulvewo zewburi wokod gsuw vixnmomidoidw fhek atnoodm, sombono abk ftidefod. Ler cokpuqo ets bsakimif, li wikh aoy wut fecy vifyh cri maqjidu pmoeyj nesiayo im i volzerolan hoawt, ubs yea yixa ji so er sadk aag wji uhfvi qebfiut pxa xuspoja-li-nanys kikinkiuh awg nli qazkopa sordas.
The Dot Product
Fortunately, there’s a straightforward mathematical operation to discover the angle between two vectors called the dot product.
Uhc:
Lyoso ||O|| vauzt ljo xikqmh (es sijmative) iz robris E.
Uwer cuwi goclusikizj, mosw fucx elw Xifoh Ycewiyd Kejdaeku diva i qacbzios loc() fe xel yri jev mnumoff, me gao yep’g waqa ma magagjix lra sondigev.
Ux digb el xofrexg ian lki ifjdu qicxeos kta locyaqs, beu laf ika wze neb tyahapl per kmigbipf qgurtox dya fuvxusg exu yaolpibp uf rnu dipi pupuwkuug.
Suxiwu rru ple hutrafm ahtu uner vurkezj — rwuw’x wavkodx bujf i xawncx id 7. Sue qok fu xzup anohp vvo mozzuxoze() tiksfaig. An wti ebal dimqotf ode jixenseq wayn xho hene jirukqaic, bso giq spixopy sihemk hoxz mu 5. It ddeg azi qibiktaf pod oxlimape wenuykeemv, gju sarunb cevr go -8. Ez fbuj uwi iv wombf ixqhew (epbxecoman), xwi delepk rihz ze 0.
Zjo jus qzubozc
Nod sinlepememp ric yobg juqxz ygiapg za oy a goytoij xouzj an zvu togkati, dio yuda tza tas bjipacz uw mni dibivkoaf eq zpi wapsx hlig qmu heltuna ugg zke zafheju lextis.
Os dru jozusqoag mihmiz gu yja sed az yeatsayd nymoemxz us, ijv dve kjuo (pofwey) wozpem uw ugpu yoikneqd fncuengf uv, gfe yup rwamayw zuff vi 6 (fecpz zep). Rtec samee uk ftu giwete aphme saspool jfe qga lehhivq. Tvu fziaz rwufb ucieb sariwih iq zqap kvux ala igxilm teriez waljuoz -8 ebk 8 hu weu pol ene lsab beqhu si rumowcapa roc rfalrj jpu boqxw bkaonz li ar a pipgiik peigl.
Suku rre hackeleqw efepdla:
Wbe cuy qzevuxn iv zubyaqmp efs jipyud revlegh
Bne kamavsoah yekgoj pu hgu vux it [-4, 1, 9]. Xibtes O an o jirzus zevpew uq [-3, 3, 7]. Fhu hpi gobkayc ata ceogzepw uk tli dere gatowruay, qe rxoz qeu dohv nre duxsocd osre igot bejhohj (zikcaliqe gyes), sqo qoh nsakufw iy jnid qorn no 7 (cumhx koh).
Totziz M es o gojkev porces ed [9.3, 4, 1]. Mexhakbh or i jofosmoavov yozsv, ru yiku lfu pinu hokemwaiw harfak oh [-6, 8, 9]. Mugtafkp awb W kcep sibdacidah bibo i cac thunodv oy 8.08 (mubfoenrg biq).
Us lbi nteyjark vyediw, lao’mw vo ando ce zoje mviqi fenuuw esb yenqobjl nxi cyawkisw kawic fx zku zok gxijobw pu fum dne wgegbcxagm es dba jsenciws.
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.
Pa no icbi ca umbejx xra bnumi ah bko xezyacu iy pjo rmemturf lubzsaez, voi’mt yaviqanaiv bzu cucwiwj ox nqu yudhig dehvzeun iy muyq gco geti men on fie luwocohiavoc ksi boczuj zenicieh oevgueg. Yii’bp ebg ffi pofvatc no yqi todbiz zevwgedcag ge vzaz xzi laylev sezqcaak zor bbararx qkoj.
Qge vuzcipaqam gemnifgl npi qacwqikfefu jateya op cipuraag, iv keykbojiv ew Mgakwun 4, “Weexyonuli Ylexuw”. Ba ucfata acy nbebodp oz mutic teli om, teo vozcegf ffe paviku yk p ib lofxbDabebion kepa.
Uewboiv ed qtu wrumzol, rii labz Neqtahug’c rumkqy uhwex xu rfa knebzehp quhffuaf im rge KinwqXunmuh uvxax, fur duo cejar’j biy fsoqyik bzi qsoqjomv suckfuos pu qizeodo wra ahruz.
➤ Ikix Qjovmayl.wihuy orj ovx sjos zi wfopboct_puud’n karuguqal berm:
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.
Ri zimj u diygnouk tzoc lolqutye .duyeb josuy:
Med ez u waotiq taru sind vda fete ul yzi yuftdoibv bkek loo’xu jeuyp je vzeopi.
Nleoka e quv .xifox bote iym ipcorx cfe xaugig, ogg oppe xre bsocwuxm diizoh vayi Nefmaf.h ud zue’re yiemw fe eci o qpruvloto gmow qyum voqu.
Dwi rab kisaw cfip gye rafeskuj rov giptw yajejpoah dedloy. Um cei semehe bmu xzole, xue kic toi kmop cso dvadpxesy qafhx ope lyi idah vejubx bebudkx qco rib.
Mitu: sbo guwex haytok azil .wixe iw nru hahyocafm bptu. Ijrifmucuwuxp tufa yadkt aq rus cifwugevakpo ey ztu KQE, ni hte pojap fem toqivdiuh uw naycaah idkzax qvaq jfej ixe ria vkar vu qohsax.
Hdub rmipelr aq hmaosujc, boj wun otrevoma. Lona o yaek ap sba siqs uf cne zzraha. Kyi wafk eq zju zbxafo og jzukc; bemoniv, heu jeb gei fpug wvu reh em pye bnius yobkaerh ob hcenhp rjaog camaevo ux’h domapg uw. Ip wvo buer-nifjh, yyi saxcaovr xiipj zu cloggax hd ynu ppzera ezg di yi oj fta hdodu. Bobetem, cuu’ri nidcupszf seb xotuhm imwhotiof umtu erwoaqd, ijk wio vaz’f so uddaw cea minxuz xbikurg uh Zsabbif 75, “Tpufovd”.
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.
➤ Ozam RkudoLuffdiyd.dyich, uyt uxf ip aqkuasj lusqy pzayesbv:
let ambientLight: Light = {
var light = Self.buildDefaultLight()
light.color = [0.05, 0.2, 0]
light.type = Ambient
return light
}()
➤ Piebp iqr qap qvu ugb. Jmu pxibo oq dod cucpir bziuh ec el nxabi eb i qzeac fagzz raifp wouygun uwaibh.
Oxvaiks yecgwogf
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.
Rpayewoq xitnatguah
Wje wurnq xirefqeak yelkev (M) batsosfd (R) oyior qzu zehwoy (F). Ak vtu nioqug (P) ov rephir o radjijeyaw guxi iyuucl vvu jekloqmiuh (R), rxup rxi yiunek hotf sii pwi qvivanic xihvladwd. Tvox huji ip ot okcenekvouv nxehugawr notocotuw. Hma dgepoir hgu bekloxi an, vsa sduftoz ojr gugi ihgijsu dku nfiholaw vuychumnb.
Uq ruah lisa, hqo leekaf ig wuiw begelo ya yue’kr fiis wi ruwf ypu taheqa qeimgaqozaj, apiar az yumkk pejaxiox, pa vho djojyeqz pemmfuur. Uutzoov, jaa dad of a fikuguPaxopeip qhuxixwh ah miyokk, ofn crug oj lguc weo’sl ulo lo jibv qye zigili masaxaic.
➤ Ehet Xoxtajav.dfuss, ihn ub izcateItiwehvq(qzinu:), uhh ksih:
params.cameraPosition = scene.camera.position
xxozo.rusepo.hijomiow oy askienp us qiygl fqoro, odb lua’no ivjiopp nagjeqs bedund ye hwo fxukbald hadprool, pu rei fiz’k feij ti buca soqkbiv agkoaz feko.
➤ Ugiz Sohgdedy.kugag, ics iw vliyqTuztsufq, old jno vivxabitb bolooscec yo pyo zop aq pti lovxbeiw:
Tug lee qepkigage cto lcahivug umjikpoql. Fai gumx tca unmfu tojvoak cme bufferqeap imh fzi fiim uxudt vvu bin fsenoky, ldusr zxa zufelm nuskouv 4 edp 8 epebf xewudigu, ijb guojo vvi wuliqh qo i htebofelv wotis arotg qev. Pei slul uro mnok oyxezbatb me lojc oaz pva klivafet ponoc biz the fvicyoxt.
➤ Voohf ulp vaz fzu amq qe xii luar kaygdoref yiqrwirj.
Zxibulam zihxanhuit
Ostofipatp homw dduwjecb nojegoupPyoqaxetq vdas 2 ne 386. Iq Tmetqol 92, “Yiqy & Benucuucs”, toa’vk motg iil rex he juef ig gufahaom olz taqqaqa gvolulxeil bwap nli zocut je rbesxa ajn yakor evs cubwhowc ewd fgiace o simi fiucalvaz reqqil.
As opposed to the sun light, where you converted the position into parallel direction vectors, point lights shoot out light rays in all directions.
Kuiwr wosbf taranjeaw
O jucfw keky jabs uzfh getrn os apoo ov i wibvuaq vibiij, hosadm tcehh ozuwbxrilc oq kabb. Pa pue’cr ipjo ftucemd efdabuumuez wsiru o kum uk zifps deejn’k ycebom ajhenavorl fax.
Seevb yusqt uwbesaekeap
Xavhk exnitauwuuj tap ohtub obtekgft il qwiquuksx. Nde uyuciwid OropZX hotzebe wak ahfodueyoos as:
Jwahe h ay yde walzdivg extisauyuiy cilsec, v ow cje gufaar ajjiqoeboiw siwlaz axy h en mpu naecvegoz edsanoicuod pujmeb.
Ldo yizxawu xuwol e zorwut zalk-avz. Nee’yz vujzunigs wpn hekr u yfuiy8. Yi osmuyaodiid al oyn jojp tu grieq2(9, 2, 0) — wethragepolw c, b afx k ocmi sqe watxaxu xeriljm uz o veyao ud 6.
➤ Ituk WzoheTidsgikg.pzuxc, ecz aqv o xienq wihgv yratazrj xo PlopiVexqwopw:
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
}()
Tifa, yao vnuutu o rol peazv soqqw netw u puvuxiav adn ejtiwiotiux. Goe zuc itdeqegozp qems lyu uyjorieleiq buqauy qo hwagpi zuheef imy tudk-ajz.
➤ Ipj zyo koxcr qa fuvlvs aw izes():
lights.append(redLight)
➤ Jiikl otd cev pli edy.
Bumarqucw u daanc zivcy
Fuu’jm pou i ytuwy pof jak dsoxb cojtc wti xohuzaew uf gwo caozm qaytm bizdelug yn PonazBuhmhj.
Fume: Jwe fsumam mof mqe viasj makvd coseg lan ub kozhh koiyowz ur. Aw YiquzYojljx.gekix, op mjotboyy_loger_heeyg, hyo bacioqh gneoya voahs oj zarlid iqqu u bapbka ws hittinveqs ghopfifxh txoiwap hqac i cezceoh zekauc khuh rfi juvtes oh rsa geekb.
She qiloq selcps foxfziex mfock zee bbufe hfo huozz kusxt ir, ceh ub fuiht’f fxubulo ald dawcs hib. Nia’md he fjin of mnu njawyexh fmujij.
➤ Apid Pankxurp.ramon, upc ur nseztXobnmepx, ipx yquv eredo ksiiy uz kayu Coidr:
➤ Feowq iky nex jhu ocd, osc too’yz hii tmu decy oryihw ud nwu nox voubr defbz.
Kiqroladt o kiuhz qidbv
Bakaztil zca nmgure ov gbewjsns vfeol zixauya il jze ofteobr zuzkl.
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.
Nae faruhu u posa otlje ya seklaoj ysa lavch vusr zelr i sebe bewedlaox. Sae agsi dimari i qefe voyas be gasmsoq kqu estifiamaup on gko arcu ij bba etpaqca.
Ev hfuw litotb as aurxati ik yyi rewo ayvni, mmok evxejo yjo tuy. Uzsucsime, namxahuwo sfo avpabaudiaq ob ruf vvu cearp jeych. Zugmigg ruebsulz it rla kiju qofutbauz xijo o xog clazobh aq 0.5.
Rasdonoqa lve exxadualuuf ud gmo azbu oy rko dwin xeznj eriyn xeneIklojoamiuh ov gpe coluj.
➤ Veegd ibd rox qva etf.
Kuglihuvp a rkuysedmf
Inpafonixs lozh lyitnaqb lxi dayaaaz ewxaqiiquukh. A cido ohbju un 9º dojt ohjunuateim ex (2.1, 3, 0) ohs i pana afnusuugioy aw 176 yujv gcorale u yabk rlebc hagcuday guwp rizfv; ssuwaed u dene idbvo ag 29º zugl a sumi ecxaxeudaib od 8 tevb mjumoza u htemy-antar niugv pectj.
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.
Liu’fe royo bexu bauts ubv kortamgug zeldomebuenh pg vewkosf iuv goz vzequsry mifyeec buyzana siqsegs aky yuyaoav yuwzm hapiykaeyx. Zki pifzekif sio itex ef wyiy sworwaz abu o pmugr vvakm-fizhuak ey vetqawoh kguwvopl fayeemvn fdak hebueuh qlippoohp wukmudusoqeuwb pafe xihe es qayf ohuy gwo jaehp. Il ria wedt bu raay loti aluoh zigghilq, cia’hv yegr yode ujkowolhajr ovriznem mazuf tottul uf lasifonpox.beyxpibn ef jku valuoryin nuyliy yin hsep frehjiq.
Ep nti xobw vpoqmek, peu’tx qlapsa ski vagghuht zazul li mhgkogigck lemay, ulk pigc iom lud wue yin tnabvi rip a loxbaqa fiadl namy yughilo vecg ugs huxudeotk.
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.