From 4021c0685251b37d81604512eb99a224d49622f4 Mon Sep 17 00:00:00 2001 From: Kevin Shanahan Date: Thu, 4 Apr 2013 14:30:09 +1030 Subject: [PATCH 1/4] build: fix ghetto unix2dos conversion to work on msys The only thing that seems to be able to convert \n to \r\n is awk, so use that everywhere. I don't understand why, but echoing the verbose command on OSX echos a literal \r and messes up the output. Adding an extra \ escape fixes it there, but then Linux/Msys echo the extra \... I think the OSX behaviour might be broken here, oh well... Signed-off-by: Kevin Shanahan --- Makefile | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 457ba2b9..60ccc6c4 100644 --- a/Makefile +++ b/Makefile @@ -207,19 +207,21 @@ define do_man2man @$(cmd_man2man); endef -# The sed magic is a little ugly, but I wanted something that would work -# across Linux/BSD/Msys/Darwin +# The sed/awk magic is a little ugly, but I wanted something that +# would work across Linux/BSD/Msys/Darwin quiet_cmd_man2txt = ' MAN2TXT $@' cmd_man2txt = \ $(GROFF) -man -Tascii $< | cat -v | \ sed -e 's/\^\[\[\([0-9]\)\{1,2\}[a-z]//g' \ - -e 's/.\^H//g' \ - -e 's/$$/'`printf \\\r`'/' > $(@D)/.$(@F).tmp && \ + -e 's/.\^H//g' | \ + awk '{ gsub("$$", "\r"); print $$0;}' - > $(@D)/.$(@F).tmp && \ mv $(@D)/.$(@F).tmp $@ + loud_cmd_man2txt = \ + $(subst ",\",$(subst $$,\$$,$(subst "\r","\\r",$(cmd_man2txt)))) define do_man2txt @$(do_mkdir) - @echo $(if $(quiet),$(quiet_cmd_man2txt),"$(cmd_man2txt)"); + @echo $(if $(quiet),$(quiet_cmd_man2txt),"$(loud_cmd_man2txt)"); @$(cmd_man2txt); endef From 4625245b0931667676f9e2884e07d7197143d673 Mon Sep 17 00:00:00 2001 From: Kevin Shanahan Date: Thu, 4 Apr 2013 15:51:18 +1030 Subject: [PATCH 2/4] light: implement the -addmin command line parameter Makes minlight additive rather than just bringing low levels up to the minimum. Not entirely identical to the bjp implementation as it seems to treat local minlights in some strange ways, but in most cases the behaviour should be identical. Added missing help text for -anglescale|-anglesense parameters too. Signed-off-by: Kevin Shanahan --- changelog.txt | 1 + include/light/light.h | 1 + light/light.c | 6 +++++- light/ltface.c | 22 ++++++++++++++++------ man/light.1 | 9 +++++++-- 5 files changed, 30 insertions(+), 9 deletions(-) diff --git a/changelog.txt b/changelog.txt index 39081da4..8b0a72e6 100644 --- a/changelog.txt +++ b/changelog.txt @@ -9,6 +9,7 @@ Unreleased * qbsp: added hintskip texture support * light: implemented self shadowing and full shadows for brush models * light: implemented the "-soft" command line option +* light: implemented the "-addmin" command line option * light: implemented the "_anglescale" (aka "_anglesense") key and cmdline * light: remove support for negative color components (never worked properly) * light: removed the "-nominlimit" option (now the default behaviour) diff --git a/include/light/light.h b/include/light/light.h index fba01641..156c4573 100644 --- a/include/light/light.h +++ b/include/light/light.h @@ -101,6 +101,7 @@ extern float fadegate; extern int softsamples; extern const vec3_t vec3_white; +extern qboolean addminlight; extern lightsample_t minlight; extern lightsample_t sunlight; extern vec3_t sunvec; diff --git a/light/light.c b/light/light.c index 9abee52b..69e07f7d 100644 --- a/light/light.c +++ b/light/light.c @@ -30,6 +30,7 @@ float fadegate = EQUAL_EPSILON; int softsamples = 0; const vec3_t vec3_white = { 255, 255, 255 }; +qboolean addminlight = false; lightsample_t minlight = { 0, { 255, 255, 255 } }; lightsample_t sunlight = { 0, { 255, 255, 255 } }; vec3_t sunvec = { 0, 0, 16384 }; /* defaults to straight down */ @@ -244,6 +245,8 @@ main(int argc, const char **argv) fadegate = atof(argv[++i]); } else if (!strcmp(argv[i], "-light")) { minlight.light = atof(argv[++i]); + } else if (!strcmp(argv[i], "-addmin")) { + addminlight = true; } else if (!strcmp(argv[i], "-lit")) { colored = true; } else if (!strcmp(argv[i], "-soft")) { @@ -263,7 +266,8 @@ main(int argc, const char **argv) } if (i != argc - 1) { - printf("usage: light [-threads num] [-light num] [-extra|-extra4]\n" + printf("usage: light [-threads num] [-extra|-extra4]\n" + " [-light num] [-addmin] [-anglescale|-anglesense]\n" " [-dist n] [-range n] [-gate n] [-lit]\n" " [-soft [n]] bspfile\n"); exit(1); diff --git a/light/ltface.c b/light/ltface.c index 7f772a2a..8a40f78e 100644 --- a/light/ltface.c +++ b/light/ltface.c @@ -748,12 +748,16 @@ FixMinlight(const lightsample_t *minlight, const lightsurf_t *lightsurf, sample = lightmaps[mapnum].samples; for (i = 0; i < lightsurf->numpoints; i++, sample++) { - if (sample->light < minlight->light) + if (addminlight) + sample->light += minlight->light; + else if (sample->light < minlight->light) sample->light = minlight->light; if (colored) { for (j = 0; j < 3; j++) { vec_t lightval = minlight->light * minlight->color[j] / 255.0f; - if (sample->color[j] < lightval) + if (addminlight) + sample->color[j] += lightval; + else if (sample->color[j] < lightval) sample->color[j] = lightval; } } @@ -769,22 +773,28 @@ FixMinlight(const lightsample_t *minlight, const lightsurf_t *lightsurf, surfpoint = lightsurf->points[0]; for (j = 0; j < lightsurf->numpoints; j++, sample++, surfpoint += 3) { qboolean trace = false; - if (sample->light < entity->light.light) { + if (addminlight || sample->light < entity->light.light) { trace = TestLight(entity->origin, surfpoint, shadowself); if (!trace) continue; - sample->light = entity->light.light; + if (addminlight) + sample->light += entity->light.light; + else + sample->light = entity->light.light; } if (!colored) continue; for (k = 0; k < 3; k++) { - if (sample->color[k] < entity->light.color[k]) { + if (addminlight || sample->color[k] < entity->light.color[k]) { if (!trace) { trace = TestLight(entity->origin, surfpoint, shadowself); if (!trace) break; } - sample->color[k] = entity->light.color[k]; + if (addminlight) + sample->color[k] += entity->light.color[k]; + else + sample->color[k] = entity->light.color[k]; } } } diff --git a/man/light.1 b/man/light.1 index 4868577e..0f2993ec 100644 --- a/man/light.1 +++ b/man/light.1 @@ -25,8 +25,13 @@ Calculate extra samples (2x2) and average the results for smoother shadows. Calculate even more samples (4x4) and average the results for smoother shadows. .IP "\fB\-light n\fP" -Set a global minimum light level. Overrides default light level set in -worldspawn. +Set a global minimum light level for style 0 (default) +lightmaps. Overrides default light level set in worldspawn. +.IP "\fB\-addmin\fP" +Changes the behaviour of \fIminlight\fP. Instead of increasing low +light levels to the global minimum, add the global minimum light level +to all style 0 lightmaps. This may help reducing the sometimes +uniform minlight effect. .IP "\fB\-dist n\fP" Scales the fade distance of all lights by a factor of n. If n > 1 lights fade more quickly with distance and if n < 1, lights fade more slowly with distance From ee2dc38f71d0b9163e3390bb689b6035f9706b5b Mon Sep 17 00:00:00 2001 From: Kevin Shanahan Date: Sat, 6 Apr 2013 08:35:38 +1030 Subject: [PATCH 3/4] light: make command line set sun anglescale as well Signed-off-by: Kevin Shanahan --- light/light.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/light/light.c b/light/light.c index 69e07f7d..a05270e2 100644 --- a/light/light.c +++ b/light/light.c @@ -256,7 +256,7 @@ main(int argc, const char **argv) softsamples = -1; /* auto, based on oversampling */ } else if (!strcmp(argv[i], "-anglescale") || !strcmp(argv[i], "-anglesense")) { if (i < argc - 2 && isdigit(argv[i + 1][0])) - anglescale = atoi(argv[++i]); + anglescale = sun_anglescale = atoi(argv[++i]); else Error("-anglesense requires a numeric argument (0.0 - 1.0)"); } else if (argv[i][0] == '-') From c193c18d5b6368d52e29288e2ac63dad280317c5 Mon Sep 17 00:00:00 2001 From: Kevin Shanahan Date: Sat, 6 Apr 2013 13:25:11 +1030 Subject: [PATCH 4/4] make -gate affect linear falloff lights as well Signed-off-by: Kevin Shanahan --- changelog.txt | 1 + light/entities.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/changelog.txt b/changelog.txt index 8b0a72e6..b728fbe7 100644 --- a/changelog.txt +++ b/changelog.txt @@ -14,6 +14,7 @@ Unreleased * light: remove support for negative color components (never worked properly) * light: removed the "-nominlimit" option (now the default behaviour) * light: removed the "-compress" option (a bad idea from long ago) +* light: make -gate command line affect linear falloff lights as well * vis: changed the default testlevel to 4 * vis: added the '-noambient*' options to disable auto ambient sounds. diff --git a/light/entities.c b/light/entities.c index 1cd0e9d4..1e6bd33e 100644 --- a/light/entities.c +++ b/light/entities.c @@ -198,7 +198,8 @@ CheckEntityFields(entity_t *entity) if (entity->formula == LF_LINEAR) { /* Linear formula always has a falloff point */ - entity->fadedist = fabs(entity->light.light / entity->atten / scaledist); + entity->fadedist = fabs(entity->light.light) - fadegate; + entity->fadedist = entity->fadedist / entity->atten / scaledist; } else if (fadegate < EQUAL_EPSILON) { /* If fadegate is tiny, other lights have effectively infinite reach */ entity->fadedist = VECT_MAX;