From a267cf737e7c68f78164b525140469fb7a188327 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Wed, 22 Mar 2023 00:06:13 +0100 Subject: [PATCH] Add support for using #include in glsl files and improve glsl compile errors --- .../hwrenderer/data/hw_shaderpatcher.cpp | 38 ++--- .../rendering/vulkan/shaders/vk_shader.cpp | 156 ++++++++++++------ .../rendering/vulkan/shaders/vk_shader.h | 5 +- wadsrc/static/shaders/scene/desaturate.glsl | 2 +- wadsrc/static/shaders/scene/frag_2d.glsl | 3 +- .../static/shaders/scene/frag_2d_stencil.glsl | 3 +- wadsrc/static/shaders/scene/frag_surface.glsl | 3 +- .../shaders/scene/frag_surface_stencil.glsl | 3 +- wadsrc/static/shaders/scene/includes.glsl | 5 + ...ayout_frag_scene.glsl => layout_frag.glsl} | 0 ...ayout_vert_scene.glsl => layout_vert.glsl} | 0 ...ightmodel_default.glsl => lightmodel.glsl} | 4 +- wadsrc/static/shaders/scene/material.glsl | 3 + .../shaders/scene/material_gettexel.glsl | 3 +- .../scene/material_legacy_process.glsl | 9 + .../scene/{vert_scene.glsl => vert_main.glsl} | 2 +- 16 files changed, 159 insertions(+), 80 deletions(-) create mode 100644 wadsrc/static/shaders/scene/includes.glsl rename wadsrc/static/shaders/scene/{layout_frag_scene.glsl => layout_frag.glsl} (100%) rename wadsrc/static/shaders/scene/{layout_vert_scene.glsl => layout_vert.glsl} (100%) rename wadsrc/static/shaders/scene/{lightmodel_default.glsl => lightmodel.glsl} (97%) create mode 100644 wadsrc/static/shaders/scene/material_legacy_process.glsl rename wadsrc/static/shaders/scene/{vert_scene.glsl => vert_main.glsl} (99%) diff --git a/src/common/rendering/hwrenderer/data/hw_shaderpatcher.cpp b/src/common/rendering/hwrenderer/data/hw_shaderpatcher.cpp index 50fed5a948..3b0104e3b3 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/glsl/func_normal.fp", "shaders/glsl/material_normal.fp", ""}, - {"Warp 1", "shaders/glsl/func_warp1.fp", "shaders/glsl/material_normal.fp", ""}, - {"Warp 2", "shaders/glsl/func_warp2.fp", "shaders/glsl/material_normal.fp", ""}, - {"Specular", "shaders/glsl/func_spec.fp", "shaders/glsl/material_specular.fp", "#define SPECULAR\n#define NORMALMAP\n"}, - {"PBR","shaders/glsl/func_pbr.fp", "shaders/glsl/material_pbr.fp", "#define PBR\n#define NORMALMAP\n"}, - {"Paletted", "shaders/glsl/func_paletted.fp", "shaders/glsl/material_nolight.fp", "#define PALETTE_EMULATION\n"}, - {"No Texture", "shaders/glsl/func_notexture.fp", "shaders/glsl/material_normal.fp", "#define NO_LAYERS\n"}, - {"Basic Fuzz", "shaders/glsl/fuzz_standard.fp", "shaders/glsl/material_normal.fp", ""}, - {"Smooth Fuzz", "shaders/glsl/fuzz_smooth.fp", "shaders/glsl/material_normal.fp", ""}, - {"Swirly Fuzz", "shaders/glsl/fuzz_swirly.fp", "shaders/glsl/material_normal.fp", ""}, - {"Translucent Fuzz", "shaders/glsl/fuzz_smoothtranslucent.fp", "shaders/glsl/material_normal.fp", ""}, - {"Jagged Fuzz", "shaders/glsl/fuzz_jagged.fp", "shaders/glsl/material_normal.fp", ""}, - {"Noise Fuzz", "shaders/glsl/fuzz_noise.fp", "shaders/glsl/material_normal.fp", ""}, - {"Smooth Noise Fuzz", "shaders/glsl/fuzz_smoothnoise.fp", "shaders/glsl/material_normal.fp", ""}, - {"Software Fuzz", "shaders/glsl/fuzz_software.fp", "shaders/glsl/material_normal.fp", ""}, + {"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/glsl/main.vp", "shaders/glsl/fogboundary.fp", nullptr, nullptr, "#define NO_ALPHATEST\n" }, - { "spheremap", "shaders/glsl/main.vp", "shaders/glsl/main.fp", "shaders/glsl/func_normal.fp", "shaders/glsl/material_normal.fp", "#define SPHEREMAP\n#define NO_ALPHATEST\n" }, - { "burn", "shaders/glsl/main.vp", "shaders/glsl/burn.fp", nullptr, nullptr, "#define SIMPLE\n#define NO_ALPHATEST\n" }, - { "stencil", "shaders/glsl/main.vp", "shaders/glsl/stencil.fp", nullptr, nullptr, "#define SIMPLE\n#define NO_ALPHATEST\n" }, + { "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" }, }; int DFrameBuffer::GetShaderCount() diff --git a/src/common/rendering/vulkan/shaders/vk_shader.cpp b/src/common/rendering/vulkan/shaders/vk_shader.cpp index 52336773ac..c9e5efd173 100644 --- a/src/common/rendering/vulkan/shaders/vk_shader.cpp +++ b/src/common/rendering/vulkan/shaders/vk_shader.cpp @@ -32,8 +32,8 @@ bool VkShaderManager::CompileNextShader() { - const char *mainvp = "shaders/glsl/vert_scene.vp"; - const char *mainfp = "shaders/glsl/frag_surface.fp"; + const char *mainvp = "shaders/scene/vert_main.glsl"; + const char *mainfp = "shaders/scene/frag_surface.glsl"; int i = compileIndex; if (compileState == 0) @@ -155,127 +155,189 @@ VkShaderProgram *VkShaderManager::Get(unsigned int eff, bool alphateston, EPassT std::unique_ptr VkShaderManager::LoadVertShader(FString shadername, const char *vert_lump, const char *defines) { - FString code = GetTargetGlslVersion(); - code << defines; - code << "\n#define MAX_STREAM_DATA " << std::to_string(MAX_STREAM_DATA).c_str() << "\n"; + FString definesBlock; + definesBlock << defines << "\n"; + definesBlock << "#define MAX_STREAM_DATA " << std::to_string(MAX_STREAM_DATA).c_str() << "\n"; #ifdef NPOT_EMULATION - code << "#define NPOT_EMULATION\n"; + definesBlock << "#define NPOT_EMULATION\n"; #endif - code << LoadPrivateShaderLump("shaders/scene/layout_shared.glsl"); - if (!fb->device->EnabledFeatures.Features.shaderClipDistance) code << "#define NO_CLIPDISTANCE_SUPPORT\n"; - code << "#line 1\n"; - code << LoadPrivateShaderLump(vert_lump).GetChars() << "\n"; + if (!fb->device->EnabledFeatures.Features.shaderClipDistance) + { + definesBlock << "#define NO_CLIPDISTANCE_SUPPORT\n"; + } + + FString layoutBlock; + layoutBlock << LoadPrivateShaderLump("shaders/scene/layout_shared.glsl").GetChars() << "\n"; + layoutBlock << LoadPrivateShaderLump("shaders/scene/layout_vert.glsl").GetChars() << "\n"; + + FString codeBlock; + codeBlock << LoadPrivateShaderLump(vert_lump).GetChars() << "\n"; return ShaderBuilder() .Type(ShaderType::Vertex) - .AddSource(shadername.GetChars(), code.GetChars()) .DebugName(shadername.GetChars()) + .AddSource("VersionBlock", GetVersionBlock().GetChars()) + .AddSource("DefinesBlock", definesBlock.GetChars()) + .AddSource("LayoutBlock", layoutBlock.GetChars()) + .AddSource(vert_lump, codeBlock.GetChars()) + .OnIncludeLocal([=](std::string headerName, std::string includerName, size_t depth) { return OnInclude(headerName.c_str(), includerName.c_str(), depth, false); }) + .OnIncludeSystem([=](std::string headerName, std::string includerName, size_t depth) { return OnInclude(headerName.c_str(), includerName.c_str(), depth, true); }) .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) { - FString code = GetTargetGlslVersion(); - if (fb->device->SupportsExtension(VK_KHR_RAY_QUERY_EXTENSION_NAME)) - code << "\n#define SUPPORTS_RAYTRACING\n"; - code << defines; - code << "\n$placeholder$"; // here the code can later add more needed #defines. - code << "\n#define MAX_STREAM_DATA " << std::to_string(MAX_STREAM_DATA).c_str() << "\n"; + FString definesBlock; + definesBlock << defines << "\n"; + if (fb->device->SupportsExtension(VK_KHR_RAY_QUERY_EXTENSION_NAME)) definesBlock << "\n#define SUPPORTS_RAYTRACING\n"; + definesBlock << defines; + definesBlock << "\n#define MAX_STREAM_DATA " << std::to_string(MAX_STREAM_DATA).c_str() << "\n"; #ifdef NPOT_EMULATION - code << "#define NPOT_EMULATION\n"; + definesBlock << "#define NPOT_EMULATION\n"; #endif - code << LoadPrivateShaderLump("shaders/scene/layout_shared.glsl"); - FString placeholder = "\n"; + if (!fb->device->EnabledFeatures.Features.shaderClipDistance) definesBlock << "#define NO_CLIPDISTANCE_SUPPORT\n"; + if (!alphatest) definesBlock << "#define NO_ALPHATEST\n"; + if (gbufferpass) definesBlock << "#define GBUFFER_PASS\n"; - if (!fb->device->EnabledFeatures.Features.shaderClipDistance) code << "#define NO_CLIPDISTANCE_SUPPORT\n"; - if (!alphatest) code << "#define NO_ALPHATEST\n"; - if (gbufferpass) code << "#define GBUFFER_PASS\n"; + FString layoutBlock; + layoutBlock << LoadPrivateShaderLump("shaders/scene/layout_shared.glsl").GetChars() << "\n"; + layoutBlock << LoadPrivateShaderLump("shaders/scene/layout_frag.glsl").GetChars() << "\n"; - code << "\n#line 1\n"; - code << LoadPrivateShaderLump(frag_lump).GetChars() << "\n"; + FString codeBlock; + codeBlock << LoadPrivateShaderLump(frag_lump).GetChars() << "\n"; + FString materialname = "MaterialBlock"; + 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. - // add ProcessMaterial function that calls the older ProcessTexel function if (pp_code.IndexOf("GetTexCoord") >= 0) { - code << "\n" << LoadPrivateShaderLump("shaders/glsl/func_defaultmat2.fp").GetChars() << "\n"; + materialBlock << LoadPrivateShaderLump("shaders/scene/material_default.glsl").GetChars() << "\n"; } else { - code << "\n" << LoadPrivateShaderLump("shaders/glsl/func_defaultmat.fp").GetChars() << "\n"; if (pp_code.IndexOf("ProcessTexel") < 0) { // this looks like an even older custom hardware shader. - // We need to replace the ProcessTexel call to make it work. - - code.Substitute("material.Base = ProcessTexel();", "material.Base = Process(vec4(1.0));"); + 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. - code << "\nvec4 ProcessLight(vec4 color);\n"; - code << "\nvec4 ProcessLight(Material material, vec4 color) { return ProcessLight(color); }\n"; + materialBlock << "\nvec4 ProcessLight(vec4 color);\n"; + materialBlock << "\nvec4 ProcessLight(Material material, vec4 color) { return ProcessLight(color); }\n"; } } - code << "\n#line 1\n"; - code << RemoveLegacyUserUniforms(pp_code).GetChars(); - code.Substitute("gl_TexCoord[0]", "vTexCoord"); // fix old custom shaders. + 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) { - code << "\n" << LoadPrivateShaderLump("shaders/glsl/func_defaultlight.fp").GetChars() << "\n"; + 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. - placeholder << "#define LEGACY_USER_SHADER\n"; + definesBlock << "#define LEGACY_USER_SHADER\n"; } } else { // material_lump is not a lump name but the source itself (from generated shaders) - code << (material_lump + 1) << "\n"; + materialBlock << (material_lump + 1) << "\n"; } } - code.Substitute("$placeholder$", placeholder); + FString lightname = "LightBlock"; + FString lightBlock; if (light_lump) { - code << "\n#line 1\n"; - code << LoadPrivateShaderLump(light_lump).GetChars(); + lightname = light_lump; + lightBlock << LoadPrivateShaderLump(light_lump).GetChars(); } return ShaderBuilder() .Type(ShaderType::Fragment) - .AddSource(shadername.GetChars(), code.GetChars()) .DebugName(shadername.GetChars()) + .AddSource("VersionBlock", GetVersionBlock().GetChars()) + .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(materialname.GetChars(), materialBlock.GetChars()) + .AddSource(lightname.GetChars(), lightBlock.GetChars()) + .AddSource(frag_lump, codeBlock.GetChars()) + .OnIncludeLocal([=](std::string headerName, std::string includerName, size_t depth) { return OnInclude(headerName.c_str(), includerName.c_str(), depth, false); }) + .OnIncludeSystem([=](std::string headerName, std::string includerName, size_t depth) { return OnInclude(headerName.c_str(), includerName.c_str(), depth, true); }) .Create(shadername.GetChars(), fb->device.get()); } -FString VkShaderManager::GetTargetGlslVersion() +FString VkShaderManager::GetVersionBlock() { - if (fb->device->Instance->ApiVersion == VK_API_VERSION_1_2) + FString versionBlock; + + if (fb->device->Instance->ApiVersion >= VK_API_VERSION_1_2) { - return "#version 460\n#extension GL_EXT_ray_query : enable\n"; + versionBlock << "#version 460 core\n"; } else { - return "#version 450 core\n"; + versionBlock << "#version 450 core\n"; } + + versionBlock << "#extension GL_GOOGLE_include_directive : enable\n"; + + if (fb->device->SupportsExtension(VK_KHR_RAY_QUERY_EXTENSION_NAME)) + { + versionBlock << "#extension GL_EXT_ray_query : enable\n"; + } + + return versionBlock; +} + +ShaderIncludeResult VkShaderManager::OnInclude(FString headerName, FString includerName, size_t depth, bool system) +{ + if (depth > 8) + I_Error("Too much include recursion!"); + + FString includeguardname; + includeguardname << "_HEADERGUARD_" << headerName.GetChars(); + includeguardname.ReplaceChars("/\\.", '_'); + + FString code; + code << "#ifndef " << includeguardname.GetChars() << "\n"; + code << "#define " << includeguardname.GetChars() << "\n"; + code << "#line 1\n"; + + if (system) + code << LoadPrivateShaderLump(headerName.GetChars()).GetChars() << "\n"; + else + code << LoadPublicShaderLump(headerName.GetChars()).GetChars() << "\n"; + + code << "#endif\n"; + + return ShaderIncludeResult(headerName.GetChars(), code.GetChars()); } FString VkShaderManager::LoadPublicShaderLump(const char *lumpname) diff --git a/src/common/rendering/vulkan/shaders/vk_shader.h b/src/common/rendering/vulkan/shaders/vk_shader.h index cac924916b..6dae96297b 100644 --- a/src/common/rendering/vulkan/shaders/vk_shader.h +++ b/src/common/rendering/vulkan/shaders/vk_shader.h @@ -11,6 +11,7 @@ #define SHADER_MIN_REQUIRED_TEXTURE_LAYERS 11 +class ShaderIncludeResult; class VulkanRenderDevice; class VulkanDevice; class VulkanShader; @@ -85,7 +86,9 @@ 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); - FString GetTargetGlslVersion(); + ShaderIncludeResult OnInclude(FString headerName, FString includerName, size_t depth, bool system); + + FString GetVersionBlock(); FString LoadPublicShaderLump(const char *lumpname); FString LoadPrivateShaderLump(const char *lumpname); diff --git a/wadsrc/static/shaders/scene/desaturate.glsl b/wadsrc/static/shaders/scene/desaturate.glsl index 3b4a9e1260..719c577848 100644 --- a/wadsrc/static/shaders/scene/desaturate.glsl +++ b/wadsrc/static/shaders/scene/desaturate.glsl @@ -1,5 +1,5 @@ -#include "grayscale.glsl" +#include "shaders/scene/grayscale.glsl" // Desaturate a color diff --git a/wadsrc/static/shaders/scene/frag_2d.glsl b/wadsrc/static/shaders/scene/frag_2d.glsl index d40d21df12..f3d99bee42 100644 --- a/wadsrc/static/shaders/scene/frag_2d.glsl +++ b/wadsrc/static/shaders/scene/frag_2d.glsl @@ -1,6 +1,5 @@ -#include "layout_frag_scene.glsl" -#include "material.glsl" +#include "shaders/scene/material.glsl" void main() { diff --git a/wadsrc/static/shaders/scene/frag_2d_stencil.glsl b/wadsrc/static/shaders/scene/frag_2d_stencil.glsl index 4189acadbf..14f46049d9 100644 --- a/wadsrc/static/shaders/scene/frag_2d_stencil.glsl +++ b/wadsrc/static/shaders/scene/frag_2d_stencil.glsl @@ -1,6 +1,5 @@ -#include "layout_frag_scene.glsl" -#include "material.glsl" +#include "shaders/scene/material.glsl" void main() { diff --git a/wadsrc/static/shaders/scene/frag_surface.glsl b/wadsrc/static/shaders/scene/frag_surface.glsl index ddb96d8820..15bc499565 100644 --- a/wadsrc/static/shaders/scene/frag_surface.glsl +++ b/wadsrc/static/shaders/scene/frag_surface.glsl @@ -1,6 +1,5 @@ -#include "layout_frag_scene.glsl" -#include "material.glsl" +#include "shaders/scene/material.glsl" void main() { diff --git a/wadsrc/static/shaders/scene/frag_surface_stencil.glsl b/wadsrc/static/shaders/scene/frag_surface_stencil.glsl index 72721ff2be..2d0d4bbb0e 100644 --- a/wadsrc/static/shaders/scene/frag_surface_stencil.glsl +++ b/wadsrc/static/shaders/scene/frag_surface_stencil.glsl @@ -1,6 +1,5 @@ -#include "layout_frag_scene.glsl" -#include "material.glsl" +#include "shaders/scene/material.glsl" void main() { diff --git a/wadsrc/static/shaders/scene/includes.glsl b/wadsrc/static/shaders/scene/includes.glsl new file mode 100644 index 0000000000..7bc217ad46 --- /dev/null +++ b/wadsrc/static/shaders/scene/includes.glsl @@ -0,0 +1,5 @@ + +#include "shaders/scene/material.glsl" +#include "shaders/scene/lightmodel.glsl" +#include "shaders/scene/light_shadow.glsl" +#include "shaders/scene/light_spot.glsl" diff --git a/wadsrc/static/shaders/scene/layout_frag_scene.glsl b/wadsrc/static/shaders/scene/layout_frag.glsl similarity index 100% rename from wadsrc/static/shaders/scene/layout_frag_scene.glsl rename to wadsrc/static/shaders/scene/layout_frag.glsl diff --git a/wadsrc/static/shaders/scene/layout_vert_scene.glsl b/wadsrc/static/shaders/scene/layout_vert.glsl similarity index 100% rename from wadsrc/static/shaders/scene/layout_vert_scene.glsl rename to wadsrc/static/shaders/scene/layout_vert.glsl diff --git a/wadsrc/static/shaders/scene/lightmodel_default.glsl b/wadsrc/static/shaders/scene/lightmodel.glsl similarity index 97% rename from wadsrc/static/shaders/scene/lightmodel_default.glsl rename to wadsrc/static/shaders/scene/lightmodel.glsl index 64d19e4528..143f09ada8 100644 --- a/wadsrc/static/shaders/scene/lightmodel_default.glsl +++ b/wadsrc/static/shaders/scene/lightmodel.glsl @@ -1,6 +1,6 @@ -#include "lightmodel_software.glsl" -#include "material.glsl" +#include "shaders/scene/lightmodel_software.glsl" +#include "shaders/scene/material.glsl" vec4 ProcessLight(Material mat, vec4 color); diff --git a/wadsrc/static/shaders/scene/material.glsl b/wadsrc/static/shaders/scene/material.glsl index a39c8042a3..c43026dfba 100644 --- a/wadsrc/static/shaders/scene/material.glsl +++ b/wadsrc/static/shaders/scene/material.glsl @@ -1,4 +1,7 @@ +#include "shaders/scene/material_getTexel.glsl" +#include "shaders/scene/material_normalmap.glsl" + struct Material { vec4 Base; diff --git a/wadsrc/static/shaders/scene/material_gettexel.glsl b/wadsrc/static/shaders/scene/material_gettexel.glsl index dc71f86dd7..5b21e6a358 100644 --- a/wadsrc/static/shaders/scene/material_gettexel.glsl +++ b/wadsrc/static/shaders/scene/material_gettexel.glsl @@ -1,5 +1,5 @@ -#include "desaturate.glsl" +#include "shaders/scene/desaturate.glsl" vec4 ApplyTextureManipulation(vec4 texel, int blendflags); @@ -26,6 +26,7 @@ vec4 getTexel(vec2 st) } #elif (uTextureMode & 0xffff) == 6 // TM_OPAQUEINVERSE texel = vec4(1.0-texel.r, 1.0-texel.b, 1.0-texel.g, 1.0); + #endif #if (uTextureMode & 0x80000) == 0x80000 // TEXF_ClampY if (st.t < 0.0 || st.t > 1.0) diff --git a/wadsrc/static/shaders/scene/material_legacy_process.glsl b/wadsrc/static/shaders/scene/material_legacy_process.glsl new file mode 100644 index 0000000000..e2bbd63566 --- /dev/null +++ b/wadsrc/static/shaders/scene/material_legacy_process.glsl @@ -0,0 +1,9 @@ + +vec4 Process(vec4); + +void SetupMaterial(inout Material material) +{ + material.Base = Process(vec4(1.0)); + material.Normal = ApplyNormalMap(vTexCoord.st); + material.Bright = texture(brighttexture, vTexCoord.st); +} diff --git a/wadsrc/static/shaders/scene/vert_scene.glsl b/wadsrc/static/shaders/scene/vert_main.glsl similarity index 99% rename from wadsrc/static/shaders/scene/vert_scene.glsl rename to wadsrc/static/shaders/scene/vert_main.glsl index 9ca64dae7f..dbd1c6f0e1 100644 --- a/wadsrc/static/shaders/scene/vert_scene.glsl +++ b/wadsrc/static/shaders/scene/vert_main.glsl @@ -1,5 +1,5 @@ -#include "bones.glsl" +#include "shaders/scene/bones.glsl" void main() {