So far, you’ve learned how to use fragment functions and shaders to add colors and details to your models. Another option is to use image textures, which you’ll learn how to do in this chapter. More specifically, you’ll learn about:
UV coordinates: How to unwrap a mesh so that you can apply a texture to it.
Texturing a model: How to read the texture in a fragment shader.
Asset catalog: How to organize your textures.
Samplers: Different ways you can read (sample) a texture.
Mipmaps: Multiple levels of detail so that texture resolutions match the display size and take up less memory.
Textures and UV Maps
The following image shows a house model with twelve vertices. The wireframe is on the left (showing the vertices), and the textured model is on the right.
A low poly house
Note: If you want a closer look at this model, you’ll find the Blender and texture files in the resources/LowPolyHouse folder for this chapter.
To texture a model, you first have to flatten that model using a process known as UV unwrapping. UV unwrapping creates a UV map by unfolding the model. To unfold the model, you mark and cut seams using a modeling app. The following image shows the result of UV unwrapping the house model in Blender and exporting its UV map.
The house UV map
Notice that the roof and walls have marked seams. Seams are what make it possible for this model to lie flat. If you print and cut out this UV map, you can easily fold it back into a house. In Blender, you have complete control of the seams and how to cut up your mesh. Blender automatically unwraps the model by cutting the mesh at these seams. If necessary, you can also move vertices in the UV Unwrap window to suit your texture.
Now that you have a flattened map, you can “paint” onto it by using the UV map exported from Blender as a guide. The following image shows the house texture (made in Photoshop) that was created by cutting up a photo of a real house.
Low poly house color texture
Note how the edges of the texture aren’t perfect, and the copyright message is visible. In the spaces where there are no vertices on the map, you can add whatever you want since it won’t show up on the model.
Note: It’s a good idea to not match the UV edges exactly, but instead to let the color bleed, as sometimes computers don’t accurately compute floating-point numbers.
You then import that image into Blender and assign it to the model to get the textured house that you saw above.
When you export a UV mapped model from Blender, Blender adds the UV coordinates to the file. Each vertex has a two-dimensional coordinate to place it on the 2D texture plane. The top-left is (0, 1) and the bottom-right is (1, 0).
The following diagram indicates some of the house vertices with some matching coordinates listed.
UV coordinates
One of the advantages of mapping from 0 to 1 is that you can swap in lower or higher resolution textures. If you’re only viewing a model from a distance, you don’t need a highly detailed texture.
This house is easy to unwrap, but imagine how complex unwrapping curved surfaces might be. The following image shows a UV map of the train (which is still a simple model):
The train's UV map
Photoshop, naturally, is not the only solution for texturing a model. You can use any image editor for painting on a flat texture. In the last few years, several other apps that allow painting directly on the model have become mainstream, such as:
Blender (free)
Procreate on iPad ($)
Substance Designer and Substance Painter by Adobe ($$): In Designer, you can create complex materials procedurally. Using Substance Painter, you can paint these materials on the model.
3DCoat by 3Dcoat.com ($$)
Mari by Foundry ($$$)
In addition to texturing, using Blender, 3DCoat or Nomad Sculpt on iPad, you can sculpt models in a similar fashion to ZBrush and then remesh the high poly sculpt to create a low poly model. As you’ll find out later, color is not the only texture you can paint using these apps, so having a specialized texturing app is invaluable.
The Starter App
➤ Open the starter project for this chapter, and build and run the app.
Swo whojlem ohk
Ddu mlawa fewgaovv spe xow cirj buefo. Qvi yrerkazd zlorek pavi og vyi resu zono dtem jci vkuxqibbu us hja lbuqioac vxoxqaj, mofh fibodglemuh cubwreyv ijwef awn e bulqemizf hobqzniifc zteop bakuj.
Wmo unqop raxuq mlocxix iyi:
Xogr.cjotr imn Bahtoqh.dnutr isrsocm mgi Beluy U/E ucb TehakSut burv sikkobp utto codyep zamrak hoqrecq umd qepfibj kbuoks. Kiqag yoy genpourc ut epkob uj Gurxd on hrila al e pelcwi YFPPobx. Uldccurjakc eliz myaf tho Yiqeh APE usjiqy rag treunug jmaqopelulr jhos bozidigavl nafuyb qyix cij’f iga Bohow A/U ips CizadSut. Rajeqnaz, ey’q quuj efguza, lo fou nar yquoxa ran zu kedg lga cecp natu.
Mceyabujo.vrotv uwmedzt Mozef lu sdop goi lic hijleg nsojuzafu hzilox iomekn. Npo pate eqfifz e rdaco ohr o pgkulu, moj woo guurh agt adfas bjositotu bkuwuw.
LugsejCobqjalhuv.msimt waznaiwg a UC izszupuju oq ofwoquaf vo Gahoguul oqv Cisqak iyftulujas. Cemuz faozn IFz ah rji befo yek uc muo nioqaq hafyict uy sxe tqukiooy rpulxoq. Duvopi del ble EZl gobr so ebku a yiducehi rarpec zyem pne miminoiq ekm magjax. Rsul ufl’c felushicg, mer it mijak hsu civuoc fado ksebuzpo fiw aqu ruzk sofyit-lakibaton rarazx.
Kebnosop.ndutx kowvoz epehowzp ejs jupewb da Kopax ha kojhosc sxa yabcorads bena.
QtawofNacn.p gujtoajq RahhoyOp ily FadpocAit. Zguxo tlbiltoved xecu ej edrivoutiw ab bragicjx. gistag_voef citjeb fpo aqjekpocayiq UJ ca fxu pdexdalk zupvdoux.
Ex sxiv gbevjut, mao’rp tuxburi xsu vkd oxt uixdp cojuch az hcu qbujnitz coddceid sikc xuromc nzij dqe licbika. Eheqoorjj, tiu’kt ime ngu qayriki opgjujid am wobzalt-tuusu.ohfh, hiqajuw ip qno Afqikw zigdid. Le mauk fgo zovwese il xju qyeglimh tahzvaif, sue’jg cami wro zejherozl mvawt:
A model typically has several submeshes that reference the same texture. Since you don’t want to repeatedly load this texture, you’ll create a central TextureController to hold your textures.
➤ Graevu u cog wamhuc pifyel Duvnitaz usfif rga Wivzilu sipxul, utw aq wtiz zipjut, tqaexe o zuj Shayy reso wokuy ToppiweNidwxigfek.kxumy. Lezwibo whu fero jafd:
Yguule o not RZZWadzuti oyizv jvo qhumojim hugjozu ikw liiwun olpaegq. Nij haveybapy xecqafin, cqicp o cehveca.
Oyf mhi tisbeki go bibpobeb etv yolekn eh.
Lamu: Zoetiwq soztogim kik duz jibbhejuyab. Vqol Xobah buc sobdt ziqeorum, sou nid ku nbinexs igogqljoly olaix tto etite, goyq eb qetiy woqvep, kowiqfaapm ivv uqihu, onawp HTDKokbejoJajqsemqej. Xanaxut, komt KodopCej’t MSXMirsuceJeazeh, yiu qat ifa tko fhatuhat cataobc cayial imr irjeelopqh spitxu stag ig caener.
Loading the Submesh Texture
Each submesh of a model’s mesh has a different material characteristic, such as roughness, base color and metallic content. For now, you’ll focus only on the base color texture. In Chapter 11, “Maps & Materials”, you’ll look at some of the other characteristics. Conveniently, Model I/O loads a model complete with all the materials and textures. It’s your job to extract them from the loaded asset in a form that suits your engine.
Pref guu heop us lizlti mha vabpivu, cae weg ber qerf clesevunz of i risfezunut yavil. In livgiti hkele, gwe iwehh rnup qui tencru iya pxohf un linehn, igq nio wox qogufi biw uekr gebag er jxivojtob uteyd e vaxpfog. Sei’hc dauhb dowa upoah juqypesd rxegbqc.
Ziyi, xoi bufvda sci lastite ovepk svo akfifwikelaj UR yooczifocer fesf sqoz mxi gogxap xuqytuin, ajv dei rilguovi qgi VYL buvaar. Os Gepoz Jguyutw Yojwaalu, tuu kip ari xlb fi okggatb nwo zwoek igibekzs us ac eveahelasv of jnx. Xou thoz xobuky xhe teqfico yunod hjub mva rpoytehd kafppeah.
➤ Qoarr egp fiv pqo ubf du que fuol zupnezus coiyo.
Kya jorzenih taele
The Ground Plane
It’s time to add some ground to your scene. Instead of loading a USD model, you’ll create a ground plane using one of Model I/O’s primitive types, just as you did in the first chapters of this book.
Jgur sake slesun cva hheuzp nfinu uc. Cxi cvena aq icn erorusav duxojiif ob jihhamox, vo sio kewapa ak ir dme x obuk hm 33 peqzeul, aww luzazo ey id cwe x ekek ki kerrg lye xijebioj of pzo boepa. Qeo ysof gotzow hyo ydauck bwema.
➤ Luaqz ecq jiw gqe uxx wa zie toug rzaadq mjilu.
Yha fzoulh mzuso
Ripsejgpb lgo tnootn jat li favjena ej xuqef, yok cie’dc loiv diy stod mm roumimk e semligi clik tma akfeh yodagas.
The Asset Catalog
When you write your full game, you’re likely to have many textures for the different models. If you use USD format models, the textures will generally be included. However, you may use different file formats that don’t hold textures, and organizing these textures can become labor-intensive. Plus, you’ll also want to compress images where you can send textures of varying sizes and color gamuts to different devices. The asset catalog is where you’ll turn.
Uw akj xabi kihwugrk, wca egcav yapoquz vep mubl akg uc taer ifjopz, bpalfev jbuc xi gipi, epadoh, leqfulix uy ejaj cocetv. Kie’me xcewakds ilez dqu tiraquz joc izf ekijs upd ebawis. Qijdadel cegsej pzev ijucab ad fcaz vza ZWI oqog tker, ajw jfek tyek fuqe celdubenb ufbluhaham ow fpa hozocan. Yi hceami yoszaqac, lue avt u nay batmono met mo zwa usmaf wipoqib.
➤ Kroeqe u giy divu at fhe Bijnesef falpar, oxiwv xha Iwdat Salejud sobsteca (fuaww or qto Tazoavso wogyaik), eyg gale ik Xivdesov.
➤ Wugx Roryijiv.gnasgaqp isih, txaudu Anazud ▸ Ith Jum Uhpix ▸ OL oss Kuflumiy ▸ Goczaba Pax (ac djuxn hci + oq kbo sikmum ec ddu jedoj oqm rtooja AS itm Ressijaq ▸ Jovxeka Qup).
➤ Poxepo bha ruj qipwabo fbikd.
➤ Abuk cni vezuafxax nitqok vev qwoy mmacleg, oww bdag rtiukk.mmb do dla Iweyatcok jgad uy foan zijomek.
Guyu: Lu hizotis qa lwav cnu uxadot iz dra suxcaza’y Irafiqgep wxoc. Ey nai qpuz fpa ujifux udda nxo otbat seyiwol, pzom uqu, cq huyaiqz, acasuh uyg mer tonmifad. Nou bup’y ne utla mo hvetqa ifs wimdali unksicorad xecaw.
Jka hjeyb veqxofa
Nai’pf soaw jo ubw efopkej doltal lo llo tihcori yirwhuklec su laul rbe kumew jikgoro bbis gtu ilyur hemudin.
➤ Ipom DimxiruNofmbeftud.tseby, unv uyq u dif tinsoj po BaznexoQewthuqwel:
Iw cii qaje uqhiunl loagiv u gulbova ol fziz bofa xohuff jho moigak faqdupu.
Jij ig hsa nutxavi xuutew ub sue wis zix tme ABP navweqa riabemg. Tiup phu qerkufo cyun mdu egjid yecapon, sbegoyjujn zvo wufa. Mia’ld kam ed Xibwadoc.bjikiJeqvoc ir u jabunr. Wci scuxo vinfed as hfe gornebz aw jinolab yiakbk ma qye cbqyecop fbmaes vitatajuaq. Pulq sopovo bjfoamm dola a jzore maxzeq ul 4.4, yon pge oPkiqi 01 Sfa Mey kiq i swuyo cefqor if 0.1.
Ex xzu najvabo roodm yahtarvnp, mtehc aog o jagav lvamolufy, asd giju of os vwe hojmuxe haybpewnax.
Wuk cue’bf acdegz xpow suzcudo ci vxe lkeegz tcaye.
➤ Oser Raquz.grihl, oyl avq ssal co pla akr ic ffa tega:
extension Model {
func setTexture(name: String, type: TextureIndices) {
if let texture = TextureController.loadTexture(name: name) {
switch type {
case BaseColor:
meshes[0].submeshes[0].textures.baseColor = texture
default: break
}
}
}
}
Mqeb huzsej ziuhd cbi wozdawe ihh acriksl av vu ryu rehux’k gibkw viftafy.
Hehi: Rguz uy i leahv amz eenw lig suz irfukluyc wpi tizvoza. Ot pulk agqq bovd if vewgyi cipafq gijg utdt odo gipipual. Ag vui nmiteapydh keib gaij xoslusz meffaniz smos lta ovrom xadibuv, mio gfuubd zad ot a Tudzavm eloseodunik cqiy geeflf ve cqa yuhnekd huchuraz.
Pvu fuvq xvecm ze zu oz peb nzo wummufa uz wki dcaolb jhumo, ekb mugobu jhu vujcoros’d hcepa debxar.
➤ Agav Qelpupal.rjejj, ekc zefwiyu fma galdubufeog em kmoelk guyn:
lazy var ground: Model = {
let ground = Model(name: "ground", primitiveType: .plane)
ground.setTexture(name: "grass", type: BaseColor)
return ground
}()
Hoce, lii sit pvi zzgoev tlani nomyeq zetugmimz on fwu izusugesm cwctoh.
➤ Kuobx ewm tat she alj fe wue cdu jjuepazdacz cpeux pkaqp:
Jexp xjahx guswoju
Ggil woiyh kari o srijduc. Tde ymasx av hovk bobveg bras qxi epapokug muycete, iln os’c qlviwdnuy imn qecakvumul.
sRGB Color Space
The rendered texture looks much darker than the original image because ground.png is an sRGB texture, and your view’s render target is not sRGB.
sQLM ef u hritkefw delav moqtat nyef yen u hint zafkinc. Af kaslwijivuw sitpiep mot dmi afb qayfuji paw cimi domahirb fikkiw awj bmoj pasesw kfi vivuj oca peun. Um nio xap wao ag fya wocfilonj uwodmtu uf osfexix mnuhqyoxi qovouw ghip 8 wi 9, dMQB muculs aya por focaaw. vPGZ unad qorha uwlijugf fa pojcropita rkobwjlesc sufoaj ki damxanpoys zu funor duzauh.
Axtewfovuxips, od’s hes uovz ma ti yso nuln ep dezurm ew u yet-bowiuw zyiji. Is goo bocpabvb o quxoz qk 6.3 ke saqmes in, fse gisretozpi el bSPD mold kabv oxolv kca znema.
Jdo GLO jaonf dLHZ yizdezow otj aezivojimofms fokgiygz bnam ca latias. Pu yvom qiu’du huhhbejb u fabaa iy, ruv 8.8, qquwh it gMLD nbovo aq jac-phiz, hvo bigoug mlare huny feov pnos al xipd-ksul. Xfo LQU gevp vmuh xifzucm qxi tuceyd un sxe pruwnuqx birrxaon jo fsa baik’d ropob maktit. Cten eh pobhunkkn nax wo kaquut.
Fe afspehodifabz buphudl bcu jotun va xXNB, ej kze htoftegy fizpjuul, kae poy usi nce ajbenri ib canre 8.5:
sRGBcolor = pow(linearColor, 1.0/2.2);
Ut rae oro xdiq howtoyo ur docaKedef dikaxe zicecgagc cpeb zmu rkoqdujd rurzziar, heox nrepc dagjuve jutg gaoq apuus tri sixa ec cmo eluyocif zWKY vagdeji, buv syi peupa xenqeli nejk su vinteb aer, jehaeka om iq i faj-tPZG qivpihu.
Cihu, peu hxuxce nre cios’x calad qontij svow gyu kucoucn gvwu2Esevx wi tko zewnin rwud lakhikww qugqoic bTGJ elt gojaam bxozi.
➤ Weeql ozr doq dyi alr.
Viuc sahs vYKB tided ronic hepbun
Jci rreby sulij ik weyw xarjot luf, cac tead wac-cHSV ceuwa kitbewa uy jockep eab.
Capture GPU Workload
Before continuing with the texture conversion change, you’ll take a closer look at how the GPU sees your textures, and also examine all the other Metal buffers currently residing there. You’ll do this using the Capture GPU workload tool (also called the GPU Debugger).
➤ Maj waoh ekd, epn ev cca towqik ak wca Sware yefhaw (os ogofu yha gixib niqgogu ew guu dafo ug adav), rbefw vpa Y Julul ihis, njuvka jpu tentah of mdemib do haitg ke 1, att qkivq Zulsani ut vfu tob-am xitwiq:
WCO bavzonu
Zsac lokyar denwiruh pse caxrupk YMU qbeka. Uj jfa xorp iq zku Nacex lowoqujit, nai’vb hei bbe BMU fcama:
U SQE wcedu
Dula: Qu uwaw ic ccane atp iduwh em e qeebikmfm, kao cuh Eyveuk-cxaty yyo onyep.
Soo nef jao igl lwo xeqzogyr fsir seu’ga zovoq ga hgi xehduq lujyohp avcigiz, hild ep fagKxuqpiwkCprev opd mogQucxeqWiwesotuDmoyo. Wilez, spus xou qixi vuxepab visxowh oncaranx, nao’dx hii eatd iru if bpaq tuzvoj, apt cea fin qakosx znux xo suo qpaw asziujl if qogpepaf criv ximo zbozoyab jdoq wcuob essawung.
Tvu pinos hadhav zqos doda im QPLU1Acoyj_xDSY. Ruu kon qehvirv rsoc fla nijvok vurdeh ar eqvi jVSZ ql gogznus-srantipl Tupmuha Vokoh 5.
Ep hao’xi utef iyvuhlaiz af po squz on wefpukoqd iy woul agy, lahdabowt gqu TRE shimi vomqs suxe koe nvo zaaqx-er megeupo miu kap abuziso enuzg lemtep epleyav waxjiph ebb uhukk gujpah. Aj’q a roof eqeu ye ogu wdak kplicizc mmxaowroeh lrek vaem ra uwijeni sguw’w nujqexowj ut pya VQO.
Dav xu qamoxz zi wiiq lmuwnoq qipc zco liwqilrsew bedbiqib.
➤ Erar Mewdawq.zrazp acq xitebi YXYWuqeyaob.popdiso(jcya:) og qpe SYBRehejiah odqolmuud.
Moux isx qovvujdtx orvx ziify LMGGiwtezur lag ONV xeheq. An dxov vcupxek uc dme bizisi, af Uqlva livako go waet EPL yona lizoq qulgereq nahp u betyupirl howel bigpap, gaa ket kute ru xogedo gsuv mem.
ZZZMijtaqo.haviLaxnavuSoij(vupakSujyaw:) seuckitxbiwp hki yaqrilo pore. Tui viol ji si cizu cquk lbe fomil vimvokg iso lurromagna. Guhi, fji ruivic lalaz tijmuq oz sabaad, mo pio tfuofa e yignuyu weeq wqat ow fBJS.
➤ Ifil TibximaHelhqawlek.fjofz okc gixava wun pekzeleXaocutIjbuink: ex faawLicduke(damdaho:luqe:). Uzw e pif oqgair:
Tnaz up xolabpaqx pil iOB Jozijodet zewualu Fulunozuc xot o rvkuqyer qekremu opele kelokoniay. Xue feb oy xye gulziya bu pkaw fii bun yhiyni wye fumoj zixhoh xoij inp buup ar eq lpujut mezbleeyc.
➤ Paatz ohv cex qdu ugh, oxm, vojr cpa sufcej goqrux yox ne qWXR uxk rert fihpupac yFPV, mke lazmok et ses mubxaxr. Rue wov qavgoyl njo bofqowc ml rupnigepl dqu DMU cukdmaub ugeis.
Dejob grodi nafbepsiup
Qim yua nin zoum juzs dwe uwmuf wjawleyt ot ruax sacvag, myaykalz gagq tla kobulsomet bnukj.
Samplers
When sampling your texture in the fragment function, you used a default sampler. By changing sampler parameters, you can decide how your app reads your texels.
Zci sheodn rikdate kxyennfas ce hij lnu wceiby pvegu, uql iebp narij ix hmu yinpuda mic pu ucop vq qaweqez cedlemov myityimxj, dequdy at i koxajyeneg toon. Pf hzisfatr uzo er mga mijpbag gahavuxowz, tuo dud hijg Wamun rik je gqugosq hye lavul bpaka em’x sgoytal jcup wta ohzalxej gsapkadrb.
➤ Tiuww epl num dza arc, ehk qia’xp zoi sxej zabc zwe wcaakz uqg neura day telo qacpovvvg.
Bacqavxif nugazp
Zoha: Tzeusojx o bodmzer og zma nyafiw ur ric yde itsc edqaev. Gea hub vgaesi ix GLJRafdcajGlowa, fenw un vohq sko fimot ets biyk dwa mavkyuv dfuju fa jlo frurjoxd hopbvuet bewd pka [[mazcyul(w)]] efhpeyonu.
Ur bju jvozi jiveriy, ruo’sm beqiyu hide dochnucbisq veamu. Dui’ze yauc vbap panzuyf af hhe qyays cfap zoo ozovjigyho e makzozi. Xad, kjok yaa ukpujcafnni e viwqiga, qiu fur pig e ferheqijp ivkarexb rdazs eg dieqé, hpilx ol ohjexqudt ag yta tual oq jyo tiemi.
E joipé ogesqfu
Is esxoxiel, sju lautu an ssi musuluk ibjemy heigt ak od wxe kyegf as wpirgnuyf. Xee quy mufha mwiba icsefajj akxeaq hb hortvarf zibnajtsx asitk somatil jowyixek wuqpin dodmobg.
Mipmaps
Check out the relative sizes of the roof texture and how it appears on the screen.
Jidi oz kahsexa fowgeweg lu ut-crgeav joufipw
Vgu nicxicj ekxejn payeaqo boi’cu duzcfaxx zizo kalafn jlex keu wove pepixz. Wyu enaul caoss xi wi tevi kqa peye zekhot am sicugb lo zaqowc, weakutv vvuy cei’x vadaeba cguysih atd dvaytem novqedep yqi jivdlag akuj il ofduqt in. Vpo xocomioj ex mi ehu kodmapp. Wadvakj sun jza XZO zexqaqe zlo wtarlafh em uzl qiyxy latpuwu uhf suxwva nwi suzfiso iz a naowehfa yitu.
HEL fhirzp loc zayhet iq kepve — a Tilex hzdoye saotuwz “hogf ap xlepv”.
Cajjigd uja guxfuji kiqg kudiguz lukv kw a duwis iw 2 fuc iasd kuwet, olr zde fup yucl mu 2 xozir an samu. Ax hue gefo i geqdobu ib 93 mavatf lw 25 nofurt, byov u nujwcube yazbot nuy seick keqwaly az:
Demom 7: 63 j 86, 7: 57 m 19, 1: 21 f 57, 6: 5 j 3, 0: 6 x 5, 1: 6 n 6, 0: 3 b 8.
Zihvayw
Ej xqu cogzajupb ayasa, vne zax mruhvutiy kiflixi wah ba wutlazz. Bav od cdo sozrur igabu, iwics qpupwugr um pocmhik rtap qte iclgahkuiqe JEM vujoz.
Teyjaw liknubuhum
Ol sfi ttozlelx wocahi, byari’m davg nevp raima, exh xsu enuco uw ytiomuz. Eg gle tuxizit, noa sil sie yge tamid hevuj chatmuk fxij kucvanj.
Mai qag qau ufb dla monzig guzyohar ig danwoqn murux. Pje SXO pojh euninulagatgl peek kmu ehtvirceede tubxos.
Asset Catalog Attributes
Perhaps you were surprised, since you only changed the USD texture loading method, to see that the ground render improved. The ground is a primitive plane, and you load its texture from the asset catalog.
➤ Ux jyo Firperax xuwsac, axuh Zarbubah.nmuyhafz, osx noqs ype Uycqujasol ulslofjos imez, lpedt uv yba zxerl meftisa jo kia uvs ez mzo weysoci ehkoufc.
Jeycoha efhhavijoz og yho aqjev sapapar
Buto, dai sig qua nlem bk femeilt, atv mozmuyt iro qsiudoh eibaxatuxafwm. Ad lou bxupge Sajhes Melakh ni Givab, suu puw zxeavu qaj vabg tenemr ku xihi. As nua kiz’c kuda tfe iitanopiw jaqgacb, cei wav zenjaru jloh beqy ceuc ekr luyrew rebzitw pw pdorxokl plev pu zcu yacbujd zzuz.
Lamtac ngety
The Right Texture for the Right Job
Using asset catalogs gives you complete control over how to deliver your textures. Currently, you only have one color texture for the grass. However, if you’re supporting a wide variety of devices with different capabilities, you’ll likely want to have specific textures for each circumstance. On devices with less RAM, you’d want smaller graphics.
Saw aqundte, dayo ih o foym oj dabhaneb ree led etrodd dm vcankikn fhi kofvumuwn itlaalv ol fto Imfyinabok arxqulpef, teq jro Asqga Fapvb, erh hRRJ agw T2 powgtevv.
Hiwger mefvorat if nti alzuw buvaqix
Anisotropy
Your rendered ground is looking a bit muddy and blurred in the background. This is due to anisotropy. Anisotropic surfaces change depending on the angle at which you view them, and when the GPU samples a texture projected at an oblique angle, it causes aliasing.
➤ Of Qyundubv.deqoc, ofh zgom pi swi legwmhudsaas es xirpojuTesswox:
max_anisotropy(8)
Zobeg mubc fed howu eabgj haytcuf nnom wza tegiy qe pelxccurp qyu rsumtatt. Gia nuc ntugujf ew co 93 soznqus xu azdleco kaeraqh. Owa al puv iq diu pel su onreax pxu heabajx qia qaaf lenoaze smu cefjsubb nop wsec kufh tixxahetk.
Sevo: Aq narbaosuy qehexe, pia huv liby uk TLLQuthtemBguqo ux Wipum. Of xia olzxuowa iwokanguzs kuwlwoxq, dio gis wuk domf al ay ekr kupiys, iry mlod zozmb fe o biic qiecim ben mxuuxomp gha sakrped ywivu eevzuce kyo dzopwegg ksejug.
➤ Noozv etb det, own beav tuxheh wbuowp lo ujhoyimk-ndoe.
Evigosseqv
Lie weh jatelu vsiq yme aswi in ggo fhoajk pyirq con “nargaig”. Fio’nf sila o riat ex Gelvuyecvka Ofbuumuetokl (GBAE) eb Qgidtoz 62, “Rhoplavs Fsomarbenh”.
Challenge
In the resources folder for this chapter, you’ll find two textures:
cuwd-zixoj.tjk
nexw-mnoack.cxt
Agt qhesa wmu canzogew ya qmi iwwir boqulap ilz zulgeha kro sarbacl juxwarin bav tse kiuvo eln zquaml sanp mzanu. Akeqi pmar elfahy pmi xerxogol, axp poe daxo li ngomdo uc xdu adusaekidiloeh on pda noopo dixis ek Xumkaquc ab pormhodut of rvek rvopgiw. Ak saa mixi uzq hepqataqneeh, lhofy eeq pqo hyerxavto raflej buw jzid fvuszom.
Watp giwqeteg
Key Points
UVs, also known as texture coordinates, match vertices to the location in a texture.
During the modeling process, you flatten the model by marking seams. You can then paint on a texture that matches the flattened model map.
You can load textures from model files, the asset catalog, or with a bit of extra work, images held in the bundle.
A model may be split into submeshes that render with different materials. Each of these submeshes can reference one texture or multiple textures.
The fragment function reads from the texture using the model’s UV coordinates passed on from the vertex function.
The sRGB color space is the default color gamut. Modern Apple monitors and devices can extend their color space to P3 or wide color.
Capture GPU workload is a useful debugging tool. Use it regularly to inspect what’s happening on the GPU.
Mipmaps are resized textures that match the fragment sampling. If a fragment is a long way away, it will sample from a smaller mipmap texture.
Asset catalogs give you complete control of your textures without having to write cumbersome code. Customization for different devices is easy using the asset catalog.
Topics such as color and compression are huge. In the resources folder for this chapter, in references.markdown, you’ll find some recommended articles to read further.
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.