From f220b2f531425d55f6b8ffbc1c69694b228ecef3 Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Wed, 9 Oct 2019 00:47:39 -0600 Subject: [PATCH] light: support "_suntexture" key on "_sun" "1" entities to limit them to being cast from a specific sky texture. Fixes #110 --- include/light/entities.hh | 6 ++++-- include/light/light.hh | 1 + light/entities.cc | 21 +++++++++++---------- light/ltface.cc | 12 +++++++++++- man/light.1 | 3 +++ 5 files changed, 30 insertions(+), 13 deletions(-) diff --git a/include/light/entities.hh b/include/light/entities.hh index 6c8df0cb..0dd63ec6 100644 --- a/include/light/entities.hh +++ b/include/light/entities.hh @@ -80,6 +80,7 @@ public: lockable_bool_t bleed; lockable_vec3_t origin, color, mangle, projangle; lockable_string_t project_texture; + lockable_string_t suntexture; light_formula_t getFormula() const { return static_cast(formula.intValue()); } @@ -120,7 +121,8 @@ public: color { "color", 255.0f, 255.0f, 255.0f, vec3_transformer_t::NORMALIZE_COLOR_TO_255 }, mangle { "mangle", 0, 0, 0 }, // not transformed to vec projangle { "project_mangle", 20, 0, 0 }, // not transformed to vec - project_texture { "project_texture", "" } + project_texture { "project_texture", "" }, + suntexture { "suntexture", "" } { VectorSet(spotvec, 0, 0, 0); @@ -136,7 +138,7 @@ public: &dirt_off_radius, &dirt_on_radius, &sun, //mxd &falloff, //mxd - &origin, &color, &mangle, &projangle, &project_texture + &origin, &color, &mangle, &projangle, &project_texture, &suntexture }}; } diff --git a/include/light/light.hh b/include/light/light.hh index 9e34fe7d..d64ba698 100644 --- a/include/light/light.hh +++ b/include/light/light.hh @@ -72,6 +72,7 @@ public: qboolean dirt; float anglescale; int style; + std::string suntexture; }; /* for vanilla this would be 18. some engines allow higher limits though, which will be needed if we're scaling lightmap resolution. */ diff --git a/light/entities.cc b/light/entities.cc index 8ddd325a..d5979436 100644 --- a/light/entities.cc +++ b/light/entities.cc @@ -402,7 +402,7 @@ Dirt_ResolveFlag(const globalconfig_t &cfg, int dirtInt) * ============= */ static void -AddSun(const globalconfig_t &cfg, vec3_t sunvec, vec_t light, const vec3_t color, int dirtInt, float sun_anglescale, const int style) +AddSun(const globalconfig_t &cfg, vec3_t sunvec, vec_t light, const vec3_t color, int dirtInt, float sun_anglescale, const int style, const std::string& suntexture) { if (light == 0.0f) return; @@ -416,6 +416,7 @@ AddSun(const globalconfig_t &cfg, vec3_t sunvec, vec_t light, const vec3_t color sun.anglescale = sun_anglescale; sun.dirt = Dirt_ResolveFlag(cfg, dirtInt); sun.style = style; + sun.suntexture = suntexture; // add to list all_suns.push_back(sun); @@ -440,7 +441,7 @@ AddSun(const globalconfig_t &cfg, vec3_t sunvec, vec_t light, const vec3_t color */ static void SetupSun(const globalconfig_t &cfg, vec_t light, const vec3_t color, const vec3_t sunvec_in, const float sun_anglescale, const float sun_deviance, const int sunlight_dirt, - const int style) + const int style, const std::string& suntexture) { vec3_t sunvec; int i; @@ -489,7 +490,7 @@ SetupSun(const globalconfig_t &cfg, vec_t light, const vec3_t color, const vec3_ //printf( "sun %d is using vector %f %f %f\n", i, direction[0], direction[1], direction[2]); - AddSun(cfg, direction, light, color, sunlight_dirt, sun_anglescale, style); + AddSun(cfg, direction, light, color, sunlight_dirt, sun_anglescale, style, suntexture); } } @@ -514,18 +515,18 @@ SetupSuns(const globalconfig_t &cfg) } // Add the sun - SetupSun(cfg, entity.light.floatValue(), *entity.color.vec3Value(), sunvec, entity.anglescale.floatValue(), entity.deviance.floatValue(), entity.dirt.intValue(), entity.style.intValue()); + SetupSun(cfg, entity.light.floatValue(), *entity.color.vec3Value(), sunvec, entity.anglescale.floatValue(), entity.deviance.floatValue(), entity.dirt.intValue(), entity.style.intValue(), entity.suntexture.stringValue()); // Disable the light itself... entity.light.setFloatValue(0.0f); } } - SetupSun(cfg, cfg.sunlight.floatValue(), *cfg.sunlight_color.vec3Value(), *cfg.sunvec.vec3Value(), cfg.global_anglescale.floatValue(), cfg.sun_deviance.floatValue(), cfg.sunlight_dirt.intValue(), 0); + SetupSun(cfg, cfg.sunlight.floatValue(), *cfg.sunlight_color.vec3Value(), *cfg.sunvec.vec3Value(), cfg.global_anglescale.floatValue(), cfg.sun_deviance.floatValue(), cfg.sunlight_dirt.intValue(), 0, ""); if (cfg.sun2.floatValue() != 0) { logprint("creating sun2\n"); - SetupSun(cfg, cfg.sun2.floatValue(), *cfg.sun2_color.vec3Value(), *cfg.sun2vec.vec3Value(), cfg.global_anglescale.floatValue(), cfg.sun_deviance.floatValue(), cfg.sunlight_dirt.intValue(), 0); + SetupSun(cfg, cfg.sun2.floatValue(), *cfg.sun2_color.vec3Value(), *cfg.sun2vec.vec3Value(), cfg.global_anglescale.floatValue(), cfg.sun_deviance.floatValue(), cfg.sunlight_dirt.intValue(), 0, ""); } } @@ -591,14 +592,14 @@ SetupSkyDome(const globalconfig_t &cfg) /* insert top hemisphere light */ if (sunlight2value > 0) { - AddSun(cfg, direction, sunlight2value, *cfg.sunlight2_color.vec3Value(), cfg.sunlight2_dirt.intValue(), cfg.global_anglescale.floatValue(), 0); + AddSun(cfg, direction, sunlight2value, *cfg.sunlight2_color.vec3Value(), cfg.sunlight2_dirt.intValue(), cfg.global_anglescale.floatValue(), 0, ""); } direction[ 2 ] = -direction[ 2 ]; /* insert bottom hemisphere light */ if (sunlight3value > 0) { - AddSun(cfg, direction, sunlight3value, *cfg.sunlight3_color.vec3Value(), cfg.sunlight2_dirt.intValue(), cfg.global_anglescale.floatValue(), 0); + AddSun(cfg, direction, sunlight3value, *cfg.sunlight3_color.vec3Value(), cfg.sunlight2_dirt.intValue(), cfg.global_anglescale.floatValue(), 0, ""); } /* move */ @@ -614,13 +615,13 @@ SetupSkyDome(const globalconfig_t &cfg) VectorSet( direction, 0.0f, 0.0f, -1.0f ); if (sunlight2value > 0) { - AddSun(cfg, direction, sunlight2value, *cfg.sunlight2_color.vec3Value(), cfg.sunlight2_dirt.intValue(), cfg.global_anglescale.floatValue(), 0); + AddSun(cfg, direction, sunlight2value, *cfg.sunlight2_color.vec3Value(), cfg.sunlight2_dirt.intValue(), cfg.global_anglescale.floatValue(), 0, ""); } VectorSet( direction, 0.0f, 0.0f, 1.0f ); if (sunlight3value > 0) { - AddSun(cfg, direction, sunlight3value, *cfg.sunlight3_color.vec3Value(), cfg.sunlight2_dirt.intValue(), cfg.global_anglescale.floatValue(), 0); + AddSun(cfg, direction, sunlight3value, *cfg.sunlight3_color.vec3Value(), cfg.sunlight2_dirt.intValue(), cfg.global_anglescale.floatValue(), 0, ""); } } diff --git a/light/ltface.cc b/light/ltface.cc index 4e0d4023..504c43b2 100644 --- a/light/ltface.cc +++ b/light/ltface.cc @@ -1597,7 +1597,17 @@ LightFace_Sky(const sun_t *sun, const lightsurf_t *lightsurf, lightmapdict_t *li if (rs->getPushedRayHitType(j) != hittype_t::SKY) { continue; } - + + // check if we hit the wrong texture + // TODO: this could be faster! + if (!sun->suntexture.empty()) { + const bsp2_dface_t *face = rs->getPushedRayHitFace(j); + const char* facetex = Face_TextureName(lightsurf->bsp, face); + if (sun->suntexture != facetex) { + continue; + } + } + const int i = rs->getPushedRayPointIndex(j); // check if we hit a dynamic shadow caster diff --git a/man/light.1 b/man/light.1 index 0cecba3b..9102fc51 100644 --- a/man/light.1 +++ b/man/light.1 @@ -431,6 +431,9 @@ The following light properties correspond to these sunlight settings: _color => _sunlight_color _dirt => _sunlight_dirt _anglescale => _anglescale + style => flicker style for styled sunlight + targetname => targetname for switchable sunlight + _suntexture => this sunlight is only emitted from faces with this texture name .fi .SH "OTHER INFORMATION"