switch from uniform to shader keys

This commit is contained in:
Ricardo Luís Vaz Silva 2024-10-06 19:54:37 -03:00 committed by Magnus Norddahl
commit 04ee3c335e
9 changed files with 94 additions and 90 deletions

View file

@ -646,8 +646,6 @@ public:
matrices.mPalLightLevels = palLightLevels;
matrices.mClipLine.X = -10000000.0f;
matrices.mShadowFilter = gl_light_shadow_filter;
matrices.mLightBlendMode = 0;
matrices.mLightAttenuationMode = 0;
matrices.mProjectionMatrix.ortho(0, (float)width, (float)height, 0, -1.0f, 1.0f);
matrices.CalcDependencies();
return SetViewpoint(matrices);

View file

@ -221,6 +221,29 @@ std::unique_ptr<VulkanShader> VkShaderManager::LoadFragShader(FString shadername
if (key.GBufferPass) definesBlock << "#define GBUFFER_PASS\n";
if (key.AlphaTestOnly) definesBlock << "#define ALPHATEST_ONLY\n";
switch(key.LightBlendMode)
{
case 0:
definesBlock << "#define LIGHT_BLEND_CLAMPED\n";
break;
case 1:
definesBlock << "#define LIGHT_BLEND_COLORED_CLAMP\n";
break;
case 2:
definesBlock << "#define LIGHT_BLEND_UNCLAMPED\n";
break;
}
switch(key.LightAttenuationMode)
{
case 0:
definesBlock << "#define LIGHT_ATTENUATION_LINEAR\n";
break;
case 1:
definesBlock << "#define LIGHT_ATTENUATION_INVERSE_SQUARE\n";
break;
}
if (key.DepthFadeThreshold) definesBlock << "#define USE_DEPTHFADETHRESHOLD\n";
if (key.Simple2D) definesBlock << "#define SIMPLE2D\n";

View file

@ -98,7 +98,9 @@ public:
uint64_t NoFragmentShader : 1;
uint64_t DepthFadeThreshold : 1;
uint64_t AlphaTestOnly : 1; // ALPHATEST_ONLY
uint64_t Unused : 40;
uint64_t LightBlendMode : 2; // LIGHT_BLEND_CLAMPED , LIGHT_BLEND_COLORED_CLAMP , LIGHT_BLEND_UNCLAMPED
uint64_t LightAttenuationMode : 1; // LIGHT_ATTENUATION_LINEAR , LIGHT_ATTENUATION_INVERSE_SQUARE
uint64_t Unused : 37;
};
uint64_t AsQWORD = 0;
};

View file

@ -38,6 +38,8 @@
#include "hw_clock.h"
#include "flatvertices.h"
#include "g_levellocals.h"
CVAR(Int, vk_submit_size, 1000, 0);
EXTERN_CVAR(Bool, r_skipmats)
@ -305,6 +307,9 @@ void VkRenderState::ApplyRenderPass(int dt)
pipelineKey.ShaderKey.GBufferPass = mRenderTarget.DrawBuffers > 1;
pipelineKey.ShaderKey.LightBlendMode = (level.info ? static_cast<int>(level.info->lightblendmode) : 0);
pipelineKey.ShaderKey.LightAttenuationMode = (level.info ? static_cast<int>(level.info->lightattenuationmode) : 0);
// Is this the one we already have?
bool inRenderPass = mCommandBuffer;
bool changingPipeline = (!inRenderPass) || (pipelineKey != mPipelineKey);

View file

@ -127,8 +127,6 @@ void HWDrawInfo::StartScene(FRenderViewpoint &parentvp, HWViewpointUniforms *uni
}
VPUniforms.mClipLine.X = -10000000.0f;
VPUniforms.mShadowFilter = static_cast<int>(gl_light_shadow_filter);
VPUniforms.mLightBlendMode = (level.info ? static_cast<int>(level.info->lightblendmode) : 0);
VPUniforms.mLightAttenuationMode = (level.info ? static_cast<int>(level.info->lightattenuationmode) : 0);
}
mClipper->SetViewpoint(Viewpoint);
vClipper->SetViewpoint(Viewpoint);

View file

@ -17,12 +17,8 @@ layout(set = 1, binding = 0, std140) uniform ViewpointUBO
float uClipHeight;
float uClipHeightDirection;
int uShadowmapFilter;
int uLightBlendMode;
int uLightTilesWidth; // Levelmesh light tiles
int uLightAttenuationMode;
};
layout(set = 1, binding = 1, std140) uniform MatricesUBO

View file

