How can i improve the performance of this code?

Hello i made this work on recent Processing 4:

But rendering the city in full style (press “T” while running the code) takes about a minute.

it takes a red and green picture of 120 pixels width and 80 pixels height and turns every pixel, that has some value in the red color-channel and 0 in the green color channel, into a city-block, that is surrounded by streets and contains about 10 buildings and a fitting number of small city-detail-objects.
That makes a lot of models to render.

How can i improve the performance-speed, even if looking at the whole city from high above, what really needs to render all models, because they are all in the field of view?

here is a screenshot of such a view:

1 Like

You would improve it by re-writing it from scratch. Is that something you are prepared to do?

He has a very impressive amount of customization throughout his buildings, but that comes at a huge cost since he essentially recreates the geometry for every unique visible building every frame. The most obvious optimization would be to wrap all of the generating code into PShapes. At least each building should be its own PShape, but better would be for each block or NxN blocks to be in a single PShape that gets generated once and stored. The building name signs could all be packed into a single texture image with either one per block cluster or possible one big one for the entire city. I don’t know what limits Processing or your graphics card might have on the number or size of PShapes is.

As he said his brother said in the video, if you want this to run well, you’d write it in Unreal Engine which is designed to handle massive amounts of geometry and provides level-of-detail and view frustum culling along with shadows and volumetric lighting and so on.

1 Like

I noticed, that in the setup function are three pairs of for-loops with exactly the same instructions in their round brackets.

If i merge them into one, i get this error, even if i merge only two of them (I placed comments, that tells this in the two spots between them):

RuntimeException: java.lang.AssertionError
java.lang.RuntimeException: java.lang.AssertionError
at processing.opengl.PSurfaceJOGL.lambda$initAnimator$2(
at java.base/
Caused by: java.lang.AssertionError
at jogamp.opengl.glu.tessellator.Sweep.AddRightEdges(
at jogamp.opengl.glu.tessellator.Sweep.ConnectLeftVertex(
at jogamp.opengl.glu.tessellator.Sweep.SweepEvent(
at jogamp.opengl.glu.tessellator.Sweep.__gl_computeInterior(
at jogamp.opengl.glu.tessellator.GLUtessellatorImpl.gluTessEndPolygon(
at com.jogamp.opengl.glu.GLU.gluTessEndPolygon(
at processing.opengl.PJOGL$Tessellator.endPolygon(
at processing.opengl.PGraphicsOpenGL$Tessellator.tessellatePolygon(
at processing.opengl.PGraphicsOpenGL.tessellate(
at processing.opengl.PGraphicsOpenGL.endShape(
at processing.core.PApplet.endShape(
at yoyleCityWords.drawLand(
at yoyleCityWords.draw(
at processing.core.PApplet.handleDraw(
at processing.opengl.PSurfaceJOGL$DrawListener.display(
at jogamp.opengl.GLDrawableHelper.displayImpl(
at jogamp.opengl.GLDrawableHelper.display(
at jogamp.opengl.GLAutoDrawableBase$
at jogamp.opengl.GLDrawableHelper.invokeGLImpl(
at jogamp.opengl.GLDrawableHelper.invokeGL(
at com.jogamp.newt.opengl.GLWindow.display(
at com.jogamp.opengl.util.AWTAnimatorImpl.display(
at com.jogamp.opengl.util.AnimatorBase.display(
at com.jogamp.opengl.util.FPSAnimator$
at java.base/java.util.TimerThread.mainLoop(
at java.base/
RuntimeException: java.lang.AssertionError