PDA

View Full Version : experiences rendering instances



cyrfer
04-19-2010, 10:19 AM
Hi,
I'm trying to understand how I can specify transform data for multiple object instances. I've seen the NVIDIA SDK 10 (Simple Texture Buffer Object) example that gets data stored in a TBO with an integer index, just like how I think I would need to use 'gl_InstanceID'. Are TBOs the preferred way to access data via an index?

Also, should the application be able to draw many more objects at a higher frame rate? I modified the NVIDIA example to synthesize a position offset based on 'gl_InstanceID' and the performance is much worse (model=venusm.obj, instance count=300).

Alfonse Reinheart
04-19-2010, 10:40 AM
instance count=300

That's why your performance wasn't better: too few instances. Instancing isn't a win until your instance count is in the thousands.

Also, instancing isn't a win unless your application is draw-call or state-change limited to begin with. Is it?

cyrfer
04-19-2010, 10:52 AM
Well, _my_ application is draw call limited, but the NVIDIA sample is not. It rendered at 60 FPS until I tried rendering with instanced draw of N=hundreds. Reducing the model count down to 30 gets the performance back up to 60 FPS. This example seems touchy for some reason.

Is there example code showing how to specify the transform data for object instances? I've not found one online.

Alfonse Reinheart
04-19-2010, 11:19 AM
Is there example code showing how to specify the transform data for object instances?

I don't know why there would be. It's up to you. It's all done in shader logic, which is arbitrary.

You could do transforms based on a simple integer per-instance, using some heuristic specific to your problem domain. Or you could send position+quaternions for each instance. Or even full matrices.

There's no "right" way to do this; it all depends on your specific needs.

cyrfer
04-19-2010, 11:33 AM
Yes, I understand I can do whatever I want with GL. It would be nice if there was a clear sample somewhere that showed one way to specify transform data per object. Controlling individual positions of things like trees and bushes seems like a good use of instancing. It seems obvious to me why an example should exist.

I'm trying to use TBOs and they are giving me headaches because it *appears* like I have to bind them like multitexturing instead of like VBO/IBOs. This makes for spaghetti code and I want to confirm whether or not this this is how GL intended you to specify transform data for object instances, or if another method exists, and is documented.

Alfonse Reinheart
04-19-2010, 11:44 AM
I'm trying to use TBOs and they are giving me headaches because it *appears* like I have to bind them like multitexturing instead of like VBO/IBOs.

Of course you do; they're textures. The fact that their storage happens to come from a buffer object rather than some place else doesn't change the fact that they're textures and that you access them like a texture.


This makes for spaghetti code and I want to confirm whether or not this this is how GL intended you to specify transform data for object instances, or if another method exists, and is documented.

I don't know how using buffer textures makes "spaghetti code," but you could use uniform buffer objects (though they generally can't be as big as a buffer texture). Or use the recently canonized ARB_instanced_arrays.

AlexN
04-19-2010, 11:51 AM
Also, should the application be able to draw many more objects at a higher frame rate? I modified the NVIDIA example to synthesize a position offset based on 'gl_InstanceID' and the performance is much worse (model=venusm.obj, instance count=300).

When instanced drawing was first made available, I saw similar results where instancing was actually slower than pseudo-instancing. Over time, drivers seem to have improved and now the exact same test shows instancing to be faster than pseudo-instancing. Are you using a recent driver?

DmitryM
04-19-2010, 12:53 PM
Wow, ARB_instanced_arrays work great! I've just tried them myself instead of TBO.

Thanks, Alfonse!