Processing/Drawing Unseen geometry

I’m currently randomly generating a dungeon out of a 2d grid, and everything is working fine except for one thing, when the map gets in sizes bigger than 50 grid spaces squared, my fps starts to go down, looking at the statistics even if there is only 2 grid boxes visible, it processes the grid boxes behind them too! is there any way I can fix this? Or am I gonna have to find another way to generate maps that doesn’t rely on grids?

Batching.

You are never going to get good performance making thousands of little tiny draw calls to the GPU. And for all of those objects, JME will have to see if they are on screen or not in order to decide to cull them.

You will need to spatially batch your cells together into single objects or groups of objects (per material).

We’d have to know a lot more about your scene to help further but any thread you find on optimization is bound to talk exactly about this. Super common problem.

First I take a 2D grid of any size, for instance, 10, which means it’s 10 by 10, and I use noise to generate caves and such. Each tile is assigned a id, and when making the world, it sees that the generated world has a stone at 4,7, so it places a box with the stone texture there. With smaller map sizes it’s not a problem but with huge maps it gets really laggy (down to 0 fps). Btw all of the boxes are in a ‘map’ node.

EDIT: Here are some screenshots that better show what I am doing

https://lh3.googleusercontent.com/yyZKL28gUgc628SVnoVxJAButwVxVkBnBL6J564g0XCsU96oXDblccRnpjW_RDlBaDMzlhkYRER7P0E=w1280-h934-rw

1 Like

This has been answered sooooooo many times but here goes… Don’t place lots of boxes, make one (or more) mesh(es) based on the data. Use a texture atlas and texture coordinates on the mesh to apply different textures. (Which is basically what pspeed said)

See the jME manual:
https://jmonkeyengine.github.io/wiki/jme3/intermediate/optimization.html
https://jmonkeyengine.github.io/wiki/jme3/advanced/custom_meshes.html

Thanks for that, I’ve managed to trim down the entire world into 1 draw call, I’ve went from 68fps on a 40 square grid level to about 2000 on a 100 square grid.