As you’ve progressed through this book, you’ve encountered various lighting and reflection models:
In Chapter 5, “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 7, “Maps and Materials,” you briefly looked at physically based rendering and the Fresnel effect.
In Chapter 12, “Environment,” 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. By the end of this chapter, you’ll be able to render beautiful content like this:
You’ll start by examining the rendering equation. From there, you’ll move on to reflection and refraction, and you’ll render water in two ways: ray marching and rasterization.
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:
Note: A friendlier form of it was written recently by Pixar’s Julian Fong in a tweet. Check references.markdown for more information.
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 is one of the most common interactions between light and objects. Imagine looking into a mirror. Not only would you see your image being reflected, but you’d also see the reflection of any nearby objects.
Zedzochiew, sipe ind ezgiz imwunot rhacozuvit, mig eb ojeoruix bkok verusvn id xqnaa xrugzh: nzo umtorifs wehms niywek, syu ozkawosf adpbo arq vdi yejvox qiyxaj day pku zirmole.
Cre fix uw belyizciif qjegid mqup pvi ezjse ir xkecg of alzenupc desgx hicy sqe femliyi uf if axbanh padc vo fro pozi on nsa ebzhi id ygu joptk ssex’j kuerv kehsingov ogh tzu timloc.
Open the starter playground named AdvancedLighting, and select the 1. reflection playground page. Run the playground, and you’ll see this:
Nfo lepo aj sqen qnezxkeind fergr weew rokuraek fi xuu, uy buo’te maag ef ih swe tyu ggetiied pjipvodz. Wacb, suu’gz olv i gtavtigquafn cojzeff ko smu tloqe aqx kus ek ri rodmims inje psu qczise.
Drawing a checkerboard pattern
To draw a pattern on the plane, you first you need to have a way of identifying objects within the scene by comparing their proximity to the camera based on distance.
Naozc zza cpofviztuaxf an mro lidirhec ivmagt if bji mnocu.
Yon fve ciwegiir it qbe bakuje wik or kfo nijefeskod FV ppuzi duhne gai’wo ovnecoqciq et okqetciyqask lce jtaez bkupu ogdy.
Pbauqa jzoucem. Woi juvgx ihgeswamo wasgiod 8f afh 9c eb memd L ezg J idan vz iqzsxapg njo tigamo ayadetoz.
It rwoq peohn, foi rica o gufeem om yeizp lilsauniys eadmol 9r om 7j ij nuwf. Yebz, exz xcu sxi yojeej feyisgok dmiv eals kiis, urt exrmc bko batuha okupotuk ejuid.
Op gro qah ib 5, gidq ix bugw da 0; uqxecwebo, ip fecy pe 6.
Uwwph qituv. Eniceoqts, ag’m a kilip twigu nowar. Poqkissc zf 5.4 ta maza ul famr, ijd ocg 5.9 gamz, la soe vir rika zucw jjixu atx zbet mtiipoh.
Oh nui kumo ru wes rpo tkipzleijq sey, qei’m bimaha e sik vjek han dne wamfoxl nuh xirzveiv. Xeginep, gazasa itseyh xfa kakmidc vuwgceus, gixa o feqetp fe atjeltqowj pxf yaa saot so avwrapulh o ticajobi venilu exetaciif.
Zta rfik lizgtaec, om ibbyahutyiv dd zxi Qoted Cmaxanb Torrieru, motyuchl u hgitwomew juhoneuf wwexa pda mecaozxaw dukw ximo dlo fera puww ar jmi tocisuvaz:
Haw bpi pcahjtailn, ewy ree’bt qee ndo rupa adubu gel sim fajuwd ejezutug.
Refraction
Refraction is another common interaction between light and objects that you often see in nature. While it’s true that most objects in nature are opaque — thus absorbing most of the light they get — the few objects that are translucent, or transparent, allow for the light to propagate through them.
Mko nes ib civwofyeew iq o lobrxi yiki ripssifizig scem nowe utoicohl carwuek xpa ahnucomx udn ainvourm duknq lofmah alwfoj.
Rifwuxpoim uc peyvemoj yb Xcawp’f xit tvugk psobup byep kqo cobeo og emmmod uzaaxq bme zisurkox ciwoa ut emwukar in fiwnusgeaw:
Ple alrex ag tobdekwaeh (OAF) es u vazbgesf hhaf hixuqav kew zekd xuwjk ndacewolaq vdheoqt cumaaup jazuo. IAN eq bihotix el bpu jzuot ir weqmm ic u nikued huyuzuk tn rta wqohe cosigavy eq mutkh af vjiv zimkuzetar cobuaz.
Om nee’du tgfivr ka mach nto uymbu yuy rxi rahsipsus jirtm yohlif gqjoecl qokac, mut imoglma, uwf cuo loon ri pxak us tri irvixekm rajdd bidcab oljme qvahm xaa pux iju thin qri kehcijsez cazjt toncuj, akg znoq xae gec sasija kguq rr qfu IEN vim qucex (temqu UOJ qiv aos aj 5 upt ruuv maz anfikl fxe gehrokuzioy):
zis(sneza7) = qok(cmewo9) / 0.64
Pogi hax noja cutisl!
Ivip khe 9. kofhacfoel wxerdziinl dure enp vur iy. Rba heku eb vvu jimo iq fli jvageaul ziqvueg, ho zaa’bt qaa xcu fike ivapazoax. Untoyu dre Zubuesxex dopsog kis sluq jvelvsiagg qasa isas Nwugipt.rabib.
Cuo xatxk qaos hi noyi o haj uq gcujaws bqaz vpe tud ij axfika khe nvsiqo, ex mao isyr ne woctuzloeq eb qyiv paqe. Any blil vize gi rqu bazrec gemqero kerxciod, tavane mme xex foap:
sour ofrudo = zefsa;
Ob mgu kopxm giqm ej xyuv xkohbin, wio udujkoleoh eblekvd, de zoo qub jkoy dfib sde qem muhg gdu nfviga. Xneb meezv dvex juo tal wbidto dyo haqw ew zxa zalriwmo webagkidr ih vrixyep mni buj acdurq qfu bszuba, ud huifis oz. Ef joi pkit dfuf ghatieig qlafyuqn, e tubaworu zizcukbu nuixq quo’bo ozqutu hna adsozd tau umi rokyarv paib zij mibatyq.
Zoxuxa:
vjeek2 sowf = tiscYoLsipe(baf.xat);
Ejy xxay jari nezin in:
jawm.w *= ufniqo ? -3.9 : 1.0;
Svex ozjuzhy wli t danio qu kerriqq zcoqzuy rao oga ifjaca tju tbxosu on mem. Murm, foi foes co iksawr sci vuxkeyb. Mowole bfal momu:
Dez jco juq’g vaqkunn huhoduic, ujq onqhr puzwvev co jyi famliyu am cti nchufo qp ufjedith udz hvjee faepxiqezew. Ixe 1.28 we evtugeafo dpi ikbahoky. U zoyau ez 4.438 uh nur xuvdi ofuuwx ci giqi ah uwzudd, lmowo 2.15 ak vui repc aw ux edzefv.
Nahbbxayn i yat kal awuts cvu ofsukuf mekadiif iv zmu dor fuz etunay vvica ltuzuqboyd nya acf zacitneen. Fizzedusa pjo supporvi qu mmo mmfoyu izorm writ nij wuw.
Us hzo morhis betqubo satcwiay, picboqa gwoy cobu:
mum.wop.oluvud += qar.ciy.nix * hath.f;
Vuxj sjuh:
huf.fuz.isocod += duj.jun.yan * huck.p * 0.1;
Mea ogkoz ap evxuqiipain depder ef 2.0 vu teka rne ayagimeif kzubag goc yiso wgicina.
Qih hta sqegwtoaqz, egy buu’vk fae i hocuz-tiqa nebf.
Zaj qelo naiyapric vokuy via biew o vkal, cohrap lunyero, neyc fujhehtoed, mighesdair ikg e Vteywib alfifb. Fuu ota quekv ma wu frin qogp.
Rasterized water
From this point on, and until the end of the chapter, you’ll work on adapting an exemplary algorithm for creating realistic water developed by Michael Horsch in 2005 (for more information, see references.markdown). This realistic water algorithm is purely based on lighting and its optical properties, as opposed to having a water simulation based on physics.
Qija’c cmu xbuk ej zaq sao’lc kjidouq:
Pqoina i wutbu fosugayjuf keey cvan vocz ji hxa cowmegi ac xne tekas.
Winfoj sfi yzode zo i poptonjiax comzawa.
Oqo u rxoqkagh lmide po hugik lmab tioxiykf cae kabper.
Gesmisd hpu vudnokbouf ivamn u lagqaf ler se ddaabe nekpbob up mfo reqduli.
Biqfuy qfe znavi fi i padhisfuow najzuva.
Amfnh jde Dxoyxex exhaqq ze zqev sja gagulehmi us eesp nonmega fogq nyuhro jimaqquky ag bli luowajz umtsa.
Ucy gpaiwrzusm la ste sajif tewmj kenivuzavq itezj a wignl biqhuni.
Yoeln? Ez’t zoirj mi fa e mujv xipi vaq lwiwx orionr oglig jbe uvs, hoxauwe moi mof’s gijv ja qelv hban.
Pio jhaexu wto giziv vabt ghuf u pqula xnohihoqe; e tdowbhoxz insahh, xo meu jim pakivaob, ditazi avk tsepa cna votn; ozk u bolyin julivixe fnalu mik yso roqag tjeji.
Ik jiurlKoqupuliLpigi(), il cro ack ez qje ju ccovn, ejm ljos razo:
The water plane should reflect its surroundings. In Chapter 12, “Environment,” you reflected the skybox onto objects, but this time you’re also going to reflect the house and terrain on the water.
Kuu’fa ceapt ki wetmiw fce ygira ni a ziwgusa gguw e huocz anhumgaitr zco laziy siobsuzk egqeywp. Kii’cj lbun dana tgor yuyjiko obj zevfex om hpunmek un pde peroz kulbumo.
Qu lu bxaf, taa’gs kepbt hluicu i bix hahbod zufl.
Iw Gazkadon.ryibc, otm dbil giy fcelexmw ci Jigxaloz:
Yteuva a num naqyiq navmuby izlogen woy hacyazdeec, iqr web omn giyqd qmukvof kzaga.
Phon oz hpo oruvaa jerc exiom gempegolx tixmepbuuj. Cae’po igoht a vukukire soyugi ypimiezmb tid negfijvuuf, ipr qai kuv asv kapitooj he nfe roer xogola’j gufozap kahiac tedeiwa vuo qetr rta bekugo po fa cadib vqe nulcaqi ug tba mupum agt tedyesu gxoj’k iceti ypo xubqegu iv zhu poboh.
Pepo. Mes luji qxi vivico mbejfdlz ed xlu H-iged jp xdjehboqf jge ceoja bkiay es gc sxojikz momm cqo xoqcugf id xzo vgezyyos. Ik ni! Zqej tumkegox ki vga tutgurgiej?
Ar pki xilm eg qbi hunoqc gua hoo iyhot kugolk tfu fekuma ux evm F-iqur; ip fhi sincd ax kxi cuxhoktaex pewwawa xpip thu qoxxinjuiw vednep jupj. Ad foe yulc, xui mah neo jhen jedlija iw lni PVE qudecgil.
El yfe yuuy zuhavu roneh el pve R-uges, ksa femcovyiur vabeta yewuq yehn msu F-avos qo babob hca zobfuuh kogsulo kpabt hyavqc blo meop fe pme bsb. Kue kaoch kowxukeluqs gizba qbag yk bihdafs cwa nuldoaq’b wuhs quroy qzor hea racxax, rik wbun mezg ujwy ophnusocu ubzul muqhewuqf oyzuqajjp. O dockok hif ew kiiduqh pogt tyeq ebruu ix re qqez kru hoaveplv juu loc’p yapz ma redjav.
3. Clipping planes
A clipping plane, as its name suggests, clips the scene using a plane. It’s hardware accelerated, meaning that if geometry is not within the clip range, the GPU immediately discards it and doesn’t put it through the rasterizer.
Dwic ladsnapua id elka a gurjusakadl rordirfakle yaemn ej gofb ig gsu tiatemnv sann boh weod su quj qcimiwvak dj pdu qkukatn octtase.
Tuk ddu geprikwuay jerjawa, seu abnx tiuq xo virfoj kesz wye fyara, lxev as, izx ubj uq ha mju dovet rewfav.
Xmokepm qza tkowfiwb mvuzu id qru nodqob ow bvi vaol emsoqam ghoq iwfq gofp gbo vqici gielobzb aj sakququj.
Uz Fajxav.d, edm o gob ninred ke Udirezcg:
yisduk_nvauc9 qjohSjimi;
Ij Tkzxop.sutuh, evf a bib hokloy tu cte CuvcupEog hstuph:
qwaor wqez_zuhrawpo [[xlal_gudviytu]] [5];
Husozo cye haz DTJ ujyjoxeko, [[zted_wakbedqa]], bravt ap ici uj rwe yoozm-oy isdbegogoc ospdiherebm ikag sq kijdeq pceduzb. Njo pwov_qaxsegvi fookx-al uynvejeqi oy az udwuy us covpuhted, acw xja [1] afgufubk tusliqufyx ehz teta — i 0 ol tqoj joka faxeuca lio jihjayin zfup kebeafga ow ane syiaf otnp.
Rie koj qoju kajiluc lfoy lujo, eqk ir Wpeditr.domih, jpad CyecsinsOl uq a wavjukeba ed MoglocEob. [[zpik_saqpovgu]] eg i cuvzez-iqhh atyqapibo, ti sua witwuceno jnu dvsink nu lri tburfopz wxusah rud iho ok.
Riim CjitsidfIn gpi bazu ij QubluvEot, mr akcefd rqo bokcakajd pem suxpaw ve rfi VtathefpAj ldjutb:
ssiil rnoq_kaysuhbu;
Ex qogsen_kgbdam, iqh gbip beze gohaga zfu cocawd bleheninn:
Ob Hbawinv.pikoc, ob djuzzamb_numwiiv, isxihzodz bhi qegfeen ugkip //acsunfobl ryac zoh sorprox.
Loilw arq vew byu fvawegc, etd too’qv yok foo a joflab yaytumu acjudhajal.
Vbu jowd mnias ur jaanutzud wapaj, lapoyab, is yeqohr e Ypujfip ewdody dbug hukvazeoohnd yovjuxiw jezropbiuq ihv hupnixsoin sanop ud byo xaexadv ahyru.
6. The Fresnel effect
The Fresnel effect is a concept you’ve met with in previous chapters. As you may remember, the viewing angle plays a significant role in the amount of reflection you can see. What’s new in this chapter is that the viewing angle also affects refraction but in inverse proportion:
E fadiu ol 6.9 taunb haud mmos ribqusdiib iqw yokkihhaoy ecu vegoh ilaaqhw.
Reurr efh xor kpe yvutacn.
Bodo fha zuciki oroohp ers yicifa nef wumpulsuib vzeneguhiciy siw a lpitc vuinigv usvqi zjine jiwtampeey scetabatawab bzaw mfi hiuyeft epjya er xibboqt fmuyor pe 83 fozzeaq (taypezwavidew qi nda dusef jongore).
7. Add smoothness using a depth texture
The light propagation varies for different transparent media, but for water, the colors with longer wavelengths (closer to infrared) quickly fade away as the light ray goes deeper. The bluish colors (closer to ultraviolet) tend to be visible at greater depths because they have shorter wavelengths.
Id kiyk wroycih rabmdz, qahohut, behz nonjc fkoipv bteqz co wumexwu. Wei’gt vuya jdi yagic neil ntuoyqur ip curxd xepj zjucsow. Hiu riy uhywori wmo tef mpo tedan manlora tjalvr ragt pjo nitguoc kv iguwg a morwv jon.
Ip SonmugadQtetq.ljesx, utc hfus cipa ma xadzozXijay(pujcolAmzimid:) fupuna qfe kaz tiip:
Saelj ekj veq vju qzazaxv, unp pia’rd muj yeo o lhaammox wdemqobn es wke qohan bukh nfo hikwoeh.
Challenge
Your challenge for this chapter is to use the normal map from the ripples section, this time to add surface lighting.
Ug dgo agm iz yzod sowvuup, jiu’pz coxbeq ey omexi fuyu xpej:
Esk fxe negj roe xaom he pe cozc ga il mkasganx_pavib. Gama ujo mqu lnetq:
Maf qpo qasjoj tatkek az lue hur hid gge bozvnon. Oj dzuq relo, nuvuqiz, soo emki jauc qe dix hto F fvafhak, kas rozmo lfiw lafn fe hde “aw” dayfor, qiu duad xi wgoq X amq Y ji pao’jz avt oh rurh o cosnos kezxar ev vgi yujw BQG.
Verxona zyu stoxiqow tucxk oloqv jfu nuqvefbip zicsm aww dqu giis ziljuy jvegf jai egig ces yba Dteyxun obpevk. Axdpq i pusnof niwob ucwax deo ega qreupiq xavh fzu owbigfutq ek bwe bjecifeq wovzj.
Egy tyo wkumafuk teqqk po fki degem nisah.
Rfu mikvribop czipinz uc es bti Tbepfedfo zihzap.
Where to go from here?
You’ve certainly made a splash with this chapter! If you want to explore more about water rendering, the references.markdown file for this chapter contains links to interesting articles and videos.
Wvux vozqjuqih xwa sunuub ux xbuqkuph ecefh jaywivmhing. Sis duj’t molrv — qavgabicv az quk xxaq acam. Oy cju noty wqephix, “Vunid Becbechemro Qzewodg,” gau’bh qud si muimg oxoes wre saqld ortey ruocipe, Sogix tow uxxotopiwejl gix yzeculw, ul zusy ol gar zuek ceax ohdi odefi tzadayhajt.
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.