light: store normal contribution in ray stream

This commit is contained in:
Eric Wasylishen 2016-08-12 11:51:27 -06:00
parent 8ca5fafffc
commit ed43b29489
3 changed files with 25 additions and 5 deletions

View File

@ -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() {};
};

View File

@ -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();
}

View File

@ -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<vec3_t *>(calloc(maxRays, sizeof(vec3_t))) },
_ray_normalcontribs { static_cast<vec3_t *>(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;