Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

Re : frameRate() can crash 2.0b7

$
0
0
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):
  1. int cuantos = 20000;
  2. Pelo[] lista ;
  3. float radio = 200;
  4. float rx = 0;
  5. float ry =0;

  6. int fcount, lastm;
  7. float frate;
  8. int fint = 3;

  9. void setup() {
  10.   size(1280, 800, P3D);

  11.   radio = height/3.5;

  12.   lista = new Pelo[cuantos];
  13.   for (int i = 0; i < lista.length; i++) {
  14.     lista[i] = new Pelo();
  15.   }
  16.   noiseDetail(3);
  17. }

  18. void draw() {
  19.   background(0);
  20.   
  21. //  float rxp = (mouseX-(width/2)) * 0.005;
  22. //  float ryp = (mouseY-(height/2)) * 0.005;
  23. //  rx = rx*0.9 + rxp*0.1;
  24. //  ry = ry*0.9 + ryp*0.1;
  25.   ry += 0.01;
  26.   
  27.   translate(width/2, height/2);
  28.   rotateY(ry);
  29. //  rotateX(rx);
  30.   fill(0);
  31.   noStroke();
  32.   sphere(radio);

  33.   for (int i = 0; i < lista.length; i++) {
  34.     lista[i].dibujar();
  35.   }

  36.   fcount += 1;
  37.   int m = millis();
  38.   if (m - lastm > 1000 * fint) {
  39.     frate = float(fcount) / fint;
  40.     fcount = 0;
  41.     lastm = m;
  42.     println("fps: " + frate); 
  43.   } 
  44. }

  45. class Pelo
  46. {
  47.   float z = random(-radio, radio);
  48.   float phi = random(TWO_PI);
  49.   float largo = random(1.15, 1.2);
  50.   float theta = asin(z/radio);

  51.   Pelo() { // what's wrong with a constructor here
  52.     z = random(-radio, radio);
  53.     phi = random(TWO_PI);
  54.     largo = random(1.15, 1.2);
  55.     theta = asin(z/radio);
  56.   }

  57.   void dibujar() {

  58.     //float off = (noise(millis() * 0.0005, sin(phi))-0.5) * 0.3;
  59.     //float offb = (noise(millis() * 0.0007, sin(z) * 0.01)-0.5) * 0.3;
  60.     float off = 0;
  61.     float offb = 0;

  62.     float thetaff = theta+off;
  63.     float phff = phi+offb;
  64.     float x = radio * cos(theta) * cos(phi);
  65.     float y = radio * cos(theta) * sin(phi);
  66.     float z = radio * sin(theta);

  67.     float xo = radio * cos(thetaff) * cos(phff);
  68.     float yo = radio * cos(thetaff) * sin(phff);
  69.     float zo = radio * sin(thetaff);

  70.     float xb = xo * largo;
  71.     float yb = yo * largo;
  72.     float zb = zo * largo;

  73.     strokeWeight(1);
  74.     beginShape(LINES);
  75.     stroke(0);
  76.     vertex(x, y, z);
  77.     stroke(200, 150);
  78.     vertex(xb, yb, zb);
  79.     endShape();
  80.   }
  81. }
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:
  1.   gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, nodes_vbo[0]);
  2.   gl.glVertexPointer(3, GL2.GL_FLOAT, 0, 0);
  3.   gl.glDrawArrays(GL2.GL_POINTS, 0, nodecount);
  4.   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.

Viewing all articles
Browse latest Browse all 1768

Trending Articles