diff --git a/include/light/trace.hh b/include/light/trace.hh index 3a8cad55..e00c4e33 100644 --- a/include/light/trace.hh +++ b/include/light/trace.hh @@ -66,6 +66,7 @@ public: virtual float getPushedRayDist(size_t j) = 0; virtual float getPushedRayHitDist(size_t j) = 0; virtual hittype_t getPushedRayHitType(size_t j) = 0; + virtual const bsp2_dface_t *getPushedRayHitFace(size_t j) = 0; virtual void getPushedRayDir(size_t j, vec3_t out) = 0; virtual int getPushedRayPointIndex(size_t j) = 0; virtual void getPushedRayColor(size_t j, vec3_t out) = 0; diff --git a/light/trace.cc b/light/trace.cc index 427e63f8..7abf1c9a 100644 --- a/light/trace.cc +++ b/light/trace.cc @@ -800,6 +800,7 @@ public: // hit info float _hitdist; hittype_t _hittype; + const bsp2_dface_t *_hitface; bool _hit_occluded; bsp_ray_t(int i, const vec_t *origin, const vec3_t dir, float dist, const dmodel_t *selfshadow, const vec_t *color, const vec_t *normalcontrib) : @@ -808,6 +809,7 @@ public: _selfshadow{selfshadow}, _hitdist{dist}, _hittype{hittype_t::NONE}, + _hitface(nullptr), _hit_occluded{false} { VectorCopy(origin, _origin); VectorCopy(dir, _dir); @@ -857,7 +859,7 @@ public: return; for (bsp_ray_t &ray : _rays) { - ray._hittype = BSP_DirtTrace(ray._origin, ray._dir, ray._maxdist, ray._selfshadow, &ray._hitdist, nullptr, nullptr); + ray._hittype = BSP_DirtTrace(ray._origin, ray._dir, ray._maxdist, ray._selfshadow, &ray._hitdist, nullptr, &ray._hitface); } } @@ -877,6 +879,10 @@ public: return _rays.at(j)._hittype; } + virtual const bsp2_dface_t *getPushedRayHitFace(size_t j) { + return _rays.at(j)._hitface; + } + virtual void getPushedRayDir(size_t j, vec3_t out) { for (int i=0; i<3; i++) { out[i] = _rays.at(j)._dir[i]; diff --git a/light/trace_embree.cc b/light/trace_embree.cc index 8ec5b414..7468f07d 100644 --- a/light/trace_embree.cc +++ b/light/trace_embree.cc @@ -869,6 +869,21 @@ public: } } + virtual const bsp2_dface_t *getPushedRayHitFace(size_t j) { + Q_assert(j < _maxrays); + + const RTCRay &ray = _rays[j]; + + if (ray.geomID == RTC_INVALID_GEOMETRY_ID) + return nullptr; + + const sceneinfo &si = Embree_SceneinfoForGeomID(ray.geomID); + const bsp2_dface_t *face = si.triToFace.at(ray.primID); + Q_assert(face != nullptr); + + return face; + } + virtual void getPushedRayDir(size_t j, vec3_t out) { Q_assert(j < _maxrays); for (int i=0; i<3; i++) {