- refactoring of fixed colormap stuff to have it better organized and to reduce the number of uniforms in the main shader.

This removes 3 uniforms, consisting of 9 floats. Those were merged into other values that never get used at the same time.
It also moves the costly setup of the fixed colormap out of the render state into the 2D processing code.
Since 3D forces use of render buffers now, it is no longer necessary to draw the entire scene with the colormap active, meaning it can be handled more efficiently.
This commit is contained in:
Christoph Oelckers 2018-06-16 13:47:24 +02:00
parent 9ff7e5a4ef
commit 4937848123
35 changed files with 250 additions and 453 deletions

View file

@ -73,6 +73,7 @@ void FGLRenderer::PostProcessScene(int fixedcm, const std::function<void()> &aft
mCustomPostProcessShaders->Run("scene"); mCustomPostProcessShaders->Run("scene");
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// //
// Adds ambient occlusion to the scene // Adds ambient occlusion to the scene

View file

@ -326,8 +326,6 @@ sector_t *FGLRenderer::RenderView(player_t* player)
GLSceneDrawer drawer; GLSceneDrawer drawer;
drawer.SetFixedColormap(player);
mShadowMap.Update(); mShadowMap.Update();
retsec = drawer.RenderViewpoint(player->camera, NULL, r_viewpoint.FieldOfView.Degrees, ratio, fovratio, true, true); 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()); bounds.height = FHardwareTexture::GetTexDimension(gltex->GetHeight());
GLSceneDrawer drawer; GLSceneDrawer drawer;
drawer.FixedColormap = CM_DEFAULT;
gl_RenderState.SetFixedColormap(CM_DEFAULT);
drawer.RenderViewpoint(Viewpoint, &bounds, FOV, (float)width / height, (float)width / height, false, false); drawer.RenderViewpoint(Viewpoint, &bounds, FOV, (float)width / height, (float)width / height, false, false);
EndOffscreen(); EndOffscreen();
@ -478,7 +474,6 @@ void FGLRenderer::Draw2D(F2DDrawer *drawer)
auto vb = new F2DVertexBuffer; auto vb = new F2DVertexBuffer;
vb->UploadData(&vertices[0], vertices.Size(), &indices[0], indices.Size()); vb->UploadData(&vertices[0], vertices.Size(), &indices[0], indices.Size());
gl_RenderState.SetVertexBuffer(vb); gl_RenderState.SetVertexBuffer(vb);
gl_RenderState.SetFixedColormap(CM_DEFAULT);
gl_RenderState.EnableFog(false); gl_RenderState.EnableFog(false);
for(auto &cmd : commands) for(auto &cmd : commands)
@ -493,6 +488,7 @@ void FGLRenderer::Draw2D(F2DDrawer *drawer)
gl_RenderState.BlendEquation(be); gl_RenderState.BlendEquation(be);
gl_RenderState.BlendFunc(sb, db); gl_RenderState.BlendFunc(sb, db);
gl_RenderState.EnableBrightmap(!(cmd.mRenderStyle.Flags & STYLEF_ColorIsFixed)); 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. // 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"); 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); else glDisable(GL_SCISSOR_TEST);
if (cmd.mSpecialColormap != nullptr) if (cmd.mSpecialColormap[0].a != 0)
{ {
auto index = cmd.mSpecialColormap - &SpecialColormaps[0]; gl_RenderState.SetTextureMode(TM_FIXEDCOLORMAP);
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.SetObjectColor(cmd.mSpecialColormap[0]);
gl_RenderState.SetFixedColormap(CM_FIRSTSPECIALCOLORMAPFORCED + int(index)); gl_RenderState.SetObjectColor2(cmd.mSpecialColormap[1]);
} }
else
{
gl_RenderState.SetFog(cmd.mColor1, 0); gl_RenderState.SetFog(cmd.mColor1, 0);
gl_RenderState.SetFixedColormap(CM_PLAIN2D);
}
gl_RenderState.SetColor(1, 1, 1, 1, cmd.mDesaturate); gl_RenderState.SetColor(1, 1, 1, 1, cmd.mDesaturate);
gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f); gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f);
@ -570,7 +561,8 @@ void FGLRenderer::Draw2D(F2DDrawer *drawer)
break; break;
} }
gl_RenderState.SetEffect(EFF_NONE); gl_RenderState.SetObjectColor(0xffffffff);
gl_RenderState.SetObjectColor2(0);
gl_RenderState.EnableTextureMatrix(false); gl_RenderState.EnableTextureMatrix(false);
} }
glDisable(GL_SCISSOR_TEST); glDisable(GL_SCISSOR_TEST);
@ -579,7 +571,7 @@ void FGLRenderer::Draw2D(F2DDrawer *drawer)
gl_RenderState.EnableTexture(true); gl_RenderState.EnableTexture(true);
gl_RenderState.EnableBrightmap(true); gl_RenderState.EnableBrightmap(true);
gl_RenderState.SetTextureMode(TM_MODULATE); gl_RenderState.SetTextureMode(TM_MODULATE);
gl_RenderState.SetFixedColormap(CM_DEFAULT); gl_RenderState.EnableFog(false);
gl_RenderState.ResetColor(); gl_RenderState.ResetColor();
gl_RenderState.Apply(); gl_RenderState.Apply();
delete vb; delete vb;

View file

@ -77,7 +77,6 @@ void FRenderState::Reset()
mObjectColor = 0xffffffff; mObjectColor = 0xffffffff;
mObjectColor2 = 0; mObjectColor2 = 0;
mVertexBuffer = mCurrentVertexBuffer = NULL; mVertexBuffer = mCurrentVertexBuffer = NULL;
mColormapState = CM_DEFAULT;
mSoftLight = 0; mSoftLight = 0;
mLightParms[0] = mLightParms[1] = mLightParms[2] = 0.0f; mLightParms[0] = mLightParms[1] = mLightParms[2] = 0.0f;
mLightParms[3] = -1.f; mLightParms[3] = -1.f;
@ -144,7 +143,11 @@ bool FRenderState::ApplyShader()
if (mFogEnabled) if (mFogEnabled)
{ {
if ((mFogColor & 0xffffff) == 0) if (mFogEnabled == 2)
{
fogset = -3; // 2D rendering with 'foggy' overlay.
}
else if ((mFogColor & 0xffffff) == 0)
{ {
fogset = gl_fogmode; fogset = gl_fogmode;
} }
@ -221,73 +224,6 @@ bool FRenderState::ApplyShader()
activeShader->currentcliplinestate = 0; 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) if (mTextureMatrixEnabled)
{ {
matrixToGL(mTextureMatrix, activeShader->texturematrix_index); matrixToGL(mTextureMatrix, activeShader->texturematrix_index);

View file

@ -61,7 +61,6 @@ enum EEffect
EFF_SPHEREMAP, EFF_SPHEREMAP,
EFF_BURN, EFF_BURN,
EFF_STENCIL, EFF_STENCIL,
EFF_SWQUAD,
MAX_EFFECTS MAX_EFFECTS
}; };
@ -77,7 +76,7 @@ class FRenderState
{ {
friend void gl_SetTextureMode(int type); friend void gl_SetTextureMode(int type);
bool mTextureEnabled; bool mTextureEnabled;
bool mFogEnabled; uint8_t mFogEnabled;
bool mGlowEnabled; bool mGlowEnabled;
bool mSplitEnabled; bool mSplitEnabled;
bool mClipLineEnabled; bool mClipLineEnabled;
@ -116,7 +115,6 @@ class FRenderState
float mClipSplit[2]; float mClipSplit[2];
int mEffectState; int mEffectState;
int mColormapState;
int mTempTM = TM_MODULATE; int mTempTM = TM_MODULATE;
float stAlphaThreshold; float stAlphaThreshold;
@ -276,7 +274,7 @@ public:
mTextureEnabled = on; mTextureEnabled = on;
} }
void EnableFog(bool on) void EnableFog(uint8_t on)
{ {
mFogEnabled = on; mFogEnabled = on;
} }
@ -417,16 +415,6 @@ public:
mLightParms[0] = d; mLightParms[0] = d;
} }
void SetFixedColormap(int cm)
{
mColormapState = cm;
}
int GetFixedColormap()
{
return mColormapState;
}
PalEntry GetFogColor() const PalEntry GetFogColor() const
{ {
return mFogColor; return mFogColor;

View file

@ -197,7 +197,6 @@ FDrawInfo *FDrawInfo::StartDrawInfo(GLSceneDrawer *drawer)
di->mVBO = GLRenderer->mVBO; di->mVBO = GLRenderer->mVBO;
di->mClipper = &staticClipper; di->mClipper = &staticClipper;
staticClipper.Clear(); staticClipper.Clear();
di->FixedColormap = drawer->FixedColormap;
di->StartScene(); di->StartScene();
return di; return di;
} }
@ -212,6 +211,11 @@ void FDrawInfo::StartScene()
decals[0].Clear(); decals[0].Clear();
decals[1].Clear(); decals[1].Clear();
hudsprites.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); gltexture=FMaterial::ValidateTexture(plane.texture, false, true);
if (!gltexture) return; if (!gltexture) return;
if (mDrawer->FixedColormap) if (isFullbrightScene())
{ {
Colormap.Clear(); Colormap.Clear();
lightlevel=255; lightlevel=255;
@ -333,8 +337,8 @@ void FDrawInfo::DrawFloodedPlane(wallseg * ws, float planez, sector_t * sec, boo
} }
int rel = getExtraLight(); int rel = getExtraLight();
mDrawer->SetColor(lightlevel, rel, Colormap, 1.0f); SetColor(lightlevel, rel, Colormap, 1.0f);
mDrawer->SetFog(lightlevel, rel, &Colormap, false); SetFog(lightlevel, rel, &Colormap, false);
gl_RenderState.SetMaterial(gltexture, CLAMP_NONE, 0, -1, false); gl_RenderState.SetMaterial(gltexture, CLAMP_NONE, 0, -1, false);
float fviewx = r_viewpoint.Pos.X; float fviewx = r_viewpoint.Pos.X;

View file

@ -1,6 +1,7 @@
#ifndef __GL_DRAWINFO_H #ifndef __GL_DRAWINFO_H
#define __GL_DRAWINFO_H #define __GL_DRAWINFO_H
#include "gl/renderer/gl_lightdata.h"
#include "hwrenderer/scene/hw_drawlist.h" #include "hwrenderer/scene/hw_drawlist.h"
#include "hwrenderer/scene/hw_weapon.h" #include "hwrenderer/scene/hw_weapon.h"
@ -119,6 +120,17 @@ struct FDrawInfo : public HWDrawInfo
if (sector<otherceilingplanes.Size()) return otherceilingplanes[sector]; if (sector<otherceilingplanes.Size()) return otherceilingplanes[sector];
else return NULL; else return NULL;
} }
void SetColor(int light, int rellight, const FColormap &cm, float alpha, bool weapon = false)
{
gl_SetColor(light, rellight, isFullbrightScene(), cm, alpha, weapon);
}
void SetFog(int lightlevel, int rellight, const FColormap *cmap, bool isadditive)
{
gl_SetFog(lightlevel, rellight, isFullbrightScene(), cmap, isadditive);
}
}; };
class FDrawInfoList class FDrawInfoList

View file

