A hack is best solved by adding another hack on top. Everyone knows this.
This commit is contained in:
parent
6e5df8ef4c
commit
ae33d583ad
1 changed files with 37 additions and 41 deletions
|
|
@ -29,6 +29,16 @@
|
|||
#include "earcut.hpp"
|
||||
#include "v_video.h"
|
||||
|
||||
struct SectorVertexOrigin
|
||||
{
|
||||
SectorVertexOrigin() = default;
|
||||
SectorVertexOrigin(subsector_t* sub, int plane, int lightmapSlot) : sub(sub), plane(plane), lightmapSlot(lightmapSlot) { }
|
||||
subsector_t* sub;
|
||||
int plane;
|
||||
int lightmapSlot;
|
||||
};
|
||||
|
||||
static TArray<SectorVertexOrigin> sector_origins;
|
||||
TArray<FFlatVertex> sector_vertices;
|
||||
TArray<uint32_t> sector_indexes;
|
||||
|
||||
|
|
@ -232,7 +242,9 @@ static int CreateIndexedSectorVerticesLM(sector_t* sec, const secplane_t& plane,
|
|||
}
|
||||
|
||||
auto& vbo_shadowdata = sector_vertices;
|
||||
auto& vbo_origins = sector_origins;
|
||||
int vi = vbo_shadowdata.Reserve(pos);
|
||||
vbo_origins.Reserve(pos);
|
||||
int idx = ibo_data.Reserve((pos - 2 * sec->subsectorcount) * 3);
|
||||
|
||||
// Create the actual vertices.
|
||||
|
|
@ -255,6 +267,7 @@ static int CreateIndexedSectorVerticesLM(sector_t* sec, const secplane_t& plane,
|
|||
FVector2 luv = tile.ToUV(FVector3((float)vt->fX(), (float)vt->fY(), (float)plane.ZatPoint(vt)), textureSize);
|
||||
SetFlatVertex(vbo_shadowdata[vi + pos], vt, plane, luv.X, luv.Y, lindex);
|
||||
vbo_shadowdata[vi + pos].z += diff;
|
||||
vbo_origins[vi + pos] = SectorVertexOrigin(sub, h, lightmapIndex);
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
|
|
@ -264,6 +277,7 @@ static int CreateIndexedSectorVerticesLM(sector_t* sec, const secplane_t& plane,
|
|||
{
|
||||
SetFlatVertex(vbo_shadowdata[vi + pos], sub->firstline[j].v1, plane);
|
||||
vbo_shadowdata[vi + pos].z += diff;
|
||||
vbo_origins[vi + pos] = SectorVertexOrigin(sub, h, lightmapIndex);
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
|
|
@ -297,7 +311,9 @@ static int CreateIndexedSectorVertices(sector_t* sec, const secplane_t& plane, i
|
|||
return CreateIndexedSectorVerticesLM(sec, plane, floor, h, lightmapIndex);
|
||||
|
||||
auto& vbo_shadowdata = sector_vertices;
|
||||
auto& vbo_origins = sector_origins;
|
||||
unsigned vi = vbo_shadowdata.Reserve(verts.vertices.Size());
|
||||
vbo_origins.Reserve(verts.vertices.Size());
|
||||
float diff;
|
||||
|
||||
// Create the actual vertices.
|
||||
|
|
@ -307,6 +323,7 @@ static int CreateIndexedSectorVertices(sector_t* sec, const secplane_t& plane, i
|
|||
{
|
||||
SetFlatVertex(vbo_shadowdata[vi + i], verts.vertices[i].vertex, plane);
|
||||
vbo_shadowdata[vi + i].z += diff;
|
||||
vbo_origins[vi + i] = SectorVertexOrigin(nullptr, h, lightmapIndex);
|
||||
}
|
||||
|
||||
auto& ibo_data = sector_indexes;
|
||||
|
|
@ -451,41 +468,29 @@ static void UpdatePlaneVertices(FRenderState& renderstate, sector_t* sec, int pl
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
static void UpdatePlaneLightmap(FRenderState& renderstate, sector_t* sec, int plane, int lightmapIndex)
|
||||
static void UpdatePlaneLightmap(FRenderState& renderstate, sector_t* sec, int plane)
|
||||
{
|
||||
if (!sec->HasLightmaps)
|
||||
return;
|
||||
|
||||
int startvt = sec->vboindex[plane];
|
||||
int countvt = sec->vbocount[plane];
|
||||
secplane_t& splane = sec->GetSecPlane(plane);
|
||||
|
||||
auto sections = sec->Level->sections.SectionsForSector(sec);
|
||||
int pos = startvt;
|
||||
for (auto& section : sections)
|
||||
FFlatVertex* vt = §or_vertices[startvt];
|
||||
SectorVertexOrigin* origin = §or_origins[startvt];
|
||||
for (int i = 0; i < countvt; i++, vt++, origin++)
|
||||
{
|
||||
for (auto& sub : section.subsectors)
|
||||
if (origin->sub)
|
||||
{
|
||||
// vertices
|
||||
int lightmap = sub->LightmapTiles[plane].Size() > lightmapIndex ? sub->LightmapTiles[plane][lightmapIndex] : -1;
|
||||
int lightmap = origin->sub->LightmapTiles[origin->plane].Size() > origin->lightmapSlot ? origin->sub->LightmapTiles[origin->plane][origin->lightmapSlot] : -1;
|
||||
if (lightmap >= 0) // tile may be missing if the subsector is degenerate triangle
|
||||
{
|
||||
const auto& tile = level.levelMesh->Lightmap.Tiles[lightmap];
|
||||
float textureSize = (float)level.levelMesh->Lightmap.TextureSize;
|
||||
float lindex = (float)tile.AtlasLocation.ArrayIndex;
|
||||
for (unsigned int j = 0, end = sub->numlines; j < end; j++)
|
||||
{
|
||||
vertex_t* vt = sub->firstline[j].v1;
|
||||
FVector2 luv = tile.ToUV(FVector3((float)vt->fX(), (float)vt->fY(), (float)splane.ZatPoint(vt)), textureSize);
|
||||
sector_vertices[pos].lu = luv.X;
|
||||
sector_vertices[pos].lv = luv.Y;
|
||||
sector_vertices[pos].lindex = lightmapIndex;
|
||||
pos++;
|
||||
}
|
||||
FVector2 luv = tile.ToUV(FVector3(vt->x, vt->y, vt->z), textureSize);
|
||||
vt->lu = luv.X;
|
||||
vt->lv = luv.Y;
|
||||
vt->lindex = lindex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
renderstate.UpdateShadowData(startvt, §or_vertices[startvt], countvt);
|
||||
}
|
||||
|
||||
|
|
@ -498,6 +503,7 @@ static void UpdatePlaneLightmap(FRenderState& renderstate, sector_t* sec, int pl
|
|||
static void CreateVertices(TArray<sector_t>& sectors)
|
||||
{
|
||||
sector_vertices.Clear();
|
||||
sector_origins.Clear();
|
||||
CreateIndexedFlatVertices(sectors);
|
||||
}
|
||||
|
||||
|
|
@ -521,18 +527,6 @@ static void CheckPlanes(FRenderState& renderstate, sector_t* sector)
|
|||
}
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
static void UpdateLightmapPlanes(FRenderState& renderstate, sector_t* sector)
|
||||
{
|
||||
UpdatePlaneLightmap(renderstate, sector, sector_t::ceiling, 0);
|
||||
UpdatePlaneLightmap(renderstate, sector, sector_t::floor, 0);
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// checks the validity of all planes attached to this sector
|
||||
|
|
@ -557,19 +551,20 @@ void CheckUpdate(FRenderState& renderstate, sector_t* sector)
|
|||
|
||||
void UpdateVBOLightmap(FRenderState& renderstate, sector_t* sector)
|
||||
{
|
||||
UpdatePlaneLightmap(renderstate, sector, sector_t::ceiling, 0);
|
||||
UpdatePlaneLightmap(renderstate, sector, sector_t::floor, 0);
|
||||
UpdatePlaneLightmap(renderstate, sector, sector_t::ceiling);
|
||||
UpdatePlaneLightmap(renderstate, sector, sector_t::floor);
|
||||
|
||||
sector_t* hs = sector->GetHeightSec();
|
||||
if (hs != NULL)
|
||||
if (hs)
|
||||
{
|
||||
UpdatePlaneLightmap(renderstate, hs, sector_t::ceiling, -1);
|
||||
UpdatePlaneLightmap(renderstate, hs, sector_t::floor, -1);
|
||||
UpdatePlaneLightmap(renderstate, hs, sector_t::ceiling);
|
||||
UpdatePlaneLightmap(renderstate, hs, sector_t::floor);
|
||||
}
|
||||
|
||||
for (unsigned i = 0; i < sector->e->XFloor.ffloors.Size(); i++)
|
||||
{
|
||||
UpdatePlaneLightmap(renderstate, sector->e->XFloor.ffloors[i]->model, sector_t::ceiling, i + 1);
|
||||
UpdatePlaneLightmap(renderstate, sector->e->XFloor.ffloors[i]->model, sector_t::floor, i + 1);
|
||||
UpdatePlaneLightmap(renderstate, sector->e->XFloor.ffloors[i]->model, sector_t::ceiling);
|
||||
UpdatePlaneLightmap(renderstate, sector->e->XFloor.ffloors[i]->model, sector_t::floor);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -582,6 +577,7 @@ void UpdateVBOLightmap(FRenderState& renderstate, sector_t* sector)
|
|||
void CreateVBO(FRenderState& renderstate, TArray<sector_t>& sectors)
|
||||
{
|
||||
sector_vertices.Clear();
|
||||
sector_origins.Clear();
|
||||
CreateVertices(sectors);
|
||||
renderstate.SetShadowData(sector_vertices, sector_indexes);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue