From 9b5a2f1247208cb620a30de73ffce0a1e747f601 Mon Sep 17 00:00:00 2001 From: Elronnd Date: Sun, 29 Jul 2018 06:31:37 -0700 Subject: [PATCH] add *much nicer* brightness normalization, thanks to /u/dustyloops and /u/aotdev --- src/light.d | 5 +++-- src/myfov.d | 10 +++++++++- src/util.d | 5 ++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/light.d b/src/light.d index 67af244..e6a49ea 100644 --- a/src/light.d +++ b/src/light.d @@ -48,9 +48,10 @@ void do_colour(ref Map map, list!Being mons) { continue; } - float f = base[y][x].value / maxf; + float f1 = pow(base[y][x].value, .8) / 4.3; + float f = f1 / (f1+1); //smaxf; // map[y, x].bgcolour = RGBColour(pow(f/2, 1.5), pow(f/1.4, 3), pow(f/16, 2)); - map[y, x].bgcolour = RGBColour(f, f, f); + map[y, x].bgcolour = RGBColour(f*1.1, f, f/9); //writefln("Set bg to %s", map[y, x].bgcolour); } } diff --git a/src/myfov.d b/src/myfov.d index 1e053f7..c5214f3 100644 --- a/src/myfov.d +++ b/src/myfov.d @@ -62,7 +62,15 @@ private void compute(const ref Map map, ref Lightmap lightmap, int octant, Point default: break; } lightmap[ny, nx].visible = true; - lightmap[ny, nx].visibility = 1 - dist(nx, ny, origin.x, origin.y) / sqrt(rangeLimit); + float vis_sq = dist_sq(nx, ny, origin.x, origin.y); + float f3 = sqrt(rangeLimit) / (vis_sq); + //float f3 = f1 / (f1 + 5); + /* + float f1 = 1. / (1. + vis_sq/40.); + float f2 = f1 - 1. / (1. + rangeLimit); + float f3 = f2 / (1. - 1. / (1. + rangeLimit)); + */ + lightmap[ny, nx].visibility = f3; //1 - dist(nx, ny, origin.x, origin.y) / sqrt(rangeLimit); // this makes conentric squares. Probably faster //lightmap[ny, nx].visibility = 1 - cast(float)max(abs(nx - origin.x), abs(ny - origin.y)) / 32.; } diff --git a/src/util.d b/src/util.d index 84aead0..f7eb432 100644 --- a/src/util.d +++ b/src/util.d @@ -101,9 +101,12 @@ alias get256colour = memoize!((RGBColour colour) { }); float dist(int x1, int y1, int x2, int y2) { + return sqrt(dist_sq(x1, y1, x2, y2)); +} +int dist_sq(int x1, int y1, int x2, int y2) { int px = x1 - x2; int py = y1 - y2; - return sqrt(cast(float)px * px + py * py); + return px * px + py * py; } -- 2.11.4.GIT