From b6c9873289968bf51989f3fefb86e5ceef8b6aaa Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Sun, 10 Apr 2016 15:27:21 -0600 Subject: [PATCH] light: return hit normal for DirtTrace --- include/light/light.h | 3 ++- light/ltface.c | 17 ++++++++++++----- light/trace.c | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/include/light/light.h b/include/light/light.h index 1960d530..d2afb429 100644 --- a/include/light/light.h +++ b/include/light/light.h @@ -45,6 +45,7 @@ extern "C" { typedef struct traceinfo_s { vec3_t point; const bsp2_dface_t *face; + vec3_t hitnormal; /* returns true if sky was hit. */ bool hitsky; bool hitback; @@ -99,7 +100,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); +qboolean DirtTrace(const vec3_t start, const vec3_t stop, const dmodel_t *self, vec3_t hitpoint_out, vec3_t hitnormal_out); typedef struct { vec_t light; diff --git a/light/ltface.c b/light/ltface.c index 5a246b7e..d2cac3f6 100644 --- a/light/ltface.c +++ b/light/ltface.c @@ -594,7 +594,8 @@ CheckObstructed(const lightsurf_t *surf, const vec3_t offset, const vec_t us, co VectorAdd(testpoint, offset, testpoint); vec3_t hitpoint = {0}; - if (DirtTrace(surf->midpoint, testpoint, surf->modelinfo->model, hitpoint)) { + vec3_t hitnormal = {0}; + if (DirtTrace(surf->midpoint, testpoint, surf->modelinfo->model, hitpoint, hitnormal)) { // make a corrected point vec3_t tracedir; @@ -1440,7 +1441,7 @@ void SetupDirt( void ) { * ============ */ qboolean -DirtTrace(const vec3_t start, const vec3_t stop, const dmodel_t *self, vec3_t hitpoint_out) +DirtTrace(const vec3_t start, const vec3_t stop, const dmodel_t *self, vec3_t hitpoint_out, vec3_t hitnormal_out) { const modelinfo_t *const *model; traceinfo_t ti = {0}; @@ -1451,6 +1452,9 @@ 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); + } return !ti.hitsky; } } @@ -1461,6 +1465,9 @@ 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); + } return !ti.hitsky; } } @@ -1526,7 +1533,7 @@ DirtForSample(const dmodel_t *model, const vec3_t origin, const vec3_t normal){ VectorMA( origin, dirtDepth, direction, traceEnd ); /* trace */ - if (DirtTrace(origin, traceEnd, model, traceHitpoint)) { + if (DirtTrace(origin, traceEnd, model, traceHitpoint, NULL)) { VectorSubtract( traceHitpoint, origin, displacement ); gatherDirt += 1.0f - ooDepth * VectorLength( displacement ); } @@ -1543,7 +1550,7 @@ DirtForSample(const dmodel_t *model, const vec3_t origin, const vec3_t normal){ VectorMA( origin, dirtDepth, direction, traceEnd ); /* trace */ - if (DirtTrace(origin, traceEnd, model, traceHitpoint)) { + if (DirtTrace(origin, traceEnd, model, traceHitpoint, NULL)) { VectorSubtract( traceHitpoint, origin, displacement ); gatherDirt += 1.0f - ooDepth * VectorLength( displacement ); } @@ -1554,7 +1561,7 @@ DirtForSample(const dmodel_t *model, const vec3_t origin, const vec3_t normal){ VectorMA( origin, dirtDepth, normal, traceEnd ); /* trace */ - if (DirtTrace(origin, traceEnd, model, traceHitpoint)) { + if (DirtTrace(origin, traceEnd, model, traceHitpoint, NULL)) { VectorSubtract( traceHitpoint, origin, displacement ); gatherDirt += 1.0f - ooDepth * VectorLength( displacement ); } diff --git a/light/trace.c b/light/trace.c index 42227bb6..2eec8362 100644 --- a/light/trace.c +++ b/light/trace.c @@ -612,7 +612,7 @@ 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); // check if we hit the back side ti->hitback = (DotProduct(ti->dir, fi->plane.normal) >= 0);