@ -56,7 +56,7 @@
void FDrawInfo::SetupSubsectorLights(GLFlat *flat, int pass, subsector_t * sub, int *dli) void FDrawInfo::SetupSubsectorLights(GLFlat *flat, int pass, subsector_t * sub, int *dli)
{ {
if (FixedColormap != CM_DEFAULT) return; if (isFullbrightScene()) return;
if (dli != NULL && *dli != -1) if (dli != NULL && *dli != -1)
{ {
gl_RenderState.ApplyLightIndex(GLRenderer->mLights->GetIndex(*dli)); gl_RenderState.ApplyLightIndex(GLRenderer->mLights->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) void FDrawInfo::SetupSectorLights(GLFlat *flat, int pass, int *dli)
{ {
if (FixedColormap != CM_DEFAULT) return; if (isFullbrightScene()) return;
if (dli != NULL && *dli != -1) if (dli != NULL && *dli != -1)
{ {
gl_RenderState.ApplyLightIndex(GLRenderer->mLights->GetIndex(*dli)); 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) switch (pass)
{ {
case GLPASS_ALL: // Single-pass rendering case GLPASS_ALL: // Single-pass rendering
mDrawer->SetColor(flat->lightlevel, rel, flat->Colormap,1.0f); SetColor(flat->lightlevel, rel, flat->Colormap,1.0f);
mDrawer->SetFog(flat->lightlevel, rel, &flat->Colormap, false); SetFog(flat->lightlevel, rel, &flat->Colormap, false);
if (!flat->gltexture->tex->isFullbright()) if (!flat->gltexture->tex->isFullbright())
gl_RenderState.SetObjectColor(flat->FlatColor | 0xff000000); gl_RenderState.SetObjectColor(flat->FlatColor | 0xff000000);
if (flat->sector->special != GLSector_Skybox) 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: case GLPASS_TRANSLUCENT:
if (flat->renderstyle==STYLE_Add) gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE); if (flat->renderstyle==STYLE_Add) gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE);
mDrawer->SetColor(flat->lightlevel, rel, flat->Colormap, flat->alpha); SetColor(flat->lightlevel, rel, flat->Colormap, flat->alpha);
mDrawer->SetFog(flat->lightlevel, rel, &flat->Colormap, false); SetFog(flat->lightlevel, rel, &flat->Colormap, false);
if (!flat->gltexture || !flat->gltexture->tex->isFullbright()) if (!flat->gltexture || !flat->gltexture->tex->isFullbright())
gl_RenderState.SetObjectColor(flat->FlatColor | 0xff000000); gl_RenderState.SetObjectColor(flat->FlatColor | 0xff000000);
if (!flat->gltexture) if (!flat->gltexture)

View file

@ -1134,14 +1134,14 @@ void GLHorizonPortal::DrawContents(FDrawInfo *di)
if (gltexture && gltexture->tex->isFullbright()) if (gltexture && gltexture->tex->isFullbright())
{ {
// glowing textures are always drawn full bright without color // glowing textures are always drawn full bright without color
drawer->SetColor(255, 0, origin->colormap, 1.f); di->SetColor(255, 0, origin->colormap, 1.f);
drawer->SetFog(255, 0, &origin->colormap, false); di->SetFog(255, 0, &origin->colormap, false);
} }
else else
{ {
int rel = getExtraLight(); int rel = getExtraLight();
drawer->SetColor(origin->lightlevel, rel, origin->colormap, 1.0f); di->SetColor(origin->lightlevel, rel, origin->colormap, 1.0f);
drawer->SetFog(origin->lightlevel, rel, &origin->colormap, false); di->SetFog(origin->lightlevel, rel, &origin->colormap, false);
} }

View file

@ -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, // 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. // 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(); GLRenderer->mLights->Begin();
di->drawlists[GLDL_PLAINFLATS].DrawFlats(di, GLPASS_LIGHTSONLY); di->drawlists[GLDL_PLAINFLATS].DrawFlats(di, GLPASS_LIGHTSONLY);
@ -487,19 +487,11 @@ void GLSceneDrawer::EndDrawScene(FDrawInfo *di, sector_t * viewsector)
Reset3DViewport(); 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 // Restore standard rendering state
gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
gl_RenderState.ResetColor(); gl_RenderState.ResetColor();
gl_RenderState.EnableTexture(true); gl_RenderState.EnableTexture(true);
glDisable(GL_SCISSOR_TEST); glDisable(GL_SCISSOR_TEST);
}
} }
void GLSceneDrawer::DrawEndScene2D(FDrawInfo *di, sector_t * viewsector) void GLSceneDrawer::DrawEndScene2D(FDrawInfo *di, sector_t * viewsector)
@ -516,7 +508,6 @@ void GLSceneDrawer::DrawEndScene2D(FDrawInfo *di, sector_t * viewsector)
di->DrawPlayerSprites(false); di->DrawPlayerSprites(false);
gl_RenderState.SetFixedColormap(CM_DEFAULT);
gl_RenderState.SetSoftLightLevel(-1); gl_RenderState.SetSoftLightLevel(-1);
// Restore standard rendering state // 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 // Renders one viewpoint in a scene
@ -634,8 +579,6 @@ sector_t * GLSceneDrawer::RenderViewpoint (AActor * camera, IntRect * bounds, fl
stereo3dMode.SetUp(); stereo3dMode.SetUp();
for (int eye_ix = 0; eye_ix < stereo3dMode.eye_count(); ++eye_ix) 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); const s3d::EyePose * eye = stereo3dMode.getEyePose(eye_ix);
eye->SetUp(); eye->SetUp();
screen->SetViewportRects(bounds); screen->SetViewportRects(bounds);
@ -645,6 +588,7 @@ sector_t * GLSceneDrawer::RenderViewpoint (AActor * camera, IntRect * bounds, fl
FDrawInfo *di = FDrawInfo::StartDrawInfo(this); FDrawInfo *di = FDrawInfo::StartDrawInfo(this);
di->SetViewArea(); di->SetViewArea();
auto cm = di->SetFullbrightFlags(mainview ? r_viewpoint.camera->player : nullptr);
// Stereo mode specific perspective projection // Stereo mode specific perspective projection
SetProjection( eye->GetProjection(fov, ratio, fovratio) ); SetProjection( eye->GetProjection(fov, ratio, fovratio) );
@ -661,7 +605,7 @@ sector_t * GLSceneDrawer::RenderViewpoint (AActor * camera, IntRect * bounds, fl
if (mainview) 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. // This should be done after postprocessing, not before.
GLRenderer->mBuffers->BindCurrentFB(); GLRenderer->mBuffers->BindCurrentFB();
@ -707,14 +651,12 @@ void GLSceneDrawer::WriteSavePic (player_t *player, FileWriter *file, int width,
GLRenderer->mBuffers = GLRenderer->mSaveBuffers; GLRenderer->mBuffers = GLRenderer->mSaveBuffers;
P_FindParticleSubsectors(); // make sure that all recently spawned particles have a valid subsector. P_FindParticleSubsectors(); // make sure that all recently spawned particles have a valid subsector.
SetFixedColormap(player);
gl_RenderState.SetVertexBuffer(GLRenderer->mVBO); gl_RenderState.SetVertexBuffer(GLRenderer->mVBO);
GLRenderer->mVBO->Reset(); GLRenderer->mVBO->Reset();
GLRenderer->mLights->Clear(); GLRenderer->mLights->Clear();
sector_t *viewsector = RenderViewpoint(players[consoleplayer].camera, &bounds, r_viewpoint.FieldOfView.Degrees, 1.6f, 1.6f, true, false); sector_t *viewsector = RenderViewpoint(players[consoleplayer].camera, &bounds, r_viewpoint.FieldOfView.Degrees, 1.6f, 1.6f, true, false);
glDisable(GL_STENCIL_TEST); glDisable(GL_STENCIL_TEST);
gl_RenderState.SetFixedColormap(CM_DEFAULT);
gl_RenderState.SetSoftLightLevel(-1); gl_RenderState.SetSoftLightLevel(-1);
GLRenderer->CopyToBackbuffer(&bounds, false); GLRenderer->CopyToBackbuffer(&bounds, false);

View file

@ -28,16 +28,14 @@ public:
GLPortal::drawer = this; GLPortal::drawer = this;
} }
int FixedColormap;
angle_t FrustumAngle(); angle_t FrustumAngle();
void SetViewMatrix(float vx, float vy, float vz, bool mirror, bool planemirror); 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 SetupView(float vx, float vy, float vz, DAngle va, bool mirror, bool planemirror);
void SetViewAngle(DAngle viewangle); void SetViewAngle(DAngle viewangle);
void SetProjection(VSMatrix matrix); void SetProjection(VSMatrix matrix);
void Set3DViewport(bool mainview); void Set3DViewport(bool mainview);
void Reset3DViewport(); void Reset3DViewport();
void SetFixedColormap(player_t *player);
void DrawScene(FDrawInfo *di, int drawmode); void DrawScene(FDrawInfo *di, int drawmode);
void ProcessScene(FDrawInfo *di, bool toscreen = false); void ProcessScene(FDrawInfo *di, bool toscreen = false);
void EndDrawScene(FDrawInfo *di, sector_t * viewsector); 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 *RenderViewpoint(AActor * camera, IntRect * bounds, float fov, float ratio, float fovratio, bool mainview, bool toscreen);
sector_t *RenderView(player_t *player); sector_t *RenderView(player_t *player);
void WriteSavePic(player_t *player, FileWriter *file, int width, int height); 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);
}
}; };

View file

@ -299,7 +299,7 @@ void GLSkyPortal::DrawContents(FDrawInfo *di)
RenderDome(origin->texture[1], origin->x_offset[1], origin->y_offset, false, FSkyVertexBuffer::SKYMODE_SECONDLAYER); 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; PalEntry FadeColor = origin->fadecolor;
FadeColor.a = clamp<int>(::level.skyfog, 0, 255); FadeColor.a = clamp<int>(::level.skyfog, 0, 255);

View file

@ -92,7 +92,7 @@ void FDrawInfo::DrawSprite(GLSprite *sprite, int pass)
gl_SetRenderStyle(RenderStyle, false, gl_SetRenderStyle(RenderStyle, false,
// The rest of the needed checks are done inside gl_SetRenderStyle // 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()); sprite->fullbright && sprite->gltexture && !sprite->gltexture->tex->GetTranslucency());
if (sprite->hw_styleflags == STYLEHW_NoAlphaTest) if (sprite->hw_styleflags == STYLEHW_NoAlphaTest)
@ -144,7 +144,7 @@ void FDrawInfo::DrawSprite(GLSprite *sprite, int pass)
} }
if (RenderStyle.BlendOp != STYLEOP_Shadow) 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. 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); 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. 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 else
{ {
gl_RenderState.EnableFog(false); 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)); 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); 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; unsigned int iter = sprite->lightlist? sprite->lightlist->Size() : 1;
bool clipping = false; bool clipping = false;
@ -231,10 +231,10 @@ void FDrawInfo::DrawSprite(GLSprite *sprite, int pass)
thiscm.Decolorize(); thiscm.Decolorize();
} }
mDrawer->SetColor(thisll, rel, thiscm, sprite->trans); SetColor(thisll, rel, thiscm, sprite->trans);
if (!foglayer) if (!foglayer)
{ {
mDrawer->SetFog(thislight, rel, &thiscm, additivefog); SetFog(thislight, rel, &thiscm, additivefog);
} }
gl_RenderState.SetSplitPlanes(*topplane, *lowplane); gl_RenderState.SetSplitPlanes(*topplane, *lowplane);
} }
@ -265,7 +265,7 @@ void FDrawInfo::DrawSprite(GLSprite *sprite, int pass)
if (foglayer) if (foglayer)
{ {
// If we get here we know that we have colored fog and no fixed colormap. // 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.SetTextureMode(TM_FOGLAYER);
gl_RenderState.BlendEquation(GL_FUNC_ADD); gl_RenderState.BlendEquation(GL_FUNC_ADD);
gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

View file

@ -65,10 +65,10 @@ void FDrawInfo::RenderWall(GLWall *wall, int textured)
void FDrawInfo::RenderFogBoundary(GLWall *wall) void FDrawInfo::RenderFogBoundary(GLWall *wall)
{ {
if (gl_fogmode && mDrawer->FixedColormap == 0) if (gl_fogmode && !isFullbrightScene())
{ {
int rel = wall->rellight + getExtraLight(); 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.EnableDrawBuffers(1);
gl_RenderState.SetEffect(EFF_FOGBOUNDARY); gl_RenderState.SetEffect(EFF_FOGBOUNDARY);
gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f); gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f);
@ -99,8 +99,8 @@ void FDrawInfo::RenderMirrorSurface(GLWall *wall)
// Use sphere mapping for this // Use sphere mapping for this
gl_RenderState.SetEffect(EFF_SPHEREMAP); gl_RenderState.SetEffect(EFF_SPHEREMAP);
mDrawer->SetColor(wall->lightlevel, 0, wall->Colormap ,0.1f); SetColor(wall->lightlevel, 0, wall->Colormap ,0.1f);
mDrawer->SetFog(wall->lightlevel, 0, &wall->Colormap, true); SetFog(wall->lightlevel, 0, &wall->Colormap, true);
gl_RenderState.BlendFunc(GL_SRC_ALPHA,GL_ONE); gl_RenderState.BlendFunc(GL_SRC_ALPHA,GL_ONE);
gl_RenderState.AlphaFunc(GL_GREATER,0); gl_RenderState.AlphaFunc(GL_GREATER,0);
glDepthFunc(GL_LEQUAL); glDepthFunc(GL_LEQUAL);
@ -161,7 +161,7 @@ void FDrawInfo::RenderTexturedWall(GLWall *wall, int rflags)
{ {
if (tmode == TM_MODULATE) gl_RenderState.SetTextureMode(TM_CLAMPY); 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.SetObjectColor(wall->seg->frontsector->SpecialColors[sector_t::walltop] | 0xff000000);
gl_RenderState.SetObjectColor2(wall->seg->frontsector->SpecialColors[sector_t::wallbottom] | 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); float absalpha = fabsf(wall->alpha);
if (wall->lightlist == nullptr) if (wall->lightlist == nullptr)
{ {
if (wall->type != RENDERWALL_M2SNF) mDrawer->SetFog(wall->lightlevel, rel, &wall->Colormap, wall->RenderStyle == STYLE_Add); if (wall->type != RENDERWALL_M2SNF) SetFog(wall->lightlevel, rel, &wall->Colormap, wall->RenderStyle == STYLE_Add);
mDrawer->SetColor(wall->lightlevel, rel, wall->Colormap, absalpha); SetColor(wall->lightlevel, rel, wall->Colormap, absalpha);
RenderWall(wall, rflags); RenderWall(wall, rflags);
} }
else else
@ -191,8 +191,8 @@ void FDrawInfo::RenderTexturedWall(GLWall *wall, int rflags)
thiscm.FadeColor = wall->Colormap.FadeColor; thiscm.FadeColor = wall->Colormap.FadeColor;
thiscm.FogDensity = wall->Colormap.FogDensity; thiscm.FogDensity = wall->Colormap.FogDensity;
thiscm.CopyFrom3DLight(&(*wall->lightlist)[i]); thiscm.CopyFrom3DLight(&(*wall->lightlist)[i]);
mDrawer->SetColor(thisll, rel, thiscm, absalpha); SetColor(thisll, rel, thiscm, absalpha);
if (wall->type != RENDERWALL_M2SNF) mDrawer->SetFog(thisll, rel, &thiscm, wall->RenderStyle == STYLE_Add); if (wall->type != RENDERWALL_M2SNF) SetFog(thisll, rel, &thiscm, wall->RenderStyle == STYLE_Add);
gl_RenderState.SetSplitPlanes((*wall->lightlist)[i].plane, lowplane); gl_RenderState.SetSplitPlanes((*wall->lightlist)[i].plane, lowplane);
RenderWall(wall, rflags); RenderWall(wall, rflags);
} }
@ -226,8 +226,8 @@ void FDrawInfo::RenderTranslucentWall(GLWall *wall)
else else
{ {
gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f); gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f);
mDrawer->SetColor(wall->lightlevel, 0, wall->Colormap, fabsf(wall->alpha)); SetColor(wall->lightlevel, 0, wall->Colormap, fabsf(wall->alpha));
mDrawer->SetFog(wall->lightlevel, 0, &wall->Colormap, wall->RenderStyle == STYLE_Add); SetFog(wall->lightlevel, 0, &wall->Colormap, wall->RenderStyle == STYLE_Add);
gl_RenderState.EnableTexture(false); gl_RenderState.EnableTexture(false);
RenderWall(wall, GLWall::RWF_NOSPLIT); RenderWall(wall, GLWall::RWF_NOSPLIT);
gl_RenderState.EnableTexture(true); gl_RenderState.EnableTexture(true);
@ -243,7 +243,7 @@ void FDrawInfo::DrawWall(GLWall *wall, int pass)
{ {
if (screen->hwcaps & RFL_BUFFER_STORAGE) 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); wall->SetupLights(this, lightdata);
} }
@ -426,7 +426,7 @@ void FDrawInfo::DrawDecal(GLDecal *gldecal)
auto tex = gldecal->gltexture; auto tex = gldecal->gltexture;
// calculate dynamic light effect. // 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. // Note: This should be replaced with proper shader based lighting.
double x, y; double x, y;
@ -451,7 +451,7 @@ void FDrawInfo::DrawDecal(GLDecal *gldecal)
else gl_RenderState.AlphaFunc(GL_GREATER, 0.f); 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. // for additively drawn decals we must temporarily set the fog color to black.
PalEntry fc = gl_RenderState.GetFogColor(); PalEntry fc = gl_RenderState.GetFogColor();
if (decal->RenderStyle.BlendOp == STYLEOP_Add && decal->RenderStyle.DestAlpha == STYLEALPHA_One) if (decal->RenderStyle.BlendOp == STYLEOP_Add && decal->RenderStyle.DestAlpha == STYLEALPHA_One)
@ -484,9 +484,9 @@ void FDrawInfo::DrawDecal(GLDecal *gldecal)
FColormap thiscm; FColormap thiscm;
thiscm.FadeColor = gldecal->Colormap.FadeColor; thiscm.FadeColor = gldecal->Colormap.FadeColor;
thiscm.CopyFrom3DLight(&lightlist[k]); 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(); 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.SetSplitPlanes(lightlist[k].plane, lowplane);
gl_RenderState.Apply(); gl_RenderState.Apply();
@ -526,7 +526,7 @@ void FDrawInfo::DrawDecals()
{ {
gl_RenderState.EnableSplit(false); gl_RenderState.EnableSplit(false);
splitting = false; splitting = false;
mDrawer->SetFog(gldecal->lightlevel, gldecal->rellight, &gldecal->Colormap, false); SetFog(gldecal->lightlevel, gldecal->rellight, &gldecal->Colormap, false);
} }
} }
DrawDecal(gldecal); DrawDecal(gldecal);
@ -541,7 +541,7 @@ void FDrawInfo::DrawDecals()
//========================================================================== //==========================================================================
void FDrawInfo::DrawDecalsForMirror(GLWall *wall) 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]) for (auto gldecal : decals[1])
{ {
if (gldecal->decal->Side == wall->seg->sidedef) if (gldecal->decal->Side == wall->seg->sidedef)

View file

@ -56,7 +56,7 @@ void FDrawInfo::DrawPSprite (HUDSprite *huds)
} }
else 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_SetRenderStyle(huds->RenderStyle, false, false);
gl_RenderState.SetObjectColor(huds->ObjectColor); gl_RenderState.SetObjectColor(huds->ObjectColor);

