How can i improve the performance of this code?

Hello i made this work on recent Processing 4:
yoyleCityWords

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(PSurfaceJOGL.java:430)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.AssertionError
at jogamp.opengl.glu.tessellator.Sweep.AddRightEdges(Sweep.java:358)
at jogamp.opengl.glu.tessellator.Sweep.ConnectLeftVertex(Sweep.java:1053)
at jogamp.opengl.glu.tessellator.Sweep.SweepEvent(Sweep.java:1078)
at jogamp.opengl.glu.tessellator.Sweep.__gl_computeInterior(Sweep.java:1339)
at jogamp.opengl.glu.tessellator.GLUtessellatorImpl.gluTessEndPolygon(GLUtessellatorImpl.java:526)
at com.jogamp.opengl.glu.GLU.gluTessEndPolygon(GLU.java:896)
at processing.opengl.PJOGL$Tessellator.endPolygon(PJOGL.java:639)
at processing.opengl.PGraphicsOpenGL$Tessellator.tessellatePolygon(PGraphicsOpenGL.java:13537)
at processing.opengl.PGraphicsOpenGL.tessellate(PGraphicsOpenGL.java:2220)
at processing.opengl.PGraphicsOpenGL.endShape(PGraphicsOpenGL.java:1930)
at processing.core.PApplet.endShape(PApplet.java:10870)
at yoyleCityWords.drawLand(yoyleCityWords.java:2882)
at yoyleCityWords.draw(yoyleCityWords.java:704)
at processing.core.PApplet.handleDraw(PApplet.java:2094)
at processing.opengl.PSurfaceJOGL$DrawListener.display(PSurfaceJOGL.java:840)
at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:692)
at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:674)
at jogamp.opengl.GLAutoDrawableBase$2.run(GLAutoDrawableBase.java:443)
at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1293)
at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:1147)
at com.jogamp.newt.opengl.GLWindow.display(GLWindow.java:782)
at com.jogamp.opengl.util.AWTAnimatorImpl.display(AWTAnimatorImpl.java:81)
at com.jogamp.opengl.util.AnimatorBase.display(AnimatorBase.java:453)
at com.jogamp.opengl.util.FPSAnimator$MainTask.run(FPSAnimator.java:178)
at java.base/java.util.TimerThread.mainLoop(Timer.java:566)
at java.base/java.util.TimerThread.run(Timer.java:516)
RuntimeException: java.lang.AssertionError