I can notice the jerkiness you are referring to in your sketch (https://dl.dropbox.com/u/95395455/sphereofpoints6.zip, I'm testing it on a MacBook Pro with OS X 10.8.2 and a Radeon HD 6490M). My guess at this moment is that is due to the particular way you are rendering your geometry.
Consider this other sketch (just a slightly modified version of the Esfera example that comes with Processing):
- int cuantos = 20000;
- Pelo[] lista ;
- float radio = 200;
- float rx = 0;
- float ry =0;
- int fcount, lastm;
- float frate;
- int fint = 3;
- void setup() {
- size(1280, 800, P3D);
- radio = height/3.5;
- lista = new Pelo[cuantos];
- for (int i = 0; i < lista.length; i++) {
- lista[i] = new Pelo();
- }
- noiseDetail(3);
- }
- void draw() {
- background(0);
- // float rxp = (mouseX-(width/2)) * 0.005;
- // float ryp = (mouseY-(height/2)) * 0.005;
- // rx = rx*0.9 + rxp*0.1;
- // ry = ry*0.9 + ryp*0.1;
- ry += 0.01;
- translate(width/2, height/2);
- rotateY(ry);
- // rotateX(rx);
- fill(0);
- noStroke();
- sphere(radio);
- for (int i = 0; i < lista.length; i++) {
- lista[i].dibujar();
- }
- fcount += 1;
- int m = millis();
- if (m - lastm > 1000 * fint) {
- frate = float(fcount) / fint;
- fcount = 0;
- lastm = m;
- println("fps: " + frate);
- }
- }
- class Pelo
- {
- float z = random(-radio, radio);
- float phi = random(TWO_PI);
- float largo = random(1.15, 1.2);
- float theta = asin(z/radio);
- Pelo() { // what's wrong with a constructor here
- z = random(-radio, radio);
- phi = random(TWO_PI);
- largo = random(1.15, 1.2);
- theta = asin(z/radio);
- }
- void dibujar() {
- //float off = (noise(millis() * 0.0005, sin(phi))-0.5) * 0.3;
- //float offb = (noise(millis() * 0.0007, sin(z) * 0.01)-0.5) * 0.3;
- float off = 0;
- float offb = 0;
- float thetaff = theta+off;
- float phff = phi+offb;
- float x = radio * cos(theta) * cos(phi);
- float y = radio * cos(theta) * sin(phi);
- float z = radio * sin(theta);
- float xo = radio * cos(thetaff) * cos(phff);
- float yo = radio * cos(thetaff) * sin(phff);
- float zo = radio * sin(thetaff);
- float xb = xo * largo;
- float yb = yo * largo;
- float zb = zo * largo;
- strokeWeight(1);
- beginShape(LINES);
- stroke(0);
- vertex(x, y, z);
- stroke(200, 150);
- vertex(xb, yb, zb);
- endShape();
- }
- }
I find the animation to be quite smooth in this case, and I'd say that the complexity of the geometry is comparable to your sketch. Maybe I can notice one or two bumps right at the beginning, but it might be due to the GC kicking in and disposing some temporary objects used during initialization (just guessing).
If I disable the point rendering in you sketch, the jerkiness seems to disappear. Specifically, by commenting out:
- gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, nodes_vbo[0]);
- gl.glVertexPointer(3, GL2.GL_FLOAT, 0, 0);
- gl.glDrawArrays(GL2.GL_POINTS, 0, nodecount);
- gl.glBindBuffer( GL2.GL_ARRAY_BUFFER, 0);
What I found problematic about the way you render points is that you use gl_PointSize in your shader, and my impression (not 100% sure though) is that by doing so you are loosing the performance advantage of the VBOs because for each point center, the gpu needs in each frame to tessellate and rasterize the rest of the circle. I think it would be a better idea to use triangles to represent each point explicitly as a strip. The vertex count would be higher, but you can store all the vertices beforehand inside the VBO.