View file

@ -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 uDesaturationFactor;\n";
i_data += "uniform float uInterpolationFactor;\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 // Glowing walls stuff
i_data += "uniform vec4 uGlowTopPlane;\n"; i_data += "uniform vec4 uGlowTopPlane;\n";
i_data += "uniform vec4 uGlowTopColor;\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"); muCameraPos.Init(hShader, "uCameraPos");
muLightParms.Init(hShader, "uLightAttr"); muLightParms.Init(hShader, "uLightAttr");
muClipSplit.Init(hShader, "uClipSplit"); muClipSplit.Init(hShader, "uClipSplit");
muColormapStart.Init(hShader, "uFixedColormapStart");
muColormapRange.Init(hShader, "uFixedColormapRange");
muLightIndex.Init(hShader, "uLightIndex"); muLightIndex.Init(hShader, "uLightIndex");
muFogColor.Init(hShader, "uFogColor"); muFogColor.Init(hShader, "uFogColor");
muDynLightColor.Init(hShader, "uDynLightColor"); 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"); muSplitBottomPlane.Init(hShader, "uSplitBottomPlane");
muSplitTopPlane.Init(hShader, "uSplitTopPlane"); muSplitTopPlane.Init(hShader, "uSplitTopPlane");
muClipLine.Init(hShader, "uClipLine"); muClipLine.Init(hShader, "uClipLine");
muFixedColormap.Init(hShader, "uFixedColormap");
muInterpolationFactor.Init(hShader, "uInterpolationFactor"); muInterpolationFactor.Init(hShader, "uInterpolationFactor");
muClipHeight.Init(hShader, "uClipHeight"); muClipHeight.Init(hShader, "uClipHeight");
muClipHeightDirection.Init(hShader, "uClipHeightDirection"); 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" }, { "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" }, { "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" }, { "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() FShaderManager::FShaderManager()
@ -557,12 +548,6 @@ void FShaderManager::ApplyMatrices(VSMatrix *proj, VSMatrix *view, EPassType pas
mActiveShader->Bind(); mActiveShader->Bind();
} }
void FShaderManager::ResetFixedColormap()
{
for (auto &collection : mPassShaders)
collection->ResetFixedColormap();
}
//========================================================================== //==========================================================================
// //
// //

