How to improve Ray Performance


I’m currently in the process of getting my performance to the target after I manged to put together a somewhat compleet proof of concept prototype.

On the client I use jme rays, to determine if I look at a useable object. I need at most a range like 10 meters for this.
In my current scene this needs around 70ms. Are the any possible optimisations possible with stock jme that can help improve the performance?

(I already use a very hard lod, does the raytest skip cullhint always objects?)


Where do you raytest on? On the RootNode?

What I currently do is keep a list of spatials with the ActionControl on and manually check for the CullHint.
You could also do a pre sorting like “if distance > 10 skip”, but such a raytest doesn’t do more than “c = a + b * x” → solving to x for every c in the list, so I guess a distance check will take more or less the same power than the actual ray itself.

Other than that, you could use a Future<> to raytest or manually raytest 1/4th every frame and process the results after 4 frames, that way you can improve FPS.
(You could even mix both, so you have all four cores calculating, depends on your design though)

Tiling the scene up in subnodes should help since afaik if the parents node bounding volume is not hit, the childs are not tested

JME picking ignores cull hint… but it does work as zuegg suggests in that it ignores things where the ray misses the bounding shape.

That being said, if you only care if the object is hit and not specifically where it’s hit then it might be better to do your own picking based solely on bounding shapes… and then organize your ‘world’ spatially.

Also, what does ‘look at’ mean in this case? Anywhere near you in the frustum or directly in front of the eye? Of under the mouse cursor?

It’s not clear from your screen shot.

Also, I presume you have limited the ray’s length.

I test if I look at a Entity, that is useable,
either under the mouse cursor, or directly forward, depending on the cursor visbility.

I only need a limited range, however a initial test did not help much.
Each of the spaceships is already a node with all other stuff parented to it.

With stock jme there does not seem to be a ray limit for grafical rays (the physic ones can do, but would require rigidbodys on the client)

I will check the bounding box based casting, maybee this is what I need, as in fact I only care about the hit object roughly.

Yeah, then you are better off using that (or even tracking your own bounding spheres even) than doing a per-triangle intersection.

Oh, i must have overlooked that method, thanks :smile:

As for the boundings, with only one ship it is lighting fast, so maybee the limit will be enough already.