light: DirtTrace: return hitdist instead of hitpoint
This commit is contained in:
parent
1d3774a9e0
commit
913d6f068c
|
|
@ -42,12 +42,12 @@ extern "C" {
|
||||||
*/
|
*/
|
||||||
qboolean TestSky(const vec3_t start, const vec3_t dirn, const dmodel_t *self);
|
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 TestLight(const vec3_t start, const vec3_t stop, const dmodel_t *self);
|
||||||
qboolean DirtTrace(const vec3_t start, const vec3_t dirn, vec_t dist, 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 dirn, vec_t dist, const dmodel_t *self, vec_t *hitdist_out, plane_t *hitplane_out, const bsp2_dface_t **face_out);
|
||||||
|
|
||||||
void Embree_TraceInit(const bsp2_t *bsp);
|
void Embree_TraceInit(const bsp2_t *bsp);
|
||||||
qboolean Embree_TestSky(const vec3_t start, const vec3_t dirn, const dmodel_t *self);
|
qboolean Embree_TestSky(const vec3_t start, const vec3_t dirn, const dmodel_t *self);
|
||||||
qboolean Embree_TestLight(const vec3_t start, const vec3_t stop, const dmodel_t *self);
|
qboolean Embree_TestLight(const vec3_t start, const vec3_t stop, const dmodel_t *self);
|
||||||
qboolean Embree_DirtTrace(const vec3_t start, const vec3_t dirn, vec_t dist, const dmodel_t *self, vec3_t hitpoint_out, plane_t *hitplane_out, const bsp2_dface_t **face_out);
|
qboolean Embree_DirtTrace(const vec3_t start, const vec3_t dirn, vec_t dist, const dmodel_t *self, vec_t *hitdist_out, plane_t *hitplane_out, const bsp2_dface_t **face_out);
|
||||||
|
|
||||||
int
|
int
|
||||||
SampleTexture(const bsp2_dface_t *face, const bsp2_t *bsp, const vec3_t point);
|
SampleTexture(const bsp2_dface_t *face, const bsp2_t *bsp, const vec3_t point);
|
||||||
|
|
|
||||||
|
|
@ -602,7 +602,6 @@ CheckObstructed(const lightsurf_t *surf, const vec3_t offset, const vec_t us, co
|
||||||
TexCoordToWorld(us + (x/10.0), ut + (y/10.0), &surf->texorg, testpoint);
|
TexCoordToWorld(us + (x/10.0), ut + (y/10.0), &surf->texorg, testpoint);
|
||||||
VectorAdd(testpoint, offset, testpoint);
|
VectorAdd(testpoint, offset, testpoint);
|
||||||
|
|
||||||
vec3_t hitpoint = {0};
|
|
||||||
plane_t hitplane = {0};
|
plane_t hitplane = {0};
|
||||||
|
|
||||||
const dmodel_t *selfshadow = (surf->modelinfo->shadowself) ? surf->modelinfo->model : NULL;
|
const dmodel_t *selfshadow = (surf->modelinfo->shadowself) ? surf->modelinfo->model : NULL;
|
||||||
|
|
@ -615,14 +614,10 @@ CheckObstructed(const lightsurf_t *surf, const vec3_t offset, const vec_t us, co
|
||||||
}
|
}
|
||||||
|
|
||||||
// trace from surf->midpoint to testpoint
|
// trace from surf->midpoint to testpoint
|
||||||
if (DirtTrace(surf->midpoint, dirn, dist, selfshadow, hitpoint, &hitplane, NULL)) {
|
vec_t hitdist = 0;
|
||||||
|
if (DirtTrace(surf->midpoint, dirn, dist, selfshadow, &hitdist, &hitplane, NULL)) {
|
||||||
// make a corrected point
|
// make a corrected point
|
||||||
|
VectorMA(surf->midpoint, qmax(0.0f, hitdist - 0.25f), dirn, corrected);
|
||||||
vec3_t tracedir;
|
|
||||||
VectorSubtract(hitpoint, surf->midpoint, tracedir);
|
|
||||||
const vec_t hitdist = VectorNormalize(tracedir);
|
|
||||||
|
|
||||||
VectorMA(surf->midpoint, qmax(0.0f, hitdist - 0.25f), tracedir, corrected);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1831,8 +1826,8 @@ static vec_t
|
||||||
DirtForSample(const dmodel_t *model, const vec3_t origin, const vec3_t normal){
|
DirtForSample(const dmodel_t *model, const vec3_t origin, const vec3_t normal){
|
||||||
int i;
|
int i;
|
||||||
float gatherDirt, angle, elevation, ooDepth;
|
float gatherDirt, angle, elevation, ooDepth;
|
||||||
vec3_t worldUp, myUp, myRt, temp, direction, displacement;
|
vec3_t worldUp, myUp, myRt, temp, direction;
|
||||||
vec3_t traceHitpoint;
|
vec_t traceHitdist;
|
||||||
|
|
||||||
/* dummy check */
|
/* dummy check */
|
||||||
if ( !dirty.value ) {
|
if ( !dirty.value ) {
|
||||||
|
|
@ -1877,9 +1872,8 @@ DirtForSample(const dmodel_t *model, const vec3_t origin, const vec3_t normal){
|
||||||
direction[ 2 ] = myRt[ 2 ] * temp[ 0 ] + myUp[ 2 ] * temp[ 1 ] + normal[ 2 ] * temp[ 2 ];
|
direction[ 2 ] = myRt[ 2 ] * temp[ 0 ] + myUp[ 2 ] * temp[ 1 ] + normal[ 2 ] * temp[ 2 ];
|
||||||
|
|
||||||
/* trace */
|
/* trace */
|
||||||
if (DirtTrace(origin, direction, dirtDepth.value, model, traceHitpoint, NULL, NULL)) {
|
if (DirtTrace(origin, direction, dirtDepth.value, model, &traceHitdist, NULL, NULL)) {
|
||||||
VectorSubtract( traceHitpoint, origin, displacement );
|
gatherDirt += 1.0f - ooDepth * traceHitdist;
|
||||||
gatherDirt += 1.0f - ooDepth * VectorLength( displacement );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -1891,17 +1885,15 @@ DirtForSample(const dmodel_t *model, const vec3_t origin, const vec3_t normal){
|
||||||
direction[ 2 ] = myRt[ 2 ] * dirtVectors[ i ][ 0 ] + myUp[ 2 ] * dirtVectors[ i ][ 1 ] + normal[ 2 ] * dirtVectors[ i ][ 2 ];
|
direction[ 2 ] = myRt[ 2 ] * dirtVectors[ i ][ 0 ] + myUp[ 2 ] * dirtVectors[ i ][ 1 ] + normal[ 2 ] * dirtVectors[ i ][ 2 ];
|
||||||
|
|
||||||
/* trace */
|
/* trace */
|
||||||
if (DirtTrace(origin, direction, dirtDepth.value, model, traceHitpoint, NULL, NULL)) {
|
if (DirtTrace(origin, direction, dirtDepth.value, model, &traceHitdist, NULL, NULL)) {
|
||||||
VectorSubtract( traceHitpoint, origin, displacement );
|
gatherDirt += 1.0f - ooDepth * traceHitdist;
|
||||||
gatherDirt += 1.0f - ooDepth * VectorLength( displacement );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* trace */
|
/* trace */
|
||||||
if (DirtTrace(origin, direction, dirtDepth.value, model, traceHitpoint, NULL, NULL)) {
|
if (DirtTrace(origin, direction, dirtDepth.value, model, &traceHitdist, NULL, NULL)) {
|
||||||
VectorSubtract( traceHitpoint, origin, displacement );
|
gatherDirt += 1.0f - ooDepth * traceHitdist;
|
||||||
gatherDirt += 1.0f - ooDepth * VectorLength( displacement );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* save gatherDirt, the rest of the scaling of the dirt value is done
|
/* save gatherDirt, the rest of the scaling of the dirt value is done
|
||||||
|
|
|
||||||
|
|
@ -659,7 +659,7 @@ BSP_TestSky(const vec3_t start, const vec3_t dirn, const dmodel_t *self)
|
||||||
* ============
|
* ============
|
||||||
*/
|
*/
|
||||||
qboolean
|
qboolean
|
||||||
BSP_DirtTrace(const vec3_t start, const vec3_t dirn, vec_t dist, const dmodel_t *self, vec3_t hitpoint_out, plane_t *hitplane_out, const bsp2_dface_t **face_out)
|
BSP_DirtTrace(const vec3_t start, const vec3_t dirn, const vec_t dist, const dmodel_t *self, vec_t *hitdist_out, plane_t *hitplane_out, const bsp2_dface_t **face_out)
|
||||||
{
|
{
|
||||||
vec3_t stop;
|
vec3_t stop;
|
||||||
VectorMA(start, dist, dirn, stop);
|
VectorMA(start, dist, dirn, stop);
|
||||||
|
|
@ -669,7 +669,11 @@ BSP_DirtTrace(const vec3_t start, const vec3_t dirn, vec_t dist, const dmodel_t
|
||||||
|
|
||||||
if (self) {
|
if (self) {
|
||||||
if (TraceFaces (&ti, self->headnode[0], start, stop)) {
|
if (TraceFaces (&ti, self->headnode[0], start, stop)) {
|
||||||
VectorCopy(ti.point, hitpoint_out);
|
if (hitdist_out) {
|
||||||
|
vec3_t delta;
|
||||||
|
VectorSubtract(ti.point, start, delta);
|
||||||
|
*hitdist_out = VectorLength(delta);
|
||||||
|
}
|
||||||
if (hitplane_out) {
|
if (hitplane_out) {
|
||||||
*hitplane_out = ti.hitplane;
|
*hitplane_out = ti.hitplane;
|
||||||
}
|
}
|
||||||
|
|
@ -686,7 +690,11 @@ BSP_DirtTrace(const vec3_t start, const vec3_t dirn, vec_t dist, const dmodel_t
|
||||||
if ((*model)->model == self)
|
if ((*model)->model == self)
|
||||||
continue;
|
continue;
|
||||||
if (TraceFaces (&ti, (*model)->model->headnode[0], start, stop)) {
|
if (TraceFaces (&ti, (*model)->model->headnode[0], start, stop)) {
|
||||||
VectorCopy(ti.point, hitpoint_out);
|
if (hitdist_out) {
|
||||||
|
vec3_t delta;
|
||||||
|
VectorSubtract(ti.point, start, delta);
|
||||||
|
*hitdist_out = VectorLength(delta);
|
||||||
|
}
|
||||||
if (hitplane_out) {
|
if (hitplane_out) {
|
||||||
*hitplane_out = ti.hitplane;
|
*hitplane_out = ti.hitplane;
|
||||||
}
|
}
|
||||||
|
|
@ -815,15 +823,15 @@ qboolean TestLight(const vec3_t start, const vec3_t stop, const dmodel_t *self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
qboolean DirtTrace(const vec3_t start, const vec3_t dirn, vec_t dist, 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 dirn, vec_t dist, const dmodel_t *self, vec_t *hitdist_out, plane_t *hitplane_out, const bsp2_dface_t **face_out)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_EMBREE
|
#ifdef HAVE_EMBREE
|
||||||
if (rtbackend == backend_embree) {
|
if (rtbackend == backend_embree) {
|
||||||
return Embree_DirtTrace(start, dirn, dist, self, hitpoint_out, hitplane_out, face_out);
|
return Embree_DirtTrace(start, dirn, dist, self, hitdist_out, hitplane_out, face_out);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (rtbackend == backend_bsp) {
|
if (rtbackend == backend_bsp) {
|
||||||
return BSP_DirtTrace(start, dirn, dist, self, hitpoint_out, hitplane_out, face_out);
|
return BSP_DirtTrace(start, dirn, dist, self, hitdist_out, hitplane_out, face_out);
|
||||||
}
|
}
|
||||||
Error("no backend available");
|
Error("no backend available");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -289,7 +289,7 @@ qboolean Embree_TestSky(const vec3_t start, const vec3_t dirn, const dmodel_t *s
|
||||||
}
|
}
|
||||||
|
|
||||||
//public
|
//public
|
||||||
qboolean Embree_DirtTrace(const vec3_t start, const vec3_t dirn, vec_t dist, const dmodel_t *self, vec3_t hitpoint_out, plane_t *hitplane_out, const bsp2_dface_t **face_out)
|
qboolean Embree_DirtTrace(const vec3_t start, const vec3_t dirn, vec_t dist, const dmodel_t *self, vec_t *hitdist_out, plane_t *hitplane_out, const bsp2_dface_t **face_out)
|
||||||
{
|
{
|
||||||
RTCRay ray = SetupRay(start, dirn, dist, self);
|
RTCRay ray = SetupRay(start, dirn, dist, self);
|
||||||
rtcIntersect(scene, ray);
|
rtcIntersect(scene, ray);
|
||||||
|
|
@ -298,9 +298,8 @@ qboolean Embree_DirtTrace(const vec3_t start, const vec3_t dirn, vec_t dist, con
|
||||||
|| ray.geomID == skygeom.geomID)
|
|| ray.geomID == skygeom.geomID)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// compute hitpoint_out
|
if (hitdist_out) {
|
||||||
if (hitpoint_out) {
|
*hitdist_out = ray.tfar;
|
||||||
VectorMA(start, ray.tfar, dirn, hitpoint_out);
|
|
||||||
}
|
}
|
||||||
if (hitplane_out) {
|
if (hitplane_out) {
|
||||||
for (int i=0; i<3; i++) {
|
for (int i=0; i<3; i++) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue