diff --git a/src/common/rendering/hwrenderer/data/hw_shaderpatcher.cpp b/src/common/rendering/hwrenderer/data/hw_shaderpatcher.cpp index 3b0104e3b3..342c343b04 100644 --- a/src/common/rendering/hwrenderer/data/hw_shaderpatcher.cpp +++ b/src/common/rendering/hwrenderer/data/hw_shaderpatcher.cpp @@ -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() diff --git a/src/common/rendering/hwrenderer/data/hw_shaderpatcher.h b/src/common/rendering/hwrenderer/data/hw_shaderpatcher.h index 4a3a1c39fd..aeb8f3cdd8 100644 --- a/src/common/rendering/hwrenderer/data/hw_shaderpatcher.h +++ b/src/common/rendering/hwrenderer/data/hw_shaderpatcher.h @@ -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; }; diff --git a/src/common/rendering/vulkan/shaders/vk_shader.cpp b/src/common/rendering/vulkan/shaders/vk_shader.cpp index c9e5efd173..27a3a5fe48 100644 --- a/src/common/rendering/vulkan/shaders/vk_shader.cpp +++ b/src/common/rendering/vulkan/shaders/vk_shader.cpp @@ -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 VkShaderManager::LoadVertShader(FString shadername .Create(shadername.GetChars(), fb->device.get()); } -std::unique_ptr 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 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 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 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 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()) diff --git a/src/common/rendering/vulkan/shaders/vk_shader.h b/src/common/rendering/vulkan/shaders/vk_shader.h index 6dae96297b..37d45fc646 100644 --- a/src/common/rendering/vulkan/shaders/vk_shader.h +++ b/src/common/rendering/vulkan/shaders/vk_shader.h @@ -84,7 +84,7 @@ public: private: std::unique_ptr LoadVertShader(FString shadername, const char *vert_lump, const char *defines); - std::unique_ptr 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 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); diff --git a/wadsrc/static/shaders/scene/frag_2d.glsl b/wadsrc/static/shaders/scene/frag_2d.glsl index f3d99bee42..8eff32483d 100644 --- a/wadsrc/static/shaders/scene/frag_2d.glsl +++ b/wadsrc/static/shaders/scene/frag_2d.glsl @@ -1,6 +1,4 @@ -#include "shaders/scene/material.glsl" - void main() { #ifdef NO_CLIPDISTANCE_SUPPORT diff --git a/wadsrc/static/shaders/scene/frag_2d_stencil.glsl b/wadsrc/static/shaders/scene/frag_2d_stencil.glsl index 14f46049d9..4cfcdccb2f 100644 --- a/wadsrc/static/shaders/scene/frag_2d_stencil.glsl +++ b/wadsrc/static/shaders/scene/frag_2d_stencil.glsl @@ -1,6 +1,4 @@ -#include "shaders/scene/material.glsl" - void main() { #ifdef NO_CLIPDISTANCE_SUPPORT diff --git a/wadsrc/static/shaders/scene/frag_burn.glsl b/wadsrc/static/shaders/scene/frag_burn.glsl index ff9c1d699d..0c572aa9a5 100644 --- a/wadsrc/static/shaders/scene/frag_burn.glsl +++ b/wadsrc/static/shaders/scene/frag_burn.glsl @@ -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; diff --git a/wadsrc/static/shaders/scene/frag_fogboundary.glsl b/wadsrc/static/shaders/scene/frag_fogboundary.glsl index b3d4de6275..4332c8c93e 100644 --- a/wadsrc/static/shaders/scene/frag_fogboundary.glsl +++ b/wadsrc/static/shaders/scene/frag_fogboundary.glsl @@ -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; diff --git a/wadsrc/static/shaders/scene/frag_stencil.glsl b/wadsrc/static/shaders/scene/frag_stencil.glsl index 7405df648d..0a305b3564 100644 --- a/wadsrc/static/shaders/scene/frag_stencil.glsl +++ b/wadsrc/static/shaders/scene/frag_stencil.glsl @@ -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); diff --git a/wadsrc/static/shaders/scene/frag_surface.glsl b/wadsrc/static/shaders/scene/frag_surface.glsl index 15bc499565..78a56bc9cf 100644 --- a/wadsrc/static/shaders/scene/frag_surface.glsl +++ b/wadsrc/static/shaders/scene/frag_surface.glsl @@ -1,6 +1,4 @@ -#include "shaders/scene/material.glsl" - void main() { #ifdef NO_CLIPDISTANCE_SUPPORT diff --git a/wadsrc/static/shaders/scene/frag_surface_stencil.glsl b/wadsrc/static/shaders/scene/frag_surface_stencil.glsl index 2d0d4bbb0e..5b531a7780 100644 --- a/wadsrc/static/shaders/scene/frag_surface_stencil.glsl +++ b/wadsrc/static/shaders/scene/frag_surface_stencil.glsl @@ -1,6 +1,4 @@ -#include "shaders/scene/material.glsl" - void main() { #ifdef NO_CLIPDISTANCE_SUPPORT diff --git a/wadsrc/static/shaders/scene/lighteffect_default.glsl b/wadsrc/static/shaders/scene/lighteffect_default.glsl deleted file mode 100644 index 6738af8f5f..0000000000 --- a/wadsrc/static/shaders/scene/lighteffect_default.glsl +++ /dev/null @@ -1,5 +0,0 @@ - -vec4 ProcessLight(Material material, vec4 color) -{ - return color; -} diff --git a/wadsrc/static/shaders/scene/lightmodel.glsl b/wadsrc/static/shaders/scene/lightmodel.glsl index 143f09ada8..c6fc3c7dc4 100644 --- a/wadsrc/static/shaders/scene/lightmodel.glsl +++ b/wadsrc/static/shaders/scene/lightmodel.glsl @@ -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 // diff --git a/wadsrc/static/shaders/scene/mateffect_warp3.glsl b/wadsrc/static/shaders/scene/mateffect_warp3.glsl deleted file mode 100644 index 614e05c813..0000000000 --- a/wadsrc/static/shaders/scene/mateffect_warp3.glsl +++ /dev/null @@ -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; -} diff --git a/wadsrc/static/shaders/scene/mateffect_wavex.glsl b/wadsrc/static/shaders/scene/mateffect_wavex.glsl deleted file mode 100644 index 397157c533..0000000000 --- a/wadsrc/static/shaders/scene/mateffect_wavex.glsl +++ /dev/null @@ -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; -}