Instancing in OpenGL

文章推薦指數: 80 %
投票人數:10人

Whenever you find yourself in a situation where you want to render many copies of a single object, you're instancing said object. The general case that I was ... Thesol.gfxile.netserverisgoingawaysometimeintheyear2022.You'rebrowsingtheoldserver;thesepageswillnotbeupdated. Thepermalinktothispageishttp://iki.fi/sol/instancing.html Pleaseupdateyourlinks,andseeyouonthenewserver! News/Blog Who? Stories Tutorials Speccy Code Demos Breakdown Games Audio Miscfiles Links Stuff Sol::Tutorials InstancinginOpenGL Thisismoreorlessare-hashofmy"renderinglotsofcubes"article,buthopefullymorecoherentandinformative. Whatisinstancing? Wheneveryoufindyourselfinasituationwhereyouwanttorendermanycopiesofasingleobject,you'reinstancingsaidobject.ThegeneralcasethatIwastryingtooptimizeforwastohavelotsofotherwiseidenticalobjects,buteachwithitsowntransformationmatrix. That'swhat125000cubeslooklike.IpumpedtheinstancecountuptoridiculouslevelssoIcouldseewhatkindofperformancedifferentinstancingapproacheswouldget.Eachoftheapproachesdescribedherehasitsgoodandbadsides. Fortheperformancevalueslistedhere,twocomputerswereused.BothhaveCorei7,8GBofRAMandwin764bit;onehasanNvidiagtx260andtheotherhasaATIhd5700videocard.Screenrefreshsyncwasturnedoffforalltests.Here'sanoverviewtableoftheresults,beforewedigintotheapproaches: Nvidia ATI Cubes(VA)Cubes(VBO)Torus(lo)Torus(hi)Cubes(VA)Cubes(VBO)Torus(lo)Torus(hi) Noshaders59.3ms41.1ms41.1ms55.3ms49.2ms Plainshaders86.7ms80.5ms81.0ms80.4ms50.0ms Pseudoinstancing70.1ms30.0ms30.4ms51.9ms103.6ms Matricesintexture41.0ms10.4ms22.8ms50.7ms18.8ms2.8ms12.2ms23.0ms Matricesinuniforms45.5ms18.7ms23.1ms50.5ms Instancedarrays11.3ms22.8ms53.2ms19.3ms2.8ms12.2ms23.0ms Thetestsetupuses64000instances,andthegeometryincludescubesinvertexarrays(VA)orvertexbufferobjects(VBO),andlow(~80tris)andhigh(~230tris)polycounttoruses(bothinaVBO).Ididnotrunthroughalltestcasesonbothmachines,becausesomeoftheseteststakealongtimetorun. Specificallynon-VBOinstancedarrayswereextremelyslowonNvidia,andmymatricesinuniformscasedoesn'trunontheATIboardeventhoughI'm"only"usinganarrayof32matrices(theNvidiaboardcando100). Noshaders The"noshaders"testcaseisjustthat-noshaders,noinstancingextensions.Theold-school,fixed-function,opengl1.xwayofdoingthings.Justrenderlotsofcopiesofasingleobject. for(i=0;i



請為這篇文章評分?