jMonkey optimization similar to Java3D's
Asked Answered
G

2

35

Edit: For having real-time drawing, started using lwjgl which is base of jmonkeyengine and jocl in an "interoperability" between opengl and opencl, now can calculate and draw 100k particles real-time. Maybe mantle version of jmonkey engine can cure this drawcall overhead problem.

For several days, I have been learning jMonkey engine(ver:3.0) in Eclipse(java 64 bit) and trying how to optimize a scene with using GeometryBatchFactory.optimize(rootNode); command.

Without optimization(with capability of changing spheres positions):

enter image description here

Okay, only 1-fps is originated from both pci-express bandwidth+jvm overhead.

With optimization(without capability to change positions of spheres):

enter image description here

Now it is 29 fps even with increased triangle number.

Java3D had a setCapability() method which makes a scene object be able to be read/written even in an optimized form. jMonkey engine 3.0 must be capable of this subject but I couldn't find any trace of it(searched tutorials and examples, failed).

Question: How can I set read/write position/rotation/scale capabilities of optimized nodes of a scene in jMonkey 3.0? If you cannot give an answer to first question, can you tell me why triangle numbers increase when I use optimization command? Do I have to create a new method to access the graphics card and change the variables myself(jogl maybe?)?

Scene information: 16k particles(spheres of 16x16 res) + 1 point light(and its 4096 resolutioned shadow).

I'm sure we can send several thousands of float numbers in a millisecond through pci-express with ease.

  • Additional info: I'm using Aparapi-kernels to update particle positions which takes 10 milliseconds(16k * 16k interactions to calculate forces).(does not change anything in optimized mode :( ) Can aparapi access those optimized data?

For the case of batchNode.batch(); optimization, here is 1 fps again with lessened object-numbers:

enter image description here

Object number is now only several hundreds but fps is still at 1!

Sending just sphere positions to gpu and letting it calculate the vertex positions could be better than calculating vertexes on cpu plus sending huge data to gpu.

No-one here to help? Already tried batchNode but did not help enough.

I dont want to change 3d api because jMonkey people already reinvented the wheel and I'm happy with current situation. Just trying to squeeze a little more performance(canceling shadows gives %100 speed but quality is important too!).

This java program will become an asteroid-impact scene simulator(there will be choice of asteroid size,mass,speed,angle) with marching-cubes algorithm with LOD(will be millions of particles).

Marching-cubes algorithm would decrease the triangle numbers greatly. If you couldnt give any answer the question, any marching-cubes(or any O(n) convex hull) algorithm for java will be accepted! Data: x,y,z arrays as source and triangle-strip-array as target(iso-surface mesh points)

Thanks.

Here are some samples about the stream(with a much lower resolution):

1)Collapsing of a cube-shaped rock-group by gravitation: enter image description here

2)Exclusion force starts to show itself: enter image description here

3)Exclusion force + gravitation makes the group form a more smooth shape: enter image description here

4)Group forms a sphere(as expected): enter image description here

5)Then, a big stellar body approaches: enter image description here

6)About to touch: enter image description here

7)The moment of impact: enter image description here

With help of Barnes-Hutt algorithm and a truncated potential, particle numbers will be 10x(maybe 100x) more.

Rather than Marching-Cubes algorithm, a ghost cloth which wraps the nbody can give a low-resolutioned hull(more easier than BH but need more computation)

Ghost cloth will be affected by nbody(gravity + exclusion) but nbody will not be affected by cloth which wraps it. Nbody wont be rendered but cloth mesh will be rendered with lower triange count.

enter image description here enter image description here

If MC or above works, this will let the program render a wrapping-cloth for ~200x more particles.

Genuine answered 12/11, 2012 at 21:56 Comment(1)
You should ask jMonkeyEngine related questions on their forums (jmonkeyengine.org/forums). You have a much higher chance of getting an answer there. It's quite an active community.Extortionate
E
4

So sorry....

You can batch all Geometries in a scene (or a subnode) that remains static.

