- spread light surface sample points evenly across walls

This commit is contained in:
Magnus Norddahl 2018-11-06 14:58:05 +01:00
parent c3494a045d
commit 57b39458f0

View file

@ -192,6 +192,8 @@ bool kexLightSurface::SubdivideRecursion(vertexBatch_t &surfPoints, float divide
void kexLightSurface::Subdivide(const float divide)
{
if (surface->type == ST_CEILING || surface->type == ST_FLOOR)
{
std::vector<std::unique_ptr<vertexBatch_t>> points;
vertexBatch_t surfPoints;
@ -216,6 +218,49 @@ void kexLightSurface::Subdivide(const float divide)
origins.push_back(center / (float)vb->size());
}
}
else
{
float length = surface->verts[0].Distance(surface->verts[1]);
if (length < divide)
{
kexVec3 top = surface->verts[0] * 0.5f + surface->verts[1] * 0.5f;
kexVec3 bottom = surface->verts[2] * 0.5f + surface->verts[3] * 0.5f;
origins.push_back(top * 0.5f + bottom * 0.5f);
}
else
{
float frac = length / divide;
frac = frac - std::floor(frac);
float start = divide * 0.5f + frac * 0.5f * divide;
for (float i = start; i < length; i += divide)
{
float t = i / length;
kexVec3 top = surface->verts[0] * (1.0f - t) + surface->verts[1] * t;
kexVec3 bottom = surface->verts[2] * (1.0f - t) + surface->verts[3] * t;
float length2 = top.Distance(bottom);
if (length2 < divide)
{
origins.push_back(top * 0.5f + bottom * 0.5f);
}
else
{
float frac2 = length2 / divide;
frac2 = frac2 - std::floor(frac2);
float start2 = divide * 0.5f + frac2 * 0.5f * divide;
for (float j = start2; j < length2; j += divide)
{
float t2 = j / length2;
origins.push_back(top * (1.0f - t2) + bottom * t2);
}
}
}
}
}
}
float kexLightSurface::TraceSurface(FLevel *map, const surface_t *fragmentSurface, const kexVec3 &fragmentPos)