From cf8e3fc935cc9187137dfc04ec4cfe7dddad2d3d Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Sun, 10 Apr 2016 22:29:59 -0600 Subject: [PATCH] light: augment DirtTrace with the hit plane --- include/light/light.h | 13 ++++++------- light/ltface.c | 14 +++++++------- light/trace.c | 4 +++- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/include/light/light.h b/include/light/light.h index 7221d3c2..7b3bf262 100644 --- a/include/light/light.h +++ b/include/light/light.h @@ -41,11 +41,15 @@ extern "C" { #define TRACE_HIT_LAVA (1 << 3) #define TRACE_HIT_SKY (1 << 4) +typedef struct { + vec3_t normal; + vec_t dist; +} plane_t; typedef struct traceinfo_s { vec3_t point; const bsp2_dface_t *face; - vec3_t hitnormal; + plane_t hitplane; /* returns true if sky was hit. */ bool hitsky; bool hitback; @@ -100,7 +104,7 @@ int TraceLine(const dmodel_t *model, const int traceflags, */ qboolean TestSky(const vec3_t start, const vec3_t dirn, const dmodel_t *self); qboolean TestLight(const vec3_t start, const vec3_t stop, const dmodel_t *self); -qboolean DirtTrace(const vec3_t start, const vec3_t stop, const dmodel_t *self, vec3_t hitpoint_out, vec3_t hitnormal_out); +qboolean DirtTrace(const vec3_t start, const vec3_t stop, const dmodel_t *self, vec3_t hitpoint_out, plane_t *hitplane_out); typedef struct { vec_t light; @@ -126,11 +130,6 @@ typedef struct sun_s { float anglescale; } sun_t; -typedef struct { - vec3_t normal; - vec_t dist; -} plane_t; - /* for vanilla this would be 18. some engines allow higher limits though, which will be needed if we're scaling lightmap resolution. */ /*with extra sampling, lit+lux etc, we need at least 46mb stack space per thread. yes, that's a lot. on the plus side, it doesn't affect bsp complexity (actually, can simplify it a little)*/ #define MAXDIMENSION (255+1) diff --git a/light/ltface.c b/light/ltface.c index 15ded1d9..c0333dfd 100644 --- a/light/ltface.c +++ b/light/ltface.c @@ -594,8 +594,8 @@ CheckObstructed(const lightsurf_t *surf, const vec3_t offset, const vec_t us, co VectorAdd(testpoint, offset, testpoint); vec3_t hitpoint = {0}; - vec3_t hitnormal = {0}; - if (DirtTrace(surf->midpoint, testpoint, surf->modelinfo->model, hitpoint, hitnormal)) { + plane_t hitplane = {0}; + if (DirtTrace(surf->midpoint, testpoint, surf->modelinfo->model, hitpoint, &hitplane)) { // make a corrected point vec3_t tracedir; @@ -1442,7 +1442,7 @@ void SetupDirt( void ) { * ============ */ qboolean -DirtTrace(const vec3_t start, const vec3_t stop, const dmodel_t *self, vec3_t hitpoint_out, vec3_t hitnormal_out) +DirtTrace(const vec3_t start, const vec3_t stop, const dmodel_t *self, vec3_t hitpoint_out, plane_t *hitplane_out) { const modelinfo_t *const *model; traceinfo_t ti = {0}; @@ -1453,8 +1453,8 @@ DirtTrace(const vec3_t start, const vec3_t stop, const dmodel_t *self, vec3_t hi if (self) { if (TraceFaces (&ti, self->headnode[0], start, stop)) { VectorCopy(ti.point, hitpoint_out); - if (hitnormal_out) { - VectorCopy(ti.hitnormal, hitnormal_out); + if (hitplane_out) { + *hitplane_out = ti.hitplane; } return !ti.hitsky; } @@ -1466,8 +1466,8 @@ DirtTrace(const vec3_t start, const vec3_t stop, const dmodel_t *self, vec3_t hi continue; if (TraceFaces (&ti, (*model)->model->headnode[0], start, stop)) { VectorCopy(ti.point, hitpoint_out); - if (hitnormal_out) { - VectorCopy(ti.hitnormal, hitnormal_out); + if (hitplane_out) { + *hitplane_out = ti.hitplane; } return !ti.hitsky; } diff --git a/light/trace.c b/light/trace.c index 439d832d..a4d8fb48 100644 --- a/light/trace.c +++ b/light/trace.c @@ -615,7 +615,9 @@ bool TraceFaces (traceinfo_t *ti, int node, const vec3_t start, const vec3_t end if (fi->content == CONTENTS_SOLID || fi->content == CONTENTS_SKY) { ti->face = face; ti->hitsky = (fi->content == CONTENTS_SKY); - VectorCopy(fi->plane.normal, ti->hitnormal); + VectorCopy(fi->plane.normal, ti->hitplane.normal); + ti->hitplane.dist = fi->plane.dist; + // check if we hit the back side ti->hitback = (DotProduct(ti->dir, fi->plane.normal) >= 0);