View file

@ -248,9 +248,6 @@ class FShader
FBufferedUniform4f muCameraPos; FBufferedUniform4f muCameraPos;
FBufferedUniform4f muLightParms; FBufferedUniform4f muLightParms;
FBufferedUniform2f muClipSplit; FBufferedUniform2f muClipSplit;
FUniform1i muFixedColormap;
FUniform4f muColormapStart;
FUniform4f muColormapRange;
FBufferedUniform1i muLightIndex; FBufferedUniform1i muLightIndex;
FBufferedUniformPE muFogColor; FBufferedUniformPE muFogColor;
FBufferedUniform4f muDynLightColor; FBufferedUniform4f muDynLightColor;
@ -331,8 +328,6 @@ public:
FShader *Get(unsigned int eff, bool alphateston, EPassType passType); FShader *Get(unsigned int eff, bool alphateston, EPassType passType);
void ApplyMatrices(VSMatrix *proj, VSMatrix *view, EPassType passType); void ApplyMatrices(VSMatrix *proj, VSMatrix *view, EPassType passType);
void ResetFixedColormap();
private: private:
FShader *mActiveShader = nullptr; FShader *mActiveShader = nullptr;
TArray<FShaderCollection*> mPassShaders; TArray<FShaderCollection*> mPassShaders;
@ -355,18 +350,6 @@ public:
FShader *BindEffect(int effect); FShader *BindEffect(int effect);
void ApplyMatrices(VSMatrix *proj, VSMatrix *view); 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) FShader *Get(unsigned int eff, bool alphateston)
{ {
// indices 0-2 match the warping modes, 3 is brightmap, 4 no texture, the following are custom // indices 0-2 match the warping modes, 3 is brightmap, 4 no texture, the following are custom

View file

@ -372,14 +372,6 @@ void OpenGLFrameBuffer::TextureFilterChanged()
if (GLRenderer != NULL && GLRenderer->mSamplerManager != NULL) GLRenderer->mSamplerManager->SetTextureFilterMode(); 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) void OpenGLFrameBuffer::BlurScene(float amount)
{ {
GLRenderer->BlurScene(amount); GLRenderer->BlurScene(amount);

View file

@ -39,7 +39,6 @@ public:
void UnbindTexUnit(int no) override; void UnbindTexUnit(int no) override;
void FlushTextures() override; void FlushTextures() override;
void TextureFilterChanged() override; void TextureFilterChanged() override;
void ResetFixedColormap() override;
void BeginFrame() override; void BeginFrame() override;
void SetViewportRects(IntRect *bounds) override; void SetViewportRects(IntRect *bounds) override;
void BlurScene(float amount) override; void BlurScene(float amount) override;

View file

@ -13,6 +13,7 @@ enum TexMode
TM_CLAMPY, // (r, g, b, (t >= 0.0 && t <= 1.0)? a:0) TM_CLAMPY, // (r, g, b, (t >= 0.0 && t <= 1.0)? a:0)
TM_INVERTOPAQUE, // (1-r, 1-g, 1-b, 1) TM_INVERTOPAQUE, // (1-r, 1-g, 1-b, 1)
TM_FOGLAYER, // (renders a fog layer in the shape of the active texture) 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 enum ELightMethod

View file

@ -80,7 +80,18 @@ struct HWDrawInfo
uint8_t flags; uint8_t flags;
}; };
int FixedColormap; 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 FullbrightFlags;
std::atomic<int> spriteindex; std::atomic<int> spriteindex;
IPortal *mClipPortal; IPortal *mClipPortal;
FRotator mAngles; FRotator mAngles;
@ -141,6 +152,7 @@ public:
void ClearBuffers(); void ClearBuffers();
void SetViewArea(); void SetViewArea();
int SetFullbrightFlags(player_t *player);
bool DoOneSectorUpper(subsector_t * subsec, float planez, area_t in_area); bool DoOneSectorUpper(subsector_t * subsec, float planez, area_t in_area);
bool DoOneSectorLower(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 GLDecal *AddDecal(bool onmirror) = 0;
virtual std::pair<FFlatVertex *, unsigned int> AllocVertices(unsigned int count) = 0; virtual std::pair<FFlatVertex *, unsigned int> AllocVertices(unsigned int count) = 0;
}; };

