Add gl_model_light_contrast cvar and only apply the directional light contrast for models

This commit is contained in:
Magnus Norddahl 2020-03-22 07:42:38 +01:00
parent d18e89ea72
commit 631b66a83f
8 changed files with 41 additions and 9 deletions

View file

@ -276,6 +276,9 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
// Blinn glossiness and specular level
i_data += "uniform vec2 uSpecularMaterial;\n";
// Light level weighted directional light
i_data += "uniform vec4 uLightLevelContrast;\n";
// matrices
i_data += "uniform mat4 ModelMatrix;\n";
i_data += "uniform mat4 NormalModelMatrix;\n";
@ -554,6 +557,7 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
muTextureModulateColor.Init(hShader, "uTextureModulateColor");
muTextureBlendColor.Init(hShader, "uTextureBlendColor");
muTimer.Init(hShader, "timer");
muLightLevelContrast.Init(hShader, "uLightLevelContrast");
lights_index = glGetUniformLocation(hShader, "lights");
modelmatrix_index = glGetUniformLocation(hShader, "ModelMatrix");

View file

@ -261,6 +261,7 @@ class FShader
FBufferedUniform1f muAlphaThreshold;
FBufferedUniform2f muSpecularMaterial;
FBufferedUniform1f muTimer;
FUniform4f muLightLevelContrast;
int lights_index;
int modelmatrix_index;

View file

