Lighting is working way better and now for world generation work.

This commit is contained in:
Zed A. Shaw 2024-12-28 12:04:21 -05:00
parent 9c03e850b5
commit 194cc6664b
8 changed files with 57 additions and 63 deletions

View file

@ -8,6 +8,9 @@ namespace lighting {
void LightRender::render_square_light(LightSource source, Point at, PointList &has_light) {
for(matrix::in_box it{$lightmap, at.x, at.y, (size_t)floor(source.radius)}; it.next();) {
if($paths.$paths[it.y][it.x] != WALL_PATH_LIMIT) {
if(it.x == at.x && it.y == at.y) {
println("distance at center: {}", it.distance());
}
$lightmap[it.y][it.x] = light_level(source.strength, it.distance(), it.x, it.y);
has_light.push_back({it.x, it.y});
}
@ -33,10 +36,10 @@ namespace lighting {
}
}
int LightRender::light_level(int level, float distance, size_t x, size_t y) {
size_t at = level + ceil(distance);
int LightRender::light_level(int strength, float distance, size_t x, size_t y) {
int cur_level = $lightmap[y][x];
int new_level = at < lighting::LEVELS.size() ? lighting::LEVELS[at] : lighting::MIN;
int new_level = strength / sqrt(distance + 0.6f);
return cur_level < new_level ? new_level : cur_level;
}