- moved the color/fog setters to hwrenderer.

This commit is contained in:
Christoph Oelckers 2018-10-20 23:33:07 +02:00
parent fac7c7a31c
commit e8f48e7535
6 changed files with 167 additions and 132 deletions

View file

@ -841,6 +841,7 @@ set( FASTMATH_SOURCES
hwrenderer/scene/hw_flats.cpp
hwrenderer/scene/hw_portal.cpp
hwrenderer/scene/hw_renderhacks.cpp
hwrenderer/scene/hw_renderstate.cpp
hwrenderer/scene/hw_sky.cpp
hwrenderer/scene/hw_sprites.cpp
hwrenderer/scene/hw_spritelight.cpp

View file

@ -89,125 +89,3 @@ void gl_GetRenderStyle(FRenderStyle style, bool drawopaque, bool allowcolorblend
}
//==========================================================================
//
// set current light color
//
//==========================================================================
void gl_SetColor(int sectorlightlevel, int rellight, bool fullbright, const FColormap &cm, float alpha, bool weapon)
{
if (fullbright)
{
gl_RenderState.SetColorAlpha(0xffffff, alpha, 0);
gl_RenderState.SetSoftLightLevel(255);
}
else
{
int hwlightlevel = hw_CalcLightLevel(sectorlightlevel, rellight, weapon, cm.BlendFactor);
PalEntry pe = hw_CalcLightColor(hwlightlevel, cm.LightColor, cm.BlendFactor);
gl_RenderState.SetColorAlpha(pe, alpha, cm.Desaturation);
gl_RenderState.SetSoftLightLevel(hw_ClampLight(sectorlightlevel + rellight), cm.BlendFactor);
}
}
//==========================================================================
//
// Lighting stuff
//
//==========================================================================
void gl_SetShaderLight(float level, float olight)
{
const float MAXDIST = 256.f;
const float THRESHOLD = 96.f;
const float FACTOR = 0.75f;
if (level > 0)
{
float lightdist, lightfactor;
if (olight < THRESHOLD)
{
lightdist = (MAXDIST/2) + (olight * MAXDIST / THRESHOLD / 2);
olight = THRESHOLD;
}
else lightdist = MAXDIST;
lightfactor = 1.f + ((olight/level) - 1.f) * FACTOR;
if (lightfactor == 1.f) lightdist = 0.f; // save some code in the shader
gl_RenderState.SetLightParms(lightfactor, lightdist);
}
else
{
gl_RenderState.SetLightParms(1.f, 0.f);
}
}
//==========================================================================
//
// Sets the fog for the current polygon
//
//==========================================================================
void gl_SetFog(int lightlevel, int rellight, bool fullbright, const FColormap *cmap, bool isadditive)
{
PalEntry fogcolor;
float fogdensity;
if (level.flags&LEVEL_HASFADETABLE)
{
fogdensity=70;
fogcolor=0x808080;
}
else if (cmap != NULL && !fullbright)
{
fogcolor = cmap->FadeColor;
fogdensity = hw_GetFogDensity(lightlevel, fogcolor, cmap->FogDensity, cmap->BlendFactor);
fogcolor.a=0;
}
else
{
fogcolor = 0;
fogdensity = 0;
}
// Make fog a little denser when inside a skybox
if (GLRenderer->mPortalState.inskybox) fogdensity+=fogdensity/2;
// no fog in enhanced vision modes!
if (fogdensity==0 || gl_fogmode == 0)
{
gl_RenderState.EnableFog(false);
gl_RenderState.SetFog(0,0);
}
else
{
if ((level.lightmode == 2 || (level.lightmode == 8 && cmap->BlendFactor > 0)) && fogcolor == 0)
{
float light = hw_CalcLightLevel(lightlevel, rellight, false, cmap->BlendFactor);
gl_SetShaderLight(light, lightlevel);
}
else
{
gl_RenderState.SetLightParms(1.f, 0.f);
}
// For additive rendering using the regular fog color here would mean applying it twice
// so always use black
if (isadditive)
{
fogcolor=0;
}
gl_RenderState.EnableFog(true);
gl_RenderState.SetFog(fogcolor, fogdensity);
// Korshun: fullbright fog like in software renderer.
if (level.lightmode == 8 && cmap->BlendFactor == 0 && level.brightfog && fogdensity != 0 && fogcolor != 0)
{
gl_RenderState.SetSoftLightLevel(255);
}
}
}

View file

@ -10,9 +10,5 @@
void gl_GetRenderStyle(FRenderStyle style, bool drawopaque, bool allowcolorblending,
int *tm, int *sb, int *db, int *be);
void gl_SetColor(int light, int rellight, bool fullbright, const FColormap &cm, float alpha, bool weapon=false);
void gl_SetFog(int lightlevel, int rellight, bool fullbright, const FColormap *cm, bool isadditive);
#endif

View file

@ -6,6 +6,8 @@
#include "hwrenderer/scene/hw_weapon.h"
#include "hwrenderer/scene/hw_viewpointuniforms.h"
#include "gl/renderer/gl_renderstate.h" // temporary
#ifdef _MSC_VER
#pragma warning(disable:4244)
#endif
@ -104,12 +106,12 @@ struct FDrawInfo : public HWDrawInfo
void SetColor(int light, int rellight, const FColormap &cm, float alpha, bool weapon = false)
{
gl_SetColor(light, rellight, isFullbrightScene(), cm, alpha, weapon);
gl_RenderState.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);
gl_RenderState.SetFog(lightlevel, rellight, isFullbrightScene(), cmap, isadditive);
}
};

View file