Batching means that all Geometries with the same Material are combined into one mesh. This optimization only has an effect if you use only few (roughly up to 32) Materials total. The pay-off is that batching takes extra time when the game is initialized

The change in triangles therefore is because they have been all assembled into one mesh.... The only suggestion if this is necessary, is trying to get the mesh and altering points on it, but at that point I don't think it makes sense.

Perhaps try a different optimization method.

Good luck, haven't used JMonkey in a bit, but glad to see others do and its continued growth!

EDIT

BTW, a way to minimize the math might be to use half a sphere of cubes, an impact on the earth likely wouldn't affect the other side (unless the sphere isn't the earth but already a small sample of the earth taken as a sphere)...

Perhaps try a 2d shape as the impact surface, though I know this won't be your best choice, it might give you an idea of how the number of shapes might have an affect and how grand. If it does then an avenue might be to consider how to remove some of the particles, if it doesn't you need not worry. I am almost sure it will.

Finally:

Perhaps don't render in real time? Take a minute to draw the frames to a buffer then play, by the time your playing you will have another 40 or so frames etc... and maybe approx 30 secs worth is all you will need.

Extravasate answered 12/11, 2012 at 21:56 Comment(3)
I want to make this program runnable on every hardware thats why im trying to optimize for real-time.Genuine
All I am saying is that you might want to use the graphics card of the machine (making it runnable on every hardware), but just buffer the frames.... At the very least you cannot use GeometryBatchFactory.optimize(rootNode); for this, or not that I would, it is not intended functionality.Extravasate
If you want real time, then look into other ways of optimizing, make sure your culling make sure your doing all the regular types of optimization....Extravasate
G
4

There is a pretty solid set of documentation within the JMonkeyEngine wiki which talks quite a bit about how to utilize the transformations you are referring to, which can be found here: Advanced Spatial Concepts.

In addition, there is quite a bit of information regarding the meshes and their rendering which you can view here: Polygon Meshes.

Glabrescent answered 12/11, 2012 at 21:56 Comment(1)
Okay, thanks for the source. Do you know how to make opencl coop with opengl buffers?Genuine
E
4

So sorry....

You can batch all Geometries in a scene (or a subnode) that remains static.

Batching means that all Geometries with the same Material are combined into one mesh. This optimization only has an effect if you use only few (roughly up to 32) Materials total. The pay-off is that batching takes extra time when the game is initialized

The change in triangles therefore is because they have been all assembled into one mesh.... The only suggestion if this is necessary, is trying to get the mesh and altering points on it, but at that point I don't think it makes sense.

Perhaps try a different optimization method.

Good luck, haven't used JMonkey in a bit, but glad to see others do and its continued growth!

EDIT

BTW, a way to minimize the math might be to use half a sphere of cubes, an impact on the earth likely wouldn't affect the other side (unless the sphere isn't the earth but already a small sample of the earth taken as a sphere)...

Perhaps try a 2d shape as the impact surface, though I know this won't be your best choice, it might give you an idea of how the number of shapes might have an affect and how grand. If it does then an avenue might be to consider how to remove some of the particles, if it doesn't you need not worry. I am almost sure it will.

Finally:

Perhaps don't render in real time? Take a minute to draw the frames to a buffer then play, by the time your playing you will have another 40 or so frames etc... and maybe approx 30 secs worth is all you will need.

Extravasate answered 12/11, 2012 at 21:56 Comment(3)
I want to make this program runnable on every hardware thats why im trying to optimize for real-time.Genuine
All I am saying is that you might want to use the graphics card of the machine (making it runnable on every hardware), but just buffer the frames.... At the very least you cannot use GeometryBatchFactory.optimize(rootNode); for this, or not that I would, it is not intended functionality.Extravasate
If you want real time, then look into other ways of optimizing, make sure your culling make sure your doing all the regular types of optimization....Extravasate

© 2022 - 2024 — McMap. All rights reserved.