Fix shader build errors and remove support for old deprecated shader types

This commit is contained in:
Magnus Norddahl 2023-03-24 03:34:24 +01:00 committed by Christoph Oelckers
parent a267cf737e
commit e34ee1e462
15 changed files with 41 additions and 149 deletions

View file

@ -275,30 +275,30 @@ FString RemoveLayoutLocationDecl(FString code, const char *inoutkeyword)
// Note: the MaterialShaderIndex enum in gl_shader.h needs to be updated whenever this array is modified.
const FDefaultShader defaultshaders[] =
{
{"Default", "shaders/scene/material_default.glsl", /*"shaders/scene/mateffect_default.glsl",*/ "shaders/scene/lightmodel_normal.glsl", ""},
{"Warp 1", "shaders/scene/material_default.glsl", /*"shaders/scene/mateffect_warp1.glsl",*/ "shaders/scene/lightmodel_normal.glsl", ""},
{"Warp 2", "shaders/scene/material_default.glsl", /*"shaders/scene/mateffect_warp2.glsl",*/ "shaders/scene/lightmodel_normal.glsl", ""},
{"Specular", "shaders/scene/material_spec.glsl", /*"shaders/scene/mateffect_default.glsl",*/ "shaders/scene/lightmodel_specular.glsl", "#define SPECULAR\n#define NORMALMAP\n"},
{"PBR", "shaders/scene/material_pbr.glsl", /*"shaders/scene/mateffect_default.glsl",*/ "shaders/scene/lightmodel_pbr.glsl", "#define PBR\n#define NORMALMAP\n"},
{"Paletted", "shaders/scene/material_paletted.glsl", /*"shaders/scene/mateffect_default.glsl",*/ "shaders/scene/lightmodel_nolights.glsl", "#define PALETTE_EMULATION\n"},
{"No Texture", "shaders/scene/material_notexture.glsl", /*"shaders/scene/mateffect_default.glsl",*/ "shaders/scene/lightmodel_normal.glsl", "#define NO_LAYERS\n"},
{"Basic Fuzz", "shaders/scene/material_fuzz_standard.glsl", /*"shaders/scene/mateffect_default.glsl",*/ "shaders/scene/lightmodel_normal.glsl", ""},
{"Smooth Fuzz", "shaders/scene/material_fuzz_smooth.glsl", /*"shaders/scene/mateffect_default.glsl",*/ "shaders/scene/lightmodel_normal.glsl", ""},
{"Swirly Fuzz", "shaders/scene/material_fuzz_swirly.glsl", /*"shaders/scene/mateffect_default.glsl",*/ "shaders/scene/lightmodel_normal.glsl", ""},
{"Translucent Fuzz", "shaders/scene/material_fuzz_smoothtranslucent.glsl", /*"shaders/scene/mateffect_default.glsl",*/ "shaders/scene/lightmodel_normal.glsl", ""},
{"Jagged Fuzz", "shaders/scene/material_fuzz_jagged.glsl", /*"shaders/scene/mateffect_default.glsl",*/ "shaders/scene/lightmodel_normal.glsl", ""},
{"Noise Fuzz", "shaders/scene/material_fuzz_noise.glsl", /*"shaders/scene/mateffect_default.glsl",*/ "shaders/scene/lightmodel_normal.glsl", ""},
{"Smooth Noise Fuzz", "shaders/scene/material_fuzz_smoothnoise.glsl", /*"shaders/scene/mateffect_default.glsl",*/ "shaders/scene/lightmodel_normal.glsl", ""},
{"Software Fuzz", "shaders/scene/material_fuzz_software.glsl", /*"shaders/scene/mateffect_default.glsl",*/ "shaders/scene/lightmodel_normal.glsl", ""},
{"Default", "shaders/scene/material_default.glsl", "shaders/scene/mateffect_default.glsl", "shaders/scene/lightmodel_normal.glsl", ""},
{"Warp 1", "shaders/scene/material_default.glsl", "shaders/scene/mateffect_warp1.glsl", "shaders/scene/lightmodel_normal.glsl", ""},
{"Warp 2", "shaders/scene/material_default.glsl", "shaders/scene/mateffect_warp2.glsl", "shaders/scene/lightmodel_normal.glsl", ""},
{"Specular", "shaders/scene/material_spec.glsl", "shaders/scene/mateffect_default.glsl", "shaders/scene/lightmodel_specular.glsl", "#define SPECULAR\n#define NORMALMAP\n"},
{"PBR", "shaders/scene/material_pbr.glsl", "shaders/scene/mateffect_default.glsl", "shaders/scene/lightmodel_pbr.glsl", "#define PBR\n#define NORMALMAP\n"},
{"Paletted", "shaders/scene/material_paletted.glsl", "shaders/scene/mateffect_default.glsl", "shaders/scene/lightmodel_nolights.glsl", "#define PALETTE_EMULATION\n"},
{"No Texture", "shaders/scene/material_notexture.glsl", "shaders/scene/mateffect_default.glsl", "shaders/scene/lightmodel_normal.glsl", "#define NO_LAYERS\n"},
{"Basic Fuzz", "shaders/scene/material_fuzz_standard.glsl", "shaders/scene/mateffect_default.glsl", "shaders/scene/lightmodel_normal.glsl", ""},
{"Smooth Fuzz", "shaders/scene/material_fuzz_smooth.glsl", "shaders/scene/mateffect_default.glsl", "shaders/scene/lightmodel_normal.glsl", ""},
{"Swirly Fuzz", "shaders/scene/material_fuzz_swirly.glsl", "shaders/scene/mateffect_default.glsl", "shaders/scene/lightmodel_normal.glsl", ""},
{"Translucent Fuzz", "shaders/scene/material_fuzz_smoothtranslucent.glsl", "shaders/scene/mateffect_default.glsl", "shaders/scene/lightmodel_normal.glsl", ""},
{"Jagged Fuzz", "shaders/scene/material_fuzz_jagged.glsl", "shaders/scene/mateffect_default.glsl", "shaders/scene/lightmodel_normal.glsl", ""},
{"Noise Fuzz", "shaders/scene/material_fuzz_noise.glsl", "shaders/scene/mateffect_default.glsl", "shaders/scene/lightmodel_normal.glsl", ""},
{"Smooth Noise Fuzz", "shaders/scene/material_fuzz_smoothnoise.glsl", "shaders/scene/mateffect_default.glsl", "shaders/scene/lightmodel_normal.glsl", ""},
{"Software Fuzz", "shaders/scene/material_fuzz_software.glsl", "shaders/scene/mateffect_default.glsl", "shaders/scene/lightmodel_normal.glsl", ""},
{nullptr,nullptr,nullptr,nullptr}
};
const FEffectShader effectshaders[] =
{
{ "fogboundary", "shaders/scene/vert_main.glsl", "shaders/scene/frag_fogboundary.glsl", nullptr, nullptr, "#define NO_ALPHATEST\n" },
{ "spheremap", "shaders/scene/vert_main.glsl", "shaders/scene/frag_surface.glsl", "shaders/scene/material_default.glsl", "shaders/scene/lightmodel_normal.glsl", "#define SPHEREMAP\n#define NO_ALPHATEST\n" },
{ "burn", "shaders/scene/vert_main.glsl", "shaders/scene/frag_burn.glsl", nullptr, nullptr, "#define SIMPLE\n#define NO_ALPHATEST\n" },
{ "stencil", "shaders/scene/vert_main.glsl", "shaders/scene/frag_stencil.glsl", nullptr, nullptr, "#define SIMPLE\n#define NO_ALPHATEST\n" },
{ "fogboundary", "shaders/scene/frag_fogboundary.glsl", nullptr, nullptr, nullptr, "#define NO_ALPHATEST\n" },
{ "spheremap", "shaders/scene/frag_surface.glsl", "shaders/scene/material_default.glsl", "shaders/scene/mateffect_default.glsl", "shaders/scene/lightmodel_normal.glsl", "#define SPHEREMAP\n#define NO_ALPHATEST\n" },
{ "burn", "shaders/scene/frag_burn.glsl", nullptr, nullptr, nullptr, "#define SIMPLE\n#define NO_ALPHATEST\n" },
{ "stencil", "shaders/scene/frag_stencil.glsl", nullptr, nullptr, nullptr, "#define SIMPLE\n#define NO_ALPHATEST\n" },
};
int DFrameBuffer::GetShaderCount()

