Optimization tips

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
OmarShehata
Party member
Posts: 259
Joined: Tue May 29, 2012 6:46 pm
Location: Egypt
Contact:

Optimization tips

Post by OmarShehata »

I'm at a point where I need to do some serious optimization.

My biggest issue is with rendering large amounts of objects. I would appreciate any tips or tricks. Like, do you use SpriteBatches? Perhaps a clever use of canvases? I know I'm being super vague, but any general tips would be awesome. Just for example if you want to have as many animated enemies on screen as you can.

Now for a specific question. I'm applying a shader to every object in play. Instead of doing that, if I take a screenshot of the stage, render that image, and apply the shader on it, would I have effectively gone from running my shader on thousands of objects to 1? Sounds a bit too good to be true. Any foreseeable drawbacks?
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Optimization tips

Post by Nixola »

Using a screenshot instead of a canvas doesn't seem a good idea to me, taking a screenshot and converting it into an image every frame is quite slow, and it uses lots and lots of RAM, forcing the garbage collector to run way more frequently than normal
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Optimization tips

Post by bartbes »

As for the "shader optimization" (which really shouldn't affect you too much unless you've got tons and tons of overlap), this does in fact work this way. I would recommend using a canvas for it instead, though, as Nixola mentioned.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Optimization tips

Post by Jasoco »

Though be careful as a bunch of our users (Not me) have computers that can't use Canvases because their video cards are old or they have outdated drivers or random other reasons. So its best to include a Canvas-less mode for them and detect whether they support them by using the isSupported() function.
User avatar
OmarShehata
Party member
Posts: 259
Joined: Tue May 29, 2012 6:46 pm
Location: Egypt
Contact:

Re: Optimization tips

Post by OmarShehata »

Thanks for the replies Nixola and bartbes!
Jasoco wrote:Though be careful as a bunch of our users (Not me) have computers that can't use Canvases because their video cards are old or they have outdated drivers or random other reasons. So its best to include a Canvas-less mode for them and detect whether they support them by using the isSupported() function.
I am planning on doing that, but I'm having doubts on whether it's worth it. There's a lot of stuff that would be dependent on shaders and/or canvases, and without it the game would either look horrible or have really bad performance. We could try to fake some things and cut some corners just so people without the hardware can play.

My first priority is actually getting the game to work correctly on my machines, then I can start to worry about making it work for everyone, even if I have to rewrite some things.
holothurian
Prole
Posts: 22
Joined: Sat Dec 22, 2012 11:59 pm

Re: Optimization tips

Post by holothurian »

Omar I had a look at some concerned joe videos and I love his face getting more and more anxious when he's standing still. Very expressive sprite work!
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: Optimization tips

Post by BlackBulletIV »

OmarShehata wrote:I am planning on doing that, but I'm having doubts on whether it's worth it. There's a lot of stuff that would be dependent on shaders and/or canvases, and without it the game would either look horrible or have really bad performance. We could try to fake some things and cut some corners just so people without the hardware can play.

My first priority is actually getting the game to work correctly on my machines, then I can start to worry about making it work for everyone, even if I have to rewrite some things.
Don't let it deter you from using shaders and canvases; almost all games use things like that nowadays. I'd recommend giving people the option to not run it with those features, but only if it's not too much of a hassle.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Optimization tips

Post by Jasoco »

Yeah. A lot of games will let you turn settings off to get better performance or for compatibility reasons. It's always nice to have really high settings and something that can still be enjoyed by others.
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: Optimization tips

Post by BlackBulletIV »

That's what I'm doing with my arena shooter, although the game looks terrible without bloom on.
User avatar
OmarShehata
Party member
Posts: 259
Joined: Tue May 29, 2012 6:46 pm
Location: Egypt
Contact:

Re: Optimization tips

Post by OmarShehata »

Ok so, as far limitations go, all objects rendered with one SpriteBatch need to share the same:

-Alpha & color
-Depth (as in, something outside the sprite batch can't be between two things inside a sprite batch)
-Shader effect

So I just need to be smart about which objects I group into an atlas.

There doesn't seem to be a way to remove individual items from a Batch, would I have to clear everything and add them all back if I wanted to remove 1?

So so far it seems Sprite Batches are really good for things that won't move or get changed often, that don't need to be updated every frame.

Also, is there any way I can use canvases to speed things up even more? I keep thinking I could draw the backgrounds and static tiles onto a canvas, so that I only draw it once, and only redraw that canvas when I change anything, but then I could do the same thing with a sprite batch and update the sprite batch when I need to.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 212 guests