Instanced Drawing in jPCT

Started by george2209, June 18, 2015, 12:00:31 PM

Previous topic - Next topic

george2209

Hi ,

I am planing to use jPCT (Android) in the future. It seems the best framework at the moment. I also had an own framework but it is dificult to maintain it alone..maybe I will participate to the development of jPCT as a better approach.

Anyway, how about the "Instanced Drawing"? Is it supported?

If I have, for example in my application one tree and I want to create a forest how can this framework help me? Is there any approach to this or I need to have N0000 Objects of tree (having for each the same shader but with different vertice values)....

Any hint?

Thank you.
George

EgonOlsen

There's no support for hardware instancing yet, because OpenGL ES 2.0 doesn't support it. However, you don't have to create all of the trees as distinct objects...at least not as individual geometric instances. Object3D instances can share a lot of their data with others, i.e. you can derive your trees from a kind of blue print object. This can be done by creating the instances from a base object with this constructor: http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Object3D.html#Object3D(com.threed.jpct.Object3D, boolean) and reuseMesh set to true. The resulting objects will share their geometry with the base object, so this saves memory and processing time. However, this applies to the objects in VM memory only. On the GPU, the geometry would still be distinct. You can avoid this by calling copy.shareCompiledData(bluePrint); on your cloned instances (http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Object3D.html#shareCompiledData(com.threed.jpct.Object3D)). And if it's applicable in your case, you can use this in addition: http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Object3D.html#shareTextureData(com.threed.jpct.Object3D).

In your case (thousands of objects), I would modify this approach by not creating thousands of clones instances of Object3D but by separating the model from the view. i.e. create simple beans that contain only the basic information that a tree needs (like position, rotation and scale). Apply some spatial sorting to them if needed and at render time, determine which might be visible and assign an actual Object3D from some object pool as a view only for those. That way, you can get away with much less Object3D instances. All visible objects like trees, bushes, npcs, houses, fences, rocks... in my game (http://jpct.de/jpctnet/img/rpg_and78.png) are using this approach.

george2209

Thank you Egon.
I was thinking to such approach (althrou you've detailied very nicely) but one think what I learn while eperimenting with new framework: don't try to reinvent the wheel. This is the reason for asking, I was afrait to make use on something that is already in there.

Thanks.
George