From 98cc7eeb99087e3e2976c9474bd05d08ed3a926c Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 12 May 2014 00:13:19 +0200 Subject: [PATCH] pass softlightlevel through render state. --- src/gl/renderer/gl_lightdata.cpp | 91 ++++++------------------------ src/gl/renderer/gl_lightdata.h | 4 +- src/gl/renderer/gl_renderer.cpp | 2 +- src/gl/renderer/gl_renderstate.cpp | 5 ++ src/gl/renderer/gl_renderstate.h | 6 ++ src/gl/scene/gl_decal.cpp | 2 +- src/gl/scene/gl_drawinfo.cpp | 2 +- src/gl/scene/gl_flats.cpp | 6 +- src/gl/scene/gl_portal.cpp | 4 +- src/gl/scene/gl_scene.cpp | 2 +- src/gl/scene/gl_sprite.cpp | 2 +- src/gl/scene/gl_walls_draw.cpp | 11 ++-- src/gl/scene/gl_weapon.cpp | 2 +- 13 files changed, 45 insertions(+), 94 deletions(-) diff --git a/src/gl/renderer/gl_lightdata.cpp b/src/gl/renderer/gl_lightdata.cpp index 60bc1bd67..60ecf70be 100644 --- a/src/gl/renderer/gl_lightdata.cpp +++ b/src/gl/renderer/gl_lightdata.cpp @@ -225,11 +225,11 @@ int gl_CalcLightLevel(int lightlevel, int rellight, bool weapon) // //========================================================================== -PalEntry gl_CalcLightColor(int light, PalEntry pe, int blendfactor, bool force) +static PalEntry gl_CalcLightColor(int light, PalEntry pe, int blendfactor) { int r,g,b; - if (glset.lightmode == 8 && !force) + if (glset.lightmode == 8) { return pe; } @@ -254,81 +254,22 @@ PalEntry gl_CalcLightColor(int light, PalEntry pe, int blendfactor, bool force) //========================================================================== // -// Get current light color +// set current light color // //========================================================================== -void gl_GetLightColor(int lightlevel, int rellight, const FColormap * cm, float * pred, float * pgreen, float * pblue, bool weapon) -{ - float & r=*pred,& g=*pgreen,& b=*pblue; - int torch=0; - - if (gl_fixedcolormap) +void gl_SetColor(int sectorlightlevel, int rellight, const FColormap &cm, float alpha, bool weapon) +{ + if (gl_fixedcolormap != CM_DEFAULT) { - if (!gl_enhanced_nightvision || !gl.hasGLSL()) - { - // we cannot multiply the light in here without causing major problems with the ThingColor so for older hardware - // these maps are done as a postprocessing overlay. - r = g = b = 1.0f; - } - else if (gl_fixedcolormap == CM_LITE) - { - r = 0.375f, g = 1.0f, b = 0.375f; - } - else if (gl_fixedcolormap >= CM_TORCH) - { - int flicker = gl_fixedcolormap - CM_TORCH; - r = (0.8f + (7 - flicker) / 70.0f); - if (r > 1.0f) r = 1.0f; - g = r; - b = g * 0.75f; - } - else r = g = b = 1.0f; - return; + gl_RenderState.SetColorAlpha(0xffffff, alpha, 0); + gl_RenderState.SetSoftLightLevel(255); } - - PalEntry lightcolor = cm? cm->LightColor : PalEntry(255,255,255); - int blendfactor = cm? cm->blendfactor : 0; - - lightlevel = gl_CalcLightLevel(lightlevel, rellight, weapon); - PalEntry pe = gl_CalcLightColor(lightlevel, lightcolor, blendfactor); - r = pe.r/255.f; - g = pe.g/255.f; - b = pe.b/255.f; -} - -//========================================================================== -// -// set current light color -// -//========================================================================== -void gl_SetColor(int light, int rellight, const FColormap * cm, float *red, float *green, float *blue, bool weapon) -{ - gl_GetLightColor(light, rellight, cm, red, green, blue, weapon); -} - -//========================================================================== -// -// set current light color -// -//========================================================================== -void gl_SetColor(int light, int rellight, const FColormap * cm, float alpha, bool weapon) -{ - float r,g,b; - - gl_GetLightColor(light, rellight, cm, &r, &g, &b, weapon); - - gl_RenderState.SetColor(r, g, b, alpha, cm->desaturation); - if (glset.lightmode == 8) - { - if (gl_fixedcolormap) - { - glVertexAttrib1f(VATTR_LIGHTLEVEL, 1.0); - } - else - { - float lightlevel = gl_CalcLightLevel(light, rellight, weapon) / 255.0f; - glVertexAttrib1f(VATTR_LIGHTLEVEL, lightlevel); - } + else + { + int hwlightlevel = gl_CalcLightLevel(sectorlightlevel, rellight, weapon); + PalEntry pe = gl_CalcLightColor(hwlightlevel, cm.LightColor, cm.blendfactor); + gl_RenderState.SetColorAlpha(pe, alpha, cm.desaturation); + gl_RenderState.SetSoftLightLevel(gl_ClampLight(sectorlightlevel + rellight)); } } @@ -586,7 +527,9 @@ void gl_SetFog(int lightlevel, int rellight, const FColormap *cmap, bool isaddit // Korshun: fullbright fog like in software renderer. if (glset.lightmode == 8 && glset.brightfog && fogdensity != 0 && fogcolor != 0) - glVertexAttrib1f(VATTR_LIGHTLEVEL, 1.0); + { + gl_RenderState.SetSoftLightLevel(255); + } } } diff --git a/src/gl/renderer/gl_lightdata.h b/src/gl/renderer/gl_lightdata.h index b968bfe7a..f76f732af 100644 --- a/src/gl/renderer/gl_lightdata.h +++ b/src/gl/renderer/gl_lightdata.h @@ -15,9 +15,7 @@ void gl_GetRenderStyle(FRenderStyle style, bool drawopaque, bool allowcolorblend void gl_SetFogParams(int _fogdensity, PalEntry _outsidefogcolor, int _outsidefogdensity, int _skyfog); int gl_CalcLightLevel(int lightlevel, int rellight, bool weapon); -PalEntry gl_CalcLightColor(int light, PalEntry pe, int blendfactor, bool force = false); -void gl_GetLightColor(int lightlevel, int rellight, const FColormap * cm, float * pred, float * pgreen, float * pblue, bool weapon=false); -void gl_SetColor(int light, int rellight, const FColormap * cm, float alpha, bool weapon=false); +void gl_SetColor(int light, int rellight, const FColormap &cm, float alpha, bool weapon=false); float gl_GetFogDensity(int lightlevel, PalEntry fogcolor); struct sector_t; diff --git a/src/gl/renderer/gl_renderer.cpp b/src/gl/renderer/gl_renderer.cpp index f6420ce28..b6d64eeee 100644 --- a/src/gl/renderer/gl_renderer.cpp +++ b/src/gl/renderer/gl_renderer.cpp @@ -593,7 +593,7 @@ void FGLRenderer::FillSimplePoly(FTexture *texture, FVector2 *points, int npoint FColormap cm; cm = colormap; - gl_SetColor(lightlevel, 0, &cm, 1.f); + gl_SetColor(lightlevel, 0, cm, 1.f); gltexture->Bind(); diff --git a/src/gl/renderer/gl_renderstate.cpp b/src/gl/renderer/gl_renderstate.cpp index d6cf1804e..71198bafe 100644 --- a/src/gl/renderer/gl_renderstate.cpp +++ b/src/gl/renderer/gl_renderstate.cpp @@ -212,6 +212,11 @@ bool FRenderState::ApplyShader() glUniform4f(activeShader->dlightcolor_index, mDynColor.r / 255.f, mDynColor.g / 255.f, mDynColor.b / 255.f, 0); } + if (glset.lightmode == 8) + { + glVertexAttrib1f(VATTR_LIGHTLEVEL, mSoftLight / 255.f); + } + return true; } return false; diff --git a/src/gl/renderer/gl_renderstate.h b/src/gl/renderer/gl_renderstate.h index ab58c9509..5308da42b 100644 --- a/src/gl/renderer/gl_renderstate.h +++ b/src/gl/renderer/gl_renderstate.h @@ -96,6 +96,7 @@ class FRenderState bool mBrightmapEnabled; int mSpecialEffect; int mTextureMode; + int mSoftLight; float mLightParms[2]; int mNumLights[3]; float *mLightData; @@ -221,6 +222,11 @@ public: mGlowBottom.Set(b[0], b[1], b[2], b[3]); } + void SetSoftLightLevel(int level) + { + mSoftLight = level; + } + void SetGlowPlanes(const secplane_t &top, const secplane_t &bottom) { mGlowTopPlane.Set(FIXED2FLOAT(top.a), FIXED2FLOAT(top.b), FIXED2FLOAT(top.ic), FIXED2FLOAT(top.d)); diff --git a/src/gl/scene/gl_decal.cpp b/src/gl/scene/gl_decal.cpp index 5e490b8a7..1d15ebcab 100644 --- a/src/gl/scene/gl_decal.cpp +++ b/src/gl/scene/gl_decal.cpp @@ -317,7 +317,7 @@ void GLWall::DrawDecal(DBaseDecal *decal) gl_RenderState.SetObjectColor(decal->AlphaColor); } - gl_SetColor(light, rel, &p, a); + gl_SetColor(light, rel, p, a); // for additively drawn decals we must temporarily set the fog color to black. PalEntry fc = gl_RenderState.GetFogColor(); diff --git a/src/gl/scene/gl_drawinfo.cpp b/src/gl/scene/gl_drawinfo.cpp index 4db9602dc..2c7a4a15a 100644 --- a/src/gl/scene/gl_drawinfo.cpp +++ b/src/gl/scene/gl_drawinfo.cpp @@ -1066,7 +1066,7 @@ void FDrawInfo::DrawFloodedPlane(wallseg * ws, float planez, sector_t * sec, boo } int rel = getExtraLight(); - gl_SetColor(lightlevel, rel, &Colormap, 1.0f); + gl_SetColor(lightlevel, rel, Colormap, 1.0f); gl_SetFog(lightlevel, rel, &Colormap, false); gltexture->Bind(); diff --git a/src/gl/scene/gl_flats.cpp b/src/gl/scene/gl_flats.cpp index 383ee1574..7be264e68 100644 --- a/src/gl/scene/gl_flats.cpp +++ b/src/gl/scene/gl_flats.cpp @@ -395,7 +395,7 @@ void GLFlat::Draw(int pass) switch (pass) { case GLPASS_BASE: - gl_SetColor(lightlevel, rel, &Colormap,1.0f); + gl_SetColor(lightlevel, rel, Colormap,1.0f); if (!foggy) gl_SetFog(lightlevel, rel, &Colormap, false); DrawSubsectors(pass, false); break; @@ -403,7 +403,7 @@ void GLFlat::Draw(int pass) case GLPASS_PLAIN: // Single-pass rendering case GLPASS_ALL: case GLPASS_BASE_MASKED: - gl_SetColor(lightlevel, rel, &Colormap,1.0f); + gl_SetColor(lightlevel, rel, Colormap,1.0f); if (!foggy || pass != GLPASS_BASE_MASKED) gl_SetFog(lightlevel, rel, &Colormap, false); // fall through case GLPASS_TEXTURE: @@ -460,7 +460,7 @@ void GLFlat::Draw(int pass) case GLPASS_TRANSLUCENT: if (renderstyle==STYLE_Add) gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE); - gl_SetColor(lightlevel, rel, &Colormap, alpha); + gl_SetColor(lightlevel, rel, Colormap, alpha); gl_SetFog(lightlevel, rel, &Colormap, false); gl_RenderState.AlphaFunc(GL_GEQUAL,gl_mask_threshold*(alpha)); if (!gltexture) diff --git a/src/gl/scene/gl_portal.cpp b/src/gl/scene/gl_portal.cpp index 020a37b4e..b49b0027d 100644 --- a/src/gl/scene/gl_portal.cpp +++ b/src/gl/scene/gl_portal.cpp @@ -962,13 +962,13 @@ void GLHorizonPortal::DrawContents() if (gltexture && gltexture->tex->isFullbright()) { // glowing textures are always drawn full bright without color - gl_SetColor(255, 0, &origin->colormap, 1.f); + gl_SetColor(255, 0, origin->colormap, 1.f); gl_SetFog(255, 0, &origin->colormap, false); } else { int rel = getExtraLight(); - gl_SetColor(origin->lightlevel, rel, &origin->colormap, 1.0f); + gl_SetColor(origin->lightlevel, rel, origin->colormap, 1.0f); gl_SetFog(origin->lightlevel, rel, &origin->colormap, false); } diff --git a/src/gl/scene/gl_scene.cpp b/src/gl/scene/gl_scene.cpp index d32432a28..3804ea048 100644 --- a/src/gl/scene/gl_scene.cpp +++ b/src/gl/scene/gl_scene.cpp @@ -460,7 +460,7 @@ void FGLRenderer::RenderScene(int recursion) { gl_RenderState.BlendFunc(GL_ONE, GL_ONE); glDepthFunc(GL_EQUAL); - if (glset.lightmode == 8) glVertexAttrib1f(VATTR_LIGHTLEVEL, 1.0f); // Korshun. + gl_RenderState.SetSoftLightLevel(255); for(int i=GLDL_FIRSTLIGHT; i<=GLDL_LASTLIGHT; i++) { gl_drawinfo->drawlists[i].Draw(GLPASS_LIGHT); diff --git a/src/gl/scene/gl_sprite.cpp b/src/gl/scene/gl_sprite.cpp index c051e94ee..41e94a73b 100644 --- a/src/gl/scene/gl_sprite.cpp +++ b/src/gl/scene/gl_sprite.cpp @@ -178,7 +178,7 @@ void GLSprite::Draw(int pass) { gl_SetDynSpriteLight(gl_light_sprites ? actor : NULL, gl_light_particles ? particle : NULL); } - gl_SetColor(lightlevel, rel, &Colormap, trans); + gl_SetColor(lightlevel, rel, Colormap, trans); } gl_RenderState.SetObjectColor(ThingColor); diff --git a/src/gl/scene/gl_walls_draw.cpp b/src/gl/scene/gl_walls_draw.cpp index d3574ebe9..dc7127690 100644 --- a/src/gl/scene/gl_walls_draw.cpp +++ b/src/gl/scene/gl_walls_draw.cpp @@ -371,8 +371,7 @@ void GLWall::RenderFogBoundary() gl_RenderState.EnableFog(false); gl_RenderState.AlphaFunc(GL_GREATER,0); glDepthFunc(GL_LEQUAL); - gl_RenderState.SetColor(fc[0], fc[1], fc[2], fogd1, Colormap.desaturation); - if (glset.lightmode == 8) glVertexAttrib1f(VATTR_LIGHTLEVEL, 1.0); // Korshun. + gl_RenderState.SetColor(fc[0], fc[1], fc[2], fogd1); flags &= ~GLWF_GLOW; RenderWall(4,fc); @@ -403,7 +402,7 @@ void GLWall::RenderMirrorSurface() // Use sphere mapping for this gl_RenderState.SetEffect(EFF_SPHEREMAP); - gl_SetColor(lightlevel, 0, &Colormap ,0.1f); + gl_SetColor(lightlevel, 0, Colormap ,0.1f); gl_SetFog(lightlevel, 0, &Colormap, true); gl_RenderState.BlendFunc(GL_SRC_ALPHA,GL_ONE); gl_RenderState.AlphaFunc(GL_GREATER,0); @@ -471,7 +470,7 @@ void GLWall::RenderTranslucentWall() extra = 0; } - gl_SetColor(lightlevel, extra, &Colormap, fabsf(alpha)); + gl_SetColor(lightlevel, extra, Colormap, fabsf(alpha)); if (type!=RENDERWALL_M2SNF) gl_SetFog(lightlevel, extra, &Colormap, isadditive); else gl_SetFog(255, 0, NULL, false); @@ -523,7 +522,7 @@ void GLWall::Draw(int pass) // fall through case GLPASS_PLAIN: // Single-pass rendering rel = rellight + getExtraLight(); - gl_SetColor(lightlevel, rel, &Colormap,1.0f); + gl_SetColor(lightlevel, rel, Colormap,1.0f); if (type!=RENDERWALL_M2SNF) gl_SetFog(lightlevel, rel, &Colormap, false); else gl_SetFog(255, 0, NULL, false); @@ -537,7 +536,7 @@ void GLWall::Draw(int pass) case GLPASS_BASE: // Base pass for non-masked polygons (all opaque geometry) case GLPASS_BASE_MASKED: // Base pass for masked polygons (2sided mid-textures and transparent 3D floors) rel = rellight + getExtraLight(); - gl_SetColor(lightlevel, rel, &Colormap,1.0f); + gl_SetColor(lightlevel, rel, Colormap,1.0f); if (!(flags&GLWF_FOGGY)) { if (type!=RENDERWALL_M2SNF) gl_SetFog(lightlevel, rel, &Colormap, false); diff --git a/src/gl/scene/gl_weapon.cpp b/src/gl/scene/gl_weapon.cpp index 1b0c99053..c6cd3c5dd 100644 --- a/src/gl/scene/gl_weapon.cpp +++ b/src/gl/scene/gl_weapon.cpp @@ -384,7 +384,7 @@ void FGLRenderer::DrawPlayerSprites(sector_t * viewsector, bool hudModelStep) else { gl_SetDynSpriteLight(playermo, NULL); - gl_SetColor(statebright[i] ? 255 : lightlevel, 0, &cmc, trans, true); + gl_SetColor(statebright[i] ? 255 : lightlevel, 0, cmc, trans, true); } DrawPSprite(player, psp, psp->sx + ofsx, psp->sy + ofsy, hudModelStep, OverrideShader, !!(vis.RenderStyle.Flags & STYLEF_RedIsAlpha)); }