Add Alternate Light Blending Options

This commit is contained in:
Ricardo Luís Vaz Silva 2022-12-06 22:51:45 -03:00 committed by Rachael Alexanderson
parent aa061562cd
commit 8e7897233e
10 changed files with 77 additions and 4 deletions

View file

@ -235,6 +235,8 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
float uClipHeight; float uClipHeight;
float uClipHeightDirection; float uClipHeightDirection;
int uShadowmapFilter; int uShadowmapFilter;
int uLightBlendMode;
}; };
uniform int uTextureMode; uniform int uTextureMode;

View file

@ -30,6 +30,7 @@
#include "hw_renderstate.h" #include "hw_renderstate.h"
#include "hw_viewpointbuffer.h" #include "hw_viewpointbuffer.h"
#include "hw_cvars.h" #include "hw_cvars.h"
#include "g_levellocals.h"
static const int INITIAL_BUFFER_SIZE = 100; // 100 viewpoints per frame should nearly always be enough static const int INITIAL_BUFFER_SIZE = 100; // 100 viewpoints per frame should nearly always be enough
@ -91,6 +92,7 @@ void HWViewpointBuffer::Set2D(FRenderState &di, int width, int height, int pll)
matrices.mPalLightLevels = pll; matrices.mPalLightLevels = pll;
matrices.mClipLine.X = -10000000.0f; matrices.mClipLine.X = -10000000.0f;
matrices.mShadowmapFilter = gl_shadowmap_filter; matrices.mShadowmapFilter = gl_shadowmap_filter;
matrices.mLightBlendMode = (level.info ? (int)level.info->lightblendmode : 0);
matrices.mProjectionMatrix.ortho(0, (float)width, (float)height, 0, -1.0f, 1.0f); matrices.mProjectionMatrix.ortho(0, (float)width, (float)height, 0, -1.0f, 1.0f);
matrices.CalcDependencies(); matrices.CalcDependencies();

View file

@ -19,6 +19,8 @@ struct HWViewpointUniforms
float mClipHeightDirection = 0.f; float mClipHeightDirection = 0.f;
int mShadowmapFilter = 1; int mShadowmapFilter = 1;
int mLightBlendMode = 0;
void CalcDependencies() void CalcDependencies()
{ {
mNormalViewMatrix.computeNormalMatrix(mViewMatrix); mNormalViewMatrix.computeNormalMatrix(mViewMatrix);

View file

@ -175,6 +175,8 @@ static const char *shaderBindings = R"(
float uClipHeight; float uClipHeight;
float uClipHeightDirection; float uClipHeightDirection;
int uShadowmapFilter; int uShadowmapFilter;
int uLightBlendMode;
}; };
layout(set = 1, binding = 1, std140) uniform MatricesUBO { layout(set = 1, binding = 1, std140) uniform MatricesUBO {

View file

@ -53,4 +53,13 @@ enum class ELightMode : int8_t
DoomSoftware = 16 DoomSoftware = 16
}; };
enum class ELightBlendMode : uint8_t
{
CLAMP = 0,
CLAMP_COLOR = 1,
NOCLAMP = 2,
DEFAULT = CLAMP,
};
#endif #endif

View file

@ -302,7 +302,7 @@ void level_info_t::Reset()
lightadditivesurfaces = -1; lightadditivesurfaces = -1;
skyrotatevector = FVector3(0, 0, 1); skyrotatevector = FVector3(0, 0, 1);
skyrotatevector2 = FVector3(0, 0, 1); skyrotatevector2 = FVector3(0, 0, 1);
lightblendmode = ELightBlendMode::DEFAULT;
} }
@ -1496,6 +1496,29 @@ DEFINE_MAP_OPTION(lightmode, false)
} }
} }
DEFINE_MAP_OPTION(lightblendmode, false)
{
parse.ParseAssign();
parse.sc.MustGetString();
if(strcmp(parse.sc.String,"DEFAULT") == 0 || strcmp(parse.sc.String,"CLAMP") == 0)
{
info->lightblendmode = ELightBlendMode::DEFAULT;
}
else if(strcmp(parse.sc.String,"COLOR_CORRECT_CLAMP") == 0)
{
info->lightblendmode = ELightBlendMode::CLAMP_COLOR;
}
else if(strcmp(parse.sc.String,"UNCLAMPED") == 0)
{
info->lightblendmode = ELightBlendMode::NOCLAMP;
}
else
{
parse.sc.ScriptMessage("Invalid light blend mode %s", parse.sc.String);
}
}
DEFINE_MAP_OPTION(notexturefill, false) DEFINE_MAP_OPTION(notexturefill, false)
{ {
if (parse.CheckAssign()) if (parse.CheckAssign())

View file

@ -409,6 +409,7 @@ struct level_info_t
FString EDName; FString EDName;
FString acsName; FString acsName;
bool fs_nocheckposition; bool fs_nocheckposition;
ELightBlendMode lightblendmode;
CutsceneDef intro, outro; CutsceneDef intro, outro;

View file

@ -48,6 +48,7 @@
#include "a_corona.h" #include "a_corona.h"
#include "texturemanager.h" #include "texturemanager.h"
#include "actorinlines.h" #include "actorinlines.h"
#include "g_levellocals.h"
EXTERN_CVAR(Float, r_visibility) EXTERN_CVAR(Float, r_visibility)
CVAR(Bool, gl_bandedswlight, false, CVAR_ARCHIVE) CVAR(Bool, gl_bandedswlight, false, CVAR_ARCHIVE)
@ -164,6 +165,7 @@ void HWDrawInfo::StartScene(FRenderViewpoint &parentvp, HWViewpointUniforms *uni
} }
VPUniforms.mClipLine.X = -10000000.0f; VPUniforms.mClipLine.X = -10000000.0f;
VPUniforms.mShadowmapFilter = gl_shadowmap_filter; VPUniforms.mShadowmapFilter = gl_shadowmap_filter;
VPUniforms.mLightBlendMode = (level.info ? (int)level.info->lightblendmode : 0);
} }
mClipper->SetViewpoint(Viewpoint); mClipper->SetViewpoint(Viewpoint);

View file

@ -59,7 +59,21 @@ vec3 ProcessMaterialLight(Material material, vec3 color)
} }
} }
vec3 frag = material.Base.rgb * clamp(color + desaturate(dynlight).rgb, 0.0, 1.4); vec3 frag;
if ( uLightBlendMode == 1 )
{ // COLOR_CORRECT_CLAMPING
vec3 lightcolor = color + desaturate(dynlight).rgb;
frag = material.Base.rgb * ((lightcolor / max(max(max(lightcolor.r, lightcolor.g), lightcolor.b), 1.4) * 1.4));
}
else if ( uLightBlendMode == 2 )
{ // UNCLAMPED
frag = material.Base.rgb * (color + desaturate(dynlight).rgb);
}
else
{
frag = material.Base.rgb * clamp(color + desaturate(dynlight).rgb, 0.0, 1.4);
}
if (uLightIndex >= 0) if (uLightIndex >= 0)
{ {

View file

@ -67,8 +67,24 @@ vec3 ProcessMaterialLight(Material material, vec3 color)
} }
} }
if ( uLightBlendMode == 1 )
{ // COLOR_CORRECT_CLAMPING
dynlight.rgb = color + desaturate(dynlight).rgb;
specular.rgb = desaturate(specular).rgb;
dynlight.rgb = ((dynlight.rgb / max(max(max(dynlight.r, dynlight.g), dynlight.b), 1.4) * 1.4));
specular.rgb = ((specular.rgb / max(max(max(specular.r, specular.g), specular.b), 1.4) * 1.4));
}
else if ( uLightBlendMode == 2 )
{ // UNCLAMPED
dynlight.rgb = color + desaturate(dynlight).rgb;
specular.rgb = desaturate(specular).rgb;
}
else
{
dynlight.rgb = clamp(color + desaturate(dynlight).rgb, 0.0, 1.4); dynlight.rgb = clamp(color + desaturate(dynlight).rgb, 0.0, 1.4);
specular.rgb = clamp(desaturate(specular).rgb, 0.0, 1.4); specular.rgb = clamp(desaturate(specular).rgb, 0.0, 1.4);
}
vec3 frag = material.Base.rgb * dynlight.rgb + material.Specular * specular.rgb; vec3 frag = material.Base.rgb * dynlight.rgb + material.Specular * specular.rgb;