@ -0,0 +1,155 @@
//
//---------------------------------------------------------------------------
//
// Copyright(C) 2000-2018 Christoph Oelckers
// All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see http://www.gnu.org/licenses/
//
//--------------------------------------------------------------------------
//
/*
** hw_renderstate.cpp
** hardware independent part of render state.
**
*/
#include "hw_renderstate.h"
#include "hw_drawstructs.h"
#include "hwrenderer/utility/hw_lighting.h"
#include "hwrenderer/utility/hw_cvars.h"
//==========================================================================
//
// set current light color
//
//==========================================================================
void FRenderState::SetColor(int sectorlightlevel, int rellight, bool fullbright, const FColormap &cm, float alpha, bool weapon)
{
if (fullbright)
{
SetColorAlpha(0xffffff, alpha, 0);
SetSoftLightLevel(255);
}
else
{
int hwlightlevel = hw_CalcLightLevel(sectorlightlevel, rellight, weapon, cm.BlendFactor);
PalEntry pe = hw_CalcLightColor(hwlightlevel, cm.LightColor, cm.BlendFactor);
SetColorAlpha(pe, alpha, cm.Desaturation);
SetSoftLightLevel(hw_ClampLight(sectorlightlevel + rellight), cm.BlendFactor);
}
}
//==========================================================================
//
// Lighting stuff
//
//==========================================================================
void FRenderState::SetShaderLight(float level, float olight)
{
const float MAXDIST = 256.f;
const float THRESHOLD = 96.f;
const float FACTOR = 0.75f;
if (level > 0)
{
float lightdist, lightfactor;
if (olight < THRESHOLD)
{
lightdist = (MAXDIST / 2) + (olight * MAXDIST / THRESHOLD / 2);
olight = THRESHOLD;
}
else lightdist = MAXDIST;
lightfactor = 1.f + ((olight / level) - 1.f) * FACTOR;
if (lightfactor == 1.f) lightdist = 0.f; // save some code in the shader
SetLightParms(lightfactor, lightdist);
}
else
{
SetLightParms(1.f, 0.f);
}
}
//==========================================================================
//
// Sets the fog for the current polygon
//
//==========================================================================
void FRenderState::SetFog(int lightlevel, int rellight, bool fullbright, const FColormap *cmap, bool isadditive)
{
PalEntry fogcolor;
float fogdensity;
if (level.flags&LEVEL_HASFADETABLE)
{
fogdensity = 70;
fogcolor = 0x808080;
}
else if (cmap != NULL && !fullbright)
{
fogcolor = cmap->FadeColor;
fogdensity = hw_GetFogDensity(lightlevel, fogcolor, cmap->FogDensity, cmap->BlendFactor);
fogcolor.a = 0;
}
else
{
fogcolor = 0;
fogdensity = 0;
}
// Make fog a little denser when inside a skybox
//if (GLRenderer->mPortalState.inskybox) fogdensity += fogdensity / 2;
// no fog in enhanced vision modes!
if (fogdensity == 0 || gl_fogmode == 0)
{
EnableFog(false);
SetFog(0, 0);
}
else
{
if ((level.lightmode == 2 || (level.lightmode == 8 && cmap->BlendFactor > 0)) && fogcolor == 0)
{
float light = (float)hw_CalcLightLevel(lightlevel, rellight, false, cmap->BlendFactor);
SetShaderLight(light, lightlevel);
}
else
{
SetLightParms(1.f, 0.f);
}
// For additive rendering using the regular fog color here would mean applying it twice
// so always use black
if (isadditive)
{
fogcolor = 0;
}
EnableFog(true);
SetFog(fogcolor, fogdensity);
// Korshun: fullbright fog like in software renderer.
if (level.lightmode == 8 && cmap->BlendFactor == 0 && level.brightfog && fogdensity != 0 && fogcolor != 0)
{
SetSoftLightLevel(255);
}
}
}

View file

@ -3,6 +3,7 @@
#include "v_palette.h"
#include "vectors.h"
#include "g_levellocals.h"
#include "hw_drawstructs.h"
#include "r_data/matrix.h"
#include "hwrenderer/textures/hw_material.h"
@ -135,6 +136,8 @@ protected:
FStencilState mStencil;
FDepthBiasState mBias;
void SetShaderLight(float level, float olight);
public:
VSMatrix mModelMatrix;
VSMatrix mTextureMatrix;
@ -271,16 +274,16 @@ public:
{
DVector3 tn = top.Normal();
DVector3 bn = bottom.Normal();
mGlowTopPlane.Set(tn.X, tn.Y, 1. / tn.Z, top.fD());
mGlowBottomPlane.Set(bn.X, bn.Y, 1. / bn.Z, bottom.fD());
mGlowTopPlane.Set((float)tn.X, (float)tn.Y, (float)(1. / tn.Z), (float)top.fD());
mGlowBottomPlane.Set((float)bn.X, (float)bn.Y, (float)(1. / bn.Z), (float)bottom.fD());
}
void SetSplitPlanes(const secplane_t &top, const secplane_t &bottom)
{
DVector3 tn = top.Normal();
DVector3 bn = bottom.Normal();
mSplitTopPlane.Set(tn.X, tn.Y, 1. / tn.Z, top.fD());
mSplitBottomPlane.Set(bn.X, bn.Y, 1. / bn.Z, bottom.fD());
mSplitTopPlane.Set((float)tn.X, (float)tn.Y, (float)(1. / tn.Z), (float)top.fD());
mSplitBottomPlane.Set((float)bn.X, (float)bn.Y, (float)(1. / bn.Z), (float)bottom.fD());
}
void SetDynLight(float r, float g, float b)