Author Topic: Comparative study of field of view algorithms for 2D grid based worlds  (Read 9715 times)

Hvilela

  • Newcomer
  • Posts: 6
  • Karma: +0/-0
    • View Profile
    • Email
Hi Guys,

Even though I'm a gamer and a game developer I have to admit I never developed (or even played) a rogue like game. I'm here cause I'm trying to implement the x-com gameplay and for this I need to implement fog of war / field of view.

My researches lead me to this article (http://www.robotacid.com/flash/red_rogue/shadow_casting/fov.pdf), that lead me to Roguebasin, that finally lead me here.

My first problem is that the link for the algorithm called DIAMOND (http://www.geocities.com/temerra/los_rays.html) is broken and I just can't find it, so I have no idea about how to implement it. It has another name? Were can I find an article about it?
I guess it's Ray Casting (http://roguebasin.roguelikedevelopment.org/index.php/Ray_casting) but I'm not sure.

My second problem is that each algorithm has his flaws, and (for my case, at least) that flaws are unacceptable. After a fast look I realized that a logic AND between the SHADOW and DIAMOND (the tile is visible if it's considered unblocked by both algorithms) would result in a better result.
The easiest way to imagine the result is to "sum" both shadows.

Let's take a look in each case:
Adjacent to the pillar behavior: Just like SHADOW, a nice V shaped shadow.
Away form the pillar behavior: The sum of the algorithms create a nice V shaped shadow. Better than any of the algorithms alone.
Corner peeking: Not allowed, just like SHADOW.
Inverted corner peeking: Not allowed, just like DIAMOND, making the corner peeking symmetric.
Diagonal Wall: Blocks view, like DIAMOND. What is the expected result for me, cause I allow diagonal movement but only when the 3 tiles involved are unblocked.

Symmetry: As long it's not implemented yet, I did not calculate the symmetry, but at least in the corner peeking special case it's symmetric.

Performance: My idea is to call SHADOW, and cast the rays (DIAMOND) only for the tiles considered visible. On the worst case it would roughly be the sum of the cost of both algorithms, what is in most of cases it's still faster than DIGITAL.

I would like to hear opinions about that.
« Last Edit: September 04, 2012, 03:42:14 PM by Hvilela »

Hvilela

  • Newcomer
  • Posts: 6
  • Karma: +0/-0
    • View Profile
    • Email
Result of SHADOW and DIAMOND
« Reply #1 on: September 04, 2012, 03:58:05 PM »
I created an image to illustrate the result of SHADOW and DIAMOND.

requerent

  • Rogueliker
  • ***
  • Posts: 355
  • Karma: +0/-0
    • View Profile
Re: Comparative study of field of view algorithms for 2D grid based worlds
« Reply #2 on: September 04, 2012, 05:13:22 PM »
http://blog.pixelpracht.net/?p=340

From a recent post here that would probably be useful to you. It includes source and an interactive flash demo.

Hvilela

  • Newcomer
  • Posts: 6
  • Karma: +0/-0
    • View Profile
    • Email
Re: Comparative study of field of view algorithms for 2D grid based worlds
« Reply #3 on: September 04, 2012, 06:12:12 PM »
Thank you for the reply. But I need to be sure:
Diamond == Ray Casting ?

requerent

  • Rogueliker
  • ***
  • Posts: 355
  • Karma: +0/-0
    • View Profile
Re: Comparative study of field of view algorithms for 2D grid based worlds
« Reply #4 on: September 04, 2012, 07:00:22 PM »
I'm not really sure what DIAMOND is. The link I sent you shows a pretty clear example of what ray-casting is.

In your first DIAMOND image, more than one ray should be blocked by the pillar, which would produce a cone, pending on how many rays are cast. In your example, it looks like you've got something of the order of 80 rays. The pillar would block at least 8 or so rays

DIAMOND looks like it calculates lines between all light obstructing objects and just places shadows on those lines where pertinent. This isn't quite ray-casting.


Hvilela

  • Newcomer
  • Posts: 6
  • Karma: +0/-0
    • View Profile
    • Email
Re: Comparative study of field of view algorithms for 2D grid based worlds
« Reply #6 on: September 04, 2012, 08:12:36 PM »
The fist link do not explain how to implement it, the diagonal walls result are not what I expect and it do not show the results for "away the pillar".

The second has no usefull information.

The third would be great if the link to the source wans't broken. :)

XLambda

  • Rogueliker
  • ***
  • Posts: 208
  • Karma: +0/-0
    • MSN Messenger - tau_iota@live.de
    • View Profile
    • The Weird Rogue
Re: Comparative study of field of view algorithms for 2D grid based worlds
« Reply #7 on: September 04, 2012, 08:54:09 PM »
The third would be great if the link to the source wans't broken. :)

I just checked it, the file it links to is still in the libtcod source. It's just not hosted on googlecode anymore.

Normally I'd tell you to just download the libtcod source (which is located here). However, because I'm feeling generous today, here's a straight link to fov_diamond_raycasting.c! ;D

Hvilela

  • Newcomer
  • Posts: 6
  • Karma: +0/-0
    • View Profile
    • Email
Re: Comparative study of field of view algorithms for 2D grid based worlds
« Reply #8 on: September 05, 2012, 12:41:48 PM »
Thanks man!