Fix the shadow data VBO not updating its lightmap UVs
This commit is contained in:
parent
737b7ece96
commit
6e5df8ef4c
3 changed files with 88 additions and 1 deletions
|
|
@ -331,9 +331,15 @@ void DoomLevelMesh::BeginFrame(FLevelLocals& doomMap)
|
|||
}
|
||||
Flats[flatIndex].UpdateType = SurfaceUpdateType::None;
|
||||
}
|
||||
FlatUpdateList.Clear();
|
||||
|
||||
PackLightmapAtlas();
|
||||
|
||||
for (int flatIndex : FlatUpdateList)
|
||||
{
|
||||
UpdateVBOLightmap(*screen->RenderState(), &doomMap.sectors[flatIndex]);
|
||||
}
|
||||
FlatUpdateList.Clear();
|
||||
|
||||
UpdateWallPortals();
|
||||
UploadDynLights(doomMap);
|
||||
|
||||
|
|
|
|||
|
|
@ -451,6 +451,50 @@ static void UpdatePlaneVertices(FRenderState& renderstate, sector_t* sec, int pl
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
static void UpdatePlaneLightmap(FRenderState& renderstate, sector_t* sec, int plane, int lightmapIndex)
|
||||
{
|
||||
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)
|
||||
{
|
||||
for (auto& sub : section.subsectors)
|
||||
{
|
||||
// vertices
|
||||
int lightmap = sub->LightmapTiles[plane].Size() > lightmapIndex ? sub->LightmapTiles[plane][lightmapIndex] : -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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
renderstate.UpdateShadowData(startvt, §or_vertices[startvt], countvt);
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
static void CreateVertices(TArray<sector_t>& sectors)
|
||||
{
|
||||
sector_vertices.Clear();
|
||||
|
|
@ -477,6 +521,18 @@ 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
|
||||
|
|
@ -493,6 +549,30 @@ void CheckUpdate(FRenderState& renderstate, sector_t* sector)
|
|||
CheckPlanes(renderstate, sector->e->XFloor.ffloors[i]->model);
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// Update the lightmap UV coordinates for the sector
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void UpdateVBOLightmap(FRenderState& renderstate, sector_t* sector)
|
||||
{
|
||||
UpdatePlaneLightmap(renderstate, sector, sector_t::ceiling, 0);
|
||||
UpdatePlaneLightmap(renderstate, sector, sector_t::floor, 0);
|
||||
|
||||
sector_t* hs = sector->GetHeightSec();
|
||||
if (hs != NULL)
|
||||
{
|
||||
UpdatePlaneLightmap(renderstate, hs, sector_t::ceiling, -1);
|
||||
UpdatePlaneLightmap(renderstate, hs, sector_t::floor, -1);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
|
|
|
|||
|
|
@ -71,6 +71,7 @@ VertexContainers BuildVertices(TArray<sector_t> §ors);
|
|||
|
||||
class FRenderState;
|
||||
void CheckUpdate(FRenderState& renderstate, sector_t* sector);
|
||||
void UpdateVBOLightmap(FRenderState& renderstate, sector_t* sector);
|
||||
void CreateVBO(FRenderState& renderstate, TArray<sector_t>& sectors);
|
||||
|
||||
extern TArray<FFlatVertex> sector_vertices;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue