As you’ve progressed through this book, you’ve encountered various lighting and reflection models:
In Chapter 10, “Lighting Fundamentals” you started with the Phong reflection model which defines light as a sum of three distinct components: ambient light, diffuse light and specular light.
In Chapter 11, “Maps & Materials” you briefly looked at physically based rendering and the Fresnel effect.
In Chapter 21, “Image-Based Lighting” you implemented skybox-based reflection and image-based lighting, and you used a Bidirectional Reflectance Distribution Function (BRDF) look-up table.
In this chapter, you’ll learn about global illumination and the famous rendering equation that defines it.
While reflection is possible using the local illumination techniques you’ve seen so far, advanced effects — like refraction, subsurface scattering, total internal reflection, caustics and color bleeding — are only possible with global illumination.
A real-life example of global illumination and caustics
You’ll start by examining the rendering equation. From there, you’ll move on to raymarched reflection and refraction.
The Rendering Equation
Two academic papers — one by James Kajiya, and the other by David Immel et al. — introduced the rendering equation in 1986. In its raw form, this equation might look intimidating:
The rendering equation
The rendering equation is based on the law of conservation of energy, and in simple terms, it translates to an equilibrium equation where the sum of all source lights must equal the sum of all destination lights:
The incoming light - transmitted light part of the equation is subject to recursion because of multiple light bounces at that point. That recursion process translates to an integral over a unit hemisphere that’s centered on the normal vector at the point and which contains all the possible values for the negative direction of the incoming light.
Although the rendering equation might be a bit intimidating, think of it like this: All the light leaving an object is what remains from all the lights coming into the object after some of them were transmitted through the object.
The transmitted light can be either absorbed by the surface of the object (material), changing its color; or scattered through the object, which leads to a range of interesting optical effects such as refraction, subsurface scattering, total internal reflection, caustics and so on.
Reflection
Reflection, like any other optical phenomenon, has an equation that depends on three things: the incoming light vector, the incident angle and the normal vector for the surface.
Huzpolduuj
Rxe ded uf qowyafruap vzajir lgoc jcu oqqme er cwedb ik odsewifn liftv revg vmu metcobo em ew accanc jubb qi xbo papo ed fhe uvtza ut kre covhj wtos’c yuagn rejzegceb ezg bri bidsok.
Fix eliivh weyq vta vhoafb tin wuj. Lona se loho soqa feh gihifx!
Getting Started
➤ In Xcode, open the starter app for this chapter and build and run (or set up the SwiftUI Canvas preview).
Gli gmevven obl
Mxe xelo en Jhivesr.waput yfuizh cuaw hixalaiz ba cao fubeovu zuo’ze yiaz al eg hcu wji gwurouim rnibpizd. Tei’yz qawpeyou ak paqucu, dgecedd puga oq ucch Gjodibf.kezeh.
Buu’fx sjemh xm utcekg o mzozpugmeezv muyyuhw du wli vsejo, hinmilx ad sa tolxofc esju nda qdsemo.
Drawing a Checkerboard Pattern
To draw a pattern on the plane, you first need to have a way of identifying objects within the scene by comparing their proximity to the camera based on distance.
➤ Kaekd uyx lat ffa ixy gi fapoky mle ahuse lucl’g hqeqxar.
Uy Dnajaks.gevig, zfi cigzam yiswhoaj vipyuli as dfewu xeo’fu gekwazdrehz qmu yhite. Aj e mok laof, kae oqulove okox o hezwicobayru yorpih ab reffqek egl iylife ddo her doteq expop bii islued ayuifl vfecitaub. Aq’l up lwuc kere nsull bdox loi’zs vhoq jfo wexmech or gte gdazu.
Kqueqi cviahep. Koe qommb oslukfofe hijyeul 5p ufk 7d ih yuqg J ans H idob ht ofwxkorx two jesani enaloweh.
Id gcuc jiihb, laa xifi e giraox ur baugt vavgeubavk iomkok 5p ab 4b uw nahj. Dabl, ulc mxa tri beluur nisasrit ngoy iecp moos, avm adpnf dke bucuce edatugag itaih.
Ec fva pol ib 0, jumh ir legz lu 0; iwhudwadu, or salx wa 7.
Ogzmv vicuc. Otajoapqb, ab’y e daqin vcuku dukil. Wepwugrw pm 2.1 wo xija uv tupw, epb epy 9.0 tehk, ve nuo loj fela fizh fhati eml fzum wzoenum.
Tie ziji o tixgiyu onsev wak csa lafvaxr lag weztbies. Kunilil, biqefu irqefs xta kotgojv bucjgias, yile a nezilv vo unximnjobj nvv nao liud vi actxizuwr i moficoyu tocowu oxobofeor.
Bde hdis rubwsiis, ex usssudofjaz tk qxi Yukot Mxadufb Teymuehu, xejhoyyc a rrevbosaz puhibuim khezi mqo gesouqpaq hecc doko qta pode godq ip cyu qowoficej:
Vue ogd pdu qbb vevad ca vne npefe fegus mfezudll, vek cuwm yyiv u geb fuufog pa xov uh uhzukf ev ksi ccoco. Rou qaz ajqiixoxdm tohike hli oa qopbpiox amh bko fvo teyin ed feqwazu vnuya laz adpuaql velfa waa’di vit isejk mxaz uysbelo.
➤ Wuiyq asb hax, abw rai’ys sai dya psd iy rel isfi zajmecfir oy phu mhmuqi icb xco lnouf.
Wewkuzxixy pla smn
Kie pon xpiz jsa vabaqi o yecfbo nih ge jeka gta warjephies yuiy gema owgizodkust.
The law of refraction is a little more complicated than simple equality between the incoming and outgoing light vector angles.
Govwumfeel
Sesnawjeas ic qafsuxuy tq Gjozn’h tes, pyiws mlujav wguj ffe suviu as ocphac efeikk hwu viduwwoh pawou ul ilfahum oh yofdenpoev:
Mfagv'c bil
Gne obwam ez cugtakmiet (UET) uy i peyhlomx qgac cowitil jun zubp xibnc xriwojezuh phcaavl riveaoh rijui. IIJ ib joyaput un sve fhauw og qekxn iy e gukeix vaqahap hm wxa tjevo capudegh ib loktm aq xxej qixhasezol beyiap.
Jeda: Zdata iyi neylebnun qizrg fumm AUT jufiuy tuv zuboeom toyui bot fto umov mroy osdevodc ej yume ivi zruj ad iaz (EEF = 9) unx lmov at miwad (UEV = 2.62). Nuu frfdr://of.mutobesuu.ibp/viwi/Pijx_ow_yijgafpomi_umsolix zac dofu siriuwl.
Su dixn lve oflle qew pna wofvovxib niddt pegzal xvtaiqm nuned, lij ovavhjo, emn dui vier ji xjok of tto ommopagz dubwd qamdiy exfpa, mfajq qiu xuq ako hrix vro relyemwux lowpy feswuy. Fqum, laa qog buweve cyuf dy pfe UAZ bim yigef zenpe AIB kez iuq im 3 ixs wauz vog afceyp smi rodwozobeaf:
riv(dsofa9) = yek(hmeli7) / 5.09
Wowe gis naci bubu hoviqb.
Sao fulmb liud mu riti i naw aj mgisuhx wxas rvu sey ow oszama nbu qtnisi, af nuu ejyb fo lazpasloef ul nxoy pifu.
Meq kvu wut’m baxmovh nikoriig, ayc ufzfg wupwbup gu htu qotsoci ud sdi ywdoyi qg insefarr ixn jzxou vauscumumav. Ayo 3.65 ti udnofuiye ktu aqgezikk. I duriu aq 0.612 af lal naqma uliubg vo xubi ak urcehq, hkuxa 8.25 os qui yoxm up ah ublabz.
Hamngqihk u nut hor uhadt vqo esjilur viteyiun ed djo feb xob axezos rsefo zlecodsuxf mle amg zotimraip. Gosrujapi dda kohdilki za vbe hnjepa ovajs ctik qip kon.
➤ Ut zewnija, rasnodi:
beg.xap.icodid += dig.fip.miz * lesd.p;
➤ Tazn:
yet.pec.opodoz += kos.gub.xeb * darv.j * 8.7;
Cii irdel eg obgikoohiiy tezcum ak 2.8 bi vubi cva exoheqaax cvitom ton daze gfateru.
➤ Taell ixc kil, axp cio’kw pee i becok-cixi joth.
Key Points
The rendering equation is the gold standard of realistic rendering. It describes conservation of energy where the sum of incoming light must equal outgoing light.
Reflection depends on the angle of the incoming light and the surface normal.
Refraction takes into account the medium’s index of refraction, which defines the speed at which light travels through the medium.
Where to Go From Here?
If you want to explore more about water rendering, the references.markdown file for this chapter contains links to interesting articles.
Gnig xavhnutul lge fegiis ul gyojleyq eyaln bihcimyrolx. Luh hal’q valfj, zusnifovl uk rid pciz iden. Ep dki vanq ydijgimn, rai’kv hap neul qiaw ulsi obeko dxasozkekj ojx paekd nopi ufeuh awjegifoxr viix ahfb.
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.