From d2ecc73db3087ba79e350c4ccdb3c50343b30169 Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Tue, 8 Oct 2019 23:43:22 -0600 Subject: [PATCH] light: support "style" / "targetname" on "_sun" "1" entities. Fixes #253 --- include/light/light.hh | 5 ++++- light/entities.cc | 23 +++++++++++++---------- light/ltface.cc | 14 +++++++++----- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/include/light/light.hh b/include/light/light.hh index 80934f6a..9e34fe7d 100644 --- a/include/light/light.hh +++ b/include/light/light.hh @@ -61,14 +61,17 @@ static inline float LightSample_Brightness(const qvec3f color) { return ((color[0] + color[1] + color[2]) / 3.0); } +/** + * A directional light, emitted from "sky*" textured faces. + */ class sun_t { public: vec3_t sunvec; vec_t sunlight; vec3_t sunlight_color; - struct sun_s *next; qboolean dirt; float anglescale; + int style; }; /* 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 0a700101..8ddd325a 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) +AddSun(const globalconfig_t &cfg, vec3_t sunvec, vec_t light, const vec3_t color, int dirtInt, float sun_anglescale, const int style) { if (light == 0.0f) return; @@ -415,6 +415,7 @@ AddSun(const globalconfig_t &cfg, vec3_t sunvec, vec_t light, const vec3_t color VectorCopy(color, sun.sunlight_color); sun.anglescale = sun_anglescale; sun.dirt = Dirt_ResolveFlag(cfg, dirtInt); + sun.style = style; // add to list all_suns.push_back(sun); @@ -438,7 +439,8 @@ 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) +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) { vec3_t sunvec; int i; @@ -487,7 +489,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); + AddSun(cfg, direction, light, color, sunlight_dirt, sun_anglescale, style); } } @@ -512,18 +514,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()); + SetupSun(cfg, entity.light.floatValue(), *entity.color.vec3Value(), sunvec, entity.anglescale.floatValue(), entity.deviance.floatValue(), entity.dirt.intValue(), entity.style.intValue()); // 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()); + 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()); + 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); } } @@ -589,14 +591,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()); + 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()); + AddSun(cfg, direction, sunlight3value, *cfg.sunlight3_color.vec3Value(), cfg.sunlight2_dirt.intValue(), cfg.global_anglescale.floatValue(), 0); } /* move */ @@ -612,13 +614,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()); + 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()); + AddSun(cfg, direction, sunlight3value, *cfg.sunlight3_color.vec3Value(), cfg.sunlight2_dirt.intValue(), cfg.global_anglescale.floatValue(), 0); } } @@ -1047,6 +1049,7 @@ LoadEntities(const globalconfig_t &cfg, const mbsp_t *bsp) } // setup light styles for switchable lights + // NOTE: this also handles "_sun" "1" entities without any extra work. std::string classname = EntDict_StringForKey(entdict, "classname"); if (classname.find("light") == 0) { const std::string targetname = EntDict_StringForKey(entdict, "targetname"); diff --git a/light/ltface.cc b/light/ltface.cc index 6ec38c12..4e0d4023 100644 --- a/light/ltface.cc +++ b/light/ltface.cc @@ -1383,7 +1383,11 @@ GetDirectLighting(const globalconfig_t &cfg, raystream_t *rs, const vec3_t origi } for (const sun_t &sun : GetSuns()) { - + // Skip styled lights if "bouncestyled" setting is off. + if (sun.style != 0 && !cfg.bouncestyled.boolValue()) { + continue; + } + // NOTE: Skip negative lights, which would make no sense to bounce! if (sun.sunlight < 0) continue; @@ -1409,9 +1413,8 @@ GetDirectLighting(const globalconfig_t &cfg, raystream_t *rs, const vec3_t origi dirt = Dirt_GetScaleFactor(cfg, occlusion, nullptr, 0.0, /* FIXME: pass */ nullptr); } - const int sunstyle = 0; const qvec3f sunContrib = vec3_t_to_glm(sun.sunlight_color) * (dirt * cosangle * sun.sunlight / 255.0f); - result[sunstyle] += sunContrib; + result[sun.style] += sunContrib; } return result; @@ -1534,6 +1537,7 @@ LightFace_Sky(const sun_t *sun, const lightsurf_t *lightsurf, lightmapdict_t *li const plane_t *plane = &lightsurf->plane; // FIXME: Normalized sun vector should be stored in the sun_t. Also clarify which way the vector points (towards or away..) + // FIXME: Much of this is copied/pasted from LightFace_Entity, should probably be merged vec3_t incoming; VectorCopy(sun->sunvec, incoming); VectorNormalize(incoming); @@ -1585,7 +1589,7 @@ LightFace_Sky(const sun_t *sun, const lightsurf_t *lightsurf, lightmapdict_t *li rs->tracePushedRaysIntersection(); /* if sunlight is set, use a style 0 light map */ - int cached_style = 0; + int cached_style = sun->style; lightmap_t *cached_lightmap = Lightmap_ForStyle(lightmaps, cached_style, lightsurf); const int N = rs->numPushedRays(); @@ -1597,7 +1601,7 @@ LightFace_Sky(const sun_t *sun, const lightsurf_t *lightsurf, lightmapdict_t *li const int i = rs->getPushedRayPointIndex(j); // check if we hit a dynamic shadow caster - int desired_style = 0; + int desired_style = sun->style; if (rs->getPushedRayDynamicStyle(j) != 0) { desired_style = rs->getPushedRayDynamicStyle(j); }