Search code examples
frame-rate

how to develop demo application with FPS rate using kick.js?


I'm very interested in Kick.js. To convince my professor to use this framework, I want to develop an application which I can load/code custom 3D model using kick.js and should be able to add more objects. I should also able to print FPS to check the variations in FPS as I add more 3D objects on canvas. I'm new to graphic programming, I neither have knowledge on shader programming nor openGL. Being a newbie, how can I start diving into this framework?

The following steps I wanted to implement (Suggest me if I go wrong):

  1. Develop simple demo using kick.js loading single cube or sphere or teapot on canvas.
  2. Able to see the fps as I change the camera angles.
  3. Later I should be able to add more triangles(Models) on the canvas of same type (ex: Teapot) and able to compare the fps with single teapot one.

Am i approaching the right way or please suggestions needed. The provided tutorials neither of them having FPS demo. Please someone HELP ME. I really liked the features stated on homepage but I don't know how can I implement them in my demo.


Solution

  • Assuming that Kick.js has a "render" callback or something similar that's invoked for each frame you want to render (and you know the time between frames, or the absolute time since program start), it's fairly simple to calculate your frame rate.

    The method I've used before is: pick a sample rate (I like 250ms so it updates 4 times a second), and count how many frames have executed every 250ms. When you hit 250ms, update the on-screen frame rate counter variable and start counting again.

    timeSinceLastFPSUpdate += millisecondsSinceLastFrame;
    framesSinceLastFPSUpdate++;
    if timeSinceLastFPSUpdate > 250:
        timeSinceLastFPSUpdate = 0
        fps = framesSinceLastFPSUpdate * (1000 / 250); // convert "frames per 250ms" to "frames per 1s"
        framesSinceLastFPSUpdate = 0;
    
    print fps to screen;
    

    You can play around with different sample rates or use a different frame rate calculation method to get the timer to be more "accurate" (to better find frame rate dips) but it sounds like you're looking for something that's less accurate and is just giving you a reasonable idea of the overall complexity of rendering rather than frame to frame dips.