From a9c8546ba3ae93534560fe00b6275ffee6886660 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 13 Aug 2018 23:13:06 +0200 Subject: [PATCH] - changed dynamic light setup so that it is completely in the processing pass, not the render pass. # Conflicts: # src/gl/scene/gl_flats.cpp # src/hwrenderer/scene/hw_flats.cpp --- src/gl/dynlights/gl_lightbuffer.cpp | 1 - src/gl/dynlights/gl_lightbuffer.h | 4 - src/gl/scene/gl_drawinfo.h | 4 - src/gl/scene/gl_flats.cpp | 115 +----------------------- src/gl/scene/gl_scene.cpp | 12 --- src/gl/scene/gl_sprite.cpp | 2 +- src/hwrenderer/scene/hw_drawinfo.h | 2 + src/hwrenderer/scene/hw_drawstructs.h | 4 +- src/hwrenderer/scene/hw_flats.cpp | 28 +++--- src/hwrenderer/scene/hw_renderhacks.cpp | 41 +++++++++ 10 files changed, 60 insertions(+), 153 deletions(-) diff --git a/src/gl/dynlights/gl_lightbuffer.cpp b/src/gl/dynlights/gl_lightbuffer.cpp index 465189937..145a90327 100644 --- a/src/gl/dynlights/gl_lightbuffer.cpp +++ b/src/gl/dynlights/gl_lightbuffer.cpp @@ -84,7 +84,6 @@ FLightBuffer::~FLightBuffer() void FLightBuffer::Clear() { mIndex = 0; - mIndices.Clear(); mUploadIndex = 0; } diff --git a/src/gl/dynlights/gl_lightbuffer.h b/src/gl/dynlights/gl_lightbuffer.h index 959dddcbd..be2026d09 100644 --- a/src/gl/dynlights/gl_lightbuffer.h +++ b/src/gl/dynlights/gl_lightbuffer.h @@ -6,7 +6,6 @@ class FLightBuffer { - TArray mIndices; unsigned int mBufferId; float * mBufferPointer; @@ -30,9 +29,6 @@ public: int BindUBO(unsigned int index); unsigned int GetBlockSize() const { return mBlockSize; } unsigned int GetBufferType() const { return mBufferType; } - unsigned int GetIndexPtr() const { return mIndices.Size(); } - void StoreIndex(int index) { mIndices.Push(index); } - int GetIndex(int i) const { return mIndices[i]; } }; int gl_SetDynModelLight(AActor *self, int dynlightindex); diff --git a/src/gl/scene/gl_drawinfo.h b/src/gl/scene/gl_drawinfo.h index 702c3981c..8f0e0dea4 100644 --- a/src/gl/scene/gl_drawinfo.h +++ b/src/gl/scene/gl_drawinfo.h @@ -28,7 +28,6 @@ enum DrawListType enum Drawpasses { GLPASS_ALL, // Main pass with dynamic lights - GLPASS_LIGHTSONLY, // only collect dynamic lights GLPASS_DECALS, // Draws a decal GLPASS_TRANSLUCENT, // Draws translucent objects }; @@ -76,10 +75,7 @@ struct FDrawInfo : public HWDrawInfo void DrawFlat(GLFlat *flat, int pass, bool trans) override; // trans only has meaning for GLPASS_LIGHTSONLY void DrawSkyboxSector(GLFlat *flat, int pass, bool processlights); void DrawSubsectors(GLFlat *flat, int pass, bool processlights, bool istrans); - void ProcessLights(GLFlat *flat, bool istrans); void DrawSubsector(GLFlat *flat, subsector_t * sub); - void SetupSubsectorLights(GLFlat *flat, int pass, subsector_t * sub, int *dli); - void SetupSectorLights(GLFlat *flat, int pass, int *dli); // Sprite drawer void DrawSprite(GLSprite *sprite, int pass); diff --git a/src/gl/scene/gl_flats.cpp b/src/gl/scene/gl_flats.cpp index 159a8e16a..ca18a589a 100644 --- a/src/gl/scene/gl_flats.cpp +++ b/src/gl/scene/gl_flats.cpp @@ -47,64 +47,6 @@ #include "gl/scene/gl_drawinfo.h" #include "gl/renderer/gl_quaddrawer.h" -//========================================================================== -// -// Flats -// -//========================================================================== - -void FDrawInfo::SetupSubsectorLights(GLFlat *flat, int pass, subsector_t * sub, int *dli) -{ - if (dli != NULL && *dli != -1) - { - if (flat->renderstyle == STYLE_Add && !level.lightadditivesurfaces) return; // no lights on additively blended surfaces. - gl_RenderState.ApplyLightIndex(GLRenderer->mLights->GetIndex(*dli)); - (*dli)++; - return; - } - if (flat->SetupSubsectorLights(pass, sub, lightdata)) - { - int d = GLRenderer->mLights->UploadLights(lightdata); - if (pass == GLPASS_LIGHTSONLY) - { - GLRenderer->mLights->StoreIndex(d); - } - else - { - gl_RenderState.ApplyLightIndex(d); - } - } -} - -//========================================================================== -// -// -// -//========================================================================== - -void FDrawInfo::SetupSectorLights(GLFlat *flat, int pass, int *dli) -{ - if (dli != NULL && *dli != -1) - { - if (flat->renderstyle == STYLE_Add && !level.lightadditivesurfaces) return; // no lights on additively blended surfaces. - gl_RenderState.ApplyLightIndex(GLRenderer->mLights->GetIndex(*dli)); - (*dli)++; - return; - } - if (flat->SetupSectorLights(pass, flat->sector, lightdata)) - { - int d = GLRenderer->mLights->UploadLights(lightdata); - if (pass == GLPASS_LIGHTSONLY) - { - GLRenderer->mLights->StoreIndex(d); - } - else - { - gl_RenderState.ApplyLightIndex(d); - } - } -} - //========================================================================== // // @@ -156,49 +98,6 @@ void FDrawInfo::DrawSubsector(GLFlat *flat, subsector_t * sub) } -//========================================================================== -// -// this is only used by LM_DEFERRED -// -//========================================================================== - -void FDrawInfo::ProcessLights(GLFlat *flat, bool istrans) -{ - flat->dynlightindex = GLRenderer->mLights->GetIndexPtr(); - - if (flat->sector->ibocount > 0 && !ClipLineShouldBeActive()) - { - SetupSectorLights(flat, GLPASS_LIGHTSONLY, nullptr); - } - else - { - // Draw the subsectors belonging to this sector - for (int i = 0; i < flat->sector->subsectorcount; i++) - { - subsector_t * sub = flat->sector->subsectors[i]; - if (ss_renderflags[sub->Index()] & flat->renderflags || istrans) - { - SetupSubsectorLights(flat, GLPASS_LIGHTSONLY, sub, nullptr); - } - } - } - - // Draw the subsectors assigned to it due to missing textures - if (!(flat->renderflags&SSRF_RENDER3DPLANES)) - { - gl_subsectorrendernode * node = (flat->renderflags&SSRF_RENDERFLOOR)? - GetOtherFloorPlanes(flat->sector->sectornum) : - GetOtherCeilingPlanes(flat->sector->sectornum); - - while (node) - { - SetupSubsectorLights(flat, GLPASS_LIGHTSONLY, node->sub, nullptr); - node = node->next; - } - } -} - - //========================================================================== // // @@ -213,11 +112,12 @@ void FDrawInfo::DrawSubsectors(GLFlat *flat, int pass, bool processlights, bool gl_RenderState.Apply(); auto iboindex = flat->iboindex; + if (processlights) gl_RenderState.ApplyLightIndex(flat->dynlightindex); + if (iboindex >= 0) { if (vcount > 0 && !ClipLineShouldBeActive()) { - if (processlights) SetupSectorLights(flat, GLPASS_ALL, &dli); drawcalls.Clock(); glDrawElements(GL_TRIANGLES, vcount, GL_UNSIGNED_INT, GLRenderer->mVBO->GetIndexPointer() + iboindex); drawcalls.Unclock(); @@ -234,7 +134,6 @@ void FDrawInfo::DrawSubsectors(GLFlat *flat, int pass, bool processlights, bool if (ss_renderflags[sub->Index()] & flat->renderflags || istrans) { - if (processlights) SetupSubsectorLights(flat, GLPASS_ALL, sub, &dli); drawcalls.Clock(); glDrawElements(GL_TRIANGLES, (sub->numlines - 2) * 3, GL_UNSIGNED_INT, GLRenderer->mVBO->GetIndexPointer() + index); drawcalls.Unclock(); @@ -253,7 +152,6 @@ void FDrawInfo::DrawSubsectors(GLFlat *flat, int pass, bool processlights, bool subsector_t * sub = flat->sector->subsectors[i]; if (ss_renderflags[sub->Index()]& flat->renderflags || istrans) { - if (processlights) SetupSubsectorLights(flat, GLPASS_ALL, sub, &dli); DrawSubsector(flat, sub); } } @@ -268,7 +166,7 @@ void FDrawInfo::DrawSubsectors(GLFlat *flat, int pass, bool processlights, bool while (node) { - if (processlights) SetupSubsectorLights(flat, GLPASS_ALL, node->sub, &dli); + if (processlights) gl_RenderState.ApplyLightIndex(node->lightindex); DrawSubsector(flat, node->sub); node = node->next; } @@ -328,13 +226,6 @@ void FDrawInfo::DrawFlat(GLFlat *flat, int pass, bool trans) // trans only has m gl_RenderState.SetObjectColor(0xffffffff); break; - case GLPASS_LIGHTSONLY: - if ((!trans || flat->gltexture) && processLights) - { - ProcessLights(flat, trans); - } - break; - case GLPASS_TRANSLUCENT: if (flat->renderstyle==STYLE_Add) gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE); SetColor(flat->lightlevel, rel, flat->Colormap, flat->alpha); diff --git a/src/gl/scene/gl_scene.cpp b/src/gl/scene/gl_scene.cpp index 1a83521f1..c643a7318 100644 --- a/src/gl/scene/gl_scene.cpp +++ b/src/gl/scene/gl_scene.cpp @@ -163,18 +163,6 @@ void FDrawInfo::RenderScene(int recursion) drawlists[GLDL_MASKEDWALLSOFS].SortWalls(); } - // if we don't have a persistently mapped buffer, we have to process all the dynamic lights up front, - // so that we don't have to do repeated map/unmap calls on the buffer. - if (gl.lightmethod == LM_DEFERRED && level.HasDynamicLights && !isFullbrightScene()) - { - GLRenderer->mLights->Begin(); - drawlists[GLDL_PLAINFLATS].DrawFlats(this, GLPASS_LIGHTSONLY); - drawlists[GLDL_MASKEDFLATS].DrawFlats(this, GLPASS_LIGHTSONLY); - drawlists[GLDL_TRANSLUCENTBORDER].Draw(this, GLPASS_LIGHTSONLY); - drawlists[GLDL_TRANSLUCENT].Draw(this, GLPASS_LIGHTSONLY, true); - GLRenderer->mLights->Finish(); - } - // Part 1: solid geometry. This is set up so that there are no transparent parts glDepthFunc(GL_LESS); gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f); diff --git a/src/gl/scene/gl_sprite.cpp b/src/gl/scene/gl_sprite.cpp index 985286a2a..665687d6e 100644 --- a/src/gl/scene/gl_sprite.cpp +++ b/src/gl/scene/gl_sprite.cpp @@ -71,7 +71,7 @@ void gl_SetRenderStyle(FRenderStyle style, bool drawopaque, bool allowcolorblend void FDrawInfo::DrawSprite(GLSprite *sprite, int pass) { - if (pass == GLPASS_DECALS || pass == GLPASS_LIGHTSONLY) return; + if (pass == GLPASS_DECALS) return; auto RenderStyle = sprite->RenderStyle; diff --git a/src/hwrenderer/scene/hw_drawinfo.h b/src/hwrenderer/scene/hw_drawinfo.h index 7f403e54d..57434d952 100644 --- a/src/hwrenderer/scene/hw_drawinfo.h +++ b/src/hwrenderer/scene/hw_drawinfo.h @@ -34,6 +34,7 @@ struct gl_subsectorrendernode { gl_subsectorrendernode * next; subsector_t * sub; + int lightindex; }; enum area_t : int; @@ -160,6 +161,7 @@ private: void AddSpecialPortalLines(subsector_t * sub, sector_t * sector, line_t *line); void RenderThings(subsector_t * sub, sector_t * sector); void DoSubsector(subsector_t * sub); + int SetupLightsForOtherPlane(subsector_t * sub, FDynLightData &lightdata, const secplane_t *plane); public: void SetCameraPos(const DVector3 &pos) diff --git a/src/hwrenderer/scene/hw_drawstructs.h b/src/hwrenderer/scene/hw_drawstructs.h index cdeb410ce..c84f8c179 100644 --- a/src/hwrenderer/scene/hw_drawstructs.h +++ b/src/hwrenderer/scene/hw_drawstructs.h @@ -315,9 +315,7 @@ public: int dynlightindex; void CreateSkyboxVertices(FFlatVertex *buffer); - bool SetupLights(int pass, FLightNode *head, FDynLightData &lightdata, int portalgroup); - bool SetupSubsectorLights(int pass, subsector_t * sub, FDynLightData &lightdata); - bool SetupSectorLights(int pass, sector_t * sec, FDynLightData &lightdata); + void SetupLights(HWDrawInfo *di, FLightNode *head, FDynLightData &lightdata, int portalgroup); void PutFlat(HWDrawInfo *di, bool fog = false); void Process(HWDrawInfo *di, sector_t * model, int whichplane, bool notexture); diff --git a/src/hwrenderer/scene/hw_flats.cpp b/src/hwrenderer/scene/hw_flats.cpp index 0c3ec07e4..33937f390 100644 --- a/src/hwrenderer/scene/hw_flats.cpp +++ b/src/hwrenderer/scene/hw_flats.cpp @@ -135,13 +135,15 @@ void GLFlat::CreateSkyboxVertices(FFlatVertex *vert) // //========================================================================== -bool GLFlat::SetupLights(int pass, FLightNode * node, FDynLightData &lightdata, int portalgroup) +void GLFlat::SetupLights(HWDrawInfo *di, FLightNode * node, FDynLightData &lightdata, int portalgroup) { Plane p; - lightdata.Clear(); - if (renderstyle == STYLE_Add && !level.lightadditivesurfaces) return false; // no lights on additively blended surfaces. - + if (renderstyle == STYLE_Add && !level.lightadditivesurfaces) + { + dynlightindex = -1; + return; // no lights on additively blended surfaces. + } while (node) { ADynamicLight * light = node->lightsource; @@ -167,17 +169,7 @@ bool GLFlat::SetupLights(int pass, FLightNode * node, FDynLightData &lightdata, node = node->nextLight; } - return true; -} - -bool GLFlat::SetupSubsectorLights(int pass, subsector_t * sub, FDynLightData &lightdata) -{ - return SetupLights(pass, sub->lighthead, lightdata, sub->sector->PortalGroup); -} - -bool GLFlat::SetupSectorLights(int pass, sector_t * sec, FDynLightData &lightdata) -{ - return SetupLights(pass, sec->lighthead, lightdata, sec->PortalGroup); + dynlightindex = di->UploadLights(lightdata); } //========================================================================== @@ -190,11 +182,15 @@ bool GLFlat::SetupSectorLights(int pass, sector_t * sec, FDynLightData &lightdat inline void GLFlat::PutFlat(HWDrawInfo *di, bool fog) { + if (di->isFullbrightScene()) { Colormap.Clear(); } - dynlightindex = -1; // make sure this is always initialized to something proper. + else if (level.HasDynamicLights && gltexture != nullptr) + { + SetupLights(di, sector->lighthead, lightdata, sector->PortalGroup); + } di->AddFlat(this, fog); } diff --git a/src/hwrenderer/scene/hw_renderhacks.cpp b/src/hwrenderer/scene/hw_renderhacks.cpp index 52f996f41..e918ec286 100644 --- a/src/hwrenderer/scene/hw_renderhacks.cpp +++ b/src/hwrenderer/scene/hw_renderhacks.cpp @@ -29,13 +29,52 @@ #include "r_utility.h" #include "r_sky.h" #include "g_levellocals.h" +#include "a_dynlight.h" #include "hw_drawinfo.h" #include "hw_drawstructs.h" #include "hwrenderer/utility/hw_clock.h" +#include "hwrenderer/dynlights/hw_dynlightdata.h" sector_t * hw_FakeFlat(sector_t * sec, sector_t * dest, area_t in_area, bool back); +//========================================================================== +// +// light setup for render hacks. +// This can ignore many of the special checks because +// this will never be translucent and never be part of a portal or a 3D floor +// +//========================================================================== + +int HWDrawInfo::SetupLightsForOtherPlane(subsector_t * sub, FDynLightData &lightdata, const secplane_t *plane) +{ + if (level.HasDynamicLights && !isFullbrightScene()) + { + Plane p; + FLightNode * node = sub->lighthead; + + lightdata.Clear(); + while (node) + { + ADynamicLight * light = node->lightsource; + + if (light->flags2&MF2_DORMANT) + { + node = node->nextLight; + continue; + } + iter_dlightf++; + + p.Set(plane->Normal(), plane->fD()); + lightdata.GetLight(sub->sector->PortalGroup, p, light, true); + node = node->nextLight; + } + + return UploadLights(lightdata); + } + else return -1; +} + //========================================================================== // // Adds a subsector plane to a sector's render list @@ -52,6 +91,7 @@ void HWDrawInfo::AddOtherFloorPlane(int sector, gl_subsectorrendernode * node) for(int i=oldcnt;i<=sector;i++) otherfloorplanes[i]=NULL; } node->next = otherfloorplanes[sector]; + node->lightindex = SetupLightsForOtherPlane(node->sub, lightdata, &node->sub->sector->floorplane); otherfloorplanes[sector] = node; } @@ -65,6 +105,7 @@ void HWDrawInfo::AddOtherCeilingPlane(int sector, gl_subsectorrendernode * node) for(int i=oldcnt;i<=sector;i++) otherceilingplanes[i]=NULL; } node->next = otherceilingplanes[sector]; + node->lightindex = SetupLightsForOtherPlane(node->sub, lightdata, &node->sub->sector->ceilingplane); otherceilingplanes[sector] = node; }