On Android Device Animation too slow! (on PC its normal) GPU? OpenGL?

I followed a tutorial from

And the Code runs very well in PC(Laptop).(It runs fluently)

But when I tried to run it on Android Device it became very slow. (i guess one frame / 2 Seconds) The Core Code is here

void draw() {
  background(51);

  loadPixels();
  for (int x = 0; x < width; x++) {
    for (int y = 0; y < height; y++) {
      int index = x + y * width;
      float sum = 0;
      for (Blob b : blobs) {
        float d = dist(x, y, b.pos.x, b.pos.y);
        sum += 10 * b.r / d;
      }
      pixels[index] = color(sum, 255, 255);
    }
  }

  updatePixels();

  for (Blob b : blobs) {
    b.update();
  }
}

Can anyone help me, what is the problem here?

Because it loads every pixel and does pixel processing, so it uses CPU? How can I do pixel Processing using GPU?(I am not sure, if i express this correctly, i have no experience in computer graphics)

Thanks

Answers

  • It is known that running processing in android is slow. You could reduce the size of your sketch if you want to work in a prototype that acts faster. You can try using P2D/P3D renderer if you are not done so.

    Where is your blob data coming from? What kind of data is it? If it doesn't change over time, then you could do all the operation only once.

    Kf

  • I'm having a very similar problem (and learning from the same guy!) So I can make a simple gravity simulation no problem. But when I try to make things more complicated I get very low framerates, even using P3D. Is there any other optimizations I could utilize? This is a 3D mesh of springs that bounces up and down with gravity.

    `

        import toxi.physics3d.*;
        import toxi.physics3d.behaviors.*;
        import toxi.physics3d.constraints.*;
        import toxi.geom.*;
    
        //create the mesh
        int cols = 40;
        int rows = 40;
    
        //fill mesh with springs
        Particle[][] particles = new Particle[cols][rows];
        ArrayList<Spring> springs;
    
        //Field of View
        float w = 8;
        int b = 1;
    
        //bring in the physics
        VerletPhysics3D physics;
    
        void setup() {
          size(600, 600, P3D); 
          springs = new ArrayList<Spring>();
          physics = new VerletPhysics3D();
          Vec3D gravity = new Vec3D(0, 1, 0);
          //Vec3D wind = new Vec3D(b, 0,0);
          GravityBehavior3D gb = new GravityBehavior3D(gravity);
          //ConstantForceBehavior3D gw = new ConstantForceBehavior3D(wind);
          //physics.addBehavior(gw);
          physics.addBehavior(gb);
    
          float x = -cols*w/2;
          for (int i = 0; i < cols; i++) {
            float z = 0;
            for (int j = 0; j < rows; j++) {
              Particle p = new Particle(x, -200, z);
              particles[i][j] = p;
              physics.addParticle(p);
              z = z + w;
            }
            x = x + w;
          }
    
          for (int i = 0; i < cols; i++) {
            for (int j = 0; j < rows; j++) {
              Particle a = particles[i][j];
              if (i != cols-1) {
                Particle b1 = particles[i+1][j];
                Spring s1 = new Spring(a, b1);
                springs.add(s1);
                physics.addSpring(s1);
              }
              if (j != rows-1) {
                Particle b2 = particles[i][j+1];
                Spring s2 = new Spring(a, b2);
                springs.add(s2);
                physics.addSpring(s2);
              }
            }
          }
    
    
    
    
          //Lock top two corners
          particles[0][0].lock();
          particles[cols-1][0].lock();
          particles[0][rows-1].lock();
          particles[cols-1][rows-1].lock();
        }
        float a = 0;
    
        void draw() {
          background(51);
    
          translate(width/2, height/2);
    
          //rotate around mesh
          //rotateY(a);
          a += 0.005;
          physics.update();
    
          for (int i = 0; i < cols; i++) {
            for (int j = 0; j < rows; j++) {
              //particles[i][j].display();
            }
          }
    
          for (Spring s : springs) {
            s.display();
          }
    
        }
    
        void mouseClicked(){
          //b = b+1;
          physics.update();
          setup();
        }
    
    `
    
Sign In or Register to comment.