Author Topic: Lighting Issues  (Read 15385 times)

penguin_buddha

  • Newcomer
  • Posts: 19
  • Karma: +0/-0
    • View Profile
    • Email
Lighting Issues
« on: September 24, 2012, 03:32:01 PM »
I've successfully set up the FOV and Lighting for my game but there is one thing wrong. As it currently works, a wall tile can be considered "lit" because it is within the LOS and radius of a light source. This is fine, except that the wall tile is considered lit even when being viewed from the opposite side. For example:

. . . . .. . . . Wall . . .. . . .. . . . .
PC . . . . . . Wall . .. . . . . Light
. . . . . . . .. Wall . . .. . . . . .. . .

In such a scenario the player would see the walls as lit up, even though they are getting light from the opposite direction. Any ideas on how to prevent this? My current method of FOV is with a shadowcasting algorithm.

Hi

  • 7DRL Reviewer
  • Rogueliker
  • *
  • Posts: 154
  • Karma: +0/-0
    • View Profile
    • Email
Re: Lighting Issues
« Reply #1 on: September 24, 2012, 04:47:15 PM »
Make everything double thickness (every tile is really 4 tiles). And then do FoV after lighting so it selects which appearance the tile has by what angle you are looking at it.
« Last Edit: September 24, 2012, 04:49:10 PM by Hi »

penguin_buddha

  • Newcomer
  • Posts: 19
  • Karma: +0/-0
    • View Profile
    • Email
Re: Lighting Issues
« Reply #2 on: September 24, 2012, 05:52:32 PM »
I suppose thats a possible way, but it would require a major change and a lot of time on my part.

Omnomnom

  • Rogueliker
  • ***
  • Posts: 79
  • Karma: +0/-0
    • View Profile
    • Email
Re: Lighting Issues
« Reply #3 on: September 25, 2012, 04:10:17 PM »
What about only drawing a wall tile as lit if the player can see at least one lit floor tile adjacent to that wall tile?

Alex E

  • Rogueliker
  • ***
  • Posts: 118
  • Karma: +0/-0
    • View Profile
    • Email
Re: Lighting Issues
« Reply #4 on: September 25, 2012, 10:18:07 PM »
What about only drawing a wall tile as lit if the player can see at least one lit floor tile adjacent to that wall tile?


That's a good idea. Have a second check come off the player. If both the light and the player's check meet a wall, then that wall becomes lit.

Omnomnom

  • Rogueliker
  • ***
  • Posts: 79
  • Karma: +0/-0
    • View Profile
    • Email
Re: Lighting Issues
« Reply #5 on: September 25, 2012, 11:20:55 PM »
Maybe I misunderstand, but that doesn't sound like the idea I was suggesting.

I am saying don't do another check from the player. I am saying if either of the floor tiles bordering the 2 sides of the wall tile facing the player are both lit and visible to the player then light up the wall tile. Caveat is that I don't know for sure if this works.

