- rename LightSurface to SurfaceLight

This commit is contained in:
Magnus Norddahl 2018-11-09 22:17:36 +01:00
parent 908c048464
commit b3250f4bac
6 changed files with 45 additions and 64 deletions

View file

@ -247,7 +247,7 @@ class Vec3;
class Vec2; class Vec2;
struct vertex_t; struct vertex_t;
struct Surface; struct Surface;
struct thingLight_t; struct ThingLight;
struct FloatVertex struct FloatVertex
{ {
@ -255,26 +255,7 @@ struct FloatVertex
float y; float y;
}; };
struct lightDef_t struct ThingLight
{
int doomednum;
float height;
float radius;
float intensity;
float falloff;
bool bCeiling;
Vec3 rgb;
};
struct mapDef_t
{
int map;
int sunIgnoreTag;
Vec3 sunDir;
Vec3 sunColor;
};
struct thingLight_t
{ {
IntThing *mapThing; IntThing *mapThing;
Vec2 origin; Vec2 origin;
@ -289,7 +270,7 @@ struct thingLight_t
MapSubsectorEx *ssect; MapSubsectorEx *ssect;
}; };
struct surfaceLightDef struct SurfaceLightDef
{ {
float distance; float distance;
float intensity; float intensity;
@ -351,8 +332,8 @@ struct FLevel
// Dlight helpers // Dlight helpers
TArray<thingLight_t> ThingLights; TArray<ThingLight> ThingLights;
TArray<surfaceLightDef> SurfaceLights; TArray<SurfaceLightDef> SurfaceLights;
void SetupDlight(); void SetupDlight();
void CreateLights(); void CreateLights();

View file

@ -247,7 +247,7 @@ void FLevel::CreateLights()
int x = thing->x >> FRACBITS; int x = thing->x >> FRACBITS;
int y = thing->y >> FRACBITS; int y = thing->y >> FRACBITS;
thingLight_t thingLight; ThingLight thingLight;
thingLight.mapThing = thing; thingLight.mapThing = thing;
thingLight.rgb.x = ((lightcolor >> 16) & 0xff) / 255.0f; thingLight.rgb.x = ((lightcolor >> 16) & 0xff) / 255.0f;
thingLight.rgb.y = ((lightcolor >> 8) & 0xff) / 255.0f; thingLight.rgb.y = ((lightcolor >> 8) & 0xff) / 255.0f;
@ -300,7 +300,7 @@ void FLevel::CreateLights()
if (lightdistance > 0.0f && lightintensity > 0.0f && lightcolor != 0) if (lightdistance > 0.0f && lightintensity > 0.0f && lightcolor != 0)
{ {
surfaceLightDef desc; SurfaceLightDef desc;
desc.intensity = lightintensity; desc.intensity = lightintensity;
desc.distance = lightdistance; desc.distance = lightdistance;
desc.rgb.x = ((lightcolor >> 16) & 0xff) / 255.0f; desc.rgb.x = ((lightcolor >> 16) & 0xff) / 255.0f;
@ -341,7 +341,7 @@ void FLevel::CreateLights()
if (lightdistance > 0.0f && lightintensity > 0.0f && lightcolor != 0) if (lightdistance > 0.0f && lightintensity > 0.0f && lightcolor != 0)
{ {
surfaceLightDef desc; SurfaceLightDef desc;
desc.intensity = lightintensity; desc.intensity = lightintensity;
desc.distance = lightdistance; desc.distance = lightdistance;
desc.rgb.x = ((lightcolor >> 16) & 0xff) / 255.0f; desc.rgb.x = ((lightcolor >> 16) & 0xff) / 255.0f;
@ -373,7 +373,7 @@ void FLevel::CreateLights()
if (lightdistance > 0.0f && lightintensity > 0.0f && lightcolor != 0) if (lightdistance > 0.0f && lightintensity > 0.0f && lightcolor != 0)
{ {
surfaceLightDef desc; SurfaceLightDef desc;
desc.intensity = lightintensity; desc.intensity = lightintensity;
desc.distance = lightdistance; desc.distance = lightdistance;
desc.rgb.x = ((lightcolor >> 16) & 0xff) / 255.0f; desc.rgb.x = ((lightcolor >> 16) & 0xff) / 255.0f;

View file

@ -213,7 +213,7 @@ Vec3 LightmapBuilder::LightTexelSample(const Vec3 &origin, Surface *surface)
// check all thing lights // check all thing lights
for (unsigned int i = 0; i < map->ThingLights.Size(); i++) for (unsigned int i = 0; i < map->ThingLights.Size(); i++)
{ {
thingLight_t *tl = &map->ThingLights[i]; ThingLight *tl = &map->ThingLights[i];
float originZ; float originZ;
if (!tl->bCeiling) if (!tl->bCeiling)
@ -286,9 +286,9 @@ Vec3 LightmapBuilder::LightTexelSample(const Vec3 &origin, Surface *surface)
} }
// trace against surface lights // trace against surface lights
for (size_t i = 0; i < lightSurfaces.size(); ++i) for (size_t i = 0; i < surfaceLights.size(); ++i)
{ {
LightSurface *surfaceLight = lightSurfaces[i].get(); SurfaceLight *surfaceLight = surfaceLights[i].get();
float attenuation = surfaceLight->TraceSurface(mesh.get(), surface, origin); float attenuation = surfaceLight->TraceSurface(mesh.get(), surface, origin);
if (attenuation > 0.0f) if (attenuation > 0.0f)
@ -646,7 +646,7 @@ void LightmapBuilder::TraceIndirectLight(Surface *surface)
} }
} }
void LightmapBuilder::LightSurfacex(const int surfid) void LightmapBuilder::LightSurface(const int surfid)
{ {
BuildSurfaceParams(mesh->surfaces[surfid].get()); BuildSurfaceParams(mesh->surfaces[surfid].get());
TraceSurface(mesh->surfaces[surfid].get()); TraceSurface(mesh->surfaces[surfid].get());
@ -679,7 +679,7 @@ void LightmapBuilder::LightIndirect(const int surfid)
} }
} }
void LightmapBuilder::CreateLightSurfaces() void LightmapBuilder::CreateSurfaceLights()
{ {
for (size_t j = 0; j < mesh->surfaces.size(); ++j) for (size_t j = 0; j < mesh->surfaces.size(); ++j)
{ {
@ -690,9 +690,9 @@ void LightmapBuilder::CreateLightSurfaces()
int lightdefidx = map->Sides[surface->typeIndex].lightdef; int lightdefidx = map->Sides[surface->typeIndex].lightdef;
if (lightdefidx != -1) if (lightdefidx != -1)
{ {
auto lightSurface = std::make_unique<LightSurface>(map->SurfaceLights[lightdefidx], surface); auto surfaceLight = std::make_unique<SurfaceLight>(map->SurfaceLights[lightdefidx], surface);
lightSurface->Subdivide(16); surfaceLight->Subdivide(16);
lightSurfaces.push_back(std::move(lightSurface)); surfaceLights.push_back(std::move(surfaceLight));
} }
} }
else if (surface->type == ST_FLOOR || surface->type == ST_CEILING) else if (surface->type == ST_FLOOR || surface->type == ST_CEILING)
@ -704,15 +704,15 @@ void LightmapBuilder::CreateLightSurfaces()
{ {
if (sector->floorlightdef != -1 && surface->type == ST_FLOOR) if (sector->floorlightdef != -1 && surface->type == ST_FLOOR)
{ {
auto lightSurface = std::make_unique<LightSurface>(map->SurfaceLights[sector->floorlightdef], surface); auto surfaceLight = std::make_unique<SurfaceLight>(map->SurfaceLights[sector->floorlightdef], surface);
lightSurface->Subdivide(16); surfaceLight->Subdivide(16);
lightSurfaces.push_back(std::move(lightSurface)); surfaceLights.push_back(std::move(surfaceLight));
} }
else if (sector->ceilinglightdef != -1 && surface->type == ST_CEILING) else if (sector->ceilinglightdef != -1 && surface->type == ST_CEILING)
{ {
auto lightSurface = std::make_unique<LightSurface>(map->SurfaceLights[sector->ceilinglightdef], surface); auto surfaceLight = std::make_unique<SurfaceLight>(map->SurfaceLights[sector->ceilinglightdef], surface);
lightSurface->Subdivide(16); surfaceLight->Subdivide(16);
lightSurfaces.push_back(std::move(lightSurface)); surfaceLights.push_back(std::move(surfaceLight));
} }
} }
} }
@ -724,7 +724,7 @@ void LightmapBuilder::CreateLightmaps(FLevel &doomMap)
map = &doomMap; map = &doomMap;
mesh = std::make_unique<LevelMesh>(doomMap); mesh = std::make_unique<LevelMesh>(doomMap);
CreateLightSurfaces(); CreateSurfaceLights();
printf("-------------- Tracing cells ---------------\n"); printf("-------------- Tracing cells ---------------\n");
@ -743,7 +743,7 @@ void LightmapBuilder::CreateLightmaps(FLevel &doomMap)
tracedTexels = 0; tracedTexels = 0;
processed = 0; processed = 0;
Worker::RunJob(mesh->surfaces.size(), [=](int id) { Worker::RunJob(mesh->surfaces.size(), [=](int id) {
LightSurfacex(id); LightSurface(id);
}); });
printf("Texels traced: %i \n\n", tracedTexels); printf("Texels traced: %i \n\n", tracedTexels);

View file

@ -37,7 +37,7 @@
#define LIGHTCELL_BLOCK_SIZE 16 #define LIGHTCELL_BLOCK_SIZE 16
class FWadWriter; class FWadWriter;
class LightSurface; class SurfaceLight;
class LightCellBlock class LightCellBlock
{ {
@ -82,14 +82,14 @@ private:
void TraceIndirectLight(Surface *surface); void TraceIndirectLight(Surface *surface);
void SetupLightCellGrid(); void SetupLightCellGrid();
void LightBlock(int blockid); void LightBlock(int blockid);
void LightSurfacex(const int surfid); void LightSurface(const int surfid);
void LightIndirect(const int surfid); void LightIndirect(const int surfid);
void CreateLightSurfaces(); void CreateSurfaceLights();
std::unique_ptr<LevelMesh> mesh; std::unique_ptr<LevelMesh> mesh;
FLevel *map; FLevel *map;
std::vector<std::unique_ptr<LightSurface>> lightSurfaces; std::vector<std::unique_ptr<SurfaceLight>> surfaceLights;
std::vector<std::vector<uint16_t>> textures; std::vector<std::vector<uint16_t>> textures;
std::vector<uint16_t> indirectoutput; std::vector<uint16_t> indirectoutput;
std::vector<std::vector<int>> allocBlocks; std::vector<std::vector<int>> allocBlocks;

View file

@ -29,20 +29,20 @@
#include "level/level.h" #include "level/level.h"
#include "lightsurface.h" #include "lightsurface.h"
LightSurface::LightSurface(const surfaceLightDef &lightSurfaceDef, Surface *surface) SurfaceLight::SurfaceLight(const SurfaceLightDef &surfaceLightDef, Surface *surface)
{ {
this->intensity = lightSurfaceDef.intensity; this->intensity = surfaceLightDef.intensity;
this->distance = lightSurfaceDef.distance; this->distance = surfaceLightDef.distance;
this->rgb = lightSurfaceDef.rgb; this->rgb = surfaceLightDef.rgb;
this->surface = surface; this->surface = surface;
} }
LightSurface::~LightSurface() SurfaceLight::~SurfaceLight()
{ {
} }
// Splits surface vertices into two groups while adding new ones caused by the split // Splits surface vertices into two groups while adding new ones caused by the split
void LightSurface::Clip(VertexBatch &points, const Vec3 &normal, float dist, VertexBatch *frontPoints, VertexBatch *backPoints) void SurfaceLight::Clip(VertexBatch &points, const Vec3 &normal, float dist, VertexBatch *frontPoints, VertexBatch *backPoints)
{ {
std::vector<float> dists; std::vector<float> dists;
std::vector<char> sides; std::vector<char> sides;
@ -116,7 +116,7 @@ void LightSurface::Clip(VertexBatch &points, const Vec3 &normal, float dist, Ver
} }
// Recursively divides the surface // Recursively divides the surface
bool LightSurface::SubdivideRecursion(VertexBatch &surfPoints, float divide, std::vector<std::unique_ptr<VertexBatch>> &points) bool SurfaceLight::SubdivideRecursion(VertexBatch &surfPoints, float divide, std::vector<std::unique_ptr<VertexBatch>> &points)
{ {
BBox bounds; BBox bounds;
Vec3 splitNormal; Vec3 splitNormal;
@ -161,7 +161,7 @@ bool LightSurface::SubdivideRecursion(VertexBatch &surfPoints, float divide, std
return false; return false;
} }
void LightSurface::Subdivide(const float divide) void SurfaceLight::Subdivide(const float divide)
{ {
if (surface->type == ST_CEILING || surface->type == ST_FLOOR) if (surface->type == ST_CEILING || surface->type == ST_FLOOR)
{ {
@ -234,7 +234,7 @@ void LightSurface::Subdivide(const float divide)
} }
} }
float LightSurface::TraceSurface(LevelMesh *mesh, const Surface *fragmentSurface, const Vec3 &fragmentPos) float SurfaceLight::TraceSurface(LevelMesh *mesh, const Surface *fragmentSurface, const Vec3 &fragmentPos)
{ {
if (fragmentSurface == surface) if (fragmentSurface == surface)
return 1.0f; // light surface will always be fullbright return 1.0f; // light surface will always be fullbright

View file

@ -30,13 +30,13 @@
#include "surfaces.h" #include "surfaces.h"
struct FLevel; struct FLevel;
struct surfaceLightDef; struct SurfaceLightDef;
class LightSurface class SurfaceLight
{ {
public: public:
LightSurface(const surfaceLightDef &lightSurfaceDef, Surface *surface); SurfaceLight(const SurfaceLightDef &surfaceLightDef, Surface *surface);
~LightSurface(); ~SurfaceLight();
void Subdivide(const float divide); void Subdivide(const float divide);
float TraceSurface(LevelMesh *map, const Surface *surface, const Vec3 &origin); float TraceSurface(LevelMesh *map, const Surface *surface, const Vec3 &origin);