Skip to content

Commit

Permalink
Add Alternate Light Blending Options
Browse files Browse the repository at this point in the history
  • Loading branch information
RicardoLuis0 authored and madame-rachelle committed Jan 14, 2023
1 parent aa06156 commit 8e78972
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/common/rendering/gl/gl_shader.cpp
Expand Up @@ -235,6 +235,8 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
float uClipHeight;
float uClipHeightDirection;
int uShadowmapFilter;
int uLightBlendMode;
};
uniform int uTextureMode;
Expand Down
2 changes: 2 additions & 0 deletions src/common/rendering/hwrenderer/data/hw_viewpointbuffer.cpp
Expand Up @@ -30,6 +30,7 @@
#include "hw_renderstate.h"
#include "hw_viewpointbuffer.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

Expand Down Expand Up @@ -91,6 +92,7 @@ void HWViewpointBuffer::Set2D(FRenderState &di, int width, int height, int pll)
matrices.mPalLightLevels = pll;
matrices.mClipLine.X = -10000000.0f;
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.CalcDependencies();
Expand Down
2 changes: 2 additions & 0 deletions src/common/rendering/hwrenderer/data/hw_viewpointuniforms.h
Expand Up @@ -19,6 +19,8 @@ struct HWViewpointUniforms
float mClipHeightDirection = 0.f;
int mShadowmapFilter = 1;

int mLightBlendMode = 0;

void CalcDependencies()
{
mNormalViewMatrix.computeNormalMatrix(mViewMatrix);
Expand Down
2 changes: 2 additions & 0 deletions src/common/rendering/vulkan/shaders/vk_shader.cpp
Expand Up @@ -175,6 +175,8 @@ static const char *shaderBindings = R"(
float uClipHeight;
float uClipHeightDirection;
int uShadowmapFilter;
int uLightBlendMode;
};
layout(set = 1, binding = 1, std140) uniform MatricesUBO {
Expand Down
9 changes: 9 additions & 0 deletions src/doomtype.h
Expand Up @@ -53,4 +53,13 @@ enum class ELightMode : int8_t
DoomSoftware = 16
};

enum class ELightBlendMode : uint8_t
{
CLAMP = 0,
CLAMP_COLOR = 1,
NOCLAMP = 2,

DEFAULT = CLAMP,
};

#endif
25 changes: 24 additions & 1 deletion src/gamedata/g_mapinfo.cpp
Expand Up @@ -302,7 +302,7 @@ void level_info_t::Reset()
lightadditivesurfaces = -1;
skyrotatevector = FVector3(0, 0, 1);
skyrotatevector2 = FVector3(0, 0, 1);

lightblendmode = ELightBlendMode::DEFAULT;
}


Expand Down Expand Up @@ -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)
{
if (parse.CheckAssign())
Expand Down
1 change: 1 addition & 0 deletions src/gamedata/g_mapinfo.h
Expand Up @@ -409,6 +409,7 @@ struct level_info_t
FString EDName;
FString acsName;
bool fs_nocheckposition;
ELightBlendMode lightblendmode;

CutsceneDef intro, outro;

Expand Down
2 changes: 2 additions & 0 deletions src/rendering/hwrenderer/scene/hw_drawinfo.cpp
Expand Up @@ -48,6 +48,7 @@
#include "a_corona.h"
#include "texturemanager.h"
#include "actorinlines.h"
#include "g_levellocals.h"

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

Expand Down
16 changes: 15 additions & 1 deletion wadsrc/static/shaders/glsl/material_normal.fp
Expand Up @@ -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)
{
Expand Down
20 changes: 18 additions & 2 deletions wadsrc/static/shaders/glsl/material_specular.fp
Expand Up @@ -66,9 +66,25 @@ 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 = clamp(color + desaturate(dynlight).rgb, 0.0, 1.4);
specular.rgb = clamp(desaturate(specular).rgb, 0.0, 1.4);
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);
specular.rgb = clamp(desaturate(specular).rgb, 0.0, 1.4);
}

vec3 frag = material.Base.rgb * dynlight.rgb + material.Specular * specular.rgb;

Expand Down

0 comments on commit 8e78972

Please sign in to comment.