mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-11 23:32:02 +00:00
pass softlightlevel through render state.
This commit is contained in:
parent
b9a6fe80a4
commit
98cc7eeb99
13 changed files with 45 additions and 94 deletions
|
@ -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;
|
||||
}
|
||||
|
@ -252,83 +252,24 @@ PalEntry gl_CalcLightColor(int light, PalEntry pe, int blendfactor, bool force)
|
|||
return PalEntry(255, BYTE(r), BYTE(g), BYTE(b));
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// Get 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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
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)
|
||||
void gl_SetColor(int sectorlightlevel, int rellight, const FColormap &cm, float alpha, 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)
|
||||
if (gl_fixedcolormap != CM_DEFAULT)
|
||||
{
|
||||
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);
|
||||
gl_RenderState.SetColorAlpha(0xffffff, alpha, 0);
|
||||
gl_RenderState.SetSoftLightLevel(255);
|
||||
}
|
||||
else
|
||||
{
|
||||
float lightlevel = gl_CalcLightLevel(light, rellight, weapon) / 255.0f;
|
||||
glVertexAttrib1f(VATTR_LIGHTLEVEL, lightlevel);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue