- add dynamic lights to softpoly and software renderer models

This commit is contained in:
Magnus Norddahl 2018-06-05 22:43:11 +02:00
commit 5464d2a577
13 changed files with 283 additions and 65 deletions

View file

@ -34,6 +34,7 @@
#include "hwrenderer/dynlights/hw_dynlightdata.h"
#include "hwrenderer/dynlights/hw_shadowmap.h"
#include "hwrenderer/scene/hw_drawinfo.h"
#include "r_data/models/models.h"
template<class T>
T smoothstep(const T edge0, const T edge1, const T x)
@ -138,49 +139,6 @@ void HWDrawInfo::GetDynSpriteLight(AActor *thing, particle_t *particle, float *o
}
}
// Check if circle potentially intersects with node AABB
static bool CheckBBoxCircle(float *bbox, float x, float y, float radiusSquared)
{
float centerX = (bbox[BOXRIGHT] + bbox[BOXLEFT]) * 0.5f;
float centerY = (bbox[BOXBOTTOM] + bbox[BOXTOP]) * 0.5f;
float extentX = (bbox[BOXRIGHT] - bbox[BOXLEFT]) * 0.5f;
float extentY = (bbox[BOXBOTTOM] - bbox[BOXTOP]) * 0.5f;
float aabbRadiusSquared = extentX * extentX + extentY * extentY;
x -= centerX;
y -= centerY;
float dist = x * x + y * y;
return dist <= radiusSquared + aabbRadiusSquared;
}
template<typename Callback>
void BSPNodeWalkCircle(void *node, float x, float y, float radiusSquared, const Callback &callback)
{
while (!((size_t)node & 1))
{
node_t *bsp = (node_t *)node;
if (CheckBBoxCircle(bsp->bbox[0], x, y, radiusSquared))
BSPNodeWalkCircle(bsp->children[0], x, y, radiusSquared, callback);
if (!CheckBBoxCircle(bsp->bbox[1], x, y, radiusSquared))
return;
node = bsp->children[1];
}
subsector_t *sub = (subsector_t *)((uint8_t *)node - 1);
callback(sub);
}
template<typename Callback>
void BSPWalkCircle(float x, float y, float radiusSquared, const Callback &callback)
{
if (level.nodes.Size() == 0)
callback(&level.subsectors[0]);
else
BSPNodeWalkCircle(level.HeadNode(), x, y, radiusSquared, callback);
}
// static so that we build up a reserve (memory allocations stop)
// For multithread processing each worker thread needs its own copy, though.
static thread_local TArray<ADynamicLight*> addedLightsArray;