View file

@ -11,18 +11,19 @@ FString RemoveLayoutLocationDecl(FString code, const char *inoutkeyword);
struct FDefaultShader
{
const char * ShaderName;
const char * gettexelfunc;
const char * lightfunc;
const char * material_lump;
const char * mateffect_lump;
const char * lightmodel_lump;
const char * Defines;
};
struct FEffectShader
{
const char *ShaderName;
const char *vp;
const char *fp1;
const char *fp2;
const char *fp3;
const char *fp4;
const char *defines;
};

View file

@ -42,7 +42,7 @@ bool VkShaderManager::CompileNextShader()
VkShaderProgram prog;
prog.vert = LoadVertShader(defaultshaders[i].ShaderName, mainvp, defaultshaders[i].Defines);
prog.frag = LoadFragShader(defaultshaders[i].ShaderName, mainfp, defaultshaders[i].gettexelfunc, defaultshaders[i].lightfunc, defaultshaders[i].Defines, true, compilePass == GBUFFER_PASS);
prog.frag = LoadFragShader(defaultshaders[i].ShaderName, mainfp, defaultshaders[i].material_lump, defaultshaders[i].mateffect_lump, defaultshaders[i].lightmodel_lump, defaultshaders[i].Defines, true, compilePass == GBUFFER_PASS);
mMaterialShaders[compilePass].push_back(std::move(prog));
compileIndex++;
@ -58,7 +58,7 @@ bool VkShaderManager::CompileNextShader()
VkShaderProgram natprog;
natprog.vert = LoadVertShader(defaultshaders[i].ShaderName, mainvp, defaultshaders[i].Defines);
natprog.frag = LoadFragShader(defaultshaders[i].ShaderName, mainfp, defaultshaders[i].gettexelfunc, defaultshaders[i].lightfunc, defaultshaders[i].Defines, false, compilePass == GBUFFER_PASS);
natprog.frag = LoadFragShader(defaultshaders[i].ShaderName, mainfp, defaultshaders[i].material_lump, defaultshaders[i].mateffect_lump, defaultshaders[i].lightmodel_lump, defaultshaders[i].Defines, false, compilePass == GBUFFER_PASS);
mMaterialShadersNAT[compilePass].push_back(std::move(natprog));
compileIndex++;
@ -78,7 +78,7 @@ bool VkShaderManager::CompileNextShader()
VkShaderProgram prog;
prog.vert = LoadVertShader(name, mainvp, defines);
prog.frag = LoadFragShader(name, mainfp, usershaders[i].shader, defaultshaders[usershaders[i].shaderType].lightfunc, defines, true, compilePass == GBUFFER_PASS);
prog.frag = LoadFragShader(name, mainfp, usershaders[i].shader, defaultshaders[usershaders[i].shaderType].mateffect_lump, defaultshaders[usershaders[i].shaderType].lightmodel_lump, defines, true, compilePass == GBUFFER_PASS);
mMaterialShaders[compilePass].push_back(std::move(prog));
compileIndex++;
@ -93,8 +93,8 @@ bool VkShaderManager::CompileNextShader()
// Effect shaders
VkShaderProgram prog;
prog.vert = LoadVertShader(effectshaders[i].ShaderName, effectshaders[i].vp, effectshaders[i].defines);
prog.frag = LoadFragShader(effectshaders[i].ShaderName, effectshaders[i].fp1, effectshaders[i].fp2, effectshaders[i].fp3, effectshaders[i].defines, true, compilePass == GBUFFER_PASS);
prog.vert = LoadVertShader(effectshaders[i].ShaderName, mainvp, effectshaders[i].defines);
prog.frag = LoadFragShader(effectshaders[i].ShaderName, effectshaders[i].fp1, effectshaders[i].fp2, effectshaders[i].fp3, effectshaders[i].fp4, effectshaders[i].defines, true, compilePass == GBUFFER_PASS);
mEffectShaders[compilePass].push_back(std::move(prog));
compileIndex++;
@ -185,7 +185,7 @@ std::unique_ptr<VulkanShader> VkShaderManager::LoadVertShader(FString shadername
.Create(shadername.GetChars(), fb->device.get());
}
std::unique_ptr<VulkanShader> VkShaderManager::LoadFragShader(FString shadername, const char *frag_lump, const char *material_lump, const char *light_lump, const char *defines, bool alphatest, bool gbufferpass)
std::unique_ptr<VulkanShader> VkShaderManager::LoadFragShader(FString shadername, const char *frag_lump, const char *material_lump, const char* mateffect_lump, const char *light_lump, const char *defines, bool alphatest, bool gbufferpass)
{
FString definesBlock;
definesBlock << defines << "\n";
@ -210,62 +210,8 @@ std::unique_ptr<VulkanShader> VkShaderManager::LoadFragShader(FString shadername
FString materialBlock;
if (material_lump)
{
if (material_lump[0] != '#')
{
materialname = material_lump;
FString pp_code = LoadPublicShaderLump(material_lump);
if (pp_code.IndexOf("ProcessMaterial") < 0 && pp_code.IndexOf("SetupMaterial") < 0)
{
// this looks like an old custom hardware shader.
if (pp_code.IndexOf("GetTexCoord") >= 0)
{
materialBlock << LoadPrivateShaderLump("shaders/scene/material_default.glsl").GetChars() << "\n";
}
else
{
if (pp_code.IndexOf("ProcessTexel") < 0)
{
// this looks like an even older custom hardware shader.
materialBlock << LoadPrivateShaderLump("shaders/scene/material_legacy_process.glsl").GetChars() << "\n";
}
else
{
materialBlock << LoadPrivateShaderLump("shaders/scene/material_legacy_ptexel.glsl").GetChars() << "\n";
}
}
if (pp_code.IndexOf("ProcessLight") >= 0)
{
// The ProcessLight signatured changed. Forward to the old one.
materialBlock << "\nvec4 ProcessLight(vec4 color);\n";
materialBlock << "\nvec4 ProcessLight(Material material, vec4 color) { return ProcessLight(color); }\n";
}
}
materialBlock << "\n#line 1\n";
materialBlock << RemoveLegacyUserUniforms(pp_code).GetChars();
materialBlock.Substitute("gl_TexCoord[0]", "vTexCoord"); // fix old custom shaders.
if (pp_code.IndexOf("ProcessLight") < 0)
{
materialBlock << "\n" << LoadPrivateShaderLump("shaders/scene/lighteffect_default.glsl").GetChars() << "\n";
}
// ProcessMaterial must be considered broken because it requires the user to fill in data they possibly cannot know all about.
if (pp_code.IndexOf("ProcessMaterial") >= 0 && pp_code.IndexOf("SetupMaterial") < 0)
{
// This reactivates the old logic and disables all features that cannot be supported with that method.
definesBlock << "#define LEGACY_USER_SHADER\n";
}
}
else
{
// material_lump is not a lump name but the source itself (from generated shaders)
materialBlock << (material_lump + 1) << "\n";
}
materialname = material_lump;
materialBlock = LoadPublicShaderLump(material_lump);
}
FString lightname = "LightBlock";
@ -276,6 +222,14 @@ std::unique_ptr<VulkanShader> VkShaderManager::LoadFragShader(FString shadername
lightBlock << LoadPrivateShaderLump(light_lump).GetChars();
}
FString mateffectname = "MaterialEffectBlock";
FString mateffectBlock;
if (mateffect_lump)
{
mateffectname = mateffect_lump;
mateffectBlock << LoadPrivateShaderLump(mateffect_lump).GetChars();
}
return ShaderBuilder()
.Type(ShaderType::Fragment)
.DebugName(shadername.GetChars())
@ -283,8 +237,7 @@ std::unique_ptr<VulkanShader> VkShaderManager::LoadFragShader(FString shadername
.AddSource("DefinesBlock", definesBlock.GetChars())
.AddSource("LayoutBlock", layoutBlock.GetChars())
.AddSource("shaders/scene/includes.glsl", LoadPrivateShaderLump("shaders/scene/includes.glsl").GetChars())
.AddSource("shaders/scene/mateffect_default.glsl", LoadPrivateShaderLump("shaders/scene/mateffect_default.glsl").GetChars())
//.AddSource("shaders/scene/lighteffect_default.glsl", LoadPrivateShaderLump("shaders/scene/lighteffect_default.glsl").GetChars())
.AddSource(mateffectname.GetChars(), mateffectBlock.GetChars())
.AddSource(materialname.GetChars(), materialBlock.GetChars())
.AddSource(lightname.GetChars(), lightBlock.GetChars())
.AddSource(frag_lump, codeBlock.GetChars())

View file

@ -84,7 +84,7 @@ public:
private:
std::unique_ptr<VulkanShader> LoadVertShader(FString shadername, const char *vert_lump, const char *defines);
std::unique_ptr<VulkanShader> LoadFragShader(FString shadername, const char *frag_lump, const char *material_lump, const char *light_lump, const char *defines, bool alphatest, bool gbufferpass);
std::unique_ptr<VulkanShader> LoadFragShader(FString shadername, const char *frag_lump, const char *material_lump, const char* mateffect_lump, const char *lightmodel_lump, const char *defines, bool alphatest, bool gbufferpass);
ShaderIncludeResult OnInclude(FString headerName, FString includerName, size_t depth, bool system);

View file

@ -1,6 +1,4 @@
#include "shaders/scene/material.glsl"
void main()
{
#ifdef NO_CLIPDISTANCE_SUPPORT

View file

@ -1,6 +1,4 @@
#include "shaders/scene/material.glsl"
void main()
{
#ifdef NO_CLIPDISTANCE_SUPPORT

View file

@ -1,8 +1,4 @@
layout(location=0) in vec4 vTexCoord;
layout(location=1) in vec4 vColor;
layout(location=0) out vec4 FragColor;
void main()
{
vec4 frag = vColor;

View file

@ -1,11 +1,4 @@
layout(location=2) in vec4 pixelpos;
layout(location=0) out vec4 FragColor;
#ifdef GBUFFER_PASS
layout(location=1) out vec4 FragFog;
layout(location=2) out vec4 FragNormal;
#endif
void main()
{
float fogdist;

View file

@ -1,10 +1,4 @@
layout(location=0) out vec4 FragColor;
#ifdef GBUFFER_PASS
layout(location=1) out vec4 FragFog;
layout(location=2) out vec4 FragNormal;
#endif
void main()
{
FragColor = vec4(1.0, 1.0, 1.0, 0.0);

View file

@ -1,6 +1,4 @@
#include "shaders/scene/material.glsl"
void main()
{
#ifdef NO_CLIPDISTANCE_SUPPORT

View file

@ -1,6 +1,4 @@
#include "shaders/scene/material.glsl"
void main()
{
#ifdef NO_CLIPDISTANCE_SUPPORT

View file

@ -1,5 +0,0 @@
vec4 ProcessLight(Material material, vec4 color)
{
return color;
}

View file

@ -2,8 +2,6 @@
#include "shaders/scene/lightmodel_software.glsl"
#include "shaders/scene/material.glsl"
vec4 ProcessLight(Material mat, vec4 color);
//===========================================================================
//
// Calculate light
@ -83,11 +81,6 @@ vec4 getLightColor(Material material)
color.rgb = min(color.rgb + material.Bright.rgb, 1.0);
#endif
//
// apply other light manipulation by custom shaders, default is a NOP.
//
color = ProcessLight(material, color);
//
// apply lightmaps
//

View file

@ -1,14 +0,0 @@
vec2 GetTexCoord()
{
vec2 texCoord = vTexCoord.st;
const float pi = 3.14159265358979323846;
vec2 offset = vec2(0.0,0.0);
float siny = sin(pi * 2.0 * (texCoord.y * 2.0 + timer * 0.75)) * 0.03;
offset.y = siny + sin(pi * 2.0 * (texCoord.x + timer * 0.75)) * 0.03;
offset.x = siny + sin(pi * 2.0 * (texCoord.x + timer * 0.45)) * 0.02;
return texCoord + offset;
}

View file

@ -1,11 +0,0 @@
vec2 GetTexCoord()
{
vec2 texCoord = vTexCoord.st;
const float pi = 3.14159265358979323846;
texCoord.x += sin(pi * 2.0 * (texCoord.y + timer * 0.125)) * 0.1;
return texCoord;
}