We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello
I'm creating a Tile object and then I have a function to draw things with this tiles. Problem is that I need at least 140 instances of those tiles and my frame rate is being killed
My Tile object is made of 2 arcs() and 2 lines(). Sometimes I have a third arc() colouring the tile. My Tile object changes its size according to how the function that draws with it calls it.
Looking for the solution I found Daniel's pshape tutotal which says:
Try to draw around 500 stars and your sketch may run rather slowly, about 10 FPS. This is because this style of drawing, often referred to as "immediate" mode, requires the renderer to compute the geometry each time through draw for each and every star. But is this necessary? After all, it's the same star over and over and over again. Using a PShape allows Processing to essentially "memorize" the geometry of that star. Drawing the memorized geometry (called a "Vertex Buffer Object" in lower-level OpenGL syntax) is called "retained" mode and is a great deal faster. Those 500 stars render easily at 60 FPS using a PShape instead. This can be achieved by including a PShape variable as part of the Star class.
So I looked for such PShape in P5 and only found that where the topic of PShape seems to be in the design phase.
So here I am, asking you guy for a work around : ]
(things I have tried: - hide my tiles as much as possible (I get 5 FPS that way) - render my tile with 2 arcs with big strokes (I get 10 FPS that way [ I need 30]) - render my tile with a bezier... I get lost trying to make my shape parametric - move everything, as is, over to Processing (I get almost 30 FPS !!! :) but my webpage doesn't get better :( ) - I didn't even try to implement the PShape thing in Processing since the Frame Rate is fine )
cheers
Answers
https://GitHub.com/zenozeng/p5.js-svg
http://ProcessingJS.org/reference/
Thank you for your answer GoTo :)
Maybe I'm not enough of an expert to fully appreciate it yet because it takes me to things I don't quite master yet.
Do you mind if I post some code here to see how I should proceed to better it ?
Results of a very quick optimisation below. Main changes:
Framerate improvements were modest, but significant on my laptop: from ~30fps to ~35fps - I've just upgraded to a core i7 with 12GB RAM and am very happy :D
Here's the code:
Obviously caching the shape to SVG should result in far greater gains. I don't have time to look into that: meant to be teaching myself NodeJS and AngularJS at the moment...
What about drawing it on a PGraphics instead of PShape, could it improve the frameRate?
Yep - that had occurred to me too...
For the sheer hell of it I just tried what I've seen recommended in the past for this type of sketch: namely using translate and rotate to achieve the position/rotation; instead of re-calculating everything for each object position. It does have the advantage of simplifying the code a little... I had also hoped that this would be more performant too; since it means you can pre-calculate all the drawing stuff; but the impression is that any gains are lost because of the additional calculations that must be performed by rotate()...
Here's the code (haven't done much by way of tidying/testing/optimisation) for reference:
Wow impressed how you guys are getting into it :D
I have been testing your 2 attempts blindfish and the first one gives me more or less the same FPS as mine while the 2nd is almost 10 FPS slower on my machine.
It looks like my last resort is to try the zenozeng's p5.js-svg option. I'll keep you posted
thank you again !
ok, tested "as is" with zenozeng's svg renderer and FPS is between 3 and 4 FPS.
here is how I did it:
create a new sketch and save it with the proper name ex "svg-test"
download tha lastest p5.js and the latest p5.svg.js
place both files inside the Librairies/ folder in the "svg-test" sketch folder
add in the of the index.html file
paste the above code inside the sktech
change createCanvas(1000, 350); to createCanvas(1000, 350, SVG);
run
I guess the point is now to make a good use of the zenozeng library to turn the tile into some kind of svg parametric object ... I'm going to dig this but it doesn't feel good to me
It's running faster here using PGraphics.
I changed the meaning of radius while editing cause it was calling the diameter radius and it was confusing me.
wow it works really well ! :)
thank you so much Barbara
it is going to take me some time to get this createGraphics() thing to work on my code, but I have the feeling that this is it.
I'll keep you posted