batching of draw calls of all objects with same mesh - maintaining independent properties of objects
Would it be possible to batch the draw calls like explained here? http://youtu.be/rfQ8rKGTVlg?t=14m44s
He basically batches together in the same draw call many objects with the same mesh, sending to the shader the per-object information.
Note that this is not equivalent to a mesh merge, as all objects maintain their independent position and properties that can be still changed at will between frames.
Advantage being that, say for drawing x boxes, one would issue far less than x draw calls (and related calls for setting uniforms, etc.). In the demo of the link, this buys quite a lot of performance...
Would this make sense? Would it be possible?
Are you asking for an API to do this? Right now, this can be archived using a merged geometry with custom attributes or using BufferGeometry (with some extra shader code).
Also, rendering multiple instances can be improved when WebGL instanced arrays arrive in browsers.
this can be archived using a merged geometry with custom attributes
Cool. In this case too obviously I need to change the default shaders a bit to make sense of the extra custom attributes, correct?
Useful to know, but yes I was rather thinking of a way where this type of batching happens automatically? If I add n geometries of the same type to the scene, would it make sense for three.js to figure out automatically that batching of the calls needs to happen? Or for some reason is this a bad idea?
@zz85: could you provide some more info on how to do this with BufferGeometry?
@zz85: could you provide some more info on how to do this with BufferGeometry?
You can find the technique details in this video:
http://www.youtube.com/watch?v=rfQ8rKGTVlg
while it could be possible to create an API like new THREE.InstancedMesh(mesh, material, copies), i'm not keen to implement it now. anyone whose interested should look into instanced arrays mentioned above, which probably allows instancing for materials too.
for an example, you can look into examples/webgl_gpgpu_birds. it's an example of a "merged" geometry while rendering it as many independent objects in the shaders. it can technically be done the same way for BufferGeometry, but i haven't gone into that yet.
Closing in favor of #17505.