View file

@ -29,9 +29,11 @@
#include "p_local.h" #include "p_local.h"
#include "g_levellocals.h" #include "g_levellocals.h"
#include "a_sharedglobal.h" #include "a_sharedglobal.h"
#include "d_player.h"
#include "r_sky.h" #include "r_sky.h"
#include "hw_fakeflat.h" #include "hw_fakeflat.h"
#include "hw_drawinfo.h" #include "hw_drawinfo.h"
#include "hwrenderer/utility/hw_cvars.h"
#include "r_utility.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;
}
}

View file

@ -147,7 +147,7 @@ bool GLFlat::SetupSectorLights(int pass, sector_t * sec, FDynLightData &lightdat
inline void GLFlat::PutFlat(HWDrawInfo *di, bool fog) inline void GLFlat::PutFlat(HWDrawInfo *di, bool fog)
{ {
if (di->FixedColormap) if (di->isFullbrightScene())
{ {
Colormap.Clear(); 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_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)) if (!rover->top.copied && rover->flags&(FF_INVERTPLANES | FF_BOTHPLANES))
{ {
double ff_top = rover->top.plane->ZatPoint(sector->centerspot); 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_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)) if (!rover->bottom.copied && rover->flags&(FF_INVERTPLANES | FF_BOTHPLANES))
{ {
double ff_bottom = rover->bottom.plane->ZatPoint(sector->centerspot); double ff_bottom = rover->bottom.plane->ZatPoint(sector->centerspot);

View file

@ -219,7 +219,7 @@ bool GLSprite::CalculateVertices(HWDrawInfo *di, FVector3 *v)
inline void GLSprite::PutSprite(HWDrawInfo *di, bool translucent) inline void GLSprite::PutSprite(HWDrawInfo *di, bool translucent)
{ {
// That's a lot of checks... // 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); hw_GetDynModelLight(actor, lightdata);
dynlightindex = di->UploadLights(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->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; return;
} }
@ -655,19 +655,15 @@ void GLSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t
RenderStyle = thing->RenderStyle; RenderStyle = thing->RenderStyle;
// colormap stuff is a little more complicated here... // 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 enhancedvision = di->isStealthVision();
|| (gl_enhanced_nv_stealth == 2 && di->FixedColormap >= CM_TORCH)// Also torches
|| (gl_enhanced_nv_stealth == 3)) // Any fixed colormap
enhancedvision = true;
Colormap.Clear(); Colormap.Clear();
if (di->FixedColormap == CM_LITE) if (di->isNightvision())
{ {
if (gl_enhanced_nightvision && if ((thing->IsKindOf(RUNTIME_CLASS(AInventory)) || thing->flags3&MF3_ISMONSTER || thing->flags&MF_MISSILE || thing->flags&MF_CORPSE))
(thing->IsKindOf(RUNTIME_CLASS(AInventory)) || thing->flags3&MF3_ISMONSTER || thing->flags&MF_MISSILE || thing->flags&MF_CORPSE))
{ {
RenderStyle.Flags |= STYLEF_InvertSource; RenderStyle.Flags |= STYLEF_InvertSource;
} }
@ -811,7 +807,7 @@ void GLSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t
// 3. any bright object // 3. any bright object
// 4. any with render style shadow (which doesn't use the sector light) // 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) // 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) RenderStyle.BlendOp != STYLEOP_Shadow && RenderStyle.BlendOp != STYLEOP_RevSub)
{ {
if (screen->hwcaps & RFL_NO_CLIP_PLANES) // on old hardware we are rather limited... 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()); sector->GetCeilingLight() : sector->GetFloorLight());
foglevel = (uint8_t)clamp<short>(sector->lightlevel, 0, 255); foglevel = (uint8_t)clamp<short>(sector->lightlevel, 0, 255);
if (di->FixedColormap) if (di->isFullbrightScene())
{ {
Colormap.Clear(); 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; if (gl_particles_style != 2 && trans>=1.0f-FLT_EPSILON) hw_styleflags = STYLEHW_Solid;
else hw_styleflags = STYLEHW_NoAlphaTest; 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 = &sector->e->XFloor.lightlist; lightlist = &sector->e->XFloor.lightlist;
else else
lightlist = nullptr; lightlist = nullptr;

View file

@ -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(); 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 // light planes don't get drawn with fullbright rendering
if (gltexture == NULL) return; if (gltexture == NULL) return;
Colormap.Clear(); Colormap.Clear();
} }
if (di->FixedColormap != CM_DEFAULT || (Colormap.LightColor.isWhite() && lightlevel == 255)) if (di->isFullbrightScene() || (Colormap.LightColor.isWhite() && lightlevel == 255))
flags &= ~GLWF_GLOW; flags &= ~GLWF_GLOW;
if (!(screen->hwcaps & RFL_BUFFER_STORAGE)) 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); 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); hi.colormap.CopyLight(light->extra_colormap);
} }
if (di->FixedColormap) hi.colormap.Clear(); if (di->isFullbrightScene()) hi.colormap.Clear();
horizon = &hi; horizon = &hi;
PutPortal(di, PORTALTYPE_HORIZON); 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); hi.colormap.CopyLight(light->extra_colormap);
} }
if (di->FixedColormap) hi.colormap.Clear(); if (di->isFullbrightScene()) hi.colormap.Clear();
horizon = &hi; horizon = &hi;
PutPortal(di, PORTALTYPE_HORIZON); 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 // Add this wall to the render list
sector_t * sec = sub ? sub->sector : seg->frontsector; 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); else SplitWall(di, sec, false);
} }
@ -1076,7 +1076,7 @@ void GLWall::DoMidTexture(HWDrawInfo *di, seg_t * seg, bool drawfogboundary,
// Draw the stuff // 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); else split.SplitWall(di, front, translucent);
t=1; t=1;
@ -1090,7 +1090,7 @@ void GLWall::DoMidTexture(HWDrawInfo *di, seg_t * seg, bool drawfogboundary,
// Draw the stuff without splitting // 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); else SplitWall(di, front, translucent);
} }
alpha=1.0f; alpha=1.0f;
@ -1123,7 +1123,7 @@ void GLWall::BuildFFBlock(HWDrawInfo *di, seg_t * seg, F3DFloor * rover,
if (rover->flags&FF_FOG) if (rover->flags&FF_FOG)
{ {
if (!di->FixedColormap) if (!di->isFullbrightScene())
{ {
// this may not yet be done // this may not yet be done
light = P_GetPlaneLight(rover->target, rover->top.plane, true); 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; 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); else SplitWall(di, sec, translucent);
alpha = 1.0f; 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]; bool isportal = seg->linedef->isVisualPortal() && seg->sidedef == seg->linedef->sidedef[0];
sector_t *backsec = isportal? seg->linedef->getPortalDestination()->frontsector : backsector; 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)); FTexture *tex = TexMan(seg->sidedef->GetTexture(side_t::mid));
if (tex != NULL) if (tex != NULL)
{ {

View file

@ -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; WeaponLighting l;
if (FixedColormap) if (cm)
{ {
l.lightlevel = 255; l.lightlevel = 255;
l.cm.Clear(); l.cm.Clear();
@ -438,7 +438,7 @@ void HWDrawInfo::PreparePlayerSprites(sector_t * viewsector, area_t in_area)
return; return;
WeaponPosition weap = GetWeaponPosition(camera->player); 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 // hack alert! Rather than changing everything in the underlying lighting code let's just temporarily change
// light mode here to draw the weapon sprite. // 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.dynrgb[0] = hudsprite.dynrgb[1] = hudsprite.dynrgb[2] = 0;
hudsprite.lightindex = -1; hudsprite.lightindex = -1;
// set the lighting parameters // 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) if (!hudModelStep)
{ {

View file

@ -34,14 +34,7 @@
static float distfogtable[2][256]; // light to fog conversion table for black fog static float distfogtable[2][256]; // light to fog conversion table for black fog
CVAR(Int, gl_weaponlight, 8, CVAR_ARCHIVE); CVAR(Int, gl_weaponlight, 8, CVAR_ARCHIVE);
CUSTOM_CVAR(Bool, gl_enhanced_nightvision, true, CVAR_ARCHIVE|CVAR_NOINITCALL) 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();
}
//========================================================================== //==========================================================================
// //

View file

@ -128,18 +128,11 @@ extern uint8_t DesaturateColormap[31][256];
enum EColorManipulation 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_PLAIN2D = -2, // regular 2D drawing.
CM_INVALID = -1, CM_INVALID = -1,
CM_DEFAULT = 0, // untranslated CM_DEFAULT = 0, // untranslated
CM_FIRSTSPECIALCOLORMAP, // first special fixed colormap CM_FIRSTSPECIALCOLORMAP, // first special fixed colormap
CM_FIRSTSPECIALCOLORMAPFORCED = 0x08000000, // first special fixed colormap, application forced (for 2D overlays) 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()) #define CM_MAXCOLORMAP int(CM_FIRSTSPECIALCOLORMAP + SpecialColormaps.Size())

View file

@ -180,8 +180,12 @@ bool F2DDrawer::SetStyle(FTexture *tex, DrawParms &parms, PalEntry &vertexcolor,
} }
if (parms.specialcolormap != nullptr) if (parms.specialcolormap != nullptr)
{ // Emulate an invulnerability or similar colormap. { // draw with an invulnerability or similar colormap.
quad.mSpecialColormap = parms.specialcolormap;
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.mColor1 = 0; // this disables the color overlay.
} }
quad.mDesaturate = parms.desaturate; quad.mDesaturate = parms.desaturate;

View file

@ -76,7 +76,7 @@ public:
FTexture *mTexture; FTexture *mTexture;
FRemapTable *mTranslation; FRemapTable *mTranslation;
FSpecialColormap *mSpecialColormap; PalEntry mSpecialColormap[2];
int mScissor[4]; int mScissor[4];
int mDesaturate; int mDesaturate;
FRenderStyle mRenderStyle; FRenderStyle mRenderStyle;

View file

@ -49,6 +49,7 @@
#include "i_video.h" #include "i_video.h"
#include "g_levellocals.h" #include "g_levellocals.h"
#include "vm.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 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); 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) if (player)
{ {

View file

@ -407,7 +407,6 @@ public:
virtual void UnbindTexUnit(int no) {} virtual void UnbindTexUnit(int no) {}
virtual void FlushTextures() {} virtual void FlushTextures() {}
virtual void TextureFilterChanged() {} virtual void TextureFilterChanged() {}
virtual void ResetFixedColormap() {}
virtual void BeginFrame() {} virtual void BeginFrame() {}
virtual int GetClientWidth() = 0; virtual int GetClientWidth() = 0;

View file

@ -75,9 +75,11 @@ vec4 getTexel(vec2 st)
break; break;
case 4: // TM_REDTOALPHA case 4: // TM_REDTOALPHA
{
float gray = grayscale(texel); float gray = grayscale(texel);
texel = vec4(1.0, 1.0, 1.0, gray*texel.a); texel = vec4(1.0, 1.0, 1.0, gray*texel.a);
break; break;
}
case 5: // TM_CLAMPY case 5: // TM_CLAMPY
if (st.t < 0.0 || st.t > 1.0) if (st.t < 0.0 || st.t > 1.0)
@ -92,6 +94,7 @@ vec4 getTexel(vec2 st)
case 7: //TM_FOGLAYER case 7: //TM_FOGLAYER
return texel; return texel;
} }
if (uObjectColor2.a == 0.0) texel *= uObjectColor; if (uObjectColor2.a == 0.0) texel *= uObjectColor;
else texel *= mix(uObjectColor, uObjectColor2, glowdist.z); else texel *= mix(uObjectColor, uObjectColor2, glowdist.z);
@ -431,35 +434,11 @@ void main()
if (frag.a <= uAlphaThreshold) discard; if (frag.a <= uAlphaThreshold) discard;
#endif #endif
if (uTextureMode == 7) if (uFogEnabled != -3) // check for special 2D 'fog' mode.
{
float fogdist;
float fogfactor;
//
// calculate fog factor
//
if (uFogEnabled == -1)
{
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 fogdist = 0.0;
float fogfactor = 0.0; float fogfactor = 0.0;
// //
// calculate fog factor // calculate fog factor
// //
@ -476,8 +455,9 @@ void main()
fogfactor = exp2 (uFogDensity * fogdist); fogfactor = exp2 (uFogDensity * fogdist);
} }
if (uTextureMode != 7)
{
frag = getLightColor(frag, fogdist, fogfactor); frag = getLightColor(frag, fogdist, fogfactor);
// //
// colored fog // colored fog
// //
@ -485,36 +465,22 @@ void main()
{ {
frag = applyFog(frag, fogfactor); frag = applyFog(frag, fogfactor);
} }
break;
} }
else
case 1: // special colormap {
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); float gray = grayscale(frag);
vec4 cm = uFixedColormapStart + gray * uFixedColormapRange; vec4 cm = (uObjectColor + gray * (uObjectColor2 - uObjectColor)) * 2;
frag = vec4(clamp(cm.rgb, 0.0, 1.0), frag.a*vColor.a); frag = vec4(clamp(cm.rgb, 0.0, 1.0), frag.a);
break;
} }
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 = frag * ProcessLight(vColor);
frag.rgb = frag.rgb + uFogColor.rgb; frag.rgb = frag.rgb + uFogColor.rgb;
break;
}
} }
FragColor = frag; FragColor = frag;
#ifdef GBUFFER_PASS #ifdef GBUFFER_PASS

View file

@ -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);
}
}

View file

@ -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
}

View file

@ -1,6 +0,0 @@
void main()
{
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform();
}