@ -1,9 +1,6 @@
float linearDistanceAttenuation(vec4 lightpos, float d)
{
return clamp((lightpos.w - d) / lightpos.w, 0.0, 1.0);
}
#ifdef LIGHT_ATTENUATION_INVERSE_SQUARE
float inverseSquareDistanceAttenuation(vec4 lightpos, float d)
float distanceAttenuation(vec4 lightpos, float d)
{
float strength = 1500.0;
float r = lightpos.w;
@ -12,18 +9,15 @@ float inverseSquareDistanceAttenuation(vec4 lightpos, float d)
return (b * b) / (d * d + 1.0) * strength;
}
#else //elif defined(LIGHT_ATTENUATION_LINEAR)
float distanceAttenuation(vec4 lightpos, float d)
{
if ( uLightAttenuationMode == 1 )
{
return inverseSquareDistanceAttenuation(lightpos, d);
}
else
{
return linearDistanceAttenuation(lightpos, d);
}
return clamp((lightpos.w - d) / lightpos.w, 0.0, 1.0);
}
#endif
vec3 lightContribution(int i, vec3 normal)
{
vec4 lightpos = lights[i];
@ -83,22 +77,22 @@ vec3 ProcessMaterialLight(Material material, vec3 color)
}
}
}
#ifdef LIGHT_BLEND_CLAMPED
vec3 frag = material.Base.rgb * clamp(color + desaturate(dynlight).rgb, 0.0, 1.4);
#elif defined(LIGHT_BLEND_COLORED_CLAMP)
vec3 frag = color + desaturate(dynlight).rgb;
frag = material.Base.rgb * ((frag / max(max(max(frag.r, frag.g), frag.b), 1.4) * 1.4));
#else // elif defined(LIGHT_BLEND_UNCLAMPED)
vec3 frag = material.Base.rgb * (color + desaturate(dynlight).rgb);
#endif
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)
{

View file

@ -1,3 +1,24 @@
#ifdef LIGHT_ATTENUATION_INVERSE_SQUARE
float distanceAttenuation(vec4 lightpos)
{
float strength = 1500.0;
float d = distance(lightpos.xyz, pixelpos.xyz);
float r = lightpos.w;
float a = d / r;
float b = clamp(1.0 - a * a * a * a, 0.0, 1.0);
return (b * b) / (d * d + 1.0) * strength;
}
#else //elif defined(LIGHT_ATTENUATION_LINEAR)
float distanceAttenuation(vec4 lightpos)
{
float lightdistance = distance(lightpos.xyz, pixelpos.xyz);
return clamp((lightpos.w - lightdistance) / lightpos.w, 0.0, 1.0);
}
#endif
const float PI = 3.14159265359;
@ -45,34 +66,6 @@ vec3 fresnelSchlickRoughness(float cosTheta, vec3 F0, float roughness)
return F0 + (max(vec3(1.0 - roughness), F0) - F0) * pow(1.0 - cosTheta, 5.0);
}
float linearDistanceAttenuation(vec4 lightpos)
{
float lightdistance = distance(lightpos.xyz, pixelpos.xyz);
return clamp((lightpos.w - lightdistance) / lightpos.w, 0.0, 1.0);
}
float inverseSquareDistanceAttenuation(vec4 lightpos)
{
float strength = 1500.0;
float d = distance(lightpos.xyz, pixelpos.xyz);
float r = lightpos.w;
float a = d / r;
float b = clamp(1.0 - a * a * a * a, 0.0, 1.0);
return (b * b) / (d * d + 1.0) * strength;
}
float distanceAttenuation(vec4 lightpos)
{
if ( uLightAttenuationMode == 1 )
{
return inverseSquareDistanceAttenuation(lightpos);
}
else
{
return linearDistanceAttenuation(lightpos);
}
}
vec3 ProcessMaterialLight(Material material, vec3 ambientLight)
{
vec3 worldpos = pixelpos.xyz;

View file

@ -1,9 +1,6 @@
float linearDistanceAttenuation(vec4 lightpos, float d)
{
return clamp((lightpos.w - d) / lightpos.w, 0.0, 1.0);
}
#ifdef LIGHT_ATTENUATION_INVERSE_SQUARE
float inverseSquareDistanceAttenuation(vec4 lightpos, float d)
float distanceAttenuation(vec4 lightpos, float d)
{
float strength = 1500.0;
float r = lightpos.w;
@ -12,18 +9,15 @@ float inverseSquareDistanceAttenuation(vec4 lightpos, float d)
return (b * b) / (d * d + 1.0) * strength;
}
#else //elif defined(LIGHT_ATTENUATION_LINEAR)
float distanceAttenuation(vec4 lightpos, float d)
{
if ( uLightAttenuationMode == 1 )
{
return inverseSquareDistanceAttenuation(lightpos, d);
}
else
{
return linearDistanceAttenuation(lightpos, d);
}
return clamp((lightpos.w - d) / lightpos.w, 0.0, 1.0);
}
#endif
vec2 lightAttenuation(int i, vec3 normal, vec3 viewdir, float lightcolorA, float glossiness, float specularLevel)
{
vec4 lightpos = lights[i];
@ -88,25 +82,26 @@ vec3 ProcessMaterialLight(Material material, vec3 color)
}
}
}
if ( uLightBlendMode == 1 )
{ // COLOR_CORRECT_CLAMPING
#if defined(LIGHT_BLEND_CLAMPED)
dynlight.rgb = clamp(color + desaturate(dynlight).rgb, 0.0, 1.4);
specular.rgb = clamp(desaturate(specular).rgb, 0.0, 1.4);
#elif defined(LIGHT_BLEND_COLORED_CLAMP)
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
#else // elif defined(LIGHT_BLEND_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);
}
#endif
vec3 frag = material.Base.rgb * dynlight.rgb + material.Specular * specular.rgb;