From ed43b29489be83fbf4e1eb2fb5bebd58aa800666 Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Fri, 12 Aug 2016 11:51:27 -0600 Subject: [PATCH] light: store normal contribution in ray stream --- include/light/trace.hh | 3 ++- light/trace.cc | 14 +++++++++++--- light/trace_embree.cc | 13 ++++++++++++- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/include/light/trace.hh b/include/light/trace.hh index e6c0a198..ecaabc66 100644 --- a/include/light/trace.hh +++ b/include/light/trace.hh @@ -59,7 +59,7 @@ bool IntersectSingleModel(const vec3_t start, const vec3_t dir, vec_t dist, cons class raystream_t { public: - virtual void pushRay(int i, const vec_t *origin, const vec3_t dir, float dist, const dmodel_t *selfshadow, const vec_t *color = nullptr) = 0; + virtual void pushRay(int i, const vec_t *origin, const vec3_t dir, float dist, const dmodel_t *selfshadow, const vec_t *color = nullptr, const vec_t *normalcontrib = nullptr) = 0; virtual size_t numPushedRays() = 0; virtual void tracePushedRaysOcclusion() = 0; virtual void tracePushedRaysIntersection() = 0; @@ -70,6 +70,7 @@ public: 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; + virtual void getPushedRayNormalContrib(size_t j, vec3_t out) = 0; virtual void clearPushedRays() = 0; virtual ~raystream_t() {}; }; diff --git a/light/trace.cc b/light/trace.cc index f0be8558..841fefe4 100644 --- a/light/trace.cc +++ b/light/trace.cc @@ -868,13 +868,14 @@ public: float _maxdist; const dmodel_t *_selfshadow; vec3_t _color; + vec3_t _normalcontrib; // hit info float _hitdist; hittype_t _hittype; 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) : + 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) : _pointindex{i}, _maxdist{dist}, _selfshadow{selfshadow}, @@ -886,6 +887,9 @@ public: if (color != nullptr) { VectorCopy(color, _color); } + if (normalcontrib != nullptr) { + VectorCopy(normalcontrib, _normalcontrib); + } } }; @@ -900,8 +904,8 @@ public: raystream_bsp_t() {} - virtual void pushRay(int i, const vec_t *origin, const vec3_t dir, float dist, const dmodel_t *selfshadow, const vec_t *color = nullptr) { - bsp_ray_t r { i, origin, dir, dist, selfshadow, color }; + virtual void pushRay(int i, const vec_t *origin, const vec3_t dir, float dist, const dmodel_t *selfshadow, const vec_t *color = nullptr, const vec_t *normalcontrib = nullptr) { + bsp_ray_t r { i, origin, dir, dist, selfshadow, color, normalcontrib }; _rays.push_back(r); assert(_rays.size() <= _maxrays); } @@ -960,6 +964,10 @@ public: VectorCopy(_rays.at(j)._color, out); } + virtual void getPushedRayNormalContrib(size_t j, vec3_t out) { + VectorCopy(_rays.at(j)._normalcontrib, out); + } + virtual void clearPushedRays() { _rays.clear(); } diff --git a/light/trace_embree.cc b/light/trace_embree.cc index 727cbf9c..e0aa85d8 100644 --- a/light/trace_embree.cc +++ b/light/trace_embree.cc @@ -455,6 +455,7 @@ private: float *_rays_maxdist; int *_point_indices; vec3_t *_ray_colors; + vec3_t *_ray_normalcontribs; int _numrays; int _maxrays; // streamstate_t _state; @@ -465,6 +466,7 @@ public: _rays_maxdist { new float[maxRays] }, _point_indices { new int[maxRays] }, _ray_colors { static_cast(calloc(maxRays, sizeof(vec3_t))) }, + _ray_normalcontribs { static_cast(calloc(maxRays, sizeof(vec3_t))) }, _numrays { 0 }, _maxrays { maxRays } {} //, @@ -475,9 +477,10 @@ public: delete[] _rays_maxdist; delete[] _point_indices; free(_ray_colors); + free(_ray_normalcontribs); } - virtual void pushRay(int i, const vec_t *origin, const vec3_t dir, float dist, const dmodel_t *selfshadow, const vec_t *color = nullptr) { + virtual void pushRay(int i, const vec_t *origin, const vec3_t dir, float dist, const dmodel_t *selfshadow, const vec_t *color = nullptr, const vec_t *normalcontrib = nullptr) { assert(_numrays<_maxrays); _rays[_numrays] = SetupRay(origin, dir, dist, selfshadow); _rays_maxdist[_numrays] = dist; @@ -485,6 +488,9 @@ public: if (color) { VectorCopy(color, _ray_colors[_numrays]); } + if (normalcontrib) { + VectorCopy(normalcontrib, _ray_normalcontribs[_numrays]); + } _numrays++; } @@ -563,6 +569,11 @@ public: VectorCopy(_ray_colors[j], out); } + virtual void getPushedRayNormalContrib(size_t j, vec3_t out) { + assert(j < _maxrays); + VectorCopy(_ray_normalcontribs[j], out); + } + virtual void clearPushedRays() { _numrays = 0; //_state = streamstate_t::READY;