Question

I'm working on a game that is basically a rapid changing 2D scene where some point lights (each can have its own color) are placed on the screen that can also move on their own with each frame.

Let me first give you a few situations I sketched on paper earlier today:

Different kind of point light situations

The endproduct should be like shown in 4. My question boils down to: Which implementation would you choose for performance, and why would you do so.

  • How many shader programs will be needed, what resources & how big (texture ? VBO ?)
  • How many context switches (program change, other uniforms, ..)

My current approach would be to have a texture of where light is and where not. This will get rendered at start of each frame, but only used on the next frame. So Light would always laag 1 Frame behind, which might just look fine anyways. During normal rendering of objects (e.g. blue rectangle) i'll look up the light texture in fragment shader and combine that value with the objects one.

However, I see the following drawbacks:

  • Light always laags behind (60 FPS => 16.6ms). With objects moving up to 15 pixels per frame, this might look laagy.
  • I need to keep a big texture no matter how many lights are on the screen (can be 0, can be 100).
  • With each frame, I'd need to clear the light texture to gray with alpha for global dimmdown and then redraw all lights..

The biggest advantage I see is that this is only 2D, so it does not really need to be aware of any shadows or something.

Feel free to post any suggestions, I'm happy to read about and test them all. Don't want to waste any performance unnecessarily.

Was it helpful?

Solution

here I risk probably to oversimplify your problem. If I do so, sorry about it.

When you talk about lighting and 2D sprites, I always think about an overkill. A huge hammer (which costs you in implementation time + rendering time) for a very small nail.

There are plenty of ways to simulate lighting in a very cheap and efficient way.

A typical example is to draw a bitmap with alpha simulating the light point of effect which creates a very good sense of "fake lighting" on isometric games. There are (or better, there were) plenty of commercial games using this trick.

An example of this https://gamedev.stackexchange.com/questions/22159/can-i-achieve-a-torchlight-effect-lighter-area-around-a-light-source-in-a-2d-g

If hypothetically you could use a solution like this, you could achieve outstanding performances at parity of solution since this effect would be much much cheaper than any other lighting calculation.

I hope to have helped in some way.

Cheers Maurizio

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top