jMonkey optimization similar to Java3D's

冷暖自知 提交于 2019-12-20 09:48:02

问题


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):

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

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

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:

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:

2)Exclusion force starts to show itself:

3)Exclusion force + gravitation makes the group form a more smooth shape:

4)Group forms a sphere(as expected):

5)Then, a big stellar body approaches:

6)About to touch:

7)The moment of impact:

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.

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


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/13352237/jmonkey-optimization-similar-to-java3ds

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!