This project is read-only.

krypton and a large scale tilemap

Mar 25, 2012 at 9:15 PM
Edited Mar 25, 2012 at 9:23 PM

I am currently trying to implement a tilemap with atleast 50k+ shadowhulls/lights. Obviously the solution would be to divide the tilemap into smaller sections to manage iterations on smaller lists. What would be the best approach to handle lighting in sections?

 

So far I have come up with:

1) Using a single krypton engine throughout the tilemap and recreating lights/shadowhulls of the current section and 8 surrounding sections every time player enters a new section.

2) Single krypton engine with a single active map section, which will be recreated around the player every time player reaches the edge of the section.

2) Using multiple krypton engines as if assigning each section its own engine and only drawing currently active engines.

 

Any idea is welcome! Thanks in advance!

Edit: By the way, I would like to thank you xixonia for your time developing krypton. It is an excellent lighting engine both for its quality and ease of use! Keep up the good work!

Mar 31, 2012 at 12:35 AM

Hi

I also did this in a tilemap your size, so far I have been checking which tiles are visible (+ some more offscreen for more distant lights), drawing those, and clearing the list every time (300+ hulls). This is not very effective ofcourse as it produces a lot of garbage and framerate drops for slower computers.

This was not my highest priority since I'm still in Alpha development phase and just wanted to see what I could do with the engine. (got an AMD six core 2,8 gHz + 8GB ram anyway xD) So I have done little in working my way around this.

Before I continue I'd want to say that I'm just an amateur developer, but I think your nr. 1 might be a good idea based on my experiences. Krypton handled my way of 'screwing around' very well plus the calculations are done every frame anyway, whether you recreate the hulls or not.
What you do have to watch out for is that you should never have more than 1000 hulls, this will not only cause your game to lag it'll freeze. So you have to take in account.

I don't know how large your sections would be or how much hulls will be on them. But I work with a 1920*1080 monitor on fullscreen and already have 300+ hulls per frame. If you render 8 sections (Your game is top-down btw??) There'd be 2400 hulls, way too much. This wouldn't be a problem if you worked with a 500*500 viewport ofc, then there would be something like 30 hulls per section so 240 hulls in 8 sections.

What would be really awesome is that you would have a 2d array, and you check which array[x,y]; would need to be rendered by Krypton, Krypton does not support this by default but you (we) could try to put open-source into practice and change the code so it does work. Bye-bye garbage.

I hope this helped you in some way. :)

Apr 1, 2012 at 10:58 AM

You could always do:

if (oldCameraPoint != newCameraPoint)
{
    krypton.hulls.clear();

setNewHulls();
}
This way you may be able to save a lot of power still if there is not much reason to move the camera.

Apr 1, 2012 at 5:09 PM

Yeah, I'm creating a tilemap from top down perspective. The camera will be in constant movement as it is centered around the player.

Anyway, I am going to try out this "recreating hulls only when player is moving" idea and let you know how it went.

Storing hulls in a 2d array would make perfect sense for these kind of tilemap games and would drastically improve performance/amount of hulls possible to store on the map. The ideal solution for my case would be to store tilemap hulls in a 2d array and entity hulls in a dynamic list

Apr 1, 2012 at 10:19 PM

First of all...

NEVER RECREATE HULLS.

Hulls should never be recreated. They should simply be removed from Krypton's list of hulls and saved for later. Unless you have some serious memory issues. And if that's the case, I doubt removing references to the hulls is going to help anything.

Second of all...

Have you actually run into any performance issues yet, or are you simply anticipating them? If you're just anticipating them, then hold off on the optimization. You could end up wasting a lot of time for zero to little results. Krypton already culls lights, and lights only render hulls within their radius, so it's not *rendering* anything unnecessarily. I'd suggest throwing all of the hulls in there at once and seeing what happens (just make sure the view matrix doesn't put all of them in view at one time).

Third of all...

The best way to actively add / remove lights from the Krypton engine would be to modify the engine to accept an IEnumerable<ShadowHull> as it's list of hulls. Then you can create a quad-tree class that holds all of your hulls (2 quad trees, really... once for static hulls, and one for hulls that move around), and implement IEnumerable<ShadowHull> on that quad tree. The quad tree class's GetEnumerator method can then use the quad tree to figure out what hulls need to be drawn, and "yield return" only those hulls.

Apr 1, 2012 at 10:20 PM

This problem is inspiring... Something like this should be included in Krypton.

Apr 1, 2012 at 10:22 PM

I used a similar method for Erin Cato's Box 2D example back in the day. I was able to reduce the number of calculations used for physics by quite a bit, enabling me to increase from 50 rigid bodies to over 500 rigid bodies at the same frame rate. And that was accessing the quad tree for every body, not just once per frame render like we're suggesting here.

Apr 2, 2012 at 4:55 PM
Edited Apr 2, 2012 at 4:55 PM
xixonia wrote:

First of all...

NEVER RECREATE HULLS.

Hulls should never be recreated. They should simply be removed from Krypton's list of hulls and saved for later. Unless you have some serious memory issues. And if that's the case, I doubt removing references to the hulls is going to help anything.

 

What I meant under recreating hulls was clearing and adding necessary hull references to the kryptonengines hull list. Sorry if I misspoke :)

AmazingDreams wrote:

You could always do:

 

if (oldCameraPoint != newCameraPoint)
{
    krypton.hulls.clear();

setNewHulls();
}
This way you may be able to save a lot of power still if there is not much reason to move the camera.

 

Currently implemented this solution. If camera has been moved/zoomed or rotated the hull list will be cleared and visible hulls will be added to the hull list.

Exactly what I was looking for! :) Tried even with full hd screen all filled with hulls (32px tile width/height => 1920 / 32 * 1080 / 32 = 2025 active hulls) and its running great.

 

Apr 3, 2012 at 5:23 PM

It's cool. I'm not trying to punish you for implying incorrectly. I just wanted to ensure you got off on the right foot. The best of ideas are sometimes shot down by the simplest of mistakes.

Apr 4, 2012 at 4:01 PM

"punish".... poor choice of words. :) Sorry!

Apr 4, 2012 at 5:08 PM

hehe, no probs!

Am gonna continue working on my tileengine and krypton next week ... I'll let you know once I have something to demo, but so far Krypton is great ... Gotta love the visuals! Good luck working on 3.0!