visualization - Easiest way to visualize 10,000 shaded boxes in 3D -
i have simple task: have 10,000 3d boxes, each x,y,z, width, height, depth, rotation, , color. want throw them 3d space, visualize it, , let user fly through using mouse. there easy way put together?
one easy way of doing using recent (v 3.2) opengl be:
- make array 8 vertices (the corners of cube), give them coordinates on unit cube, (-1,-1, -1) (1, 1, 1)
- create vertex buffer object
- use
glbufferdataarray vertex buffer - bind vertex buffer
- create, set up, , bind textures may want use (skip if don't use textures)
- create vertex shader applies transform matrix read "some source" (see below) according value of
gl_instanceid - compile shader, link program, bind program
- set instance transform data (see below) cube instances
- depending on method use communicate transform data, may draw in 1 batch, or use several batches
- call
gldrawelementsinstancedn number of timescountset many elements fit 1 batch - if use several batches, update transform data in between
- the vertex shader applies transform in addition normal mvp stuff
to communicate per-cube transform data, have several alternatives, among them are:
- uniform buffer objects, have guaranteed minimum of 4096 values, respectively 256 4x4 matrices, can query actual value
- texture buffer objects, again have guaranteed minimum of 65536 values, respectively 4096 4x4 matrices (but larger, elderly card can 128,000,000 values, should query actual value)
- manually set uniforms each batch, not need "buffer" stuff, slower
alternatively: use pseudo-instancing work on hardware not support instancing directly. not elegant , slower, job.
Comments
Post a Comment