Very Slow 3D Render, need Fixed Framerate. Render to Surface in Background Thread?

edited February 2018 in Programming Questions

I have a sketch that records video at 30fps with a 3D model overlay. The problem is that the 3D model renders much slower than the necessary framerate, which causes missed frames in the video feed that translates into double or triple the expected playback speed. The 3D model is necessarily complex as it's a time-series waterfall chart.

Is it possible to render a 3D model in a separate thread onto a PGraphics P3D surface while the draw() method continues re-drawing the previous frame until a new frame of the 3D model is ready?

My sketch is a bit of a mess at the moment, as it's also reading serial (this I was able to do in a separate thread using a ring buffer) and blending camera images for motion blur, which can keep the pace. I can try to make an MCVE if anyone thinks this is even remotely possible. TIA!


  • Answer ✓

    The usual answer to this is to make it a two stage process. Record all the data on the first pass, in real time. Render the images on a second pass, maybe even a second sketch. This second pass doesn't need to be real time. Save the frames, make the video afterwards.

Sign In or Register to comment.