@ -44,6 +44,9 @@
#include "hw_models.h"
CVAR(Bool, gl_light_models, true, CVAR_ARCHIVE)
CVAR(Bool, gl_model_light_contrast, true, CVAR_ARCHIVE)
static FVector4 ModelLightLevelContrast = { -0.55708601453f, 0.7427813527f, -0.37139067635f, 0.25f };
VSMatrix FHWModelRenderer::GetViewToWorldMatrix()
{
@ -67,10 +70,16 @@ void FHWModelRenderer::BeginDrawModel(AActor *actor, FSpriteModelFrame *smf, con
state.mModelMatrix = objectToWorldMatrix;
state.EnableModelMatrix(true);
if (gl_model_light_contrast)
state.SetLightLevelContrast(ModelLightLevelContrast.X, ModelLightLevelContrast.Y, ModelLightLevelContrast.Z, ModelLightLevelContrast.W);
}
void FHWModelRenderer::EndDrawModel(AActor *actor, FSpriteModelFrame *smf)
{
if (gl_model_light_contrast)
state.SetLightLevelContrast(0.0f, 0.0f, 0.0f, 0.0f);
state.EnableModelMatrix(false);
state.SetDepthFunc(DF_Less);
if (!(actor->RenderStyle == DefaultRenderStyle()) && !(smf->flags & MDL_DONTCULLBACKFACES))
@ -91,10 +100,16 @@ void FHWModelRenderer::BeginDrawHUDModel(AActor *actor, const VSMatrix &objectTo
state.mModelMatrix = objectToWorldMatrix;
state.EnableModelMatrix(true);
if (gl_model_light_contrast)
state.SetLightLevelContrast(ModelLightLevelContrast.X, ModelLightLevelContrast.Y, ModelLightLevelContrast.Z, ModelLightLevelContrast.W);
}
void FHWModelRenderer::EndDrawHUDModel(AActor *actor)
{
if (gl_model_light_contrast)
state.SetLightLevelContrast(0.0f, 0.0f, 0.0f, 0.0f);
state.EnableModelMatrix(false);
state.SetDepthFunc(DF_Less);

View file

@ -199,6 +199,8 @@ struct StreamData
FVector4 uSplitTopPlane;
FVector4 uSplitBottomPlane;
FVector4 uLightLevelContrast;
};
class FRenderState
@ -288,6 +290,8 @@ public:
mStreamData.uSplitBottomPlane = { 0.0f, 0.0f, 0.0f, 0.0f };
mStreamData.uDynLightColor = { 0.0f, 0.0f, 0.0f, 0.0f };
mStreamData.uLightLevelContrast = { 0.0f, 0.0f, 0.0f, 0.0f };
mModelMatrix.loadIdentity();
mTextureMatrix.loadIdentity();
ClearClipSplit();
@ -451,6 +455,11 @@ public:
mStreamData.uSplitBottomPlane = { (float)bn.X, (float)bn.Y, (float)bottom.negiC, (float)bottom.fD() };
}
void SetLightLevelContrast(float x, float y, float z, float strength)
{
mStreamData.uLightLevelContrast = { x, y, z, strength };
}
void SetDynLight(float r, float g, float b)
{
mStreamData.uDynLightColor = { r, g, b, 0.0f };

View file

@ -160,6 +160,8 @@ static const char *shaderBindings = R"(
vec4 uSplitTopPlane;
vec4 uSplitBottomPlane;
vec4 uLightLevelContrast;
};
layout(set = 0, binding = 3, std140) uniform StreamUBO {
@ -237,6 +239,7 @@ static const char *shaderBindings = R"(
#define uGradientBottomPlane data[uDataIndex].uGradientBottomPlane
#define uSplitTopPlane data[uDataIndex].uSplitTopPlane
#define uSplitBottomPlane data[uDataIndex].uSplitBottomPlane
#define uLightLevelContrast data[uDataIndex].uLightLevelContrast
#define SUPPORTS_SHADOWMAPS
#define VULKAN_COORDINATE_SYSTEM

View file

@ -37,7 +37,7 @@ vec3 lightContribution(int i, vec3 normal)
float lightLevelContrastAttenuation(vec3 normal)
{
vec3 lightdir = vec3(-0.55708601453, 0.7427813527, -0.37139067635);
vec3 lightdir = uLightLevelContrast.xyz;
return clamp(dot(lightdir, normal), 0.0, 1.0);
}
@ -46,9 +46,9 @@ vec3 ProcessMaterialLight(Material material, vec3 color)
vec4 dynlight = uDynLightColor;
vec3 normal = material.Normal;
if (normal != vec3(0.0))
if (uLightLevelContrast.w != 0 && normal != vec3(0.0))
{
float lightLevelContrastStrength = 0.25;
float lightLevelContrastStrength = uLightLevelContrast.w;
dynlight.rgb += color * lightLevelContrastAttenuation(normal) * lightLevelContrastStrength;
color *= 1.0 - lightLevelContrastStrength;
}

View file

@ -80,11 +80,11 @@ vec3 ProcessMaterialLight(Material material, vec3 ambientLight)
vec3 Lo = uDynLightColor.rgb;
if (N != vec3(0.0))
if (uLightLevelContrast.w != 0.0 && N != vec3(0.0))
{
float lightLevelContrastStrength = 0.25;
float lightLevelContrastStrength = uLightLevelContrast.w;
vec3 L = vec3(-0.55708601453, 0.7427813527, -0.37139067635);
vec3 L = uLightLevelContrast.xyz;
float attenuation = clamp(dot(N, L), 0.0, 1.0);
if (attenuation > 0.0)
{

View file

@ -36,7 +36,7 @@ vec2 lightAttenuation(int i, vec3 normal, vec3 viewdir, float lightcolorA)
vec2 lightLevelContrastAttenuation(vec3 normal, vec3 viewdir)
{
vec3 lightdir = vec3(-0.55708601453, 0.7427813527, -0.37139067635);
vec3 lightdir = uLightLevelContrast.xyz;
float attenuation = clamp(dot(lightdir, normal), 0.0, 1.0);
float glossiness = uSpecularMaterial.x;
@ -56,9 +56,9 @@ vec3 ProcessMaterialLight(Material material, vec3 color)
vec3 normal = material.Normal;
vec3 viewdir = normalize(uCameraPos.xyz - pixelpos.xyz);
if (normal != vec3(0.0))
if (uLightLevelContrast.w != 0.0 && normal != vec3(0.0))
{
float lightLevelContrastStrength = 0.25;
float lightLevelContrastStrength = uLightLevelContrast.w;
vec2 lightLevelAttenuation = lightLevelContrastAttenuation(normal, viewdir) * lightLevelContrastStrength;
dynlight.rgb += color * lightLevelAttenuation.x;
specular.rgb += color * lightLevelAttenuation.y;