www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: Redman on July 07, 2016, 05:08:42 pm

Title: Speeding up rendering an Object3D multiple times: "Instance-Batch-Rendering"
Post by: Redman on July 07, 2016, 05:08:42 pm
I'm currently working on an RTS project for Android using jPCT-AE.  There could possibly be up to 300+ objects on screen at one time, and I found I needed to lighten the CPU processing and memory load.  I am working on something I'm dubbing "Instance-Batch-Rendering" and I wanted to get thoughts and suggestions.

This method is for speeding up the process of rendering an Object3D multiple times on screen.

How it works:

So far, I have seen pretty good performance improvements using this method.  I have not tested everything out, and this is certainly not for everybody.  I have a bit more work to do on this methodology, but I wanted to gather opinions on it.  If anybody is interested, I will publish the work in this Thread, but it will be a use at your own risk as it will not support everything that jPCT-AE does and you will definitely need to build your own logic to fit your project.

I will be adding support for my hybrid-GPU-bones-animated objects for this methodology so it can support animations as well as static objects.

This is only for GLES 2.0+ as it uses Shaders at its core.
Title: Re: Speeding up rendering an Object3D multiple times: "Instance-Batch-Rendering"
Post by: EgonOlsen on July 07, 2016, 08:44:37 pm
The actual idea behind adding the repeatRendering()-method was exactly this. However, nobody has done it before (including myself)... ;) Good job. I'm pretty sure that it would make an interesting addition to the Wiki...
Title: Re: Speeding up rendering an Object3D multiple times: "Instance-Batch-Rendering"
Post by: Redman on July 08, 2016, 02:38:35 pm
Sure.  I also thought of another good use of repeatRendering() that I'm going to need... a particle emitter.  I'll release a GLSL particle emitter next (no plan for collision detection particles).
Title: Re: Speeding up rendering an Object3D multiple times: "Instance-Batch-Rendering"
Post by: Redman on July 11, 2016, 05:12:44 pm
I don't get much free time, but here's an update:


Todo:

More to follow.
Title: Re: Speeding up rendering an Object3D multiple times: "Instance-Batch-Rendering"
Post by: Redman on July 12, 2016, 10:08:16 pm
I have finished my todo list of adding rotations & animation support (and moving the MVM to software instead of vertex shader calc ).  I will add something to the Wiki soon.  More to follow.
Title: Re: Speeding up rendering an Object3D multiple times: "Instance-Batch-Rendering"
Post by: Redman on July 15, 2016, 04:46:20 am
Anybody want to try this out to see how my documentation is:
http://www.jpct.net/wiki/index.php?title=Instance_Batch_Rendering (http://www.jpct.net/wiki/index.php?title=Instance_Batch_Rendering)

I'm a little tired writing it   :P
Title: Re: Speeding up rendering an Object3D multiple times: "Instance-Batch-Rendering"
Post by: AeroShark333 on July 20, 2016, 12:39:33 am
Hmm looks interesting but how can one detect when an InstanceObject3D is touched?

EDIT:
Another question, does the order in which the InstanceObject3D's are drawn matter?
Title: Re: Speeding up rendering an Object3D multiple times: "Instance-Batch-Rendering"
Post by: Redman on July 21, 2016, 05:06:50 pm
Quote
Hmm looks interesting but how can one detect when an InstanceObject3D is touched?
By default the mesh of an InstanceObject3D is not touched by IBR.  If you do alter the mesh data, you already have access to the Mesh / Object3D as you've altered the vertices / uvs.  If you do alter the mesh, note that it will affect all instances as it uses a shared mesh.  If you need to get the Object3D of an InstanceObject3D type, use the InstanceManager.getObject3DOfInstanceType().

As for the transform matrices of the InstanceObject3D, by default it does a sort of lazy-transformations.  Any time you do a scale/translation/rotation, it sets a protected boolean changed to true.  On call of getTransformMatrix(), it will re-create the transform matrix if changed==true, otherwise it just returns the previously calculated transform matrix.  getTransformMatrix() get called when rendering each instance (every frame).  I have added a method to the code called hasChanged(), which will return true if there has been a translate, scale or rotation since last getTransformMatrix().  I hope this answers your question.


Quote
Another question, does the order in which the InstanceObject3D's are drawn matter?

It can, and Egon may be able to better explain some of this.  It should only matter if your Object3D uses transparency or you set the OpenGL to disable the depth test, in which case it will render in synchronous order.  To put it simply, I don't believe transparency InstanceObject3D's are going to play nicely with other transparent Object3D's, other transparent InstanceObject3D types, or overlaps of the multiple IntanceObject3D of that type.  I believe jPCT has software-side ordering (based off the Object3D's origin distance from camera?) when it comes to transparent objects, and the transparent objects are rendered last as transparency requires the solid pixels behind it for the different pixel write modes (add, modulate, blend, etc...).  Because all Object3D's for this method are stacked a certain distance from the camera, they will be picked up by jPCT render pipeline in regards to that distance from the camera.  All InstanceObject3D's that are rendered would be synchronously rendered on top of one another according to the order when added.  I could add simple sorting, but it won't solve all problems, as transparency is a complex subject that requires work arounds and tweaks for speed.  But it will never work great with IBR as the distance from the camera will mess up jPCT's sorting order.

Egon, did I miss anything or is anything inaccurate?
Title: Re: Speeding up rendering an Object3D multiple times: "Instance-Batch-Rendering"
Post by: EgonOlsen on July 22, 2016, 10:19:36 am
Sounds fine. Sorting of transparent objects is done per object based on the distance from the camera. All other objects are sorted by state by default.