iDevGames Forums
2D lighting - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: iPhone, iPad & iPod Game Development (/forum-11.html)
+--- Thread: 2D lighting (/thread-8345.html)



2D lighting - markhula - Nov 23, 2010 10:21 AM

Hi all,

I am about to implement some 'method' for lighting in my tile based gamed.
My intention was; to save on draw time to perhaps 'light' (alter the colour of each floor vertex quad) relative to the light source.
For example a 'red fire bolt' is produced and as it moves across the screen it 'lights' the floor tiles with red.
Is this the correct approach? or *must* I have alpha quads across each tile and alter their color and translucency to produce a decent visual effect.
Any advice/pointers (*joke :-) ) appreciated!

Cheers


RE: 2D lighting - warmi - Nov 23, 2010 10:54 AM

Vertex lighting will give you very coarse results , which could or could not be enough depending on your goals.
In terms of smooth lighting to handle moving bullets etc , you can simply use an animated (moving) quad blended with GL_ADD with some sort of radial gradient type of black-white texture.


RE: 2D lighting - markhula - Nov 23, 2010 01:02 PM

Hey warmi,

That's a good thought.
But I did want to extend the lighting requirements to any 'object' that can emit light (a flame, a torch on the wall etc.), but not at the expense
of the frame rate dropping below 60fps :-)))))))

Cheers


RE: 2D lighting - warmi - Nov 23, 2010 01:07 PM

Well, there are no free lunches you know .... you want to have more fancy stuff there is going to some cost in terms of fps - it shouldn't matter much as long as you keep your overlay lighting quads small but it may drop your frame rate on iPad where fillrate is at premium.

If you already have vertex colors included in your vertex definitions , you can try with that since it won't make any difference in terms of fps - it just won't look good unless you tesselate your sprites into a very fine grid which in turn will kill your fps.


RE: 2D lighting - markhula - Nov 23, 2010 01:09 PM

Ho-hum!
What to do :-)))
Perhaps I can combine vertex lighting with alpha quads on-top for a kind of compromise......


RE: 2D lighting - Skorche - Nov 23, 2010 01:50 PM

Render your lights into a texture that is a fraction of the screen size. You don't really need a fullsize buffer when the lights are basically blurry splotches.

The lights in Twilight golf were rendered at 128x128, and that was only because we were doing hard edged shadows. It ran 40-60fps on a 1G iPod Touch. If we just wanted soft ligts without shadows, we could have gone down to 64x64 without anybody noticing. On the 3GS and up, we increased the size to 512x512 and it seemed to be able to handle 60fps just fine.
http://howlingmoonsoftware.com/twilightGolf.php


RE: 2D lighting - markhula - Nov 23, 2010 01:55 PM

Ok Skorche,

It sounds good but I am gonna need a bit more detail when you say "render your lights into a texture"
What exactly do you imply I do??????? <sorry for the dumb response!>

:-)

p.s. actually the lighting effects in twilight golf look like the type of thing I am trying to achieve


RE: 2D lighting - Skorche - Nov 23, 2010 02:10 PM

Basically you create a framebufer object (FBO) that is tied to a texture. This lets you render into a texture's pixels instead of the screen's pixels. This lets you draw all the lights once into the smaller sized texture and then apply that over the screen. The idea is to reduce the amount of fillrate needed.

Keep in mind that this only reduces the fillrate when the area of the quads in pixels is much higher than the number of pixels on the screen. You also don't really want to do this until you know performance isn't good enough just rendering them directly to the screen. FBO's aren't rocket science, but they are still sort of a pain.


RE: 2D lighting - markhula - Nov 23, 2010 02:39 PM

Ok
I think I have got what you are saying
Basically know where all my lights will be on screen but render them
Into a smaller texture which I then scale across the whole screen when
I draw
Yeah ? :-)

Ok ,that's the render technique but is the actual light render circle
Just a simple alpha texture of a circle ??

Cheers