Instancing in OpenGL
文章推薦指數: 80 %
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
延伸文章資訊
- 1Instancing in OpenGL
Whenever you find yourself in a situation where you want to render many copies of a single object...
- 2Particles / Instancing - OpenGL Tutorial
Thanks to instancing, they will be shared by all particles. static const GLfloat ... Update the b...
- 3Instancing - LearnOpenGL
Instancing is a technique where we draw many (equal mesh data) objects at once with a single rend...
- 4实例化
如果我们能够将数据一次发送给GPU,就会更方便,然后告诉OpenGL使用一个绘制函数,将这些数据绘制为多个物体。这就是我们将要展开讨论的实例化(Instancing)。
- 5How to do instancing the right way in OpenGL. - Stack Overflow
glDrawElementsInstanced use gl_InstanceID variable as if it were a static integer vertex attribut...