4
\$\begingroup\$

I am working on a terraria-clone and I am aiming for it to be able to be run on most Android devices. I am able to generate a world, jump around, etc but I am not looking to add in some efficient lighting. In the past I have tried doing a tile-based lighting system but the project quickly came to an end after that because it dropped performance hugely. In that demo I was drawing a transparent black square over each tile and setting the alpha value dependent on surrounding lights. I envision that this will not be efficient on mobile so I don't even know if I want to go down that road. I don't need the shadows or anything like that (as of right now), I just need the lighting portion implemented. I have also looked at the other suggestions on the page here but am not sure which is the best option.

If tile-based lighting is the way to go I'd have to think of the best way to go about it. I don't think that it would be a problem to just have it work with a torch giving off light and only updating light values when a light source is added/removed, but when entities are incorporated I also have to think about how will I efficiently update an entities light value based off of surround light values. I have optimized the game a lot so far, with a world of 1,620,000 tiles being contained within it and getting a stable, smooth 30 fps even on mobile. I haven't attempted creating larger worlds than that but I don't see why, at this rate, it wouldn't be able to become any larger. I am trying to keep it as optimized as possible throughout development of the entire game so coming up with an efficient, optimized lighting system is essential.

Any suggestions are greatly appreciated.

\$\endgroup\$
6
\$\begingroup\$

One option would be to load lighting information only as it appears on the screen. You would get one performance hit at the beginning as the full screen lighting is calculated, but from there you could cache the information and (as you mentioned) update it only when a light is flagged as modified. As you move across the world, you could calculate a short distance ahead so the player doesn't run into a dark area when it should be broad daylight.

For tile shading, I would recommend tinting/multiplying the tile color by the lighting percentage as this doesn't require adding an additional draw call for a shading square.

Terraria now has a mini-map feature that gradually fills out as you visit areas, and I suspect you could save your lighting information in a similar way.

Two other options, which could be overlapped with my suggestion above, include multithreading or offloading the lighting computations to the GPU. If these features are supported on Android, which I would certainly assume to be true.

\$\endgroup\$
  • \$\begingroup\$ Yeah I definitely already had the idea to only handle it if it is on the screen. I have the world split off into chunks that are 50x50 tiles so I would only find the lights saved within there and update/render them. I have a ton of cases and specifics written down that would speed it up. Maybe I should just implement it instead of asking questions and going in circles. And yes pushing the work off to the GPU would be done through shaders. \$\endgroup\$ – Jmrapp Sep 23 '15 at 1:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.