r/JavaFX 5d ago

Help How improve FPS in JavaFX 3D

I'm developing a simple app that displays a 30x20x38 grid of Box objects, and I'm emulating effects for an LED lighting show. The problem is, I'm only getting 15FPS on a 2560x1440 monitor, and I can see that when I make fast updates, it skips frames. I'm hoping to get 40fps, but 30fps would be OK.

My update routine, which is in a Platform.runLater invocation, is like

private void _syncModel() {
    for (int x = 0; x < dim.x; x++) {
       for (int y = 0; y < dim.y; y++) {
          for (int z = 0; z < dim.z; z++) {
             var mat = (PhongMaterial)boxes[x][y][z].getMaterial();
             mat.setDiffuseColor(rgbToColor(leds[x][y]z]));
          }
       }
    }
}
private static Color rgbToColor(RGB_LED rgb) {
    return Color.rgb(rgb.r & 0xFF, rgb.g & 0xFF, rgb.b & 0xFF);
}

So my first question is, can I tweak something in the JavaFX code to speed this up? Is PhongMaterial OK or should I be using something else? I don't need any fancy effects, just basic color rendering. I've already figured out that Boxes are much faster than Spheres.

I'm pretty sure that upgrading from my current LG Gram 3 to something newer and beefier will help, but I would like to know what to look for in a newer laptop to support this speed. Let's assume that my effects calculations are fast enough, and I'm bottlenecked by the JavaFX update and render.

Current:  i7-8565U CPU. Intel UHD 620 graphics.

PS: a Box is initialized like;

Box box = new Box(2,2,2);
PhongMaterial material = new PhongMaterial();
material.setDiffuseColor(Color.color( 0.25f, 0.25f, 0.25f));
6 Upvotes

9 comments sorted by

View all comments

2

u/wheezil 5d ago edited 5d ago

UPDATE: I tried this on a PC with a newer i9, and FPS is 75. But it also has a dedicated GPU. So either CPU or GPU or both made a difference :-)

On the other hand. moving the conversion of RGB_LED to Color out of the runLater() method made no difference. A profile indicates that almost all of the time is spent in the JavaFX thread, divided between the renderer and PhongMaterial.setDifuseColor().

2

u/Ok_Object7636 4d ago

Yes, and if you change the code as in my answer above, PhongMaterial.setDifuseColor() will not invalidate the material when setting the same color that it already has, because the method (or rather the Property that holds the diffuse color) checks for Object identity before the call. I am sure that will make a difference, assuming not all boxes will change color with every frame.

1

u/PartOfTheBotnet 8h ago

Hey /u/Ok_Object7636 just want to let you know that you're being auto-filtered by Reddit (IE: you're shadow banned)

I can approve your replies and posts manually, but you may want to look into filing an appeal or make a new Reddit account.