diff --git a/src/rendering/gl/shaders/gl_shader.cpp b/src/rendering/gl/shaders/gl_shader.cpp index 939faf557d..284aa21c09 100644 --- a/src/rendering/gl/shaders/gl_shader.cpp +++ b/src/rendering/gl/shaders/gl_shader.cpp @@ -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"); diff --git a/src/rendering/gl/shaders/gl_shader.h b/src/rendering/gl/shaders/gl_shader.h index e9d638446b..ae26974760 100644 --- a/src/rendering/gl/shaders/gl_shader.h +++ b/src/rendering/gl/shaders/gl_shader.h @@ -261,6 +261,7 @@ class FShader FBufferedUniform1f muAlphaThreshold; FBufferedUniform2f muSpecularMaterial; FBufferedUniform1f muTimer; + FUniform4f muLightLevelContrast; int lights_index; int modelmatrix_index; diff --git a/src/rendering/hwrenderer/models/hw_models.cpp b/src/rendering/hwrenderer/models/hw_models.cpp index e3353d01a4..dddb7413f2 100644 --- a/src/rendering/hwrenderer/models/hw_models.cpp +++ b/src/rendering/hwrenderer/models/hw_models.cpp @@ -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); diff --git a/src/rendering/hwrenderer/scene/hw_renderstate.h b/src/rendering/hwrenderer/scene/hw_renderstate.h index 42092b2e1a..40ce23cf5e 100644 --- a/src/rendering/hwrenderer/scene/hw_renderstate.h +++ b/src/rendering/hwrenderer/scene/hw_renderstate.h @@ -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 }; diff --git a/src/rendering/vulkan/shaders/vk_shader.cpp b/src/rendering/vulkan/shaders/vk_shader.cpp index 32e13c2dff..a5b0a00149 100644 --- a/src/rendering/vulkan/shaders/vk_shader.cpp +++ b/src/rendering/vulkan/shaders/vk_shader.cpp @@ -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 diff --git a/wadsrc/static/shaders/glsl/material_normal.fp b/wadsrc/static/shaders/glsl/material_normal.fp index 369139ed4e..5012c753a0 100644 --- a/wadsrc/static/shaders/glsl/material_normal.fp +++ b/wadsrc/static/shaders/glsl/material_normal.fp @@ -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; } diff --git a/wadsrc/static/shaders/glsl/material_pbr.fp b/wadsrc/static/shaders/glsl/material_pbr.fp index da820ef9a3..f9fdf26a7f 100644 --- a/wadsrc/static/shaders/glsl/material_pbr.fp +++ b/wadsrc/static/shaders/glsl/material_pbr.fp @@ -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) { diff --git a/wadsrc/static/shaders/glsl/material_specular.fp b/wadsrc/static/shaders/glsl/material_specular.fp index cdf6e8c3af..01e98a0468 100644 --- a/wadsrc/static/shaders/glsl/material_specular.fp +++ b/wadsrc/static/shaders/glsl/material_specular.fp @@ -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;