Visible surfaces are gathered in processing (gathering) render phase and lightmaps drawn before rendering

This commit is contained in:
RaveYard 2023-09-09 17:56:46 +02:00 committed by Christoph Oelckers
parent f279fa69f4
commit f0b1739b2d
4 changed files with 61 additions and 59 deletions

View file

@ -51,7 +51,6 @@
#include "hwrenderer/scene/hw_drawcontext.h"
#include "hw_vrmodes.h"
EXTERN_CVAR(Int, lm_background_updates);
EXTERN_CVAR(Bool, cl_capfps)
extern bool NoInterpolateView;
@ -97,34 +96,6 @@ void CollectLights(FLevelLocals* Level)
}
}
void UpdateLightmaps(DFrameBuffer* screen, FRenderState& RenderState)
{
// Lightmapping stuff
auto& list = RenderState.GetVisibleSurfaceList();
auto size = RenderState.GetVisibleSurfaceListCount();
list.Resize(min(list.Size(), unsigned(size)));
if (size < lm_background_updates)
{
int index = 0;
for (auto& e : level.levelMesh->Surfaces)
{
if (e.needsUpdate)
{
list.Push(index);
if (list.Size() >= lm_background_updates)
break;
}
++index;
}
}
screen->UpdateLightmaps(list);
}
//-----------------------------------------------------------------------------
//
// Renders one viewpoint in a scene
@ -152,7 +123,6 @@ sector_t* RenderViewpoint(FRenderViewpoint& mainvp, AActor* camera, IntRect* bou
screen->mShadowMap->SetCollectLights(nullptr);
}
RenderState.ClearVisibleSurfaceList();
screen->SetLevelMesh(camera->Level->levelMesh);
static HWDrawContext mainthread_drawctx;
@ -226,8 +196,6 @@ sector_t* RenderViewpoint(FRenderViewpoint& mainvp, AActor* camera, IntRect* bou
screen->NextEye(eyeCount);
}
UpdateLightmaps(screen, RenderState);
return mainvp.sector;
}

View file

@ -52,6 +52,7 @@ CVAR(Bool, gl_multithread, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
EXTERN_CVAR(Float, r_actorspriteshadowdist)
EXTERN_CVAR(Bool, gl_meshcache)
EXTERN_CVAR(Int, lm_background_updates);
thread_local bool isWorkerThread;
ctpl::thread_pool renderPool(1);
@ -856,8 +857,37 @@ void HWDrawInfo::RenderBSPNode (void *node, FRenderState& state)
DoSubsector ((subsector_t *)((uint8_t *)node - 1), state);
}
void UpdateLightmaps(DFrameBuffer* screen, FRenderState& RenderState)
{
// Lightmapping stuff
auto& list = RenderState.GetVisibleSurfaceList();
auto size = RenderState.GetVisibleSurfaceListCount();
list.Resize(min(list.Size(), unsigned(size)));
if (size < lm_background_updates)
{
int index = 0;
for (auto& e : level.levelMesh->Surfaces)
{
if (e.needsUpdate)
{
list.Push(index);
if (list.Size() >= lm_background_updates)
break;
}
++index;
}
}
screen->UpdateLightmaps(list);
}
void HWDrawInfo::RenderBSP(void *node, bool drawpsprites, FRenderState& state)
{
state.ClearVisibleSurfaceList();
Bsp.Clock();
// Give the DrawInfo the viewpoint in fixed point because that's what the nodes are.
@ -892,4 +922,6 @@ void HWDrawInfo::RenderBSP(void *node, bool drawpsprites, FRenderState& state)
if (drawpsprites)
PreparePlayerSprites(Viewpoint.sector, in_area, state);
UpdateLightmaps(screen, state);
}

View file

@ -191,28 +191,6 @@ void HWFlat::DrawSubsectors(HWDrawInfo *di, FRenderState &state)
SetupLights(di, state, section->lighthead, lightdata, sector->PortalGroup);
}
state.SetLightIndex(dynlightindex);
const auto* lm = &sector->Level->levelMesh->Surfaces[0]; // temporay hack on top of a temporary hack
for (auto& subsector : section->subsectors)
{
if (auto lightmap = subsector->lightmap[ceiling ? 1 : 0][0])
{
state.PushVisibleSurface(lightmap - lm, lightmap);
}
}
if (auto subsectors = sector->Level->levelMesh->XFloorToSurface.CheckKey(sector))
{
for (auto* surface : *subsectors)
{
if (surface)
{
state.PushVisibleSurface(surface - lm, surface);
}
}
}
state.DrawIndexed(DT_Triangles, iboindex + section->vertexindex, section->vertexcount);
flatvertices += section->vertexcount;
flatprimitives++;
@ -523,6 +501,31 @@ void HWFlat::ProcessSector(HWDrawInfo *di, FRenderState& state, sector_t * front
uint8_t &srf = hacktype? sink : di->section_renderflags[di->Level->sections.SectionIndex(section)];
const auto &vp = di->Viewpoint;
//
// Lightmaps
//
const auto* lm = &sector->Level->levelMesh->Surfaces[0]; // temporay hack on top of a temporary hack
for (auto& subsector : section->subsectors)
{
if (auto lightmap = subsector->lightmap[ceiling ? 1 : 0][0])
{
state.PushVisibleSurface(lightmap - lm, lightmap);
}
}
if (auto subsectors = sector->Level->levelMesh->XFloorToSurface.CheckKey(sector))
{
for (auto* surface : *subsectors)
{
if (surface)
{
state.PushVisibleSurface(surface - lm, surface);
}
}
}
//
//
//

View file

@ -347,11 +347,6 @@ void HWWall::DrawWall(HWDrawInfo *di, FRenderState &state, bool translucent)
MakeVertices(di, state, !!(flags & HWWall::HWF_TRANSLUCENT));
}
if (lightmap)
{
state.PushVisibleSurface(lightmap - &seg->Subsector->sector->Level->levelMesh->Surfaces[0], lightmap);
}
state.SetNormal(glseg.Normal());
if (!translucent)
{
@ -1270,6 +1265,10 @@ void HWWall::DoTexture(HWDrawInfo *di, FRenderState& state, int _type,seg_t * se
if (seg->sidedef->lightmap && type >= RENDERWALL_TOP && type <= RENDERWALL_BOTTOM)
{
lightmap = seg->sidedef->lightmap[type - RENDERWALL_TOP];
if (lightmap)
{
state.PushVisibleSurface(lightmap - &seg->Subsector->sector->Level->levelMesh->Surfaces[0], lightmap);
}
}
else
{