Grid based lighting/field of view

Discussion and feedback on Construct 2

Post » Tue Sep 20, 2011 7:12 am

Now averages around 57 FPS - much better :)
If your vision so exceeds your ability, then look to something closer.
Moderator
B
120
S
28
G
68
Posts: 4,850
Reputation: 48,301

Post » Tue Sep 20, 2011 11:12 am

[QUOTE=tulamide] [QUOTE=00Rez]EDIT: Here is a quick implementation of the plugin version using pre-calculated light/sight arrays. Left click to create a "House" which blocks sight. PLEASE NOTE: The slow down is caused by the number of black blocks, not related to the plugin! This is just a simple example to show the speed difference so nothing fancy![/QUOTE]
And what a difference it makes!
The event driven demo runs with 4 to 26 fps on my pc, the plugin version runs with 58 to 65 fps (slowing down to 26 as soon as the black blocks are drawn).

But I must say the event driven demo reminds me more on some topdown minecraft thingy :D[/QUOTE]

Yeah it has all fancy opacity events and is based on the mouse position. None of that in the second test. I'm glad the speed is better still more to do. Need to find a way to show the field of view without the use of blocks maybe. Definitely influenced by Minecraft and roguelikes.
B
21
S
7
G
2
Posts: 185
Reputation: 3,280

Post » Tue Sep 20, 2011 11:13 am

[QUOTE=zenox98] Now averages around 57 FPS - much better :)[/QUOTE]

That's great! Still more to do...
B
21
S
7
G
2
Posts: 185
Reputation: 3,280

Post » Wed Sep 21, 2011 12:17 am

Another update! Just a few more tests. See first post.
B
21
S
7
G
2
Posts: 185
Reputation: 3,280

Post » Wed Sep 21, 2011 12:36 am

love the improvements rez,

hope you don't lose the 'retro' graphic opacity zones of the first test. that has dungeon crawl written all over it...lol.

love the smoothness of the latest tests as well.

my half-orc 'grogan t. blackblade' awaits your progress.
B
52
S
17
G
15
Posts: 1,029
Reputation: 26,339

Post » Wed Sep 21, 2011 10:55 am

[QUOTE=harrio] love the improvements rez,

hope you don't lose the 'retro' graphic opacity zones of the first test. that has dungeon crawl written all over it...lol.

love the smoothness of the latest tests as well.

my half-orc 'grogan t. blackblade' awaits your progress.[/QUOTE]

If I can find a quicker way of rendering shadows then this would be easy just a play on opacity. Another way is to limit the range so when you render the light it only uses a few objects for lit squares but I still need to find a quick/good way of doing this. Then you would have a dark layer over everything then use light objects to cut out the dark layer like the way the light works in my demos, hopefully that would speed things up! Then there's making it as easy as possible for everyone...
B
21
S
7
G
2
Posts: 185
Reputation: 3,280

Post » Thu Sep 22, 2011 9:37 am

Getting there! Went back to real time calculation which is actually really fast. Made it so you can limit the radius which speeds things up. Currently working on a method to make finding lit/seen cells faster (for rendering)... 00Rez2011-09-22 09:38:16
B
21
S
7
G
2
Posts: 185
Reputation: 3,280

Post » Thu Sep 22, 2011 12:50 pm

Good work. Running 60 fps in the 40x40 cells demo, needing 1.5 seconds to re-calculate.

I don't know your algorithm, but make it flexible enough to only calculate rows and columns, instead of the whole scene. Then, while moving the camera only calculate the next one or two (depends on the speed of the camera movement) rows/columns.

If the camera goes to the right, you only need to calculate one or two columns to the right, if the movement hits the next column (grid-based, in this case column 41 would be needed, etc.). Same for all other directions. The heaviest impact would be a diagonal movement, where both, row and column needs to be calculated.

EDIT: Forget about it. Was writing quicker than thinking. It doesn't solve the problem of light cells that may influence the rows/columns. Sorry.tulamide2011-09-22 12:52:06
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Thu Sep 22, 2011 1:26 pm

[QUOTE=tulamide] Good work. Running 60 fps in the 40x40 cells demo, needing 1.5 seconds to re-calculate.

I don't know your algorithm, but make it flexible enough to only calculate rows and columns, instead of the whole scene. Then, while moving the camera only calculate the next one or two (depends on the speed of the camera movement) rows/columns.

If the camera goes to the right, you only need to calculate one or two columns to the right, if the movement hits the next column (grid-based, in this case column 41 would be needed, etc.). Same for all other directions. The heaviest impact would be a diagonal movement, where both, row and column needs to be calculated.

EDIT: Forget about it. Was writing quicker than thinking. It doesn't solve the problem of light cells that may influence the rows/columns. Sorry.[/QUOTE]

No worries. I've noticed I can use a real time method which doesn't impact performance as much as long as the "radius" of light is limited. My algorithm is just BASIC fov so it sends rays out. Limiting the rays to a certain length increases speed alot. The only problem I'm having is I've created a "list" to hold all "lit" cells instead of having to iterate through all which slows it right down on large grids! The problem I'm having at the moment is overlapping which adds the same positions to the list, I need a way to make sure only one position is added and no duplicates.
B
21
S
7
G
2
Posts: 185
Reputation: 3,280

Post » Thu Sep 22, 2011 1:39 pm

Here's my progress:

This shows pretty much how the Events will work:



And this is the latest example!

This example is 40x40 and calculates real time! Move the purple block with the arrow keys!

Edit: The example now only renders lit cells surrounding the Purple player. The grid is 60x60 with the sight radius of 6! I get about 30 fps which is pretty good at 60x60 cells. For some reason the "light" is brighter when exported?00Rez2011-09-22 15:25:01
B
21
S
7
G
2
Posts: 185
Reputation: 3,280

PreviousNext

Return to Construct 2 General

Who is online

Users browsing this forum: pablo7, Yahoo [Bot] and 14 guests