From 388c0272b0a9686667a4e583e5620c0ee3581032 Mon Sep 17 00:00:00 2001 From: Jan Laupetin Date: Wed, 8 Apr 2026 10:39:24 +0100 Subject: [PATCH] feat: add shader compilers for IW3,IW5,T5,T6 --- src/ObjCompiling/Game/IW3/ObjCompilerIW3.cpp | 4 ++++ src/ObjCompiling/Game/IW5/ObjCompilerIW5.cpp | 4 ++++ src/ObjCompiling/Game/T5/ObjCompilerT5.cpp | 4 ++++ src/ObjCompiling/Game/T6/ObjCompilerT6.cpp | 4 ++++ .../Techset/PixelShaderCompiler.cpp.template | 24 +++++++++++++++---- .../Techset/PixelShaderCompiler.h.template | 2 +- .../Techset/VertexShaderCompiler.cpp.template | 24 +++++++++++++++---- .../Techset/VertexShaderCompiler.h.template | 2 +- 8 files changed, 58 insertions(+), 10 deletions(-) diff --git a/src/ObjCompiling/Game/IW3/ObjCompilerIW3.cpp b/src/ObjCompiling/Game/IW3/ObjCompilerIW3.cpp index ad084e43..a1b03bbb 100644 --- a/src/ObjCompiling/Game/IW3/ObjCompilerIW3.cpp +++ b/src/ObjCompiling/Game/IW3/ObjCompilerIW3.cpp @@ -1,9 +1,11 @@ #include "ObjCompilerIW3.h" #include "Game/IW3/IW3.h" +#include "Game/IW3/Techset/PixelShaderCompilerIW3.h" #include "Game/IW3/Techset/TechniqueCompilerIW3.h" #include "Game/IW3/Techset/TechsetCompilerIW3.h" #include "Game/IW3/Techset/VertexDeclCompilerIW3.h" +#include "Game/IW3/Techset/VertexShaderCompilerIW3.h" #include "Image/ImageIwdPostProcessor.h" #include @@ -20,6 +22,8 @@ namespace collection.AddSubAssetCreator(techset::CreateTechniqueCompilerIW3(memory, zone, searchPath)); collection.AddSubAssetCreator(techset::CreateVertexDeclCompilerIW3(memory)); + collection.AddSubAssetCreator(techset::CreateVertexShaderCompilerIW3(memory, searchPath)); + collection.AddSubAssetCreator(techset::CreatePixelShaderCompilerIW3(memory, searchPath)); } void ConfigurePostProcessors(AssetCreatorCollection& collection, diff --git a/src/ObjCompiling/Game/IW5/ObjCompilerIW5.cpp b/src/ObjCompiling/Game/IW5/ObjCompilerIW5.cpp index 5a6ba6d3..e2338bc5 100644 --- a/src/ObjCompiling/Game/IW5/ObjCompilerIW5.cpp +++ b/src/ObjCompiling/Game/IW5/ObjCompilerIW5.cpp @@ -1,9 +1,11 @@ #include "ObjCompilerIW5.h" #include "Game/IW5/IW5.h" +#include "Game/IW5/Techset/PixelShaderCompilerIW5.h" #include "Game/IW5/Techset/TechniqueCompilerIW5.h" #include "Game/IW5/Techset/TechsetCompilerIW5.h" #include "Game/IW5/Techset/VertexDeclCompilerIW5.h" +#include "Game/IW5/Techset/VertexShaderCompilerIW5.h" #include "Image/ImageIwdPostProcessor.h" #include @@ -17,6 +19,8 @@ namespace auto& memory = zone.Memory(); collection.AddAssetCreator(techset::CreateVertexDeclCompilerIW5(memory)); + collection.AddAssetCreator(techset::CreateVertexShaderCompilerIW5(memory, searchPath)); + collection.AddAssetCreator(techset::CreatePixelShaderCompilerIW5(memory, searchPath)); collection.AddAssetCreator(techset::CreateTechsetCompilerIW5(memory, searchPath)); collection.AddSubAssetCreator(techset::CreateTechniqueCompilerIW5(memory, zone, searchPath)); diff --git a/src/ObjCompiling/Game/T5/ObjCompilerT5.cpp b/src/ObjCompiling/Game/T5/ObjCompilerT5.cpp index 12a63556..cea01648 100644 --- a/src/ObjCompiling/Game/T5/ObjCompilerT5.cpp +++ b/src/ObjCompiling/Game/T5/ObjCompilerT5.cpp @@ -1,9 +1,11 @@ #include "ObjCompilerT5.h" #include "Game/T5/T5.h" +#include "Game/T5/Techset/PixelShaderCompilerT5.h" #include "Game/T5/Techset/TechniqueCompilerT5.h" #include "Game/T5/Techset/TechsetCompilerT5.h" #include "Game/T5/Techset/VertexDeclCompilerT5.h" +#include "Game/T5/Techset/VertexShaderCompilerT5.h" #include "Image/ImageIwdPostProcessor.h" #include @@ -20,6 +22,8 @@ namespace collection.AddSubAssetCreator(techset::CreateTechniqueCompilerT5(memory, zone, searchPath)); collection.AddSubAssetCreator(techset::CreateVertexDeclCompilerT5(memory)); + collection.AddSubAssetCreator(techset::CreateVertexShaderCompilerT5(memory, searchPath)); + collection.AddSubAssetCreator(techset::CreatePixelShaderCompilerT5(memory, searchPath)); } void ConfigurePostProcessors(AssetCreatorCollection& collection, diff --git a/src/ObjCompiling/Game/T6/ObjCompilerT6.cpp b/src/ObjCompiling/Game/T6/ObjCompilerT6.cpp index 37ac9529..0577f440 100644 --- a/src/ObjCompiling/Game/T6/ObjCompilerT6.cpp +++ b/src/ObjCompiling/Game/T6/ObjCompilerT6.cpp @@ -1,9 +1,11 @@ #include "ObjCompilerT6.h" #include "Game/T6/T6.h" +#include "Game/T6/Techset/PixelShaderCompilerT6.h" #include "Game/T6/Techset/TechniqueCompilerT6.h" #include "Game/T6/Techset/TechsetCompilerT6.h" #include "Game/T6/Techset/VertexDeclCompilerT6.h" +#include "Game/T6/Techset/VertexShaderCompilerT6.h" #include "Image/ImageIPakPostProcessor.h" #include "Image/ImageIwdPostProcessor.h" #include "KeyValuePairs/KeyValuePairsCompilerT6.h" @@ -27,6 +29,8 @@ namespace collection.AddSubAssetCreator(techset::CreateTechniqueCompilerT6(memory, zone, searchPath)); collection.AddSubAssetCreator(techset::CreateVertexDeclCompilerT6(memory)); + collection.AddSubAssetCreator(techset::CreateVertexShaderCompilerT6(memory, searchPath)); + collection.AddSubAssetCreator(techset::CreatePixelShaderCompilerT6(memory, searchPath)); } void ConfigurePostProcessors(AssetCreatorCollection& collection, diff --git a/src/ObjCompiling/Techset/PixelShaderCompiler.cpp.template b/src/ObjCompiling/Techset/PixelShaderCompiler.cpp.template index 14fc8e6e..76553259 100644 --- a/src/ObjCompiling/Techset/PixelShaderCompiler.cpp.template +++ b/src/ObjCompiling/Techset/PixelShaderCompiler.cpp.template @@ -1,4 +1,4 @@ -#options GAME(IW4) +#options GAME(IW3, IW4, IW5, T5, T6) #filename "Game/" + GAME + "/Techset/PixelShaderCompiler" + GAME + ".cpp" @@ -66,7 +66,16 @@ namespace AssetCreationResult OVERRIDDEN_CREATOR_METHOD(const std::string& assetName, AssetCreationContext& context) override { - auto result = shader::CompileShader(assetName, "PSMain", "ps_3_0", false, m_search_path, m_memory); + auto result = shader::CompileShader(assetName, + "PSMain", +#ifdef IS_DX9 + "ps_3_0", +#else + "ps_4_0", +#endif + false, + m_search_path, + m_memory); if (result.has_value()) { @@ -76,12 +85,19 @@ namespace con::info("Compiled pixel shader \"{}\"", assetName); +#ifdef IS_DX9 assert(maybeShader->m_shader_size % sizeof(uint32_t) == 0); +#endif auto* pixelShader = m_memory.Alloc(); pixelShader->name = m_memory.Dup(assetName.c_str()); - pixelShader->prog.loadDef.program = static_cast(maybeShader->m_shader_bin); - pixelShader->prog.loadDef.programSize = static_cast(maybeShader->m_shader_size / sizeof(uint32_t)); + pixelShader->prog.loadDef.program = static_cast(maybeShader->m_shader_bin); +#ifdef IS_DX9 + pixelShader->prog.loadDef.programSize = static_cast( + maybeShader->m_shader_size / sizeof(std::remove_pointer_t)); +#else + pixelShader->prog.loadDef.programSize = static_cast(maybeShader->m_shader_size); +#endif return AssetCreationResult::Success(context.ADD_ASSET_METHOD(AssetRegistration(assetName, pixelShader))); } diff --git a/src/ObjCompiling/Techset/PixelShaderCompiler.h.template b/src/ObjCompiling/Techset/PixelShaderCompiler.h.template index 8c5f1e81..67bfd9ae 100644 --- a/src/ObjCompiling/Techset/PixelShaderCompiler.h.template +++ b/src/ObjCompiling/Techset/PixelShaderCompiler.h.template @@ -1,4 +1,4 @@ -#options GAME(IW4) +#options GAME(IW3, IW4, IW5, T5, T6) #filename "Game/" + GAME + "/Techset/PixelShaderCompiler" + GAME + ".h" diff --git a/src/ObjCompiling/Techset/VertexShaderCompiler.cpp.template b/src/ObjCompiling/Techset/VertexShaderCompiler.cpp.template index 653421a1..0282ffe0 100644 --- a/src/ObjCompiling/Techset/VertexShaderCompiler.cpp.template +++ b/src/ObjCompiling/Techset/VertexShaderCompiler.cpp.template @@ -1,4 +1,4 @@ -#options GAME(IW4) +#options GAME(IW3, IW4, IW5, T5, T6) #filename "Game/" + GAME + "/Techset/VertexShaderCompiler" + GAME + ".cpp" @@ -66,7 +66,16 @@ namespace AssetCreationResult OVERRIDDEN_CREATOR_METHOD(const std::string& assetName, AssetCreationContext& context) override { - auto result = shader::CompileShader(assetName, "VSMain", "vs_3_0", false, m_search_path, m_memory); + auto result = shader::CompileShader(assetName, + "VSMain", +#ifdef IS_DX9 + "vs_3_0", +#else + "vs_4_0", +#endif + false, + m_search_path, + m_memory); if (result.has_value()) { @@ -76,12 +85,19 @@ namespace con::info("Compiled vertex shader \"{}\"", assetName); +#ifdef IS_DX9 assert(maybeShader->m_shader_size % sizeof(uint32_t) == 0); +#endif auto* vertexShader = m_memory.Alloc(); vertexShader->name = m_memory.Dup(assetName.c_str()); - vertexShader->prog.loadDef.program = static_cast(maybeShader->m_shader_bin); - vertexShader->prog.loadDef.programSize = static_cast(maybeShader->m_shader_size / sizeof(uint32_t)); + vertexShader->prog.loadDef.program = static_cast(maybeShader->m_shader_bin); +#ifdef IS_DX9 + vertexShader->prog.loadDef.programSize = static_cast( + maybeShader->m_shader_size / sizeof(std::remove_pointer_t)); +#else + vertexShader->prog.loadDef.programSize = static_cast(maybeShader->m_shader_size); +#endif return AssetCreationResult::Success(context.ADD_ASSET_METHOD(AssetRegistration(assetName, vertexShader))); } diff --git a/src/ObjCompiling/Techset/VertexShaderCompiler.h.template b/src/ObjCompiling/Techset/VertexShaderCompiler.h.template index f4076334..509ebdf1 100644 --- a/src/ObjCompiling/Techset/VertexShaderCompiler.h.template +++ b/src/ObjCompiling/Techset/VertexShaderCompiler.h.template @@ -1,4 +1,4 @@ -#options GAME(IW4) +#options GAME(IW3, IW4, IW5, T5, T6) #filename "Game/" + GAME + "/Techset/VertexShaderCompiler" + GAME + ".h"