three.js icon indicating copy to clipboard operation
three.js copied to clipboard

batching of draw calls of all objects with same mesh - maintaining independent properties of objects

Open davidedc opened this issue 13 years ago • 6 comments

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?

davidedc avatar Dec 01 '13 12:12 davidedc

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.

zz85 avatar Dec 01 '13 14:12 zz85

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?

davidedc avatar Dec 01 '13 14:12 davidedc

@zz85: could you provide some more info on how to do this with BufferGeometry?

GuyGood avatar Dec 01 '13 21:12 GuyGood

@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

mrdoob avatar Dec 02 '13 06:12 mrdoob

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.

zz85 avatar Dec 04 '13 04:12 zz85

Closing in favor of #17505.

mrdoob avatar Sep 16 '19 23:09 mrdoob