I'm currently working on my first Three.js / WebGL application, and while it runs smoothly on my PC (Chrome), I've noticed that the framerate tends to drop below 30 frames per second on other PCs.
Despite the application not being overly complex, I would appreciate any tips you have to offer on how to enhance its performance. You can find a version of the app here:
www.wrodewald.de/StackOverflowExample/
The main element in the application is a dynamic plane with 64² vertices that morphs. It utilizes a matrix to store a static heightmap and wavemap, which is updated every frame to recalibrate itself using filters to maintain consistency among neighboring vertices. As a result, each frame requires updating the plane's color and vertex position, potentially contributing to the performance issue.
The secondary object, a rhombus, should not pose a problem as it is static, only moving slightly.
In terms of lighting, there are three types present (ambient, directional, spherical) without shadows, along with a tilt shift shader and vignette shader.
The following functions are executed per frame:
var render = function() {
requestAnimationFrame( render );
var time = clock.getDelta();
world.updateWorld(time);
diamond.rotate(time);
diamond.update(time);
control.updateCamera(camera, time);
composer.render();
stats.update();
}
This is what world.updateWorld(time)
entails:
// Within world.updateWorld(time):
// accmap stores acceleration and wavemap stores position
// this.mapSize indicates the plane's size in vertices (64)
// Update Acceleration Map
for(var iX = 1; iX < (this.mapSize-1); iX++) {
for(var iY = 1; iY < (this.mapSize-1); iY++) {
accmap[iX][iY] -= dT * (wavemap[iX][iY]) * Math.abs(wavemap[iX][iY]);
}
}
// Smooth Acceleration Map
for(var iX = 1; iX < (this.mapSize-1); iX++) {
for(var iY = 1; iY < (this.mapSize-1); iY++) {
// Calculation omitted for brevity
}
}
// Update Wave Map
// Wave map update and vertex calculation code provided
Here are the "diamond" functions:
this.rotate = function(dT) {
// Rotation logic explained
}
this.update = function(dT) {
// Color interpolation logic described
}
Can you identify any specific reasons causing the inconsistent framerate in the application?