light: add cull_backfaces hack used by CalcPoints, to handle the case when a shadow-casting bmodel is obstructing the midpoint of a face.

probably should be removed and CalcPoints made more robust.
This commit is contained in:
Eric Wasylishen 2016-06-10 12:23:22 -06:00
parent 5ac054c2de
commit 412e169ef6
3 changed files with 16 additions and 7 deletions

View File

@ -42,7 +42,7 @@ extern "C" {
*/
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, plane_t *hitplane_out, const bsp2_dface_t **face_out);
qboolean DirtTrace(const vec3_t start, const vec3_t stop, const dmodel_t *self, bool cull_backfaces, vec3_t hitpoint_out, plane_t *hitplane_out, const bsp2_dface_t **face_out);
int
SampleTexture(const bsp2_dface_t *face, const bsp2_t *bsp, const vec3_t point);

View File

@ -604,7 +604,7 @@ CheckObstructed(const lightsurf_t *surf, const vec3_t offset, const vec_t us, co
vec3_t hitpoint = {0};
plane_t hitplane = {0};
if (DirtTrace(surf->midpoint, testpoint, surf->modelinfo->model, hitpoint, &hitplane, NULL)) {
if (DirtTrace(surf->midpoint, testpoint, surf->modelinfo->model, true, hitpoint, &hitplane, NULL)) {
// make a corrected point
vec3_t tracedir;
@ -1869,7 +1869,7 @@ DirtForSample(const dmodel_t *model, const vec3_t origin, const vec3_t normal){
VectorMA( origin, dirtDepth.value, direction, traceEnd );
/* trace */
if (DirtTrace(origin, traceEnd, model, traceHitpoint, NULL, NULL)) {
if (DirtTrace(origin, traceEnd, model, false, traceHitpoint, NULL, NULL)) {
VectorSubtract( traceHitpoint, origin, displacement );
gatherDirt += 1.0f - ooDepth * VectorLength( displacement );
}
@ -1886,7 +1886,7 @@ DirtForSample(const dmodel_t *model, const vec3_t origin, const vec3_t normal){
VectorMA( origin, dirtDepth.value, direction, traceEnd );
/* trace */
if (DirtTrace(origin, traceEnd, model, traceHitpoint, NULL, NULL)) {
if (DirtTrace(origin, traceEnd, model, false, traceHitpoint, NULL, NULL)) {
VectorSubtract( traceHitpoint, origin, displacement );
gatherDirt += 1.0f - ooDepth * VectorLength( displacement );
}
@ -1897,7 +1897,7 @@ DirtForSample(const dmodel_t *model, const vec3_t origin, const vec3_t normal){
VectorMA( origin, dirtDepth.value, normal, traceEnd );
/* trace */
if (DirtTrace(origin, traceEnd, model, traceHitpoint, NULL, NULL)) {
if (DirtTrace(origin, traceEnd, model, false, traceHitpoint, NULL, NULL)) {
VectorSubtract( traceHitpoint, origin, displacement );
gatherDirt += 1.0f - ooDepth * VectorLength( displacement );
}

View File

@ -30,6 +30,8 @@ typedef struct traceinfo_s {
vec3_t point;
const bsp2_dface_t *face;
plane_t hitplane;
bool option_cull_backface;
/* returns true if sky was hit. */
bool hitsky;
bool hitback;
@ -653,13 +655,18 @@ TestSky(const vec3_t start, const vec3_t dirn, const dmodel_t *self)
*
* returns true if the trace from start to stop hits something solid,
* or if it started in the void.
*
* cull_backfaces is a hack used by CalcPoints, to handle the case when a
* shadow-casting bmodel is obstructing the midpoint of a face.
* probably should be removed and CalcPoints made more robust.
* ============
*/
qboolean
DirtTrace(const vec3_t start, const vec3_t stop, const dmodel_t *self, vec3_t hitpoint_out, plane_t *hitplane_out, const bsp2_dface_t **face_out)
DirtTrace(const vec3_t start, const vec3_t stop, const dmodel_t *self, bool cull_backfaces, vec3_t hitpoint_out, plane_t *hitplane_out, const bsp2_dface_t **face_out)
{
const modelinfo_t *const *model;
traceinfo_t ti = {0};
ti.option_cull_backface = cull_backfaces;
VectorSubtract(stop, start, ti.dir);
VectorNormalize(ti.dir);
@ -769,7 +776,9 @@ bool TraceFaces (traceinfo_t *ti, int node, const vec3_t start, const vec3_t end
// check if we hit the back side
ti->hitback = (DotProduct(ti->dir, fi->plane.normal) >= 0);
return true;
if (!(ti->option_cull_backface && ti->hitback)) {
return true;
}
}
}