SolastweekweventuredintoUnity, ourfirstforayintothree D andnotonlythree D, butalsojustgettingourhandsaround, um, ourheadsandhandsaroundtheUnityGameengine, whichisamongunrealandotherssortofthemostpopulargameenginesanduseforto D andthree d games.
Um, andlastweekwedidsortof, ah, 2.5 d stylehelicoptergamewherebyeverythingwasn't three D, butwewerestillaligningthingsbasedonjusttwoaxes.
The X and A y, I believepossibledizzyandwhy I don't remember.
Buttwoaxesversusthreeaxestodaywillactuallybedivingintousingallthreeaxesavailable, twisting 93 d inthecontextof a gamecalleddreadhalls.
Andso a dreadhallsisis a V.
Itwas a PRgame, actually, thefirstoftheourgamethat I everplayedontheOculus.
TheGear v.
R.
Simpsongiv e r.
Anditputsyouinsortofthisdarkandeeriethree D mazewhereyoudon't reallyknowwhat's goingon, andyoucangoaroundandgetcollectiblesandencountercreaturesandstuffasyoucanseeinthebottom.
Right?
Screenshotthere.
Um, today's examplesgonnabe a littlesimpler, butitallowsustoexplorethingslikeproceduralmazegenerationand, um, firstpersoncameracontrols.
Solastweek, recallwewereusingsortof a 3 1/3 personcamerawherebyweweresortoffarbackonthescenetodaywillactuallybeusing a firstpersoncamerawherethecameraiseffectivelyoureyesasifyouwerewalkingaroundinthemazeourselves.
Unfortunately, wewon't beusing a V R demonstrationthisweek, butnextweek I hopetoputtogethersortof a V R sampling.
Sonotonlymaterials, butalsothedifferentkindsoflightsthatunitysupportsand a fewdetailsaboutthosewe'lltalkaboutagainthree d maisgenerationsSowe'llhave a simplebuteffectivealgorithmforcreating.
Um, a three D datastructuretripisinourlevel, asopposedtopreviouslywherewehadjust a, youknow, a tilemapthatwecouldgeneratetogiveustheappearanceofwalkingaroundinsomesortoftwo d world.
Nowwell, actuallyperform a similaroperationondatatodeArray.
Butwe'lltakethatarraignwell, actuallycreatethree D blocksandcreate a mazethatwecanwalkthroughinthree D space.
Um, whichiskindoffunandinteresting.
Lastweekweonlyhadonesceneinourgame.
Sowhichwasjust a placeseen.
Andeventhoughwehadsortoflike a gameoverstatewithinthatscene, wedidn't transitionbetweenscenes.
Wejustsortofreloadedthesamescene.
Todaywe'llhave a titlescreenand a placescene.
Whichsortof, um, isanevolutionoftheideathatwehadinloveto D, wherewehad a statemachinethatwasgoverningourentiregameintermsofthedifferentstatesthatwecouldbein, whetheritwasthetitleofthegameovertheplace, stateandsoforth.
Unitydoesthesamethingwithseenobjects, whichareeffectively a snapshotofahSiri's ofgameobjectsalignedin a particularway.
Intheeditor, we'lltalkaboutfogandalsogloballightingandcertainotherthingsthatallowustocreate a atmosphereconducivetothesortoffeelthatwewanttogetinourgametoday, whichissortofcreepyandeerie.
Andlastly, whenwetalkabouthowtocreateyou y elementsinthegame, we'lltalkaboutunityto D.
Um, wehave a verywecouldhaveeasilydonethisinloveto D.
Thisisjust a blackscreenwithtwo, uh, textlabelsonit.
AndthisisdonewithUnity's two d.
U.
I.
Toolkit.
Andsoitsaysittellsustopress, enter.
Soif I pressenter, weinstantlygetteleportedintokindoflikethismaze, thiscreepylookingmaize, andso I canwalkaroundinthismazeandthereare a fewthingsgoingon.
So, anybodycananybodytellmesomeofthethingstheynoticeaboutthescene, Butwhatjumpsoutofthem, whataresomeoftheelements?
AndthereisSowe'regenerating, uh, notonlywallsinourscene, ofcourse, butweneed a groundtositinanoffice.
Andalso, ifyoulookuptop, it's kindofdifficulttotell, butwealsohave a ceilingsogroundintheceilingandwalls.
Somekindoflighting.
Yes.
Um, Andsointhiscase, we'reactuallyusingambientworldlightingasopposedtohaving a lightsource.
Sowe'lltake a lookatthat.
Lastinlastweek's lectureweusedfortwoweeksPriorislectureweused a directionallightobject, butinthiscasewehavenolightsinthescene.
We'reactuallyusingUnity's Worldlighting, whichwilltake a lookatsoon.
Um, whenwewalkaroundknowsthat I canmovemywheremycamera's lookingwithmymouse.
Sowe'reactuallycontrollingthecamerawith a firstpersoncontrollerin F PScontroller, whichisactually a componentthatunityprovidestoyouandthennoticeeventually.
Ifwekeepexploringthemaze, wecomeacrossthislittlethinghere, whichis a sortof a pickup, andwhenwepickthisup, wegetsortoflikethispianoweird, creepypianosoundandinthescenereloads, um, anybodynoticedanythingaboutwhatweseeinthedistance, likehowthat's howthat's effective.
I thinkif I'm lookingatthiswallrighthere, forexample, it's kindofhardtotell.
Sowe'rewe'reexperiencingherewe'reseeingis a It's a a graphicssortofconceptcalledfogandSowhatfogletsyoudoiseffectivelyaddscolortothescenebaseduponhowfarawaytheobjectsareinthesceneandmultipliescolorontothem.
Yeah, that's muchyouneedasmuchpixelclaritykindofthethebigthingaboutfogandthewaythatitwasused a longtimeago.
Isthatbecauseeventuallythingsarecompletelyopaquebeyond a certainpoint, youdon't needfardrawdistanceinyourgamesoyoucanactuallylikedynamicallyyoucanyoucanomitrenderingthingsthatare a certaindistanceawaybecauseyouwouldn't beabletoseethemanyway, asthiswasanoptimizationtechnique.
Used a lotbackwhendrawdistancewas a hugebottleneckoncomputersandgavevideogameconsolesbackinthenineties.
Forexample, likeSilentHill, thegameforPSonewasalmostexclusivelyfog, andyoucouldseeverylittleinfrontofyou, andwe'llsee a screenshowthatlater.
Um, andtheyusethatfortoboosttheirperformanceandalsotoprovide a certainaesthetic.
Andthenoneotherthingyoumightbebeingattentiontoisthere's a soundonloop, justsortofthiscreepysortofwhisperingsound.
Um, butitwouldbenotterriblydifficulttoadd, butbecausewe'reusingproceduralgeneration, youwouldneedwhat's called a knavemesh, andyouwouldneedtogeneratethatprocedure, least, thatthingscouldfollowyouinthree D space.
Um, mighthavesometimetotalkabouthowtodothat a littlebitlatertoday.
Um, butthat's notimplementedinthisparticularlecture, butitwouldbenottoinfeasibletoaccomplish, butthosearesomeofthepiecesthatwilltake a lookattoday.
Butwecanseeeventhoughit's a two d sortof, um, you I it's veryvisibleinthree D space.
Andifyouclickthisbuttonhere, weendupgettinguhoh, no, that's justbringsusintoSorry.
Clickthisbuttonhere.
Thatbringsusintosortofthetwo D unitytodemotesanhourinteractingwiththingsintwo D, and I canactuallyclickonthislabelandmoveitaroundintwo D, asifwewereusing a to D gameengine, asopposedto a three d gamementioned, sowe'lllookatthat a littlebitlater.
Thisisthejustthetitlescene.
Sotheplacingitself, I'm notgoingtosavethat.
Theplaysceneitselfgonnagofromtwo D backto 32 hereisprettymuchempty.
ButthecamerarightwheretheplayeriseffectivelywheretheirheadshouldberelativetowheretheirbodyisandtheirbodyWhat's constitutingtheirbodyhere, Canyoutellyoucouldjustbe a cutelookslike a Cuban.
It's this.
It's actuallythiscapsulerighthereifyoucanseeit.
Uh, there's thiscapsulehere, thisgreencapsule.
It's a littlebitmoreorganicfeelingthan a cube, necessarily.
Butyoucoulduse a CubasWell, um, but a capsuleishow, uh, charactercontrollersandunityarerepresentedandcharactercontrollerssortofcomeforfreeinunity, whichisreallynice.
They'repartofthestandardassets.
Soifyougotoimportpackageimmunity, ifyou'regoingtoassetsimportpackage, there's a lotofpackagesthatcomeforfree.
Thesortofbootstrapyou, um, noticed.
There's activitypackages, cameras, characters.
Thecharacterspackagehasthree D charactersarethirdpersoncharacters, firstpersoncharacters, somethatarephysicsbasedonthatarenotphysicsbased.
Butit's notstrictlyphysicsbasedlike a rigidbodyand a rigidbodywould.
Andthecollisionsthatoccurbetweenthisandotherrigidbodyaren't thesameastheywouldbeifweweretomakethis a purelyrigid, bodybasedcharactercontroller.
Thereis a purelyrigid, bodybasedcharactercontrollerthatyoucanimporthavingexperimentedwithit a lot, butyoucouldprobablyfigureout a gooduseforthatintermsofthegameremade, youwanttoemovepreciselyonsurfacesthathavedifferentmaterials, likeicysurfacesorwhatnotandhaveitapplyitin a veryphysicallyrealisticway.
Um, I have a fewthingsthatwehavehereinourplace.
Seen.
Wehave a dungeongeneratorobject.
Sothisdungeongeneratorobjectisjustempty.
Objectwith a levelgeneratorscripthere.
Andthenwehave a fewotherobjects a floorparent, a wallsparentand a whispersource.
Youcandoeverythingveryvisuallyandwiththemousesince, actuallyit's a It's a pleasuretomakinginterfacesifyou'reusedtojustmakingtheminincode, sotext a ring.
Whatbasicallyhappensisgoingtointerpretbetweenthetexturepixels, thattextileswhenyouapply a texturetoyourcube, andsowhenyouplay a smalltextureto a largesurface, it's gonnalookstretched.
IsitlikeyousortofseeinsomeYouTubevideosifyouwatchthemandtheyrecorded a verysmallresolution, butyoublowthemup, theylookfiltered.
Orifyou'veeverstretched a pictureintherightsoftwareandit's looked, looksinterpretedandfiltered, it's gonnahavethatlook.
Soyoucandoisyoucanapplytiling.
Soherewecanseethere's a tilingelement X and Y soofoneinthe X and Y directionbecauseitonlyapplieson a flatsurface.
Sotheeffectoftilingwouldbesuchthatifyouhave a 64 by 64 texture, youcouldjusttilethattextureseveraltimestogetthedesiredlookthatyouwantonwhateversurfacethatyou'retryingtolookatinyourgameworld.
Maybeit's a verysmallobject, butmaybeit's a verylargeobjectthatyou'relookingatas a character, andyouwant a tilebricks, forexample, or, youknow, Stone.
Sotoapply a textureto a, um, to a three d objectinthescene, I'm gonnagointoheresoyouneed a materialfirst.
Theseareallunitymaterialobjectsyoucantellbecausetheyhave a circular, thatlittleeyesifthey'vebeenwrappedaround a sphere.
Theseareallunitymaterials, asopposedtotextures, texturesorjusttwo d Objectto d, youknow, texturestotheimages.
Sothisispartof a anassetpactthat I downloadedforthislecturecalledDungeonModules.
LowPollyDungeonmodules, whichisintheassetstore.
Umandsowhat I'm goingtodois I'm justgonnaapply.
Let's say I wanttojustapplythisrockmaterialtothisobject, right?
I goovertothatgoingtofirst, uh, at a I thinkbecause I wentintothematerial, uh, I had a incorrectappearance.
Sodothat.
That's strange.
I'm gonnacreate a newscene, andthen I'm gonnaadd a cubeandthen a notpop, maybethebeam.
I wonderwhyitisnot.
That's verystrange.
Forsomereason, itmightbe a settingthat I haveenabled.
Butwhat I candois I cangototextureshere, andthisshouldworktogotothat, andthenitwillplayitthatway.
Sonormally, ifyou'rein a freshprojectandyouadd a newthree D objectandjustclickanddrag a materialonto a three D object, itwilltextureitforyou.
Inthiscase, I think, becauseit's automaticallyassigning a materialtotheseobjectsbasedonsomeprojectsettingthat I'm offoffthecuff, justunableto, um, I don't knowforsureyoucaninsteadjustgotothealbedocomponenthere.
Soalbedofunctionsnotonlyas a colorbutalsoas a textureforyourobject.
Andsoyoucanapply a texturejust a to D imagetoyouralbedocomponentof a material, right, Andthenwe'llhavethesameeffect.
Istexture.
Ringit, um, immediately.
Sonormally, whatifthisissupposedtodoiscreate a, um, albedocreatingnewmaterialwiththattextureastheElBeato?
Whenyousaidthematerialtotheumthree D objectnow, I wonderif I Yeah, I'm notsure.
I'm notsureexactlywhyitdidn't workas, uh, like, rightoffthebatlikeit's normallysupposedtoin a freshproject.
Itwill.
I'lltrytoinvestigate.
Butifiteverhappenslikethat, whereforsomereasonyou're I thinkithastodowiththewaytheShakersaresetonhere.
Maybethere's a setting I'm justnotsureabout.
ButyoucanjustsetthealbEdocomponentheremanually.
It'llhavethesameeffect.
Sothealbedocomponentofyourmaterialsettingthatwith a texture, textures, objects.
Andsothat's effectivelyhowwegetfrom, uh, thissortoflookof a flatshadedorflatcolorshadedobjectto a textureshadedobjectjustlikethatandtexturemappingsortofinitselfis a verywidefieldandfairlycomplicated.
But, um, ultimately, itlookssomethinglikethis.
DoesanybodyCananybodytellmewhatthislookslikehere?
Soweseehere, obviously, wehave a fullytexturedmodel.
Now, ifyouimported a modelthatwaslike a tableorcharacterandhejustapplied a texturetoit, it's notgoingtolookgood.
It's gonnalookmessedup.
Andsoyourthree D softwarewillexport a materialwiththemodel.
Assumingthatyou'vemodeledinthatsoftwarewith a texture, it'llactuallygiveyoumaterialthatyoucanthenreferencethatwillproperlyapply a texturetoyourcharacter.
Butthesamesortofapply a texture.
Just a regulartextureto a complicatedmodeljustisn't gonnaworkbecauseithasn't beenUVmapped.
In a smartway, unityisnotgonnaknow.
I have a table I wanttomap.
I wanttomapthetexturetoo.
Thetablein a youknow, in a waythatlooksconvincing.
Youcanseethiskindofifwecreate a cube, andthenifwegoaheadandbeenmakingapparentforsomereason, uh, ifweappeargonnafirst a sign, uh, okay, forsomereasonthatworkedinstantly, Um, butyoucanseewe'veapplied a sortofwalltexturetoit.
Butifyouarecreatingyourowntreatyassetsforimportingthree D assetson, ifyouwanttousetexturesin a waythatwe'redoingtoday, youwillneedtoprobablybecomefamiliarwithyou.
I don't do a lotofit, butit's somethingthat I imaginethatyoujustgetbetteratwithtimeandartists, texture, artistsandmodelingartistsprobablydeveloped, sortoflikeinattunedsenseofwhatmakes a goodtextureversuswhatdoesn't.
Effectively, whattheydoistheyuseseverallayersofmapslike a shinynousmap, whichisthetexturethattells, um, thatyoureferencein a unitycustomshaderthatyouwritewhichthearticleteachesyouhowtowrite, whichwillmakecertainpartsofthetextureglossyandcertainpartsofitnotglossy.
So, Matt, andsoyoucando a lotofreallycool, veryinterestingthings.
And, uh, thethisiseffectivelyisall a shader, andit's all a shaderthat's beenwrittenincode.
Butwehave a lotofthesevariablesthatareexposedtous, andalbedoisoneofthem, andalbedoissortofconditionalifitifitgets a textureappliedtoit, itwilljustrenderthattexture.
Andallofthesedifferentthingswaspartof a singleshader, andmaterialiseffectively a shader.
They'rekindofoneofthesame.
Materialis a littlebitdifferentinthatyoucanalsospecifyhowitssurfaceshouldinteractwithotherthings.
So, forexample, ifyou'reinanicelevel, materialcannotonlybelikethesortofglossy I seelookofsomething, butalsohowslipperyisitwhen I walkoveritandshould I slide?
Andthisarticleandmanyothersonthiswebsite, which I highlyrecommendifyou'relookingtogetreallydeepintounitywillgiveyou a lotofinsightintohowthingsworkfarbeyondjustthesurfacelevelthere.
Soanyquestionsonmaterials?
Allright, sowe'regonnatake a looknowatlighting, somaterialsmaterialsareonepartoftheequation.
Anditteachesyou a lot, teachesyoualmost, youknow, downtotheverybareingredientsofthesortofthesoftwareintherendering.
Ifyouwanttogothatdeep, I certainlyhavebeengonethrougheveryarticlebecausethere's just a tremendousamountofcontent.
It's verydeep.
Butifyou'relookingtoreallylookingtoreallyget a senseofhowitworks, I would I wouldencourageyoutoexplorethat, Um, sowelookat a fewdifferenttypesoflighting.
Okay, so a pointlightis a sourceoflightthatactually, uh, shootsoutinalldirectionsaroundit, soitemitslightinalldirections.
Butwithin a confinedareaand a specificintensity, a spotlightshineslightin a specificdirection.
Soonlyonedirection.
Andwhat's interestingaboutspotlightsisyoucanactuallyapplywhat's called a cookietothemandwhat a cookiedoes, verysimilartowhatthebatliketheBatmanLitedoes.
Itallowsyoutoapply a textureto a lightandthereforecastshadowsspecificshadowsonthelight.
It's effectivelythesamethingastaking a literalspotlightandputting a objectontoit.
Itproduces a shadowEmmanuelshow.
It's calledcookieUm, a directionallightsoanybodyknowwhat a directionallightis.
Sodespiteitsname, it's actuallynotus.
Notthesamethingas a spotlight.
Sodirectionallight.
Weused a directionallightlastweek, actually, lastlectureDirectionallightcastslightin a singledirection, butthroughouttheentiresceneasifit's thesun, sothisallowsustoilluminategloballytheentirescene.
Butalllightgetscastfromonedirection.
Soifyouwant a toe, producetheappearanceofdaylightinyourscene.
Just a singledirectionallightwillilluminateeverything, andthenthelastthingwhichisusedlessiscalledanarealight.
Soit's lightthatwillemitfromthesurfaceof a, um, specificallydesignated, uh, rectangleeffectivelyinonedirection.
Soyoucandefine a largearea, forexample, maybelikemaybeyouwant, like a wallstripinyourgameorsomethingalongthewalltoemitlightspecificallytotheleftorsomethinglikethat.
That's whatanarealightiscapableof.
Now.
Arealightsarecomputational e expensive, andsoyoucanonlyusethemwhenyoubakeyourlightingseemtorememberwhatbakingmeans.
We'rein a frankthelighting, sobakedlightingjustmeansthatinsteadofrealtimelighting, calculatingthingsdynamically.
Soifyou'rewalkingthrough a bakedlightingsceneandyou'reexpectingtocast a shadowonsomething, orforsomethingtocast a shadowontoyou, it's notgonnahappenbecausetheenvironmentsalreadybeenthelighting.
Forthat, Sean's beenprebaked.
It's almostasifwe'vejustrecoloredtheworldin a specificway, Butwe'renotactuallydoinganylightingcalculations.
Butthisishowlightingworkedinlikethe N 64 era, andit's howitstillworksnowforcertainsituations, youknownothing's gonnacast a shadowonsomething.
Youcanmakereallynicelookinglightingfor a scenewithoutumneedingtodoitinrealtime.
Um, thisdirectionallightisOnleyshininginonedirectionso I canmoveithere.
Socurrently I'm in.
Um, it's a littlebitweirdtonavigatejustbecauseit's beenrotated a littlebit, giventhatit's a directionallight, itsrotation, umsonoticehowitchanges.
Soif I shineitupwards, knowseverythingcomesblackbecausethelightingisjustshiningupwards.
Writesasifit's comingfrombelow.
Andif I shineittowardsthereknowsthatthelightingonthethesphereandthelittlecubetheresortofchange a bit, right, becausethey'regettingaffectedbythedirectionofthelight a littlebit.
Um, wewon't talkaboutthoseintoday's lecture, butthere's a point, like, forexample, Solet's see, Whereisit?
That's rightoverhere.
So I'm gonnamoveitoverheresoyoucanseeit's notglobal, likethe, um, directionallightwasright.
It's justaffectingthisverylimited.
I'm gonnazoomin a littlebitsoyoucansee a littlebitbetter, butit's affectingjustsortofthesetwoobjectsrelativetowhereitspositionisright, andsothisworksperfectlyforthingslikelampsandyourscene.
Ifyouwannahave a streetlightorwhetheryouwanttohavetobelike a firegoingoninthehouse, orifyouwantthe, Youknow, likethepowerupthatwehadinthe, uh, thepickupthatwehadintheah, unity.
Seenright.
WehavejusttheIt's just a meeting.
A purplelightthat, um, iswithin a verysmallradius.
Noticeherewecanchangethecolorofthelight.
Soif I makeitlikethat, um, forsomereasonOh, hereyougo.
Sodothat.
SonoticeNowit's emitting a purplelightsoyoucancoloralight.
Thea, forexample, themanualin, um, it's nothere, So I didn't include a picturehere, butthemanualshowsliketherearesomekindoflikethelightsthatyouputonthestandandtheyhave a bunchof L E.
D's right, andthey'reserving a gridandtheyshootout.
Spotlightyoucancreate a cookie.
That's kindof a grayscalewiththosegreetedlines, anditwillshootlightontothesceneasifit's beingbroadcastfrom a sortofgridof L E.
D's.
Sothere's a lotyoucandowithjustsomeverysimpleideas.
Wecanseewhat's called a bumpmap, andontheright, wecansee a district a flat, um, like a flatplanewith a bumpmapwiththesamebumpmap, applytoitandthenilluminated.
Sowhat a bumpmapallowsustodoistotake a flatwallorflatsurfaceorwhateveryouwantandthensimulatelikeanactualthreedimensionalcontour, threedimensionalbumpsorwhateveryouwantonthatsurface, um, withoutneedingtocreatetheactualgeometrytomakeitpossible.
Um, thisiskindof a toyexample, butit's actuallyrelevantintheinthecaseofwallsthathaveandwecoveredthislastweekjustnotasmuchdetailbutwallsthatyouwanttobeflatandyoudon't wanttohave a lotofpolygons, foryoucancreate a bumpmapforandapplythatbumpmap.
Andthenwhenyou'rerenderingitwhenyouwalkpast a wall, it's gonnalookasifthewallactuallyhascracksandbumpsinit, Um, for a realisticeffect, andthisisusedinthegametoo.
Slightdegree.
Youcancrankitupifyouwantto.
I didn't onmycomputerbecausemysettingsareMyspecsaren't sufficient, buteverytextureintoday's examplehas a bumpmapassociatedwithit.
Um, soyoucanactuallyseewherewhatthe, umumyoucanactuallyseetheeffectofbummappingatvariousdegreesof, umofusethematerialshere, So I'm gonnago.
I'm gonnaloadupthescenethathastheactualstuff I'm goingto, actually, I don't needtolooktosee.
So I'm intheactualplace, seensoinscenes I loadedupPlayasbefore I'm goingtohitplay.
Um, I'm gonnaturnoffmysoundsbecausethecreepysounds a littledisorientingafter a while, um, andthengoingthioUm, actually, I'm goingtogoto a twobythreeofyouandthenhitplaysowehavetheregulargameviewdownherebelow, andthenalso, if I zoomout, youcanseethatareseenwasemptybefore.
Butnowwe'vegot a maze, andcurrentlyit's notveryvisibleatallbecauseonewereplayingfog.