diff --git a/src/gl/renderer/gl_postprocess.cpp b/src/gl/renderer/gl_postprocess.cpp index be08075994..89a688ea14 100644 --- a/src/gl/renderer/gl_postprocess.cpp +++ b/src/gl/renderer/gl_postprocess.cpp @@ -73,6 +73,7 @@ void FGLRenderer::PostProcessScene(int fixedcm, const std::function &aft mCustomPostProcessShaders->Run("scene"); } + //----------------------------------------------------------------------------- // // Adds ambient occlusion to the scene diff --git a/src/gl/renderer/gl_renderer.cpp b/src/gl/renderer/gl_renderer.cpp index fd888e03c0..60ce968d70 100644 --- a/src/gl/renderer/gl_renderer.cpp +++ b/src/gl/renderer/gl_renderer.cpp @@ -326,8 +326,6 @@ sector_t *FGLRenderer::RenderView(player_t* player) GLSceneDrawer drawer; - drawer.SetFixedColormap(player); - mShadowMap.Update(); retsec = drawer.RenderViewpoint(player->camera, NULL, r_viewpoint.FieldOfView.Degrees, ratio, fovratio, true, true); } @@ -357,8 +355,6 @@ void FGLRenderer::RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint, doub bounds.height = FHardwareTexture::GetTexDimension(gltex->GetHeight()); GLSceneDrawer drawer; - drawer.FixedColormap = CM_DEFAULT; - gl_RenderState.SetFixedColormap(CM_DEFAULT); drawer.RenderViewpoint(Viewpoint, &bounds, FOV, (float)width / height, (float)width / height, false, false); EndOffscreen(); @@ -478,7 +474,6 @@ void FGLRenderer::Draw2D(F2DDrawer *drawer) auto vb = new F2DVertexBuffer; vb->UploadData(&vertices[0], vertices.Size(), &indices[0], indices.Size()); gl_RenderState.SetVertexBuffer(vb); - gl_RenderState.SetFixedColormap(CM_DEFAULT); gl_RenderState.EnableFog(false); for(auto &cmd : commands) @@ -493,6 +488,7 @@ void FGLRenderer::Draw2D(F2DDrawer *drawer) gl_RenderState.BlendEquation(be); gl_RenderState.BlendFunc(sb, db); gl_RenderState.EnableBrightmap(!(cmd.mRenderStyle.Flags & STYLEF_ColorIsFixed)); + gl_RenderState.EnableFog(2); // Special 2D mode 'fog'. // Rather than adding remapping code, let's enforce that the constants here are equal. static_assert(int(F2DDrawer::DTM_Normal) == int(TM_MODULATE), "DTM_Normal != TM_MODULATE"); @@ -515,18 +511,13 @@ void FGLRenderer::Draw2D(F2DDrawer *drawer) } else glDisable(GL_SCISSOR_TEST); - if (cmd.mSpecialColormap != nullptr) + if (cmd.mSpecialColormap[0].a != 0) { - auto index = cmd.mSpecialColormap - &SpecialColormaps[0]; - if (index < 0 || (unsigned)index >= SpecialColormaps.Size()) index = 0; // if it isn't in the table FBitmap cannot use it. Shouldn't happen anyway. - gl_RenderState.SetFixedColormap(CM_FIRSTSPECIALCOLORMAPFORCED + int(index)); + gl_RenderState.SetTextureMode(TM_FIXEDCOLORMAP); + gl_RenderState.SetObjectColor(cmd.mSpecialColormap[0]); + gl_RenderState.SetObjectColor2(cmd.mSpecialColormap[1]); } - else - { - gl_RenderState.SetFog(cmd.mColor1, 0); - gl_RenderState.SetFixedColormap(CM_PLAIN2D); - } - + gl_RenderState.SetFog(cmd.mColor1, 0); gl_RenderState.SetColor(1, 1, 1, 1, cmd.mDesaturate); gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f); @@ -570,7 +561,8 @@ void FGLRenderer::Draw2D(F2DDrawer *drawer) break; } - gl_RenderState.SetEffect(EFF_NONE); + gl_RenderState.SetObjectColor(0xffffffff); + gl_RenderState.SetObjectColor2(0); gl_RenderState.EnableTextureMatrix(false); } glDisable(GL_SCISSOR_TEST); @@ -579,7 +571,7 @@ void FGLRenderer::Draw2D(F2DDrawer *drawer) gl_RenderState.EnableTexture(true); gl_RenderState.EnableBrightmap(true); gl_RenderState.SetTextureMode(TM_MODULATE); - gl_RenderState.SetFixedColormap(CM_DEFAULT); + gl_RenderState.EnableFog(false); gl_RenderState.ResetColor(); gl_RenderState.Apply(); delete vb; diff --git a/src/gl/renderer/gl_renderstate.cpp b/src/gl/renderer/gl_renderstate.cpp index 9ce22f1705..9a57719827 100644 --- a/src/gl/renderer/gl_renderstate.cpp +++ b/src/gl/renderer/gl_renderstate.cpp @@ -77,7 +77,6 @@ void FRenderState::Reset() mObjectColor = 0xffffffff; mObjectColor2 = 0; mVertexBuffer = mCurrentVertexBuffer = NULL; - mColormapState = CM_DEFAULT; mSoftLight = 0; mLightParms[0] = mLightParms[1] = mLightParms[2] = 0.0f; mLightParms[3] = -1.f; @@ -144,7 +143,11 @@ bool FRenderState::ApplyShader() if (mFogEnabled) { - if ((mFogColor & 0xffffff) == 0) + if (mFogEnabled == 2) + { + fogset = -3; // 2D rendering with 'foggy' overlay. + } + else if ((mFogColor & 0xffffff) == 0) { fogset = gl_fogmode; } @@ -221,73 +224,6 @@ bool FRenderState::ApplyShader() activeShader->currentcliplinestate = 0; } - if (mColormapState == CM_PLAIN2D) // 2D operations - { - activeShader->muFixedColormap.Set(4); - activeShader->currentfixedcolormap = mColormapState; - } - else if (mColormapState != activeShader->currentfixedcolormap) - { - float r, g, b; - activeShader->currentfixedcolormap = mColormapState; - if (mColormapState == CM_DEFAULT) - { - activeShader->muFixedColormap.Set(0); - } - else if ((mColormapState >= CM_FIRSTSPECIALCOLORMAP && mColormapState < CM_MAXCOLORMAPFORCED)) - { - if (mColormapState < CM_FIRSTSPECIALCOLORMAPFORCED) - { - // When using postprocessing to apply the colormap, we must render the image fullbright here. - activeShader->muFixedColormap.Set(2); - activeShader->muColormapStart.Set(1, 1, 1, 1.f); - } - else - { - if (mColormapState >= CM_FIRSTSPECIALCOLORMAPFORCED) - { - auto colormapState = mColormapState + CM_FIRSTSPECIALCOLORMAP - CM_FIRSTSPECIALCOLORMAPFORCED; - if (colormapState < CM_MAXCOLORMAP) - { - FSpecialColormap *scm = &SpecialColormaps[colormapState - CM_FIRSTSPECIALCOLORMAP]; - float m[] = { scm->ColorizeEnd[0] - scm->ColorizeStart[0], - scm->ColorizeEnd[1] - scm->ColorizeStart[1], scm->ColorizeEnd[2] - scm->ColorizeStart[2], 0.f }; - - activeShader->muFixedColormap.Set(1); - activeShader->muColormapStart.Set(scm->ColorizeStart[0], scm->ColorizeStart[1], scm->ColorizeStart[2], 0.f); - activeShader->muColormapRange.Set(m); - } - } - } - } - else if (mColormapState == CM_FOGLAYER) - { - activeShader->muFixedColormap.Set(3); - } - else if (mColormapState == CM_LITE) - { - if (gl_enhanced_nightvision) - { - r = 0.375f, g = 1.0f, b = 0.375f; - } - else - { - r = g = b = 1.f; - } - activeShader->muFixedColormap.Set(2); - activeShader->muColormapStart.Set(r, g, b, 1.f); - } - else if (mColormapState >= CM_TORCH) - { - int flicker = mColormapState - CM_TORCH; - r = (0.8f + (7 - flicker) / 70.0f); - if (r > 1.0f) r = 1.0f; - b = g = r; - if (gl_enhanced_nightvision) b = g * 0.75f; - activeShader->muFixedColormap.Set(2); - activeShader->muColormapStart.Set(r, g, b, 1.f); - } - } if (mTextureMatrixEnabled) { matrixToGL(mTextureMatrix, activeShader->texturematrix_index); diff --git a/src/gl/renderer/gl_renderstate.h b/src/gl/renderer/gl_renderstate.h index 993b98ab5c..b188b42d23 100644 --- a/src/gl/renderer/gl_renderstate.h +++ b/src/gl/renderer/gl_renderstate.h @@ -61,7 +61,6 @@ enum EEffect EFF_SPHEREMAP, EFF_BURN, EFF_STENCIL, - EFF_SWQUAD, MAX_EFFECTS }; @@ -77,7 +76,7 @@ class FRenderState { friend void gl_SetTextureMode(int type); bool mTextureEnabled; - bool mFogEnabled; + uint8_t mFogEnabled; bool mGlowEnabled; bool mSplitEnabled; bool mClipLineEnabled; @@ -116,7 +115,6 @@ class FRenderState float mClipSplit[2]; int mEffectState; - int mColormapState; int mTempTM = TM_MODULATE; float stAlphaThreshold; @@ -276,7 +274,7 @@ public: mTextureEnabled = on; } - void EnableFog(bool on) + void EnableFog(uint8_t on) { mFogEnabled = on; } @@ -417,16 +415,6 @@ public: mLightParms[0] = d; } - void SetFixedColormap(int cm) - { - mColormapState = cm; - } - - int GetFixedColormap() - { - return mColormapState; - } - PalEntry GetFogColor() const { return mFogColor; diff --git a/src/gl/scene/gl_drawinfo.cpp b/src/gl/scene/gl_drawinfo.cpp index 74dc7708d4..cdb16c9b35 100644 --- a/src/gl/scene/gl_drawinfo.cpp +++ b/src/gl/scene/gl_drawinfo.cpp @@ -197,7 +197,6 @@ FDrawInfo *FDrawInfo::StartDrawInfo(GLSceneDrawer *drawer) di->mVBO = GLRenderer->mVBO; di->mClipper = &staticClipper; staticClipper.Clear(); - di->FixedColormap = drawer->FixedColormap; di->StartScene(); return di; } @@ -212,6 +211,11 @@ void FDrawInfo::StartScene() decals[0].Clear(); decals[1].Clear(); hudsprites.Clear(); + + // Fullbright information needs to be propagated from the main view. + if (next != nullptr) FullbrightFlags = next->FullbrightFlags; + else FullbrightFlags = 0; + } //========================================================================== @@ -316,7 +320,7 @@ void FDrawInfo::DrawFloodedPlane(wallseg * ws, float planez, sector_t * sec, boo gltexture=FMaterial::ValidateTexture(plane.texture, false, true); if (!gltexture) return; - if (mDrawer->FixedColormap) + if (isFullbrightScene()) { Colormap.Clear(); lightlevel=255; @@ -333,8 +337,8 @@ void FDrawInfo::DrawFloodedPlane(wallseg * ws, float planez, sector_t * sec, boo } int rel = getExtraLight(); - mDrawer->SetColor(lightlevel, rel, Colormap, 1.0f); - mDrawer->SetFog(lightlevel, rel, &Colormap, false); + SetColor(lightlevel, rel, Colormap, 1.0f); + SetFog(lightlevel, rel, &Colormap, false); gl_RenderState.SetMaterial(gltexture, CLAMP_NONE, 0, -1, false); float fviewx = r_viewpoint.Pos.X; diff --git a/src/gl/scene/gl_drawinfo.h b/src/gl/scene/gl_drawinfo.h index 35c78af22a..f069f2736f 100644 --- a/src/gl/scene/gl_drawinfo.h +++ b/src/gl/scene/gl_drawinfo.h @@ -1,6 +1,7 @@ #ifndef __GL_DRAWINFO_H #define __GL_DRAWINFO_H +#include "gl/renderer/gl_lightdata.h" #include "hwrenderer/scene/hw_drawlist.h" #include "hwrenderer/scene/hw_weapon.h" @@ -119,6 +120,17 @@ struct FDrawInfo : public HWDrawInfo if (sectormLights->GetIndex(*dli)); @@ -85,7 +85,7 @@ void FDrawInfo::SetupSubsectorLights(GLFlat *flat, int pass, subsector_t * sub, void FDrawInfo::SetupSectorLights(GLFlat *flat, int pass, int *dli) { - if (FixedColormap != CM_DEFAULT) return; + if (isFullbrightScene()) return; if (dli != NULL && *dli != -1) { gl_RenderState.ApplyLightIndex(GLRenderer->mLights->GetIndex(*dli)); @@ -341,8 +341,8 @@ void FDrawInfo::DrawFlat(GLFlat *flat, int pass, bool trans) // trans only has m switch (pass) { case GLPASS_ALL: // Single-pass rendering - mDrawer->SetColor(flat->lightlevel, rel, flat->Colormap,1.0f); - mDrawer->SetFog(flat->lightlevel, rel, &flat->Colormap, false); + SetColor(flat->lightlevel, rel, flat->Colormap,1.0f); + SetFog(flat->lightlevel, rel, &flat->Colormap, false); if (!flat->gltexture->tex->isFullbright()) gl_RenderState.SetObjectColor(flat->FlatColor | 0xff000000); if (flat->sector->special != GLSector_Skybox) @@ -369,8 +369,8 @@ void FDrawInfo::DrawFlat(GLFlat *flat, int pass, bool trans) // trans only has m case GLPASS_TRANSLUCENT: if (flat->renderstyle==STYLE_Add) gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE); - mDrawer->SetColor(flat->lightlevel, rel, flat->Colormap, flat->alpha); - mDrawer->SetFog(flat->lightlevel, rel, &flat->Colormap, false); + SetColor(flat->lightlevel, rel, flat->Colormap, flat->alpha); + SetFog(flat->lightlevel, rel, &flat->Colormap, false); if (!flat->gltexture || !flat->gltexture->tex->isFullbright()) gl_RenderState.SetObjectColor(flat->FlatColor | 0xff000000); if (!flat->gltexture) diff --git a/src/gl/scene/gl_portal.cpp b/src/gl/scene/gl_portal.cpp index 3f8ede410a..8c82e387b4 100644 --- a/src/gl/scene/gl_portal.cpp +++ b/src/gl/scene/gl_portal.cpp @@ -1134,14 +1134,14 @@ void GLHorizonPortal::DrawContents(FDrawInfo *di) if (gltexture && gltexture->tex->isFullbright()) { // glowing textures are always drawn full bright without color - drawer->SetColor(255, 0, origin->colormap, 1.f); - drawer->SetFog(255, 0, &origin->colormap, false); + di->SetColor(255, 0, origin->colormap, 1.f); + di->SetFog(255, 0, &origin->colormap, false); } else { int rel = getExtraLight(); - drawer->SetColor(origin->lightlevel, rel, origin->colormap, 1.0f); - drawer->SetFog(origin->lightlevel, rel, &origin->colormap, false); + di->SetColor(origin->lightlevel, rel, origin->colormap, 1.0f); + di->SetFog(origin->lightlevel, rel, &origin->colormap, false); } diff --git a/src/gl/scene/gl_scene.cpp b/src/gl/scene/gl_scene.cpp index 2517d3a8aa..73421a52a3 100644 --- a/src/gl/scene/gl_scene.cpp +++ b/src/gl/scene/gl_scene.cpp @@ -291,7 +291,7 @@ void GLSceneDrawer::RenderScene(FDrawInfo *di, int recursion) // 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 && FixedColormap == CM_DEFAULT) + if (gl.lightmethod == LM_DEFERRED && level.HasDynamicLights && !di->isFullbrightScene()) { GLRenderer->mLights->Begin(); di->drawlists[GLDL_PLAINFLATS].DrawFlats(di, GLPASS_LIGHTSONLY); @@ -487,19 +487,11 @@ void GLSceneDrawer::EndDrawScene(FDrawInfo *di, sector_t * viewsector) Reset3DViewport(); - // Delay drawing psprites until after bloom has been applied, if enabled. - if (!gl_bloom || FixedColormap != CM_DEFAULT) - { - DrawEndScene2D(di, viewsector); - } - else - { - // Restore standard rendering state - gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - gl_RenderState.ResetColor(); - gl_RenderState.EnableTexture(true); - glDisable(GL_SCISSOR_TEST); - } + // Restore standard rendering state + gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + gl_RenderState.ResetColor(); + gl_RenderState.EnableTexture(true); + glDisable(GL_SCISSOR_TEST); } void GLSceneDrawer::DrawEndScene2D(FDrawInfo *di, sector_t * viewsector) @@ -516,7 +508,6 @@ void GLSceneDrawer::DrawEndScene2D(FDrawInfo *di, sector_t * viewsector) di->DrawPlayerSprites(false); - gl_RenderState.SetFixedColormap(CM_DEFAULT); gl_RenderState.SetSoftLightLevel(-1); // Restore standard rendering state @@ -544,52 +535,6 @@ void GLSceneDrawer::ProcessScene(FDrawInfo *di, bool toscreen) } -//----------------------------------------------------------------------------- -// -// gl_SetFixedColormap -// -//----------------------------------------------------------------------------- - -void GLSceneDrawer::SetFixedColormap (player_t *player) -{ - FixedColormap=CM_DEFAULT; - - // check for special colormaps - player_t * cplayer = player->camera->player; - if (cplayer) - { - if (cplayer->extralight == INT_MIN) - { - FixedColormap=CM_FIRSTSPECIALCOLORMAP + INVERSECOLORMAP; - r_viewpoint.extralight=0; - } - else if (cplayer->fixedcolormap != NOFIXEDCOLORMAP) - { - FixedColormap = CM_FIRSTSPECIALCOLORMAP + cplayer->fixedcolormap; - } - else if (cplayer->fixedlightlevel != -1) - { - auto torchtype = PClass::FindActor(NAME_PowerTorch); - auto litetype = PClass::FindActor(NAME_PowerLightAmp); - for(AInventory * in = cplayer->mo->Inventory; in; in = in->Inventory) - { - PalEntry color = in->CallGetBlend (); - - // Need special handling for light amplifiers - if (in->IsKindOf(torchtype)) - { - FixedColormap = cplayer->fixedlightlevel + CM_TORCH; - } - else if (in->IsKindOf(litetype)) - { - FixedColormap = CM_LITE; - } - } - } - } - gl_RenderState.SetFixedColormap(FixedColormap); -} - //----------------------------------------------------------------------------- // // Renders one viewpoint in a scene @@ -634,8 +579,6 @@ sector_t * GLSceneDrawer::RenderViewpoint (AActor * camera, IntRect * bounds, fl stereo3dMode.SetUp(); for (int eye_ix = 0; eye_ix < stereo3dMode.eye_count(); ++eye_ix) { - if (eye_ix > 0 && camera->player) - SetFixedColormap(camera->player); // reiterate color map for each eye, so night vision goggles work in both eyes const s3d::EyePose * eye = stereo3dMode.getEyePose(eye_ix); eye->SetUp(); screen->SetViewportRects(bounds); @@ -645,6 +588,7 @@ sector_t * GLSceneDrawer::RenderViewpoint (AActor * camera, IntRect * bounds, fl FDrawInfo *di = FDrawInfo::StartDrawInfo(this); di->SetViewArea(); + auto cm = di->SetFullbrightFlags(mainview ? r_viewpoint.camera->player : nullptr); // Stereo mode specific perspective projection SetProjection( eye->GetProjection(fov, ratio, fovratio) ); @@ -661,7 +605,7 @@ sector_t * GLSceneDrawer::RenderViewpoint (AActor * camera, IntRect * bounds, fl if (mainview) { - GLRenderer->PostProcessScene(FixedColormap, [&]() { if (gl_bloom && FixedColormap == CM_DEFAULT) DrawEndScene2D(di, lviewsector); }); + GLRenderer->PostProcessScene(cm, [&]() { DrawEndScene2D(di, lviewsector); }); // This should be done after postprocessing, not before. GLRenderer->mBuffers->BindCurrentFB(); @@ -707,14 +651,12 @@ void GLSceneDrawer::WriteSavePic (player_t *player, FileWriter *file, int width, GLRenderer->mBuffers = GLRenderer->mSaveBuffers; P_FindParticleSubsectors(); // make sure that all recently spawned particles have a valid subsector. - SetFixedColormap(player); gl_RenderState.SetVertexBuffer(GLRenderer->mVBO); GLRenderer->mVBO->Reset(); GLRenderer->mLights->Clear(); sector_t *viewsector = RenderViewpoint(players[consoleplayer].camera, &bounds, r_viewpoint.FieldOfView.Degrees, 1.6f, 1.6f, true, false); glDisable(GL_STENCIL_TEST); - gl_RenderState.SetFixedColormap(CM_DEFAULT); gl_RenderState.SetSoftLightLevel(-1); GLRenderer->CopyToBackbuffer(&bounds, false); diff --git a/src/gl/scene/gl_scenedrawer.h b/src/gl/scene/gl_scenedrawer.h index 3396c269c9..3f088fd6b4 100644 --- a/src/gl/scene/gl_scenedrawer.h +++ b/src/gl/scene/gl_scenedrawer.h @@ -28,16 +28,14 @@ public: GLPortal::drawer = this; } - int FixedColormap; - angle_t FrustumAngle(); + void SetViewMatrix(float vx, float vy, float vz, bool mirror, bool planemirror); void SetupView(float vx, float vy, float vz, DAngle va, bool mirror, bool planemirror); void SetViewAngle(DAngle viewangle); void SetProjection(VSMatrix matrix); void Set3DViewport(bool mainview); void Reset3DViewport(); - void SetFixedColormap(player_t *player); void DrawScene(FDrawInfo *di, int drawmode); void ProcessScene(FDrawInfo *di, bool toscreen = false); void EndDrawScene(FDrawInfo *di, sector_t * viewsector); @@ -46,20 +44,4 @@ public: sector_t *RenderViewpoint(AActor * camera, IntRect * bounds, float fov, float ratio, float fovratio, bool mainview, bool toscreen); sector_t *RenderView(player_t *player); void WriteSavePic(player_t *player, FileWriter *file, int width, int height); - - void SetColor(int light, int rellight, const FColormap &cm, float alpha, bool weapon = false) - { - gl_SetColor(light, rellight, FixedColormap != CM_DEFAULT, cm, alpha, weapon); - } - - bool CheckFog(sector_t *frontsector, sector_t *backsector) - { - if (FixedColormap != CM_DEFAULT) return false; - return hw_CheckFog(frontsector, backsector); - } - - void SetFog(int lightlevel, int rellight, const FColormap *cmap, bool isadditive) - { - gl_SetFog(lightlevel, rellight, FixedColormap != CM_DEFAULT, cmap, isadditive); - } }; diff --git a/src/gl/scene/gl_skydome.cpp b/src/gl/scene/gl_skydome.cpp index dbe72cb223..4077387545 100644 --- a/src/gl/scene/gl_skydome.cpp +++ b/src/gl/scene/gl_skydome.cpp @@ -299,7 +299,7 @@ void GLSkyPortal::DrawContents(FDrawInfo *di) RenderDome(origin->texture[1], origin->x_offset[1], origin->y_offset, false, FSkyVertexBuffer::SKYMODE_SECONDLAYER); } - if (::level.skyfog>0 && drawer->FixedColormap == CM_DEFAULT && (origin->fadecolor & 0xffffff) != 0) + if (::level.skyfog>0 && !di->isFullbrightScene() && (origin->fadecolor & 0xffffff) != 0) { PalEntry FadeColor = origin->fadecolor; FadeColor.a = clamp(::level.skyfog, 0, 255); diff --git a/src/gl/scene/gl_sprite.cpp b/src/gl/scene/gl_sprite.cpp index b4116d60eb..039e973263 100644 --- a/src/gl/scene/gl_sprite.cpp +++ b/src/gl/scene/gl_sprite.cpp @@ -92,7 +92,7 @@ void FDrawInfo::DrawSprite(GLSprite *sprite, int pass) gl_SetRenderStyle(RenderStyle, false, // The rest of the needed checks are done inside gl_SetRenderStyle - sprite->trans > 1.f - FLT_EPSILON && gl_usecolorblending && mDrawer->FixedColormap == CM_DEFAULT && sprite->actor && + sprite->trans > 1.f - FLT_EPSILON && gl_usecolorblending && !isFullbrightScene() && sprite->actor && sprite->fullbright && sprite->gltexture && !sprite->gltexture->tex->GetTranslucency()); if (sprite->hw_styleflags == STYLEHW_NoAlphaTest) @@ -144,7 +144,7 @@ void FDrawInfo::DrawSprite(GLSprite *sprite, int pass) } if (RenderStyle.BlendOp != STYLEOP_Shadow) { - if (level.HasDynamicLights && mDrawer->FixedColormap == CM_DEFAULT && !sprite->fullbright) + if (level.HasDynamicLights && !isFullbrightScene() && !sprite->fullbright) { if ( sprite->dynlightindex == -1) // only set if we got no light buffer index. This covers all cases where sprite lighting is used. { @@ -162,7 +162,7 @@ void FDrawInfo::DrawSprite(GLSprite *sprite, int pass) gl_RenderState.SetObjectColor(finalcol); } - mDrawer->SetColor(sprite->lightlevel, rel, sprite->Colormap, sprite->trans); + SetColor(sprite->lightlevel, rel, sprite->Colormap, sprite->trans); } @@ -189,7 +189,7 @@ void FDrawInfo::DrawSprite(GLSprite *sprite, int pass) else RenderStyle.BlendOp = STYLEOP_Fuzz; // subtractive with models is not going to work. } - if (!foglayer) mDrawer->SetFog(sprite->foglevel, rel, &sprite->Colormap, additivefog); + if (!foglayer) SetFog(sprite->foglevel, rel, &sprite->Colormap, additivefog); else { gl_RenderState.EnableFog(false); @@ -199,7 +199,7 @@ void FDrawInfo::DrawSprite(GLSprite *sprite, int pass) if (sprite->gltexture) gl_RenderState.SetMaterial(sprite->gltexture, CLAMP_XY, sprite->translation, sprite->OverrideShader, !!(RenderStyle.Flags & STYLEF_RedIsAlpha)); else if (!sprite->modelframe) gl_RenderState.EnableTexture(false); - //mDrawer->SetColor(lightlevel, rel, Colormap, trans); + //SetColor(lightlevel, rel, Colormap, trans); unsigned int iter = sprite->lightlist? sprite->lightlist->Size() : 1; bool clipping = false; @@ -231,10 +231,10 @@ void FDrawInfo::DrawSprite(GLSprite *sprite, int pass) thiscm.Decolorize(); } - mDrawer->SetColor(thisll, rel, thiscm, sprite->trans); + SetColor(thisll, rel, thiscm, sprite->trans); if (!foglayer) { - mDrawer->SetFog(thislight, rel, &thiscm, additivefog); + SetFog(thislight, rel, &thiscm, additivefog); } gl_RenderState.SetSplitPlanes(*topplane, *lowplane); } @@ -265,7 +265,7 @@ void FDrawInfo::DrawSprite(GLSprite *sprite, int pass) if (foglayer) { // If we get here we know that we have colored fog and no fixed colormap. - mDrawer->SetFog(sprite->foglevel, rel, &sprite->Colormap, additivefog); + SetFog(sprite->foglevel, rel, &sprite->Colormap, additivefog); gl_RenderState.SetTextureMode(TM_FOGLAYER); gl_RenderState.BlendEquation(GL_FUNC_ADD); gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); diff --git a/src/gl/scene/gl_walls_draw.cpp b/src/gl/scene/gl_walls_draw.cpp index f4eb806832..173c3311ec 100644 --- a/src/gl/scene/gl_walls_draw.cpp +++ b/src/gl/scene/gl_walls_draw.cpp @@ -65,10 +65,10 @@ void FDrawInfo::RenderWall(GLWall *wall, int textured) void FDrawInfo::RenderFogBoundary(GLWall *wall) { - if (gl_fogmode && mDrawer->FixedColormap == 0) + if (gl_fogmode && !isFullbrightScene()) { int rel = wall->rellight + getExtraLight(); - mDrawer->SetFog(wall->lightlevel, rel, &wall->Colormap, false); + SetFog(wall->lightlevel, rel, &wall->Colormap, false); gl_RenderState.EnableDrawBuffers(1); gl_RenderState.SetEffect(EFF_FOGBOUNDARY); gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f); @@ -99,8 +99,8 @@ void FDrawInfo::RenderMirrorSurface(GLWall *wall) // Use sphere mapping for this gl_RenderState.SetEffect(EFF_SPHEREMAP); - mDrawer->SetColor(wall->lightlevel, 0, wall->Colormap ,0.1f); - mDrawer->SetFog(wall->lightlevel, 0, &wall->Colormap, true); + SetColor(wall->lightlevel, 0, wall->Colormap ,0.1f); + SetFog(wall->lightlevel, 0, &wall->Colormap, true); gl_RenderState.BlendFunc(GL_SRC_ALPHA,GL_ONE); gl_RenderState.AlphaFunc(GL_GREATER,0); glDepthFunc(GL_LEQUAL); @@ -161,7 +161,7 @@ void FDrawInfo::RenderTexturedWall(GLWall *wall, int rflags) { if (tmode == TM_MODULATE) gl_RenderState.SetTextureMode(TM_CLAMPY); } - mDrawer->SetFog(255, 0, nullptr, false); + SetFog(255, 0, nullptr, false); } gl_RenderState.SetObjectColor(wall->seg->frontsector->SpecialColors[sector_t::walltop] | 0xff000000); gl_RenderState.SetObjectColor2(wall->seg->frontsector->SpecialColors[sector_t::wallbottom] | 0xff000000); @@ -169,8 +169,8 @@ void FDrawInfo::RenderTexturedWall(GLWall *wall, int rflags) float absalpha = fabsf(wall->alpha); if (wall->lightlist == nullptr) { - if (wall->type != RENDERWALL_M2SNF) mDrawer->SetFog(wall->lightlevel, rel, &wall->Colormap, wall->RenderStyle == STYLE_Add); - mDrawer->SetColor(wall->lightlevel, rel, wall->Colormap, absalpha); + if (wall->type != RENDERWALL_M2SNF) SetFog(wall->lightlevel, rel, &wall->Colormap, wall->RenderStyle == STYLE_Add); + SetColor(wall->lightlevel, rel, wall->Colormap, absalpha); RenderWall(wall, rflags); } else @@ -191,8 +191,8 @@ void FDrawInfo::RenderTexturedWall(GLWall *wall, int rflags) thiscm.FadeColor = wall->Colormap.FadeColor; thiscm.FogDensity = wall->Colormap.FogDensity; thiscm.CopyFrom3DLight(&(*wall->lightlist)[i]); - mDrawer->SetColor(thisll, rel, thiscm, absalpha); - if (wall->type != RENDERWALL_M2SNF) mDrawer->SetFog(thisll, rel, &thiscm, wall->RenderStyle == STYLE_Add); + SetColor(thisll, rel, thiscm, absalpha); + if (wall->type != RENDERWALL_M2SNF) SetFog(thisll, rel, &thiscm, wall->RenderStyle == STYLE_Add); gl_RenderState.SetSplitPlanes((*wall->lightlist)[i].plane, lowplane); RenderWall(wall, rflags); } @@ -226,8 +226,8 @@ void FDrawInfo::RenderTranslucentWall(GLWall *wall) else { gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f); - mDrawer->SetColor(wall->lightlevel, 0, wall->Colormap, fabsf(wall->alpha)); - mDrawer->SetFog(wall->lightlevel, 0, &wall->Colormap, wall->RenderStyle == STYLE_Add); + SetColor(wall->lightlevel, 0, wall->Colormap, fabsf(wall->alpha)); + SetFog(wall->lightlevel, 0, &wall->Colormap, wall->RenderStyle == STYLE_Add); gl_RenderState.EnableTexture(false); RenderWall(wall, GLWall::RWF_NOSPLIT); gl_RenderState.EnableTexture(true); @@ -243,7 +243,7 @@ void FDrawInfo::DrawWall(GLWall *wall, int pass) { if (screen->hwcaps & RFL_BUFFER_STORAGE) { - if (level.HasDynamicLights && FixedColormap == CM_DEFAULT && wall->gltexture != nullptr) + if (level.HasDynamicLights && !isFullbrightScene() && wall->gltexture != nullptr) { wall->SetupLights(this, lightdata); } @@ -426,7 +426,7 @@ void FDrawInfo::DrawDecal(GLDecal *gldecal) auto tex = gldecal->gltexture; // calculate dynamic light effect. - if (level.HasDynamicLights && !mDrawer->FixedColormap && gl_light_sprites) + if (level.HasDynamicLights && !isFullbrightScene() && gl_light_sprites) { // Note: This should be replaced with proper shader based lighting. double x, y; @@ -451,7 +451,7 @@ void FDrawInfo::DrawDecal(GLDecal *gldecal) else gl_RenderState.AlphaFunc(GL_GREATER, 0.f); - mDrawer->SetColor(gldecal->lightlevel, gldecal->rellight, gldecal->Colormap, gldecal->alpha); + SetColor(gldecal->lightlevel, gldecal->rellight, gldecal->Colormap, gldecal->alpha); // for additively drawn decals we must temporarily set the fog color to black. PalEntry fc = gl_RenderState.GetFogColor(); if (decal->RenderStyle.BlendOp == STYLEOP_Add && decal->RenderStyle.DestAlpha == STYLEALPHA_One) @@ -484,9 +484,9 @@ void FDrawInfo::DrawDecal(GLDecal *gldecal) FColormap thiscm; thiscm.FadeColor = gldecal->Colormap.FadeColor; thiscm.CopyFrom3DLight(&lightlist[k]); - mDrawer->SetColor(thisll, gldecal->rellight, thiscm, gldecal->alpha); + SetColor(thisll, gldecal->rellight, thiscm, gldecal->alpha); if (level.flags3 & LEVEL3_NOCOLOREDSPRITELIGHTING) thiscm.Decolorize(); - mDrawer->SetFog(thisll, gldecal->rellight, &thiscm, false); + SetFog(thisll, gldecal->rellight, &thiscm, false); gl_RenderState.SetSplitPlanes(lightlist[k].plane, lowplane); gl_RenderState.Apply(); @@ -526,7 +526,7 @@ void FDrawInfo::DrawDecals() { gl_RenderState.EnableSplit(false); splitting = false; - mDrawer->SetFog(gldecal->lightlevel, gldecal->rellight, &gldecal->Colormap, false); + SetFog(gldecal->lightlevel, gldecal->rellight, &gldecal->Colormap, false); } } DrawDecal(gldecal); @@ -541,7 +541,7 @@ void FDrawInfo::DrawDecals() //========================================================================== void FDrawInfo::DrawDecalsForMirror(GLWall *wall) { - mDrawer->SetFog(wall->lightlevel, wall->rellight + getExtraLight(), &wall->Colormap, false); + SetFog(wall->lightlevel, wall->rellight + getExtraLight(), &wall->Colormap, false); for (auto gldecal : decals[1]) { if (gldecal->decal->Side == wall->seg->sidedef) diff --git a/src/gl/scene/gl_weapon.cpp b/src/gl/scene/gl_weapon.cpp index 6ab0d52228..07114369be 100644 --- a/src/gl/scene/gl_weapon.cpp +++ b/src/gl/scene/gl_weapon.cpp @@ -56,7 +56,7 @@ void FDrawInfo::DrawPSprite (HUDSprite *huds) } else { - mDrawer->SetColor(huds->lightlevel, 0, huds->cm, huds->alpha, true); + SetColor(huds->lightlevel, 0, huds->cm, huds->alpha, true); } gl_SetRenderStyle(huds->RenderStyle, false, false); gl_RenderState.SetObjectColor(huds->ObjectColor); diff --git a/src/gl/shaders/gl_shader.cpp b/src/gl/shaders/gl_shader.cpp index f81ff79ff5..5293187fdc 100644 --- a/src/gl/shaders/gl_shader.cpp +++ b/src/gl/shaders/gl_shader.cpp @@ -70,11 +70,6 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char * i_data += "uniform float uDesaturationFactor;\n"; i_data += "uniform float uInterpolationFactor;\n"; - // Fixed colormap stuff - i_data += "uniform int uFixedColormap;\n"; // 0, when no fixed colormap, 1 for a light value, 2 for a color blend, 3 for a fog layer - i_data += "uniform vec4 uFixedColormapStart;\n"; - i_data += "uniform vec4 uFixedColormapRange;\n"; - // Glowing walls stuff i_data += "uniform vec4 uGlowTopPlane;\n"; i_data += "uniform vec4 uGlowTopColor;\n"; @@ -318,8 +313,6 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char * muCameraPos.Init(hShader, "uCameraPos"); muLightParms.Init(hShader, "uLightAttr"); muClipSplit.Init(hShader, "uClipSplit"); - muColormapStart.Init(hShader, "uFixedColormapStart"); - muColormapRange.Init(hShader, "uFixedColormapRange"); muLightIndex.Init(hShader, "uLightIndex"); muFogColor.Init(hShader, "uFogColor"); muDynLightColor.Init(hShader, "uDynLightColor"); @@ -332,7 +325,6 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char * muSplitBottomPlane.Init(hShader, "uSplitBottomPlane"); muSplitTopPlane.Init(hShader, "uSplitTopPlane"); muClipLine.Init(hShader, "uClipLine"); - muFixedColormap.Init(hShader, "uFixedColormap"); muInterpolationFactor.Init(hShader, "uInterpolationFactor"); muClipHeight.Init(hShader, "uClipHeight"); muClipHeightDirection.Init(hShader, "uClipHeightDirection"); @@ -505,7 +497,6 @@ static const FEffectShader effectshaders[]= { "spheremap", "shaders/glsl/main.vp", "shaders/glsl/main.fp", "shaders/glsl/func_normal.fp", "shaders/glsl/material_normal.fp", "#define SPHEREMAP\n#define NO_ALPHATEST\n" }, { "burn", "shaders/glsl/main.vp", "shaders/glsl/burn.fp", nullptr, nullptr, "#define SIMPLE\n#define NO_ALPHATEST\n" }, { "stencil", "shaders/glsl/main.vp", "shaders/glsl/stencil.fp", nullptr, nullptr, "#define SIMPLE\n#define NO_ALPHATEST\n" }, - { "swrquad", "shaders/glsl/main.vp", "shaders/glsl/swshader.fp", nullptr, nullptr, "#define SIMPLE\n" }, }; FShaderManager::FShaderManager() @@ -557,12 +548,6 @@ void FShaderManager::ApplyMatrices(VSMatrix *proj, VSMatrix *view, EPassType pas mActiveShader->Bind(); } -void FShaderManager::ResetFixedColormap() -{ - for (auto &collection : mPassShaders) - collection->ResetFixedColormap(); -} - //========================================================================== // // diff --git a/src/gl/shaders/gl_shader.h b/src/gl/shaders/gl_shader.h index 021c6d2882..6307fce8fb 100644 --- a/src/gl/shaders/gl_shader.h +++ b/src/gl/shaders/gl_shader.h @@ -248,9 +248,6 @@ class FShader FBufferedUniform4f muCameraPos; FBufferedUniform4f muLightParms; FBufferedUniform2f muClipSplit; - FUniform1i muFixedColormap; - FUniform4f muColormapStart; - FUniform4f muColormapRange; FBufferedUniform1i muLightIndex; FBufferedUniformPE muFogColor; FBufferedUniform4f muDynLightColor; @@ -331,8 +328,6 @@ public: FShader *Get(unsigned int eff, bool alphateston, EPassType passType); void ApplyMatrices(VSMatrix *proj, VSMatrix *view, EPassType passType); - void ResetFixedColormap(); - private: FShader *mActiveShader = nullptr; TArray mPassShaders; @@ -355,18 +350,6 @@ public: FShader *BindEffect(int effect); void ApplyMatrices(VSMatrix *proj, VSMatrix *view); - void ResetFixedColormap() - { - for (unsigned i = 0; i < mMaterialShaders.Size(); i++) - { - mMaterialShaders[i]->currentfixedcolormap = -1; - } - for (unsigned i = 0; i < mMaterialShadersNAT.Size(); i++) - { - mMaterialShadersNAT[i]->currentfixedcolormap = -1; - } - } - FShader *Get(unsigned int eff, bool alphateston) { // indices 0-2 match the warping modes, 3 is brightmap, 4 no texture, the following are custom diff --git a/src/gl/system/gl_framebuffer.cpp b/src/gl/system/gl_framebuffer.cpp index 8e8905e3c1..c1e7fc3e0e 100644 --- a/src/gl/system/gl_framebuffer.cpp +++ b/src/gl/system/gl_framebuffer.cpp @@ -372,14 +372,6 @@ void OpenGLFrameBuffer::TextureFilterChanged() if (GLRenderer != NULL && GLRenderer->mSamplerManager != NULL) GLRenderer->mSamplerManager->SetTextureFilterMode(); } -void OpenGLFrameBuffer::ResetFixedColormap() -{ - if (GLRenderer != nullptr && GLRenderer->mShaderManager != nullptr) - { - GLRenderer->mShaderManager->ResetFixedColormap(); - } -} - void OpenGLFrameBuffer::BlurScene(float amount) { GLRenderer->BlurScene(amount); diff --git a/src/gl/system/gl_framebuffer.h b/src/gl/system/gl_framebuffer.h index ef375c2e47..24311f8537 100644 --- a/src/gl/system/gl_framebuffer.h +++ b/src/gl/system/gl_framebuffer.h @@ -39,7 +39,6 @@ public: void UnbindTexUnit(int no) override; void FlushTextures() override; void TextureFilterChanged() override; - void ResetFixedColormap() override; void BeginFrame() override; void SetViewportRects(IntRect *bounds) override; void BlurScene(float amount) override; diff --git a/src/gl_load/gl_interface.h b/src/gl_load/gl_interface.h index fcb25fda20..b4efdbc3de 100644 --- a/src/gl_load/gl_interface.h +++ b/src/gl_load/gl_interface.h @@ -13,6 +13,7 @@ enum TexMode TM_CLAMPY, // (r, g, b, (t >= 0.0 && t <= 1.0)? a:0) TM_INVERTOPAQUE, // (1-r, 1-g, 1-b, 1) TM_FOGLAYER, // (renders a fog layer in the shape of the active texture) + TM_FIXEDCOLORMAP = TM_FOGLAYER, // repurposes the objectcolor uniforms to render a fixed colormap range. (Same constant because they cannot be used in the same context. }; enum ELightMethod diff --git a/src/hwrenderer/scene/hw_drawinfo.h b/src/hwrenderer/scene/hw_drawinfo.h index 8bec0df27e..40b009041e 100644 --- a/src/hwrenderer/scene/hw_drawinfo.h +++ b/src/hwrenderer/scene/hw_drawinfo.h @@ -79,8 +79,19 @@ struct HWDrawInfo subsector_t * sub; uint8_t flags; }; + + enum EFullbrightFlags + { + Fullbright = 1, + Nightvision = 2, + StealthVision = 4 + }; + + bool isFullbrightScene() const { return !!(FullbrightFlags & Fullbright); } + bool isNightvision() const { return !!(FullbrightFlags & Nightvision); } + bool isStealthVision() const { return !!(FullbrightFlags & StealthVision); } - int FixedColormap; + int FullbrightFlags; std::atomic spriteindex; IPortal *mClipPortal; FRotator mAngles; @@ -141,6 +152,7 @@ public: void ClearBuffers(); void SetViewArea(); + int SetFullbrightFlags(player_t *player); bool DoOneSectorUpper(subsector_t * subsec, float planez, area_t in_area); bool DoOneSectorLower(subsector_t * subsec, float planez, area_t in_area); @@ -197,6 +209,5 @@ public: virtual GLDecal *AddDecal(bool onmirror) = 0; virtual std::pair AllocVertices(unsigned int count) = 0; - }; diff --git a/src/hwrenderer/scene/hw_fakeflat.cpp b/src/hwrenderer/scene/hw_fakeflat.cpp index e4e986ca8b..d13f8e909c 100644 --- a/src/hwrenderer/scene/hw_fakeflat.cpp +++ b/src/hwrenderer/scene/hw_fakeflat.cpp @@ -29,9 +29,11 @@ #include "p_local.h" #include "g_levellocals.h" #include "a_sharedglobal.h" +#include "d_player.h" #include "r_sky.h" #include "hw_fakeflat.h" #include "hw_drawinfo.h" +#include "hwrenderer/utility/hw_cvars.h" #include "r_utility.h" @@ -408,3 +410,55 @@ void HWDrawInfo::SetViewArea() } } + +int HWDrawInfo::SetFullbrightFlags(player_t *player) +{ + FullbrightFlags = 0; + + // check for special colormaps + player_t * cplayer = player->camera->player; + if (cplayer) + { + int cm = CM_DEFAULT; + if (cplayer->extralight == INT_MIN) + { + cm = CM_FIRSTSPECIALCOLORMAP + INVERSECOLORMAP; + r_viewpoint.extralight = 0; + FullbrightFlags = Fullbright; + // This does never set stealth vision. + } + else if (cplayer->fixedcolormap != NOFIXEDCOLORMAP) + { + cm = CM_FIRSTSPECIALCOLORMAP + cplayer->fixedcolormap; + FullbrightFlags = Fullbright; + if (gl_enhanced_nv_stealth > 2) FullbrightFlags |= StealthVision; + } + else if (cplayer->fixedlightlevel != -1) + { + auto torchtype = PClass::FindActor(NAME_PowerTorch); + auto litetype = PClass::FindActor(NAME_PowerLightAmp); + for (AInventory * in = cplayer->mo->Inventory; in; in = in->Inventory) + { + //PalEntry color = in->CallGetBlend(); + + // Need special handling for light amplifiers + if (in->IsKindOf(torchtype)) + { + FullbrightFlags = Fullbright; + if (gl_enhanced_nv_stealth > 1) FullbrightFlags |= StealthVision; + } + else if (in->IsKindOf(litetype)) + { + FullbrightFlags = Fullbright; + if (gl_enhanced_nightvision) FullbrightFlags |= Nightvision; + if (gl_enhanced_nv_stealth > 0) FullbrightFlags |= StealthVision; + } + } + } + return cm; + } + else + { + return CM_DEFAULT; + } +} diff --git a/src/hwrenderer/scene/hw_flats.cpp b/src/hwrenderer/scene/hw_flats.cpp index 27e31843f3..25574fbd3d 100644 --- a/src/hwrenderer/scene/hw_flats.cpp +++ b/src/hwrenderer/scene/hw_flats.cpp @@ -147,7 +147,7 @@ bool GLFlat::SetupSectorLights(int pass, sector_t * sec, FDynLightData &lightdat inline void GLFlat::PutFlat(HWDrawInfo *di, bool fog) { - if (di->FixedColormap) + if (di->isFullbrightScene()) { Colormap.Clear(); } @@ -416,7 +416,7 @@ void GLFlat::ProcessSector(HWDrawInfo *di, sector_t * frontsector) if ((rover->flags&(FF_EXISTS | FF_RENDERPLANES | FF_THISINSIDE)) == (FF_EXISTS | FF_RENDERPLANES)) { - if (rover->flags&FF_FOG && di->FixedColormap) continue; + if (rover->flags&FF_FOG && di->isFullbrightScene()) continue; if (!rover->top.copied && rover->flags&(FF_INVERTPLANES | FF_BOTHPLANES)) { double ff_top = rover->top.plane->ZatPoint(sector->centerspot); @@ -456,7 +456,7 @@ void GLFlat::ProcessSector(HWDrawInfo *di, sector_t * frontsector) if ((rover->flags&(FF_EXISTS | FF_RENDERPLANES | FF_THISINSIDE)) == (FF_EXISTS | FF_RENDERPLANES)) { - if (rover->flags&FF_FOG && di->FixedColormap) continue; + if (rover->flags&FF_FOG && di->isFullbrightScene()) continue; if (!rover->bottom.copied && rover->flags&(FF_INVERTPLANES | FF_BOTHPLANES)) { double ff_bottom = rover->bottom.plane->ZatPoint(sector->centerspot); diff --git a/src/hwrenderer/scene/hw_sprites.cpp b/src/hwrenderer/scene/hw_sprites.cpp index eed84a7db4..c6b388b040 100644 --- a/src/hwrenderer/scene/hw_sprites.cpp +++ b/src/hwrenderer/scene/hw_sprites.cpp @@ -219,7 +219,7 @@ bool GLSprite::CalculateVertices(HWDrawInfo *di, FVector3 *v) inline void GLSprite::PutSprite(HWDrawInfo *di, bool translucent) { // That's a lot of checks... - if (modelframe && RenderStyle.BlendOp != STYLEOP_Shadow && gl_light_sprites && level.HasDynamicLights && di->FixedColormap == CM_DEFAULT && !fullbright) + if (modelframe && RenderStyle.BlendOp != STYLEOP_Shadow && gl_light_sprites && level.HasDynamicLights && !di->isFullbrightScene() && !fullbright) { hw_GetDynModelLight(actor, lightdata); dynlightindex = di->UploadLights(lightdata); @@ -407,7 +407,7 @@ void GLSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t if (thing->renderflags & RF_INVISIBLE || !thing->RenderStyle.IsVisible(thing->Alpha)) { - if (!(thing->flags & MF_STEALTH) || !di->FixedColormap || !gl_enhanced_nightvision || thing == camera) + if (!(thing->flags & MF_STEALTH) || !di->isStealthVision() || thing == camera) return; } @@ -655,19 +655,15 @@ void GLSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t RenderStyle = thing->RenderStyle; // colormap stuff is a little more complicated here... - if (di->FixedColormap) + if (di->isFullbrightScene()) { - if ((gl_enhanced_nv_stealth > 0 && di->FixedColormap == CM_LITE) // Infrared powerup only - || (gl_enhanced_nv_stealth == 2 && di->FixedColormap >= CM_TORCH)// Also torches - || (gl_enhanced_nv_stealth == 3)) // Any fixed colormap - enhancedvision = true; + enhancedvision = di->isStealthVision(); Colormap.Clear(); - if (di->FixedColormap == CM_LITE) + if (di->isNightvision()) { - if (gl_enhanced_nightvision && - (thing->IsKindOf(RUNTIME_CLASS(AInventory)) || thing->flags3&MF3_ISMONSTER || thing->flags&MF_MISSILE || thing->flags&MF_CORPSE)) + if ((thing->IsKindOf(RUNTIME_CLASS(AInventory)) || thing->flags3&MF3_ISMONSTER || thing->flags&MF_MISSILE || thing->flags&MF_CORPSE)) { RenderStyle.Flags |= STYLEF_InvertSource; } @@ -811,7 +807,7 @@ void GLSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t // 3. any bright object // 4. any with render style shadow (which doesn't use the sector light) // 5. anything with render style reverse subtract (light effect is not what would be desired here) - if (thing->Sector->e->XFloor.lightlist.Size() != 0 && di->FixedColormap == CM_DEFAULT && !fullbright && + if (thing->Sector->e->XFloor.lightlist.Size() != 0 && !di->isFullbrightScene() && !fullbright && RenderStyle.BlendOp != STYLEOP_Shadow && RenderStyle.BlendOp != STYLEOP_RevSub) { if (screen->hwcaps & RFL_NO_CLIP_PLANES) // on old hardware we are rather limited... @@ -853,7 +849,7 @@ void GLSprite::ProcessParticle (HWDrawInfo *di, particle_t *particle, sector_t * sector->GetCeilingLight() : sector->GetFloorLight()); foglevel = (uint8_t)clamp(sector->lightlevel, 0, 255); - if (di->FixedColormap) + if (di->isFullbrightScene()) { Colormap.Clear(); } @@ -964,7 +960,7 @@ void GLSprite::ProcessParticle (HWDrawInfo *di, particle_t *particle, sector_t * if (gl_particles_style != 2 && trans>=1.0f-FLT_EPSILON) hw_styleflags = STYLEHW_Solid; else hw_styleflags = STYLEHW_NoAlphaTest; - if (sector->e->XFloor.lightlist.Size() != 0 && di->FixedColormap == CM_DEFAULT && !fullbright) + if (sector->e->XFloor.lightlist.Size() != 0 && !di->isFullbrightScene() && !fullbright) lightlist = §or->e->XFloor.lightlist; else lightlist = nullptr; diff --git a/src/hwrenderer/scene/hw_walls.cpp b/src/hwrenderer/scene/hw_walls.cpp index ca817cdbb5..fbc8c55580 100644 --- a/src/hwrenderer/scene/hw_walls.cpp +++ b/src/hwrenderer/scene/hw_walls.cpp @@ -172,19 +172,19 @@ void GLWall::PutWall(HWDrawInfo *di, bool translucent) ViewDistance = (r_viewpoint.Pos - (seg->linedef->v1->fPos() + seg->linedef->Delta() / 2)).XY().LengthSquared(); } - if (di->FixedColormap) + if (di->isFullbrightScene()) { // light planes don't get drawn with fullbright rendering if (gltexture == NULL) return; Colormap.Clear(); } - if (di->FixedColormap != CM_DEFAULT || (Colormap.LightColor.isWhite() && lightlevel == 255)) + if (di->isFullbrightScene() || (Colormap.LightColor.isWhite() && lightlevel == 255)) flags &= ~GLWF_GLOW; if (!(screen->hwcaps & RFL_BUFFER_STORAGE)) { - if (level.HasDynamicLights && di->FixedColormap == CM_DEFAULT && gltexture != nullptr) + if (level.HasDynamicLights && !di->isFullbrightScene() && gltexture != nullptr) { SetupLights(di, lightdata); } @@ -467,7 +467,7 @@ bool GLWall::DoHorizon(HWDrawInfo *di, seg_t * seg,sector_t * fs, vertex_t * v1, hi.colormap.CopyLight(light->extra_colormap); } - if (di->FixedColormap) hi.colormap.Clear(); + if (di->isFullbrightScene()) hi.colormap.Clear(); horizon = &hi; PutPortal(di, PORTALTYPE_HORIZON); } @@ -496,7 +496,7 @@ bool GLWall::DoHorizon(HWDrawInfo *di, seg_t * seg,sector_t * fs, vertex_t * v1, hi.colormap.CopyLight(light->extra_colormap); } - if (di->FixedColormap) hi.colormap.Clear(); + if (di->isFullbrightScene()) hi.colormap.Clear(); horizon = &hi; PutPortal(di, PORTALTYPE_HORIZON); } @@ -764,7 +764,7 @@ void GLWall::DoTexture(HWDrawInfo *di, int _type,seg_t * seg, int peg, // Add this wall to the render list sector_t * sec = sub ? sub->sector : seg->frontsector; - if (sec->e->XFloor.lightlist.Size()==0 || di->FixedColormap) PutWall(di, false); + if (sec->e->XFloor.lightlist.Size()==0 || di->isFullbrightScene()) PutWall(di, false); else SplitWall(di, sec, false); } @@ -1076,7 +1076,7 @@ void GLWall::DoMidTexture(HWDrawInfo *di, seg_t * seg, bool drawfogboundary, // Draw the stuff // // - if (front->e->XFloor.lightlist.Size()==0 || di->FixedColormap) split.PutWall(di, translucent); + if (front->e->XFloor.lightlist.Size()==0 || di->isFullbrightScene()) split.PutWall(di, translucent); else split.SplitWall(di, front, translucent); t=1; @@ -1090,7 +1090,7 @@ void GLWall::DoMidTexture(HWDrawInfo *di, seg_t * seg, bool drawfogboundary, // Draw the stuff without splitting // // - if (front->e->XFloor.lightlist.Size()==0 || di->FixedColormap) PutWall(di, translucent); + if (front->e->XFloor.lightlist.Size()==0 || di->isFullbrightScene()) PutWall(di, translucent); else SplitWall(di, front, translucent); } alpha=1.0f; @@ -1123,7 +1123,7 @@ void GLWall::BuildFFBlock(HWDrawInfo *di, seg_t * seg, F3DFloor * rover, if (rover->flags&FF_FOG) { - if (!di->FixedColormap) + if (!di->isFullbrightScene()) { // this may not yet be done light = P_GetPlaneLight(rover->target, rover->top.plane, true); @@ -1202,7 +1202,7 @@ void GLWall::BuildFFBlock(HWDrawInfo *di, seg_t * seg, F3DFloor * rover, sector_t * sec = sub ? sub->sector : seg->frontsector; - if (sec->e->XFloor.lightlist.Size() == 0 || di->FixedColormap) PutWall(di, translucent); + if (sec->e->XFloor.lightlist.Size() == 0 || di->isFullbrightScene()) PutWall(di, translucent); else SplitWall(di, sec, translucent); alpha = 1.0f; @@ -1671,7 +1671,7 @@ void GLWall::Process(HWDrawInfo *di, seg_t *seg, sector_t * frontsector, sector_ bool isportal = seg->linedef->isVisualPortal() && seg->sidedef == seg->linedef->sidedef[0]; sector_t *backsec = isportal? seg->linedef->getPortalDestination()->frontsector : backsector; - bool drawfogboundary = di->FixedColormap == CM_DEFAULT && hw_CheckFog(frontsector, backsec); + bool drawfogboundary = !di->isFullbrightScene() && hw_CheckFog(frontsector, backsec); FTexture *tex = TexMan(seg->sidedef->GetTexture(side_t::mid)); if (tex != NULL) { diff --git a/src/hwrenderer/scene/hw_weapon.cpp b/src/hwrenderer/scene/hw_weapon.cpp index 7c3242c505..dd6829323f 100644 --- a/src/hwrenderer/scene/hw_weapon.cpp +++ b/src/hwrenderer/scene/hw_weapon.cpp @@ -141,11 +141,11 @@ static FVector2 BobWeapon(WeaponPosition &weap, DPSprite *psp) // //========================================================================== -static WeaponLighting GetWeaponLighting(sector_t *viewsector, const DVector3 &pos, int FixedColormap, area_t in_area, const DVector3 &playerpos) +static WeaponLighting GetWeaponLighting(sector_t *viewsector, const DVector3 &pos, int cm, area_t in_area, const DVector3 &playerpos) { WeaponLighting l; - if (FixedColormap) + if (cm) { l.lightlevel = 255; l.cm.Clear(); @@ -438,7 +438,7 @@ void HWDrawInfo::PreparePlayerSprites(sector_t * viewsector, area_t in_area) return; WeaponPosition weap = GetWeaponPosition(camera->player); - WeaponLighting light = GetWeaponLighting(viewsector, r_viewpoint.Pos, FixedColormap, in_area, camera->Pos()); + WeaponLighting light = GetWeaponLighting(viewsector, r_viewpoint.Pos, isFullbrightScene(), in_area, camera->Pos()); // hack alert! Rather than changing everything in the underlying lighting code let's just temporarily change // light mode here to draw the weapon sprite. @@ -465,7 +465,7 @@ void HWDrawInfo::PreparePlayerSprites(sector_t * viewsector, area_t in_area) hudsprite.dynrgb[0] = hudsprite.dynrgb[1] = hudsprite.dynrgb[2] = 0; hudsprite.lightindex = -1; // set the lighting parameters - if (hudsprite.RenderStyle.BlendOp != STYLEOP_Shadow && level.HasDynamicLights && FixedColormap == CM_DEFAULT && gl_light_sprites) + if (hudsprite.RenderStyle.BlendOp != STYLEOP_Shadow && level.HasDynamicLights && !isFullbrightScene() && gl_light_sprites) { if (!hudModelStep) { diff --git a/src/hwrenderer/utility/hw_lighting.cpp b/src/hwrenderer/utility/hw_lighting.cpp index a261120de7..04836a51c2 100644 --- a/src/hwrenderer/utility/hw_lighting.cpp +++ b/src/hwrenderer/utility/hw_lighting.cpp @@ -34,14 +34,7 @@ static float distfogtable[2][256]; // light to fog conversion table for black fog CVAR(Int, gl_weaponlight, 8, CVAR_ARCHIVE); -CUSTOM_CVAR(Bool, gl_enhanced_nightvision, true, CVAR_ARCHIVE|CVAR_NOINITCALL) -{ - // The fixed colormap state needs to be reset because if this happens when - // a shader is set to CM_LITE or CM_TORCH it won't register the change in behavior caused by this CVAR. - screen->ResetFixedColormap(); -} - - +CVAR(Bool, gl_enhanced_nightvision, true, CVAR_ARCHIVE|CVAR_NOINITCALL) //========================================================================== // diff --git a/src/r_data/colormaps.h b/src/r_data/colormaps.h index 379e1cfff2..128a6eeb73 100644 --- a/src/r_data/colormaps.h +++ b/src/r_data/colormaps.h @@ -128,18 +128,11 @@ extern uint8_t DesaturateColormap[31][256]; enum EColorManipulation { - CM_SPECIAL2D = -3, // the special colormaps get passed as color pair from the 2D drawer so they need a different value here. CM_PLAIN2D = -2, // regular 2D drawing. CM_INVALID = -1, CM_DEFAULT = 0, // untranslated CM_FIRSTSPECIALCOLORMAP, // first special fixed colormap CM_FIRSTSPECIALCOLORMAPFORCED = 0x08000000, // first special fixed colormap, application forced (for 2D overlays) - - CM_FOGLAYER = 0x10000000, // Sprite shaped fog layer - - // These are not to be passed to the texture manager - CM_LITE = 0x20000000, // special values to handle these items without excessive hacking - CM_TORCH = 0x20000010, // These are not real color manipulations }; #define CM_MAXCOLORMAP int(CM_FIRSTSPECIALCOLORMAP + SpecialColormaps.Size()) diff --git a/src/v_2ddrawer.cpp b/src/v_2ddrawer.cpp index bbf9105fea..8a2df83138 100644 --- a/src/v_2ddrawer.cpp +++ b/src/v_2ddrawer.cpp @@ -180,8 +180,12 @@ bool F2DDrawer::SetStyle(FTexture *tex, DrawParms &parms, PalEntry &vertexcolor, } if (parms.specialcolormap != nullptr) - { // Emulate an invulnerability or similar colormap. - quad.mSpecialColormap = parms.specialcolormap; + { // draw with an invulnerability or similar colormap. + + auto scm = parms.specialcolormap; + + quad.mSpecialColormap[0] = PalEntry(255, int(scm->ColorizeStart[0] * 127.5f), int(scm->ColorizeStart[1] * 127.5f), int(scm->ColorizeStart[2] * 127.5f)); + quad.mSpecialColormap[1] = PalEntry(255, int(scm->ColorizeEnd[0] * 127.5f), int(scm->ColorizeEnd[1] * 127.5f), int(scm->ColorizeEnd[2] * 127.5f)); quad.mColor1 = 0; // this disables the color overlay. } quad.mDesaturate = parms.desaturate; diff --git a/src/v_2ddrawer.h b/src/v_2ddrawer.h index 96fb51782a..c1c08d3b79 100644 --- a/src/v_2ddrawer.h +++ b/src/v_2ddrawer.h @@ -76,7 +76,7 @@ public: FTexture *mTexture; FRemapTable *mTranslation; - FSpecialColormap *mSpecialColormap; + PalEntry mSpecialColormap[2]; int mScissor[4]; int mDesaturate; FRenderStyle mRenderStyle; diff --git a/src/v_draw.cpp b/src/v_draw.cpp index f43bffd193..d1525d686b 100644 --- a/src/v_draw.cpp +++ b/src/v_draw.cpp @@ -49,6 +49,7 @@ #include "i_video.h" #include "g_levellocals.h" #include "vm.h" +#include "hwrenderer/utility/hw_cvars.h" CVAR(Float, underwater_fade_scalar, 1.0f, CVAR_ARCHIVE) // [Nash] user-settable underwater blend intensity @@ -1404,6 +1405,38 @@ void DFrameBuffer::DrawBlend(sector_t * viewsector) V_AddBlend(blendv.r / 255.f, blendv.g / 255.f, blendv.b / 255.f, cnt / 255.0f, blend); } } + else if (player && player->fixedlightlevel != -1 && player->fixedcolormap != NOFIXEDCOLORMAP) + { + // Draw fixedlightlevel effects as a 2D overlay. The hardware renderer just processes such a scene fullbright without any lighting. + auto torchtype = PClass::FindActor(NAME_PowerTorch); + auto litetype = PClass::FindActor(NAME_PowerLightAmp); + PalEntry color = 0xffffffff; + for (AInventory * in = player->mo->Inventory; in; in = in->Inventory) + { + // Need special handling for light amplifiers + if (in->IsKindOf(torchtype)) + { + // The software renderer already bakes the torch flickering into its output, so this must be omitted here. + float r = vid_rendermode < 4? 1.f : (0.8f + (7 - player->fixedlightlevel) / 70.0f); + if (r > 1.0f) r = 1.0f; + int rr = (int)(r * 255); + int b = rr; + if (gl_enhanced_nightvision) b = b * 3 / 4; + color = PalEntry(255, rr, rr, b); + } + else if (in->IsKindOf(litetype)) + { + if (gl_enhanced_nightvision) + { + color = PalEntry(255, 104, 255, 104); + } + } + } + if (color != 0xffffffff) + { + screen->Dim(color, 1, 0, 0, screen->GetWidth(), screen->GetHeight(), &LegacyRenderStyles[STYLE_Multiply]); + } + } if (player) { diff --git a/src/v_video.h b/src/v_video.h index abb0d4e79e..ad589652c6 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -407,7 +407,6 @@ public: virtual void UnbindTexUnit(int no) {} virtual void FlushTextures() {} virtual void TextureFilterChanged() {} - virtual void ResetFixedColormap() {} virtual void BeginFrame() {} virtual int GetClientWidth() = 0; diff --git a/wadsrc/static/shaders/glsl/main.fp b/wadsrc/static/shaders/glsl/main.fp index 0fdd3abdd5..441d5f9879 100644 --- a/wadsrc/static/shaders/glsl/main.fp +++ b/wadsrc/static/shaders/glsl/main.fp @@ -75,9 +75,11 @@ vec4 getTexel(vec2 st) break; case 4: // TM_REDTOALPHA + { float gray = grayscale(texel); texel = vec4(1.0, 1.0, 1.0, gray*texel.a); break; + } case 5: // TM_CLAMPY if (st.t < 0.0 || st.t > 1.0) @@ -92,6 +94,7 @@ vec4 getTexel(vec2 st) case 7: //TM_FOGLAYER return texel; + } if (uObjectColor2.a == 0.0) texel *= uObjectColor; else texel *= mix(uObjectColor, uObjectColor2, glowdist.z); @@ -431,53 +434,30 @@ void main() if (frag.a <= uAlphaThreshold) discard; #endif - if (uTextureMode == 7) + if (uFogEnabled != -3) // check for special 2D 'fog' mode. { - float fogdist; - float fogfactor; + float fogdist = 0.0; + float fogfactor = 0.0; // // calculate fog factor // - if (uFogEnabled == -1) + if (uFogEnabled != 0) { - fogdist = pixelpos.w; - } - else - { - fogdist = max(16.0, distance(pixelpos.xyz, uCameraPos.xyz)); - } - fogfactor = exp2 (uFogDensity * fogdist); - - frag = vec4(uFogColor.rgb, (1.0 - fogfactor) * frag.a * 0.75 * vColor.a); - } - else switch (uFixedColormap) - { - case 0: // in-game rendering. - { - float fogdist = 0.0; - float fogfactor = 0.0; - - - - // - // calculate fog factor - // - if (uFogEnabled != 0) + if (uFogEnabled == 1 || uFogEnabled == -1) { - if (uFogEnabled == 1 || uFogEnabled == -1) - { - fogdist = pixelpos.w; - } - else - { - fogdist = max(16.0, distance(pixelpos.xyz, uCameraPos.xyz)); - } - fogfactor = exp2 (uFogDensity * fogdist); + fogdist = pixelpos.w; } - + else + { + fogdist = max(16.0, distance(pixelpos.xyz, uCameraPos.xyz)); + } + fogfactor = exp2 (uFogDensity * fogdist); + } + + if (uTextureMode != 7) + { frag = getLightColor(frag, fogdist, fogfactor); - // // colored fog // @@ -485,36 +465,22 @@ void main() { frag = applyFog(frag, fogfactor); } - - break; } - - case 1: // special colormap + else + { + frag = vec4(uFogColor.rgb, (1.0 - fogfactor) * frag.a * 0.75 * vColor.a); + } + } + else // simple 2D (uses the fog color to add a color overlay) + { + if (uTextureMode == 7) { float gray = grayscale(frag); - vec4 cm = uFixedColormapStart + gray * uFixedColormapRange; - frag = vec4(clamp(cm.rgb, 0.0, 1.0), frag.a*vColor.a); - break; + vec4 cm = (uObjectColor + gray * (uObjectColor2 - uObjectColor)) * 2; + frag = vec4(clamp(cm.rgb, 0.0, 1.0), frag.a); } - - case 2: // fullscreen tint. - { - frag = vColor * frag * uFixedColormapStart; - break; - } - - case 3: // unused - { - break; - } - - case 4: // simple 2D (reuses a uniform for the special colormap for the color overlay.) - { - frag = frag * ProcessLight(vColor); - frag.rgb = frag.rgb + uFogColor.rgb; - break; - } - + frag = frag * ProcessLight(vColor); + frag.rgb = frag.rgb + uFogColor.rgb; } FragColor = frag; #ifdef GBUFFER_PASS diff --git a/wadsrc/static/shaders/glsl/swshader.fp b/wadsrc/static/shaders/glsl/swshader.fp deleted file mode 100644 index b91c324b86..0000000000 --- a/wadsrc/static/shaders/glsl/swshader.fp +++ /dev/null @@ -1,31 +0,0 @@ -in vec4 vTexCoord; -layout(location=0) out vec4 FragColor; - -vec4 TextureLookup(vec2 tex_coord) -{ - if (uTextureMode == 1) - { - float index = texture(tex, tex_coord).x; - index = index * 256.0 + 0.5; // We only have 256 color palettes here. - return texture(texture2, vec2(index, 0.5)); - } - else - { - return texture(tex, tex_coord); - } -} - -void main() -{ - if (uFixedColormap == 0) - { - FragColor = TextureLookup(vTexCoord.xy); - } - else - { - vec4 frag = TextureLookup(vTexCoord.xy); - float gray = dot(frag.rgb, vec3(0.4, 0.56, 0.14)); - vec4 cm = uFixedColormapStart + gray * uFixedColormapRange; - FragColor = vec4(clamp(cm.rgb, 0.0, 1.0), 1.0); - } -} diff --git a/wadsrc/static/shaders/swgl/swshadergl2.fp b/wadsrc/static/shaders/swgl/swshadergl2.fp deleted file mode 100644 index a65538fb5d..0000000000 --- a/wadsrc/static/shaders/swgl/swshadergl2.fp +++ /dev/null @@ -1,32 +0,0 @@ -uniform sampler2D tex; -uniform sampler2D palette; -uniform vec4 uColor1; -uniform vec4 uColor2; - -vec4 TextureLookup(vec2 tex_coord) -{ -#ifdef PAL_TEX - float index = texture2D(tex, tex_coord).x; - index = ((index * 255.0) + 0.5) / 256.0; - return texture2D(palette, vec2(index, 0.5)); -#else - return texture2D(tex, tex_coord); -#endif -} - -float grayscale(vec4 rgb) -{ - return dot(rgb.rgb, vec3(0.4, 0.56, 0.14)); -} - -void main() -{ -#ifndef SPECIALCM - gl_FragColor = TextureLookup(gl_TexCoord[0].xy); -#else - vec4 frag = TextureLookup(gl_TexCoord[0].xy); - float gray = grayscale(frag); - vec4 cm = uColor1 + gray * uColor2; - gl_FragColor = vec4(clamp(cm.rgb, 0.0, 1.0), 1.0); -#endif -} diff --git a/wadsrc/static/shaders/swgl/swshadergl2.vp b/wadsrc/static/shaders/swgl/swshadergl2.vp deleted file mode 100644 index 97d05c35f8..0000000000 --- a/wadsrc/static/shaders/swgl/swshadergl2.vp +++ /dev/null @@ -1,6 +0,0 @@ - -void main() -{ - gl_TexCoord[0] = gl_MultiTexCoord0; - gl_Position = ftransform(); -}