I think you are instead suggesting to check which wall-sides are visible from both the player and light and when both the player and light can see a wall-side, that wall tile is lit. Your suggestion, unlike mine, seems 100% accurate and reliable to me, but the problem is my FOV algorithm (and I suspect penguin_buddha's too as we are both using shadowcasting) only returns which tiles are visible, it doesn't return which sides of tiles are visible.

So to avoid altering the FOV algorithm to provide tile-side visibility (I don't even know how), I was trying to solve the problem without knowing which tile-sides are visible.
« Last Edit: September 25, 2012, 11:23:33 PM by Omnomnom »

Leaf

  • Rogueliker
  • ***
  • Posts: 64
  • Karma: +0/-0
    • View Profile
    • Email
Re: Lighting Issues
« Reply #6 on: September 25, 2012, 11:33:14 PM »
Or precalculate the lighting each time an object moves and store it in some field on the tile, then use that as part of the fov algorithm when the player or a critter or whatever "looks" around themselves, be that for player map updates or monster pathfinding or whatever.

It seems to me like you are recalculating lighting every time a fov is required, which may end up being pretty inefficient.  Iunno!

If you don't want to modify your FOV algorithm, you could make it ignore the light level of the tiles and just work on boolean sorts of obstacles, and then walk through the resultant set afterwards and remove all elements that have no light.  Edit: Heck, you can't use the lack of light to block vision in the FOV calculation, anyway; otherwise the player won't be able to see things lit by a torch on the other side of a stretch of darkness.

As for the walls, I had to make every wall adjacent to a "lit" floor space also be considered lit, and not actually cast light on the walls (which makes sense if you think about it: the wall is taking up the whole tile, and no light should be actually "entering" the tile, since it's all full of opaque wall).  Even without the lighting issues you are talking about, the player's field of view looked really ugly without doing it that way.  I ended up going back through the set of visible cells and adding all of the opaque cells adjacent to visible cells to the set of results, rather than trying to write it into the shadowcasting algorithm.

I posted the code in this forum somewhere, if you wanna find it and translate it into the language of your choice. :3
« Last Edit: September 25, 2012, 11:39:28 PM by Leaf »

Alex E

  • Rogueliker
  • ***
  • Posts: 118
  • Karma: +0/-0
    • View Profile
    • Email
Re: Lighting Issues
« Reply #7 on: September 26, 2012, 12:36:23 AM »
Maybe I misunderstand, but that doesn't sound like the idea I was suggesting.

I probably misread it then.

Omnomnom

  • Rogueliker
  • ***
  • Posts: 79
  • Karma: +0/-0
    • View Profile
    • Email
Re: Lighting Issues
« Reply #8 on: September 26, 2012, 09:37:47 AM »
Maybe I misunderstand, but that doesn't sound like the idea I was suggesting.

I probably misread it then.

sorry wasn't having a go, your solution seems the best I just can't use it. I was secretly hoping penguin_buddha would try my idea so he could find any problems with it ahead of me :D i haven't even tried adding lighting yet...I am still stuck on map generator...3 months now. i am slow  :'(

Omnomnom

  • Rogueliker
  • ***
  • Posts: 79
  • Karma: +0/-0
    • View Profile
    • Email
Re: Lighting Issues
« Reply #9 on: September 26, 2012, 09:48:11 AM »
As for the walls, I had to make every wall adjacent to a "lit" floor space also be considered lit, and not actually cast light on the walls (which makes sense if you think about it: the wall is taking up the whole tile, and no light should be actually "entering" the tile, since it's all full of opaque wall).  Even without the lighting issues you are talking about, the player's field of view looked really ugly without doing it that way.  I ended up going back through the set of visible cells and adding all of the opaque cells adjacent to visible cells to the set of results, rather than trying to write it into the shadowcasting algorithm.

Interesting post...lots of things I hadn't thought of...I guess I am going to need to try lighting before being able to contribute anything to this discussion or I'll just end up spouting nonsense....*enters lurk mode*

penguin_buddha

  • Newcomer
  • Posts: 19
  • Karma: +0/-0
    • View Profile
    • Email
Re: Lighting Issues
« Reply #10 on: September 26, 2012, 01:55:16 PM »
Ill let you know when I implement it

dscreamer

  • Rogueliker
  • ***
  • Posts: 65
  • Karma: +0/-0
    • View Profile
Re: Lighting Issues
« Reply #11 on: September 26, 2012, 05:42:42 PM »

As for the walls, I had to make every wall adjacent to a "lit" floor space also be considered lit, and not actually cast light on the walls (which makes sense if you think about it: the wall is taking up the whole tile, and no light should be actually "entering" the tile, since it's all full of opaque wall).  Even without the lighting issues you are talking about, the player's field of view looked really ugly without doing it that way.  I ended up going back through the set of visible cells and adding all of the opaque cells adjacent to visible cells to the set of results, rather than trying to write it into the shadowcasting algorithm.


I do something very similar to what Leaf describes. A solid tile is lit (or not) depending on the light values of its 1 or 2 neighbors in the direction of the viewer. It works for me - good luck.

Leaf

  • Rogueliker
  • ***
  • Posts: 64
  • Karma: +0/-0
    • View Profile
    • Email
Re: Lighting Issues
« Reply #12 on: September 26, 2012, 09:30:13 PM »

As for the walls, I had to make every wall adjacent to a "lit" floor space also be considered lit, and not actually cast light on the walls (which makes sense if you think about it: the wall is taking up the whole tile, and no light should be actually "entering" the tile, since it's all full of opaque wall).  Even without the lighting issues you are talking about, the player's field of view looked really ugly without doing it that way.  I ended up going back through the set of visible cells and adding all of the opaque cells adjacent to visible cells to the set of results, rather than trying to write it into the shadowcasting algorithm.


I do something very similar to what Leaf describes. A solid tile is lit (or not) depending on the light values of its 1 or 2 neighbors in the direction of the viewer. It works for me - good luck.

I did all eight neighbors, as I recall.  It makes the player able to "peer" into holes from a distance a little bit too easily, but it made jagged sorts of natural cave walls render much more pleasantly (at least to my mind).

yam655

  • Rogueliker
  • ***
  • Posts: 59
  • Karma: +0/-0
    • View Profile
Re: Lighting Issues
« Reply #13 on: September 27, 2012, 08:47:05 AM »
sorry wasn't having a go, your solution seems the best I just can't use it. I was secretly hoping penguin_buddha would try my idea so he could find any problems with it ahead of me :D i haven't even tried adding lighting yet...I am still stuck on map generator...3 months now. i am slow  :'(

This is why I recommend toolkits with the common functions for folks starting out.

It's a lot easier to stay focused on the work, if the work you're actually doing is sexy. (If not sexy, then at least fundamentally meaningful for your core game idea.)

Basic dungeon generation? Not sexy. (How likely is it that it's going to be the dungeon generation that sets your game apart from others in the genre?)

I'm not saying folks shouldn't also try their hands at writing their own underlying routines, but if it is a choice between a functional-but-not-perfect lighting routine (or what-have-you) that someone else wrote and debugged versus writing my own lighting routine from scratch... Until I got to a point where I thought I could do something fun and unique in a lighting routine, I would focus on the easier parts that have more of a functional bang for their buck.

Cheers,
Steven Black

kraflab

  • Rogueliker
  • ***
  • Posts: 454
  • Karma: +0/-0
    • View Profile
    • kraflab.com
Re: Lighting Issues
« Reply #14 on: September 27, 2012, 08:57:02 AM »

It's a lot easier to stay focused on the work, if the work you're actually doing is sexy. (If not sexy, then at least fundamentally meaningful for your core game idea.)

Basic dungeon generation? Not sexy. (How likely is it that it's going to be the dungeon generation that sets your game apart from others in the genre?)


Whaaaat?  What is sexier than writing new dungeon or fov algorithms?  It's like the best part of the project! :D