[SOLVED] Question about geometry instancing

Looking around for a few hours and I could get myself familiarised a bit with how things work.

Would you mind elaborate on this please, now that
checkCulling() returns false on those geometries how should I work around it.

It’s not a noob question at all! :slight_smile:
From my experience: I too render many trees, grass, etc. Eg. Trees up close are a model, and far away are a quad. And both of these are instanced and both are culled on GPU with transform feedback. Bam 10000+ trees achieved :smiley:

2 Likes

The method that rebuilds the instances buffer, should just skip the geometries that are culled (checked with checkCulling) and then count how many geoms got culled and subtract that value on getActualNumInstances

Sorry If not understanding it correctly but as you already showed here:

checkCulling(cam) method will always return false on those geometries (as they are grouped) so how I can tell if they are in frustum or not?

how about

BoundingVolume bound = ...;
cam.contains(bound);

PS: check the documentation of the cam.contains method, it has a strange usage requirement. You better write a wrapper around it so you use it as it should be used.

NOTE: This method is used internally for culling, for public usage,
     * the plane state of the bounding volume must be saved and restored, e.g:
     * <code>BoundingVolume bv;<br>
     * Camera c;<br>
     * int planeState = bv.getPlaneState();<br>
     * bv.setPlaneState(0);<br>
     * c.contains(bv);<br>
     * bv.setPlaneState(plateState);<br>
2 Likes

right, then you can check the bounding volumes as leo suggested

1 Like

Okay, thanks so much guys.

Hm… is there a mistake in the above doc?

BoundingVolume has no getPlaneState() /setPlaneState() methods. They are only on Camera.

Should I set it on the camera instead?

BoundingVolume bv = geom.getWorldBound();
int planeState = cam.getPlaneState();
cam.setPlaneState(0);
cam.contains(bv);
cam.setPlaneState(planeState);

Ah never mind, it’s not getPlaneState()/setPlaneState() it is getCheckPlane()/setCheckPlane()

Going to fix Javadoc.

@RiccardoBlb is this ok?

https://github.com/Ali-RS/jmonkeyengine/commit/f091d4a5b090ec73a104f7c811ce47e40bd9ff4b

And here is a test result I did with TestInstanceNode with 3600 geometries:

  • Instancing Off:

    • All geometries inside camera view: 41 fps
    • Only a few objects inside camera view: 890 fps
  • Instancing On (no culling):

    • All geometries inside camera view: 210 fps
    • Only a few objects inside camera view: 226 fps
  • Instancing On (with culling):

    • All geometries inside camera view: 217 fps
    • Only a few objects inside camera view: 761 fps
3 Likes

seems good

1 Like

Ricc thanks for reviewing.
Submitted a PR:

https://github.com/jMonkeyEngine/jmonkeyengine/pull/1315

3 Likes

do it work for animated geoms maybe?

Bone animation?
Not sure, have not tried.

yes Bone animation.

curious if could put same geoms in instance and bone animation still work fine.

At best, they will all animate exactly the same… if it works at all.

Just tried instancing on animated model, it does not work (no animation plays).

2 Likes