Animation Optimisation

I had run into issues with the line animations running at a low frame rate in Processing (circa 16 fps) once I upped the output size to 1920 x 1080 pixels. Having spent some time reading around, I initially tried rendering the animation using Open GL but with no real performance gain in exchange for a loss in line draw quality. Subsequently I tried re-writing the various nested for loops as while loops and then ran them backwards eg

int i = len;
while(--len >= 0){
// do something
}

in favour of

for(int i = 0; i < len; i++){
// do something
}

This change made a marginal improvement.

I then tried removing some of the vectors supplied to the drawLine method, ie reducing the cross-hatching to single directional hatching. This made a noticeable improvement thus I realised that draw commands are relatively ‘expensive’ in Processing, as in many other languages.

Because I wanted the view of the noise lines to be close enough not to notice the edges of the distorted plane they belong to, I knew that some of the lines were being drawn off screen, thus effectively wasting valuable CPU and reducing frame rate. Looking around the Processing reference I found a couple of methods that take a vertex (ie nominal x, y, z data) and return an actual x or y value (screenX(), screenY()). Using these methods I set up a validity test which ensures only lines which begin within the visible area are actually draw.

The result is a huge improvement – not only have I pushed fps up to 30+, noise settings that previously resulted in unusable animations due to clipping or CPU meltdown are now possible.

Take a look at this full size capture.

Advertisements
Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: