Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.
Sign upPrevent seeing light through walls #26488
Conversation
jbytheway
changed the title
[WIP] Prevent seeing light through walls
[WIP][CR] Prevent seeing light through walls
Nov 1, 2018
This comment has been minimized.
This comment has been minimized.
|
This definitely looks like the right way to do it, I've been concerned that it was going to unduly impact performance, but I hadn't thought of only applying the 4 quadrant update to opaque tiles. I agree this seems to mesh with all the optimizations I have planned for shadowcasting (both the dynamic lighting overhaul and refactoring the shadowcasting algorithm to be breadth-first). |
This comment has been minimized.
This comment has been minimized.
|
The issue is #13356. |
This comment has been minimized.
This comment has been minimized.
|
The tests comparing various algorithms ( |
This comment has been minimized.
This comment has been minimized.
|
OK, I found a version that does pass (f48f788); bisecting. |
This comment has been minimized.
This comment has been minimized.
|
OK, so it broke in e858c00 slightly. It looks like it might have got worse at some point since then, but it's kind of subjective, so I'm not sure. In any case, I assume I should not be worrying about that test. (Should have paid more attention to the comment written above it, I suppose...) |
BevapDin
reviewed
Nov 3, 2018
| return *std::max_element( values.begin(), values.end() ); | ||
| } | ||
|
|
||
| friend inline four_quadrants operator*( const four_quadrants &l, const four_quadrants &r ) { |
This comment has been minimized.
This comment has been minimized.
BevapDin
Nov 3, 2018
Contributor
inline is redundant here. Functions defined inside the class definition are automatically inline.
This comment has been minimized.
This comment has been minimized.
jbytheway
Nov 3, 2018
Author
Contributor
I thought that was only true of member functions, but it seems you're right; it applies to friend definitions also. Thanks.
This comment has been minimized.
This comment has been minimized.
|
Sorry about the confusion, most of those tests are execution aids and migration validation rather then ongoing regression tests. |
This comment has been minimized.
This comment has been minimized.
|
There's another oddity I'd like to understand. If we look at the following chunk of code from the visibility algorithm (this is from master, not my branch): Lines 5458 to 5471 in f99a963 we see that it's choosing from a sequence of decreasing light levels. There's one strangeness which is already called out in a comment in this code. It can never return However, there is more. Look at the definitions of the constants: Line 6 in f99a963 Line 15 in f99a963 LIGHT_SOURCE_BRIGHT and LIGHT_AMBIENT_LIT are the same, so this function can also never return LL_LIT. Is that intentional?
|
jbytheway
force-pushed the
jbytheway:no_light_through_walls
branch
Nov 5, 2018
This comment has been minimized.
This comment has been minimized.
|
Tests written. Some bugs found and fixed. I believe it's functionally complete now. Still want to do some performance testing. |
jbytheway
changed the title
[WIP][CR] Prevent seeing light through walls
[CR] Prevent seeing light through walls
Nov 6, 2018
jbytheway
force-pushed the
jbytheway:no_light_through_walls
branch
Nov 6, 2018
This comment has been minimized.
This comment has been minimized.
|
(Rebased to avoid build error about mismatched Makefile) I think this is now ready. Of course, testing by others would be welcome. Performance testing shows very little difference between the light casting algorithms' performance (up to ~1%):
As anecdotal evidence, I also tried burning down some buildings and the performance seems fine. I used perf while doing so; it shows that My other reason for running perf was to verify that |
jbytheway
closed this
Nov 7, 2018
jbytheway
reopened this
Nov 7, 2018
jbytheway
force-pushed the
jbytheway:no_light_through_walls
branch
2 times, most recently
Nov 7, 2018
This comment has been minimized.
This comment has been minimized.
|
Got a slightly concerning crash on one of the mingw builds on Travis (looks like a null pointer dereference). Not sure how to debug that. Is it possible to get the actual binary that was built there so I can interpret the backtrace? |
This comment has been minimized.
This comment has been minimized.
|
The container is destroyed, you could possibly stick a command in the travis.yml file to push it somewhere, other than that youd have to try and recreate the docker image travis uses. |
jbytheway
changed the title
[CR] Prevent seeing light through walls
[WIP][CR] Prevent seeing light through walls
Nov 8, 2018
jbytheway
force-pushed the
jbytheway:no_light_through_walls
branch
4 times, most recently
from
87fecfb
to
cdb27a2
Nov 8, 2018
jbytheway
changed the title
[WIP][CR] Prevent seeing light through walls
[CR] Prevent seeing light through walls
Nov 10, 2018
This comment has been minimized.
This comment has been minimized.
|
OK, after some investigation it seems my test refactoring had exposed some flakiness in other tests. All the failures I've observed should be fixed now. The current test failures are the same vehicle power ones that are failing everywhere. |
jbytheway commentedNov 1, 2018
•
edited
Summary
SUMMARY: Interface "Prevent seeing light through walls"
Purpose of change
There's a long-standing issue where walls that are lit from one side appear bright from the other side. This is strange and unintuitive.
I have a proof-of-concept solution, and wanted to share it for feedback before spending the time to polish it.
Describe the solution
First some pictures.



Before:
After:
Works with vehicle lights too:
The algorithm is fairly simple. Rather than storing a single illumination value in the light map, when a tile is opaque (like a wall) we store four values: one for each quadrant of 2D space. Each value represents the illumination from that quadrant. When computing apparent visibility, we check which other tiles adjacent to the tile in question we can see, and count only those light values corresponding to the quadrants where we can see adjacent tiles.
This works pretty well in practice, the only small annoyance I've observed is that you get a 'looking around corners' kind of effect in some cases. This can be seen in the second image above: the wall to the left of the northern door appears bright because we can also see the tile to the NE of it, and it is being lit from that direction. But that's never giving away any information the player couldn't have deduced, so I think it's fine, and it doesn't look too weird.
Fixes #13356.
Performance
No formal measurements yet, but it seems fine in "normal" situations.
There are two pieces of code to consider:
The current memory layout is rather cache-unfriendly. If performance testing dictates, it may be wise to swap the array dimensions around.
Still to do
Additional context
I'm aware there has been discussion of a new lighting algorithm (#23996). I think this change is entirely compatible with that new algorithm.