CSc 165 Compuer Game Archiecure Overview Texure Mapping 9 - Game World: exure, kyboxe, ec. Game World Background SkyBoxe & SkyDome World Bound and Viibiliy Render Sae 2 Texure Mapping Texure Space Baic idea: aach an image o an objec o Objec == polygon() o Image ued hi way are called exure Texure have heir own coordinae pace: exel Image Objec Polygon Texure-mapped objec 3 4 4 Verex Texure Coordinae Each verex ha an aociaed exure coordinae o Texure coordinae can be e by he program V = (10, 20) T = (0.0, 1.0) V = (30, 20) T = (1.0, 1.0) combining ligh and exure Color = exurecolor * ( ambienligh + diffueligh ) + pecularligh or Color = exurecolor * ( ambienligh + diffueligh + pecularligh ) or Color = (ambligh * ambmaerial) + (diffligh * diffmaerial) + pecligh fragcolor = 0.5 * exurecolor + 0.5 * lighcolor 10 20 V = (10, 10) T = (0.0, 0.0) V = (30, 10) T = (1.0, 0.0) 5
RAGE Texure clae (inerface) AeManager + ebaedirecorypah (Sring pah) Game World Background (abrac) AbracAeManager + geaebyname (Sring name) + geaebypah (Sring pah) + geaecoun () TexureManager Texure * + eimage (java.aw.image.bufferedimage img) + geimage () Real cene alway have background Game world background MUST be 3D Why? Indoor: room wall Oudoor: horizon cenery TexureManager m = eng.getexuremanager(); Texure redtexure = m.geaebypah("reddolphin.jpg"); 7 8 RoomBoxe SkyBoxe Bu wha abou oudoor game?? Camera RoomBox Soluion: SkyBox o Texure-mapped oudoor cene o Can be mapped ono differen geomerie Recangle Cube Hemiphere 9 10 Texure Cube Map Creaing Texure Cube Map Unfolded cube 11 (6) differen image file Creae a 3D cene Place camera in middle wih 90 FOV Render image in each of ix direcion Some ool: Terragen Blender Bryce SkyPain 3DSudio Max Maya 12
Terragen Example Scene SkyBoxe challenge: Require ix exure ue valuable exure memory Time-conuming o build Cube can caue diorion near corner Can how arifac a exure eam mimache in adjacen exure pixel Inconien definiion of fron & back download Terragen: hp://www.planeide.co.uk 13 14 SKYDOMES World Box Bound N ack M lice (ide) Y Φ r Ө P X Careian (x,y,z) = Polar (r,θ,φ) x = r * co(θ) * co(φ) y = r * in(φ) z = r * in(θ) * co(φ) SkyBox hould alway be far away no maer where uer move Trick: move box wih camera camera alway ay a cener of box. box move, bu doe no urn, wih camera. Blender, Phoohop, and many oher have ool for manipulaing fih-eye panoramic phoo Mo common approach: ranlae box o camera locaion before drawing 15 16 Building a imple SkyBox from crach // Called from eupscene() // - creae a imple SkyBox ou of a Cube creaeskybox: { inaniae a Cube inaniae a SceneNode for he Cube, wih roo a paren aach he Cube o he SceneNode exure he cube wih SkyBox exure (require appropriae exure coordinae) poiion he cube a he camera locaion SkyBox Viibiliy Problem: objec may lie ouide box HSR mean he box will hide hoe objec // Updae() now alo poiion he SkyBox a he camera locaion Updae: { ge camera locaion ranlae SkyBox SceneNode o camera locaion (noe do NOT roae he kybox cube) SkyBox Eye a cener of box Objec ouide of box hould be viible! 17 18
The Z-Buffer ( Deph Buffer ) Pixel (x, y, z) (r, g, b) The Z-Buffer algorihm: Color if (pixel.z < dephbuffer[x,y]) { colorbuffer[x,y] = pixel(r,g,b); dephbuffer[x,y] = pixel(z); y Deph (Z) x 19 Color Buffer y x Deph ( Z ) Buffer SkyBox Viibiliy (coninued) Rendering rick: Effec: o Ree (clear) deph buffer o max deph o Diable deph eing/updaing o Draw SkyBox fir o Re-enable deph eing o SkyBox pixel will have maximum deph o Subequen objec drawn wih updaing enabled will appear cloer How can we make hi API-independen? 20 Render Sae Render Sae (con.) Deired render ae for hi Renderable Renderable Renderer diplay() { for each Renderable r { erendersae(r) drawrenderable(r) Curren renderer ae <<inerface>> RenderSae - enabled : boolean abrac getype(); abrac apply(); Render Sae example: ZBuffer mode Texure mode many oher erendersae(r) { r.gerendersae for each render ae { if enabled, apply drawrenderable(r) { drawarray(r.buffer) <<inerface>> ZBufferSae <<inerface>> TexureSae <<inerface>> FronFaceSae GL4ZBufferSae DXZBufferSae GL4TexureSae DXTexureSae 21 22 in ome engine, render ae are aociaed wih cene node (e.g., SAGE, JMonkey). Differen render ae ype can have differen capabiliie and funcionaliy in hi cae, render ae propagae hierarchically <<inerface>> RenderSae in ome engine, render ae are aociaed wih eniie or renderable, no cene node. Thi i how RAGE work. In hi cae, if a render ae i inended for an enire ubree (e.g., ranparency), he applicaion mu e he render ae for each node individually. <<inerface>> ZBufferSae GLZBufferSae gegltefuncion(); <<inerface>> TexureSae GLTexureSae eminificaionfiler(); ewrapmode(); <<inerface>> FronFaceSae 23 24
Creaing a Skybox in RAGE void eupscene() {... Configuraion conf = eng.geconfiguraion(); TexureManager exuremgr = geengine().getexuremanager(); exuremgr.ebaedirecorypah(conf.valueof("ae.kyboxe.pah")); Texure fron = exuremgr.geaebypah("fron.jpeg"); Texure back = exuremgr.geaebypah("back.jpeg"); Texure lef = exuremgr.geaebypah("lef.jpeg"); Texure righ = exuremgr.geaebypah("righ.jpeg"); Texure op = exuremgr.geaebypah("op.jpeg"); Texure boom = exuremgr.geaebypah("boom.jpeg"); exuremgr.ebaedirecorypah(conf.valueof("ae.exure.pah")); // cubemap exure mu be flipped up-ide-down o face inward; // all exure mu have he ame dimenion, // o any image heigh will do AffineTranform xform = new AffineTranform(); xform.ranlae(0, fron.geimage().geheigh()); xform.cale(1d, -1d); coninued 25 fron.ranform(xform); back.ranform(xform); lef.ranform(xform); righ.ranform(xform); op.ranform(xform); boom.ranform(xform); SkyBox b = m.creaeskybox( myskybox ); b.etexure(fron, SkyBox.Face.FRONT); b.etexure(back, SkyBox.Face.BACK); b.etexure(lef, SkyBox.Face.LEFT); b.etexure(righ, SkyBox.Face.RIGHT); b.etexure(op, SkyBox.Face.TOP); b.etexure(boom, SkyBox.Face.BOTTOM); m.eaciveskybox(b);