diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 0e0360b35..2d5621676 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -14,6 +14,10 @@ + + + + diff --git a/CMakeLists.txt b/CMakeLists.txt index aa2aa3384..0434ed540 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,14 +9,17 @@ if(APPLE AND NOT CMAKE_OSX_SYSROOT) OUTPUT_STRIP_TRAILING_WHITESPACE) endif() -project(urde) - -option(URDE_CROSSCOMPILING "Don't build tools; attempt package import" Off) +option(URDE_CROSSCOMPILING "Don't build tools; attempt package import" OFF) if (URDE_CROSSCOMPILING) set(CMAKE_CROSSCOMPILING On) - set(HAVE_WORDS_BIGENDIAN_EXITCODE 0) endif() +if(CMAKE_CROSSCOMPILING) + set(HAVE_WORDS_BIGENDIAN_EXITCODE 0 CACHE INTEGER "Makes soxr happy" FORCE) +endif() + +project(urde) + set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(BUILD_SHARED_LIBS OFF CACHE BOOL "Force shared libs off" FORCE) @@ -30,7 +33,11 @@ if(NOT MSVC OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC") include(cotire) endif() -set(URDE_VECTOR_ISA "sse2" CACHE STRING "Vector ISA to build for (sse2, sse3, sse41, avx, avx2)") +if (NX) + set(URDE_VECTOR_ISA "neon") +else() + set(URDE_VECTOR_ISA "sse2" CACHE STRING "Vector ISA to build for (sse2, sse3, sse41, avx, avx2)") +endif() if(MSVC) if(${URDE_VECTOR_ISA} STREQUAL "avx2") @@ -99,12 +106,14 @@ else() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse2") message(STATUS "Building with SSE2 Vector ISA") + elseif(${URDE_VECTOR_ISA} STREQUAL "neon") + message(STATUS "Building with NEON Vector ISA") else() message(STATUS "Building with x87 Vector ISA") endif() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}\ - -Wno-multichar -fno-exceptions -Wno-narrowing -Wno-nullability-completeness -Werror=return-type") + -Wno-multichar -fno-exceptions -fno-rtti -Wno-narrowing -Wno-nullability-completeness -Werror=return-type") if(APPLE) set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -flto=thin") @@ -141,13 +150,15 @@ if(USE_LD_GOLD AND ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_ endif() # Add discord-rpc here -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/rapidjson/include) -set(PROJECT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/discord-rpc) -if (NOT CMAKE_INSTALL_LIBDIR) - set(CMAKE_INSTALL_LIBDIR ${CMAKE_BINARY_DIR}/fake-prefix) +if(NOT GEKKO AND NOT NX) + include_directories(${CMAKE_CURRENT_SOURCE_DIR}/rapidjson/include) + set(PROJECT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/discord-rpc) + if (NOT CMAKE_INSTALL_LIBDIR) + set(CMAKE_INSTALL_LIBDIR ${CMAKE_BINARY_DIR}/fake-prefix) + endif() + add_subdirectory(discord-rpc/src) + include_directories(${CMAKE_CURRENT_SOURCE_DIR}/discord-rpc/include) endif() -add_subdirectory(discord-rpc/src) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/discord-rpc/include) add_subdirectory(nod) set(NOD_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/nod/include) @@ -185,6 +196,10 @@ set(HECL_DATASPEC_PUSHES hecl::Database::DATA_SPEC_REGISTRY.push_back(&DataSpec::SpecEntMP3); hecl::Database::DATA_SPEC_REGISTRY.push_back(&DataSpec::SpecEntMP3PC); hecl::Database::DATA_SPEC_REGISTRY.push_back(&DataSpec::SpecEntMP3ORIG);") +add_subdirectory(hecl/shaderc) +include(hecl/ApplicationTools.cmake) +add_subdirectory(specter/shaders) +add_subdirectory(Shaders) add_subdirectory(hecl) if(NOT TARGET bintoc) @@ -233,12 +248,14 @@ add_subdirectory(visigen) add_dependencies(hecl visigen) -find_package(Qt5Widgets) -if (Qt5Widgets_FOUND) +if (NOT WINDOWS_STORE AND NOT NX) + find_package(Qt5Widgets) + if (Qt5Widgets_FOUND) message(STATUS "Qt5 found, hecl-gui will be built") add_subdirectory(hecl-gui) -else() + else() message(STATUS "Qt5 not found, hecl-gui will not be built") + endif() endif() unset(GIT_EXECUTABLE CACHE) diff --git a/DataSpec/DNAMP3/CMDLMaterials.cpp b/DataSpec/DNAMP3/CMDLMaterials.cpp index 4a2938088..938d05586 100644 --- a/DataSpec/DNAMP3/CMDLMaterials.cpp +++ b/DataSpec/DNAMP3/CMDLMaterials.cpp @@ -156,7 +156,7 @@ void MaterialSet::ConstructMaterial(Stream& out, for (const Material::SectionFactory& factory : material.sections) { factory.section->constructNode(out, pakRouter, entry, prevSection, i++, texMapIdx, texMtxIdx, kColorIdx); - Material::SectionPASS* pass = dynamic_cast(factory.section.get()); + Material::SectionPASS* pass = Material::SectionPASS::castTo(factory.section.get()); if (!pass || (pass && Material::SectionPASS::Subtype(pass->subtype.toUint32()) != Material::SectionPASS::Subtype::RFLV)) prevSection = factory.section.get(); } diff --git a/DataSpec/DNAMP3/CMDLMaterials.hpp b/DataSpec/DNAMP3/CMDLMaterials.hpp index fe8898fb1..222a126e1 100644 --- a/DataSpec/DNAMP3/CMDLMaterials.hpp +++ b/DataSpec/DNAMP3/CMDLMaterials.hpp @@ -74,6 +74,8 @@ struct MaterialSet : BigDNA struct SectionPASS : ISection { SectionPASS() : ISection(ISection::Type::PASS) {} + static SectionPASS* castTo(ISection* sec) + { return sec->m_type == Type::PASS ? static_cast(sec) : nullptr; } AT_DECL_DNA AT_DECL_DNAV Value size; @@ -126,6 +128,8 @@ struct MaterialSet : BigDNA struct SectionCLR : ISection { SectionCLR() : ISection(ISection::Type::CLR) {} + static SectionCLR* castTo(ISection* sec) + { return sec->m_type == Type::CLR ? static_cast(sec) : nullptr; } AT_DECL_DNA AT_DECL_DNAV enum class Subtype : atUint32 @@ -148,6 +152,8 @@ struct MaterialSet : BigDNA struct SectionINT : ISection { SectionINT() : ISection(ISection::Type::INT) {} + static SectionINT* castTo(ISection* sec) + { return sec->m_type == Type::INT ? static_cast(sec) : nullptr; } AT_DECL_DNA AT_DECL_DNAV enum class Subtype : atUint32 diff --git a/Editor/CMakeLists.txt b/Editor/CMakeLists.txt index 0ea66faf0..1249ff332 100644 --- a/Editor/CMakeLists.txt +++ b/Editor/CMakeLists.txt @@ -101,7 +101,9 @@ target_link_libraries(urde UrdeIcons UrdeBadging RuntimeCommon NESEmulator - specter specter-fonts freetype ${DATA_SPEC_LIBS} + specter specter-fonts + ${HECL_APPLICATION_REPS_TARGETS_LIST} + freetype ${DATA_SPEC_LIBS} hecl-full hecl-blender-addon athena-core nod logvisor athena-libyaml amuse boo ${PNG_LIB} libjpeg-turbo squish xxhash zeus diff --git a/Editor/Space.cpp b/Editor/Space.cpp index e1d59b7b1..208bf5b21 100644 --- a/Editor/Space.cpp +++ b/Editor/Space.cpp @@ -98,7 +98,7 @@ void SplitSpace::joinViews(specter::SplitView* thisSplit, int thisSlot, specter: { if (thisSplit == otherSplit) { - SplitSpace* thisSS = dynamic_cast(m_slots[thisSlot].get()); + SplitSpace* thisSS = m_slots[thisSlot]->castToSplitSpace(); if (thisSS) { int ax = thisSS->m_state.axis == specter::SplitView::Axis::Horizontal ? 1 : 0; @@ -115,7 +115,7 @@ void SplitSpace::joinViews(specter::SplitView* thisSplit, int thisSlot, specter: { for (int i=0 ; i<2 ; ++i) { - SplitSpace* otherSS = dynamic_cast(m_slots[i].get()); + SplitSpace* otherSS = m_slots[i]->castToSplitSpace(); if (otherSS && otherSS->m_splitView.get() == otherSplit) { int ax = m_state.axis == specter::SplitView::Axis::Horizontal ? 1 : 0; @@ -248,23 +248,23 @@ void Space::SpaceMenuNode::SubNode::activated(const boo::SWindowCoord &coord) switch(m_data.m_cls) { case Class::InformationCenter: - if (typeid(InformationCenter) != typeid(m_space)) + if (m_space.cls() == Class::InformationCenter) newSpace.reset(new InformationCenter(m_space.m_parent->m_vm, m_space.m_parent)); break; case Class::EffectEditor: - if (typeid(EffectEditor) != typeid(m_space)) + if (m_space.cls() == Class::EffectEditor) newSpace.reset(new EffectEditor(m_space.m_parent->m_vm, m_space.m_parent)); break; case Class::ResourceBrowser: - if (typeid(ResourceBrowser) != typeid(m_space)) + if (m_space.cls() == Class::ResourceBrowser) newSpace.reset(new ResourceBrowser(m_space.m_parent->m_vm, m_space.m_parent)); break; case Class::ModelViewer: - if (typeid(ModelViewer) != typeid(m_space)) + if (m_space.cls() == Class::ModelViewer) newSpace.reset(new ModelViewer(m_space.m_parent->m_vm, m_space.m_parent)); break; case Class::GameMode: - if (typeid(GameMode) != typeid(m_space)) + if (m_space.cls() == Class::GameMode) newSpace.reset(new GameMode(m_space.m_parent->m_vm, m_space.m_parent)); break; default: break; diff --git a/Editor/Space.hpp b/Editor/Space.hpp index d0afcc679..bf069adcc 100644 --- a/Editor/Space.hpp +++ b/Editor/Space.hpp @@ -22,6 +22,7 @@ namespace urde { class ViewManager; class RootSpace; +class SplitSpace; class Space : public specter::ISpaceController { @@ -160,6 +161,8 @@ public: {return std::unique_ptr();} virtual specter::View* basisView() {return m_spaceView.get();} + Class cls() const { return m_class; } + SplitSpace* castToSplitSpace(); }; class RootSpace : public Space @@ -359,6 +362,8 @@ public: specter::View* basisView() {return m_splitView.get();} }; +inline SplitSpace* Space::castToSplitSpace() +{ return cls() == Class::SplitSpace ? static_cast(this) : nullptr; } class ViewerSpace : public Space { diff --git a/Editor/ViewManager.cpp b/Editor/ViewManager.cpp index f4f340796..562fbfa9a 100644 --- a/Editor/ViewManager.cpp +++ b/Editor/ViewManager.cpp @@ -20,6 +20,7 @@ #include "Audio/CStreamAudioManager.hpp" #include "Runtime/CStateManager.hpp" #include "Runtime/World/CPlayer.hpp" +#include "hecl/Pipeline.hpp" #include using YAMLNode = athena::io::YAMLNode; @@ -292,6 +293,8 @@ void ViewManager::init(boo::IApplication* app) float pixelFactor = m_mainWindow->getVirtualPixelFactor(); m_mainBooFactory = m_mainWindow->getMainContextDataFactory(); + m_pipelineConv = hecl::NewPipelineConverter(m_mainBooFactory); + hecl::conv = m_pipelineConv.get(); m_mainPlatformName = m_mainBooFactory->platformName(); m_mainWindow->setTitle(_S("URDE [") + hecl::SystemString(m_mainPlatformName) + _S("]")); m_mainCommandQueue = m_mainWindow->getCommandQueue(); diff --git a/Editor/ViewManager.hpp b/Editor/ViewManager.hpp index 561e49985..60c564b1d 100644 --- a/Editor/ViewManager.hpp +++ b/Editor/ViewManager.hpp @@ -22,6 +22,8 @@ #include "Runtime/Graphics/Shaders/CCameraBlurFilter.hpp" #include "Runtime/Audio/CStaticAudioPlayer.hpp" +namespace hecl { class PipelineConverterBase; } + namespace urde { class SplashScreen; @@ -43,6 +45,7 @@ class ViewManager final : public specter::IViewManager specter::Translator m_translator; boo::IGraphicsDataFactory* m_mainBooFactory = nullptr; boo::IGraphicsCommandQueue* m_mainCommandQueue = nullptr; + std::unique_ptr m_pipelineConv; boo::ObjToken m_renderTex; const boo::SystemChar* m_mainPlatformName; diff --git a/NESEmulator/CNESShader.cpp b/NESEmulator/CNESShader.cpp index 0f9683f72..5b13168c2 100644 --- a/NESEmulator/CNESShader.cpp +++ b/NESEmulator/CNESShader.cpp @@ -1,334 +1,32 @@ #include "CNESShader.hpp" #include "Graphics/CGraphics.hpp" +#include "hecl/Pipeline.hpp" namespace urde::MP1 { boo::ObjToken CNESShader::g_Pipeline; -boo::ObjToken CNESShader::g_VtxFmt; -static const char* VS_GLSL = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"layout(location=0) in vec4 posIn;\n" -"layout(location=1) in vec4 uvIn;\n" -"\n" -"UBINDING0 uniform TexuredQuadUniform\n" -"{\n" -" mat4 mtx;\n" -" vec4 color;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -" vec2 uv;\n" -"};\n" -"\n" -"SBINDING(0) out VertToFrag vtf;\n" -"void main()\n" -"{\n" -" vtf.color = color;\n" -" vtf.uv = uvIn.xy;\n" -" gl_Position = mtx * vec4(posIn.xyz, 1.0);\n" -" gl_Position = FLIPFROMGL(gl_Position);\n" -"}\n"; - -static const char* FS_GLSL = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -" vec2 uv;\n" -"};\n" -"\n" -"SBINDING(0) in VertToFrag vtf;\n" -"layout(location=0) out vec4 colorOut;\n" -"TBINDING0 uniform sampler2D tex;\n" -"void main()\n" -"{\n" -" colorOut = vtf.color * texture(tex, vtf.uv);\n" -"}\n"; - -#if _WIN32 -static const char* VS_HLSL = -"struct VertData\n" -"{\n" -" float4 posIn : POSITION;\n" -" float4 uvIn : UV;\n" -"};\n" -"\n" -"cbuffer TexuredQuadUniform : register(b0)\n" -"{\n" -" float4x4 mat;\n" -" float4 color;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float4 color : COLOR;\n" -" float2 uv : UV;\n" -"};\n" -"\n" -"VertToFrag main(in VertData v)\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.color = color;\n" -" vtf.uv = v.uvIn.xy;\n" -" vtf.position = mul(mat, float4(v.posIn.xyz, 1.0));\n" -" return vtf;\n" -"}\n"; - -static const char* FS_HLSL = -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float4 color : COLOR;\n" -" float2 uv : UV;\n" -"};\n" -"\n" -"Texture2D tex : register(t0);\n" -"SamplerState samp : register(s4);\n" -"\n" -"float4 main(in VertToFrag vtf) : SV_Target0\n" -"{\n" -" return vtf.color * tex.Sample(samp, vtf.uv);\n" -"}\n"; -#endif - -#if BOO_HAS_METAL -static const char* VS_METAL = -"#include \n" -"using namespace metal;\n" -"struct VertData\n" -"{\n" -" float4 posIn [[ attribute(0) ]];\n" -" float4 uvIn [[ attribute(1) ]];\n" -"};\n" -"\n" -"struct TexuredQuadUniform\n" -"{\n" -" float4x4 mat;\n" -" float4 color;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float4 color;\n" -" float2 uv;\n" -"};\n" -"\n" -"vertex VertToFrag vmain(VertData v [[ stage_in ]], constant TexuredQuadUniform& tqu [[ buffer(2) ]])\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.color = tqu.color;\n" -" vtf.uv = v.uvIn.xy;\n" -" vtf.position = tqu.mat * float4(v.posIn.xyz, 1.0);\n" -" return vtf;\n" -"}\n"; - - -static const char* FS_METAL = -"#include \n" -"using namespace metal;\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float4 color;\n" -" float2 uv;\n" -"};\n" -"\n" -"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n" -" sampler clampSamp [[ sampler(4) ]],\n" -" texture2d tex [[ texture(0) ]])\n" -"{\n" -" return vtf.color * tex.sample(clampSamp, vtf.uv);\n" -"}\n"; -#endif - -#if BOO_HAS_GL -void CNESShader::Initialize(boo::GLDataFactory::Context& ctx) +void CNESShader::Initialize() { - const char* texNames[] = {"tex"}; - const char* uniNames[] = {"TexuredQuadUniform"}; - g_Pipeline = ctx.newShaderPipeline(VS_GLSL, FS_GLSL, 1, texNames, 1, uniNames, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); + g_Pipeline = hecl::conv->convert(Shader_CNESShader{}); } -boo::ObjToken CNESShader::BuildShaderDataBinding(boo::GLDataFactory::Context& ctx, - boo::ObjToken vbo, - boo::ObjToken uniBuf, - boo::ObjToken tex) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {vbo.get(), nullptr, boo::VertexSemantic::Position4}, - {vbo.get(), nullptr, boo::VertexSemantic::UV4} - }; - boo::ObjToken bufs[] = {uniBuf.get()}; - boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; - boo::ObjToken texs[] = {tex.get()}; - return ctx.newShaderDataBinding(g_Pipeline, - ctx.newVertexFormat(2, VtxVmt), vbo.get(), nullptr, nullptr, - 1, bufs, stages, nullptr, nullptr, 1, texs, nullptr, nullptr); -} -#endif - -#if _WIN32 -void CNESShader::Initialize(boo::D3DDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::UV4} - }; - g_VtxFmt = ctx.newVertexFormat(2, VtxVmt); - g_Pipeline = ctx.newShaderPipeline(VS_HLSL, FS_HLSL, nullptr, nullptr, nullptr, - g_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); -} - -boo::ObjToken CNESShader::BuildShaderDataBinding(boo::D3DDataFactory::Context& ctx, - boo::ObjToken vbo, - boo::ObjToken uniBuf, - boo::ObjToken tex) -{ - boo::ObjToken bufs[] = {uniBuf.get()}; - boo::ObjToken texs[] = {tex.get()}; - return ctx.newShaderDataBinding(g_Pipeline, g_VtxFmt, - vbo.get(), nullptr, nullptr, 1, bufs, - nullptr, nullptr, nullptr, 1, texs, nullptr, nullptr); -} -#endif - -#if BOO_HAS_METAL -void CNESShader::Initialize(boo::MetalDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::UV4} - }; - g_VtxFmt = ctx.newVertexFormat(2, VtxVmt); - g_Pipeline = ctx.newShaderPipeline(VS_METAL, FS_METAL, nullptr, nullptr, - g_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); -} - -boo::ObjToken CNESShader::BuildShaderDataBinding(boo::MetalDataFactory::Context& ctx, - boo::ObjToken vbo, - boo::ObjToken uniBuf, - boo::ObjToken tex) -{ - boo::ObjToken bufs[] = {uniBuf.get()}; - boo::ObjToken texs[] = {tex.get()}; - return ctx.newShaderDataBinding(g_Pipeline, g_VtxFmt, - vbo.get(), nullptr, nullptr, 1, bufs, - nullptr, nullptr, nullptr, 1, texs, nullptr, nullptr); -} -#endif - -#if BOO_HAS_VULKAN -void CNESShader::Initialize(boo::VulkanDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::UV4} - }; - g_VtxFmt = ctx.newVertexFormat(2, VtxVmt); - g_Pipeline = ctx.newShaderPipeline(VS_GLSL, FS_GLSL, g_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); -} - -boo::ObjToken CNESShader::BuildShaderDataBinding(boo::VulkanDataFactory::Context& ctx, - boo::ObjToken vbo, - boo::ObjToken uniBuf, - boo::ObjToken tex) -{ - boo::ObjToken bufs[] = {uniBuf.get()}; - boo::ObjToken texs[] = {tex.get()}; - return ctx.newShaderDataBinding(g_Pipeline, g_VtxFmt, - vbo.get(), nullptr, nullptr, 1, bufs, - nullptr, nullptr, nullptr, 1, texs, nullptr, nullptr); -} -#endif - boo::ObjToken CNESShader::BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, boo::ObjToken vbo, boo::ObjToken uniBuf, boo::ObjToken tex) { - switch (ctx.platform()) - { -#if BOO_HAS_GL - case boo::IGraphicsDataFactory::Platform::OpenGL: - return BuildShaderDataBinding(static_cast(ctx), vbo, uniBuf, tex); -#endif -#if _WIN32 - case boo::IGraphicsDataFactory::Platform::D3D11: - return BuildShaderDataBinding(static_cast(ctx), vbo, uniBuf, tex); -#endif -#if BOO_HAS_METAL - case boo::IGraphicsDataFactory::Platform::Metal: - return BuildShaderDataBinding(static_cast(ctx), vbo, uniBuf, tex); -#endif -#if BOO_HAS_VULKAN - case boo::IGraphicsDataFactory::Platform::Vulkan: - return BuildShaderDataBinding(static_cast(ctx), vbo, uniBuf, tex); -#endif - default: - return {}; - } -} - -void CNESShader::Initialize() -{ - if (!CGraphics::g_BooFactory) - return; - - CGraphics::CommitResources( - [&](boo::IGraphicsDataFactory::Context& ctx) - { - switch (ctx.platform()) - { -#if BOO_HAS_GL - case boo::IGraphicsDataFactory::Platform::OpenGL: - Initialize(static_cast(ctx)); - break; -#endif -#if _WIN32 - case boo::IGraphicsDataFactory::Platform::D3D11: - Initialize(static_cast(ctx)); - break; -#endif -#if BOO_HAS_METAL - case boo::IGraphicsDataFactory::Platform::Metal: - Initialize(static_cast(ctx)); - break; -#endif -#if BOO_HAS_VULKAN - case boo::IGraphicsDataFactory::Platform::Vulkan: - Initialize(static_cast(ctx)); - break; -#endif - default: break; - } - return true; - } BooTrace); + boo::ObjToken bufs[] = {uniBuf.get()}; + boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; + boo::ObjToken texs[] = {tex.get()}; + return ctx.newShaderDataBinding(g_Pipeline, vbo.get(), nullptr, nullptr, + 1, bufs, stages, nullptr, nullptr, 1, texs, nullptr, nullptr); } void CNESShader::Shutdown() { g_Pipeline.reset(); - g_VtxFmt.reset(); } } diff --git a/NESEmulator/CNESShader.hpp b/NESEmulator/CNESShader.hpp index 68b263bae..6253002f8 100644 --- a/NESEmulator/CNESShader.hpp +++ b/NESEmulator/CNESShader.hpp @@ -1,10 +1,7 @@ #ifndef URDE_CNESSHADER_HPP #define URDE_CNESSHADER_HPP -#include "boo/graphicsdev/GL.hpp" -#include "boo/graphicsdev/Metal.hpp" -#include "boo/graphicsdev/D3D.hpp" -#include "boo/graphicsdev/Vulkan.hpp" +#include "boo/graphicsdev/IGraphicsDataFactory.hpp" namespace urde::MP1 { @@ -12,34 +9,6 @@ namespace urde::MP1 class CNESShader { public: -#if BOO_HAS_GL - static void Initialize(boo::GLDataFactory::Context& ctx); - static boo::ObjToken BuildShaderDataBinding(boo::GLDataFactory::Context& ctx, - boo::ObjToken vbo, - boo::ObjToken uniBuf, - boo::ObjToken tex); -#endif -#if _WIN32 - static void Initialize(boo::D3DDataFactory::Context& ctx); - static boo::ObjToken BuildShaderDataBinding(boo::D3DDataFactory::Context& ctx, - boo::ObjToken vbo, - boo::ObjToken uniBuf, - boo::ObjToken tex); -#endif -#if BOO_HAS_METAL - static void Initialize(boo::MetalDataFactory::Context& ctx); - static boo::ObjToken BuildShaderDataBinding(boo::MetalDataFactory::Context& ctx, - boo::ObjToken vbo, - boo::ObjToken uniBuf, - boo::ObjToken tex); -#endif -#if BOO_HAS_VULKAN - static void Initialize(boo::VulkanDataFactory::Context& ctx); - static boo::ObjToken BuildShaderDataBinding(boo::VulkanDataFactory::Context& ctx, - boo::ObjToken vbo, - boo::ObjToken uniBuf, - boo::ObjToken tex); -#endif static void Initialize(); static void Shutdown(); @@ -49,7 +18,6 @@ public: boo::ObjToken tex); static boo::ObjToken g_Pipeline; - static boo::ObjToken g_VtxFmt; }; } diff --git a/Runtime/CArchitectureMessage.hpp b/Runtime/CArchitectureMessage.hpp index 2431beff9..0426d6bc2 100644 --- a/Runtime/CArchitectureMessage.hpp +++ b/Runtime/CArchitectureMessage.hpp @@ -104,7 +104,7 @@ public: template const T* GetParm() const { - return dynamic_cast(x8_parm.get()); + return static_cast(x8_parm.get()); } }; diff --git a/Runtime/Graphics/CMakeLists.txt b/Runtime/Graphics/CMakeLists.txt index 907833875..0e85e28a0 100644 --- a/Runtime/Graphics/CMakeLists.txt +++ b/Runtime/Graphics/CMakeLists.txt @@ -1,85 +1,3 @@ -if(WIN32) - set(PLAT_SRCS - Shaders/CLineRendererShadersHLSL.cpp - Shaders/CTexturedQuadFilterHLSL.cpp - Shaders/CColoredQuadFilterHLSL.cpp - Shaders/CModelShadersHLSL.cpp - Shaders/CThermalColdFilterHLSL.cpp - Shaders/CThermalHotFilterHLSL.cpp - Shaders/CSpaceWarpFilterHLSL.cpp - Shaders/CCameraBlurFilterHLSL.cpp - Shaders/CXRayBlurFilterHLSL.cpp - Shaders/CTextSupportShaderHLSL.cpp - Shaders/CFogVolumePlaneShaderHLSL.cpp - Shaders/CFogVolumeFilterHLSL.cpp - Shaders/CEnergyBarShaderHLSL.cpp - Shaders/CRadarPaintShaderHLSL.cpp - Shaders/CMapSurfaceShaderHLSL.cpp - Shaders/CPhazonSuitFilterHLSL.cpp - Shaders/CScanLinesFilterHLSL.cpp - Shaders/CRandomStaticFilterHLSL.cpp - Shaders/CElementGenShadersHLSL.cpp - Shaders/CDecalShadersHLSL.cpp - Shaders/CParticleSwooshShadersHLSL.cpp - Shaders/CFluidPlaneShaderHLSL.cpp - Shaders/CAABoxShaderHLSL.cpp - Shaders/CWorldShadowShaderHLSL.cpp) -elseif(BOO_HAS_METAL) - set(PLAT_SRCS - Shaders/CLineRendererShadersMetal.cpp - Shaders/CTexturedQuadFilterMetal.cpp - Shaders/CColoredQuadFilterMetal.cpp - Shaders/CModelShadersMetal.cpp - Shaders/CThermalColdFilterMetal.cpp - Shaders/CThermalHotFilterMetal.cpp - Shaders/CSpaceWarpFilterMetal.cpp - Shaders/CCameraBlurFilterMetal.cpp - Shaders/CXRayBlurFilterMetal.cpp - Shaders/CTextSupportShaderMetal.cpp - Shaders/CFogVolumePlaneShaderMetal.cpp - Shaders/CFogVolumeFilterMetal.cpp - Shaders/CEnergyBarShaderMetal.cpp - Shaders/CRadarPaintShaderMetal.cpp - Shaders/CMapSurfaceShaderMetal.cpp - Shaders/CPhazonSuitFilterMetal.cpp - Shaders/CScanLinesFilterMetal.cpp - Shaders/CRandomStaticFilterMetal.cpp - Shaders/CElementGenShadersMetal.cpp - Shaders/CDecalShadersMetal.cpp - Shaders/CParticleSwooshShadersMetal.cpp - Shaders/CFluidPlaneShaderMetal.cpp - Shaders/CAABoxShaderMetal.cpp - Shaders/CWorldShadowShaderMetal.cpp) -endif() - -if(NOT WINDOWS_STORE) - list(APPEND PLAT_SRCS - Shaders/CLineRendererShadersGLSL.cpp - Shaders/CTexturedQuadFilterGLSL.cpp - Shaders/CColoredQuadFilterGLSL.cpp - Shaders/CModelShadersGLSL.cpp - Shaders/CThermalColdFilterGLSL.cpp - Shaders/CThermalHotFilterGLSL.cpp - Shaders/CSpaceWarpFilterGLSL.cpp - Shaders/CCameraBlurFilterGLSL.cpp - Shaders/CXRayBlurFilterGLSL.cpp - Shaders/CTextSupportShaderGLSL.cpp - Shaders/CFogVolumePlaneShaderGLSL.cpp - Shaders/CFogVolumeFilterGLSL.cpp - Shaders/CEnergyBarShaderGLSL.cpp - Shaders/CRadarPaintShaderGLSL.cpp - Shaders/CMapSurfaceShaderGLSL.cpp - Shaders/CPhazonSuitFilterGLSL.cpp - Shaders/CScanLinesFilterGLSL.cpp - Shaders/CRandomStaticFilterGLSL.cpp - Shaders/CElementGenShadersGLSL.cpp - Shaders/CDecalShadersGLSL.cpp - Shaders/CParticleSwooshShadersGLSL.cpp - Shaders/CFluidPlaneShaderGLSL.cpp - Shaders/CAABoxShaderGLSL.cpp - Shaders/CWorldShadowShaderGLSL.cpp) -endif() - set(GRAPHICS_SOURCES IRenderer.hpp IWeaponRenderer.hpp IWeaponRenderer.cpp @@ -101,12 +19,11 @@ set(GRAPHICS_SOURCES CGraphics.hpp CGraphics.cpp CSimpleShadow.hpp CSimpleShadow.cpp CRainSplashGenerator.hpp CRainSplashGenerator.cpp - Shaders/TShader.hpp Shaders/TMultiBlendShader.hpp - Shaders/TShaderDecl.hpp Shaders/TMultiBlendShaderDecl.hpp Shaders/CLineRendererShaders.hpp Shaders/CLineRendererShaders.cpp Shaders/CTexturedQuadFilter.hpp Shaders/CTexturedQuadFilter.cpp Shaders/CColoredQuadFilter.hpp Shaders/CColoredQuadFilter.cpp Shaders/CModelShaders.hpp Shaders/CModelShaders.cpp + Shaders/CModelShadersGLSL.cpp Shaders/CModelShadersHLSL.cpp Shaders/CModelShadersMetal.cpp Shaders/CThermalColdFilter.hpp Shaders/CThermalColdFilter.cpp Shaders/CThermalHotFilter.hpp Shaders/CThermalHotFilter.cpp Shaders/CSpaceWarpFilter.hpp Shaders/CSpaceWarpFilter.cpp @@ -126,7 +43,6 @@ set(GRAPHICS_SOURCES Shaders/CParticleSwooshShaders.hpp Shaders/CParticleSwooshShaders.cpp Shaders/CFluidPlaneShader.hpp Shaders/CFluidPlaneShader.cpp Shaders/CAABoxShader.hpp Shaders/CAABoxShader.cpp - Shaders/CWorldShadowShader.hpp Shaders/CWorldShadowShader.cpp - ${PLAT_SRCS}) + Shaders/CWorldShadowShader.hpp Shaders/CWorldShadowShader.cpp) runtime_add_list(Graphics GRAPHICS_SOURCES) diff --git a/Runtime/Graphics/CMetroidModelInstance.hpp b/Runtime/Graphics/CMetroidModelInstance.hpp index fbc878039..ccf7d96be 100644 --- a/Runtime/Graphics/CMetroidModelInstance.hpp +++ b/Runtime/Graphics/CMetroidModelInstance.hpp @@ -5,8 +5,8 @@ #include "RetroTypes.hpp" #include "zeus/CTransform.hpp" #include "zeus/CAABox.hpp" -#include "hecl/Runtime.hpp" #include "hecl/HMDLMeta.hpp" +#include "Shaders/CModelShaders.hpp" namespace urde { @@ -24,7 +24,7 @@ class CMetroidModelInstance std::vector m_surfaces; std::unique_ptr m_instance; hecl::HMDLMeta m_hmdlMeta; - std::unordered_map> m_shaders; + std::unordered_map m_shaders; public: CMetroidModelInstance() = default; CMetroidModelInstance(CMetroidModelInstance&&) = default; diff --git a/Runtime/Graphics/CModel.hpp b/Runtime/Graphics/CModel.hpp index 1e086ddc4..d4dbae713 100644 --- a/Runtime/Graphics/CModel.hpp +++ b/Runtime/Graphics/CModel.hpp @@ -103,18 +103,20 @@ struct GeometryUniformLayout struct SShader { + + std::vector> x0_textures; - std::unordered_map> m_shaders; + std::unordered_map m_shaders; MaterialSet m_matSet; std::experimental::optional m_geomLayout; int m_matSetIdx; SShader(int idx) : m_matSetIdx(idx) {} void InitializeLayout(const CModel* model) { m_geomLayout.emplace(model, &m_matSet); } void UnlockTextures(); - std::shared_ptr + CModelShaders::ShaderPipelines BuildShader(const hecl::HMDLMeta& meta, const MaterialSet::Material& mat); void BuildShaders(const hecl::HMDLMeta& meta, - std::unordered_map>& shaders); + std::unordered_map& shaders); void BuildShaders(const hecl::HMDLMeta& meta) { BuildShaders(meta, m_shaders); } }; @@ -144,7 +146,7 @@ private: const MaterialSet* x4_matSet; const GeometryUniformLayout* m_geomLayout; int m_matSetIdx = -1; - const std::unordered_map>* m_pipelines; + const std::unordered_map* m_pipelines; std::vector> x1c_textures; zeus::CAABox x20_aabb; CBooSurface* x38_firstUnsortedSurface = nullptr; @@ -170,15 +172,12 @@ private: boo::ObjToken m_geomUniformBuffer; boo::ObjToken m_uniformBuffer; std::vector>> m_shaderDataBindings; - boo::ObjToken m_dynamicVtxFmt; boo::ObjToken m_dynamicVbo; boo::ObjToken GetBooVBO(const CBooModel& model, boo::IGraphicsDataFactory::Context& ctx); - boo::ObjToken GetBooVtxFmt(const CBooModel& model, boo::IGraphicsDataFactory::Context& ctx); }; std::vector m_instances; - boo::ObjToken m_staticVtxFmt; boo::ObjToken m_staticVbo; boo::ObjToken m_staticIbo; @@ -206,9 +205,8 @@ private: public: ~CBooModel(); CBooModel(TToken& token, CModel* parent, std::vector* surfaces, SShader& shader, - const boo::ObjToken& vtxFmt, const boo::ObjToken& vbo, - const boo::ObjToken& ibo, const zeus::CAABox& aabb, u8 renderMask, - int numInsts, const boo::ObjToken txtrOverrides[8]); + const boo::ObjToken& vbo, const boo::ObjToken& ibo, + const zeus::CAABox& aabb, u8 renderMask, int numInsts, const boo::ObjToken txtrOverrides[8]); static void MakeTexturesFromMats(const MaterialSet& matSet, std::vector>& toksOut, @@ -221,7 +219,7 @@ public: void DisableAllLights(); void RemapMaterialData(SShader& shader); void RemapMaterialData(SShader& shader, - const std::unordered_map>& pipelines); + const std::unordered_map& pipelines); bool TryLockTextures() const; void UnlockTextures() const; void SyncLoadTextures() const; @@ -292,7 +290,6 @@ class CModel int x38_lastFrame; /* urde addition: boo! */ - boo::ObjToken m_staticVtxFmt; boo::ObjToken m_staticVbo; hecl::HMDLMeta m_hmdlMeta; std::unique_ptr m_dynamicVertexData; diff --git a/Runtime/Graphics/CModelBoo.cpp b/Runtime/Graphics/CModelBoo.cpp index dfc411dbc..2de52dabe 100644 --- a/Runtime/Graphics/CModelBoo.cpp +++ b/Runtime/Graphics/CModelBoo.cpp @@ -155,13 +155,12 @@ CBooModel::~CBooModel() } CBooModel::CBooModel(TToken& token, CModel* parent, std::vector* surfaces, SShader& shader, - const boo::ObjToken& vtxFmt, const boo::ObjToken& vbo, - const boo::ObjToken& ibo, const zeus::CAABox& aabb, u8 renderMask, - int numInsts, const boo::ObjToken txtrOverrides[8]) + const boo::ObjToken& vbo, const boo::ObjToken& ibo, + const zeus::CAABox& aabb, u8 renderMask, int numInsts, const boo::ObjToken txtrOverrides[8]) : m_modelTok(token), m_model(parent), x0_surfaces(surfaces), x4_matSet(&shader.m_matSet), m_geomLayout(&*shader.m_geomLayout), m_matSetIdx(shader.m_matSetIdx), m_pipelines(&shader.m_shaders), x1c_textures(shader.x0_textures), x20_aabb(aabb), x40_24_texturesLoaded(false), x40_25_modelVisible(0), - x41_mask(renderMask), m_staticVtxFmt(vtxFmt), m_staticVbo(vbo), m_staticIbo(ibo) + x41_mask(renderMask), m_staticVbo(vbo), m_staticIbo(ibo) { if (txtrOverrides) for (int i=0 ; i<8 ; ++i) @@ -217,21 +216,6 @@ CBooModel::ModelInstance::GetBooVBO(const CBooModel& model, return m_dynamicVbo.get(); } -boo::ObjToken -CBooModel::ModelInstance::GetBooVtxFmt(const CBooModel& model, - boo::IGraphicsDataFactory::Context& ctx) -{ - if (model.m_staticVtxFmt) - return model.m_staticVtxFmt; - if (!m_dynamicVtxFmt && model.m_model) - { - const CModel& parent = *model.m_model; - m_dynamicVtxFmt = hecl::Runtime::HMDLData::NewVertexFormat(ctx, parent.m_hmdlMeta, - GetBooVBO(model, ctx), parent.m_ibo.get()); - } - return m_dynamicVtxFmt; -} - GeometryUniformLayout::GeometryUniformLayout(const CModel* model, const MaterialSet* matSet) { if (model) @@ -418,14 +402,14 @@ CBooModel::ModelInstance* CBooModel::PushNewModelInstance(int sharedLayoutBuf) } thisSizes[3] = 256; - const std::shared_ptr& pipelines = m_pipelines->at(surf.m_data.matIdx); + const CModelShaders::ShaderPipelines& pipelines = m_pipelines->at(surf.m_data.matIdx); newInst.m_shaderDataBindings.emplace_back(); std::vector>& extendeds = newInst.m_shaderDataBindings.back(); - extendeds.reserve(pipelines->m_pipelines.size()); + extendeds.reserve(pipelines->size()); int idx = 0; - for (const boo::ObjToken& pipeline : pipelines->m_pipelines) + for (const auto& pipeline : *pipelines) { boo::ObjToken* ltexs; if (idx == EExtendedShader::Thermal) @@ -454,7 +438,7 @@ CBooModel::ModelInstance* CBooModel::PushNewModelInstance(int sharedLayoutBuf) ltexs = texs; } extendeds.push_back( - ctx.newShaderDataBinding(pipeline, newInst.GetBooVtxFmt(*this, ctx), + ctx.newShaderDataBinding(pipeline, newInst.GetBooVBO(*this, ctx), nullptr, m_staticIbo.get(), 4, bufs, stages, thisOffs, thisSizes, 8, ltexs, nullptr, nullptr)); ++idx; @@ -513,7 +497,7 @@ void CBooModel::RemapMaterialData(SShader& shader) } void CBooModel::RemapMaterialData(SShader& shader, - const std::unordered_map>& pipelines) + const std::unordered_map& pipelines) { if (!shader.m_geomLayout) return; @@ -1204,14 +1188,13 @@ std::unique_ptr CModel::MakeNewInstance(int shaderIdx, int subInsts, if (shaderIdx >= x18_matSets.size()) shaderIdx = 0; auto ret = std::make_unique(m_selfToken, this, &x8_surfaces, x18_matSets[shaderIdx], - m_staticVtxFmt, m_staticVbo, m_ibo, - m_aabb, (m_flags & 0x2) != 0, subInsts, txtrOverrides); + m_staticVbo, m_ibo, m_aabb, (m_flags & 0x2) != 0, subInsts, txtrOverrides); if (lockParent) ret->LockParent(); return ret; } -std::shared_ptr +CModelShaders::ShaderPipelines SShader::BuildShader(const hecl::HMDLMeta& meta, const MaterialSet::Material& mat) { hecl::Backend::ReflectionType reflectionType; @@ -1221,16 +1204,15 @@ SShader::BuildShader(const hecl::HMDLMeta& meta, const MaterialSet::Material& ma reflectionType = hecl::Backend::ReflectionType::Simple; else reflectionType = hecl::Backend::ReflectionType::None; - hecl::Runtime::ShaderTag tag(mat.heclIr, + hecl::Backend::ShaderTag tag(mat.heclIr, meta.colorCount, meta.uvCount, meta.weightCount, meta.weightCount * 4, boo::Primitive(meta.topology), reflectionType, true, true, true); - return CModelShaders::g_ModelShaders->buildExtendedShader - (tag, mat.heclIr, "CMDL", *CGraphics::g_BooFactory); + return CModelShaders::BuildExtendedShader(tag, mat.heclIr); } void SShader::BuildShaders(const hecl::HMDLMeta& meta, - std::unordered_map>& shaders) + std::unordered_map& shaders) { shaders.reserve(m_matSet.materials.size()); int idx = 0; @@ -1294,7 +1276,6 @@ CModel::CModel(std::unique_ptr&& in, u32 /* dataLen */, IObjectStore* stor if (m_hmdlMeta.vertCount) m_staticVbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, vboData, m_hmdlMeta.vertStride, m_hmdlMeta.vertCount); - m_staticVtxFmt = hecl::Runtime::HMDLData::NewVertexFormat(ctx, m_hmdlMeta, m_staticVbo.get(), m_ibo.get()); } else { diff --git a/Runtime/Graphics/CMoviePlayer.cpp b/Runtime/Graphics/CMoviePlayer.cpp index dcdff70ea..7a20fec40 100644 --- a/Runtime/Graphics/CMoviePlayer.cpp +++ b/Runtime/Graphics/CMoviePlayer.cpp @@ -5,158 +5,12 @@ #include "Audio/g721.h" #include "amuse/DSPCodec.hpp" #include "CDvdRequest.hpp" +#include "hecl/Pipeline.hpp" #include namespace urde { -static const char* VS_GLSL_YUV = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"layout(location=0) in vec3 posIn;\n" -"layout(location=1) in vec2 uvIn;\n" -SPECTER_GLSL_VIEW_VERT_BLOCK -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -" vec2 uv;\n" -"};\n" -"SBINDING(0) out VertToFrag vtf;\n" -"void main()\n" -"{\n" -" vtf.uv = uvIn;\n" -" vtf.color = mulColor;\n" -" gl_Position = mv * vec4(posIn, 1.0);\n" -" gl_Position = FLIPFROMGL(gl_Position);\n" -"}\n"; - -static const char* FS_GLSL_YUV = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -" vec2 uv;\n" -"};\n" -"SBINDING(0) in VertToFrag vtf;\n" -"TBINDING0 uniform sampler2D texY;\n" -"TBINDING1 uniform sampler2D texU;\n" -"TBINDING2 uniform sampler2D texV;\n" -"layout(location=0) out vec4 colorOut;\n" -"void main()\n" -"{\n" -" vec3 yuv;\n" -" yuv.r = texture(texY, vtf.uv).r;\n" -" yuv.g = texture(texU, vtf.uv).r;\n" -" yuv.b = texture(texV, vtf.uv).r;\n" -" yuv.r = 1.1643*(yuv.r-0.0625);\n" -" yuv.g = yuv.g-0.5;\n" -" yuv.b = yuv.b-0.5;\n" -" colorOut = vec4(yuv.r+1.5958*yuv.b,\n" -" yuv.r-0.39173*yuv.g-0.81290*yuv.b,\n" -" yuv.r+2.017*yuv.g, 1.0) * vtf.color;\n" -"}\n"; - -#if _WIN32 -static const char* VS_HLSL_YUV = -"struct VertData\n" -"{\n" -" float3 posIn : POSITION;\n" -" float2 uvIn : UV;\n" -"};\n" -SPECTER_HLSL_VIEW_VERT_BLOCK -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float4 color : COLOR;\n" -" float2 uv : UV;\n" -"};\n" -"VertToFrag main(in VertData v)\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.uv = v.uvIn;\n" -" vtf.color = mulColor;\n" -" vtf.position = mul(mv, float4(v.posIn, 1.0));\n" -" return vtf;\n" -"}\n"; - -static const char* FS_HLSL_YUV = -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float4 color : COLOR;\n" -" float2 uv : UV;\n" -"};\n" -"Texture2D texs[3] : register(t0);\n" -"SamplerState samp : register(s0);\n" -"float4 main(in VertToFrag vtf) : SV_Target0\n" -"{\n" -" float3 yuv;\n" -" yuv.r = texs[0].Sample(samp, vtf.uv).r;\n" -" yuv.g = texs[1].Sample(samp, vtf.uv).r;\n" -" yuv.b = texs[2].Sample(samp, vtf.uv).r;\n" -" yuv.r = 1.1643*(yuv.r-0.0625);\n" -" yuv.g = yuv.g-0.5;\n" -" yuv.b = yuv.b-0.5;\n" -" return float4(yuv.r+1.5958*yuv.b,\n" -" yuv.r-0.39173*yuv.g-0.81290*yuv.b,\n" -" yuv.r+2.017*yuv.g, 1.0) * vtf.color;\n" -"}\n"; -#endif - -#if BOO_HAS_METAL -static const char* VS_METAL_YUV = -"#include \n" -"using namespace metal;\n" -"struct VertData\n" -"{\n" -" float3 posIn [[ attribute(0) ]];\n" -" float2 uvIn [[ attribute(1) ]];\n" -"};\n" -SPECTER_METAL_VIEW_VERT_BLOCK -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float4 color;\n" -" float2 uv;\n" -"};\n" -"vertex VertToFrag vmain(VertData v [[ stage_in ]], constant SpecterViewBlock& view [[ buffer(2) ]])\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.uv = v.uvIn;\n" -" vtf.color = view.mulColor;\n" -" vtf.position = view.mv * float4(v.posIn, 1.0);\n" -" return vtf;\n" -"}\n"; - -static const char* FS_METAL_YUV = -"#include \n" -"using namespace metal;\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float4 color;\n" -" float2 uv;\n" -"};\n" -"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n" -" sampler samp [[ sampler(0) ]],\n" -" texture2d tex0 [[ texture(0) ]],\n" -" texture2d tex1 [[ texture(1) ]],\n" -" texture2d tex2 [[ texture(2) ]])\n" -"{\n" -" float3 yuv;\n" -" yuv.r = tex0.sample(samp, vtf.uv).r;\n" -" yuv.g = tex1.sample(samp, vtf.uv).r;\n" -" yuv.b = tex2.sample(samp, vtf.uv).r;\n" -" yuv.r = 1.1643*(yuv.r-0.0625);\n" -" yuv.g = yuv.g-0.5;\n" -" yuv.b = yuv.b-0.5;\n" -" return float4(yuv.r+1.5958*yuv.b,\n" -" yuv.r-0.39173*yuv.g-0.81290*yuv.b,\n" -" yuv.r+2.017*yuv.g, 1.0) * vtf.color;\n" -"}\n"; -#endif - /* used in the original to look up fixed-point dividends on a * MIDI-style volume scale (0-127) -> (n/0x8000) */ static const u16 StaticVolumeLookup[] = @@ -180,7 +34,6 @@ static const u16 StaticVolumeLookup[] = }; /* shared boo resources */ -static boo::ObjToken YUVVTXFmt; static boo::ObjToken YUVShaderPipeline; static tjhandle TjHandle = nullptr; @@ -202,63 +55,12 @@ static const char* TexNames[] = {"texY", "texU", "texV"}; void CMoviePlayer::Initialize() { - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) - { - if (!ctx.bindingNeedsVertexFormat()) - { - boo::VertexElementDescriptor texvdescs[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::UV4} - }; - YUVVTXFmt = ctx.newVertexFormat(2, texvdescs); - } - - switch (ctx.platform()) - { -#if BOO_HAS_GL - case boo::IGraphicsDataFactory::Platform::OpenGL: - YUVShaderPipeline = static_cast(ctx).newShaderPipeline - (VS_GLSL_YUV, FS_GLSL_YUV, 3, TexNames, 1, BlockNames, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::None, false, true, false, boo::CullMode::None); - break; -#endif -#if _WIN32 - case boo::IGraphicsDataFactory::Platform::D3D11: - YUVShaderPipeline = static_cast(ctx).newShaderPipeline - (VS_HLSL_YUV, FS_HLSL_YUV, nullptr, nullptr, nullptr, YUVVTXFmt, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::None, false, true, false, boo::CullMode::None); - break; -#endif -#if BOO_HAS_METAL - case boo::IGraphicsDataFactory::Platform::Metal: - YUVShaderPipeline = static_cast(ctx).newShaderPipeline - (VS_METAL_YUV, FS_METAL_YUV, nullptr, nullptr, YUVVTXFmt, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::None, false, true, false, boo::CullMode::None); - break; -#endif -#if BOO_HAS_VULKAN - case boo::IGraphicsDataFactory::Platform::Vulkan: - YUVShaderPipeline = static_cast(ctx).newShaderPipeline - (VS_GLSL_YUV, FS_GLSL_YUV, YUVVTXFmt, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::None, false, true, false, boo::CullMode::None); - break; -#endif - default: break; - } - return true; - } BooTrace); - + YUVShaderPipeline = hecl::conv->convert(Shader_CMoviePlayerShader{}); TjHandle = tjInitDecompress(); } void CMoviePlayer::Shutdown() { - YUVVTXFmt.reset(); YUVShaderPipeline.reset(); tjDestroy(TjHandle); } @@ -434,17 +236,6 @@ CMoviePlayer::CMoviePlayer(const char* path, float preLoadSeconds, bool loop, bo m_blockBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(m_viewVertBlock), 1); m_vertBuf = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(specter::View::TexShaderVert), 4); - boo::ObjToken vtxFmt = YUVVTXFmt; - if (ctx.bindingNeedsVertexFormat()) - { - boo::VertexElementDescriptor texvdescs[] = - { - {m_vertBuf.get(), nullptr, boo::VertexSemantic::Position4}, - {m_vertBuf.get(), nullptr, boo::VertexSemantic::UV4} - }; - vtxFmt = ctx.newVertexFormat(2, texvdescs); - } - /* Allocate textures here (rather than at decode time) */ x80_textures.reserve(3); for (int i=0 ; i<3 ; ++i) @@ -467,7 +258,7 @@ CMoviePlayer::CMoviePlayer(const char* path, float preLoadSeconds, bool loop, bo for (int j=0 ; j<2 ; ++j) { boo::ObjToken texs[] = {set.Y[j].get(), set.U.get(), set.V.get()}; - set.binding[j] = ctx.newShaderDataBinding(YUVShaderPipeline, vtxFmt, m_vertBuf.get(), + set.binding[j] = ctx.newShaderDataBinding(YUVShaderPipeline, m_vertBuf.get(), nullptr, nullptr, 1, bufs, nullptr, 3, texs, nullptr, nullptr); } @@ -484,7 +275,7 @@ CMoviePlayer::CMoviePlayer(const char* path, float preLoadSeconds, bool loop, bo boo::ObjToken bufs[] = {m_blockBuf.get()}; boo::ObjToken texs[] = {set.Y[0].get(), set.U.get(), set.V.get()}; - set.binding[0] = ctx.newShaderDataBinding(YUVShaderPipeline, vtxFmt, m_vertBuf.get(), + set.binding[0] = ctx.newShaderDataBinding(YUVShaderPipeline, m_vertBuf.get(), nullptr, nullptr, 1, bufs, nullptr, 3, texs, nullptr, nullptr); } diff --git a/Runtime/Graphics/Shaders/CAABoxShader.cpp b/Runtime/Graphics/Shaders/CAABoxShader.cpp index 6c4442fe6..bd9590f9b 100644 --- a/Runtime/Graphics/Shaders/CAABoxShader.cpp +++ b/Runtime/Graphics/Shaders/CAABoxShader.cpp @@ -1,16 +1,36 @@ #include "CAABoxShader.hpp" +#include "hecl/Pipeline.hpp" +#include "Graphics/CGraphics.hpp" namespace urde { -CAABoxShader::CAABoxShader(bool zOnly) -: m_zOnly(zOnly) +static boo::ObjToken s_Pipeline; +static boo::ObjToken s_zOnlyPipeline; + +void CAABoxShader::Initialize() { - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) + s_Pipeline = hecl::conv->convert(Shader_CAABoxShader{}); + s_zOnlyPipeline = hecl::conv->convert(Shader_CAABoxShaderZOnly{}); +} + +void CAABoxShader::Shutdown() +{ + s_Pipeline.reset(); + s_zOnlyPipeline.reset(); +} + +CAABoxShader::CAABoxShader(bool zOnly) +{ + CGraphics::CommitResources([this, zOnly](boo::IGraphicsDataFactory::Context& ctx) { m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(zeus::CVector3f), 34); m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); - m_dataBind = TShader::BuildShaderDataBinding(ctx, *this); + boo::ObjToken bufs[] = {m_uniBuf.get()}; + boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; + m_dataBind = ctx.newShaderDataBinding(zOnly ? s_zOnlyPipeline : s_Pipeline, + m_vbo.get(), nullptr, nullptr, 1, bufs, stages, + nullptr, nullptr, 0, nullptr, nullptr, nullptr); return true; } BooTrace); } @@ -73,6 +93,4 @@ void CAABoxShader::draw(const zeus::CColor& color) CGraphics::DrawArray(0, 34); } -URDE_SPECIALIZE_SHADER(CAABoxShader) - } diff --git a/Runtime/Graphics/Shaders/CAABoxShader.hpp b/Runtime/Graphics/Shaders/CAABoxShader.hpp index 33b5ac27c..d81511301 100644 --- a/Runtime/Graphics/Shaders/CAABoxShader.hpp +++ b/Runtime/Graphics/Shaders/CAABoxShader.hpp @@ -1,7 +1,7 @@ #ifndef __URDE_CAABOXSHADER_HPP__ #define __URDE_CAABOXSHADER_HPP__ -#include "TShader.hpp" +#include "boo/graphicsdev/IGraphicsDataFactory.hpp" #include "zeus/CMatrix4f.hpp" #include "zeus/CColor.hpp" #include "zeus/CAABox.hpp" @@ -11,11 +11,6 @@ namespace urde class CAABoxShader { - friend struct CAABoxShaderGLDataBindingFactory; - friend struct CAABoxShaderVulkanDataBindingFactory; - friend struct CAABoxShaderMetalDataBindingFactory; - friend struct CAABoxShaderD3DDataBindingFactory; - struct Uniform { zeus::CMatrix4f m_xf; @@ -25,15 +20,13 @@ class CAABoxShader boo::ObjToken m_uniBuf; boo::ObjToken m_dataBind; Uniform m_uniform; - bool m_zOnly; public: + static void Initialize(); + static void Shutdown(); CAABoxShader(bool zOnly); void setAABB(const zeus::CAABox& aabb); void draw(const zeus::CColor& color); - - using _CLS = CAABoxShader; -#include "TShaderDecl.hpp" }; } diff --git a/Runtime/Graphics/Shaders/CAABoxShaderGLSL.cpp b/Runtime/Graphics/Shaders/CAABoxShaderGLSL.cpp deleted file mode 100644 index 86d020978..000000000 --- a/Runtime/Graphics/Shaders/CAABoxShaderGLSL.cpp +++ /dev/null @@ -1,132 +0,0 @@ -#include "CAABoxShader.hpp" -#include "Graphics/CBooRenderer.hpp" - -namespace urde -{ - -static const char* VS = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"layout(location=0) in vec4 posIn;\n" -"\n" -"UBINDING0 uniform CAABoxUniform\n" -"{\n" -" mat4 xf;\n" -" vec4 color;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -"};\n" -"\n" -"SBINDING(0) out VertToFrag vtf;\n" -"void main()\n" -"{\n" -" vtf.color = color;\n" -" gl_Position = xf * vec4(posIn.xyz, 1.0);\n" -"}\n"; - -static const char* FS = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -"};\n" -"\n" -"SBINDING(0) in VertToFrag vtf;\n" -"layout(location=0) out vec4 colorOut;\n" -"void main()\n" -"{\n" -" colorOut = vtf.color;\n" -"}\n"; - -URDE_DECL_SPECIALIZE_SHADER(CAABoxShader) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_Pipeline; -static boo::ObjToken s_zOnlyPipeline; - -struct CAABoxShaderGLDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CAABoxShader& filter) - { - boo::GLDataFactory::Context& cctx = static_cast(ctx); - - const boo::VertexElementDescriptor VtxVmt[] = - { - {filter.m_vbo.get(), nullptr, boo::VertexSemantic::Position4}, - }; - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; - return cctx.newShaderDataBinding(filter.m_zOnly ? s_zOnlyPipeline : s_Pipeline, - ctx.newVertexFormat(1, VtxVmt), filter.m_vbo.get(), nullptr, nullptr, - 1, bufs, stages, nullptr, nullptr, 0, nullptr, nullptr, nullptr); - } -}; - -#if BOO_HAS_VULKAN -struct CAABoxShaderVulkanDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken - BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CAABoxShader& filter) - { - boo::VulkanDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - return cctx.newShaderDataBinding(filter.m_zOnly ? s_zOnlyPipeline : s_Pipeline, s_VtxFmt, - filter.m_vbo.get(), nullptr, nullptr, 1, bufs, - nullptr, nullptr, nullptr, 0, nullptr, nullptr, nullptr); - } -}; -#endif - -TShader::IDataBindingFactory* CAABoxShader::Initialize(boo::GLDataFactory::Context& ctx) -{ - const char* uniNames[] = {"CAABoxUniform"}; - s_Pipeline = ctx.newShaderPipeline(VS, FS, 0, nullptr, 1, uniNames, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::LEqual, true, true, false, boo::CullMode::None); - s_zOnlyPipeline = ctx.newShaderPipeline(VS, FS, 0, nullptr, 1, uniNames, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::LEqual, true, false, false, boo::CullMode::None); - return new CAABoxShaderGLDataBindingFactory; -} - -template <> -void CAABoxShader::Shutdown() -{ - s_Pipeline.reset(); - s_zOnlyPipeline.reset(); -} - -#if BOO_HAS_VULKAN -TShader::IDataBindingFactory* CAABoxShader::Initialize(boo::VulkanDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - }; - s_VtxFmt = ctx.newVertexFormat(1, VtxVmt); - s_Pipeline = ctx.newShaderPipeline(VS, FS, s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::LEqual, true, true, false, boo::CullMode::None); - s_zOnlyPipeline = ctx.newShaderPipeline(VS, FS, s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::LEqual, true, false, false, boo::CullMode::None); - return new CAABoxShaderVulkanDataBindingFactory; -} - -template <> -void CAABoxShader::Shutdown() -{ - s_VtxFmt.reset(); - s_Pipeline.reset(); - s_zOnlyPipeline.reset(); -} -#endif - -} diff --git a/Runtime/Graphics/Shaders/CAABoxShaderHLSL.cpp b/Runtime/Graphics/Shaders/CAABoxShaderHLSL.cpp deleted file mode 100644 index bbc83dd0d..000000000 --- a/Runtime/Graphics/Shaders/CAABoxShaderHLSL.cpp +++ /dev/null @@ -1,90 +0,0 @@ -#include "CAABoxShader.hpp" -#include "Graphics/CBooRenderer.hpp" - -namespace urde -{ - -static const char* VS = -"struct VertData\n" -"{\n" -" float4 posIn : POSITION;\n" -"};\n" -"\n" -"cbuffer CAABoxUniform : register(b0)\n" -"{\n" -" float4x4 xf;\n" -" float4 color;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 pos : SV_Position;\n" -" float4 color : COLOR;\n" -"};\n" -"\n" -"VertToFrag main(in VertData v)\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.color = color;\n" -" vtf.pos = mul(xf, float4(v.posIn.xyz, 1.0));\n" -" return vtf;\n" -"}\n"; - -static const char* FS = -"struct VertToFrag\n" -"{\n" -" float4 pos : SV_Position;\n" -" float4 color : COLOR;\n" -"};\n" -"\n" -"float4 main(in VertToFrag vtf) : SV_Target0\n" -"{\n" -" return vtf.color;\n" -"}\n"; - -URDE_DECL_SPECIALIZE_SHADER(CAABoxShader) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_Pipeline; -static boo::ObjToken s_zOnlyPipeline; - -struct CAABoxShaderD3DDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken - BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CAABoxShader& filter) - { - boo::D3DDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - return cctx.newShaderDataBinding(filter.m_zOnly ? s_zOnlyPipeline : s_Pipeline, s_VtxFmt, - filter.m_vbo.get(), nullptr, nullptr, 1, bufs, - nullptr, nullptr, nullptr, 0, nullptr, nullptr, nullptr); - } -}; - -TShader::IDataBindingFactory* CAABoxShader::Initialize(boo::D3DDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - }; - s_VtxFmt = ctx.newVertexFormat(1, VtxVmt); - s_Pipeline = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, nullptr, s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::LEqual, true, true, false, boo::CullMode::None); - s_zOnlyPipeline = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, nullptr, s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::LEqual, true, false, false, boo::CullMode::None); - return new CAABoxShaderD3DDataBindingFactory; -} - -template <> -void CAABoxShader::Shutdown() -{ - s_VtxFmt.reset(); - s_Pipeline.reset(); - s_zOnlyPipeline.reset(); -} - -} diff --git a/Runtime/Graphics/Shaders/CAABoxShaderMetal.cpp b/Runtime/Graphics/Shaders/CAABoxShaderMetal.cpp deleted file mode 100644 index 0a6f62b05..000000000 --- a/Runtime/Graphics/Shaders/CAABoxShaderMetal.cpp +++ /dev/null @@ -1,95 +0,0 @@ -#include "CAABoxShader.hpp" -#include "Graphics/CBooRenderer.hpp" - -namespace urde -{ - -static const char* VS = -"#include \n" -"using namespace metal;\n" -"struct VertData\n" -"{\n" -" float4 posIn [[ attribute(0) ]];\n" -"};\n" -"\n" -"struct CAABoxUniform\n" -"{\n" -" float4x4 xf;\n" -" float4 color;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 pos [[ position ]];\n" -" float4 color;\n" -"};\n" -"\n" -"vertex VertToFrag vmain(VertData v [[ stage_in ]], constant CAABoxUniform& bu [[ buffer(2) ]])\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.color = bu.color;\n" -" vtf.pos = bu.xf * float4(v.posIn.xyz, 1.0);\n" -" return vtf;\n" -"}\n"; - -static const char* FS = -"#include \n" -"using namespace metal;\n" -"struct VertToFrag\n" -"{\n" -" float4 pos [[ position ]];\n" -" float4 color;\n" -"};\n" -"\n" -"fragment float4 fmain(VertToFrag vtf [[ stage_in ]])\n" -"{\n" -" return vtf.color;\n" -"}\n"; - -URDE_DECL_SPECIALIZE_SHADER(CAABoxShader) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_Pipeline; -static boo::ObjToken s_zOnlyPipeline; - -struct CAABoxShaderMetalDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CAABoxShader& filter) - { - boo::MetalDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - return cctx.newShaderDataBinding(filter.m_zOnly ? s_zOnlyPipeline : s_Pipeline, s_VtxFmt, - filter.m_vbo.get(), nullptr, nullptr, 1, bufs, - nullptr, nullptr, nullptr, 0, nullptr, nullptr, nullptr); - } -}; - -TShader::IDataBindingFactory* CAABoxShader::Initialize(boo::MetalDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - }; - s_VtxFmt = ctx.newVertexFormat(1, VtxVmt); - s_Pipeline = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, - s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::LEqual, true, true, false, boo::CullMode::None); - s_zOnlyPipeline = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, - s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::LEqual, true, false, false, boo::CullMode::None); - return new CAABoxShaderMetalDataBindingFactory; -} - -template <> -void CAABoxShader::Shutdown() -{ - s_VtxFmt.reset(); - s_Pipeline.reset(); - s_zOnlyPipeline.reset(); -} - -} diff --git a/Runtime/Graphics/Shaders/CCameraBlurFilter.cpp b/Runtime/Graphics/Shaders/CCameraBlurFilter.cpp index c90afccbc..790eefbc7 100644 --- a/Runtime/Graphics/Shaders/CCameraBlurFilter.cpp +++ b/Runtime/Graphics/Shaders/CCameraBlurFilter.cpp @@ -1,15 +1,33 @@ #include "CCameraBlurFilter.hpp" +#include "hecl/Pipeline.hpp" +#include "Graphics/CGraphics.hpp" namespace urde { +static boo::ObjToken s_Pipeline; + +void CCameraBlurFilter::Initialize() +{ + s_Pipeline = hecl::conv->convert(Shader_CCameraBlurFilter{}); +} + +void CCameraBlurFilter::Shutdown() +{ + s_Pipeline.reset(); +} + CCameraBlurFilter::CCameraBlurFilter() { - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) + CGraphics::CommitResources([this](boo::IGraphicsDataFactory::Context& ctx) { m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, 32, 4); m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); - m_dataBind = TShader::BuildShaderDataBinding(ctx, *this); + boo::ObjToken bufs[] = {m_uniBuf.get()}; + boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; + boo::ObjToken texs[] = {CGraphics::g_SpareTexture.get()}; + m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, + 1, bufs, stages, nullptr, nullptr, 1, texs, nullptr, nullptr); return true; } BooTrace); } @@ -59,6 +77,4 @@ void CCameraBlurFilter::draw(float amount, bool clearDepth) CGraphics::DrawArray(0, 4); } -URDE_SPECIALIZE_SHADER(CCameraBlurFilter) - } diff --git a/Runtime/Graphics/Shaders/CCameraBlurFilter.hpp b/Runtime/Graphics/Shaders/CCameraBlurFilter.hpp index 18bd54cb3..0f260ac01 100644 --- a/Runtime/Graphics/Shaders/CCameraBlurFilter.hpp +++ b/Runtime/Graphics/Shaders/CCameraBlurFilter.hpp @@ -1,7 +1,7 @@ #ifndef __URDE_CCAMERABLURFILTER_HPP__ #define __URDE_CCAMERABLURFILTER_HPP__ -#include "TShader.hpp" +#include "boo/graphicsdev/IGraphicsDataFactory.hpp" #include "zeus/CMatrix4f.hpp" #include "zeus/CColor.hpp" @@ -10,11 +10,6 @@ namespace urde class CCameraBlurFilter { - friend struct CCameraBlurFilterGLDataBindingFactory; - friend struct CCameraBlurFilterVulkanDataBindingFactory; - friend struct CCameraBlurFilterMetalDataBindingFactory; - friend struct CCameraBlurFilterD3DDataBindingFactory; - struct Vert { zeus::CVector2f m_pos; @@ -32,11 +27,10 @@ class CCameraBlurFilter Uniform m_uniform; public: + static void Initialize(); + static void Shutdown(); CCameraBlurFilter(); void draw(float amount, bool clearDepth=false); - - using _CLS = CCameraBlurFilter; -#include "TShaderDecl.hpp" }; } diff --git a/Runtime/Graphics/Shaders/CCameraBlurFilterGLSL.cpp b/Runtime/Graphics/Shaders/CCameraBlurFilterGLSL.cpp deleted file mode 100644 index 30e940cc0..000000000 --- a/Runtime/Graphics/Shaders/CCameraBlurFilterGLSL.cpp +++ /dev/null @@ -1,163 +0,0 @@ -#include "CCameraBlurFilter.hpp" -#include "Graphics/CBooRenderer.hpp" - -namespace urde -{ - -static const char* VS = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"layout(location=0) in vec4 posIn;\n" -"layout(location=1) in vec4 uvIn;\n" -"\n" -"UBINDING0 uniform CameraBlurUniform\n" -"{\n" -" vec4 uv0;\n" -" vec4 uv1;\n" -" vec4 uv2;\n" -" vec4 uv3;\n" -" vec4 uv4;\n" -" vec4 uv5;\n" -" float opacity;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" vec2 uvReg;\n" -" vec2 uv0;\n" -" vec2 uv1;\n" -" vec2 uv2;\n" -" vec2 uv3;\n" -" vec2 uv4;\n" -" vec2 uv5;\n" -" float opacity;\n" -"};\n" -"\n" -"SBINDING(0) out VertToFrag vtf;\n" -"void main()\n" -"{\n" -" vtf.uvReg = uvIn.xy;\n" -" vtf.uv0 = uv0.xy + uvIn.xy;\n" -" vtf.uv1 = uv1.xy + uvIn.xy;\n" -" vtf.uv2 = uv2.xy + uvIn.xy;\n" -" vtf.uv3 = uv3.xy + uvIn.xy;\n" -" vtf.uv4 = uv4.xy + uvIn.xy;\n" -" vtf.uv5 = uv5.xy + uvIn.xy;\n" -" vtf.opacity = opacity;\n" -" gl_Position = vec4(posIn.xyz, 1.0);\n" -"}\n"; - -static const char* FS = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"struct VertToFrag\n" -"{\n" -" vec2 uvReg;\n" -" vec2 uv0;\n" -" vec2 uv1;\n" -" vec2 uv2;\n" -" vec2 uv3;\n" -" vec2 uv4;\n" -" vec2 uv5;\n" -" float opacity;\n" -"};\n" -"\n" -"SBINDING(0) in VertToFrag vtf;\n" -"layout(location=0) out vec4 colorOut;\n" -"TBINDING0 uniform sampler2D sceneTex;\n" -"void main()\n" -"{\n" -" vec4 colorSample = texture(sceneTex, vtf.uvReg) * 0.14285715;\n" -" colorSample += texture(sceneTex, vtf.uv0) * 0.14285715;\n" -" colorSample += texture(sceneTex, vtf.uv1) * 0.14285715;\n" -" colorSample += texture(sceneTex, vtf.uv2) * 0.14285715;\n" -" colorSample += texture(sceneTex, vtf.uv3) * 0.14285715;\n" -" colorSample += texture(sceneTex, vtf.uv4) * 0.14285715;\n" -" colorSample += texture(sceneTex, vtf.uv5) * 0.14285715;\n" -" colorOut = vec4(colorSample.rgb, vtf.opacity);\n" -"}\n"; - -URDE_DECL_SPECIALIZE_SHADER(CCameraBlurFilter) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_Pipeline; - -struct CCameraBlurFilterGLDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CCameraBlurFilter& filter) - { - boo::GLDataFactory::Context& cctx = static_cast(ctx); - - const boo::VertexElementDescriptor VtxVmt[] = - { - {filter.m_vbo.get(), nullptr, boo::VertexSemantic::Position4}, - {filter.m_vbo.get(), nullptr, boo::VertexSemantic::UV4} - }; - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; - boo::ObjToken texs[] = {CGraphics::g_SpareTexture.get()}; - return cctx.newShaderDataBinding(s_Pipeline, - ctx.newVertexFormat(2, VtxVmt), filter.m_vbo.get(), nullptr, nullptr, - 1, bufs, stages, nullptr, nullptr, 1, texs, nullptr, nullptr); - } -}; - -#if BOO_HAS_VULKAN -struct CCameraBlurFilterVulkanDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken - BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CCameraBlurFilter& filter) - { - boo::VulkanDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - boo::ObjToken texs[] = {CGraphics::g_SpareTexture.get()}; - return cctx.newShaderDataBinding(s_Pipeline, s_VtxFmt, - filter.m_vbo.get(), nullptr, nullptr, 1, bufs, - nullptr, nullptr, nullptr, 1, texs, nullptr, nullptr); - } -}; -#endif - -TShader::IDataBindingFactory* CCameraBlurFilter::Initialize(boo::GLDataFactory::Context& ctx) -{ - const char* texNames[] = {"sceneTex"}; - const char* uniNames[] = {"CameraBlurUniform"}; - s_Pipeline = ctx.newShaderPipeline(VS, FS, 1, texNames, 1, uniNames, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - return new CCameraBlurFilterGLDataBindingFactory; -} - -template <> -void CCameraBlurFilter::Shutdown() -{ - s_Pipeline.reset(); -} - -#if BOO_HAS_VULKAN -TShader::IDataBindingFactory* CCameraBlurFilter::Initialize(boo::VulkanDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::UV4} - }; - s_VtxFmt = ctx.newVertexFormat(2, VtxVmt); - s_Pipeline = ctx.newShaderPipeline(VS, FS, s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - return new CCameraBlurFilterVulkanDataBindingFactory; -} - -template <> -void CCameraBlurFilter::Shutdown() -{ - s_VtxFmt.reset(); - s_Pipeline.reset(); -} -#endif - -} diff --git a/Runtime/Graphics/Shaders/CCameraBlurFilterHLSL.cpp b/Runtime/Graphics/Shaders/CCameraBlurFilterHLSL.cpp deleted file mode 100644 index 46d3d97b3..000000000 --- a/Runtime/Graphics/Shaders/CCameraBlurFilterHLSL.cpp +++ /dev/null @@ -1,131 +0,0 @@ -#include "CCameraBlurFilter.hpp" -#include "Graphics/CBooRenderer.hpp" - -namespace urde -{ - -static const char* VS = -"struct VertData\n" -"{\n" -" float4 posIn : POSITION;\n" -" float4 uvIn : UV;\n" -"};\n" -"\n" -"cbuffer CameraBlurUniform : register(b0)\n" -"{\n" -" float4 uv0;\n" -" float4 uv1;\n" -" float4 uv2;\n" -" float4 uv3;\n" -" float4 uv4;\n" -" float4 uv5;\n" -" float opacity;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float2 uvReg : UV6;\n" -" float2 uv0 : UV0;\n" -" float2 uv1 : UV1;\n" -" float2 uv2 : UV2;\n" -" float2 uv3 : UV3;\n" -" float2 uv4 : UV4;\n" -" float2 uv5 : UV5;\n" -" float opacity : OPACITY;\n" -"};\n" -"\n" -"VertToFrag main(in VertData v)\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.uvReg = v.uvIn.xy;\n" -" vtf.uvReg.y = 1.0 - vtf.uvReg.y;\n" -" vtf.uv0 = uv0.xy + v.uvIn.xy;\n" -" vtf.uv0.y = 1.0 - vtf.uv0.y;\n" -" vtf.uv1 = uv1.xy + v.uvIn.xy;\n" -" vtf.uv1.y = 1.0 - vtf.uv1.y;\n" -" vtf.uv2 = uv2.xy + v.uvIn.xy;\n" -" vtf.uv2.y = 1.0 - vtf.uv2.y;\n" -" vtf.uv3 = uv3.xy + v.uvIn.xy;\n" -" vtf.uv3.y = 1.0 - vtf.uv3.y;\n" -" vtf.uv4 = uv4.xy + v.uvIn.xy;\n" -" vtf.uv4.y = 1.0 - vtf.uv4.y;\n" -" vtf.uv5 = uv5.xy + v.uvIn.xy;\n" -" vtf.uv5.y = 1.0 - vtf.uv5.y;\n" -" vtf.opacity = opacity;\n" -" vtf.position = float4(v.posIn.xyz, 1.0);\n" -" return vtf;\n" -"}\n"; - -static const char* FS = -"Texture2D sceneTex : register(t0);\n" -"SamplerState samp : register(s0);\n" -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float2 uvReg : UV6;\n" -" float2 uv0 : UV0;\n" -" float2 uv1 : UV1;\n" -" float2 uv2 : UV2;\n" -" float2 uv3 : UV3;\n" -" float2 uv4 : UV4;\n" -" float2 uv5 : UV5;\n" -" float opacity : OPACITY;\n" -"};\n" -"\n" -"float4 main(in VertToFrag vtf) : SV_Target0\n" -"{\n" -" float4 colorSample = sceneTex.Sample(samp, vtf.uvReg) * 0.14285715;\n" -" colorSample += sceneTex.Sample(samp, vtf.uv0) * 0.14285715;\n" -" colorSample += sceneTex.Sample(samp, vtf.uv1) * 0.14285715;\n" -" colorSample += sceneTex.Sample(samp, vtf.uv2) * 0.14285715;\n" -" colorSample += sceneTex.Sample(samp, vtf.uv3) * 0.14285715;\n" -" colorSample += sceneTex.Sample(samp, vtf.uv4) * 0.14285715;\n" -" colorSample += sceneTex.Sample(samp, vtf.uv5) * 0.14285715;\n" -" return float4(colorSample.rgb, vtf.opacity);\n" -"}\n"; - -URDE_DECL_SPECIALIZE_SHADER(CCameraBlurFilter) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_Pipeline; - -struct CCameraBlurFilterD3DDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken - BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CCameraBlurFilter& filter) - { - boo::D3DDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - boo::ObjToken texs[] = {CGraphics::g_SpareTexture.get()}; - return cctx.newShaderDataBinding(s_Pipeline, s_VtxFmt, - filter.m_vbo.get(), nullptr, nullptr, 1, bufs, - nullptr, nullptr, nullptr, 1, texs, nullptr, nullptr); - } -}; - -TShader::IDataBindingFactory* CCameraBlurFilter::Initialize(boo::D3DDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::UV4} - }; - s_VtxFmt = ctx.newVertexFormat(2, VtxVmt); - s_Pipeline = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, nullptr, - s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - return new CCameraBlurFilterD3DDataBindingFactory; -} - -template <> -void CCameraBlurFilter::Shutdown() -{ - s_VtxFmt.reset(); - s_Pipeline.reset(); -} - -} diff --git a/Runtime/Graphics/Shaders/CCameraBlurFilterMetal.cpp b/Runtime/Graphics/Shaders/CCameraBlurFilterMetal.cpp deleted file mode 100644 index a21a78dca..000000000 --- a/Runtime/Graphics/Shaders/CCameraBlurFilterMetal.cpp +++ /dev/null @@ -1,133 +0,0 @@ -#include "CCameraBlurFilter.hpp" -#include "Graphics/CBooRenderer.hpp" - -namespace urde -{ - -static const char* VS = -"#include \n" -"using namespace metal;\n" -"struct VertData\n" -"{\n" -" float4 posIn [[ attribute(0) ]];\n" -" float4 uvIn [[ attribute(1) ]];\n" -"};\n" -"\n" -"struct CameraBlurUniform\n" -"{\n" -" float4 uv0;\n" -" float4 uv1;\n" -" float4 uv2;\n" -" float4 uv3;\n" -" float4 uv4;\n" -" float4 uv5;\n" -" float opacity;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float2 uvReg;\n" -" float2 uv0;\n" -" float2 uv1;\n" -" float2 uv2;\n" -" float2 uv3;\n" -" float2 uv4;\n" -" float2 uv5;\n" -" float opacity;\n" -"};\n" -"\n" -"vertex VertToFrag vmain(VertData v [[ stage_in ]], constant CameraBlurUniform& cbu [[ buffer(2) ]])\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.uvReg = v.uvIn.xy;\n" -" vtf.uvReg.y = 1.0 - vtf.uvReg.y;\n" -" vtf.uv0 = cbu.uv0.xy + v.uvIn.xy;\n" -" vtf.uv0.y = 1.0 - vtf.uv0.y;\n" -" vtf.uv1 = cbu.uv1.xy + v.uvIn.xy;\n" -" vtf.uv1.y = 1.0 - vtf.uv1.y;\n" -" vtf.uv2 = cbu.uv2.xy + v.uvIn.xy;\n" -" vtf.uv2.y = 1.0 - vtf.uv2.y;\n" -" vtf.uv3 = cbu.uv3.xy + v.uvIn.xy;\n" -" vtf.uv3.y = 1.0 - vtf.uv3.y;\n" -" vtf.uv4 = cbu.uv4.xy + v.uvIn.xy;\n" -" vtf.uv4.y = 1.0 - vtf.uv4.y;\n" -" vtf.uv5 = cbu.uv5.xy + v.uvIn.xy;\n" -" vtf.uv5.y = 1.0 - vtf.uv5.y;\n" -" vtf.opacity = cbu.opacity;\n" -" vtf.position = float4(v.posIn.xyz, 1.0);\n" -" return vtf;\n" -"}\n"; - -static const char* FS = -"#include \n" -"using namespace metal;\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float2 uvReg;\n" -" float2 uv0;\n" -" float2 uv1;\n" -" float2 uv2;\n" -" float2 uv3;\n" -" float2 uv4;\n" -" float2 uv5;\n" -" float opacity;\n" -"};\n" -"\n" -"fragment float4 fmain(VertToFrag vtf [[ stage_in ]], sampler samp [[ sampler(0) ]],\n" -" texture2d sceneTex [[ texture(0) ]])\n" -"{\n" -" float4 colorSample = sceneTex.sample(samp, vtf.uvReg) * 0.14285715;\n" -" colorSample += sceneTex.sample(samp, vtf.uv0) * 0.14285715;\n" -" colorSample += sceneTex.sample(samp, vtf.uv1) * 0.14285715;\n" -" colorSample += sceneTex.sample(samp, vtf.uv2) * 0.14285715;\n" -" colorSample += sceneTex.sample(samp, vtf.uv3) * 0.14285715;\n" -" colorSample += sceneTex.sample(samp, vtf.uv4) * 0.14285715;\n" -" colorSample += sceneTex.sample(samp, vtf.uv5) * 0.14285715;\n" -" return float4(colorSample.rgb, vtf.opacity);\n" -"}\n"; - -URDE_DECL_SPECIALIZE_SHADER(CCameraBlurFilter) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_Pipeline; - -struct CCameraBlurFilterMetalDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CCameraBlurFilter& filter) - { - boo::MetalDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - boo::ObjToken texs[] = {CGraphics::g_SpareTexture.get()}; - return cctx.newShaderDataBinding(s_Pipeline, s_VtxFmt, - filter.m_vbo.get(), nullptr, nullptr, 1, bufs, - nullptr, nullptr, nullptr, 1, texs, nullptr, nullptr); - } -}; - -TShader::IDataBindingFactory* CCameraBlurFilter::Initialize(boo::MetalDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::UV4} - }; - s_VtxFmt = ctx.newVertexFormat(2, VtxVmt); - s_Pipeline = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, - s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - return new CCameraBlurFilterMetalDataBindingFactory; -} - -template <> -void CCameraBlurFilter::Shutdown() -{ - s_VtxFmt.reset(); - s_Pipeline.reset(); -} - -} diff --git a/Runtime/Graphics/Shaders/CColoredQuadFilter.cpp b/Runtime/Graphics/Shaders/CColoredQuadFilter.cpp index 3e32bf650..4cfb6c861 100644 --- a/Runtime/Graphics/Shaders/CColoredQuadFilter.cpp +++ b/Runtime/Graphics/Shaders/CColoredQuadFilter.cpp @@ -1,11 +1,46 @@ #include "CColoredQuadFilter.hpp" +#include "Graphics/CGraphics.hpp" +#include "hecl/Pipeline.hpp" namespace urde { +static boo::ObjToken s_AlphaPipeline; +static boo::ObjToken s_AddPipeline; +static boo::ObjToken s_MultPipeline; + +void CColoredQuadFilter::Initialize() +{ + s_AlphaPipeline = hecl::conv->convert(Shader_CColoredQuadFilter{}); + s_AddPipeline = hecl::conv->convert(Shader_CColoredQuadFilterAdd{}); + s_MultPipeline = hecl::conv->convert(Shader_CColoredQuadFilterMul{}); +} + +void CColoredQuadFilter::Shutdown() +{ + s_AlphaPipeline.reset(); + s_AddPipeline.reset(); + s_MultPipeline.reset(); +} + +static boo::ObjToken SelectPipeline(EFilterType type) +{ + switch (type) + { + case EFilterType::Blend: + return s_AlphaPipeline; + case EFilterType::Add: + return s_AddPipeline; + case EFilterType::Multiply: + return s_MultPipeline; + default: + return {}; + } +} + CColoredQuadFilter::CColoredQuadFilter(EFilterType type) { - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) + CGraphics::CommitResources([this, type](boo::IGraphicsDataFactory::Context& ctx) { struct Vert { @@ -19,7 +54,10 @@ CColoredQuadFilter::CColoredQuadFilter(EFilterType type) }; m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts, 16, 4); m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); - m_dataBind = TMultiBlendShader::BuildShaderDataBinding(ctx, type, *this); + boo::ObjToken bufs[] = {m_uniBuf.get()}; + boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; + m_dataBind = ctx.newShaderDataBinding(SelectPipeline(type), m_vbo.get(), nullptr, nullptr, + 1, bufs, stages, nullptr, nullptr, 0, nullptr, nullptr, nullptr); return true; } BooTrace); } @@ -90,6 +128,4 @@ void CWideScreenFilter::SetViewportToFull() const zeus::CRectangle CColoredQuadFilter::DefaultRect = {0.f, 0.f, 1.f, 1.f}; -URDE_SPECIALIZE_MULTI_BLEND_SHADER(CColoredQuadFilter) - } diff --git a/Runtime/Graphics/Shaders/CColoredQuadFilter.hpp b/Runtime/Graphics/Shaders/CColoredQuadFilter.hpp index f1fe5a2fd..c84e6dc47 100644 --- a/Runtime/Graphics/Shaders/CColoredQuadFilter.hpp +++ b/Runtime/Graphics/Shaders/CColoredQuadFilter.hpp @@ -1,7 +1,6 @@ #ifndef __URDE_CCOLOREDQUADFILTER_HPP__ #define __URDE_CCOLOREDQUADFILTER_HPP__ -#include "TMultiBlendShader.hpp" #include "zeus/CMatrix4f.hpp" #include "zeus/CColor.hpp" #include "zeus/CRectangle.hpp" @@ -12,11 +11,6 @@ namespace urde class CColoredQuadFilter { - friend struct CColoredQuadFilterGLDataBindingFactory; - friend struct CColoredQuadFilterVulkanDataBindingFactory; - friend struct CColoredQuadFilterMetalDataBindingFactory; - friend struct CColoredQuadFilterD3DDataBindingFactory; - struct Uniform { zeus::CMatrix4f m_matrix; @@ -28,15 +22,14 @@ class CColoredQuadFilter Uniform m_uniform; public: + static void Initialize(); + static void Shutdown(); static const zeus::CRectangle DefaultRect; CColoredQuadFilter(EFilterType type); CColoredQuadFilter(EFilterType type, const TLockedToken&) : CColoredQuadFilter(type) {} void draw(const zeus::CColor& color, const zeus::CRectangle& rect=DefaultRect); void DrawFilter(EFilterShape shape, const zeus::CColor& color, float t) { draw(color); } - - using _CLS = CColoredQuadFilter; -#include "TMultiBlendShaderDecl.hpp" }; class CWideScreenFilter diff --git a/Runtime/Graphics/Shaders/CColoredQuadFilterGLSL.cpp b/Runtime/Graphics/Shaders/CColoredQuadFilterGLSL.cpp deleted file mode 100644 index 833fa84bd..000000000 --- a/Runtime/Graphics/Shaders/CColoredQuadFilterGLSL.cpp +++ /dev/null @@ -1,157 +0,0 @@ -#include "CColoredQuadFilter.hpp" - -namespace urde -{ - -static const char* VS = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"layout(location=0) in vec4 posIn;\n" -"\n" -"UBINDING0 uniform ColoredQuadUniform\n" -"{\n" -" mat4 xf;\n" -" vec4 color;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -"};\n" -"\n" -"SBINDING(0) out VertToFrag vtf;\n" -"void main()\n" -"{\n" -" vtf.color = color;\n" -" gl_Position = xf * vec4(posIn.xyz, 1.0);\n" -"}\n"; - -static const char* FS = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -"};\n" -"\n" -"SBINDING(0) in VertToFrag vtf;\n" -"layout(location=0) out vec4 colorOut;\n" -"void main()\n" -"{\n" -" colorOut = vtf.color;\n" -"}\n"; - -URDE_DECL_SPECIALIZE_MULTI_BLEND_SHADER(CColoredQuadFilter) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_AlphaPipeline; -static boo::ObjToken s_AddPipeline; -static boo::ObjToken s_MultPipeline; - -static boo::ObjToken SelectPipeline(EFilterType type) -{ - switch (type) - { - case EFilterType::Blend: - return s_AlphaPipeline; - case EFilterType::Add: - return s_AddPipeline; - case EFilterType::Multiply: - return s_MultPipeline; - default: - return {}; - } -} - -struct CColoredQuadFilterGLDataBindingFactory : TMultiBlendShader::IDataBindingFactory -{ - boo::ObjToken BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - EFilterType type, CColoredQuadFilter& filter) - { - boo::GLDataFactory::Context& cctx = static_cast(ctx); - - const boo::VertexElementDescriptor VtxVmt[] = - { - {filter.m_vbo.get(), nullptr, boo::VertexSemantic::Position4} - }; - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; - return cctx.newShaderDataBinding(SelectPipeline(type), - ctx.newVertexFormat(1, VtxVmt), filter.m_vbo.get(), nullptr, nullptr, - 1, bufs, stages, nullptr, nullptr, 0, nullptr, nullptr, nullptr); - } -}; - -#if BOO_HAS_VULKAN -struct CColoredQuadFilterVulkanDataBindingFactory : TMultiBlendShader::IDataBindingFactory -{ - boo::ObjToken - BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - EFilterType type, CColoredQuadFilter& filter) - { - boo::VulkanDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - return cctx.newShaderDataBinding(SelectPipeline(type), s_VtxFmt, - filter.m_vbo.get(), nullptr, nullptr, 1, bufs, - nullptr, nullptr, nullptr, 0, nullptr, nullptr, nullptr); - } -}; -#endif - -TMultiBlendShader::IDataBindingFactory* -CColoredQuadFilter::Initialize(boo::GLDataFactory::Context& ctx) -{ - const char* uniNames[] = {"ColoredQuadUniform"}; - s_AlphaPipeline = ctx.newShaderPipeline(VS, FS, 0, nullptr, 1, uniNames, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_AddPipeline = ctx.newShaderPipeline(VS, FS, 0, nullptr, 1, uniNames, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_MultPipeline = ctx.newShaderPipeline(VS, FS, 0, nullptr, 1, uniNames, boo::BlendFactor::Zero, - boo::BlendFactor::SrcColor, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - return new CColoredQuadFilterGLDataBindingFactory; -} - -template <> -void CColoredQuadFilter::Shutdown() -{ - s_AlphaPipeline.reset(); - s_AddPipeline.reset(); - s_MultPipeline.reset(); -} - -#if BOO_HAS_VULKAN -TMultiBlendShader::IDataBindingFactory* -CColoredQuadFilter::Initialize(boo::VulkanDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4} - }; - s_VtxFmt = ctx.newVertexFormat(1, VtxVmt); - s_AlphaPipeline = ctx.newShaderPipeline(VS, FS, s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_AddPipeline = ctx.newShaderPipeline(VS, FS, s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_MultPipeline = ctx.newShaderPipeline(VS, FS, s_VtxFmt, boo::BlendFactor::Zero, - boo::BlendFactor::SrcColor, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - return new CColoredQuadFilterVulkanDataBindingFactory; -} - -template <> -void CColoredQuadFilter::Shutdown() -{ - s_VtxFmt.reset(); - s_AlphaPipeline.reset(); - s_AddPipeline.reset(); - s_MultPipeline.reset(); -} -#endif - -} diff --git a/Runtime/Graphics/Shaders/CColoredQuadFilterHLSL.cpp b/Runtime/Graphics/Shaders/CColoredQuadFilterHLSL.cpp deleted file mode 100644 index 088d06506..000000000 --- a/Runtime/Graphics/Shaders/CColoredQuadFilterHLSL.cpp +++ /dev/null @@ -1,113 +0,0 @@ -#include "CColoredQuadFilter.hpp" - -namespace urde -{ - -static const char* VS = -"struct VertData\n" -"{\n" -" float4 posIn : POSITION;\n" -"};\n" -"\n" -"cbuffer ColoredQuadUniform : register(b0)\n" -"{\n" -" float4x4 xf;\n" -" float4 color;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float4 color : COLOR;\n" -"};\n" -"\n" -"VertToFrag main(in VertData v)\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.color = color;\n" -" vtf.position = mul(xf, float4(v.posIn.xyz, 1.0));\n" -" return vtf;\n" -"}\n"; - -static const char* FS = -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float4 color : COLOR;\n" -"};\n" -"\n" -"float4 main(in VertToFrag vtf) : SV_Target0\n" -"{\n" -" return vtf.color;\n" -"}\n"; - -URDE_DECL_SPECIALIZE_MULTI_BLEND_SHADER(CColoredQuadFilter) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_AlphaPipeline; -static boo::ObjToken s_AddPipeline; -static boo::ObjToken s_MultPipeline; - -static boo::ObjToken SelectPipeline(EFilterType type) -{ - switch (type) - { - case EFilterType::Blend: - return s_AlphaPipeline; - case EFilterType::Add: - return s_AddPipeline; - case EFilterType::Multiply: - return s_MultPipeline; - default: - return {}; - } -} - -struct CColoredQuadFilterD3DDataBindingFactory : TMultiBlendShader::IDataBindingFactory -{ - boo::ObjToken - BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - EFilterType type, CColoredQuadFilter& filter) - { - boo::D3DDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - return cctx.newShaderDataBinding(SelectPipeline(type), s_VtxFmt, - filter.m_vbo.get(), nullptr, nullptr, 1, bufs, - nullptr, nullptr, nullptr, 0, nullptr, nullptr, nullptr); - } -}; - -TMultiBlendShader::IDataBindingFactory* -CColoredQuadFilter::Initialize(boo::D3DDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4} - }; - s_VtxFmt = ctx.newVertexFormat(1, VtxVmt); - s_AlphaPipeline = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, nullptr, - s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_AddPipeline = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, nullptr, - s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_MultPipeline = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, nullptr, - s_VtxFmt, boo::BlendFactor::Zero, - boo::BlendFactor::SrcColor, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - return new CColoredQuadFilterD3DDataBindingFactory; -} - -template <> -void CColoredQuadFilter::Shutdown() -{ - s_VtxFmt.reset(); - s_AlphaPipeline.reset(); - s_AddPipeline.reset(); - s_MultPipeline.reset(); -} - -} diff --git a/Runtime/Graphics/Shaders/CColoredQuadFilterMetal.cpp b/Runtime/Graphics/Shaders/CColoredQuadFilterMetal.cpp deleted file mode 100644 index 3699ee177..000000000 --- a/Runtime/Graphics/Shaders/CColoredQuadFilterMetal.cpp +++ /dev/null @@ -1,116 +0,0 @@ -#include "CColoredQuadFilter.hpp" - -namespace urde -{ - -static const char* VS = -"#include \n" -"using namespace metal;\n" -"struct VertData\n" -"{\n" -" float4 posIn [[ attribute(0) ]];\n" -"};\n" -"\n" -"struct ColoredQuadUniform\n" -"{\n" -" float4x4 xf;\n" -" float4 color;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float4 color;\n" -"};\n" -"\n" -"vertex VertToFrag vmain(VertData v [[ stage_in ]], constant ColoredQuadUniform& cqu [[ buffer(2) ]])\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.color = cqu.color;\n" -" vtf.position = cqu.xf * float4(v.posIn.xyz, 1.0);\n" -" return vtf;\n" -"}\n"; - -static const char* FS = -"#include \n" -"using namespace metal;\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float4 color;\n" -"};\n" -"\n" -"fragment float4 fmain(VertToFrag vtf [[ stage_in ]])\n" -"{\n" -" return vtf.color;\n" -"}\n"; - -URDE_DECL_SPECIALIZE_MULTI_BLEND_SHADER(CColoredQuadFilter) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_AlphaPipeline; -static boo::ObjToken s_AddPipeline; -static boo::ObjToken s_MultPipeline; - -static boo::ObjToken SelectPipeline(EFilterType type) -{ - switch (type) - { - case EFilterType::Blend: - return s_AlphaPipeline; - case EFilterType::Add: - return s_AddPipeline; - case EFilterType::Multiply: - return s_MultPipeline; - default: - return {}; - } -} - -struct CColoredQuadFilterMetalDataBindingFactory : TMultiBlendShader::IDataBindingFactory -{ - boo::ObjToken BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - EFilterType type, CColoredQuadFilter& filter) - { - boo::MetalDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - return cctx.newShaderDataBinding(SelectPipeline(type), s_VtxFmt, - filter.m_vbo.get(), nullptr, nullptr, 1, bufs, - nullptr, nullptr, nullptr, 0, nullptr, nullptr, nullptr); - } -}; - -TMultiBlendShader::IDataBindingFactory* -CColoredQuadFilter::Initialize(boo::MetalDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4} - }; - s_VtxFmt = ctx.newVertexFormat(1, VtxVmt); - s_AlphaPipeline = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, - s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_AddPipeline = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, - s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_MultPipeline = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, - s_VtxFmt, boo::BlendFactor::Zero, - boo::BlendFactor::SrcColor, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - return new CColoredQuadFilterMetalDataBindingFactory; -} - -template <> -void CColoredQuadFilter::Shutdown() -{ - s_VtxFmt.reset(); - s_AlphaPipeline.reset(); - s_AddPipeline.reset(); - s_MultPipeline.reset(); -} - -} diff --git a/Runtime/Graphics/Shaders/CDecalShaders.cpp b/Runtime/Graphics/Shaders/CDecalShaders.cpp index c59d5c4ac..7fe439eeb 100644 --- a/Runtime/Graphics/Shaders/CDecalShaders.cpp +++ b/Runtime/Graphics/Shaders/CDecalShaders.cpp @@ -1,5 +1,6 @@ #include "CDecalShaders.hpp" #include "Particle/CDecal.hpp" +#include "hecl/Pipeline.hpp" namespace urde { @@ -11,8 +12,23 @@ boo::ObjToken CDecalShaders::m_texRedToAlphaZTest; boo::ObjToken CDecalShaders::m_noTexZTestNoZWrite; boo::ObjToken CDecalShaders::m_noTexAdditiveZTest; -boo::ObjToken CDecalShaders::m_vtxFormatTex; -boo::ObjToken CDecalShaders::m_vtxFormatNoTex; +void CDecalShaders::Initialize() +{ + m_texZTestNoZWrite = hecl::conv->convert(Shader_CDecalShaderTexZTest{}); + m_texAdditiveZTest = hecl::conv->convert(Shader_CDecalShaderTexAdditiveZTest{}); + m_texRedToAlphaZTest = hecl::conv->convert(Shader_CDecalShaderTexRedToAlphaZTest{}); + m_noTexZTestNoZWrite = hecl::conv->convert(Shader_CDecalShaderNoTexZTest{}); + m_noTexAdditiveZTest = hecl::conv->convert(Shader_CDecalShaderNoTexAdditiveZTest{}); +} + +void CDecalShaders::Shutdown() +{ + m_texZTestNoZWrite.reset(); + m_texAdditiveZTest.reset(); + m_texRedToAlphaZTest.reset(); + m_noTexZTestNoZWrite.reset(); + m_noTexAdditiveZTest.reset(); +} void CDecalShaders::BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, CQuadDecal& decal) { @@ -35,10 +51,31 @@ void CDecalShaders::BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& c regPipeline = m_noTexZTestNoZWrite; } - CDecalShaders shad(decal, regPipeline, redToAlphaPipeline); - TShader::BuildShaderDataBinding(ctx, shad); + const SQuadDescr* desc = decal.m_desc; + + CUVElement* texr = desc->x14_TEX.get(); + int texCount = 0; + boo::ObjToken textures[1]; + + if (texr) + { + textures[0] = texr->GetValueTexture(0).GetObj()->GetBooTexture(); + texCount = 1; + } + + if (decal.m_instBuf) + { + boo::ObjToken uniforms[] = {decal.m_uniformBuf.get()}; + + if (regPipeline) + decal.m_normalDataBind = ctx.newShaderDataBinding(regPipeline, nullptr, + decal.m_instBuf.get(), nullptr, 1, uniforms, + nullptr, texCount, textures, nullptr, nullptr); + if (redToAlphaPipeline) + decal.m_redToAlphaDataBind = ctx.newShaderDataBinding(redToAlphaPipeline, nullptr, + decal.m_instBuf.get(), nullptr, 1, uniforms, + nullptr, texCount, textures, nullptr, nullptr); + } } -URDE_SPECIALIZE_SHADER(CDecalShaders) - } diff --git a/Runtime/Graphics/Shaders/CDecalShaders.hpp b/Runtime/Graphics/Shaders/CDecalShaders.hpp index 551e2f486..1b1294cca 100644 --- a/Runtime/Graphics/Shaders/CDecalShaders.hpp +++ b/Runtime/Graphics/Shaders/CDecalShaders.hpp @@ -1,12 +1,7 @@ #ifndef __URDE_CDECALSHADERS_HPP__ #define __URDE_CDECALSHADERS_HPP__ -#include "TShader.hpp" #include "Graphics/CGraphics.hpp" -#include "boo/graphicsdev/GL.hpp" -#include "boo/graphicsdev/D3D.hpp" -#include "boo/graphicsdev/Metal.hpp" -#include "boo/graphicsdev/Vulkan.hpp" namespace urde { @@ -14,11 +9,6 @@ struct CQuadDecal; class CDecalShaders { - friend struct OGLDecalDataBindingFactory; - friend struct VulkanDecalDataBindingFactory; - friend struct D3DDecalDataBindingFactory; - friend struct MetalDecalDataBindingFactory; - private: static boo::ObjToken m_texZTestNoZWrite; static boo::ObjToken m_texAdditiveZTest; @@ -27,22 +17,10 @@ private: static boo::ObjToken m_noTexZTestNoZWrite; static boo::ObjToken m_noTexAdditiveZTest; - static boo::ObjToken m_vtxFormatTex; /* No OpenGL */ - static boo::ObjToken m_vtxFormatNoTex; /* No OpenGL */ - - CQuadDecal& m_decal; - boo::ObjToken m_regPipeline; - boo::ObjToken m_redToAlphaPipeline; - CDecalShaders(CQuadDecal& decal, - const boo::ObjToken& regPipeline, - const boo::ObjToken& redToAlphaPipeline) - : m_decal(decal), m_regPipeline(regPipeline), m_redToAlphaPipeline(redToAlphaPipeline) {} - public: + static void Initialize(); + static void Shutdown(); static void BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, CQuadDecal& decal); - - using _CLS = CDecalShaders; -#include "TShaderDecl.hpp" }; } diff --git a/Runtime/Graphics/Shaders/CDecalShadersGLSL.cpp b/Runtime/Graphics/Shaders/CDecalShadersGLSL.cpp deleted file mode 100644 index 2df96246b..000000000 --- a/Runtime/Graphics/Shaders/CDecalShadersGLSL.cpp +++ /dev/null @@ -1,320 +0,0 @@ -#include "CDecalShaders.hpp" -#include "Particle/CDecal.hpp" -#include "Graphics/CModel.hpp" - -namespace urde -{ - -static const char* VS_GLSL_TEX = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"layout(location=0) in vec4 posIn[4];\n" -"layout(location=4) in vec4 colorIn;\n" -"layout(location=5) in vec4 uvsIn[4];\n" -"\n" -"UBINDING0 uniform DecalUniform\n" -"{\n" -" mat4 mvp;\n" -" vec4 moduColor;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -" vec2 uv;\n" -"};\n" -"\n" -"SBINDING(0) out VertToFrag vtf;\n" -"void main()\n" -"{\n" -" vtf.color = colorIn * moduColor;\n" -" vtf.uv = uvsIn[gl_VertexID].xy;\n" -" gl_Position = mvp * posIn[gl_VertexID];\n" -"}\n"; - -static const char* FS_GLSL_TEX = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -" vec2 uv;\n" -"};\n" -"\n" -"SBINDING(0) in VertToFrag vtf;\n" -"layout(location=0) out vec4 colorOut;\n" -"TBINDING0 uniform sampler2D tex;\n" -"void main()\n" -"{\n" -" colorOut = vtf.color * texture(tex, vtf.uv);\n" -"}\n"; - -static const char* FS_GLSL_TEX_REDTOALPHA = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -" vec2 uv;\n" -"};\n" -"\n" -"SBINDING(0) in VertToFrag vtf;\n" -"layout(location=0) out vec4 colorOut;\n" -"TBINDING0 uniform sampler2D tex;\n" -"void main()\n" -"{\n" -" colorOut = vtf.color;\n" -" colorOut.a = texture(tex, vtf.uv).r;\n" -"}\n"; - -static const char* VS_GLSL_NOTEX = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"layout(location=0) in vec4 posIn[4];\n" -"layout(location=4) in vec4 colorIn;\n" -"\n" -"UBINDING0 uniform DecalUniform\n" -"{\n" -" mat4 mvp;\n" -" vec4 moduColor;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -"};\n" -"\n" -"SBINDING(0) out VertToFrag vtf;\n" -"void main()\n" -"{\n" -" vtf.color = colorIn * moduColor;\n" -" gl_Position = mvp * posIn[gl_VertexID];\n" -"}\n"; - -static const char* FS_GLSL_NOTEX = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -"};\n" -"\n" -"SBINDING(0) in VertToFrag vtf;\n" -"layout(location=0) out vec4 colorOut;\n" -"void main()\n" -"{\n" -" colorOut = vtf.color;\n" -"}\n"; - -struct OGLDecalDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CDecalShaders& shaders) - { - CQuadDecal& decal = shaders.m_decal; - const SQuadDescr* desc = decal.m_desc; - - boo::ObjToken vtxFmt; - CUVElement* texr = desc->x14_TEX.get(); - int texCount = 0; - boo::ObjToken textures[1]; - - if (texr) - { - textures[0] = texr->GetValueTexture(0).GetObj()->GetBooTexture(); - texCount = 1; - if (decal.m_instBuf) - { - const boo::VertexElementDescriptor TexFmtTex[] = - { - {decal.m_instBuf.get(), nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 0}, - {decal.m_instBuf.get(), nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 1}, - {decal.m_instBuf.get(), nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 2}, - {decal.m_instBuf.get(), nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 3}, - {decal.m_instBuf.get(), nullptr, boo::VertexSemantic::Color | boo::VertexSemantic::Instanced}, - {decal.m_instBuf.get(), nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 0}, - {decal.m_instBuf.get(), nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 1}, - {decal.m_instBuf.get(), nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 2}, - {decal.m_instBuf.get(), nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 3} - }; - vtxFmt = ctx.newVertexFormat(9, TexFmtTex); - } - } - else - { - if (decal.m_instBuf) - { - const boo::VertexElementDescriptor TexFmtNoTex[] = - { - {decal.m_instBuf.get(), nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 0}, - {decal.m_instBuf.get(), nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 1}, - {decal.m_instBuf.get(), nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 2}, - {decal.m_instBuf.get(), nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 3}, - {decal.m_instBuf.get(), nullptr, boo::VertexSemantic::Color | boo::VertexSemantic::Instanced} - }; - vtxFmt = ctx.newVertexFormat(5, TexFmtNoTex); - } - } - - if (decal.m_instBuf) - { - boo::ObjToken uniforms[] = {decal.m_uniformBuf.get()}; - - if (shaders.m_regPipeline) - decal.m_normalDataBind = ctx.newShaderDataBinding(shaders.m_regPipeline, vtxFmt, nullptr, - decal.m_instBuf.get(), nullptr, 1, uniforms, - nullptr, texCount, textures, nullptr, nullptr); - if (shaders.m_redToAlphaPipeline) - decal.m_redToAlphaDataBind = ctx.newShaderDataBinding(shaders.m_redToAlphaPipeline, vtxFmt, nullptr, - decal.m_instBuf.get(), nullptr, 1, uniforms, - nullptr, texCount, textures, nullptr, nullptr); - } - - return nullptr; - } -}; - -static const char* UniNames[] = {"DecalUniform"}; -static const char* TexNames[] = {"tex"}; - -TShader::IDataBindingFactory* CDecalShaders::Initialize(boo::GLDataFactory::Context& ctx) -{ - m_texZTestNoZWrite = ctx.newShaderPipeline(VS_GLSL_TEX, FS_GLSL_TEX, 1, TexNames, 1, UniNames, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - m_texAdditiveZTest = ctx.newShaderPipeline(VS_GLSL_TEX, FS_GLSL_TEX, 1, TexNames, 1, UniNames, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - m_texRedToAlphaZTest = ctx.newShaderPipeline(VS_GLSL_TEX, FS_GLSL_TEX_REDTOALPHA, 1, TexNames, 1, UniNames, - boo::BlendFactor::One, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, true, boo::CullMode::None); - m_noTexZTestNoZWrite = ctx.newShaderPipeline(VS_GLSL_NOTEX, FS_GLSL_NOTEX, 0, nullptr, 1, UniNames, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - m_noTexAdditiveZTest = ctx.newShaderPipeline(VS_GLSL_NOTEX, FS_GLSL_NOTEX, 0, nullptr, 1, UniNames, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - - return new struct OGLDecalDataBindingFactory; -} - -template <> -void CDecalShaders::Shutdown() -{ - m_texZTestNoZWrite.reset(); - m_texAdditiveZTest.reset(); - m_texRedToAlphaZTest.reset(); - - m_noTexZTestNoZWrite.reset(); - m_noTexAdditiveZTest.reset(); -} - -#if BOO_HAS_VULKAN -struct VulkanDecalDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken - BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CDecalShaders& shaders) - { - CQuadDecal& decal = shaders.m_decal; - const SQuadDescr* desc = decal.m_desc; - - CUVElement* texr = desc->x14_TEX.get(); - int texCount = 0; - boo::ObjToken textures[1]; - - if (texr) - { - textures[0] = texr->GetValueTexture(0).GetObj()->GetBooTexture(); - texCount = 1; - } - - if (decal.m_instBuf) - { - boo::ObjToken uniforms[] = {decal.m_uniformBuf.get()}; - - if (shaders.m_regPipeline) - decal.m_normalDataBind = ctx.newShaderDataBinding(shaders.m_regPipeline, nullptr, nullptr, - decal.m_instBuf.get(), nullptr, 1, uniforms, - nullptr, texCount, textures, nullptr, nullptr); - if (shaders.m_redToAlphaPipeline) - decal.m_redToAlphaDataBind = ctx.newShaderDataBinding(shaders.m_redToAlphaPipeline, nullptr, nullptr, - decal.m_instBuf.get(), nullptr, 1, uniforms, - nullptr, texCount, textures, nullptr, nullptr); - } - - return nullptr; - } -}; - -TShader::IDataBindingFactory* CDecalShaders::Initialize(boo::VulkanDataFactory::Context& ctx) -{ - static const boo::VertexElementDescriptor TexFmtTex[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 0}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 1}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 2}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 3}, - {nullptr, nullptr, boo::VertexSemantic::Color | boo::VertexSemantic::Instanced}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 0}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 1}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 2}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 3} - }; - m_vtxFormatTex = ctx.newVertexFormat(9, TexFmtTex); - - static const boo::VertexElementDescriptor TexFmtNoTex[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 0}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 1}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 2}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 3}, - {nullptr, nullptr, boo::VertexSemantic::Color | boo::VertexSemantic::Instanced} - }; - m_vtxFormatNoTex = ctx.newVertexFormat(5, TexFmtNoTex); - - m_texZTestNoZWrite = ctx.newShaderPipeline(VS_GLSL_TEX, FS_GLSL_TEX, m_vtxFormatTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - m_texAdditiveZTest = ctx.newShaderPipeline(VS_GLSL_TEX, FS_GLSL_TEX, m_vtxFormatTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - m_texRedToAlphaZTest = ctx.newShaderPipeline(VS_GLSL_TEX, FS_GLSL_TEX_REDTOALPHA, m_vtxFormatTex, - boo::BlendFactor::One, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, true, boo::CullMode::None); - m_noTexZTestNoZWrite = ctx.newShaderPipeline(VS_GLSL_NOTEX, FS_GLSL_NOTEX, m_vtxFormatNoTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - m_noTexAdditiveZTest = ctx.newShaderPipeline(VS_GLSL_NOTEX, FS_GLSL_NOTEX, m_vtxFormatNoTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - - return new struct VulkanDecalDataBindingFactory; -} - -template <> -void CDecalShaders::Shutdown() -{ - m_vtxFormatTex.reset(); - m_vtxFormatNoTex.reset(); - - m_texZTestNoZWrite.reset(); - m_texAdditiveZTest.reset(); - m_texRedToAlphaZTest.reset(); - - m_noTexZTestNoZWrite.reset(); - m_noTexAdditiveZTest.reset(); -} -#endif - -} diff --git a/Runtime/Graphics/Shaders/CDecalShadersHLSL.cpp b/Runtime/Graphics/Shaders/CDecalShadersHLSL.cpp deleted file mode 100644 index 66209eecb..000000000 --- a/Runtime/Graphics/Shaders/CDecalShadersHLSL.cpp +++ /dev/null @@ -1,215 +0,0 @@ -#include "CDecalShaders.hpp" -#include "Particle/CDecal.hpp" -#include "Graphics/CModel.hpp" - -namespace urde -{ - -static const char* VS_HLSL_TEX = -"struct VertData\n" -"{\n" -" float4 posIn[4] : POSITION;\n" -" float4 colorIn : COLOR;\n" -" float4 uvsIn[4] : UV;\n" -"};\n" -"\n" -"cbuffer DecalUniform : register(b0)\n" -"{\n" -" float4x4 mvp;\n" -" float4 moduColor;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float4 color : COLOR;\n" -" float2 uv : UV;\n" -"};\n" -"\n" -"VertToFrag main(in VertData v, in uint vertId : SV_VertexID)\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.color = v.colorIn * moduColor;\n" -" vtf.uv = v.uvsIn[vertId].xy;\n" -" vtf.position = mul(mvp, v.posIn[vertId]);\n" -" return vtf;\n" -"}\n"; - -static const char* FS_HLSL_TEX = -"SamplerState samp : register(s0);\n" -"Texture2D tex0 : register(t0);\n" -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float4 color : COLOR;\n" -" float2 uv : UV;\n" -"};\n" -"\n" -"float4 main(in VertToFrag vtf) : SV_Target0\n" -"{\n" -" return vtf.color * tex0.Sample(samp, vtf.uv);\n" -"}\n"; - -static const char* FS_HLSL_TEX_REDTOALPHA = -"SamplerState samp : register(s0);\n" -"Texture2D tex0 : register(t0);\n" -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float4 color : COLOR;\n" -" float2 uv : UV;\n" -"};\n" -"\n" -"float4 main(in VertToFrag vtf) : SV_Target0\n" -"{\n" -" return float4(vtf.color.rgb, tex0.Sample(samp, vtf.uv).r);\n" -"}\n"; - -static const char* VS_HLSL_NOTEX = -"struct VertData\n" -"{\n" -" float4 posIn[4] : POSITION;\n" -" float4 colorIn : COLOR;\n" -"};\n" -"\n" -"cbuffer DecalUniform : register(b0)\n" -"{\n" -" float4x4 mvp;\n" -" float4 moduColor;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float4 color : COLOR;\n" -"};\n" -"\n" -"VertToFrag main(in VertData v, in uint vertId : SV_VertexID)\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.color = v.colorIn * moduColor;\n" -" vtf.position = mul(mvp, v.posIn[vertId]);\n" -" return vtf;\n" -"}\n"; - -static const char* FS_HLSL_NOTEX = -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float4 color : COLOR;\n" -"};\n" -"\n" -"float4 main(in VertToFrag vtf) : SV_Target0\n" -"{\n" -" return vtf.color;\n" -"}\n"; - -struct D3DDecalDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken - BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CDecalShaders& shaders) - { - CQuadDecal& decal = shaders.m_decal; - const SQuadDescr* desc = decal.m_desc; - - CUVElement* texr = desc->x14_TEX.get(); - int texCount = 0; - boo::ObjToken textures[1]; - - if (texr) - { - textures[0] = texr->GetValueTexture(0).GetObj()->GetBooTexture(); - texCount = 1; - } - - if (decal.m_instBuf) - { - boo::ObjToken uniforms[] = {decal.m_uniformBuf.get()}; - - if (shaders.m_regPipeline) - decal.m_normalDataBind = ctx.newShaderDataBinding(shaders.m_regPipeline, nullptr, nullptr, - decal.m_instBuf.get(), nullptr, 1, uniforms, - nullptr, texCount, textures, - nullptr, nullptr); - if (shaders.m_redToAlphaPipeline) - decal.m_redToAlphaDataBind = ctx.newShaderDataBinding(shaders.m_redToAlphaPipeline, nullptr, nullptr, - decal.m_instBuf.get(), nullptr, 1, uniforms, - nullptr, texCount, textures, - nullptr, nullptr); - } - - return nullptr; - } -}; - -TShader::IDataBindingFactory* CDecalShaders::Initialize(boo::D3DDataFactory::Context& ctx) -{ - static const boo::VertexElementDescriptor TexFmtTex[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 0}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 1}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 2}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 3}, - {nullptr, nullptr, boo::VertexSemantic::Color | boo::VertexSemantic::Instanced}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 0}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 1}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 2}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 3} - }; - m_vtxFormatTex = ctx.newVertexFormat(9, TexFmtTex); - - static const boo::VertexElementDescriptor TexFmtNoTex[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 0}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 1}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 2}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 3}, - {nullptr, nullptr, boo::VertexSemantic::Color | boo::VertexSemantic::Instanced} - }; - m_vtxFormatNoTex = ctx.newVertexFormat(5, TexFmtNoTex); - - m_texZTestNoZWrite = ctx.newShaderPipeline(VS_HLSL_TEX, FS_HLSL_TEX, nullptr, nullptr, - nullptr, m_vtxFormatTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - m_texAdditiveZTest = ctx.newShaderPipeline(VS_HLSL_TEX, FS_HLSL_TEX, nullptr, nullptr, - nullptr, m_vtxFormatTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - m_texRedToAlphaZTest = ctx.newShaderPipeline(VS_HLSL_TEX, FS_HLSL_TEX_REDTOALPHA, nullptr, nullptr, - nullptr, m_vtxFormatTex, - boo::BlendFactor::One, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, true, boo::CullMode::None); - m_noTexZTestNoZWrite = ctx.newShaderPipeline(VS_HLSL_NOTEX, FS_HLSL_NOTEX, nullptr, nullptr, - nullptr, m_vtxFormatNoTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - m_noTexAdditiveZTest = ctx.newShaderPipeline(VS_HLSL_NOTEX, FS_HLSL_NOTEX, nullptr, nullptr, - nullptr, m_vtxFormatNoTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, true, - true, false, boo::CullMode::None); - - return new struct D3DDecalDataBindingFactory; -} - -template <> -void CDecalShaders::Shutdown() -{ - m_vtxFormatTex.reset(); - m_vtxFormatNoTex.reset(); - - m_texZTestNoZWrite.reset(); - m_texAdditiveZTest.reset(); - m_texRedToAlphaZTest.reset(); - - m_noTexZTestNoZWrite.reset(); - m_noTexAdditiveZTest.reset(); -} - -} diff --git a/Runtime/Graphics/Shaders/CDecalShadersMetal.cpp b/Runtime/Graphics/Shaders/CDecalShadersMetal.cpp deleted file mode 100644 index 160b08258..000000000 --- a/Runtime/Graphics/Shaders/CDecalShadersMetal.cpp +++ /dev/null @@ -1,221 +0,0 @@ -#include "CDecalShaders.hpp" -#include "Particle/CDecal.hpp" - -namespace urde -{ - -static const char* VS_METAL_TEX = -"#include \n" -"using namespace metal;\n" -"struct VertData\n" -"{\n" -" float4 posIn[4];\n" -" float4 colorIn;\n" -" float4 uvsIn[4];\n" -"};\n" -"\n" -"struct DecalUniform\n" -"{\n" -" float4x4 mvp;\n" -" float4 moduColor;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float4 color;\n" -" float2 uv;\n" -"};\n" -"\n" -"vertex VertToFrag vmain(constant VertData* va [[ buffer(1) ]],\n" -" uint vertId [[ vertex_id ]], uint instId [[ instance_id ]],\n" -" constant DecalUniform& decal [[ buffer(2) ]])\n" -"{\n" -" VertToFrag vtf;\n" -" constant VertData& v = va[instId];\n" -" vtf.color = v.colorIn * decal.moduColor;\n" -" vtf.uv = v.uvsIn[vertId].xy;\n" -" vtf.position = decal.mvp * v.posIn[vertId];\n" -" return vtf;\n" -"}\n"; - -static const char* FS_METAL_TEX = -"#include \n" -"using namespace metal;\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float4 color;\n" -" float2 uv;\n" -"};\n" -"\n" -"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n" -" sampler samp [[ sampler(0) ]],\n" -" texture2d tex0 [[ texture(0) ]])\n" -"{\n" -" return vtf.color * tex0.sample(samp, vtf.uv);\n" -"}\n"; - -static const char* FS_METAL_TEX_REDTOALPHA = -"#include \n" -"using namespace metal;\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float4 color;\n" -" float2 uv;\n" -"};\n" -"\n" -"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n" -" sampler samp [[ sampler(0) ]],\n" -" texture2d tex0 [[ texture(0) ]])\n" -"{\n" -" return float4(vtf.color.rgb, tex0.sample(samp, vtf.uv).r);\n" -"}\n"; - -static const char* VS_METAL_NOTEX = -"#include \n" -"using namespace metal;\n" -"struct VertData\n" -"{\n" -" float4 posIn[4];\n" -" float4 colorIn;\n" -"};\n" -"\n" -"struct DecalUniform\n" -"{\n" -" float4x4 mvp;\n" -" float4 moduColor;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float4 color;\n" -"};\n" -"\n" -"vertex VertToFrag vmain(constant VertData* va [[ buffer(1) ]],\n" -" uint vertId [[ vertex_id ]], uint instId [[ instance_id ]],\n" -" constant DecalUniform& decal [[ buffer(2) ]])\n" -"{\n" -" VertToFrag vtf;\n" -" constant VertData& v = va[instId];\n" -" vtf.color = v.colorIn * decal.moduColor;\n" -" vtf.position = decal.mvp * v.posIn[vertId];\n" -" return vtf;\n" -"}\n"; - -static const char* FS_METAL_NOTEX = -"#include \n" -"using namespace metal;\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float4 color;\n" -"};\n" -"\n" -"fragment float4 fmain(VertToFrag vtf [[ stage_in ]])\n" -"{\n" -" return vtf.color;\n" -"}\n"; - -struct MetalDecalDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CDecalShaders& shader) - { - CQuadDecal& decal = shader.m_decal; - const SQuadDescr* desc = decal.m_desc; - - CUVElement* texr = desc->x14_TEX.get(); - int texCount = 0; - boo::ObjToken textures[1]; - - if (texr) - { - textures[0] = texr->GetValueTexture(0).GetObj()->GetBooTexture(); - texCount = 1; - } - - if (decal.m_instBuf) - { - boo::ObjToken uniforms[] = {decal.m_uniformBuf.get()}; - - if (shader.m_regPipeline) - decal.m_normalDataBind = ctx.newShaderDataBinding(shader.m_regPipeline, nullptr, nullptr, - decal.m_instBuf.get(), nullptr, 1, uniforms, - nullptr, texCount, textures, nullptr, nullptr); - if (shader.m_redToAlphaPipeline) - decal.m_redToAlphaDataBind = ctx.newShaderDataBinding(shader.m_redToAlphaPipeline, nullptr, nullptr, - decal.m_instBuf.get(), nullptr, 1, uniforms, - nullptr, texCount, textures, nullptr, nullptr); - } - - return {}; - } -}; - -TShader::IDataBindingFactory* CDecalShaders::Initialize(boo::MetalDataFactory::Context& ctx) -{ - static const boo::VertexElementDescriptor TexFmtTex[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 0}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 1}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 2}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 3}, - {nullptr, nullptr, boo::VertexSemantic::Color | boo::VertexSemantic::Instanced}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 0}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 1}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 2}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 3} - }; - m_vtxFormatTex = ctx.newVertexFormat(9, TexFmtTex); - - static const boo::VertexElementDescriptor TexFmtNoTex[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 0}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 1}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 2}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 3}, - {nullptr, nullptr, boo::VertexSemantic::Color | boo::VertexSemantic::Instanced} - }; - m_vtxFormatNoTex = ctx.newVertexFormat(5, TexFmtNoTex); - - m_texZTestNoZWrite = ctx.newShaderPipeline(VS_METAL_TEX, FS_METAL_TEX, nullptr, nullptr, m_vtxFormatTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, true, false, boo::CullMode::None); - - m_texAdditiveZTest = ctx.newShaderPipeline(VS_METAL_TEX, FS_METAL_TEX, nullptr, nullptr, m_vtxFormatTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, true, false, boo::CullMode::None); - - m_texRedToAlphaZTest = ctx.newShaderPipeline(VS_METAL_TEX, FS_METAL_TEX_REDTOALPHA, nullptr, nullptr, m_vtxFormatTex, - boo::BlendFactor::One, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, true, true, boo::CullMode::None); - - m_noTexZTestNoZWrite = ctx.newShaderPipeline(VS_METAL_NOTEX, FS_METAL_NOTEX, nullptr, nullptr, m_vtxFormatNoTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, true, false, boo::CullMode::None); - - m_noTexAdditiveZTest = ctx.newShaderPipeline(VS_METAL_NOTEX, FS_METAL_NOTEX, nullptr, nullptr, m_vtxFormatNoTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, true, false, boo::CullMode::None); - - return new struct MetalDecalDataBindingFactory; -} - -template <> -void CDecalShaders::Shutdown() -{ - m_texZTestNoZWrite.reset(); - m_texAdditiveZTest.reset(); - m_texRedToAlphaZTest.reset(); - - m_noTexZTestNoZWrite.reset(); - m_noTexAdditiveZTest.reset(); - - m_vtxFormatTex.reset(); - m_vtxFormatNoTex.reset(); -} - -} diff --git a/Runtime/Graphics/Shaders/CElementGenShaders.cpp b/Runtime/Graphics/Shaders/CElementGenShaders.cpp index a5f5f4116..087b2621e 100644 --- a/Runtime/Graphics/Shaders/CElementGenShaders.cpp +++ b/Runtime/Graphics/Shaders/CElementGenShaders.cpp @@ -1,5 +1,6 @@ #include "CElementGenShaders.hpp" #include "Particle/CElementGen.hpp" +#include "hecl/Pipeline.hpp" namespace urde { @@ -32,9 +33,67 @@ boo::ObjToken CElementGenShaders::m_noTexNoZTestNoZWrite; boo::ObjToken CElementGenShaders::m_noTexAdditiveZTest; boo::ObjToken CElementGenShaders::m_noTexAdditiveNoZTest; -boo::ObjToken CElementGenShaders::m_vtxFormatTex; -boo::ObjToken CElementGenShaders::m_vtxFormatIndTex; -boo::ObjToken CElementGenShaders::m_vtxFormatNoTex; +void CElementGenShaders::Initialize() +{ + m_texZTestZWrite = hecl::conv->convert(Shader_CElementGenShaderTexZTestZWrite{}); + m_texNoZTestZWrite = hecl::conv->convert(Shader_CElementGenShaderTexNoZTestZWrite{}); + m_texZTestNoZWrite = hecl::conv->convert(Shader_CElementGenShaderTexZTestNoZWrite{}); + m_texNoZTestNoZWrite = hecl::conv->convert(Shader_CElementGenShaderTexNoZTestNoZWrite{}); + m_texAdditiveZTest = hecl::conv->convert(Shader_CElementGenShaderTexAdditiveZTest{}); + m_texAdditiveNoZTest = hecl::conv->convert(Shader_CElementGenShaderTexAdditiveNoZTest{}); + m_texRedToAlphaZTest = hecl::conv->convert(Shader_CElementGenShaderTexRedToAlphaZTest{}); + m_texRedToAlphaNoZTest = hecl::conv->convert(Shader_CElementGenShaderTexRedToAlphaNoZTest{}); + m_texZTestNoZWriteSub = hecl::conv->convert(Shader_CElementGenShaderTexZTestNoZWriteSub{}); + m_texNoZTestNoZWriteSub = hecl::conv->convert(Shader_CElementGenShaderTexNoZTestNoZWriteSub{}); + m_texRedToAlphaZTestSub = hecl::conv->convert(Shader_CElementGenShaderTexRedToAlphaZTestSub{}); + m_texRedToAlphaNoZTestSub = hecl::conv->convert(Shader_CElementGenShaderTexRedToAlphaNoZTestSub{}); + + m_indTexZWrite = hecl::conv->convert(Shader_CElementGenShaderIndTexZWrite{}); + m_indTexNoZWrite = hecl::conv->convert(Shader_CElementGenShaderIndTexNoZWrite{}); + m_indTexAdditive = hecl::conv->convert(Shader_CElementGenShaderIndTexAdditive{}); + + m_cindTexZWrite = hecl::conv->convert(Shader_CElementGenShaderCindTexZWrite{}); + m_cindTexNoZWrite = hecl::conv->convert(Shader_CElementGenShaderCindTexNoZWrite{}); + m_cindTexAdditive = hecl::conv->convert(Shader_CElementGenShaderCindTexAdditive{}); + + m_noTexZTestZWrite = hecl::conv->convert(Shader_CElementGenShaderNoTexZTestZWrite{}); + m_noTexNoZTestZWrite = hecl::conv->convert(Shader_CElementGenShaderNoTexNoZTestZWrite{}); + m_noTexZTestNoZWrite = hecl::conv->convert(Shader_CElementGenShaderNoTexZTestNoZWrite{}); + m_noTexNoZTestNoZWrite = hecl::conv->convert(Shader_CElementGenShaderNoTexNoZTestNoZWrite{}); + m_noTexAdditiveZTest = hecl::conv->convert(Shader_CElementGenShaderNoTexAdditiveZTest{}); + m_noTexAdditiveNoZTest = hecl::conv->convert(Shader_CElementGenShaderNoTexAdditiveNoZTest{}); +} + +void CElementGenShaders::Shutdown() +{ + m_texZTestZWrite.reset(); + m_texNoZTestZWrite.reset(); + m_texZTestNoZWrite.reset(); + m_texNoZTestNoZWrite.reset(); + m_texAdditiveZTest.reset(); + m_texAdditiveNoZTest.reset(); + m_texRedToAlphaZTest.reset(); + m_texRedToAlphaNoZTest.reset(); + m_texZTestNoZWriteSub.reset(); + m_texNoZTestNoZWriteSub.reset(); + m_texRedToAlphaZTestSub.reset(); + m_texRedToAlphaNoZTestSub.reset(); + + m_indTexZWrite.reset(); + m_indTexNoZWrite.reset(); + m_indTexAdditive.reset(); + + m_cindTexZWrite.reset(); + m_cindTexNoZWrite.reset(); + m_cindTexAdditive.reset(); + + m_noTexZTestZWrite.reset(); + m_noTexNoZTestZWrite.reset(); + m_noTexZTestNoZWrite.reset(); + m_noTexNoZTestNoZWrite.reset(); + m_noTexAdditiveZTest.reset(); + m_noTexAdditiveNoZTest.reset(); +} CElementGenShaders::EShaderClass CElementGenShaders::GetShaderClass(CElementGen& gen) { @@ -178,11 +237,62 @@ void CElementGenShaders::BuildShaderDataBinding(boo::IGraphicsDataFactory::Conte } } - CElementGenShaders shad(gen, regPipeline, regPipelineSub, redToAlphaPipeline, redToAlphaPipelineSub, - regPipelinePmus, redToAlphaPipelinePmus); - TShader::BuildShaderDataBinding(ctx, shad); + CUVElement* texr = desc->x54_x40_TEXR.get(); + CUVElement* tind = desc->x58_x44_TIND.get(); + int texCount = 0; + boo::ObjToken textures[3]; + + if (texr) + { + textures[0] = texr->GetValueTexture(0).GetObj()->GetBooTexture(); + texCount = 1; + if (gen.m_instBuf) + { + if (tind) + { + textures[1] = CGraphics::g_SpareTexture.get(); + textures[2] = tind->GetValueTexture(0).GetObj()->GetBooTexture(); + texCount = 3; + } + } + } + + if (gen.m_instBuf) + { + boo::ObjToken uniforms[] = {gen.m_uniformBuf.get()}; + + if (regPipeline) + gen.m_normalDataBind = ctx.newShaderDataBinding(regPipeline, nullptr, + gen.m_instBuf.get(), nullptr, 1, uniforms, + nullptr, texCount, textures, nullptr, nullptr); + if (regPipelineSub) + gen.m_normalSubDataBind = ctx.newShaderDataBinding(regPipelineSub, nullptr, + gen.m_instBuf.get(), nullptr, 1, uniforms, + nullptr, texCount, textures, nullptr, nullptr); + if (redToAlphaPipeline) + gen.m_redToAlphaDataBind = ctx.newShaderDataBinding(redToAlphaPipeline, nullptr, + gen.m_instBuf.get(), nullptr, 1, uniforms, + nullptr, texCount, textures, nullptr, nullptr); + if (redToAlphaPipelineSub) + gen.m_redToAlphaSubDataBind = ctx.newShaderDataBinding(redToAlphaPipelineSub, nullptr, + gen.m_instBuf.get(), nullptr, 1, uniforms, + nullptr, texCount, textures, nullptr, nullptr); + } + + if (gen.m_instBufPmus) + { + boo::ObjToken uniforms[] = {gen.m_uniformBufPmus.get()}; + texCount = std::min(texCount, 1); + + if (regPipelinePmus) + gen.m_normalDataBindPmus = ctx.newShaderDataBinding(regPipelinePmus, nullptr, + gen.m_instBufPmus.get(), nullptr, 1, uniforms, + nullptr, texCount, textures, nullptr, nullptr); + if (redToAlphaPipelinePmus) + gen.m_redToAlphaDataBindPmus = ctx.newShaderDataBinding(redToAlphaPipelinePmus, nullptr, + gen.m_instBufPmus.get(), nullptr, 1, uniforms, + nullptr, texCount, textures, nullptr, nullptr); + } } -URDE_SPECIALIZE_SHADER(CElementGenShaders) - } diff --git a/Runtime/Graphics/Shaders/CElementGenShaders.hpp b/Runtime/Graphics/Shaders/CElementGenShaders.hpp index 844ee4a1b..4209e6a5e 100644 --- a/Runtime/Graphics/Shaders/CElementGenShaders.hpp +++ b/Runtime/Graphics/Shaders/CElementGenShaders.hpp @@ -1,12 +1,8 @@ #ifndef __URDE_CELEMENTGENSHADERS_HPP__ #define __URDE_CELEMENTGENSHADERS_HPP__ -#include "TShader.hpp" #include "Graphics/CGraphics.hpp" -#include "boo/graphicsdev/GL.hpp" -#include "boo/graphicsdev/D3D.hpp" -#include "boo/graphicsdev/Metal.hpp" -#include "boo/graphicsdev/Vulkan.hpp" +#include "boo/graphicsdev/IGraphicsDataFactory.hpp" namespace urde { @@ -14,10 +10,6 @@ class CElementGen; class CElementGenShaders { - friend struct OGLElementDataBindingFactory; - friend struct VulkanElementDataBindingFactory; - friend struct D3DElementDataBindingFactory; - friend struct MetalElementDataBindingFactory; public: enum class EShaderClass { @@ -55,34 +47,11 @@ private: static boo::ObjToken m_noTexAdditiveZTest; static boo::ObjToken m_noTexAdditiveNoZTest; - static boo::ObjToken m_vtxFormatTex; /* No OpenGL */ - static boo::ObjToken m_vtxFormatIndTex; /* No OpenGL */ - static boo::ObjToken m_vtxFormatNoTex; /* No OpenGL */ - - CElementGen& m_gen; - boo::ObjToken m_regPipeline; - boo::ObjToken m_regPipelineSub; - boo::ObjToken m_redToAlphaPipeline; - boo::ObjToken m_redToAlphaPipelineSub; - boo::ObjToken m_regPipelinePmus; - boo::ObjToken m_redToAlphaPipelinePmus; - CElementGenShaders(CElementGen& gen, - const boo::ObjToken& regPipeline, - const boo::ObjToken& regPipelineSub, - const boo::ObjToken& redToAlphaPipeline, - const boo::ObjToken& redToAlphaPipelineSub, - const boo::ObjToken& regPipelinePmus, - const boo::ObjToken& redToAlphaPipelinePmus) - : m_gen(gen), m_regPipeline(regPipeline), m_regPipelineSub(regPipelineSub), - m_redToAlphaPipeline(redToAlphaPipeline), m_redToAlphaPipelineSub(redToAlphaPipelineSub), - m_regPipelinePmus(regPipelinePmus), m_redToAlphaPipelinePmus(redToAlphaPipelinePmus) {} - public: + static void Initialize(); + static void Shutdown(); static EShaderClass GetShaderClass(CElementGen& gen); static void BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, CElementGen& gen); - - using _CLS = CElementGenShaders; -#include "TShaderDecl.hpp" }; } diff --git a/Runtime/Graphics/Shaders/CElementGenShadersGLSL.cpp b/Runtime/Graphics/Shaders/CElementGenShadersGLSL.cpp deleted file mode 100644 index 02b7db4e5..000000000 --- a/Runtime/Graphics/Shaders/CElementGenShadersGLSL.cpp +++ /dev/null @@ -1,744 +0,0 @@ -#include "CElementGenShaders.hpp" -#include "Particle/CElementGen.hpp" -#include "Particle/CGenDescription.hpp" -#include "Particle/CElectricDescription.hpp" -#include "Particle/CSwooshDescription.hpp" -#include "Graphics/CModel.hpp" - -namespace urde -{ - -static const char* VS_GLSL_TEX = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"layout(location=0) in vec4 posIn[4];\n" -"layout(location=4) in vec4 colorIn;\n" -"layout(location=5) in vec4 uvsIn[4];\n" -"\n" -"UBINDING0 uniform ParticleUniform\n" -"{\n" -" mat4 mvp;\n" -" vec4 moduColor;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -" vec2 uv;\n" -"};\n" -"\n" -"SBINDING(0) out VertToFrag vtf;\n" -"void main()\n" -"{\n" -" vec4 pos = posIn[gl_VertexID];\n" -" vtf.color = colorIn * moduColor;\n" -" vtf.uv = uvsIn[gl_VertexID].xy;\n" -" gl_Position = mvp * pos;\n" -"}\n"; - -static const char* FS_GLSL_TEX = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -" vec2 uv;\n" -"};\n" -"\n" -"SBINDING(0) in VertToFrag vtf;\n" -"layout(location=0) out vec4 colorOut;\n" -"TBINDING0 uniform sampler2D tex;\n" -"void main()\n" -"{\n" -" colorOut = vtf.color * texture(tex, vtf.uv);\n" -"}\n"; - -static const char* FS_GLSL_TEX_REDTOALPHA = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -" vec2 uv;\n" -"};\n" -"\n" -"SBINDING(0) in VertToFrag vtf;\n" -"layout(location=0) out vec4 colorOut;\n" -"TBINDING0 uniform sampler2D tex;\n" -"void main()\n" -"{\n" -" colorOut = vtf.color;\n" -" colorOut.a = texture(tex, vtf.uv).r;\n" -"}\n"; - -static const char* VS_GLSL_INDTEX = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"layout(location=0) in vec4 posIn[4];\n" -"layout(location=4) in vec4 colorIn;\n" -"layout(location=5) in vec4 uvsInTexrTind[4];\n" -"layout(location=9) in vec4 uvsInScene;\n" -"\n" -"UBINDING0 uniform ParticleUniform\n" -"{\n" -" mat4 mvp;\n" -" vec4 moduColor;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -" vec4 uvScene;\n" -" vec2 uvTexr;\n" -" vec2 uvTind;\n" -"};\n" -"\n" -"SBINDING(0) out VertToFrag vtf;\n" -"void main()\n" -"{\n" -" vec4 pos = posIn[gl_VertexID];\n" -" vtf.color = colorIn * moduColor;\n" -" vtf.uvScene = uvsInScene;\n" -" vtf.uvTexr = uvsInTexrTind[gl_VertexID].xy;\n" -" vtf.uvTind = uvsInTexrTind[gl_VertexID].zw;\n" -" gl_Position = mvp * pos;\n" -" gl_Position = FLIPFROMGL(gl_Position);\n" -"}\n"; - -static const char* FS_GLSL_INDTEX = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -" vec4 uvScene;\n" -" vec2 uvTexr;\n" -" vec2 uvTind;\n" -"};\n" -"\n" -"SBINDING(0) in VertToFrag vtf;\n" -"layout(location=0) out vec4 colorOut;\n" -"TBINDING0 uniform sampler2D texrMap;\n" -"TBINDING1 uniform sampler2D sceneMap;\n" -"TBINDING2 uniform sampler2D tindMap;\n" -"void main()\n" -"{\n" -" vec2 tindTexel = texture(tindMap, vtf.uvTind).zw;\n" -" vec4 sceneTexel = texture(sceneMap, mix(vtf.uvScene.xy, vtf.uvScene.zw, tindTexel));\n" -" vec4 texrTexel = texture(texrMap, vtf.uvTexr);\n" -" colorOut = vtf.color * vec4(sceneTexel.rgb, 1.0) + texrTexel;\n" -"}\n"; - -static const char* FS_GLSL_CINDTEX = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -" vec4 uvScene;\n" -" vec2 uvTexr;\n" -" vec2 uvTind;\n" -"};\n" -"\n" -"SBINDING(0) in VertToFrag vtf;\n" -"layout(location=0) out vec4 colorOut;\n" -"TBINDING0 uniform sampler2D texrMap;\n" -"TBINDING1 uniform sampler2D sceneMap;\n" -"TBINDING2 uniform sampler2D tindMap;\n" -"void main()\n" -"{\n" -" vec2 tindTexel = texture(tindMap, vtf.uvTind).zw;\n" -" vec4 sceneTexel = texture(sceneMap, mix(vtf.uvScene.xy, vtf.uvScene.zw, tindTexel));\n" -" colorOut = vtf.color * vec4(sceneTexel.rgb, 1.0) * texture(texrMap, vtf.uvTexr);\n" -"}\n"; - -static const char* VS_GLSL_NOTEX = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"layout(location=0) in vec4 posIn[4];\n" -"layout(location=4) in vec4 colorIn;\n" -"\n" -"UBINDING0 uniform ParticleUniform\n" -"{\n" -" mat4 mvp;\n" -" vec4 moduColor;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -"};\n" -"\n" -"SBINDING(0) out VertToFrag vtf;\n" -"void main()\n" -"{\n" -" vec4 pos = posIn[gl_VertexID];\n" -" vtf.color = colorIn * moduColor;\n" -" gl_Position = mvp * pos;\n" -"}\n"; - -static const char* FS_GLSL_NOTEX = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -"};\n" -"\n" -"SBINDING(0) in VertToFrag vtf;\n" -"layout(location=0) out vec4 colorOut;\n" -"void main()\n" -"{\n" -" colorOut = vtf.color;\n" -"}\n"; - -struct OGLElementDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CElementGenShaders& shaders) - { - CElementGen& gen = shaders.m_gen; - CGenDescription* desc = gen.GetDesc(); - - boo::ObjToken vtxFmt; - boo::ObjToken vtxFmtPmus; - CUVElement* texr = desc->x54_x40_TEXR.get(); - CUVElement* tind = desc->x58_x44_TIND.get(); - int texCount = 0; - boo::ObjToken textures[3]; - - if (texr) - { - textures[0] = texr->GetValueTexture(0).GetObj()->GetBooTexture(); - texCount = 1; - if (gen.m_instBuf) - { - if (tind) - { - textures[1] = CGraphics::g_SpareTexture.get(); - textures[2] = tind->GetValueTexture(0).GetObj()->GetBooTexture(); - texCount = 3; - - const boo::VertexElementDescriptor TexFmtIndTex[] = - { - {gen.m_instBuf.get(), nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 0}, - {gen.m_instBuf.get(), nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 1}, - {gen.m_instBuf.get(), nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 2}, - {gen.m_instBuf.get(), nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 3}, - {gen.m_instBuf.get(), nullptr, boo::VertexSemantic::Color | boo::VertexSemantic::Instanced}, - {gen.m_instBuf.get(), nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 0}, - {gen.m_instBuf.get(), nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 1}, - {gen.m_instBuf.get(), nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 2}, - {gen.m_instBuf.get(), nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 3}, - {gen.m_instBuf.get(), nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 4}, - }; - vtxFmt = ctx.newVertexFormat(10, TexFmtIndTex); - } - else - { - const boo::VertexElementDescriptor TexFmtTex[] = - { - {gen.m_instBuf.get(), nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 0}, - {gen.m_instBuf.get(), nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 1}, - {gen.m_instBuf.get(), nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 2}, - {gen.m_instBuf.get(), nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 3}, - {gen.m_instBuf.get(), nullptr, boo::VertexSemantic::Color | boo::VertexSemantic::Instanced}, - {gen.m_instBuf.get(), nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 0}, - {gen.m_instBuf.get(), nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 1}, - {gen.m_instBuf.get(), nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 2}, - {gen.m_instBuf.get(), nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 3} - }; - vtxFmt = ctx.newVertexFormat(9, TexFmtTex); - } - } - if (gen.m_instBufPmus) - { - const boo::VertexElementDescriptor TexFmtTex[] = - { - {gen.m_instBufPmus.get(), nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 0}, - {gen.m_instBufPmus.get(), nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 1}, - {gen.m_instBufPmus.get(), nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 2}, - {gen.m_instBufPmus.get(), nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 3}, - {gen.m_instBufPmus.get(), nullptr, boo::VertexSemantic::Color | boo::VertexSemantic::Instanced}, - {gen.m_instBufPmus.get(), nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 0}, - {gen.m_instBufPmus.get(), nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 1}, - {gen.m_instBufPmus.get(), nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 2}, - {gen.m_instBufPmus.get(), nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 3} - }; - vtxFmtPmus = ctx.newVertexFormat(9, TexFmtTex); - } - } - else - { - if (gen.m_instBuf) - { - const boo::VertexElementDescriptor TexFmtNoTex[] = - { - {gen.m_instBuf.get(), nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 0}, - {gen.m_instBuf.get(), nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 1}, - {gen.m_instBuf.get(), nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 2}, - {gen.m_instBuf.get(), nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 3}, - {gen.m_instBuf.get(), nullptr, boo::VertexSemantic::Color | boo::VertexSemantic::Instanced} - }; - vtxFmt = ctx.newVertexFormat(5, TexFmtNoTex); - } - if (gen.m_instBufPmus) - { - const boo::VertexElementDescriptor TexFmtNoTex[] = - { - {gen.m_instBufPmus.get(), nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 0}, - {gen.m_instBufPmus.get(), nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 1}, - {gen.m_instBufPmus.get(), nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 2}, - {gen.m_instBufPmus.get(), nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 3}, - {gen.m_instBufPmus.get(), nullptr, boo::VertexSemantic::Color | boo::VertexSemantic::Instanced} - }; - vtxFmtPmus = ctx.newVertexFormat(5, TexFmtNoTex); - } - } - - if (gen.m_instBuf) - { - boo::ObjToken uniforms[] = {gen.m_uniformBuf.get()}; - - if (shaders.m_regPipeline) - gen.m_normalDataBind = ctx.newShaderDataBinding(shaders.m_regPipeline, vtxFmt, nullptr, - gen.m_instBuf.get(), nullptr, 1, uniforms, - nullptr, texCount, textures, nullptr, nullptr); - if (shaders.m_regPipelineSub) - gen.m_normalSubDataBind = ctx.newShaderDataBinding(shaders.m_regPipelineSub, vtxFmt, nullptr, - gen.m_instBuf.get(), nullptr, 1, uniforms, - nullptr, texCount, textures, nullptr, nullptr); - if (shaders.m_redToAlphaPipeline) - gen.m_redToAlphaDataBind = ctx.newShaderDataBinding(shaders.m_redToAlphaPipeline, vtxFmt, nullptr, - gen.m_instBuf.get(), nullptr, 1, uniforms, - nullptr, texCount, textures, nullptr, nullptr); - if (shaders.m_redToAlphaPipelineSub) - gen.m_redToAlphaSubDataBind = ctx.newShaderDataBinding(shaders.m_redToAlphaPipelineSub, vtxFmt, nullptr, - gen.m_instBuf.get(), nullptr, 1, uniforms, - nullptr, texCount, textures, nullptr, nullptr); - } - - if (gen.m_instBufPmus) - { - boo::ObjToken uniforms[] = {gen.m_uniformBufPmus.get()}; - texCount = std::min(texCount, 1); - - if (shaders.m_regPipelinePmus) - gen.m_normalDataBindPmus = ctx.newShaderDataBinding(shaders.m_regPipelinePmus, vtxFmtPmus, nullptr, - gen.m_instBufPmus.get(), nullptr, 1, uniforms, - nullptr, texCount, textures, nullptr, nullptr); - if (shaders.m_redToAlphaPipelinePmus) - gen.m_redToAlphaDataBindPmus = ctx.newShaderDataBinding(shaders.m_redToAlphaPipelinePmus, vtxFmtPmus, nullptr, - gen.m_instBufPmus.get(), nullptr, 1, uniforms, - nullptr, texCount, textures, nullptr, nullptr); - } - - return nullptr; - } -}; - -static const char* UniNames[] = {"ParticleUniform"}; -static const char* TexNames[] = {"tex"}; -static const char* TindTexNames[] = {"texrMap", "sceneMap", "tindMap"}; - -TShader::IDataBindingFactory* CElementGenShaders::Initialize(boo::GLDataFactory::Context& ctx) -{ - m_texZTestZWrite = ctx.newShaderPipeline(VS_GLSL_TEX, FS_GLSL_TEX, 1, TexNames, 1, UniNames, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, true, - true, false, boo::CullMode::None); - m_texNoZTestZWrite = ctx.newShaderPipeline(VS_GLSL_TEX, FS_GLSL_TEX, 1, TexNames, 1, UniNames, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::None, true, - true, false, boo::CullMode::None); - m_texZTestNoZWrite = ctx.newShaderPipeline(VS_GLSL_TEX, FS_GLSL_TEX, 1, TexNames, 1, UniNames, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - m_texNoZTestNoZWrite = ctx.newShaderPipeline(VS_GLSL_TEX, FS_GLSL_TEX, 1, TexNames, 1, UniNames, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::None, false, - true, false, boo::CullMode::None); - - m_texAdditiveZTest = ctx.newShaderPipeline(VS_GLSL_TEX, FS_GLSL_TEX, 1, TexNames, 1, UniNames, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - m_texAdditiveNoZTest = ctx.newShaderPipeline(VS_GLSL_TEX, FS_GLSL_TEX, 1, TexNames, 1, UniNames, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::None, false, - true, false, boo::CullMode::None); - - m_texRedToAlphaZTest = ctx.newShaderPipeline(VS_GLSL_TEX, FS_GLSL_TEX_REDTOALPHA, 1, TexNames, 1, UniNames, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - m_texRedToAlphaNoZTest = ctx.newShaderPipeline(VS_GLSL_TEX, FS_GLSL_TEX_REDTOALPHA, 1, TexNames, 1, UniNames, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::None, false, - true, false, boo::CullMode::None); - - m_texZTestNoZWriteSub = ctx.newShaderPipeline(VS_GLSL_TEX, FS_GLSL_TEX, 1, TexNames, 1, UniNames, - boo::BlendFactor::Subtract, boo::BlendFactor::Subtract, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - m_texNoZTestNoZWriteSub = ctx.newShaderPipeline(VS_GLSL_TEX, FS_GLSL_TEX, 1, TexNames, 1, UniNames, - boo::BlendFactor::Subtract, boo::BlendFactor::Subtract, - boo::Primitive::TriStrips, boo::ZTest::None, false, - true, false, boo::CullMode::None); - - m_texRedToAlphaZTestSub = ctx.newShaderPipeline(VS_GLSL_TEX, FS_GLSL_TEX_REDTOALPHA, 1, TexNames, 1, UniNames, - boo::BlendFactor::Subtract, boo::BlendFactor::Subtract, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - m_texRedToAlphaNoZTestSub = ctx.newShaderPipeline(VS_GLSL_TEX, FS_GLSL_TEX_REDTOALPHA, 1, TexNames, 1, UniNames, - boo::BlendFactor::Subtract, boo::BlendFactor::Subtract, - boo::Primitive::TriStrips, boo::ZTest::None, false, - true, false, boo::CullMode::None); - - m_indTexZWrite = ctx.newShaderPipeline(VS_GLSL_INDTEX, FS_GLSL_INDTEX, 3, TindTexNames, 1, UniNames, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::None, true, - true, false, boo::CullMode::None); - m_indTexNoZWrite = ctx.newShaderPipeline(VS_GLSL_INDTEX, FS_GLSL_INDTEX, 3, TindTexNames, 1, UniNames, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::None, false, - true, false, boo::CullMode::None); - m_indTexAdditive = ctx.newShaderPipeline(VS_GLSL_INDTEX, FS_GLSL_INDTEX, 3, TindTexNames, 1, UniNames, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::None, true, - true, false, boo::CullMode::None); - - m_cindTexZWrite = ctx.newShaderPipeline(VS_GLSL_INDTEX, FS_GLSL_CINDTEX, 3, TindTexNames, 1, UniNames, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::None, true, - true, false, boo::CullMode::None); - m_cindTexNoZWrite = ctx.newShaderPipeline(VS_GLSL_INDTEX, FS_GLSL_CINDTEX, 3, TindTexNames, 1, UniNames, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::None, false, - true, false, boo::CullMode::None); - m_cindTexAdditive = ctx.newShaderPipeline(VS_GLSL_INDTEX, FS_GLSL_CINDTEX, 3, TindTexNames, 1, UniNames, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::None, true, - true, false, boo::CullMode::None); - - m_noTexZTestZWrite = ctx.newShaderPipeline(VS_GLSL_NOTEX, FS_GLSL_NOTEX, 0, nullptr, 1, UniNames, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, true, - true, false, boo::CullMode::None); - m_noTexNoZTestZWrite = ctx.newShaderPipeline(VS_GLSL_NOTEX, FS_GLSL_NOTEX, 0, nullptr, 1, UniNames, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::None, true, - true, false, boo::CullMode::None); - m_noTexZTestNoZWrite = ctx.newShaderPipeline(VS_GLSL_NOTEX, FS_GLSL_NOTEX, 0, nullptr, 1, UniNames, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - m_noTexNoZTestNoZWrite = ctx.newShaderPipeline(VS_GLSL_NOTEX, FS_GLSL_NOTEX, 0, nullptr, 1, UniNames, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::None, false, - true, false, boo::CullMode::None); - - m_noTexAdditiveZTest = ctx.newShaderPipeline(VS_GLSL_NOTEX, FS_GLSL_NOTEX, 0, nullptr, 1, UniNames, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - m_noTexAdditiveNoZTest = ctx.newShaderPipeline(VS_GLSL_NOTEX, FS_GLSL_NOTEX, 0, nullptr, 1, UniNames, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::None, false, - true, false, boo::CullMode::None); - - return new struct OGLElementDataBindingFactory; -} - -template <> -void CElementGenShaders::Shutdown() -{ - m_texZTestZWrite.reset(); - m_texNoZTestZWrite.reset(); - m_texZTestNoZWrite.reset(); - m_texNoZTestNoZWrite.reset(); - m_texAdditiveZTest.reset(); - m_texAdditiveNoZTest.reset(); - m_texRedToAlphaZTest.reset(); - m_texRedToAlphaNoZTest.reset(); - m_texZTestNoZWriteSub.reset(); - m_texNoZTestNoZWriteSub.reset(); - m_texRedToAlphaZTestSub.reset(); - m_texRedToAlphaNoZTestSub.reset(); - - m_indTexZWrite.reset(); - m_indTexNoZWrite.reset(); - m_indTexAdditive.reset(); - - m_cindTexZWrite.reset(); - m_cindTexNoZWrite.reset(); - m_cindTexAdditive.reset(); - - m_noTexZTestZWrite.reset(); - m_noTexNoZTestZWrite.reset(); - m_noTexZTestNoZWrite.reset(); - m_noTexNoZTestNoZWrite.reset(); - m_noTexAdditiveZTest.reset(); - m_noTexAdditiveNoZTest.reset(); -} - -#if BOO_HAS_VULKAN -struct VulkanElementDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken - BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CElementGenShaders& shaders) - { - CElementGen& gen = shaders.m_gen; - CGenDescription* desc = gen.GetDesc(); - - CUVElement* texr = desc->x54_x40_TEXR.get(); - CUVElement* tind = desc->x58_x44_TIND.get(); - int texCount = 0; - boo::ObjToken textures[3]; - - if (texr) - { - textures[0] = texr->GetValueTexture(0).GetObj()->GetBooTexture(); - texCount = 1; - if (tind) - { - textures[1] = CGraphics::g_SpareTexture.get(); - textures[2] = tind->GetValueTexture(0).GetObj()->GetBooTexture(); - texCount = 3; - } - } - - if (gen.m_instBuf) - { - boo::ObjToken uniforms[] = {gen.m_uniformBuf.get()}; - - if (shaders.m_regPipeline) - gen.m_normalDataBind = ctx.newShaderDataBinding(shaders.m_regPipeline, nullptr, nullptr, - gen.m_instBuf.get(), nullptr, 1, uniforms, - nullptr, texCount, textures, nullptr, nullptr); - if (shaders.m_regPipelineSub) - gen.m_normalSubDataBind = ctx.newShaderDataBinding(shaders.m_regPipelineSub, nullptr, nullptr, - gen.m_instBuf.get(), nullptr, 1, uniforms, - nullptr, texCount, textures, nullptr, nullptr); - if (shaders.m_redToAlphaPipeline) - gen.m_redToAlphaDataBind = ctx.newShaderDataBinding(shaders.m_redToAlphaPipeline, nullptr, nullptr, - gen.m_instBuf.get(), nullptr, 1, uniforms, - nullptr, texCount, textures, nullptr, nullptr); - if (shaders.m_redToAlphaPipelineSub) - gen.m_redToAlphaSubDataBind = ctx.newShaderDataBinding(shaders.m_redToAlphaPipelineSub, nullptr, nullptr, - gen.m_instBuf.get(), nullptr, 1, uniforms, - nullptr, texCount, textures, nullptr, nullptr); - - } - - if (gen.m_instBufPmus) - { - boo::ObjToken uniforms[] = {gen.m_uniformBufPmus.get()}; - texCount = std::min(texCount, 1); - - if (shaders.m_regPipelinePmus) - gen.m_normalDataBindPmus = ctx.newShaderDataBinding(shaders.m_regPipelinePmus, nullptr, nullptr, - gen.m_instBufPmus.get(), nullptr, 1, uniforms, - nullptr, texCount, textures, nullptr, nullptr); - if (shaders.m_redToAlphaPipelinePmus) - gen.m_redToAlphaDataBindPmus = ctx.newShaderDataBinding(shaders.m_redToAlphaPipelinePmus, nullptr, nullptr, - gen.m_instBufPmus.get(), nullptr, 1, uniforms, - nullptr, texCount, textures, nullptr, nullptr); - } - - return nullptr; - } -}; - -TShader::IDataBindingFactory* CElementGenShaders::Initialize(boo::VulkanDataFactory::Context& ctx) -{ - static const boo::VertexElementDescriptor TexFmtTex[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 0}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 1}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 2}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 3}, - {nullptr, nullptr, boo::VertexSemantic::Color | boo::VertexSemantic::Instanced}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 0}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 1}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 2}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 3} - }; - m_vtxFormatTex = ctx.newVertexFormat(9, TexFmtTex); - - static const boo::VertexElementDescriptor TexFmtIndTex[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 0}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 1}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 2}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 3}, - {nullptr, nullptr, boo::VertexSemantic::Color | boo::VertexSemantic::Instanced}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 0}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 1}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 2}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 3}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 4}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 5}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 6}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 7} - }; - m_vtxFormatIndTex = ctx.newVertexFormat(13, TexFmtIndTex); - - static const boo::VertexElementDescriptor TexFmtNoTex[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 0}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 1}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 2}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 3}, - {nullptr, nullptr, boo::VertexSemantic::Color | boo::VertexSemantic::Instanced} - }; - m_vtxFormatNoTex = ctx.newVertexFormat(5, TexFmtNoTex); - - m_texZTestZWrite = ctx.newShaderPipeline(VS_GLSL_TEX, FS_GLSL_TEX, m_vtxFormatTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, true, - true, false, boo::CullMode::None); - m_texNoZTestZWrite = ctx.newShaderPipeline(VS_GLSL_TEX, FS_GLSL_TEX, m_vtxFormatTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::None, true, - true, false, boo::CullMode::None); - m_texZTestNoZWrite = ctx.newShaderPipeline(VS_GLSL_TEX, FS_GLSL_TEX, m_vtxFormatTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - m_texNoZTestNoZWrite = ctx.newShaderPipeline(VS_GLSL_TEX, FS_GLSL_TEX, m_vtxFormatTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::None, false, - true, false, boo::CullMode::None); - - m_texAdditiveZTest = ctx.newShaderPipeline(VS_GLSL_TEX, FS_GLSL_TEX, m_vtxFormatTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - m_texAdditiveNoZTest = ctx.newShaderPipeline(VS_GLSL_TEX, FS_GLSL_TEX, m_vtxFormatTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::None, false, - true, false, boo::CullMode::None); - - m_texRedToAlphaZTest = ctx.newShaderPipeline(VS_GLSL_TEX, FS_GLSL_TEX_REDTOALPHA, m_vtxFormatTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - m_texRedToAlphaNoZTest = ctx.newShaderPipeline(VS_GLSL_TEX, FS_GLSL_TEX_REDTOALPHA, m_vtxFormatTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::None, false, - true, false, boo::CullMode::None); - - m_texZTestNoZWriteSub = ctx.newShaderPipeline(VS_GLSL_TEX, FS_GLSL_TEX, m_vtxFormatTex, - boo::BlendFactor::Subtract, boo::BlendFactor::Subtract, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - m_texNoZTestNoZWriteSub = ctx.newShaderPipeline(VS_GLSL_TEX, FS_GLSL_TEX, m_vtxFormatTex, - boo::BlendFactor::Subtract, boo::BlendFactor::Subtract, - boo::Primitive::TriStrips, boo::ZTest::None, false, - true, false, boo::CullMode::None); - - m_texRedToAlphaZTestSub = ctx.newShaderPipeline(VS_GLSL_TEX, FS_GLSL_TEX_REDTOALPHA, m_vtxFormatTex, - boo::BlendFactor::Subtract, boo::BlendFactor::Subtract, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - m_texRedToAlphaNoZTestSub = ctx.newShaderPipeline(VS_GLSL_TEX, FS_GLSL_TEX_REDTOALPHA, m_vtxFormatTex, - boo::BlendFactor::Subtract, boo::BlendFactor::Subtract, - boo::Primitive::TriStrips, boo::ZTest::None, false, - true, false, boo::CullMode::None); - - m_indTexZWrite = ctx.newShaderPipeline(VS_GLSL_INDTEX, FS_GLSL_INDTEX, m_vtxFormatIndTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, true, - true, false, boo::CullMode::None); - m_indTexNoZWrite = ctx.newShaderPipeline(VS_GLSL_INDTEX, FS_GLSL_INDTEX, m_vtxFormatIndTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - m_indTexAdditive = ctx.newShaderPipeline(VS_GLSL_INDTEX, FS_GLSL_INDTEX, m_vtxFormatIndTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, true, - true, false, boo::CullMode::None); - - m_cindTexZWrite = ctx.newShaderPipeline(VS_GLSL_INDTEX, FS_GLSL_CINDTEX, m_vtxFormatIndTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, true, - true, false, boo::CullMode::None); - m_cindTexNoZWrite = ctx.newShaderPipeline(VS_GLSL_INDTEX, FS_GLSL_CINDTEX, m_vtxFormatIndTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - m_cindTexAdditive = ctx.newShaderPipeline(VS_GLSL_INDTEX, FS_GLSL_CINDTEX, m_vtxFormatIndTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, true, - true, false, boo::CullMode::None); - - m_noTexZTestZWrite = ctx.newShaderPipeline(VS_GLSL_NOTEX, FS_GLSL_NOTEX, m_vtxFormatNoTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, true, - true, false, boo::CullMode::None); - m_noTexNoZTestZWrite = ctx.newShaderPipeline(VS_GLSL_NOTEX, FS_GLSL_NOTEX, m_vtxFormatNoTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::None, true, - true, false, boo::CullMode::None); - m_noTexZTestNoZWrite = ctx.newShaderPipeline(VS_GLSL_NOTEX, FS_GLSL_NOTEX, m_vtxFormatNoTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - m_noTexNoZTestNoZWrite = ctx.newShaderPipeline(VS_GLSL_NOTEX, FS_GLSL_NOTEX, m_vtxFormatNoTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::None, false, - true, false, boo::CullMode::None); - - m_noTexAdditiveZTest = ctx.newShaderPipeline(VS_GLSL_NOTEX, FS_GLSL_NOTEX, m_vtxFormatNoTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - m_noTexAdditiveNoZTest = ctx.newShaderPipeline(VS_GLSL_NOTEX, FS_GLSL_NOTEX, m_vtxFormatNoTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::None, false, - true, false, boo::CullMode::None); - - return new struct VulkanElementDataBindingFactory; -} - -template <> -void CElementGenShaders::Shutdown() -{ - m_vtxFormatTex.reset(); - m_vtxFormatIndTex.reset(); - m_vtxFormatNoTex.reset(); - - m_texZTestZWrite.reset(); - m_texNoZTestZWrite.reset(); - m_texZTestNoZWrite.reset(); - m_texNoZTestNoZWrite.reset(); - m_texAdditiveZTest.reset(); - m_texAdditiveNoZTest.reset(); - m_texRedToAlphaZTest.reset(); - m_texRedToAlphaNoZTest.reset(); - m_texZTestNoZWriteSub.reset(); - m_texNoZTestNoZWriteSub.reset(); - m_texRedToAlphaZTestSub.reset(); - m_texRedToAlphaNoZTestSub.reset(); - - m_indTexZWrite.reset(); - m_indTexNoZWrite.reset(); - m_indTexAdditive.reset(); - - m_cindTexZWrite.reset(); - m_cindTexNoZWrite.reset(); - m_cindTexAdditive.reset(); - - m_noTexZTestZWrite.reset(); - m_noTexNoZTestZWrite.reset(); - m_noTexZTestNoZWrite.reset(); - m_noTexNoZTestNoZWrite.reset(); - m_noTexAdditiveZTest.reset(); - m_noTexAdditiveNoZTest.reset(); -} -#endif - -} diff --git a/Runtime/Graphics/Shaders/CElementGenShadersHLSL.cpp b/Runtime/Graphics/Shaders/CElementGenShadersHLSL.cpp deleted file mode 100644 index d9c93a3de..000000000 --- a/Runtime/Graphics/Shaders/CElementGenShadersHLSL.cpp +++ /dev/null @@ -1,474 +0,0 @@ -#include "CElementGenShaders.hpp" -#include "Particle/CElementGen.hpp" -#include "Particle/CGenDescription.hpp" -#include "Particle/CElectricDescription.hpp" -#include "Particle/CSwooshDescription.hpp" -#include "Graphics/CModel.hpp" - -namespace urde -{ - -static const char* VS_HLSL_TEX = -"struct VertData\n" -"{\n" -" float4 posIn[4] : POSITION;\n" -" float4 colorIn : COLOR;\n" -" float4 uvsIn[4] : UV;\n" -"};\n" -"\n" -"cbuffer ParticleUniform : register(b0)\n" -"{\n" -" float4x4 mvp;\n" -" float4 moduColor;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float4 color : COLOR;\n" -" float2 uv : UV;\n" -"};\n" -"\n" -"VertToFrag main(in VertData v, in uint vertId : SV_VertexID)\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.color = v.colorIn * moduColor;\n" -" vtf.uv = v.uvsIn[vertId].xy;\n" -" vtf.position = mul(mvp, v.posIn[vertId]);\n" -" return vtf;\n" -"}\n"; - -static const char* FS_HLSL_TEX = -"SamplerState samp : register(s0);\n" -"Texture2D tex0 : register(t0);\n" -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float4 color : COLOR;\n" -" float2 uv : UV;\n" -"};\n" -"\n" -"float4 main(in VertToFrag vtf) : SV_Target0\n" -"{\n" -" return vtf.color * tex0.Sample(samp, vtf.uv);\n" -"}\n"; - -static const char* FS_HLSL_TEX_REDTOALPHA = -"SamplerState samp : register(s0);\n" -"Texture2D tex0 : register(t0);\n" -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float4 color : COLOR;\n" -" float2 uv : UV;\n" -"};\n" -"\n" -"float4 main(in VertToFrag vtf) : SV_Target0\n" -"{\n" -" return float4(vtf.color.rgb, tex0.Sample(samp, vtf.uv).r);\n" -"}\n"; - -static const char* VS_HLSL_INDTEX = -"struct VertData\n" -"{\n" -" float4 posIn[4] : POSITION;\n" -" float4 colorIn : COLOR;\n" -" float4 uvsInTexrTind[4] : UV0;\n" -" float4 uvsInScene : UV4;\n" -"};\n" -"\n" -"cbuffer ParticleUniform : register(b0)\n" -"{\n" -" float4x4 mvp;\n" -" float4 moduColor;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float4 color : COLOR;\n" -" float4 uvScene : UV0;\n" -" float2 uvTexr : UV1;\n" -" float2 uvTind : UV2;\n" -"};\n" -"\n" -"VertToFrag main(in VertData v, in uint vertId : SV_VertexID)\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.color = v.colorIn * moduColor;\n" -" vtf.uvScene = v.uvsInScene;\n" -" vtf.uvScene.y = 1.0 - vtf.uvScene.y;\n" -" vtf.uvScene.w = 1.0 - vtf.uvScene.w;\n" -" vtf.uvTexr = v.uvsInTexrTind[vertId].xy;\n" -" vtf.uvTind = v.uvsInTexrTind[vertId].zw;\n" -" vtf.position = mul(mvp, v.posIn[vertId]);\n" -" return vtf;\n" -"}\n"; - -static const char* FS_HLSL_INDTEX = -"SamplerState samp : register(s0);\n" -"Texture2D tex0 : register(t0);\n" -"Texture2D tex1 : register(t1);\n" -"Texture2D tex2 : register(t2);\n" -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float4 color : COLOR;\n" -" float4 uvScene : UV0;\n" -" float2 uvTexr : UV1;\n" -" float2 uvTind : UV2;\n" -"};\n" -"\n" -"float4 main(in VertToFrag vtf) : SV_Target0\n" -"{\n" -" float2 tindTexel = tex2.Sample(samp, vtf.uvTind).zw;\n" -" float4 sceneTexel = tex1.Sample(samp, lerp(vtf.uvScene.xy, vtf.uvScene.zw, tindTexel));\n" -" float4 texrTexel = tex0.Sample(samp, vtf.uvTexr);\n" -" float4 colorOut = vtf.color * float4(sceneTexel.rgb, 1.0) + texrTexel;\n" -" colorOut.a = vtf.color.a * texrTexel.a;\n" -" return colorOut;\n" -"}\n"; - -static const char* FS_HLSL_CINDTEX = -"SamplerState samp : register(s0);\n" -"Texture2D tex0 : register(t0);\n" -"Texture2D tex1 : register(t1);\n" -"Texture2D tex2 : register(t2);\n" -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float4 color : COLOR;\n" -" float4 uvScene : UV0;\n" -" float2 uvTexr : UV1;\n" -" float2 uvTind : UV2;\n" -"};\n" -"\n" -"float4 main(in VertToFrag vtf) : SV_Target0\n" -"{\n" -" float2 tindTexel = tex2.Sample(samp, vtf.uvTind).ba;\n" -" float4 sceneTexel = tex1.Sample(samp, lerp(vtf.uvScene.xy, vtf.uvScene.zw, tindTexel));\n" -" return vtf.color * float4(sceneTexel.rgb, 1.0) * tex0.Sample(samp, vtf.uvTexr);\n" -"}\n"; - -static const char* VS_HLSL_NOTEX = -"struct VertData\n" -"{\n" -" float4 posIn[4] : POSITION;\n" -" float4 colorIn : COLOR;\n" -"};\n" -"\n" -"cbuffer ParticleUniform : register(b0)\n" -"{\n" -" float4x4 mvp;\n" -" float4 moduColor;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float4 color : COLOR;\n" -"};\n" -"\n" -"VertToFrag main(in VertData v, in uint vertId : SV_VertexID)\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.color = v.colorIn * moduColor;\n" -" vtf.position = mul(mvp, v.posIn[vertId]);\n" -" return vtf;\n" -"}\n"; - -static const char* FS_HLSL_NOTEX = -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float4 color : COLOR;\n" -"};\n" -"\n" -"float4 main(in VertToFrag vtf) : SV_Target0\n" -"{\n" -" return vtf.color;\n" -"}\n"; - -struct D3DElementDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken - BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CElementGenShaders& shaders) - { - CElementGen& gen = shaders.m_gen; - CGenDescription* desc = gen.GetDesc(); - - CUVElement* texr = desc->x54_x40_TEXR.get(); - CUVElement* tind = desc->x58_x44_TIND.get(); - int texCount = 0; - boo::ObjToken textures[3]; - - if (texr) - { - textures[0] = texr->GetValueTexture(0).GetObj()->GetBooTexture(); - texCount = 1; - if (tind) - { - textures[1] = CGraphics::g_SpareTexture.get(); - textures[2] = tind->GetValueTexture(0).GetObj()->GetBooTexture(); - texCount = 3; - } - } - - if (gen.m_instBuf) - { - boo::ObjToken uniforms[] = {gen.m_uniformBuf.get()}; - - if (shaders.m_regPipeline) - gen.m_normalDataBind = ctx.newShaderDataBinding(shaders.m_regPipeline, nullptr, nullptr, - gen.m_instBuf.get(), nullptr, 1, uniforms, - nullptr, texCount, textures, - nullptr, nullptr); - if (shaders.m_regPipelineSub) - gen.m_normalSubDataBind = ctx.newShaderDataBinding(shaders.m_regPipelineSub, nullptr, nullptr, - gen.m_instBuf.get(), nullptr, 1, uniforms, - nullptr, texCount, textures, - nullptr, nullptr); - if (shaders.m_redToAlphaPipeline) - gen.m_redToAlphaDataBind = ctx.newShaderDataBinding(shaders.m_redToAlphaPipeline, nullptr, nullptr, - gen.m_instBuf.get(), nullptr, 1, uniforms, - nullptr, texCount, textures, - nullptr, nullptr); - if (shaders.m_redToAlphaPipelineSub) - gen.m_redToAlphaSubDataBind = ctx.newShaderDataBinding(shaders.m_redToAlphaPipelineSub, nullptr, nullptr, - gen.m_instBuf.get(), nullptr, 1, uniforms, - nullptr, texCount, textures, - nullptr, nullptr); - } - - if (gen.m_instBufPmus) - { - boo::ObjToken uniforms[] = {gen.m_uniformBufPmus.get()}; - texCount = std::min(texCount, 1); - - if (shaders.m_regPipelinePmus) - gen.m_normalDataBindPmus = ctx.newShaderDataBinding(shaders.m_regPipelinePmus, nullptr, nullptr, - gen.m_instBuf.get(), nullptr, 1, uniforms, - nullptr, texCount, textures, - nullptr, nullptr); - if (shaders.m_redToAlphaPipelinePmus) - gen.m_redToAlphaDataBindPmus = ctx.newShaderDataBinding(shaders.m_redToAlphaPipelinePmus, nullptr, nullptr, - gen.m_instBuf.get(), nullptr, 1, uniforms, - nullptr, texCount, textures, - nullptr, nullptr); - } - - return nullptr; - } -}; - -TShader::IDataBindingFactory* CElementGenShaders::Initialize(boo::D3DDataFactory::Context& ctx) -{ - static const boo::VertexElementDescriptor TexFmtTex[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 0}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 1}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 2}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 3}, - {nullptr, nullptr, boo::VertexSemantic::Color | boo::VertexSemantic::Instanced}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 0}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 1}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 2}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 3} - }; - m_vtxFormatTex = ctx.newVertexFormat(9, TexFmtTex); - - static const boo::VertexElementDescriptor TexFmtIndTex[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 0}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 1}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 2}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 3}, - {nullptr, nullptr, boo::VertexSemantic::Color | boo::VertexSemantic::Instanced}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 0}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 1}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 2}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 3}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 4} - }; - m_vtxFormatIndTex = ctx.newVertexFormat(10, TexFmtIndTex); - - static const boo::VertexElementDescriptor TexFmtNoTex[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 0}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 1}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 2}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 3}, - {nullptr, nullptr, boo::VertexSemantic::Color | boo::VertexSemantic::Instanced} - }; - m_vtxFormatNoTex = ctx.newVertexFormat(5, TexFmtNoTex); - - m_texZTestZWrite = ctx.newShaderPipeline(VS_HLSL_TEX, FS_HLSL_TEX, nullptr, nullptr, - nullptr, m_vtxFormatTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, true, - true, false, boo::CullMode::None); - m_texNoZTestZWrite = ctx.newShaderPipeline(VS_HLSL_TEX, FS_HLSL_TEX, nullptr, nullptr, - nullptr, m_vtxFormatTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::None, true, - true, false, boo::CullMode::None); - m_texZTestNoZWrite = ctx.newShaderPipeline(VS_HLSL_TEX, FS_HLSL_TEX, nullptr, nullptr, - nullptr, m_vtxFormatTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - m_texNoZTestNoZWrite = ctx.newShaderPipeline(VS_HLSL_TEX, FS_HLSL_TEX, nullptr, nullptr, - nullptr, m_vtxFormatTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::None, false, - true, false, boo::CullMode::None); - - m_texAdditiveZTest = ctx.newShaderPipeline(VS_HLSL_TEX, FS_HLSL_TEX, nullptr, nullptr, - nullptr, m_vtxFormatTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - m_texAdditiveNoZTest = ctx.newShaderPipeline(VS_HLSL_TEX, FS_HLSL_TEX, nullptr, nullptr, - nullptr, m_vtxFormatTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::None, false, - true, false, boo::CullMode::None); - - m_texRedToAlphaZTest = ctx.newShaderPipeline(VS_HLSL_TEX, FS_HLSL_TEX_REDTOALPHA, nullptr, nullptr, - nullptr, m_vtxFormatTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - m_texRedToAlphaNoZTest = ctx.newShaderPipeline(VS_HLSL_TEX, FS_HLSL_TEX_REDTOALPHA, nullptr, nullptr, - nullptr, m_vtxFormatTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::None, false, - true, false, boo::CullMode::None); - - m_texZTestNoZWriteSub = ctx.newShaderPipeline(VS_HLSL_TEX, FS_HLSL_TEX, nullptr, nullptr, - nullptr, m_vtxFormatTex, - boo::BlendFactor::Subtract, boo::BlendFactor::Subtract, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - m_texNoZTestNoZWriteSub = ctx.newShaderPipeline(VS_HLSL_TEX, FS_HLSL_TEX, nullptr, nullptr, - nullptr, m_vtxFormatTex, - boo::BlendFactor::Subtract, boo::BlendFactor::Subtract, - boo::Primitive::TriStrips, boo::ZTest::None, false, - true, false, boo::CullMode::None); - - m_texRedToAlphaZTestSub = ctx.newShaderPipeline(VS_HLSL_TEX, FS_HLSL_TEX_REDTOALPHA, nullptr, nullptr, - nullptr, m_vtxFormatTex, - boo::BlendFactor::Subtract, boo::BlendFactor::Subtract, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - m_texRedToAlphaNoZTestSub = ctx.newShaderPipeline(VS_HLSL_TEX, FS_HLSL_TEX_REDTOALPHA, nullptr, nullptr, - nullptr, m_vtxFormatTex, - boo::BlendFactor::Subtract, boo::BlendFactor::Subtract, - boo::Primitive::TriStrips, boo::ZTest::None, false, - true, false, boo::CullMode::None); - - m_indTexZWrite = ctx.newShaderPipeline(VS_HLSL_INDTEX, FS_HLSL_INDTEX, nullptr, nullptr, - nullptr, m_vtxFormatIndTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::None, true, - true, false, boo::CullMode::None); - m_indTexNoZWrite = ctx.newShaderPipeline(VS_HLSL_INDTEX, FS_HLSL_INDTEX, nullptr, nullptr, - nullptr, m_vtxFormatIndTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::None, false, - true, false, boo::CullMode::None); - m_indTexAdditive = ctx.newShaderPipeline(VS_HLSL_INDTEX, FS_HLSL_INDTEX, nullptr, nullptr, - nullptr, m_vtxFormatIndTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::None, true, - true, false, boo::CullMode::None); - - m_cindTexZWrite = ctx.newShaderPipeline(VS_HLSL_INDTEX, FS_HLSL_CINDTEX, nullptr, nullptr, - nullptr, m_vtxFormatIndTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::None, true, - true, false, boo::CullMode::None); - m_cindTexNoZWrite = ctx.newShaderPipeline(VS_HLSL_INDTEX, FS_HLSL_CINDTEX, nullptr, nullptr, - nullptr, m_vtxFormatIndTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::None, false, - true, false, boo::CullMode::None); - m_cindTexAdditive = ctx.newShaderPipeline(VS_HLSL_INDTEX, FS_HLSL_CINDTEX, nullptr, nullptr, - nullptr, m_vtxFormatIndTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::None, true, - true, false, boo::CullMode::None); - - m_noTexZTestZWrite = ctx.newShaderPipeline(VS_HLSL_NOTEX, FS_HLSL_NOTEX, nullptr, nullptr, - nullptr, m_vtxFormatNoTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, true, - true, false, boo::CullMode::None); - m_noTexNoZTestZWrite = ctx.newShaderPipeline(VS_HLSL_NOTEX, FS_HLSL_NOTEX, nullptr, nullptr, - nullptr, m_vtxFormatNoTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::None, true, - true, false, boo::CullMode::None); - m_noTexZTestNoZWrite = ctx.newShaderPipeline(VS_HLSL_NOTEX, FS_HLSL_NOTEX, nullptr, nullptr, - nullptr, m_vtxFormatNoTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - m_noTexNoZTestNoZWrite = ctx.newShaderPipeline(VS_HLSL_NOTEX, FS_HLSL_NOTEX, nullptr, nullptr, - nullptr, m_vtxFormatNoTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::None, false, - true, false, boo::CullMode::None); - - m_noTexAdditiveZTest = ctx.newShaderPipeline(VS_HLSL_NOTEX, FS_HLSL_NOTEX, nullptr, nullptr, - nullptr, m_vtxFormatNoTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, true, - true, false, boo::CullMode::None); - m_noTexAdditiveNoZTest = ctx.newShaderPipeline(VS_HLSL_NOTEX, FS_HLSL_NOTEX, nullptr, nullptr, - nullptr, m_vtxFormatNoTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::None, true, - true, false, boo::CullMode::None); - - return new struct D3DElementDataBindingFactory; -} - -template <> -void CElementGenShaders::Shutdown() -{ - m_vtxFormatTex.reset(); - m_vtxFormatIndTex.reset(); - m_vtxFormatNoTex.reset(); - - m_texZTestZWrite.reset(); - m_texNoZTestZWrite.reset(); - m_texZTestNoZWrite.reset(); - m_texNoZTestNoZWrite.reset(); - m_texAdditiveZTest.reset(); - m_texAdditiveNoZTest.reset(); - m_texRedToAlphaZTest.reset(); - m_texRedToAlphaNoZTest.reset(); - m_texZTestNoZWriteSub.reset(); - m_texNoZTestNoZWriteSub.reset(); - m_texRedToAlphaZTestSub.reset(); - m_texRedToAlphaNoZTestSub.reset(); - - m_indTexZWrite.reset(); - m_indTexNoZWrite.reset(); - m_indTexAdditive.reset(); - - m_cindTexZWrite.reset(); - m_cindTexNoZWrite.reset(); - m_cindTexAdditive.reset(); - - m_noTexZTestZWrite.reset(); - m_noTexNoZTestZWrite.reset(); - m_noTexZTestNoZWrite.reset(); - m_noTexNoZTestNoZWrite.reset(); - m_noTexAdditiveZTest.reset(); - m_noTexAdditiveNoZTest.reset(); -} - -} diff --git a/Runtime/Graphics/Shaders/CElementGenShadersMetal.cpp b/Runtime/Graphics/Shaders/CElementGenShadersMetal.cpp deleted file mode 100644 index 35d9ae6ed..000000000 --- a/Runtime/Graphics/Shaders/CElementGenShadersMetal.cpp +++ /dev/null @@ -1,444 +0,0 @@ -#include "CElementGenShaders.hpp" -#include "Particle/CElementGen.hpp" -#include "Particle/CGenDescription.hpp" - -namespace urde -{ - -static const char* VS_METAL_TEX = -"#include \n" -"using namespace metal;\n" -"struct VertData\n" -"{\n" -" float4 posIn[4];\n" -" float4 colorIn;\n" -" float4 uvsIn[4];\n" -"};\n" -"\n" -"struct ParticleUniform\n" -"{\n" -" float4x4 mvp;\n" -" float4 moduColor;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float4 color;\n" -" float2 uv;\n" -"};\n" -"\n" -"vertex VertToFrag vmain(constant VertData* va [[ buffer(1) ]],\n" -" uint vertId [[ vertex_id ]], uint instId [[ instance_id ]],\n" -" constant ParticleUniform& particle [[ buffer(2) ]])\n" -"{\n" -" VertToFrag vtf;\n" -" constant VertData& v = va[instId];\n" -" vtf.color = v.colorIn * particle.moduColor;\n" -" vtf.uv = v.uvsIn[vertId].xy;\n" -" vtf.position = particle.mvp * v.posIn[vertId];\n" -" return vtf;\n" -"}\n"; - -static const char* FS_METAL_TEX = -"#include \n" -"using namespace metal;\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float4 color;\n" -" float2 uv;\n" -"};\n" -"\n" -"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n" -" sampler samp [[ sampler(0) ]],\n" -" texture2d tex0 [[ texture(0) ]])\n" -"{\n" -" return vtf.color * tex0.sample(samp, vtf.uv);\n" -"}\n"; - -static const char* FS_METAL_TEX_REDTOALPHA = -"#include \n" -"using namespace metal;\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float4 color;\n" -" float2 uv;\n" -"};\n" -"\n" -"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n" -" sampler samp [[ sampler(0) ]],\n" -" texture2d tex0 [[ texture(0) ]])\n" -"{\n" -" return float4(vtf.color.rgb, tex0.sample(samp, vtf.uv).r);\n" -"}\n"; - -static const char* VS_METAL_INDTEX = -"#include \n" -"using namespace metal;\n" -"struct VertData\n" -"{\n" -" float4 posIn[4];\n" -" float4 colorIn;\n" -" float4 uvsInTexrTind[4];\n" -" float4 uvsInScene;\n" -"};\n" -"\n" -"struct ParticleUniform\n" -"{\n" -" float4x4 mvp;\n" -" float4 moduColor;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float4 color;\n" -" float4 uvScene;\n" -" float2 uvTexr;\n" -" float2 uvTind;\n" -"};\n" -"\n" -"vertex VertToFrag vmain(constant VertData* va [[ buffer(1) ]],\n" -" uint vertId [[ vertex_id ]], uint instId [[ instance_id ]],\n" -" constant ParticleUniform& particle [[ buffer(2) ]])\n" -"{\n" -" VertToFrag vtf;\n" -" constant VertData& v = va[instId];\n" -" vtf.color = v.colorIn * particle.moduColor;\n" -" vtf.uvScene = v.uvsInScene;\n" -" vtf.uvScene.y = 1.0 - vtf.uvScene.y;\n" -" vtf.uvScene.w = 1.0 - vtf.uvScene.w;\n" -" vtf.uvTexr = v.uvsInTexrTind[vertId].xy;\n" -" vtf.uvTind = v.uvsInTexrTind[vertId].zw;\n" -" vtf.position = particle.mvp * v.posIn[vertId];\n" -" return vtf;\n" -"}\n"; - -static const char* FS_METAL_INDTEX = -"#include \n" -"using namespace metal;\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float4 color;\n" -" float4 uvScene;\n" -" float2 uvTexr;\n" -" float2 uvTind;\n" -"};\n" -"\n" -"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n" -" sampler samp [[ sampler(0) ]]," -" texture2d tex0 [[ texture(0) ]],\n" -" texture2d tex1 [[ texture(1) ]],\n" -" texture2d tex2 [[ texture(2) ]])\n" -"{\n" -" float2 tindTexel = tex2.sample(samp, vtf.uvTind).ba;\n" -" float4 sceneTexel = tex1.sample(samp, mix(vtf.uvScene.xy, vtf.uvScene.zw, tindTexel));\n" -" float4 texrTexel = tex0.sample(samp, vtf.uvTexr);\n" -" float4 colr = vtf.color * float4(sceneTexel.rgb, 1.0) + texrTexel;\n" -" return float4(colr.rgb, vtf.color.a * texrTexel.a);" -"}\n"; - -static const char* FS_METAL_CINDTEX = -"#include \n" -"using namespace metal;\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float4 color;\n" -" float4 uvScene;\n" -" float2 uvTexr;\n" -" float2 uvTind;\n" -"};\n" -"\n" -"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n" -" sampler samp [[ sampler(0) ]],\n" -" texture2d tex0 [[ texture(0) ]],\n" -" texture2d tex1 [[ texture(1) ]],\n" -" texture2d tex2 [[ texture(2) ]])\n" -"{\n" -" float2 tindTexel = tex2.sample(samp, vtf.uvTind).ba;\n" -" float4 sceneTexel = tex1.sample(samp, mix(vtf.uvScene.xy, vtf.uvScene.zw, tindTexel));\n" -" return vtf.color * float4(sceneTexel.rgb, 1.0) * tex0.sample(samp, vtf.uvTexr);\n" -"}\n"; - -static const char* VS_METAL_NOTEX = -"#include \n" -"using namespace metal;\n" -"struct VertData\n" -"{\n" -" float4 posIn[4];\n" -" float4 colorIn;\n" -"};\n" -"\n" -"struct ParticleUniform\n" -"{\n" -" float4x4 mvp;\n" -" float4 moduColor;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float4 color;\n" -"};\n" -"\n" -"vertex VertToFrag vmain(constant VertData* va [[ buffer(1) ]],\n" -" uint vertId [[ vertex_id ]], uint instId [[ instance_id ]],\n" -" constant ParticleUniform& particle [[ buffer(2) ]])\n" -"{\n" -" VertToFrag vtf;\n" -" constant VertData& v = va[instId];\n" -" vtf.color = v.colorIn * particle.moduColor;\n" -" vtf.position = particle.mvp * v.posIn[vertId];\n" -" return vtf;\n" -"}\n"; - -static const char* FS_METAL_NOTEX = -"#include \n" -"using namespace metal;\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float4 color;\n" -"};\n" -"\n" -"fragment float4 fmain(VertToFrag vtf [[ stage_in ]])\n" -"{\n" -" return vtf.color;\n" -"}\n"; - -struct MetalElementDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CElementGenShaders& shader) - { - CElementGen& gen = shader.m_gen; - CGenDescription* desc = gen.GetDesc(); - - CUVElement* texr = desc->x54_x40_TEXR.get(); - CUVElement* tind = desc->x58_x44_TIND.get(); - int texCount = 0; - boo::ObjToken textures[3]; - - if (texr) - { - textures[0] = texr->GetValueTexture(0).GetObj()->GetBooTexture(); - texCount = 1; - if (tind) - { - textures[1] = CGraphics::g_SpareTexture.get(); - textures[2] = tind->GetValueTexture(0).GetObj()->GetBooTexture(); - texCount = 3; - } - } - - if (gen.m_instBuf) - { - boo::ObjToken uniforms[] = {gen.m_uniformBuf.get()}; - - if (shader.m_regPipeline) - gen.m_normalDataBind = ctx.newShaderDataBinding(shader.m_regPipeline, nullptr, nullptr, - gen.m_instBuf.get(), nullptr, 1, uniforms, - nullptr, texCount, textures, nullptr, nullptr); - if (shader.m_regPipelineSub) - gen.m_normalSubDataBind = ctx.newShaderDataBinding(shader.m_regPipelineSub, nullptr, nullptr, - gen.m_instBuf.get(), nullptr, 1, uniforms, - nullptr, texCount, textures, nullptr, nullptr); - if (shader.m_redToAlphaPipeline) - gen.m_redToAlphaDataBind = ctx.newShaderDataBinding(shader.m_redToAlphaPipeline, nullptr, nullptr, - gen.m_instBuf.get(), nullptr, 1, uniforms, - nullptr, texCount, textures, nullptr, nullptr); - if (shader.m_redToAlphaPipelineSub) - gen.m_redToAlphaSubDataBind = ctx.newShaderDataBinding(shader.m_redToAlphaPipelineSub, nullptr, nullptr, - gen.m_instBuf.get(), nullptr, 1, uniforms, - nullptr, texCount, textures, nullptr, nullptr); - } - - if (gen.m_instBufPmus) - { - boo::ObjToken uniforms[] = {gen.m_uniformBufPmus.get()}; - texCount = std::min(texCount, 1); - - if (shader.m_regPipelinePmus) - gen.m_normalDataBindPmus = ctx.newShaderDataBinding(shader.m_regPipelinePmus, nullptr, nullptr, - gen.m_instBufPmus.get(), nullptr, 1, uniforms, - nullptr, texCount, textures, nullptr, nullptr); - if (shader.m_redToAlphaPipelinePmus) - gen.m_redToAlphaDataBindPmus = ctx.newShaderDataBinding(shader.m_redToAlphaPipelinePmus, nullptr, nullptr, - gen.m_instBufPmus.get(), nullptr, 1, uniforms, - nullptr, texCount, textures, nullptr, nullptr); - } - - return {}; - } -}; - -TShader::IDataBindingFactory* CElementGenShaders::Initialize(boo::MetalDataFactory::Context& ctx) -{ - static const boo::VertexElementDescriptor TexFmtTex[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 0}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 1}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 2}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 3}, - {nullptr, nullptr, boo::VertexSemantic::Color | boo::VertexSemantic::Instanced}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 0}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 1}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 2}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 3} - }; - m_vtxFormatTex = ctx.newVertexFormat(9, TexFmtTex); - - static const boo::VertexElementDescriptor TexFmtIndTex[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 0}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 1}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 2}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 3}, - {nullptr, nullptr, boo::VertexSemantic::Color | boo::VertexSemantic::Instanced}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 0}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 1}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 2}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 3}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 4} - }; - m_vtxFormatIndTex = ctx.newVertexFormat(10, TexFmtIndTex); - - static const boo::VertexElementDescriptor TexFmtNoTex[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 0}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 1}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 2}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 3}, - {nullptr, nullptr, boo::VertexSemantic::Color | boo::VertexSemantic::Instanced} - }; - m_vtxFormatNoTex = ctx.newVertexFormat(5, TexFmtNoTex); - - m_texZTestZWrite = ctx.newShaderPipeline(VS_METAL_TEX, FS_METAL_TEX, nullptr, nullptr, m_vtxFormatTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, true, true, false, boo::CullMode::None); - m_texNoZTestZWrite = ctx.newShaderPipeline(VS_METAL_TEX, FS_METAL_TEX, nullptr, nullptr, m_vtxFormatTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::None, true, true, false, boo::CullMode::None); - m_texZTestNoZWrite = ctx.newShaderPipeline(VS_METAL_TEX, FS_METAL_TEX, nullptr, nullptr, m_vtxFormatTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, true, false, boo::CullMode::None); - m_texNoZTestNoZWrite = ctx.newShaderPipeline(VS_METAL_TEX, FS_METAL_TEX, nullptr, nullptr, m_vtxFormatTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::None, false, true, false, boo::CullMode::None); - - m_texAdditiveZTest = ctx.newShaderPipeline(VS_METAL_TEX, FS_METAL_TEX, nullptr, nullptr, m_vtxFormatTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, true, false, boo::CullMode::None); - m_texAdditiveNoZTest = ctx.newShaderPipeline(VS_METAL_TEX, FS_METAL_TEX, nullptr, nullptr, m_vtxFormatTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::None, false, true, false, boo::CullMode::None); - - m_texRedToAlphaZTest = ctx.newShaderPipeline(VS_METAL_TEX, FS_METAL_TEX_REDTOALPHA, nullptr, nullptr, m_vtxFormatTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, true, true, boo::CullMode::None); - m_texRedToAlphaNoZTest = ctx.newShaderPipeline(VS_METAL_TEX, FS_METAL_TEX_REDTOALPHA, nullptr, nullptr, m_vtxFormatTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::None, false, true, true, boo::CullMode::None); - - m_texZTestNoZWriteSub = ctx.newShaderPipeline(VS_METAL_TEX, FS_METAL_TEX, nullptr, nullptr, m_vtxFormatTex, - boo::BlendFactor::Subtract, boo::BlendFactor::Subtract, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - m_texNoZTestNoZWriteSub = ctx.newShaderPipeline(VS_METAL_TEX, FS_METAL_TEX, nullptr, nullptr, m_vtxFormatTex, - boo::BlendFactor::Subtract, boo::BlendFactor::Subtract, - boo::Primitive::TriStrips, boo::ZTest::None, false, - true, false, boo::CullMode::None); - - m_texRedToAlphaZTestSub = ctx.newShaderPipeline(VS_METAL_TEX, FS_METAL_TEX_REDTOALPHA, nullptr, nullptr, m_vtxFormatTex, - boo::BlendFactor::Subtract, boo::BlendFactor::Subtract, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, true, boo::CullMode::None); - m_texRedToAlphaNoZTestSub = ctx.newShaderPipeline(VS_METAL_TEX, FS_METAL_TEX_REDTOALPHA, nullptr, nullptr, m_vtxFormatTex, - boo::BlendFactor::Subtract, boo::BlendFactor::Subtract, - boo::Primitive::TriStrips, boo::ZTest::None, false, - true, true, boo::CullMode::None); - - m_indTexZWrite = ctx.newShaderPipeline(VS_METAL_INDTEX, FS_METAL_INDTEX, nullptr, nullptr, m_vtxFormatIndTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::None, true, true, false, boo::CullMode::None); - m_indTexNoZWrite = ctx.newShaderPipeline(VS_METAL_INDTEX, FS_METAL_INDTEX, nullptr, nullptr, m_vtxFormatIndTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::None, false, true, false, boo::CullMode::None); - m_indTexAdditive = ctx.newShaderPipeline(VS_METAL_INDTEX, FS_METAL_INDTEX, nullptr, nullptr, m_vtxFormatIndTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::None, true, true, false, boo::CullMode::None); - - m_cindTexZWrite = ctx.newShaderPipeline(VS_METAL_INDTEX, FS_METAL_CINDTEX, nullptr, nullptr, m_vtxFormatIndTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::None, true, true, false, boo::CullMode::None); - m_cindTexNoZWrite = ctx.newShaderPipeline(VS_METAL_INDTEX, FS_METAL_CINDTEX, nullptr, nullptr, m_vtxFormatIndTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::None, false, true, false, boo::CullMode::None); - m_cindTexAdditive = ctx.newShaderPipeline(VS_METAL_INDTEX, FS_METAL_CINDTEX, nullptr, nullptr, m_vtxFormatIndTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::None, true, true, false, boo::CullMode::None); - - m_noTexZTestZWrite = ctx.newShaderPipeline(VS_METAL_NOTEX, FS_METAL_NOTEX, nullptr, nullptr, m_vtxFormatNoTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, true, true, false, boo::CullMode::None); - m_noTexNoZTestZWrite = ctx.newShaderPipeline(VS_METAL_NOTEX, FS_METAL_NOTEX, nullptr, nullptr, m_vtxFormatNoTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::None, true, true, false, boo::CullMode::None); - m_noTexZTestNoZWrite = ctx.newShaderPipeline(VS_METAL_NOTEX, FS_METAL_NOTEX, nullptr, nullptr, m_vtxFormatNoTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, true, false, boo::CullMode::None); - m_noTexNoZTestNoZWrite = ctx.newShaderPipeline(VS_METAL_NOTEX, FS_METAL_NOTEX, nullptr, nullptr, m_vtxFormatNoTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::None, false, true, false, boo::CullMode::None); - - m_noTexAdditiveZTest = ctx.newShaderPipeline(VS_METAL_NOTEX, FS_METAL_NOTEX, nullptr, nullptr, m_vtxFormatNoTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, true, false, boo::CullMode::None); - m_noTexAdditiveNoZTest = ctx.newShaderPipeline(VS_METAL_NOTEX, FS_METAL_NOTEX, nullptr, nullptr, m_vtxFormatNoTex, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::None, false, true, false, boo::CullMode::None); - - return new struct MetalElementDataBindingFactory; -} - -template <> -void CElementGenShaders::Shutdown() -{ - m_texZTestZWrite.reset(); - m_texNoZTestZWrite.reset(); - m_texZTestNoZWrite.reset(); - m_texNoZTestNoZWrite.reset(); - m_texAdditiveZTest.reset(); - m_texAdditiveNoZTest.reset(); - m_texRedToAlphaZTest.reset(); - m_texRedToAlphaNoZTest.reset(); - m_texZTestNoZWriteSub.reset(); - m_texNoZTestNoZWriteSub.reset(); - m_texRedToAlphaZTestSub.reset(); - m_texRedToAlphaNoZTestSub.reset(); - - m_indTexZWrite.reset(); - m_indTexNoZWrite.reset(); - m_indTexAdditive.reset(); - - m_cindTexZWrite.reset(); - m_cindTexNoZWrite.reset(); - m_cindTexAdditive.reset(); - - m_noTexZTestZWrite.reset(); - m_noTexNoZTestZWrite.reset(); - m_noTexZTestNoZWrite.reset(); - m_noTexNoZTestNoZWrite.reset(); - m_noTexAdditiveZTest.reset(); - m_noTexAdditiveNoZTest.reset(); - - m_vtxFormatTex.reset(); - m_vtxFormatIndTex.reset(); - m_vtxFormatNoTex.reset(); -} - -} diff --git a/Runtime/Graphics/Shaders/CEnergyBarShader.cpp b/Runtime/Graphics/Shaders/CEnergyBarShader.cpp index 13f78855c..7c780f4d4 100644 --- a/Runtime/Graphics/Shaders/CEnergyBarShader.cpp +++ b/Runtime/Graphics/Shaders/CEnergyBarShader.cpp @@ -1,8 +1,23 @@ #include "CEnergyBarShader.hpp" +#include "hecl/Pipeline.hpp" +#include "Graphics/CGraphics.hpp" +#include "Graphics/CTexture.hpp" namespace urde { +static boo::ObjToken s_Pipeline; + +void CEnergyBarShader::Initialize() +{ + s_Pipeline = hecl::conv->convert(Shader_CEnergyBarShader{}); +} + +void CEnergyBarShader::Shutdown() +{ + s_Pipeline.reset(); +} + void CEnergyBarShader::updateModelMatrix() { m_uniform.m_matrix = CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f(); @@ -24,9 +39,17 @@ void CEnergyBarShader::draw(const zeus::CColor& color0, const std::vector bufs[1]; + boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; + boo::ObjToken texs[] = {m_tex->GetBooTexture()}; for (int i=0 ; i<3 ; ++i) + { m_uniBuf[i] = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); - TShader::BuildShaderDataBinding(ctx, *this); + bufs[0] = m_uniBuf[i].get(); + m_dataBind[i] = ctx.newShaderDataBinding(s_Pipeline, + m_vbo.get(), nullptr, nullptr, 1, bufs, stages, + nullptr, nullptr, 1, texs, nullptr, nullptr); + } return true; } BooTrace); } @@ -75,6 +98,4 @@ void CEnergyBarShader::draw(const zeus::CColor& color0, const std::vector& verts0, const zeus::CColor& color1, const std::vector& verts1, const zeus::CColor& color2, const std::vector& verts2, const CTexture* tex); - - using _CLS = CEnergyBarShader; -#include "TShaderDecl.hpp" }; } diff --git a/Runtime/Graphics/Shaders/CEnergyBarShaderGLSL.cpp b/Runtime/Graphics/Shaders/CEnergyBarShaderGLSL.cpp deleted file mode 100644 index 3c7288228..000000000 --- a/Runtime/Graphics/Shaders/CEnergyBarShaderGLSL.cpp +++ /dev/null @@ -1,146 +0,0 @@ -#include "CEnergyBarShader.hpp" -#include "TShader.hpp" -#include "Graphics/CTexture.hpp" - -namespace urde -{ - -static const char* VS = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"layout(location=0) in vec4 posIn;\n" -"layout(location=1) in vec4 uvIn;\n" -"\n" -"UBINDING0 uniform EnergyBarUniform\n" -"{\n" -" mat4 xf;\n" -" vec4 color;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -" vec2 uv;\n" -"};\n" -"\n" -"SBINDING(0) out VertToFrag vtf;\n" -"void main()\n" -"{\n" -" vtf.color = color;\n" -" vtf.uv = uvIn.xy;\n" -" gl_Position = xf * vec4(posIn.xyz, 1.0);\n" -"}\n"; - -static const char* FS = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -" vec2 uv;\n" -"};\n" -"\n" -"SBINDING(0) in VertToFrag vtf;\n" -"layout(location=0) out vec4 colorOut;\n" -"TBINDING0 uniform sampler2D tex;\n" -"void main()\n" -"{\n" -" colorOut = vtf.color * texture(tex, vtf.uv);\n" -"}\n"; - -URDE_DECL_SPECIALIZE_SHADER(CEnergyBarShader) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_Pipeline; - -struct CEnergyBarShaderGLDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CEnergyBarShader& filter) - { - boo::GLDataFactory::Context& cctx = static_cast(ctx); - - const boo::VertexElementDescriptor VtxVmt[] = - { - {filter.m_vbo.get(), nullptr, boo::VertexSemantic::Position4}, - {filter.m_vbo.get(), nullptr, boo::VertexSemantic::UV4} - }; - boo::ObjToken vtxFmt = ctx.newVertexFormat(2, VtxVmt); - boo::ObjToken bufs[1]; - boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; - boo::ObjToken texs[] = {filter.m_tex->GetBooTexture()}; - for (int i=0 ; i<3 ; ++i) - { - bufs[0] = filter.m_uniBuf[i].get(); - filter.m_dataBind[i] = cctx.newShaderDataBinding(s_Pipeline, - vtxFmt, filter.m_vbo.get(), nullptr, nullptr, - 1, bufs, stages, nullptr, nullptr, 1, texs, nullptr, nullptr); - } - return filter.m_dataBind[0]; - } -}; - -#if BOO_HAS_VULKAN -struct CEnergyBarShaderVulkanDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CEnergyBarShader& filter) - { - boo::VulkanDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken bufs[1]; - boo::ObjToken texs[] = {filter.m_tex->GetBooTexture()}; - for (int i=0 ; i<3 ; ++i) - { - bufs[0] = filter.m_uniBuf[i].get(); - filter.m_dataBind[i] = cctx.newShaderDataBinding(s_Pipeline, s_VtxFmt, - filter.m_vbo.get(), nullptr, nullptr, 1, bufs, - nullptr, nullptr, nullptr, 1, texs, nullptr, nullptr); - } - return filter.m_dataBind[0]; - } -}; -#endif - -TShader::IDataBindingFactory* -CEnergyBarShader::Initialize(boo::GLDataFactory::Context& ctx) -{ - const char* uniNames[] = {"EnergyBarUniform"}; - const char* texNames[] = {"tex"}; - s_Pipeline = ctx.newShaderPipeline(VS, FS, 1, texNames, 1, uniNames, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::LEqual, false, true, false, boo::CullMode::None); - return new CEnergyBarShaderGLDataBindingFactory; -} - -template <> -void CEnergyBarShader::Shutdown() -{ - s_Pipeline.reset(); -} - -#if BOO_HAS_VULKAN -TShader::IDataBindingFactory* -CEnergyBarShader::Initialize(boo::VulkanDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::UV4} - }; - s_VtxFmt = ctx.newVertexFormat(2, VtxVmt); - s_Pipeline = ctx.newShaderPipeline(VS, FS, s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::LEqual, false, true, false, boo::CullMode::None); - return new CEnergyBarShaderVulkanDataBindingFactory; -} - -template <> -void CEnergyBarShader::Shutdown() -{ - s_VtxFmt.reset(); - s_Pipeline.reset(); -} -#endif - -} diff --git a/Runtime/Graphics/Shaders/CEnergyBarShaderHLSL.cpp b/Runtime/Graphics/Shaders/CEnergyBarShaderHLSL.cpp deleted file mode 100644 index 86d1aa014..000000000 --- a/Runtime/Graphics/Shaders/CEnergyBarShaderHLSL.cpp +++ /dev/null @@ -1,101 +0,0 @@ -#include "CEnergyBarShader.hpp" -#include "TShader.hpp" -#include "Graphics/CTexture.hpp" - -namespace urde -{ - -static const char* VS = -"struct VertData\n" -"{\n" -" float4 posIn : POSITION;\n" -" float4 uvIn : UV;\n" -"};\n" -"\n" -"cbuffer EnergyBarUniform : register(b0)\n" -"{\n" -" float4x4 xf;\n" -" float4 color;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float4 color : COLOR;\n" -" float2 uv : UV;\n" -"};\n" -"\n" -"VertToFrag main(in VertData v)\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.color = color;\n" -" vtf.uv = v.uvIn.xy;\n" -" vtf.position = mul(xf, float4(v.posIn.xyz, 1.0));\n" -" return vtf;\n" -"}\n"; - -static const char* FS = -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float4 color : COLOR;\n" -" float2 uv : UV;\n" -"};\n" -"\n" -"Texture2D tex : register(t0);\n" -"SamplerState samp : register(s0);\n" -"\n" -"float4 main(in VertToFrag vtf) : SV_Target0\n" -"{\n" -" return vtf.color * tex.Sample(samp, vtf.uv);\n" -"}\n"; - -URDE_DECL_SPECIALIZE_SHADER(CEnergyBarShader) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_Pipeline; - -struct CEnergyBarShaderD3DDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken - BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CEnergyBarShader& filter) - { - boo::D3DDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken bufs[1]; - boo::ObjToken texs[] = {filter.m_tex->GetBooTexture()}; - for (int i=0 ; i<3 ; ++i) - { - bufs[0] = filter.m_uniBuf[i].get(); - filter.m_dataBind[i] = cctx.newShaderDataBinding(s_Pipeline, s_VtxFmt, - filter.m_vbo.get(), nullptr, nullptr, 1, bufs, - nullptr, nullptr, nullptr, 1, texs, nullptr, nullptr); - } - return filter.m_dataBind[0]; - } -}; - -TShader::IDataBindingFactory* -CEnergyBarShader::Initialize(boo::D3DDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::UV4} - }; - s_VtxFmt = ctx.newVertexFormat(2, VtxVmt); - s_Pipeline = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, nullptr, - s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::LEqual, false, true, false, boo::CullMode::None); - return new CEnergyBarShaderD3DDataBindingFactory; -} - -template <> -void CEnergyBarShader::Shutdown() -{ - s_VtxFmt.reset(); - s_Pipeline.reset(); -} -} diff --git a/Runtime/Graphics/Shaders/CEnergyBarShaderMetal.cpp b/Runtime/Graphics/Shaders/CEnergyBarShaderMetal.cpp deleted file mode 100644 index 06f397ee7..000000000 --- a/Runtime/Graphics/Shaders/CEnergyBarShaderMetal.cpp +++ /dev/null @@ -1,104 +0,0 @@ -#include "CEnergyBarShader.hpp" -#include "TShader.hpp" -#include "Graphics/CTexture.hpp" - -namespace urde -{ - -static const char* VS = -"#include \n" -"using namespace metal;\n" -"struct VertData\n" -"{\n" -" float4 posIn [[ attribute(0) ]];\n" -" float4 uvIn [[ attribute(1) ]];\n" -"};\n" -"\n" -"struct EnergyBarUniform\n" -"{\n" -" float4x4 xf;\n" -" float4 color;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float4 color;\n" -" float2 uv;\n" -"};\n" -"\n" -"vertex VertToFrag vmain(VertData v [[ stage_in ]], constant EnergyBarUniform& ebu [[ buffer(2) ]])\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.color = ebu.color;\n" -" vtf.uv = v.uvIn.xy;\n" -" vtf.position = ebu.xf * float4(v.posIn.xyz, 1.0);\n" -" return vtf;\n" -"}\n"; - -static const char* FS = -"#include \n" -"using namespace metal;\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float4 color;\n" -" float2 uv;\n" -"};\n" -"\n" -"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n" -" sampler samp [[ sampler(0) ]],\n" -" texture2d tex [[ texture(0) ]])\n" -"{\n" -" return vtf.color * tex.sample(samp, vtf.uv);\n" -"}\n"; - -URDE_DECL_SPECIALIZE_SHADER(CEnergyBarShader) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_Pipeline; - -struct CEnergyBarShaderMetalDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CEnergyBarShader& filter) - { - boo::MetalDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken bufs[1]; - boo::ObjToken texs[] = {filter.m_tex->GetBooTexture()}; - for (int i=0 ; i<3 ; ++i) - { - bufs[0] = filter.m_uniBuf[i].get(); - filter.m_dataBind[i] = cctx.newShaderDataBinding(s_Pipeline, s_VtxFmt, - filter.m_vbo.get(), nullptr, nullptr, 1, bufs, - nullptr, nullptr, nullptr, 1, texs, nullptr, nullptr); - } - return filter.m_dataBind[0]; - } -}; - -TShader::IDataBindingFactory* -CEnergyBarShader::Initialize(boo::MetalDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::UV4} - }; - s_VtxFmt = ctx.newVertexFormat(2, VtxVmt); - s_Pipeline = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, s_VtxFmt, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, - false, true, false, boo::CullMode::None); - return new CEnergyBarShaderMetalDataBindingFactory; -} - -template <> -void CEnergyBarShader::Shutdown() -{ - s_VtxFmt.reset(); - s_Pipeline.reset(); -} - -} diff --git a/Runtime/Graphics/Shaders/CFluidPlaneShader.cpp b/Runtime/Graphics/Shaders/CFluidPlaneShader.cpp index fed05370e..1b0fb8361 100644 --- a/Runtime/Graphics/Shaders/CFluidPlaneShader.cpp +++ b/Runtime/Graphics/Shaders/CFluidPlaneShader.cpp @@ -1,6 +1,7 @@ #include "CFluidPlaneShader.hpp" #include "World/CRipple.hpp" #include "World/CRippleManager.hpp" +#include "hecl/Pipeline.hpp" namespace urde { @@ -90,54 +91,32 @@ u16 CFluidPlaneShader::Cache::MakeCacheKey(const SFluidPlaneDoorShaderInfo& info return ret; } -template -CFluidPlaneShader::ShaderPair CFluidPlaneShader::Cache::GetOrBuildShader(const T& info) +template<> CFluidPlaneShader::ShaderPair +CFluidPlaneShader::Cache::GetOrBuildShader(const SFluidPlaneShaderInfo& info) { u16 key = MakeCacheKey(info); auto& slot = CacheSlot(info, key); if (slot.m_regular) return slot; - if (CGraphics::g_BooFactory == nullptr) - return {}; - - CGraphics::CommitResources( - [&](boo::IGraphicsDataFactory::Context& ctx) - { - switch (ctx.platform()) - { -#if BOO_HAS_GL - case boo::IGraphicsDataFactory::Platform::OpenGL: - slot = BuildShader(static_cast(ctx), info); - break; -#endif -#if _WIN32 - case boo::IGraphicsDataFactory::Platform::D3D11: - slot = BuildShader(static_cast(ctx), info); - break; -#endif -#if BOO_HAS_METAL - case boo::IGraphicsDataFactory::Platform::Metal: - slot = BuildShader(static_cast(ctx), info); - break; -#endif -#if BOO_HAS_VULKAN - case boo::IGraphicsDataFactory::Platform::Vulkan: - slot = BuildShader(static_cast(ctx), info); - break; -#endif - default: break; - } - return true; - } BooTrace); + slot.m_regular = hecl::conv->convert(Shader_CFluidPlaneShader{info, false}); + if (info.m_tessellation) + slot.m_tessellation = hecl::conv->convert(Shader_CFluidPlaneShader{info, true}); return slot; } +template<> CFluidPlaneShader::ShaderPair +CFluidPlaneShader::Cache::GetOrBuildShader(const SFluidPlaneDoorShaderInfo& info) +{ + u16 key = MakeCacheKey(info); + auto& slot = CacheSlot(info, key); + if (slot.m_regular) + return slot; -template CFluidPlaneShader::ShaderPair -CFluidPlaneShader::Cache::GetOrBuildShader(const SFluidPlaneShaderInfo& info); -template CFluidPlaneShader::ShaderPair -CFluidPlaneShader::Cache::GetOrBuildShader(const SFluidPlaneDoorShaderInfo& info); + slot.m_regular = hecl::conv->convert(Shader_CFluidPlaneDoorShader{info}); + + return slot; +} void CFluidPlaneShader::Cache::Clear() { @@ -157,30 +136,37 @@ void CFluidPlaneShader::PrepareBinding(const ShaderPair& pipeline, u32 maxVertCo m_pvbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(PatchVertex), maxVertCount); m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); - switch (ctx.platform()) + boo::ObjToken ubufs[] = { m_uniBuf.get(), m_uniBuf.get(), m_uniBuf.get() }; + boo::PipelineStage ubufStages[] = { boo::PipelineStage::Vertex, boo::PipelineStage::Vertex, + boo::PipelineStage::Fragment }; + size_t ubufOffs[] = {0, 0, 1280}; + size_t ubufSizes[] = {1280, 1280, sizeof(CModelShaders::LightingUniform)}; + size_t texCount = 0; + boo::ObjToken texs[8]; + if (m_patternTex1) + texs[texCount++] = m_patternTex1->GetBooTexture(); + if (m_patternTex2) + texs[texCount++] = m_patternTex2->GetBooTexture(); + if (m_colorTex) + texs[texCount++] = m_colorTex->GetBooTexture(); + if (m_bumpMap) + texs[texCount++] = m_bumpMap->GetBooTexture(); + if (m_envMap) + texs[texCount++] = m_envMap->GetBooTexture(); + if (m_envBumpMap) + texs[texCount++] = m_envBumpMap->GetBooTexture(); + if (m_lightmap) + texs[texCount++] = m_lightmap->GetBooTexture(); + auto regular = ctx.newShaderDataBinding(pipeline.m_regular, m_vbo.get(), nullptr, nullptr, 3, + ubufs, ubufStages, ubufOffs, ubufSizes, texCount, texs, nullptr, nullptr); + boo::ObjToken tessellation; + if (pipeline.m_tessellation) { -#if BOO_HAS_GL - case boo::IGraphicsDataFactory::Platform::OpenGL: - m_dataBind = BuildBinding(static_cast(ctx), pipeline); - break; -#endif -#if _WIN32 - case boo::IGraphicsDataFactory::Platform::D3D11: - m_dataBind = BuildBinding(static_cast(ctx), pipeline); - break; -#endif -#if BOO_HAS_METAL - case boo::IGraphicsDataFactory::Platform::Metal: - m_dataBind = BuildBinding(static_cast(ctx), pipeline); - break; -#endif -#if BOO_HAS_VULKAN - case boo::IGraphicsDataFactory::Platform::Vulkan: - m_dataBind = BuildBinding(static_cast(ctx), pipeline); - break; -#endif - default: break; + texs[texCount++] = m_rippleMap.get(); + tessellation = ctx.newShaderDataBinding(pipeline.m_tessellation, m_pvbo.get(), nullptr, nullptr, 3, + ubufs, ubufStages, ubufOffs, ubufSizes, texCount, texs, nullptr, nullptr); } + m_dataBind = {regular, tessellation}; return true; } BooTrace); } @@ -188,30 +174,6 @@ void CFluidPlaneShader::PrepareBinding(const ShaderPair& pipeline, u32 maxVertCo void CFluidPlaneShader::Shutdown() { _cache.Clear(); - switch (CGraphics::g_BooFactory->platform()) - { -#if BOO_HAS_GL - case boo::IGraphicsDataFactory::Platform::OpenGL: - CFluidPlaneShader::_Shutdown(); - break; -#endif -#if _WIN32 - case boo::IGraphicsDataFactory::Platform::D3D11: - CFluidPlaneShader::_Shutdown(); - break; -#endif -#if BOO_HAS_METAL - case boo::IGraphicsDataFactory::Platform::Metal: - CFluidPlaneShader::_Shutdown(); - break; -#endif -#if BOO_HAS_VULKAN - case boo::IGraphicsDataFactory::Platform::Vulkan: - CFluidPlaneShader::_Shutdown(); - break; -#endif - default: break; - } } CFluidPlaneShader::CFluidPlaneShader(EFluidType type, diff --git a/Runtime/Graphics/Shaders/CFluidPlaneShader.hpp b/Runtime/Graphics/Shaders/CFluidPlaneShader.hpp index ad35731c5..c731bdf73 100644 --- a/Runtime/Graphics/Shaders/CFluidPlaneShader.hpp +++ b/Runtime/Graphics/Shaders/CFluidPlaneShader.hpp @@ -4,52 +4,15 @@ #include "RetroTypes.hpp" #include "boo/graphicsdev/IGraphicsDataFactory.hpp" #include "CModelShaders.hpp" -#include "boo/graphicsdev/GL.hpp" -#include "boo/graphicsdev/D3D.hpp" -#include "boo/graphicsdev/Metal.hpp" -#include "boo/graphicsdev/Vulkan.hpp" #include "World/CFluidPlaneManager.hpp" #include "Graphics/CTexture.hpp" #include "CToken.hpp" #include "zeus/CAABox.hpp" +#include "Shaders/shader_CFluidPlaneShader.hpp" namespace urde { -struct SFluidPlaneShaderInfo -{ - EFluidType m_type; - bool m_hasPatternTex1; - bool m_hasPatternTex2; - bool m_hasColorTex; - bool m_hasBumpMap; - bool m_hasEnvMap; - bool m_hasEnvBumpMap; - bool m_hasLightmap; - bool m_tessellation; - bool m_doubleLightmapBlend; - bool m_additive; - - SFluidPlaneShaderInfo(EFluidType type, bool hasPatternTex1, bool hasPatternTex2, bool hasColorTex, - bool hasBumpMap, bool hasEnvMap, bool hasEnvBumpMap, bool hasLightmap, - bool tessellation, bool doubleLightmapBlend, bool additive) - : m_type(type), m_hasPatternTex1(hasPatternTex1), m_hasPatternTex2(hasPatternTex2), m_hasColorTex(hasColorTex), - m_hasBumpMap(hasBumpMap), m_hasEnvMap(hasEnvMap), m_hasEnvBumpMap(hasEnvBumpMap), m_hasLightmap(hasLightmap), - m_tessellation(tessellation), m_doubleLightmapBlend(doubleLightmapBlend), m_additive(additive) - {} -}; - -struct SFluidPlaneDoorShaderInfo -{ - bool m_hasPatternTex1; - bool m_hasPatternTex2; - bool m_hasColorTex; - - SFluidPlaneDoorShaderInfo(bool hasPatternTex1, bool hasPatternTex2, bool hasColorTex) - : m_hasPatternTex1(hasPatternTex1), m_hasPatternTex2(hasPatternTex2), m_hasColorTex(hasColorTex) - {} -}; - class CFluidPlaneShader { public: diff --git a/Runtime/Graphics/Shaders/CFogVolumeFilter.cpp b/Runtime/Graphics/Shaders/CFogVolumeFilter.cpp index 3bc1b1c99..1812c37a0 100644 --- a/Runtime/Graphics/Shaders/CFogVolumeFilter.cpp +++ b/Runtime/Graphics/Shaders/CFogVolumeFilter.cpp @@ -1,8 +1,27 @@ #include "CFogVolumeFilter.hpp" +#include "hecl/Pipeline.hpp" +#include "Graphics/CGraphics.hpp" +#include "GameGlobalObjects.hpp" +#include "Graphics/CBooRenderer.hpp" namespace urde { +static boo::ObjToken s_1WayPipeline; +static boo::ObjToken s_2WayPipeline; + +void CFogVolumeFilter::Initialize() +{ + s_1WayPipeline = hecl::conv->convert(Shader_CFogVolumeFilter1Way{}); + s_2WayPipeline = hecl::conv->convert(Shader_CFogVolumeFilter2Way{}); +} + +void CFogVolumeFilter::Shutdown() +{ + s_1WayPipeline.reset(); + s_2WayPipeline.reset(); +} + CFogVolumeFilter::CFogVolumeFilter() { CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) @@ -20,7 +39,18 @@ CFogVolumeFilter::CFogVolumeFilter() }; m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts, sizeof(Vert), 4); m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(zeus::CColor), 1); - TShader::BuildShaderDataBinding(ctx, *this); + boo::ObjToken texs[] = { CGraphics::g_SpareTexture.get(), CGraphics::g_SpareTexture.get(), + g_Renderer->GetFogRampTex().get() }; + int bindIdxs[] = {0, 1, 0}; + bool bindDepth[] = {true, true, false}; + boo::ObjToken ubufs[] = {m_uniBuf.get()}; + + m_dataBind1Way = ctx.newShaderDataBinding(s_1WayPipeline, + m_vbo.get(), nullptr, nullptr, 1, ubufs, + nullptr, nullptr, nullptr, 3, texs, bindIdxs, bindDepth); + m_dataBind2Way = ctx.newShaderDataBinding(s_2WayPipeline, + m_vbo.get(), nullptr, nullptr, 1, ubufs, + nullptr, nullptr, nullptr, 3, texs, bindIdxs, bindDepth); return true; } BooTrace); } @@ -39,6 +69,4 @@ void CFogVolumeFilter::draw1WayPass(const zeus::CColor& color) CGraphics::DrawArray(0, 4); } -URDE_SPECIALIZE_SHADER(CFogVolumeFilter) - } diff --git a/Runtime/Graphics/Shaders/CFogVolumeFilter.hpp b/Runtime/Graphics/Shaders/CFogVolumeFilter.hpp index bf9fe1466..536acc0bd 100644 --- a/Runtime/Graphics/Shaders/CFogVolumeFilter.hpp +++ b/Runtime/Graphics/Shaders/CFogVolumeFilter.hpp @@ -1,33 +1,27 @@ #ifndef __URDE_CFOGVOLUMEFILTER_HPP__ #define __URDE_CFOGVOLUMEFILTER_HPP__ -#include "TShader.hpp" #include "zeus/CMatrix4f.hpp" #include "zeus/CColor.hpp" #include "zeus/CRectangle.hpp" +#include "boo/graphicsdev/IGraphicsDataFactory.hpp" namespace urde { class CFogVolumeFilter { - friend struct CFogVolumeFilterGLDataBindingFactory; - friend struct CFogVolumeFilterVulkanDataBindingFactory; - friend struct CFogVolumeFilterMetalDataBindingFactory; - friend struct CFogVolumeFilterD3DDataBindingFactory; - boo::ObjToken m_vbo; boo::ObjToken m_uniBuf; boo::ObjToken m_dataBind1Way; boo::ObjToken m_dataBind2Way; public: + static void Initialize(); + static void Shutdown(); CFogVolumeFilter(); void draw2WayPass(const zeus::CColor& color); void draw1WayPass(const zeus::CColor& color); - - using _CLS = CFogVolumeFilter; -#include "TShaderDecl.hpp" }; } diff --git a/Runtime/Graphics/Shaders/CFogVolumeFilterGLSL.cpp b/Runtime/Graphics/Shaders/CFogVolumeFilterGLSL.cpp deleted file mode 100644 index 0966926ae..000000000 --- a/Runtime/Graphics/Shaders/CFogVolumeFilterGLSL.cpp +++ /dev/null @@ -1,196 +0,0 @@ -#include "CFogVolumeFilter.hpp" -#include "TShader.hpp" -#include "GameGlobalObjects.hpp" -#include "Graphics/CBooRenderer.hpp" - -namespace urde -{ - -static const char* VS = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"layout(location=0) in vec4 posIn;\n" -"layout(location=1) in vec2 uvIn;\n" -"\n" -"UBINDING0 uniform FogVolumeFilterUniform\n" -"{\n" -" vec4 color;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -" vec2 uv;\n" -"};\n" -"\n" -"SBINDING(0) out VertToFrag vtf;\n" -"void main()\n" -"{\n" -" gl_Position = vec4(posIn.xy, 0.0, 1.0);\n" -" vtf.color = color;\n" -" vtf.uv = uvIn;\n" -"}\n"; - -static const char* FS1Way = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"\n" -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -" vec2 uv;\n" -"};\n" -"\n" -"SBINDING(0) in VertToFrag vtf;\n" -"layout(location=0) out vec4 colorOut;\n" -"TBINDING0 uniform sampler2D zFrontfaceTex;\n" -"TBINDING1 uniform sampler2D zBackfaceTex;\n" -"TBINDING2 uniform sampler2D zLinearizer;\n" -"void main()\n" -"{\n" -" float y;\n" -" const float linScale = 65535.0 / 65536.0 * 256.0;\n" -" float x = modf(texture(zFrontfaceTex, vtf.uv).r * linScale, y);\n" -" const float uvBias = 0.5 / 256.0;\n" -" float alpha = texture(zLinearizer, vec2(x * 255.0 / 256.0 + uvBias, y / 256.0 + uvBias)).r * 10.0;\n" -" colorOut = vtf.color * alpha;\n" -"}\n"; - -static const char* FS2Way = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"\n" -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -" vec2 uv;\n" -"};\n" -"\n" -"SBINDING(0) in VertToFrag vtf;\n" -"layout(location=0) out vec4 colorOut;\n" -"TBINDING0 uniform sampler2D zFrontfaceTex;\n" -"TBINDING1 uniform sampler2D zBackfaceTex;\n" -"TBINDING2 uniform sampler2D zLinearizer;\n" -"void main()\n" -"{\n" -" float frontY;\n" -" float backY;\n" -" const float linScale = 65535.0 / 65536.0 * 256.0;\n" -" float frontX = modf(texture(zFrontfaceTex, vtf.uv).r * linScale, frontY);\n" -" float backX = modf(texture(zBackfaceTex, vtf.uv).r * linScale, backY);\n" -" const float uvBias = 0.5 / 256.0;\n" -" float frontLin = texture(zLinearizer, vec2(frontX * 255.0 / 256.0 + uvBias, frontY / 256.0 + uvBias)).r;\n" -" float backLin = texture(zLinearizer, vec2(backX * 255.0 / 256.0 + uvBias, backY / 256.0 + uvBias)).r;\n" -" colorOut = vec4(vtf.color.rgb, (frontLin - backLin) * 10.0);\n" -"}\n"; - -URDE_DECL_SPECIALIZE_SHADER(CFogVolumeFilter) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_1WayPipeline; -static boo::ObjToken s_2WayPipeline; - -struct CFogVolumeFilterGLDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CFogVolumeFilter& filter) - { - boo::GLDataFactory::Context& cctx = static_cast(ctx); - - const boo::VertexElementDescriptor VtxVmt[] = - { - {filter.m_vbo.get(), nullptr, boo::VertexSemantic::Position4}, - {filter.m_vbo.get(), nullptr, boo::VertexSemantic::UV4} - }; - boo::ObjToken VtxVmtObj = cctx.newVertexFormat(2, VtxVmt); - boo::ObjToken texs[] = { CGraphics::g_SpareTexture.get(), CGraphics::g_SpareTexture.get(), - g_Renderer->GetFogRampTex().get() }; - int bindIdxs[] = {0, 1, 0}; - bool bindDepth[] = {true, true, false}; - boo::ObjToken ubufs[] = {filter.m_uniBuf.get()}; - - filter.m_dataBind1Way = cctx.newShaderDataBinding(s_1WayPipeline, VtxVmtObj, - filter.m_vbo.get(), nullptr, nullptr, 1, ubufs, - nullptr, nullptr, nullptr, 3, texs, bindIdxs, bindDepth); - filter.m_dataBind2Way = cctx.newShaderDataBinding(s_2WayPipeline, VtxVmtObj, - filter.m_vbo.get(), nullptr, nullptr, 1, ubufs, - nullptr, nullptr, nullptr, 3, texs, bindIdxs, bindDepth); - return filter.m_dataBind1Way; - } -}; - -#if BOO_HAS_VULKAN -struct CFogVolumeFilterVulkanDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken - BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CFogVolumeFilter& filter) - { - boo::VulkanDataFactory::Context& cctx = static_cast(ctx); - boo::ObjToken texs[] = { CGraphics::g_SpareTexture.get(), CGraphics::g_SpareTexture.get(), - g_Renderer->GetFogRampTex().get() }; - int bindIdxs[] = {0, 1, 0}; - bool bindDepth[] = {true, true, false}; - boo::ObjToken ubufs[] = {filter.m_uniBuf.get()}; - - filter.m_dataBind1Way = cctx.newShaderDataBinding(s_1WayPipeline, s_VtxFmt, - filter.m_vbo.get(), nullptr, nullptr, 1, ubufs, - nullptr, nullptr, nullptr, 3, texs, bindIdxs, bindDepth); - filter.m_dataBind2Way = cctx.newShaderDataBinding(s_2WayPipeline, s_VtxFmt, - filter.m_vbo.get(), nullptr, nullptr, 1, ubufs, - nullptr, nullptr, nullptr, 3, texs, bindIdxs, bindDepth); - return filter.m_dataBind1Way; - } -}; -#endif - -TShader::IDataBindingFactory* -CFogVolumeFilter::Initialize(boo::GLDataFactory::Context& ctx) -{ - const char* texNames[] = {"zFrontfaceTex", "zBackfaceTex", "zLinearizer"}; - const char* uniNames[] = {"FogVolumeFilterUniform"}; - s_1WayPipeline = ctx.newShaderPipeline(VS, FS1Way, 3, texNames, 1, uniNames, boo::BlendFactor::DstAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_2WayPipeline = ctx.newShaderPipeline(VS, FS2Way, 3, texNames, 1, uniNames, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - return new CFogVolumeFilterGLDataBindingFactory; -} - -template <> -void CFogVolumeFilter::Shutdown() -{ - s_1WayPipeline.reset(); - s_2WayPipeline.reset(); -} - -#if BOO_HAS_VULKAN -TShader::IDataBindingFactory* -CFogVolumeFilter::Initialize(boo::VulkanDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::UV4} - }; - s_VtxFmt = ctx.newVertexFormat(2, VtxVmt); - s_1WayPipeline = ctx.newShaderPipeline(VS, FS1Way, s_VtxFmt, boo::BlendFactor::DstAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_2WayPipeline = ctx.newShaderPipeline(VS, FS2Way, s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - return new CFogVolumeFilterVulkanDataBindingFactory; -} - -template <> -void CFogVolumeFilter::Shutdown() -{ - s_VtxFmt.reset(); - s_1WayPipeline.reset(); - s_2WayPipeline.reset(); -} -#endif - -} diff --git a/Runtime/Graphics/Shaders/CFogVolumeFilterHLSL.cpp b/Runtime/Graphics/Shaders/CFogVolumeFilterHLSL.cpp deleted file mode 100644 index fb75235d1..000000000 --- a/Runtime/Graphics/Shaders/CFogVolumeFilterHLSL.cpp +++ /dev/null @@ -1,139 +0,0 @@ -#include "CFogVolumeFilter.hpp" -#include "TShader.hpp" -#include "GameGlobalObjects.hpp" -#include "Graphics/CBooRenderer.hpp" - -namespace urde -{ - -static const char* VS = -"struct VertData\n" -"{\n" -" float4 posIn : POSITION;\n" -" float2 uvIn : UV;\n" -"};\n" -"\n" -"cbuffer FogVolumeFilterUniform : register(b0)\n" -"{\n" -" float4 color;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float4 color : COLOR;\n" -" float2 uv : UV;\n" -"};\n" -"\n" -"VertToFrag main(in VertData v)\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.position = float4(v.posIn.x, -v.posIn.y, 0.0, 1.0);\n" -" vtf.color = color;\n" -" vtf.uv = v.uvIn;\n" -" return vtf;\n" -"}\n"; - -static const char* FS1Way = -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float4 color : COLOR;\n" -" float2 uv : UV;\n" -"};\n" -"\n" -"Texture2D zFrontfaceTex : register(t0);\n" -"Texture2D zBackfaceTex : register(t1);\n" -"Texture2D zLinearizer : register(t2);\n" -"SamplerState samp : register(s0);\n" -"float4 main(in VertToFrag vtf) : SV_Target0\n" -"{\n" -" float y;\n" -" const float linScale = 65535.0 / 65536.0 * 256.0;\n" -" float x = modf((1.0 - zFrontfaceTex.Sample(samp, vtf.uv).r) * linScale, y);\n" -" const float uvBias = 0.5 / 256.0;\n" -" float alpha = zLinearizer.Sample(samp, float2(x * 255.0 / 256.0 + uvBias, y / 256.0 + uvBias)).r * 10.0;\n" -" return vtf.color * alpha;\n" -"}\n"; - -static const char* FS2Way = -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float4 color : COLOR;\n" -" float2 uv : UV;\n" -"};\n" -"\n" -"Texture2D zFrontfaceTex : register(t0);\n" -"Texture2D zBackfaceTex : register(t1);\n" -"Texture2D zLinearizer : register(t2);\n" -"SamplerState samp : register(s0);\n" -"float4 main(in VertToFrag vtf) : SV_Target0\n" -"{\n" -" float frontY;\n" -" float backY;\n" -" const float linScale = 65535.0 / 65536.0 * 256.0;\n" -" float frontX = modf((1.0 - zFrontfaceTex.Sample(samp, vtf.uv).r) * linScale, frontY);\n" -" float backX = modf((1.0 - zBackfaceTex.Sample(samp, vtf.uv).r) * linScale, backY);\n" -" const float uvBias = 0.5 / 256.0;\n" -" float frontLin = zLinearizer.Sample(samp, float2(frontX * 255.0 / 256.0 + uvBias, frontY / 256.0 + uvBias)).r;\n" -" float backLin = zLinearizer.Sample(samp, float2(backX * 255.0 / 256.0 + uvBias, backY / 256.0 + uvBias)).r;\n" -" return float4(vtf.color.rgb, (frontLin - backLin) * 10.0);\n" -"}\n"; - -URDE_DECL_SPECIALIZE_SHADER(CFogVolumeFilter) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_1WayPipeline; -static boo::ObjToken s_2WayPipeline; - -struct CFogVolumeFilterD3DDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken - BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CFogVolumeFilter& filter) - { - boo::D3DDataFactory::Context& cctx = static_cast(ctx); - boo::ObjToken texs[] = { CGraphics::g_SpareTexture.get(), CGraphics::g_SpareTexture.get(), - g_Renderer->GetFogRampTex().get() }; - int bindIdxs[] = {0, 1, 0}; - bool bindDepth[] = {true, true, false}; - boo::ObjToken ubufs[] = {filter.m_uniBuf.get()}; - - filter.m_dataBind1Way = cctx.newShaderDataBinding(s_1WayPipeline, s_VtxFmt, - filter.m_vbo.get(), nullptr, nullptr, 1, ubufs, - nullptr, nullptr, nullptr, 3, texs, bindIdxs, bindDepth); - filter.m_dataBind2Way = cctx.newShaderDataBinding(s_2WayPipeline, s_VtxFmt, - filter.m_vbo.get(), nullptr, nullptr, 1, ubufs, - nullptr, nullptr, nullptr, 3, texs, bindIdxs, bindDepth); - return filter.m_dataBind1Way; - } -}; - -TShader::IDataBindingFactory* -CFogVolumeFilter::Initialize(boo::D3DDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::UV4} - }; - s_VtxFmt = ctx.newVertexFormat(2, VtxVmt); - s_1WayPipeline = ctx.newShaderPipeline(VS, FS1Way, nullptr, nullptr, nullptr, s_VtxFmt, boo::BlendFactor::DstAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_2WayPipeline = ctx.newShaderPipeline(VS, FS2Way, nullptr, nullptr, nullptr, s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - return new CFogVolumeFilterD3DDataBindingFactory; -} - -template <> -void CFogVolumeFilter::Shutdown() -{ - s_VtxFmt.reset(); - s_1WayPipeline.reset(); - s_2WayPipeline.reset(); -} - -} diff --git a/Runtime/Graphics/Shaders/CFogVolumeFilterMetal.cpp b/Runtime/Graphics/Shaders/CFogVolumeFilterMetal.cpp deleted file mode 100644 index 209b67db2..000000000 --- a/Runtime/Graphics/Shaders/CFogVolumeFilterMetal.cpp +++ /dev/null @@ -1,147 +0,0 @@ -#include "CFogVolumeFilter.hpp" -#include "TShader.hpp" -#include "GameGlobalObjects.hpp" -#include "Graphics/CBooRenderer.hpp" - -namespace urde -{ - -static const char* VS = -"#include \n" -"using namespace metal;\n" -"struct VertData\n" -"{\n" -" float4 posIn [[ attribute(0) ]];\n" -" float2 uvIn [[ attribute(1) ]];\n" -"};\n" -"\n" -"struct FogVolumeFilterUniform\n" -"{\n" -" float4 color;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 pos [[ position ]];\n" -" float4 color;\n" -" float2 uv;\n" -"};\n" -"\n" -"vertex VertToFrag vmain(VertData v [[ stage_in ]],\n" -" constant FogVolumeFilterUniform& fu [[ buffer(2) ]])\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.pos = float4(v.posIn.x, -v.posIn.y, 0.0, 1.0);\n" -" vtf.color = fu.color;\n" -" vtf.uv = v.uvIn;\n" -" return vtf;\n" -"}\n"; - -static const char* FS1Way = -"#include \n" -"using namespace metal;\n" -"struct VertToFrag\n" -"{\n" -" float4 pos [[ position ]];\n" -" float4 color;\n" -" float2 uv;\n" -"};\n" -"\n" -"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n" -" sampler samp [[ sampler(0) ]],\n" -" texture2d zFrontfaceTex [[ texture(0) ]],\n" -" texture2d zBackfaceTex [[ texture(1) ]],\n" -" texture2d zLinearizer [[ texture(2) ]])\n" -"{\n" -" float y;\n" -" const float linScale = 65535.0 / 65536.0 * 256.0;\n" -" float x = modf((1.0 - zFrontfaceTex.sample(samp, vtf.uv).r) * linScale, y);\n" -" const float uvBias = 0.5 / 256.0;\n" -" float alpha = zLinearizer.sample(samp, float2(x * 255.0 / 256.0 + uvBias, y / 256.0 + uvBias)).r * 10.0;\n" -" return vtf.color * alpha;\n" -"}\n"; - -static const char* FS2Way = -"#include \n" -"using namespace metal;\n" -"struct VertToFrag\n" -"{\n" -" float4 pos [[ position ]];\n" -" float4 color;\n" -" float2 uv;\n" -"};\n" -"\n" -"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n" -" sampler samp [[ sampler(0) ]],\n" -" texture2d zFrontfaceTex [[ texture(0) ]],\n" -" texture2d zBackfaceTex [[ texture(1) ]],\n" -" texture2d zLinearizer [[ texture(2) ]])\n" -"{\n" -" float frontY;\n" -" float backY;\n" -" const float linScale = 65535.0 / 65536.0 * 256.0;\n" -" float frontX = modf((1.0 - zFrontfaceTex.sample(samp, vtf.uv).r) * linScale, frontY);\n" -" float backX = modf((1.0 - zBackfaceTex.sample(samp, vtf.uv).r) * linScale, backY);\n" -" const float uvBias = 0.5 / 256.0;\n" -" float frontLin = zLinearizer.sample(samp, float2(frontX * 255.0 / 256.0 + uvBias, frontY / 256.0 + uvBias)).r;\n" -" float backLin = zLinearizer.sample(samp, float2(backX * 255.0 / 256.0 + uvBias, backY / 256.0 + uvBias)).r;\n" -" return float4(vtf.color.rgb, (frontLin - backLin) * 10.0);\n" -"}\n"; - -URDE_DECL_SPECIALIZE_SHADER(CFogVolumeFilter) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_1WayPipeline; -static boo::ObjToken s_2WayPipeline; - -struct CFogVolumeFilterMetalDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CFogVolumeFilter& filter) - { - boo::MetalDataFactory::Context& cctx = static_cast(ctx); - boo::ObjToken texs[] = { CGraphics::g_SpareTexture.get(), CGraphics::g_SpareTexture.get(), - g_Renderer->GetFogRampTex().get() }; - int bindIdxs[] = {0, 1, 0}; - bool bindDepth[] = {true, true, false}; - boo::ObjToken ubufs[] = {filter.m_uniBuf.get()}; - - filter.m_dataBind1Way = cctx.newShaderDataBinding(s_1WayPipeline, s_VtxFmt, - filter.m_vbo.get(), nullptr, nullptr, 1, ubufs, - nullptr, nullptr, nullptr, 3, texs, bindIdxs, bindDepth); - filter.m_dataBind2Way = cctx.newShaderDataBinding(s_2WayPipeline, s_VtxFmt, - filter.m_vbo.get(), nullptr, nullptr, 1, ubufs, - nullptr, nullptr, nullptr, 3, texs, bindIdxs, bindDepth); - return filter.m_dataBind1Way; - } -}; - -TShader::IDataBindingFactory* -CFogVolumeFilter::Initialize(boo::MetalDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::UV4} - }; - s_VtxFmt = ctx.newVertexFormat(2, VtxVmt); - s_1WayPipeline = ctx.newShaderPipeline(VS, FS1Way, nullptr, nullptr, - s_VtxFmt, boo::BlendFactor::DstAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_2WayPipeline = ctx.newShaderPipeline(VS, FS2Way, nullptr, nullptr, - s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - return new CFogVolumeFilterMetalDataBindingFactory; -} - -template <> -void CFogVolumeFilter::Shutdown() -{ - s_VtxFmt.reset(); - s_1WayPipeline.reset(); - s_2WayPipeline.reset(); -} - -} diff --git a/Runtime/Graphics/Shaders/CFogVolumePlaneShader.cpp b/Runtime/Graphics/Shaders/CFogVolumePlaneShader.cpp index 86168185f..d09df9f6b 100644 --- a/Runtime/Graphics/Shaders/CFogVolumePlaneShader.cpp +++ b/Runtime/Graphics/Shaders/CFogVolumePlaneShader.cpp @@ -1,15 +1,38 @@ #include "CFogVolumePlaneShader.hpp" +#include "hecl/Pipeline.hpp" +#include "Graphics/CGraphics.hpp" namespace urde { +static boo::ObjToken s_Pipelines[4]; + +void CFogVolumePlaneShader::Initialize() +{ + s_Pipelines[0] = hecl::conv->convert(Shader_CFogVolumePlaneShader0{}); + s_Pipelines[1] = hecl::conv->convert(Shader_CFogVolumePlaneShader1{}); + s_Pipelines[2] = hecl::conv->convert(Shader_CFogVolumePlaneShader2{}); + s_Pipelines[3] = hecl::conv->convert(Shader_CFogVolumePlaneShader3{}); +} + +void CFogVolumePlaneShader::Shutdown() +{ + s_Pipelines[0].reset(); + s_Pipelines[1].reset(); + s_Pipelines[2].reset(); + s_Pipelines[3].reset(); +} + void CFogVolumePlaneShader::CommitResources(size_t capacity) { m_vertCapacity = capacity; CGraphics::CommitResources([this, capacity](boo::IGraphicsDataFactory::Context& ctx) { m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(zeus::CVector4f), capacity); - TShader::BuildShaderDataBinding(ctx, *this); + for (int i=0 ; i<4 ; ++i) + m_dataBinds[i] = ctx.newShaderDataBinding(s_Pipelines[i], + m_vbo.get(), nullptr, nullptr, 0, nullptr, + nullptr, nullptr, nullptr, 0, nullptr, nullptr, nullptr); return true; } BooTrace); } @@ -60,6 +83,4 @@ void CFogVolumePlaneShader::draw(int pass) CGraphics::DrawArray(0, m_verts.size()); } -URDE_SPECIALIZE_SHADER(CFogVolumePlaneShader) - } diff --git a/Runtime/Graphics/Shaders/CFogVolumePlaneShader.hpp b/Runtime/Graphics/Shaders/CFogVolumePlaneShader.hpp index 10effaad6..9d30a938f 100644 --- a/Runtime/Graphics/Shaders/CFogVolumePlaneShader.hpp +++ b/Runtime/Graphics/Shaders/CFogVolumePlaneShader.hpp @@ -1,7 +1,7 @@ #ifndef __URDE_CFOGVOLUMEPLANESHADER_HPP__ #define __URDE_CFOGVOLUMEPLANESHADER_HPP__ -#include "TShader.hpp" +#include "boo/graphicsdev/IGraphicsDataFactory.hpp" #include "zeus/CMatrix4f.hpp" #include "zeus/CColor.hpp" #include "zeus/CRectangle.hpp" @@ -12,11 +12,6 @@ namespace urde class CFogVolumePlaneShader { - friend struct CFogVolumePlaneShaderGLDataBindingFactory; - friend struct CFogVolumePlaneShaderVulkanDataBindingFactory; - friend struct CFogVolumePlaneShaderMetalDataBindingFactory; - friend struct CFogVolumePlaneShaderD3DDataBindingFactory; - boo::ObjToken m_vbo; boo::ObjToken m_dataBinds[4]; std::vector m_verts; @@ -25,13 +20,12 @@ class CFogVolumePlaneShader void CommitResources(size_t capacity); public: + static void Initialize(); + static void Shutdown(); static const zeus::CRectangle DefaultRect; void reset(int numVerts) { m_verts.clear(); m_verts.reserve(numVerts); } void addFan(const zeus::CVector3f* verts, int numVerts); void draw(int pass); - - using _CLS = CFogVolumePlaneShader; -#include "TShaderDecl.hpp" }; } diff --git a/Runtime/Graphics/Shaders/CFogVolumePlaneShaderGLSL.cpp b/Runtime/Graphics/Shaders/CFogVolumePlaneShaderGLSL.cpp deleted file mode 100644 index ee5f1d7b4..000000000 --- a/Runtime/Graphics/Shaders/CFogVolumePlaneShaderGLSL.cpp +++ /dev/null @@ -1,132 +0,0 @@ -#include "CFogVolumePlaneShader.hpp" -#include "TShader.hpp" - -namespace urde -{ - -static const char* VS = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"layout(location=0) in vec4 posIn;\n" -"\n" -"void main()\n" -"{\n" -" gl_Position = posIn;\n" -"}\n"; - -static const char* FS = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"\n" -"layout(location=0) out vec4 colorOut;\n" -"void main()\n" -"{\n" -" colorOut = vec4(1.0);\n" -"}\n"; - -URDE_DECL_SPECIALIZE_SHADER(CFogVolumePlaneShader) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_Pipelines[4]; - -struct CFogVolumePlaneShaderGLDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CFogVolumePlaneShader& filter) - { - boo::GLDataFactory::Context& cctx = static_cast(ctx); - - const boo::VertexElementDescriptor VtxVmt[] = - { - {filter.m_vbo.get(), nullptr, boo::VertexSemantic::Position4} - }; - boo::ObjToken VtxVmtObj = cctx.newVertexFormat(1, VtxVmt); - for (int i=0 ; i<4 ; ++i) - filter.m_dataBinds[i] = cctx.newShaderDataBinding(s_Pipelines[i], VtxVmtObj, - filter.m_vbo.get(), nullptr, nullptr, 0, nullptr, - nullptr, nullptr, nullptr, 0, nullptr, nullptr, nullptr); - return filter.m_dataBinds[0]; - } -}; - -#if BOO_HAS_VULKAN -struct CFogVolumePlaneShaderVulkanDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken - BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CFogVolumePlaneShader& filter) - { - boo::VulkanDataFactory::Context& cctx = static_cast(ctx); - - for (int i=0 ; i<4 ; ++i) - filter.m_dataBinds[i] = cctx.newShaderDataBinding(s_Pipelines[i], s_VtxFmt, - filter.m_vbo.get(), nullptr, nullptr, 0, nullptr, - nullptr, nullptr, nullptr, 0, nullptr, nullptr, nullptr); - return filter.m_dataBinds[0]; - } -}; -#endif - -TShader::IDataBindingFactory* -CFogVolumePlaneShader::Initialize(boo::GLDataFactory::Context& ctx) -{ - s_Pipelines[0] = ctx.newShaderPipeline(VS, FS, 0, nullptr, 0, nullptr, boo::BlendFactor::Zero, - boo::BlendFactor::Zero, boo::Primitive::TriStrips, - boo::ZTest::LEqual, true, false, false, boo::CullMode::Frontface); - s_Pipelines[1] = ctx.newShaderPipeline(VS, FS, 0, nullptr, 0, nullptr, boo::BlendFactor::Zero, - boo::BlendFactor::Zero, boo::Primitive::TriStrips, - boo::ZTest::None, false, false, false, boo::CullMode::Frontface); - s_Pipelines[2] = ctx.newShaderPipeline(VS, FS, 0, nullptr, 0, nullptr, boo::BlendFactor::Zero, - boo::BlendFactor::Zero, boo::Primitive::TriStrips, - boo::ZTest::LEqual, true, false, false, boo::CullMode::Backface); - s_Pipelines[3] = ctx.newShaderPipeline(VS, FS, 0, nullptr, 0, nullptr, boo::BlendFactor::Zero, - boo::BlendFactor::Zero, boo::Primitive::TriStrips, - boo::ZTest::Greater, false, false, false, boo::CullMode::Backface); - return new CFogVolumePlaneShaderGLDataBindingFactory; -} - -template <> -void CFogVolumePlaneShader::Shutdown() -{ - s_Pipelines[0].reset(); - s_Pipelines[1].reset(); - s_Pipelines[2].reset(); - s_Pipelines[3].reset(); -} - -#if BOO_HAS_VULKAN -TShader::IDataBindingFactory* -CFogVolumePlaneShader::Initialize(boo::VulkanDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4} - }; - s_VtxFmt = ctx.newVertexFormat(1, VtxVmt); - s_Pipelines[0] = ctx.newShaderPipeline(VS, FS, s_VtxFmt, boo::BlendFactor::Zero, - boo::BlendFactor::Zero, boo::Primitive::TriStrips, - boo::ZTest::LEqual, true, false, false, boo::CullMode::Frontface); - s_Pipelines[1] = ctx.newShaderPipeline(VS, FS, s_VtxFmt, boo::BlendFactor::Zero, - boo::BlendFactor::Zero, boo::Primitive::TriStrips, - boo::ZTest::None, false, false, false, boo::CullMode::Frontface); - s_Pipelines[2] = ctx.newShaderPipeline(VS, FS, s_VtxFmt, boo::BlendFactor::Zero, - boo::BlendFactor::Zero, boo::Primitive::TriStrips, - boo::ZTest::LEqual, true, false, false, boo::CullMode::Backface); - s_Pipelines[3] = ctx.newShaderPipeline(VS, FS, s_VtxFmt, boo::BlendFactor::Zero, - boo::BlendFactor::Zero, boo::Primitive::TriStrips, - boo::ZTest::Greater, false, false, false, boo::CullMode::Backface); - return new CFogVolumePlaneShaderVulkanDataBindingFactory; -} - -template <> -void CFogVolumePlaneShader::Shutdown() -{ - s_VtxFmt.reset(); - s_Pipelines[0].reset(); - s_Pipelines[1].reset(); - s_Pipelines[2].reset(); - s_Pipelines[3].reset(); -} -#endif - -} diff --git a/Runtime/Graphics/Shaders/CFogVolumePlaneShaderHLSL.cpp b/Runtime/Graphics/Shaders/CFogVolumePlaneShaderHLSL.cpp deleted file mode 100644 index 8c1ef1718..000000000 --- a/Runtime/Graphics/Shaders/CFogVolumePlaneShaderHLSL.cpp +++ /dev/null @@ -1,78 +0,0 @@ -#include "CFogVolumePlaneShader.hpp" -#include "TShader.hpp" - -namespace urde -{ - -static const char* VS = -"struct VertData\n" -"{\n" -" float4 posIn : POSITION;\n" -"};\n" -"\n" -"float4 main(in VertData v) : SV_Position\n" -"{\n" -" return v.posIn;\n" -"}\n"; - -static const char* FS = -"float4 main() : SV_Target0\n" -"{\n" -" return float4(1.0, 1.0, 1.0, 1.0);\n" -"}\n"; - -URDE_DECL_SPECIALIZE_SHADER(CFogVolumePlaneShader) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_Pipelines[4]; - -struct CFogVolumePlaneShaderD3DDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken - BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CFogVolumePlaneShader& filter) - { - boo::D3DDataFactory::Context& cctx = static_cast(ctx); - - for (int i=0 ; i<4 ; ++i) - filter.m_dataBinds[i] = cctx.newShaderDataBinding(s_Pipelines[i], s_VtxFmt, - filter.m_vbo.get(), nullptr, nullptr, 0, nullptr, - nullptr, nullptr, nullptr, 0, nullptr, nullptr, nullptr); - return filter.m_dataBinds[0]; - } -}; - -TShader::IDataBindingFactory* -CFogVolumePlaneShader::Initialize(boo::D3DDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4} - }; - s_VtxFmt = ctx.newVertexFormat(1, VtxVmt); - s_Pipelines[0] = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, nullptr, s_VtxFmt, boo::BlendFactor::Zero, - boo::BlendFactor::Zero, boo::Primitive::TriStrips, - boo::ZTest::LEqual, true, false, false, boo::CullMode::Frontface); - s_Pipelines[1] = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, nullptr, s_VtxFmt, boo::BlendFactor::Zero, - boo::BlendFactor::Zero, boo::Primitive::TriStrips, - boo::ZTest::None, false, false, false, boo::CullMode::Frontface); - s_Pipelines[2] = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, nullptr, s_VtxFmt, boo::BlendFactor::Zero, - boo::BlendFactor::Zero, boo::Primitive::TriStrips, - boo::ZTest::LEqual, true, false, false, boo::CullMode::Backface); - s_Pipelines[3] = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, nullptr, s_VtxFmt, boo::BlendFactor::Zero, - boo::BlendFactor::Zero, boo::Primitive::TriStrips, - boo::ZTest::Greater, false, false, false, boo::CullMode::Backface); - return new CFogVolumePlaneShaderD3DDataBindingFactory; -} - -template <> -void CFogVolumePlaneShader::Shutdown() -{ - s_VtxFmt.reset(); - s_Pipelines[0].reset(); - s_Pipelines[1].reset(); - s_Pipelines[2].reset(); - s_Pipelines[3].reset(); -} - -} diff --git a/Runtime/Graphics/Shaders/CFogVolumePlaneShaderMetal.cpp b/Runtime/Graphics/Shaders/CFogVolumePlaneShaderMetal.cpp deleted file mode 100644 index d918ccba1..000000000 --- a/Runtime/Graphics/Shaders/CFogVolumePlaneShaderMetal.cpp +++ /dev/null @@ -1,97 +0,0 @@ -#include "CFogVolumePlaneShader.hpp" -#include "TShader.hpp" - -namespace urde -{ - -static const char* VS = -"#include \n" -"using namespace metal;\n" -"struct VertData\n" -"{\n" -" float4 posIn [[ attribute(0) ]];\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -"};\n" -"\n" -"vertex VertToFrag vmain(VertData v [[ stage_in ]])\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.position = v.posIn;\n" -" return vtf;\n" -"}\n"; - -static const char* FS = -"#include \n" -"using namespace metal;\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -"};\n" -"\n" -"fragment float4 fmain(VertToFrag vtf [[ stage_in ]])\n" -"{\n" -" return float4(1.0, 1.0, 1.0, 1.0);\n" -"}\n"; - -URDE_DECL_SPECIALIZE_SHADER(CFogVolumePlaneShader) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_Pipelines[4]; - -struct CFogVolumePlaneShaderMetalDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CFogVolumePlaneShader& filter) - { - boo::MetalDataFactory::Context& cctx = static_cast(ctx); - - for (int i=0 ; i<4 ; ++i) - filter.m_dataBinds[i] = cctx.newShaderDataBinding(s_Pipelines[i], s_VtxFmt, - filter.m_vbo.get(), nullptr, nullptr, 0, nullptr, - nullptr, nullptr, nullptr, 0, nullptr, nullptr, nullptr); - return filter.m_dataBinds[0]; - } -}; - -TShader::IDataBindingFactory* -CFogVolumePlaneShader::Initialize(boo::MetalDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4} - }; - s_VtxFmt = ctx.newVertexFormat(1, VtxVmt); - s_Pipelines[0] = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, - s_VtxFmt, boo::BlendFactor::Zero, - boo::BlendFactor::Zero, boo::Primitive::TriStrips, - boo::ZTest::LEqual, true, false, false, boo::CullMode::Frontface); - s_Pipelines[1] = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, - s_VtxFmt, boo::BlendFactor::Zero, - boo::BlendFactor::Zero, boo::Primitive::TriStrips, - boo::ZTest::None, false, false, false, boo::CullMode::Frontface); - s_Pipelines[2] = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, - s_VtxFmt, boo::BlendFactor::Zero, - boo::BlendFactor::Zero, boo::Primitive::TriStrips, - boo::ZTest::LEqual, true, false, false, boo::CullMode::Backface); - s_Pipelines[3] = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, - s_VtxFmt, boo::BlendFactor::Zero, - boo::BlendFactor::Zero, boo::Primitive::TriStrips, - boo::ZTest::Greater, false, false, false, boo::CullMode::Backface); - return new CFogVolumePlaneShaderMetalDataBindingFactory; -} - -template <> -void CFogVolumePlaneShader::Shutdown() -{ - s_VtxFmt.reset(); - s_Pipelines[0].reset(); - s_Pipelines[1].reset(); - s_Pipelines[2].reset(); - s_Pipelines[3].reset(); -} - -} diff --git a/Runtime/Graphics/Shaders/CLineRendererShaders.cpp b/Runtime/Graphics/Shaders/CLineRendererShaders.cpp index c9e11adb4..18e867a47 100644 --- a/Runtime/Graphics/Shaders/CLineRendererShaders.cpp +++ b/Runtime/Graphics/Shaders/CLineRendererShaders.cpp @@ -1,4 +1,6 @@ #include "CLineRendererShaders.hpp" +#include "Graphics/CLineRenderer.hpp" +#include "hecl/Pipeline.hpp" namespace urde { @@ -17,43 +19,20 @@ boo::ObjToken CLineRendererShaders::m_noTexAdditiveZ; boo::ObjToken CLineRendererShaders::m_noTexAlphaZGEqual; -boo::ObjToken CLineRendererShaders::m_texVtxFmt; -boo::ObjToken CLineRendererShaders::m_noTexVtxFmt; - -std::unique_ptr CLineRendererShaders::m_bindFactory; - void CLineRendererShaders::Initialize() { - if (!CGraphics::g_BooFactory) - return; - CGraphics::CommitResources( - [&](boo::IGraphicsDataFactory::Context& ctx) + [](boo::IGraphicsDataFactory::Context& ctx) { - switch (ctx.platform()) - { -#if BOO_HAS_GL - case boo::IGraphicsDataFactory::Platform::OpenGL: - m_bindFactory.reset(Initialize(static_cast(ctx))); - break; -#endif -#if _WIN32 - case boo::IGraphicsDataFactory::Platform::D3D11: - m_bindFactory.reset(Initialize(static_cast(ctx))); - break; -#endif -#if BOO_HAS_METAL - case boo::IGraphicsDataFactory::Platform::Metal: - m_bindFactory.reset(Initialize(static_cast(ctx))); - break; -#endif -#if BOO_HAS_VULKAN - case boo::IGraphicsDataFactory::Platform::Vulkan: - m_bindFactory.reset(Initialize(static_cast(ctx))); - break; -#endif - default: break; - } + m_texAlpha = hecl::conv->convert(ctx, Shader_CLineRendererShaderTexAlpha{}); + m_texAdditive = hecl::conv->convert(ctx, Shader_CLineRendererShaderTexAdditive{}); + m_noTexAlpha = hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAlpha{}); + m_noTexAdditive = hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAdditive{}); + m_texAlphaZ = hecl::conv->convert(ctx, Shader_CLineRendererShaderTexAlphaZ{}); + m_texAdditiveZ = hecl::conv->convert(ctx, Shader_CLineRendererShaderTexAdditiveZ{}); + m_noTexAlphaZ = hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAlphaZ{}); + m_noTexAdditiveZ = hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAdditiveZ{}); + m_noTexAlphaZGEqual = hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAlphaZGEqual{}); return true; } BooTrace); } @@ -69,8 +48,6 @@ void CLineRendererShaders::Shutdown() m_noTexAlphaZ.reset(); m_noTexAdditiveZ.reset(); m_noTexAlphaZGEqual.reset(); - m_texVtxFmt.reset(); - m_noTexVtxFmt.reset(); } void CLineRendererShaders::BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, @@ -119,7 +96,34 @@ void CLineRendererShaders::BuildShaderDataBinding(boo::IGraphicsDataFactory::Con } } - m_bindFactory->BuildShaderDataBinding(ctx, renderer, pipeline, texture); + int texCount = 0; + boo::ObjToken textures[1]; + + std::pair, + hecl::VertexBufferPool::IndexTp> vbufInfo; + std::pair, + hecl::UniformBufferPool::IndexTp> ubufInfo = + renderer.m_uniformBuf.getBufferInfo(); + if (texture) + { + vbufInfo = renderer.m_vertBufTex.getBufferInfo(); + textures[0] = texture; + texCount = 1; + } + else + { + vbufInfo = renderer.m_vertBufNoTex.getBufferInfo(); + } + + boo::ObjToken uniforms[] = {ubufInfo.first.get()}; + boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; + size_t ubufOffs[] = {size_t(ubufInfo.second)}; + size_t ubufSizes[] = {sizeof(CLineRenderer::SDrawUniform)}; + + renderer.m_shaderBind = ctx.newShaderDataBinding(pipeline, vbufInfo.first.get(), + nullptr, nullptr, 1, uniforms, stages, + ubufOffs, ubufSizes, texCount, textures, + nullptr, nullptr, vbufInfo.second); } } diff --git a/Runtime/Graphics/Shaders/CLineRendererShaders.hpp b/Runtime/Graphics/Shaders/CLineRendererShaders.hpp index ed4c1ff69..4bee04a49 100644 --- a/Runtime/Graphics/Shaders/CLineRendererShaders.hpp +++ b/Runtime/Graphics/Shaders/CLineRendererShaders.hpp @@ -2,10 +2,7 @@ #define __URDE_CLINERENDERERSHADERS_HPP__ #include "Graphics/CGraphics.hpp" -#include "boo/graphicsdev/GL.hpp" -#include "boo/graphicsdev/D3D.hpp" -#include "boo/graphicsdev/Metal.hpp" -#include "boo/graphicsdev/Vulkan.hpp" +#include "boo/graphicsdev/IGraphicsDataFactory.hpp" namespace urde { @@ -13,17 +10,6 @@ class CLineRenderer; class CLineRendererShaders { -public: - struct IDataBindingFactory - { - virtual void BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CLineRenderer& renderer, - const boo::ObjToken& pipeline, - const boo::ObjToken& texture)=0; - virtual ~IDataBindingFactory() = default; - }; - -private: static boo::ObjToken m_texAlpha; static boo::ObjToken m_texAdditive; @@ -38,25 +24,7 @@ private: static boo::ObjToken m_noTexAlphaZGEqual; - static boo::ObjToken m_texVtxFmt; - static boo::ObjToken m_noTexVtxFmt; - - static std::unique_ptr m_bindFactory; - public: -#if BOO_HAS_GL - static IDataBindingFactory* Initialize(boo::GLDataFactory::Context& ctx); -#endif -#if _WIN32 - static IDataBindingFactory* Initialize(boo::D3DDataFactory::Context& ctx); -#endif -#if BOO_HAS_METAL - static IDataBindingFactory* Initialize(boo::MetalDataFactory::Context& ctx); -#endif -#if BOO_HAS_VULKAN - static IDataBindingFactory* Initialize(boo::VulkanDataFactory::Context& ctx); -#endif - static void Initialize(); static void Shutdown(); static void BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, CLineRenderer& renderer, diff --git a/Runtime/Graphics/Shaders/CLineRendererShadersGLSL.cpp b/Runtime/Graphics/Shaders/CLineRendererShadersGLSL.cpp deleted file mode 100644 index 4ce6faa8b..000000000 --- a/Runtime/Graphics/Shaders/CLineRendererShadersGLSL.cpp +++ /dev/null @@ -1,286 +0,0 @@ -#include "CLineRendererShaders.hpp" -#include "Graphics/CLineRenderer.hpp" -#include "hecl/VertexBufferPool.hpp" - -namespace urde -{ - -static const char* VS_GLSL_TEX = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"layout(location=0) in vec4 posIn;\n" -"layout(location=1) in vec4 colorIn;\n" -"layout(location=2) in vec4 uvIn;\n" -"\n" -"UBINDING0 uniform LineUniform\n" -"{\n" -" vec4 moduColor;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -" vec2 uv;\n" -"};\n" -"\n" -"SBINDING(0) out VertToFrag vtf;\n" -"void main()\n" -"{\n" -" vtf.color = colorIn * moduColor;\n" -" vtf.uv = uvIn.xy;\n" -" gl_Position = posIn;\n" -"}\n"; - -static const char* FS_GLSL_TEX = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -" vec2 uv;\n" -"};\n" -"\n" -"SBINDING(0) in VertToFrag vtf;\n" -"layout(location=0) out vec4 colorOut;\n" -"TBINDING0 uniform sampler2D tex;\n" -"void main()\n" -"{\n" -" colorOut = vtf.color * texture(tex, vtf.uv);\n" -"}\n"; - -static const char* VS_GLSL_NOTEX = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"layout(location=0) in vec4 posIn;\n" -"layout(location=1) in vec4 colorIn;\n" -"\n" -"UBINDING0 uniform LineUniform\n" -"{\n" -" vec4 moduColor;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -"};\n" -"\n" -"SBINDING(0) out VertToFrag vtf;\n" -"void main()\n" -"{\n" -" vtf.color = colorIn * moduColor;\n" -" gl_Position = posIn;\n" -"}\n"; - -static const char* FS_GLSL_NOTEX = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -"};\n" -"\n" -"SBINDING(0) in VertToFrag vtf;\n" -"layout(location=0) out vec4 colorOut;\n" -"void main()\n" -"{\n" -" colorOut = vtf.color;\n" -"}\n"; - -struct OGLLineDataBindingFactory : CLineRendererShaders::IDataBindingFactory -{ - void BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CLineRenderer& renderer, - const boo::ObjToken& pipeline, - const boo::ObjToken& texture) - { - boo::ObjToken vtxFmt; - int texCount = 0; - boo::ObjToken textures[1]; - - std::pair, - hecl::VertexBufferPool::IndexTp> vbufInfo; - std::pair, - hecl::UniformBufferPool::IndexTp> ubufInfo = - renderer.m_uniformBuf.getBufferInfo(); - if (texture) - { - vbufInfo = renderer.m_vertBufTex.getBufferInfo(); - textures[0] = texture; - texCount = 1; - const boo::VertexElementDescriptor TexFmtTex[] = - { - {vbufInfo.first.get(), nullptr, boo::VertexSemantic::Position4}, - {vbufInfo.first.get(), nullptr, boo::VertexSemantic::Color}, - {vbufInfo.first.get(), nullptr, boo::VertexSemantic::UV4} - }; - vtxFmt = ctx.newVertexFormat(3, TexFmtTex, vbufInfo.second); - } - else - { - vbufInfo = renderer.m_vertBufNoTex.getBufferInfo(); - const boo::VertexElementDescriptor TexFmtNoTex[] = - { - {vbufInfo.first.get(), nullptr, boo::VertexSemantic::Position4}, - {vbufInfo.first.get(), nullptr, boo::VertexSemantic::Color} - }; - vtxFmt = ctx.newVertexFormat(2, TexFmtNoTex, vbufInfo.second); - } - - boo::ObjToken uniforms[] = {ubufInfo.first.get()}; - boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; - size_t ubufOffs[] = {size_t(ubufInfo.second)}; - size_t ubufSizes[] = {sizeof(CLineRenderer::SDrawUniform)}; - - renderer.m_shaderBind = ctx.newShaderDataBinding(pipeline, vtxFmt, vbufInfo.first.get(), - nullptr, nullptr, 1, uniforms, stages, - ubufOffs, ubufSizes, texCount, textures, - nullptr, nullptr, vbufInfo.second); - } -}; - -CLineRendererShaders::IDataBindingFactory* CLineRendererShaders::Initialize(boo::GLDataFactory::Context& ctx) -{ - static const char* UniNames[] = {"LineUniform"}; - static const char* TexNames[] = {"tex"}; - - m_texAlpha = ctx.newShaderPipeline(VS_GLSL_TEX, FS_GLSL_TEX, 1, TexNames, 1, UniNames, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::None, - false, true, false, boo::CullMode::None); - m_texAdditive = ctx.newShaderPipeline(VS_GLSL_TEX, FS_GLSL_TEX, 1, TexNames, 1, UniNames, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::None, - false, true, false, boo::CullMode::None); - m_noTexAlpha = ctx.newShaderPipeline(VS_GLSL_NOTEX, FS_GLSL_NOTEX, 0, nullptr, 1, UniNames, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::None, - false, true, false, boo::CullMode::None); - m_noTexAdditive = ctx.newShaderPipeline(VS_GLSL_NOTEX, FS_GLSL_NOTEX, 0, nullptr, 1, UniNames, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::None, - false, true, false, boo::CullMode::None); - - m_texAlphaZ = ctx.newShaderPipeline(VS_GLSL_TEX, FS_GLSL_TEX, 1, TexNames, 1, UniNames, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, - false, true, false, boo::CullMode::None); - m_texAdditiveZ = ctx.newShaderPipeline(VS_GLSL_TEX, FS_GLSL_TEX, 1, TexNames, 1, UniNames, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, - false, true, false, boo::CullMode::None); - m_noTexAlphaZ = ctx.newShaderPipeline(VS_GLSL_NOTEX, FS_GLSL_NOTEX, 0, nullptr, 1, UniNames, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, - false, true, false, boo::CullMode::None); - m_noTexAdditiveZ = ctx.newShaderPipeline(VS_GLSL_NOTEX, FS_GLSL_NOTEX, 0, nullptr, 1, UniNames, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, - false, true, false, boo::CullMode::None); - - m_noTexAlphaZGEqual = ctx.newShaderPipeline(VS_GLSL_NOTEX, FS_GLSL_NOTEX, 0, nullptr, 1, UniNames, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::GEqual, - false, true, false, boo::CullMode::None); - - return new struct OGLLineDataBindingFactory; -} - -#if BOO_HAS_VULKAN -struct VulkanLineDataBindingFactory : CLineRendererShaders::IDataBindingFactory -{ - void BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, CLineRenderer& renderer, - const boo::ObjToken& pipeline, - const boo::ObjToken& texture) - { - int texCount = 0; - boo::ObjToken textures[1]; - - std::pair, - hecl::VertexBufferPool::IndexTp> vbufInfo; - std::pair, - hecl::UniformBufferPool::IndexTp> ubufInfo = - renderer.m_uniformBuf.getBufferInfo(); - if (texture) - { - vbufInfo = renderer.m_vertBufTex.getBufferInfo(); - textures[0] = texture; - texCount = 1; - } - else - { - vbufInfo = renderer.m_vertBufNoTex.getBufferInfo(); - } - - boo::ObjToken uniforms[] = {ubufInfo.first.get()}; - boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; - size_t ubufOffs[] = {size_t(ubufInfo.second)}; - size_t ubufSizes[] = {sizeof(CLineRenderer::SDrawUniform)}; - - renderer.m_shaderBind = ctx.newShaderDataBinding(pipeline, nullptr, vbufInfo.first.get(), - nullptr, nullptr, 1, uniforms, - stages, ubufOffs, ubufSizes, texCount, textures, - nullptr, nullptr, vbufInfo.second); - } -}; - -CLineRendererShaders::IDataBindingFactory* CLineRendererShaders::Initialize(boo::VulkanDataFactory::Context& ctx) -{ - static const boo::VertexElementDescriptor VtxFmtTex[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::Color}, - {nullptr, nullptr, boo::VertexSemantic::UV4} - }; - m_texVtxFmt = ctx.newVertexFormat(3, VtxFmtTex); - - static const boo::VertexElementDescriptor VtxFmtNoTex[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::Color} - }; - m_noTexVtxFmt = ctx.newVertexFormat(2, VtxFmtNoTex); - - m_texAlpha = ctx.newShaderPipeline(VS_GLSL_TEX, FS_GLSL_TEX, m_texVtxFmt, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::None, - false, true, false, boo::CullMode::None); - m_texAdditive = ctx.newShaderPipeline(VS_GLSL_TEX, FS_GLSL_TEX, m_texVtxFmt, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::None, - false, true, false, boo::CullMode::None); - m_noTexAlpha = ctx.newShaderPipeline(VS_GLSL_NOTEX, FS_GLSL_NOTEX, m_noTexVtxFmt, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::None, - false, true, false, boo::CullMode::None); - m_noTexAdditive = ctx.newShaderPipeline(VS_GLSL_NOTEX, FS_GLSL_NOTEX, m_noTexVtxFmt, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::None, - false, true, false, boo::CullMode::None); - - m_texAlphaZ = ctx.newShaderPipeline(VS_GLSL_TEX, FS_GLSL_TEX, m_texVtxFmt, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, - false, true, false, boo::CullMode::None); - m_texAdditiveZ = ctx.newShaderPipeline(VS_GLSL_TEX, FS_GLSL_TEX, m_texVtxFmt, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, - false, true, false, boo::CullMode::None); - m_noTexAlphaZ = ctx.newShaderPipeline(VS_GLSL_NOTEX, FS_GLSL_NOTEX, m_noTexVtxFmt, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, - false, true, false, boo::CullMode::None); - m_noTexAdditiveZ = ctx.newShaderPipeline(VS_GLSL_NOTEX, FS_GLSL_NOTEX, m_noTexVtxFmt, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, - false, true, false, boo::CullMode::None); - - m_noTexAlphaZGEqual = ctx.newShaderPipeline(VS_GLSL_NOTEX, FS_GLSL_NOTEX, m_noTexVtxFmt, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::GEqual, - false, true, false, boo::CullMode::None); - - return new struct VulkanLineDataBindingFactory; -} -#endif - -} diff --git a/Runtime/Graphics/Shaders/CLineRendererShadersHLSL.cpp b/Runtime/Graphics/Shaders/CLineRendererShadersHLSL.cpp deleted file mode 100644 index ac16db0a1..000000000 --- a/Runtime/Graphics/Shaders/CLineRendererShadersHLSL.cpp +++ /dev/null @@ -1,194 +0,0 @@ -#include "CLineRendererShaders.hpp" -#include "Graphics/CLineRenderer.hpp" - -namespace urde -{ - -static const char* VS_HLSL_TEX = -"struct VertData\n" -"{\n" -" float4 posIn : POSITION;\n" -" float4 colorIn : COLOR;\n" -" float4 uvIn : UV;\n" -"};\n" -"\n" -"cbuffer LineUniform : register(b0)\n" -"{\n" -" float4 moduColor;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float4 color : COLOR;\n" -" float2 uv : UV;\n" -"};\n" -"\n" -"VertToFrag main(in VertData v)\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.color = v.colorIn * moduColor;\n" -" vtf.uv = v.uvIn.xy;\n" -" vtf.position = v.posIn;\n" -" return vtf;\n" -"}\n"; - -static const char* FS_HLSL_TEX = -"SamplerState samp : register(s0);\n" -"Texture2D tex0 : register(t0);\n" -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float4 color : COLOR;\n" -" float2 uv : UV;\n" -"};\n" -"\n" -"float4 main(in VertToFrag vtf) : SV_Target0\n" -"{\n" -" return vtf.color * tex0.Sample(samp, vtf.uv);\n" -"}\n"; - -static const char* VS_HLSL_NOTEX = -"struct VertData\n" -"{\n" -" float4 posIn : POSITION;\n" -" float4 colorIn : COLOR;\n" -"};\n" -"\n" -"cbuffer LineUniform : register(b0)\n" -"{\n" -" float4 moduColor;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float4 color : COLOR;\n" -"};\n" -"\n" -"VertToFrag main(in VertData v)\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.color = v.colorIn * moduColor;\n" -" vtf.position = v.posIn;\n" -" return vtf;\n" -"}\n"; - -static const char* FS_HLSL_NOTEX = -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float4 color : COLOR;\n" -"};\n" -"\n" -"float4 main(in VertToFrag vtf) : SV_Target0\n" -"{\n" -" return vtf.color;\n" -"}\n"; - -struct HLSLLineDataBindingFactory : CLineRendererShaders::IDataBindingFactory -{ - void BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, CLineRenderer& renderer, - const boo::ObjToken& pipeline, - const boo::ObjToken& texture) - { - int texCount = 0; - boo::ObjToken textures[1]; - - std::pair, - hecl::VertexBufferPool::IndexTp> vbufInfo; - std::pair, - hecl::UniformBufferPool::IndexTp> ubufInfo = - renderer.m_uniformBuf.getBufferInfo(); - if (texture) - { - vbufInfo = renderer.m_vertBufTex.getBufferInfo(); - textures[0] = texture; - texCount = 1; - } - else - { - vbufInfo = renderer.m_vertBufNoTex.getBufferInfo(); - } - - boo::ObjToken uniforms[] = {ubufInfo.first.get()}; - boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; - size_t ubufOffs[] = {size_t(ubufInfo.second)}; - size_t ubufSizes[] = {sizeof(CLineRenderer::SDrawUniform)}; - - renderer.m_shaderBind = ctx.newShaderDataBinding(pipeline, nullptr, vbufInfo.first.get(), - nullptr, nullptr, 1, uniforms, stages, - ubufOffs, ubufSizes, texCount, textures, - nullptr, nullptr, vbufInfo.second); - } -}; - -CLineRendererShaders::IDataBindingFactory* CLineRendererShaders::Initialize(boo::D3DDataFactory::Context& ctx) -{ - static const boo::VertexElementDescriptor VtxFmtTex[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::Color}, - {nullptr, nullptr, boo::VertexSemantic::UV4} - }; - m_texVtxFmt = ctx.newVertexFormat(3, VtxFmtTex); - - static const boo::VertexElementDescriptor VtxFmtNoTex[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::Color} - }; - m_noTexVtxFmt = ctx.newVertexFormat(2, VtxFmtNoTex); - - m_texAlpha = ctx.newShaderPipeline(VS_HLSL_TEX, FS_HLSL_TEX, nullptr, nullptr, - nullptr, m_texVtxFmt, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::None, - false, true, false, boo::CullMode::None); - m_texAdditive = ctx.newShaderPipeline(VS_HLSL_TEX, FS_HLSL_TEX, nullptr, nullptr, - nullptr, m_texVtxFmt, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::None, - false, true, false, boo::CullMode::None); - m_noTexAlpha = ctx.newShaderPipeline(VS_HLSL_NOTEX, FS_HLSL_NOTEX, nullptr, nullptr, - nullptr, m_noTexVtxFmt, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::None, - false, true, false, boo::CullMode::None); - m_noTexAdditive = ctx.newShaderPipeline(VS_HLSL_NOTEX, FS_HLSL_NOTEX, nullptr, nullptr, - nullptr, m_noTexVtxFmt, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::None, - false, true, false, boo::CullMode::None); - - m_texAlphaZ = ctx.newShaderPipeline(VS_HLSL_TEX, FS_HLSL_TEX, nullptr, nullptr, - nullptr, m_texVtxFmt, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, - false, true, false, boo::CullMode::None); - m_texAdditiveZ = ctx.newShaderPipeline(VS_HLSL_TEX, FS_HLSL_TEX, nullptr, nullptr, - nullptr, m_texVtxFmt, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, - false, true, false, boo::CullMode::None); - m_noTexAlphaZ = ctx.newShaderPipeline(VS_HLSL_NOTEX, FS_HLSL_NOTEX, nullptr, nullptr, - nullptr, m_noTexVtxFmt, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, - false, true, false, boo::CullMode::None); - m_noTexAdditiveZ = ctx.newShaderPipeline(VS_HLSL_NOTEX, FS_HLSL_NOTEX, nullptr, nullptr, - nullptr, m_noTexVtxFmt, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, - false, true, false, boo::CullMode::None); - - m_noTexAlphaZGEqual = ctx.newShaderPipeline(VS_HLSL_NOTEX, FS_HLSL_NOTEX, nullptr, nullptr, - nullptr, m_noTexVtxFmt, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::GEqual, - false, true, false, boo::CullMode::None); - - return new struct HLSLLineDataBindingFactory; -} - -} diff --git a/Runtime/Graphics/Shaders/CLineRendererShadersMetal.cpp b/Runtime/Graphics/Shaders/CLineRendererShadersMetal.cpp deleted file mode 100644 index eac89dcd9..000000000 --- a/Runtime/Graphics/Shaders/CLineRendererShadersMetal.cpp +++ /dev/null @@ -1,202 +0,0 @@ -#include "CLineRendererShaders.hpp" -#include "Graphics/CLineRenderer.hpp" -#if BOO_HAS_METAL - -namespace urde -{ - -static const char* VS_METAL_TEX = -"#include \n" -"using namespace metal;\n" -"struct VertData\n" -"{\n" -" float4 posIn;\n" -" float4 colorIn;\n" -" float4 uvIn;\n" -"};\n" -"\n" -"struct LineUniform\n" -"{\n" -" float4 moduColor;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float4 color;\n" -" float2 uv;\n" -"};\n" -"\n" -"vertex VertToFrag vmain(constant VertData* va [[ buffer(0) ]],\n" -" uint vertId [[ vertex_id ]],\n" -" constant LineUniform& line [[ buffer(2) ]])\n" -"{\n" -" VertToFrag vtf;\n" -" constant VertData& v = va[vertId];\n" -" vtf.color = v.colorIn * line.moduColor;\n" -" vtf.uv = v.uvIn.xy;\n" -" vtf.position = v.posIn;\n" -" return vtf;\n" -"}\n"; - -static const char* FS_METAL_TEX = -"#include \n" -"using namespace metal;\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float4 color;\n" -" float2 uv;\n" -"};\n" -"\n" -"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n" -" sampler samp [[ sampler(0) ]],\n" -" texture2d tex0 [[ texture(0) ]])\n" -"{\n" -" return vtf.color * tex0.sample(samp, vtf.uv);\n" -"}\n"; - -static const char* VS_METAL_NOTEX = -"#include \n" -"using namespace metal;\n" -"struct VertData\n" -"{\n" -" float4 posIn;\n" -" float4 colorIn;\n" -"};\n" -"\n" -"struct LineUniform\n" -"{\n" -" float4 moduColor;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float4 color;\n" -"};\n" -"\n" -"vertex VertToFrag vmain(constant VertData* va [[ buffer(0) ]],\n" -" uint vertId [[ vertex_id ]],\n" -" constant LineUniform& line [[ buffer(2) ]])\n" -"{\n" -" VertToFrag vtf;\n" -" constant VertData& v = va[vertId];\n" -" vtf.color = v.colorIn * line.moduColor;\n" -" vtf.position = v.posIn;\n" -" return vtf;\n" -"}\n"; - -static const char* FS_METAL_NOTEX = -"#include \n" -"using namespace metal;\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float4 color;\n" -"};\n" -"\n" -"fragment float4 fmain(VertToFrag vtf [[ stage_in ]])\n" -"{\n" -" return vtf.color;\n" -"}\n"; - -struct MetalLineDataBindingFactory : CLineRendererShaders::IDataBindingFactory -{ - void BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CLineRenderer& renderer, - const boo::ObjToken& pipeline, - const boo::ObjToken& texture) - { - int texCount = 0; - boo::ObjToken textures[1]; - - std::pair, - hecl::VertexBufferPool::IndexTp> vbufInfo; - std::pair, - hecl::UniformBufferPool::IndexTp> ubufInfo = - renderer.m_uniformBuf.getBufferInfo(); - if (texture) - { - vbufInfo = renderer.m_vertBufTex.getBufferInfo(); - textures[0] = texture; - texCount = 1; - } - else - { - vbufInfo = renderer.m_vertBufNoTex.getBufferInfo(); - } - - boo::ObjToken uniforms[] = {ubufInfo.first.get()}; - boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; - size_t ubufOffs[] = {ubufInfo.second}; - size_t ubufSizes[] = {sizeof(CLineRenderer::SDrawUniform)}; - - renderer.m_shaderBind = ctx.newShaderDataBinding(pipeline, nullptr, vbufInfo.first.get(), - nullptr, nullptr, 1, uniforms, stages, - ubufOffs, ubufSizes, texCount, textures, - nullptr, nullptr, vbufInfo.second); - } -}; - -CLineRendererShaders::IDataBindingFactory* CLineRendererShaders::Initialize(boo::MetalDataFactory::Context& ctx) -{ - static const boo::VertexElementDescriptor VtxFmtTex[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::Color}, - {nullptr, nullptr, boo::VertexSemantic::UV4} - }; - m_texVtxFmt = ctx.newVertexFormat(3, VtxFmtTex); - - static const boo::VertexElementDescriptor VtxFmtNoTex[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::Color} - }; - m_noTexVtxFmt = ctx.newVertexFormat(2, VtxFmtNoTex); - - m_texAlpha = ctx.newShaderPipeline(VS_METAL_TEX, FS_METAL_TEX, nullptr, nullptr, m_texVtxFmt, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::None, - false, true, false, boo::CullMode::None); - m_texAdditive = ctx.newShaderPipeline(VS_METAL_TEX, FS_METAL_TEX, nullptr, nullptr, m_texVtxFmt, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::None, - false, true, false, boo::CullMode::None); - m_noTexAlpha = ctx.newShaderPipeline(VS_METAL_NOTEX, FS_METAL_NOTEX, nullptr, nullptr, m_noTexVtxFmt, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::None, - false, true, false, boo::CullMode::None); - m_noTexAdditive = ctx.newShaderPipeline(VS_METAL_NOTEX, FS_METAL_NOTEX, nullptr, nullptr, m_noTexVtxFmt, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::None, - false, true, false, boo::CullMode::None); - - m_texAlphaZ = ctx.newShaderPipeline(VS_METAL_TEX, FS_METAL_TEX, nullptr, nullptr, m_texVtxFmt, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, - false, true, false, boo::CullMode::None); - m_texAdditiveZ = ctx.newShaderPipeline(VS_METAL_TEX, FS_METAL_TEX, nullptr, nullptr, m_texVtxFmt, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, - false, true, false, boo::CullMode::None); - m_noTexAlphaZ = ctx.newShaderPipeline(VS_METAL_NOTEX, FS_METAL_NOTEX, nullptr, nullptr, m_noTexVtxFmt, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, - false, true, false, boo::CullMode::None); - m_noTexAdditiveZ = ctx.newShaderPipeline(VS_METAL_NOTEX, FS_METAL_NOTEX, nullptr, nullptr, m_noTexVtxFmt, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, - false, true, false, boo::CullMode::None); - - m_noTexAlphaZGEqual = ctx.newShaderPipeline(VS_METAL_NOTEX, FS_METAL_NOTEX, nullptr, nullptr, m_noTexVtxFmt, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::GEqual, - false, true, false, boo::CullMode::None); - - return new struct MetalLineDataBindingFactory; -} - -} -#endif diff --git a/Runtime/Graphics/Shaders/CMapSurfaceShader.cpp b/Runtime/Graphics/Shaders/CMapSurfaceShader.cpp index 38c079172..ed4fa019a 100644 --- a/Runtime/Graphics/Shaders/CMapSurfaceShader.cpp +++ b/Runtime/Graphics/Shaders/CMapSurfaceShader.cpp @@ -1,15 +1,32 @@ #include "CMapSurfaceShader.hpp" +#include "hecl/Pipeline.hpp" +#include "Graphics/CGraphics.hpp" namespace urde { +static boo::ObjToken s_Pipeline; + +void CMapSurfaceShader::Initialize() +{ + s_Pipeline = hecl::conv->convert(Shader_CMapSurfaceShader{}); +} + +void CMapSurfaceShader::Shutdown() +{ + s_Pipeline.reset(); +} + CMapSurfaceShader::CMapSurfaceShader(boo::IGraphicsDataFactory::Context& ctx, const boo::ObjToken& vbo, const boo::ObjToken& ibo) : m_vbo(vbo), m_ibo(ibo) { m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); - m_dataBind = TShader::BuildShaderDataBinding(ctx, *this); + boo::ObjToken bufs[] = {m_uniBuf.get()}; + boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; + m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, m_ibo.get(), + 1, bufs, stages, nullptr, nullptr, 0, nullptr, nullptr, nullptr); } void CMapSurfaceShader::draw(const zeus::CColor& color, u32 start, u32 count) @@ -22,6 +39,4 @@ void CMapSurfaceShader::draw(const zeus::CColor& color, u32 start, u32 count) CGraphics::DrawArrayIndexed(start, count); } -URDE_SPECIALIZE_SHADER(CMapSurfaceShader) - } diff --git a/Runtime/Graphics/Shaders/CMapSurfaceShader.hpp b/Runtime/Graphics/Shaders/CMapSurfaceShader.hpp index 94712a132..b9d3dafb1 100644 --- a/Runtime/Graphics/Shaders/CMapSurfaceShader.hpp +++ b/Runtime/Graphics/Shaders/CMapSurfaceShader.hpp @@ -1,18 +1,16 @@ #ifndef __URDE_CMAPSURFACESHADER_HPP__ #define __URDE_CMAPSURFACESHADER_HPP__ -#include "TShader.hpp" +#include "RetroTypes.hpp" +#include "boo/graphicsdev/IGraphicsDataFactory.hpp" +#include "zeus/CMatrix4f.hpp" +#include "zeus/CColor.hpp" namespace urde { class CMapSurfaceShader { - friend struct CMapSurfaceShaderGLDataBindingFactory; - friend struct CMapSurfaceShaderVulkanDataBindingFactory; - friend struct CMapSurfaceShaderMetalDataBindingFactory; - friend struct CMapSurfaceShaderD3DDataBindingFactory; - struct Uniform { zeus::CMatrix4f mtx; @@ -25,12 +23,11 @@ class CMapSurfaceShader boo::ObjToken m_dataBind; public: + static void Initialize(); + static void Shutdown(); CMapSurfaceShader(boo::IGraphicsDataFactory::Context& ctx, const boo::ObjToken& vbo, const boo::ObjToken& ibo); void draw(const zeus::CColor& color, u32 start, u32 count); - - using _CLS = CMapSurfaceShader; -#include "TShaderDecl.hpp" }; } diff --git a/Runtime/Graphics/Shaders/CMapSurfaceShaderGLSL.cpp b/Runtime/Graphics/Shaders/CMapSurfaceShaderGLSL.cpp deleted file mode 100644 index 917616114..000000000 --- a/Runtime/Graphics/Shaders/CMapSurfaceShaderGLSL.cpp +++ /dev/null @@ -1,128 +0,0 @@ -#include "CMapSurfaceShader.hpp" - -namespace urde -{ - -static const char* VS = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"layout(location=0) in vec4 posIn;\n" -"\n" -"UBINDING0 uniform MapSurfaceUniform\n" -"{\n" -" mat4 xf;\n" -" vec4 color;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -"};\n" -"\n" -"SBINDING(0) out VertToFrag vtf;\n" -"void main()\n" -"{\n" -" vtf.color = color;\n" -" gl_Position = xf * vec4(posIn.xyz, 1.0);\n" -"}\n"; - -static const char* FS = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -"};\n" -"\n" -"SBINDING(0) in VertToFrag vtf;\n" -"layout(location=0) out vec4 colorOut;\n" -"void main()\n" -"{\n" -" colorOut = vtf.color;\n" -"}\n"; - -URDE_DECL_SPECIALIZE_SHADER(CMapSurfaceShader) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_Pipeline; - -struct CMapSurfaceShaderGLDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CMapSurfaceShader& filter) - { - boo::GLDataFactory::Context& cctx = static_cast(ctx); - - const boo::VertexElementDescriptor VtxVmt[] = - { - {filter.m_vbo.get(), filter.m_ibo.get(), boo::VertexSemantic::Position4} - }; - boo::ObjToken vtxFmt = ctx.newVertexFormat(1, VtxVmt); - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; - filter.m_dataBind = cctx.newShaderDataBinding(s_Pipeline, - vtxFmt, filter.m_vbo.get(), nullptr, filter.m_ibo.get(), - 1, bufs, stages, nullptr, nullptr, 0, nullptr, nullptr, nullptr); - return filter.m_dataBind; - } -}; - -#if BOO_HAS_VULKAN -struct CMapSurfaceShaderVulkanDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken - BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CMapSurfaceShader& filter) - { - boo::VulkanDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - filter.m_dataBind = cctx.newShaderDataBinding(s_Pipeline, s_VtxFmt, - filter.m_vbo.get(), nullptr, filter.m_ibo.get(), 1, bufs, - nullptr, nullptr, nullptr, 0, nullptr, nullptr, nullptr); - return filter.m_dataBind; - } -}; -#endif - -TShader::IDataBindingFactory* -CMapSurfaceShader::Initialize(boo::GLDataFactory::Context& ctx) -{ - const char* uniNames[] = {"MapSurfaceUniform"}; - s_Pipeline = ctx.newShaderPipeline(VS, FS, 0, nullptr, 1, uniNames, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::GEqual, false, true, - false, boo::CullMode::Backface); - return new CMapSurfaceShaderGLDataBindingFactory; -} - -template <> -void CMapSurfaceShader::Shutdown() -{ - s_Pipeline.reset(); -} - -#if BOO_HAS_VULKAN -TShader::IDataBindingFactory* -CMapSurfaceShader::Initialize(boo::VulkanDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4} - }; - s_VtxFmt = ctx.newVertexFormat(1, VtxVmt); - s_Pipeline = ctx.newShaderPipeline(VS, FS, s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::GEqual, false, true, false, boo::CullMode::Backface); - return new CMapSurfaceShaderVulkanDataBindingFactory; -} - -template <> -void CMapSurfaceShader::Shutdown() -{ - s_VtxFmt.reset(); - s_Pipeline.reset(); -} -#endif - -} diff --git a/Runtime/Graphics/Shaders/CMapSurfaceShaderHLSL.cpp b/Runtime/Graphics/Shaders/CMapSurfaceShaderHLSL.cpp deleted file mode 100644 index ac581e7f6..000000000 --- a/Runtime/Graphics/Shaders/CMapSurfaceShaderHLSL.cpp +++ /dev/null @@ -1,86 +0,0 @@ -#include "CMapSurfaceShader.hpp" - -namespace urde -{ - -static const char* VS = -"struct VertData\n" -"{\n" -" float4 posIn : POSITION;\n" -"};\n" -"\n" -"cbuffer MapSurfaceUniform : register(b0)\n" -"{\n" -" float4x4 xf;\n" -" float4 color;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float4 color : COLOR;\n" -"};\n" -"\n" -"VertToFrag main(in VertData v)\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.color = color;\n" -" vtf.position = mul(xf, float4(v.posIn.xyz, 1.0));\n" -" return vtf;\n" -"}\n"; - -static const char* FS = -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float4 color : COLOR;\n" -"};\n" -"\n" -"float4 main(in VertToFrag vtf) : SV_Target0\n" -"{\n" -" return vtf.color;\n" -"}\n"; - -URDE_DECL_SPECIALIZE_SHADER(CMapSurfaceShader) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_Pipeline; - -struct CMapSurfaceShaderD3DDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken - BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CMapSurfaceShader& filter) - { - boo::D3DDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - filter.m_dataBind = cctx.newShaderDataBinding(s_Pipeline, s_VtxFmt, - filter.m_vbo.get(), nullptr, filter.m_ibo.get(), 1, bufs, - nullptr, nullptr, nullptr, 0, nullptr, nullptr, nullptr); - return filter.m_dataBind; - } -}; - -TShader::IDataBindingFactory* -CMapSurfaceShader::Initialize(boo::D3DDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4} - }; - s_VtxFmt = ctx.newVertexFormat(1, VtxVmt); - s_Pipeline = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, nullptr, s_VtxFmt, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::GEqual, false, true, false, boo::CullMode::Backface); - return new CMapSurfaceShaderD3DDataBindingFactory; -} - -template <> -void CMapSurfaceShader::Shutdown() -{ - s_VtxFmt.reset(); - s_Pipeline.reset(); -} - -} diff --git a/Runtime/Graphics/Shaders/CMapSurfaceShaderMetal.cpp b/Runtime/Graphics/Shaders/CMapSurfaceShaderMetal.cpp deleted file mode 100644 index e3f92aed3..000000000 --- a/Runtime/Graphics/Shaders/CMapSurfaceShaderMetal.cpp +++ /dev/null @@ -1,89 +0,0 @@ -#include "CMapSurfaceShader.hpp" - -namespace urde -{ - -static const char* VS = -"#include \n" -"using namespace metal;\n" -"struct VertData\n" -"{\n" -" float4 posIn [[ attribute(0) ]];\n" -"};\n" -"\n" -"struct MapSurfaceUniform\n" -"{\n" -" float4x4 xf;\n" -" float4 color;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float4 color;\n" -"};\n" -"\n" -"vertex VertToFrag vmain(VertData v [[ stage_in ]], constant MapSurfaceUniform& msu [[ buffer(2) ]])\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.color = msu.color;\n" -" vtf.position = msu.xf * float4(v.posIn.xyz, 1.0);\n" -" return vtf;\n" -"}\n"; - -static const char* FS = -"#include \n" -"using namespace metal;\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float4 color;\n" -"};\n" -"\n" -"fragment float4 fmain(VertToFrag vtf [[ stage_in ]])\n" -"{\n" -" return vtf.color;\n" -"}\n"; - -URDE_DECL_SPECIALIZE_SHADER(CMapSurfaceShader) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_Pipeline; - -struct CMapSurfaceShaderMetalDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CMapSurfaceShader& filter) - { - boo::MetalDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - filter.m_dataBind = cctx.newShaderDataBinding(s_Pipeline, s_VtxFmt, - filter.m_vbo.get(), nullptr, filter.m_ibo.get(), 1, bufs, - nullptr, nullptr, nullptr, 0, nullptr, nullptr, nullptr); - return filter.m_dataBind; - } -}; - -TShader::IDataBindingFactory* -CMapSurfaceShader::Initialize(boo::MetalDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4} - }; - s_VtxFmt = ctx.newVertexFormat(1, VtxVmt); - s_Pipeline = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, s_VtxFmt, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::GEqual, false, true, false, boo::CullMode::Backface); - return new CMapSurfaceShaderMetalDataBindingFactory; -} - -template <> -void CMapSurfaceShader::Shutdown() -{ - s_VtxFmt.reset(); - s_Pipeline.reset(); -} - -} diff --git a/Runtime/Graphics/Shaders/CModelShaders.cpp b/Runtime/Graphics/Shaders/CModelShaders.cpp index 2bd8eb4fe..d431b2c25 100644 --- a/Runtime/Graphics/Shaders/CModelShaders.cpp +++ b/Runtime/Graphics/Shaders/CModelShaders.cpp @@ -1,10 +1,11 @@ #include "CModelShaders.hpp" #include "Graphics/CLight.hpp" +#include "hecl/Pipeline.hpp" namespace urde { -std::experimental::optional CModelShaders::g_ModelShaders; +std::unordered_map CModelShaders::g_ShaderPipelines; void CModelShaders::LightingUniform::ActivateLights(const std::vector& lts) { @@ -53,59 +54,156 @@ void CModelShaders::LightingUniform::ActivateLights(const std::vector& l } } -hecl::Runtime::ShaderCacheExtensions -CModelShaders::GetShaderExtensions(boo::IGraphicsDataFactory::Platform plat) -{ - switch (plat) - { -#if BOO_HAS_GL - case boo::IGraphicsDataFactory::Platform::OpenGL: - case boo::IGraphicsDataFactory::Platform::Vulkan: - return GetShaderExtensionsGLSL(plat); -#endif -#if _WIN32 - case boo::IGraphicsDataFactory::Platform::D3D11: - return GetShaderExtensionsHLSL(plat); -#endif -#if BOO_HAS_METAL - case boo::IGraphicsDataFactory::Platform::Metal: - return GetShaderExtensionsMetal(plat); -#endif - default: - return {boo::IGraphicsDataFactory::Platform::Null}; - } -} - -const hecl::Backend::TextureInfo CModelShaders::ThermalTextures[] = +static const hecl::Backend::TextureInfo ThermalTextures[] = { {hecl::Backend::TexGenSrc::Normal, 7, 0, 7, true} }; -const hecl::Backend::TextureInfo CModelShaders::BallFadeTextures[] = +static const hecl::Backend::TextureInfo BallFadeTextures[] = { {hecl::Backend::TexGenSrc::Position, 0, 0, 0, false}, // ID tex {hecl::Backend::TexGenSrc::Position, 1, 0, 0, false}, // Sphere ramp {hecl::Backend::TexGenSrc::Position, 2, 0, 1, false} // TXTR_BallFade }; -const hecl::Backend::TextureInfo CModelShaders::WorldShadowTextures[] = +static const hecl::Backend::TextureInfo WorldShadowTextures[] = { {hecl::Backend::TexGenSrc::Position, 7, 0, 7, false} // Shadow tex }; -CModelShaders::CModelShaders(const hecl::Runtime::FileStoreManager& storeMgr, - boo::IGraphicsDataFactory* gfxFactory) - : m_shaderCache(storeMgr, gfxFactory, GetShaderExtensions(gfxFactory->platform())) {} - -void CModelShaders::Initialize(const hecl::Runtime::FileStoreManager& storeMgr, - boo::IGraphicsDataFactory* gfxFactory) +static hecl::Backend::ExtensionSlot g_ExtensionSlots[] = { - g_ModelShaders.emplace(storeMgr, gfxFactory); -} + /* Default solid shading */ + {}, + /* Normal lit shading */ + {0, nullptr, hecl::Backend::BlendFactor::Original, + hecl::Backend::BlendFactor::Original, hecl::Backend::ZTest::Original, + hecl::Backend::CullMode::Backface, false, false, true}, + /* Thermal Visor shading */ + {1, ThermalTextures, hecl::Backend::BlendFactor::One, + hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original, + hecl::Backend::CullMode::Backface, false, false, false, true}, + /* Forced alpha shading */ + {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, + hecl::Backend::BlendFactor::InvSrcAlpha, hecl::Backend::ZTest::Original, + hecl::Backend::CullMode::Backface, false, false, true}, + /* Forced additive shading */ + {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, + hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original, + hecl::Backend::CullMode::Backface, true, false, true}, + /* Solid color */ + {0, nullptr, hecl::Backend::BlendFactor::One, + hecl::Backend::BlendFactor::Zero, hecl::Backend::ZTest::LEqual, + hecl::Backend::CullMode::Backface, false, false, false}, + /* Solid color additive */ + {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, + hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::LEqual, + hecl::Backend::CullMode::Backface, true, false, true}, + /* Alpha-only Solid color frontface cull, LEqual */ + {0, nullptr, hecl::Backend::BlendFactor::Zero, + hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::LEqual, + hecl::Backend::CullMode::Frontface, false, true, false}, + /* Alpha-only Solid color frontface cull, Always, No Z-write */ + {0, nullptr, hecl::Backend::BlendFactor::Zero, + hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::None, + hecl::Backend::CullMode::Frontface, true, true, false}, + /* Alpha-only Solid color backface cull, LEqual */ + {0, nullptr, hecl::Backend::BlendFactor::Zero, + hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::LEqual, + hecl::Backend::CullMode::Backface, false, true, false}, + /* Alpha-only Solid color backface cull, Greater, No Z-write */ + {0, nullptr, hecl::Backend::BlendFactor::Zero, + hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Greater, + hecl::Backend::CullMode::Backface, true, true, false}, + /* MorphBall shadow shading */ + {3, BallFadeTextures, + hecl::Backend::BlendFactor::SrcAlpha, + hecl::Backend::BlendFactor::InvSrcAlpha, + hecl::Backend::ZTest::Equal, + hecl::Backend::CullMode::Backface, false, false, true, false, true}, + /* World shadow shading (modified lighting) */ + {1, WorldShadowTextures, hecl::Backend::BlendFactor::Original, + hecl::Backend::BlendFactor::Original, hecl::Backend::ZTest::Original, + hecl::Backend::CullMode::Backface, false, false, true}, + /* Forced alpha shading without culling */ + {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, + hecl::Backend::BlendFactor::InvSrcAlpha, hecl::Backend::ZTest::Original, + hecl::Backend::CullMode::None, false, false, true}, + /* Forced additive shading without culling */ + {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, + hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original, + hecl::Backend::CullMode::None, false, false, true}, + /* Forced alpha shading without Z-write */ + {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, + hecl::Backend::BlendFactor::InvSrcAlpha, hecl::Backend::ZTest::Original, + hecl::Backend::CullMode::Original, true, false, true}, + /* Forced additive shading without Z-write */ + {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, + hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original, + hecl::Backend::CullMode::Original, true, false, true}, + /* Forced alpha shading without culling or Z-write */ + {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, + hecl::Backend::BlendFactor::InvSrcAlpha, hecl::Backend::ZTest::Original, + hecl::Backend::CullMode::None, true, false, true}, + /* Forced additive shading without culling or Z-write */ + {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, + hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original, + hecl::Backend::CullMode::None, true, false, true}, + /* Depth GEqual no Z-write */ + {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, + hecl::Backend::BlendFactor::InvSrcAlpha, hecl::Backend::ZTest::GEqual, + hecl::Backend::CullMode::Backface, true, false, true} +}; +extern const hecl::Backend::Function ExtensionLightingFuncsGLSL[]; +extern const hecl::Backend::Function ExtensionPostFuncsGLSL[]; +extern const hecl::Backend::Function ExtensionLightingFuncsHLSL[]; +extern const hecl::Backend::Function ExtensionPostFuncsHLSL[]; +extern const hecl::Backend::Function ExtensionLightingFuncsMetal[]; +extern const hecl::Backend::Function ExtensionPostFuncsMetal[]; + +void CModelShaders::Initialize() +{ + const hecl::Backend::Function* lightingFuncs; + const hecl::Backend::Function* postFuncs; + switch (CGraphics::g_BooPlatform) + { + case boo::IGraphicsDataFactory::Platform::OpenGL: + case boo::IGraphicsDataFactory::Platform::Vulkan: + case boo::IGraphicsDataFactory::Platform::NX: + default: + lightingFuncs = ExtensionLightingFuncsGLSL; + postFuncs = ExtensionPostFuncsGLSL; + case boo::IGraphicsDataFactory::Platform::D3D11: + lightingFuncs = ExtensionLightingFuncsHLSL; + postFuncs = ExtensionPostFuncsHLSL; + case boo::IGraphicsDataFactory::Platform::Metal: + lightingFuncs = ExtensionLightingFuncsMetal; + postFuncs = ExtensionPostFuncsMetal; + } + for (auto& ext : g_ExtensionSlots) + { + ext.lighting = *lightingFuncs++; + ext.post = *postFuncs++; + } +} void CModelShaders::Shutdown() { - g_ModelShaders = std::experimental::nullopt; + g_ShaderPipelines.clear(); +} + +CModelShaders::ShaderPipelines CModelShaders::BuildExtendedShader(const hecl::Backend::ShaderTag& tag, + const hecl::Frontend::IR& ir) +{ + auto search = g_ShaderPipelines.find(ir.m_hash); + if (search != g_ShaderPipelines.cend()) + return search->second; + ShaderPipelines& newPipelines = g_ShaderPipelines[ir.m_hash]; + newPipelines = std::make_shared(); + int idx = 0; + for (const auto& ext : g_ExtensionSlots) + (*newPipelines)[idx++] = hecl::conv->convert(hecl::HECLIR(ir, tag, ext)); + return newPipelines; } } diff --git a/Runtime/Graphics/Shaders/CModelShaders.hpp b/Runtime/Graphics/Shaders/CModelShaders.hpp index 4a3ed5f52..78a77eff7 100644 --- a/Runtime/Graphics/Shaders/CModelShaders.hpp +++ b/Runtime/Graphics/Shaders/CModelShaders.hpp @@ -2,6 +2,7 @@ #define __URDE_CMODELSHADERS_HPP__ #include "hecl/Runtime.hpp" +#include "hecl/Backend/Backend.hpp" #include "optional.hpp" #include "zeus/CVector3f.hpp" #include "zeus/CColor.hpp" @@ -33,23 +34,14 @@ enum EExtendedShader : uint8_t ForcedAdditiveNoZWrite, ForcedAlphaNoCullNoZWrite, ForcedAdditiveNoCullNoZWrite, - DepthGEqualNoZWrite + DepthGEqualNoZWrite, + MAX }; class CModelShaders { friend class CModel; - hecl::Runtime::ShaderCacheManager m_shaderCache; - static hecl::Runtime::ShaderCacheExtensions GetShaderExtensions(boo::IGraphicsDataFactory::Platform plat); - static hecl::Runtime::ShaderCacheExtensions GetShaderExtensionsGLSL(boo::IGraphicsDataFactory::Platform plat); - static hecl::Runtime::ShaderCacheExtensions GetShaderExtensionsHLSL(boo::IGraphicsDataFactory::Platform plat); - static hecl::Runtime::ShaderCacheExtensions GetShaderExtensionsMetal(boo::IGraphicsDataFactory::Platform plat); - static const hecl::Backend::TextureInfo ThermalTextures[]; - static const hecl::Backend::TextureInfo BallFadeTextures[]; - static const hecl::Backend::TextureInfo WorldShadowTextures[]; public: - static std::experimental::optional g_ModelShaders; - struct Light { zeus::CVector3f pos; @@ -87,45 +79,17 @@ public: float shadowId; }; - static void Initialize(const hecl::Runtime::FileStoreManager& storeMgr, - boo::IGraphicsDataFactory* gfxFactory); + static void Initialize(); static void Shutdown(); - CModelShaders(const hecl::Runtime::FileStoreManager& storeMgr, - boo::IGraphicsDataFactory* gfxFactory); + using ShaderPipelinesData = std::array, EExtendedShader::MAX>; + using ShaderPipelines = std::shared_ptr; - std::shared_ptr buildShader(const hecl::Runtime::ShaderTag& tag, - std::string_view source, - std::string_view diagName, - boo::IGraphicsDataFactory& factory) - { - return m_shaderCache.buildShader(tag, source, diagName, factory); - } - - std::shared_ptr buildShader(const hecl::Runtime::ShaderTag& tag, - const hecl::Frontend::IR& ir, - std::string_view diagName, - boo::IGraphicsDataFactory& factory) - { - return m_shaderCache.buildShader(tag, ir, diagName, factory); - } - - std::shared_ptr buildExtendedShader(const hecl::Runtime::ShaderTag& tag, - std::string_view source, - std::string_view diagName, - boo::IGraphicsDataFactory& factory) - { - return m_shaderCache.buildExtendedShader(tag, source, diagName, factory); - } - - std::shared_ptr buildExtendedShader(const hecl::Runtime::ShaderTag& tag, - const hecl::Frontend::IR& ir, - std::string_view diagName, - boo::IGraphicsDataFactory& factory) - { - return m_shaderCache.buildExtendedShader(tag, ir, diagName, factory); - } + static ShaderPipelines BuildExtendedShader(const hecl::Backend::ShaderTag& tag, + const hecl::Frontend::IR& ir); +private: + static std::unordered_map g_ShaderPipelines; }; } diff --git a/Runtime/Graphics/Shaders/CModelShadersGLSL.cpp b/Runtime/Graphics/Shaders/CModelShadersGLSL.cpp index 581382403..b1ff4cb20 100644 --- a/Runtime/Graphics/Shaders/CModelShadersGLSL.cpp +++ b/Runtime/Graphics/Shaders/CModelShadersGLSL.cpp @@ -3,8 +3,12 @@ namespace urde { +using namespace std::literals; -static const char* LightingGLSL = +extern const hecl::Backend::Function ExtensionLightingFuncsGLSL[]; +extern const hecl::Backend::Function ExtensionPostFuncsGLSL[]; + +static std::string_view LightingGLSL = "struct Light\n" "{\n" " vec4 pos;\n" @@ -51,9 +55,9 @@ static const char* LightingGLSL = " }\n" " \n" " return ret;\n" -"}\n"; +"}\n"sv; -static const char* LightingShadowGLSL = +static std::string_view LightingShadowGLSL = "struct Light\n" "{\n" " vec4 pos;\n" @@ -115,9 +119,9 @@ static const char* LightingShadowGLSL = " }\n" " \n" " return ret;\n" -"}\n"; +"}\n"sv; -static const char* MainPostGLSL = +static std::string_view MainPostGLSL = "vec4 MainPostFunc(vec4 colorIn)\n" "{\n" " float fogZ, temp;\n" @@ -146,9 +150,9 @@ static const char* MainPostGLSL = " }\n" " return mix(colorIn, fog.color, clamp(fogZ, 0.0, 1.0));\n" "}\n" -"\n"; +"\n"sv; -static const char* ThermalPostGLSL = +static std::string_view ThermalPostGLSL = "UBINDING2 uniform ThermalUniform\n" "{\n" " vec4 tmulColor;\n" @@ -158,9 +162,9 @@ static const char* ThermalPostGLSL = "{\n" " return vec4(texture(extTex7, vtf.extTcgs[0]).rrr * tmulColor.rgb + addColor.rgb, tmulColor.a + addColor.a);\n" "}\n" -"\n"; +"\n"sv; -static const char* SolidPostGLSL = +static std::string_view SolidPostGLSL = "UBINDING2 uniform SolidUniform\n" "{\n" " vec4 solidColor;\n" @@ -169,9 +173,9 @@ static const char* SolidPostGLSL = "{\n" " return solidColor;\n" "}\n" -"\n"; +"\n"sv; -static const char* MBShadowPostGLSL = +static std::string_view MBShadowPostGLSL = "UBINDING2 uniform MBShadowUniform\n" "{\n" " vec4 shadowUp;\n" @@ -187,146 +191,54 @@ static const char* MBShadowPostGLSL = " sphereTexel * fadeTexel;\n" " return vec4(0.0, 0.0, 0.0, val);\n" "}\n" -"\n"; +"\n"sv; -static const char* BlockNames[] = {HECL_GLSL_VERT_UNIFORM_BLOCK_NAME, - HECL_GLSL_TEXMTX_UNIFORM_BLOCK_NAME, - "LightingUniform"}; - -static const char* ThermalBlockNames[] = {HECL_GLSL_VERT_UNIFORM_BLOCK_NAME, - HECL_GLSL_TEXMTX_UNIFORM_BLOCK_NAME, - "ThermalUniform"}; - -static const char* SolidBlockNames[] = {HECL_GLSL_VERT_UNIFORM_BLOCK_NAME, - HECL_GLSL_TEXMTX_UNIFORM_BLOCK_NAME, - "SolidUniform"}; - -static const char* MBShadowBlockNames[] = {HECL_GLSL_VERT_UNIFORM_BLOCK_NAME, - HECL_GLSL_TEXMTX_UNIFORM_BLOCK_NAME, - "MBShadowUniform"}; - -hecl::Runtime::ShaderCacheExtensions -CModelShaders::GetShaderExtensionsGLSL(boo::IGraphicsDataFactory::Platform plat) +const hecl::Backend::Function ExtensionLightingFuncsGLSL[] = { - hecl::Runtime::ShaderCacheExtensions ext(plat); + {}, + {LightingGLSL, "LightingFunc"}, + {}, + {LightingGLSL, "LightingFunc"}, + {LightingGLSL, "LightingFunc"}, + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {LightingShadowGLSL, "LightingShadowFunc"}, + {LightingGLSL, "LightingFunc"}, + {LightingGLSL, "LightingFunc"}, + {LightingGLSL, "LightingFunc"}, + {LightingGLSL, "LightingFunc"}, + {LightingGLSL, "LightingFunc"}, + {LightingGLSL, "LightingFunc"}, + {LightingGLSL, "LightingFunc"} +}; - /* Normal lit shading */ - ext.registerExtensionSlot({LightingGLSL, "LightingFunc"}, {MainPostGLSL, "MainPostFunc"}, - 3, BlockNames, 0, nullptr, hecl::Backend::BlendFactor::Original, - hecl::Backend::BlendFactor::Original, hecl::Backend::ZTest::Original, - hecl::Backend::CullMode::Backface, false, false, true); - - /* Thermal Visor shading */ - ext.registerExtensionSlot({}, {ThermalPostGLSL, "ThermalPostFunc"}, 3, ThermalBlockNames, - 1, ThermalTextures, hecl::Backend::BlendFactor::One, - hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original, - hecl::Backend::CullMode::Backface, false, false, false, true); - - /* Forced alpha shading */ - ext.registerExtensionSlot({LightingGLSL, "LightingFunc"}, {MainPostGLSL, "MainPostFunc"}, - 3, BlockNames, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, - hecl::Backend::BlendFactor::InvSrcAlpha, hecl::Backend::ZTest::Original, - hecl::Backend::CullMode::Backface, false, false, true); - - /* Forced additive shading */ - ext.registerExtensionSlot({LightingGLSL, "LightingFunc"}, {MainPostGLSL, "MainPostFunc"}, - 3, BlockNames, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, - hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original, - hecl::Backend::CullMode::Backface, true, false, true); - - /* Solid color */ - ext.registerExtensionSlot({}, {SolidPostGLSL, "SolidPostFunc"}, - 3, SolidBlockNames, 0, nullptr, hecl::Backend::BlendFactor::One, - hecl::Backend::BlendFactor::Zero, hecl::Backend::ZTest::LEqual, - hecl::Backend::CullMode::Backface, false, false, false); - - /* Solid color additive */ - ext.registerExtensionSlot({}, {SolidPostGLSL, "SolidPostFunc"}, - 3, SolidBlockNames, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, - hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::LEqual, - hecl::Backend::CullMode::Backface, true, false, true); - - /* Alpha-only Solid color frontface cull, LEqual */ - ext.registerExtensionSlot({}, {SolidPostGLSL, "SolidPostFunc"}, - 3, SolidBlockNames, 0, nullptr, hecl::Backend::BlendFactor::Zero, - hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::LEqual, - hecl::Backend::CullMode::Frontface, false, true, false); - - /* Alpha-only Solid color frontface cull, Always, No Z-write */ - ext.registerExtensionSlot({}, {SolidPostGLSL, "SolidPostFunc"}, - 3, SolidBlockNames, 0, nullptr, hecl::Backend::BlendFactor::Zero, - hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::None, - hecl::Backend::CullMode::Frontface, true, true, false); - - /* Alpha-only Solid color backface cull, LEqual */ - ext.registerExtensionSlot({}, {SolidPostGLSL, "SolidPostFunc"}, - 3, SolidBlockNames, 0, nullptr, hecl::Backend::BlendFactor::Zero, - hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::LEqual, - hecl::Backend::CullMode::Backface, false, true, false); - - /* Alpha-only Solid color backface cull, Greater, No Z-write */ - ext.registerExtensionSlot({}, {SolidPostGLSL, "SolidPostFunc"}, - 3, SolidBlockNames, 0, nullptr, hecl::Backend::BlendFactor::Zero, - hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Greater, - hecl::Backend::CullMode::Backface, true, true, false); - - /* MorphBall shadow shading */ - ext.registerExtensionSlot({}, {MBShadowPostGLSL, "MBShadowPostFunc"}, - 3, MBShadowBlockNames, 3, BallFadeTextures, - hecl::Backend::BlendFactor::SrcAlpha, - hecl::Backend::BlendFactor::InvSrcAlpha, - hecl::Backend::ZTest::Equal, - hecl::Backend::CullMode::Backface, false, false, true, false, true); - - /* World shadow shading (modified lighting) */ - ext.registerExtensionSlot({LightingShadowGLSL, "LightingShadowFunc"}, {MainPostGLSL, "MainPostFunc"}, - 3, BlockNames, 1, WorldShadowTextures, hecl::Backend::BlendFactor::Original, - hecl::Backend::BlendFactor::Original, hecl::Backend::ZTest::Original, - hecl::Backend::CullMode::Backface, false, false, true); - - /* Forced alpha shading without culling */ - ext.registerExtensionSlot({LightingGLSL, "LightingFunc"}, {MainPostGLSL, "MainPostFunc"}, - 3, BlockNames, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, - hecl::Backend::BlendFactor::InvSrcAlpha, hecl::Backend::ZTest::Original, - hecl::Backend::CullMode::None, false, false, true); - - /* Forced additive shading without culling */ - ext.registerExtensionSlot({LightingGLSL, "LightingFunc"}, {MainPostGLSL, "MainPostFunc"}, - 3, BlockNames, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, - hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original, - hecl::Backend::CullMode::None, false, false, true); - - /* Forced alpha shading without Z-write */ - ext.registerExtensionSlot({LightingGLSL, "LightingFunc"}, {MainPostGLSL, "MainPostFunc"}, - 3, BlockNames, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, - hecl::Backend::BlendFactor::InvSrcAlpha, hecl::Backend::ZTest::Original, - hecl::Backend::CullMode::Original, true, false, true); - - /* Forced additive shading without Z-write */ - ext.registerExtensionSlot({LightingGLSL, "LightingFunc"}, {MainPostGLSL, "MainPostFunc"}, - 3, BlockNames, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, - hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original, - hecl::Backend::CullMode::Original, true, false, true); - - /* Forced alpha shading without culling or Z-write */ - ext.registerExtensionSlot({LightingGLSL, "LightingFunc"}, {MainPostGLSL, "MainPostFunc"}, - 3, BlockNames, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, - hecl::Backend::BlendFactor::InvSrcAlpha, hecl::Backend::ZTest::Original, - hecl::Backend::CullMode::None, true, false, true); - - /* Forced additive shading without culling or Z-write */ - ext.registerExtensionSlot({LightingGLSL, "LightingFunc"}, {MainPostGLSL, "MainPostFunc"}, - 3, BlockNames, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, - hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original, - hecl::Backend::CullMode::None, true, false, true); - - /* Depth GEqual no Z-write */ - ext.registerExtensionSlot({LightingGLSL, "LightingFunc"}, {MainPostGLSL, "MainPostFunc"}, - 3, BlockNames, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, - hecl::Backend::BlendFactor::InvSrcAlpha, hecl::Backend::ZTest::GEqual, - hecl::Backend::CullMode::Backface, true, false, true); - - return ext; -} +const hecl::Backend::Function ExtensionPostFuncsGLSL[] = +{ + {}, + {MainPostGLSL, "MainPostFunc"}, + {ThermalPostGLSL, "ThermalPostFunc"}, + {MainPostGLSL, "MainPostFunc"}, + {MainPostGLSL, "MainPostFunc"}, + {SolidPostGLSL, "SolidPostFunc"}, + {SolidPostGLSL, "SolidPostFunc"}, + {SolidPostGLSL, "SolidPostFunc"}, + {SolidPostGLSL, "SolidPostFunc"}, + {SolidPostGLSL, "SolidPostFunc"}, + {SolidPostGLSL, "SolidPostFunc"}, + {MBShadowPostGLSL, "MBShadowPostFunc"}, + {MainPostGLSL, "MainPostFunc"}, + {MainPostGLSL, "MainPostFunc"}, + {MainPostGLSL, "MainPostFunc"}, + {MainPostGLSL, "MainPostFunc"}, + {MainPostGLSL, "MainPostFunc"}, + {MainPostGLSL, "MainPostFunc"}, + {MainPostGLSL, "MainPostFunc"}, + {MainPostGLSL, "MainPostFunc"}, +}; } diff --git a/Runtime/Graphics/Shaders/CModelShadersHLSL.cpp b/Runtime/Graphics/Shaders/CModelShadersHLSL.cpp index ff71933d9..5e782865f 100644 --- a/Runtime/Graphics/Shaders/CModelShadersHLSL.cpp +++ b/Runtime/Graphics/Shaders/CModelShadersHLSL.cpp @@ -2,8 +2,12 @@ namespace urde { +using namespace std::literals; -static const char* LightingHLSL = +extern const hecl::Backend::Function ExtensionLightingFuncsHLSL[]; +extern const hecl::Backend::Function ExtensionPostFuncsHLSL[]; + +static std::string_view LightingHLSL = "struct Light\n" "{\n" " float4 pos;\n" @@ -50,9 +54,9 @@ static const char* LightingHLSL = " }\n" " \n" " return ret;\n" -"}\n"; +"}\n"sv; -static const char* LightingShadowHLSL = +static std::string_view LightingShadowHLSL = "struct Light\n" "{\n" " float4 pos;\n" @@ -111,9 +115,9 @@ static const char* LightingShadowHLSL = " }\n" " \n" " return ret;\n" -"}\n"; +"}\n"sv; -static const char* MainPostHLSL = +static std::string_view MainPostHLSL = "static float4 MainPostFunc(in VertToFrag vtf, float4 colorIn)\n" "{\n" " float fogZ, temp;\n" @@ -142,9 +146,9 @@ static const char* MainPostHLSL = " }\n" " return lerp(colorIn, fog.color, saturate(fogZ));\n" "}\n" -"\n"; +"\n"sv; -static const char* ThermalPostHLSL = +static std::string_view ThermalPostHLSL = "cbuffer ThermalUniform : register(b2)\n" "{\n" " float4 tmulColor;\n" @@ -154,9 +158,9 @@ static const char* ThermalPostHLSL = "{\n" " return float4(extTex7.Sample(samp, vtf.extTcgs[0]).rrr * tmulColor.rgb + addColor.rgb, tmulColor.a + addColor.a);\n" "}\n" -"\n"; +"\n"sv; -static const char* SolidPostHLSL = +static std::string_view SolidPostHLSL = "cbuffer SolidUniform : register(b2)\n" "{\n" " float4 solidColor;\n" @@ -165,9 +169,9 @@ static const char* SolidPostHLSL = "{\n" " return solidColor;\n" "}\n" -"\n"; +"\n"sv; -static const char* MBShadowPostHLSL = +static std::string_view MBShadowPostHLSL = "cbuffer MBShadowUniform : register(b2)\n" "{\n" " float4 shadowUp;\n" @@ -183,130 +187,54 @@ static const char* MBShadowPostHLSL = " sphereTexel * fadeTexel;\n" " return float4(0.0, 0.0, 0.0, val);\n" "}\n" -"\n"; +"\n"sv; -hecl::Runtime::ShaderCacheExtensions -CModelShaders::GetShaderExtensionsHLSL(boo::IGraphicsDataFactory::Platform plat) +const hecl::Backend::Function ExtensionLightingFuncsHLSL[] = { - hecl::Runtime::ShaderCacheExtensions ext(plat); + {}, + {LightingHLSL, "LightingFunc"}, + {}, + {LightingHLSL, "LightingFunc"}, + {LightingHLSL, "LightingFunc"}, + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {LightingShadowHLSL, "LightingShadowFunc"}, + {LightingHLSL, "LightingFunc"}, + {LightingHLSL, "LightingFunc"}, + {LightingHLSL, "LightingFunc"}, + {LightingHLSL, "LightingFunc"}, + {LightingHLSL, "LightingFunc"}, + {LightingHLSL, "LightingFunc"}, + {LightingHLSL, "LightingFunc"} +}; - /* Normal lit shading */ - ext.registerExtensionSlot({LightingHLSL, "LightingFunc"}, {MainPostHLSL, "MainPostFunc"}, - 0, nullptr, 0, nullptr, hecl::Backend::BlendFactor::Original, - hecl::Backend::BlendFactor::Original, hecl::Backend::ZTest::Original, - hecl::Backend::CullMode::Backface, false, false, true); - - /* Thermal Visor shading */ - ext.registerExtensionSlot({}, {ThermalPostHLSL, "ThermalPostFunc"}, 0, nullptr, - 1, ThermalTextures, hecl::Backend::BlendFactor::One, - hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original, - hecl::Backend::CullMode::Backface, false, false, false, true); - - /* Forced alpha shading */ - ext.registerExtensionSlot({LightingHLSL, "LightingFunc"}, {MainPostHLSL, "MainPostFunc"}, - 0, nullptr, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, - hecl::Backend::BlendFactor::InvSrcAlpha, hecl::Backend::ZTest::Original, - hecl::Backend::CullMode::Backface, false, false, true); - - /* Forced additive shading */ - ext.registerExtensionSlot({LightingHLSL, "LightingFunc"}, {MainPostHLSL, "MainPostFunc"}, - 0, nullptr, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, - hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original, - hecl::Backend::CullMode::Backface, true, false, true); - - /* Solid color */ - ext.registerExtensionSlot({}, {SolidPostHLSL, "SolidPostFunc"}, - 0, nullptr, 0, nullptr, hecl::Backend::BlendFactor::One, - hecl::Backend::BlendFactor::Zero, hecl::Backend::ZTest::LEqual, - hecl::Backend::CullMode::Backface, false, false, false); - - /* Solid color additive */ - ext.registerExtensionSlot({}, {SolidPostHLSL, "SolidPostFunc"}, - 0, nullptr, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, - hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::LEqual, - hecl::Backend::CullMode::Backface, true, false, true); - - /* Alpha-only Solid color frontface cull, LEqual */ - ext.registerExtensionSlot({}, {SolidPostHLSL, "SolidPostFunc"}, - 0, nullptr, 0, nullptr, hecl::Backend::BlendFactor::One, - hecl::Backend::BlendFactor::Zero, hecl::Backend::ZTest::LEqual, - hecl::Backend::CullMode::Frontface, false, true, false); - - /* Alpha-only Solid color frontface cull, Always, No Z-write */ - ext.registerExtensionSlot({}, {SolidPostHLSL, "SolidPostFunc"}, - 0, nullptr, 0, nullptr, hecl::Backend::BlendFactor::One, - hecl::Backend::BlendFactor::Zero, hecl::Backend::ZTest::None, - hecl::Backend::CullMode::Frontface, true, true, false); - - /* Alpha-only Solid color backface cull, LEqual */ - ext.registerExtensionSlot({}, {SolidPostHLSL, "SolidPostFunc"}, - 0, nullptr, 0, nullptr, hecl::Backend::BlendFactor::One, - hecl::Backend::BlendFactor::Zero, hecl::Backend::ZTest::LEqual, - hecl::Backend::CullMode::Backface, false, true, false); - - /* Alpha-only Solid color backface cull, Greater, No Z-write */ - ext.registerExtensionSlot({}, {SolidPostHLSL, "SolidPostFunc"}, - 0, nullptr, 0, nullptr, hecl::Backend::BlendFactor::One, - hecl::Backend::BlendFactor::Zero, hecl::Backend::ZTest::Greater, - hecl::Backend::CullMode::Backface, true, true, false); - - /* MorphBall shadow shading */ - ext.registerExtensionSlot({}, {MBShadowPostHLSL, "MBShadowPostFunc"}, - 0, nullptr, 3, BallFadeTextures, - hecl::Backend::BlendFactor::SrcAlpha, - hecl::Backend::BlendFactor::InvSrcAlpha, - hecl::Backend::ZTest::Equal, - hecl::Backend::CullMode::Backface, false, false, true, false, true); - - /* World shadow shading (modified lighting) */ - ext.registerExtensionSlot({LightingShadowHLSL, "LightingShadowFunc"}, {MainPostHLSL, "MainPostFunc"}, - 0, nullptr, 1, WorldShadowTextures, hecl::Backend::BlendFactor::Original, - hecl::Backend::BlendFactor::Original, hecl::Backend::ZTest::Original, - hecl::Backend::CullMode::Backface, false, false, true); - - /* Forced alpha shading without culling */ - ext.registerExtensionSlot({LightingHLSL, "LightingFunc"}, {MainPostHLSL, "MainPostFunc"}, - 0, nullptr, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, - hecl::Backend::BlendFactor::InvSrcAlpha, hecl::Backend::ZTest::Original, - hecl::Backend::CullMode::None, false, false, true); - - /* Forced additive shading without culling */ - ext.registerExtensionSlot({LightingHLSL, "LightingFunc"}, {MainPostHLSL, "MainPostFunc"}, - 0, nullptr, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, - hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original, - hecl::Backend::CullMode::None, false, false, true); - - /* Forced alpha shading without Z-write */ - ext.registerExtensionSlot({LightingHLSL, "LightingFunc"}, {MainPostHLSL, "MainPostFunc"}, - 0, nullptr, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, - hecl::Backend::BlendFactor::InvSrcAlpha, hecl::Backend::ZTest::Original, - hecl::Backend::CullMode::Original, true, false, true); - - /* Forced additive shading without Z-write */ - ext.registerExtensionSlot({LightingHLSL, "LightingFunc"}, {MainPostHLSL, "MainPostFunc"}, - 0, nullptr, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, - hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original, - hecl::Backend::CullMode::Original, true, false, true); - - /* Forced alpha shading without culling or Z-write */ - ext.registerExtensionSlot({LightingHLSL, "LightingFunc"}, {MainPostHLSL, "MainPostFunc"}, - 0, nullptr, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, - hecl::Backend::BlendFactor::InvSrcAlpha, hecl::Backend::ZTest::Original, - hecl::Backend::CullMode::None, true, false, true); - - /* Forced additive shading without culling or Z-write */ - ext.registerExtensionSlot({LightingHLSL, "LightingFunc"}, {MainPostHLSL, "MainPostFunc"}, - 0, nullptr, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, - hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original, - hecl::Backend::CullMode::None, true, false, true); - - /* Depth GEqual no Z-write */ - ext.registerExtensionSlot({LightingHLSL, "LightingFunc"}, {MainPostHLSL, "MainPostFunc"}, - 0, nullptr, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, - hecl::Backend::BlendFactor::InvSrcAlpha, hecl::Backend::ZTest::GEqual, - hecl::Backend::CullMode::Backface, true, false, true); - - return ext; -} +const hecl::Backend::Function ExtensionPostFuncsHLSL[] = +{ + {}, + {MainPostHLSL, "MainPostFunc"}, + {ThermalPostHLSL, "ThermalPostFunc"}, + {MainPostHLSL, "MainPostFunc"}, + {MainPostHLSL, "MainPostFunc"}, + {SolidPostHLSL, "SolidPostFunc"}, + {SolidPostHLSL, "SolidPostFunc"}, + {SolidPostHLSL, "SolidPostFunc"}, + {SolidPostHLSL, "SolidPostFunc"}, + {SolidPostHLSL, "SolidPostFunc"}, + {SolidPostHLSL, "SolidPostFunc"}, + {MBShadowPostHLSL, "MBShadowPostFunc"}, + {MainPostHLSL, "MainPostFunc"}, + {MainPostHLSL, "MainPostFunc"}, + {MainPostHLSL, "MainPostFunc"}, + {MainPostHLSL, "MainPostFunc"}, + {MainPostHLSL, "MainPostFunc"}, + {MainPostHLSL, "MainPostFunc"}, + {MainPostHLSL, "MainPostFunc"}, + {MainPostHLSL, "MainPostFunc"}, +}; } diff --git a/Runtime/Graphics/Shaders/CModelShadersMetal.cpp b/Runtime/Graphics/Shaders/CModelShadersMetal.cpp index 8b13b6ba9..355355b43 100644 --- a/Runtime/Graphics/Shaders/CModelShadersMetal.cpp +++ b/Runtime/Graphics/Shaders/CModelShadersMetal.cpp @@ -2,8 +2,12 @@ namespace urde { +using namespace std::literals; -static const char* LightingMetal = +extern const hecl::Backend::Function ExtensionLightingFuncsMetal[]; +extern const hecl::Backend::Function ExtensionPostFuncsMetal[]; + +static std::string_view LightingMetal = "struct Light\n" "{\n" " float4 pos;\n" @@ -50,9 +54,9 @@ static const char* LightingMetal = " }\n" " \n" " return ret;\n" -"}\n"; +"}\n"sv; -static const char* LightingShadowMetal = +static std::string_view LightingShadowMetal = "struct Light\n" "{\n" " float4 pos;\n" @@ -112,9 +116,9 @@ static const char* LightingShadowMetal = " }\n" " \n" " return ret;\n" -"}\n"; +"}\n"sv; -static const char* MainPostMetal = +static std::string_view MainPostMetal = "float4 MainPostFunc(thread VertToFrag& vtf, constant LightingUniform& lu, float4 colorIn)\n" "{\n" " float fogZ, temp;\n" @@ -143,9 +147,9 @@ static const char* MainPostMetal = " }\n" " return mix(colorIn, lu.fog.color, saturate(fogZ));\n" "}\n" -"\n"; +"\n"sv; -static const char* ThermalPostMetal = +static std::string_view ThermalPostMetal = "struct ThermalUniform\n" "{\n" " float4 tmulColor;\n" @@ -158,9 +162,9 @@ static const char* ThermalPostMetal = " return float4(extTex7.sample(samp, vtf.extTcgs0).rrr * lu.tmulColor.rgb + lu.addColor.rgb,\n" " lu.tmulColor.a + lu.addColor.a);\n" "}\n" -"\n"; +"\n"sv; -static const char* SolidPostMetal = +static std::string_view SolidPostMetal = "struct SolidUniform\n" "{\n" " float4 solidColor;\n" @@ -169,9 +173,9 @@ static const char* SolidPostMetal = "{\n" " return lu.solidColor;\n" "}\n" -"\n"; +"\n"sv; -static const char* MBShadowPostMetal = +static std::string_view MBShadowPostMetal = "struct MBShadowUniform\n" "{\n" " float4 shadowUp;\n" @@ -188,135 +192,59 @@ static const char* MBShadowPostMetal = " sphereTexel * fadeTexel;\n" " return float4(0.0, 0.0, 0.0, val);\n" "}\n" -"\n"; +"\n"sv; + +const hecl::Backend::Function ExtensionLightingFuncsMetal[] = +{ + {}, + {LightingMetal, "LightingFunc"}, + {}, + {LightingMetal, "LightingFunc"}, + {LightingMetal, "LightingFunc"}, + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {LightingShadowMetal, "LightingShadowFunc"}, + {LightingMetal, "LightingFunc"}, + {LightingMetal, "LightingFunc"}, + {LightingMetal, "LightingFunc"}, + {LightingMetal, "LightingFunc"}, + {LightingMetal, "LightingFunc"}, + {LightingMetal, "LightingFunc"}, + {LightingMetal, "LightingFunc"} +}; + +const hecl::Backend::Function ExtensionPostFuncsMetal[] = +{ + {}, + {MainPostMetal, "MainPostFunc"}, + {ThermalPostMetal, "ThermalPostFunc"}, + {MainPostMetal, "MainPostFunc"}, + {MainPostMetal, "MainPostFunc"}, + {SolidPostMetal, "SolidPostFunc"}, + {SolidPostMetal, "SolidPostFunc"}, + {SolidPostMetal, "SolidPostFunc"}, + {SolidPostMetal, "SolidPostFunc"}, + {SolidPostMetal, "SolidPostFunc"}, + {SolidPostMetal, "SolidPostFunc"}, + {MBShadowPostMetal, "MBShadowPostFunc"}, + {MainPostMetal, "MainPostFunc"}, + {MainPostMetal, "MainPostFunc"}, + {MainPostMetal, "MainPostFunc"}, + {MainPostMetal, "MainPostFunc"}, + {MainPostMetal, "MainPostFunc"}, + {MainPostMetal, "MainPostFunc"}, + {MainPostMetal, "MainPostFunc"}, + {MainPostMetal, "MainPostFunc"}, +}; static const char* BlockNames[] = {"LightingUniform"}; static const char* ThermalBlockNames[] = {"ThermalUniform"}; static const char* SolidBlockNames[] = {"SolidUniform"}; static const char* MBShadowBlockNames[] = {"MBShadowUniform"}; -hecl::Runtime::ShaderCacheExtensions -CModelShaders::GetShaderExtensionsMetal(boo::IGraphicsDataFactory::Platform plat) -{ - hecl::Runtime::ShaderCacheExtensions ext(plat); - - /* Normal lit shading */ - ext.registerExtensionSlot({LightingMetal, "LightingFunc"}, {MainPostMetal, "MainPostFunc"}, - 1, BlockNames, 0, nullptr, hecl::Backend::BlendFactor::Original, - hecl::Backend::BlendFactor::Original, hecl::Backend::ZTest::Original, - hecl::Backend::CullMode::Backface, false, false, true); - - /* Thermal Visor shading */ - ext.registerExtensionSlot({}, {ThermalPostMetal, "EXTThermalPostFunc"}, 1, ThermalBlockNames, - 1, ThermalTextures, hecl::Backend::BlendFactor::One, - hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original, - hecl::Backend::CullMode::Backface, false, false, false, true); - - /* Forced alpha shading */ - ext.registerExtensionSlot({LightingMetal, "LightingFunc"}, {MainPostMetal, "MainPostFunc"}, - 1, BlockNames, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, - hecl::Backend::BlendFactor::InvSrcAlpha, hecl::Backend::ZTest::Original, - hecl::Backend::CullMode::Backface, false, false, true); - - /* Forced additive shading */ - ext.registerExtensionSlot({LightingMetal, "LightingFunc"}, {MainPostMetal, "MainPostFunc"}, - 1, BlockNames, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, - hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original, - hecl::Backend::CullMode::Backface, true, false, true); - - /* Solid color */ - ext.registerExtensionSlot({}, {SolidPostMetal, "SolidPostFunc"}, - 1, SolidBlockNames, 0, nullptr, hecl::Backend::BlendFactor::One, - hecl::Backend::BlendFactor::Zero, hecl::Backend::ZTest::LEqual, - hecl::Backend::CullMode::Backface, false, false, false); - - /* Solid color additive */ - ext.registerExtensionSlot({}, {SolidPostMetal, "SolidPostFunc"}, - 1, SolidBlockNames, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, - hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::LEqual, - hecl::Backend::CullMode::Backface, true, false, true); - - /* Alpha-only Solid color frontface cull, LEqual */ - ext.registerExtensionSlot({}, {SolidPostMetal, "SolidPostFunc"}, - 1, SolidBlockNames, 0, nullptr, hecl::Backend::BlendFactor::Zero, - hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::LEqual, - hecl::Backend::CullMode::Frontface, false, true, false); - - /* Alpha-only Solid color frontface cull, Always, No Z-write */ - ext.registerExtensionSlot({}, {SolidPostMetal, "SolidPostFunc"}, - 1, SolidBlockNames, 0, nullptr, hecl::Backend::BlendFactor::Zero, - hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::None, - hecl::Backend::CullMode::Frontface, true, true, false); - - /* Alpha-only Solid color backface cull, LEqual */ - ext.registerExtensionSlot({}, {SolidPostMetal, "SolidPostFunc"}, - 1, SolidBlockNames, 0, nullptr, hecl::Backend::BlendFactor::Zero, - hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::LEqual, - hecl::Backend::CullMode::Backface, false, true, false); - - /* Alpha-only Solid color backface cull, Greater, No Z-write */ - ext.registerExtensionSlot({}, {SolidPostMetal, "SolidPostFunc"}, - 1, SolidBlockNames, 0, nullptr, hecl::Backend::BlendFactor::Zero, - hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Greater, - hecl::Backend::CullMode::Backface, true, true, false); - - /* MorphBall shadow shading */ - ext.registerExtensionSlot({}, {MBShadowPostMetal, "EXTMBShadowPostFunc"}, - 1, MBShadowBlockNames, 3, BallFadeTextures, - hecl::Backend::BlendFactor::SrcAlpha, - hecl::Backend::BlendFactor::InvSrcAlpha, - hecl::Backend::ZTest::Equal, - hecl::Backend::CullMode::Backface, false, false, true, false, true); - - /* World shadow shading (modified lighting) */ - ext.registerExtensionSlot({LightingShadowMetal, "EXTLightingShadowFunc"}, {MainPostMetal, "MainPostFunc"}, - 1, BlockNames, 1, WorldShadowTextures, hecl::Backend::BlendFactor::Original, - hecl::Backend::BlendFactor::Original, hecl::Backend::ZTest::Original, - hecl::Backend::CullMode::Backface, false, false, true); - - /* Forced alpha shading without culling */ - ext.registerExtensionSlot({LightingMetal, "LightingFunc"}, {MainPostMetal, "MainPostFunc"}, - 1, BlockNames, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, - hecl::Backend::BlendFactor::InvSrcAlpha, hecl::Backend::ZTest::Original, - hecl::Backend::CullMode::None, false, false, true); - - /* Forced additive shading without culling */ - ext.registerExtensionSlot({LightingMetal, "LightingFunc"}, {MainPostMetal, "MainPostFunc"}, - 1, BlockNames, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, - hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original, - hecl::Backend::CullMode::None, false, false, true); - - /* Forced alpha shading without Z-write */ - ext.registerExtensionSlot({LightingMetal, "LightingFunc"}, {MainPostMetal, "MainPostFunc"}, - 1, BlockNames, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, - hecl::Backend::BlendFactor::InvSrcAlpha, hecl::Backend::ZTest::Original, - hecl::Backend::CullMode::Original, true, false, true); - - /* Forced additive shading without Z-write */ - ext.registerExtensionSlot({LightingMetal, "LightingFunc"}, {MainPostMetal, "MainPostFunc"}, - 1, BlockNames, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, - hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original, - hecl::Backend::CullMode::Original, true, false, true); - - /* Forced alpha shading without culling or Z-write */ - ext.registerExtensionSlot({LightingMetal, "LightingFunc"}, {MainPostMetal, "MainPostFunc"}, - 1, BlockNames, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, - hecl::Backend::BlendFactor::InvSrcAlpha, hecl::Backend::ZTest::Original, - hecl::Backend::CullMode::None, true, false, true); - - /* Forced additive shading without culling or Z-write */ - ext.registerExtensionSlot({LightingMetal, "LightingFunc"}, {MainPostMetal, "MainPostFunc"}, - 1, BlockNames, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, - hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original, - hecl::Backend::CullMode::None, true, false, true); - - /* Depth GEqual no Z-write */ - ext.registerExtensionSlot({LightingMetal, "LightingFunc"}, {MainPostMetal, "MainPostFunc"}, - 1, BlockNames, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, - hecl::Backend::BlendFactor::InvSrcAlpha, hecl::Backend::ZTest::GEqual, - hecl::Backend::CullMode::Backface, true, false, true); - - return ext; -} - } diff --git a/Runtime/Graphics/Shaders/CParticleSwooshShaders.cpp b/Runtime/Graphics/Shaders/CParticleSwooshShaders.cpp index d2769cc6d..95a109c42 100644 --- a/Runtime/Graphics/Shaders/CParticleSwooshShaders.cpp +++ b/Runtime/Graphics/Shaders/CParticleSwooshShaders.cpp @@ -1,6 +1,7 @@ #include "CParticleSwooshShaders.hpp" #include "Particle/CParticleSwoosh.hpp" #include "Particle/CSwooshDescription.hpp" +#include "hecl/Pipeline.hpp" namespace urde { @@ -15,7 +16,31 @@ boo::ObjToken CParticleSwooshShaders::m_noTexNoZWrite; boo::ObjToken CParticleSwooshShaders::m_noTexAdditiveZWrite; boo::ObjToken CParticleSwooshShaders::m_noTexAdditiveNoZWrite; -boo::ObjToken CParticleSwooshShaders::m_vtxFormat; +static boo::ObjToken s_Pipeline; + +void CParticleSwooshShaders::Initialize() +{ + m_texZWrite = hecl::conv->convert(Shader_CParticleSwooshShaderTexZWrite{}); + m_texNoZWrite = hecl::conv->convert(Shader_CParticleSwooshShaderTexNoZWrite{}); + m_texAdditiveZWrite = hecl::conv->convert(Shader_CParticleSwooshShaderTexAdditiveZWrite{}); + m_texAdditiveNoZWrite = hecl::conv->convert(Shader_CParticleSwooshShaderTexAdditiveNoZWrite{}); + m_noTexZWrite = hecl::conv->convert(Shader_CParticleSwooshShaderNoTexZWrite{}); + m_noTexNoZWrite = hecl::conv->convert(Shader_CParticleSwooshShaderNoTexNoZWrite{}); + m_noTexAdditiveZWrite = hecl::conv->convert(Shader_CParticleSwooshShaderNoTexAdditiveZWrite{}); + m_noTexAdditiveNoZWrite = hecl::conv->convert(Shader_CParticleSwooshShaderNoTexAdditiveNoZWrite{}); +} + +void CParticleSwooshShaders::Shutdown() +{ + m_texZWrite.reset(); + m_texNoZWrite.reset(); + m_texAdditiveZWrite.reset(); + m_texAdditiveNoZWrite.reset(); + m_noTexZWrite.reset(); + m_noTexNoZWrite.reset(); + m_noTexAdditiveZWrite.reset(); + m_noTexAdditiveNoZWrite.reset(); +} CParticleSwooshShaders::EShaderClass CParticleSwooshShaders::GetShaderClass(CParticleSwoosh& gen) { @@ -67,10 +92,13 @@ void CParticleSwooshShaders::BuildShaderDataBinding(boo::IGraphicsDataFactory::C } } - CParticleSwooshShaders shad(gen, pipeline); - TShader::BuildShaderDataBinding(ctx, shad); + CUVElement* texr = desc->x3c_TEXR.get(); + boo::ObjToken textures[] = {texr ? texr->GetValueTexture(0).GetObj()->GetBooTexture() : nullptr}; + + boo::ObjToken uniforms[] = {gen.m_uniformBuf.get()}; + gen.m_dataBind = ctx.newShaderDataBinding(pipeline, gen.m_vertBuf.get(), + nullptr, nullptr, 1, uniforms, + nullptr, texr ? 1 : 0, textures, nullptr, nullptr); } -URDE_SPECIALIZE_SHADER(CParticleSwooshShaders) - } diff --git a/Runtime/Graphics/Shaders/CParticleSwooshShaders.hpp b/Runtime/Graphics/Shaders/CParticleSwooshShaders.hpp index 8ba87d5a0..a903e11f4 100644 --- a/Runtime/Graphics/Shaders/CParticleSwooshShaders.hpp +++ b/Runtime/Graphics/Shaders/CParticleSwooshShaders.hpp @@ -1,12 +1,8 @@ #ifndef __URDE_CPARTICLESWOOSHSHADERS_HPP__ #define __URDE_CPARTICLESWOOSHSHADERS_HPP__ -#include "TShader.hpp" #include "Graphics/CGraphics.hpp" -#include "boo/graphicsdev/GL.hpp" -#include "boo/graphicsdev/D3D.hpp" -#include "boo/graphicsdev/Metal.hpp" -#include "boo/graphicsdev/Vulkan.hpp" +#include "boo/graphicsdev/IGraphicsDataFactory.hpp" namespace urde { @@ -14,10 +10,6 @@ class CParticleSwoosh; class CParticleSwooshShaders { - friend struct OGLParticleSwooshDataBindingFactory; - friend struct VulkanParticleSwooshDataBindingFactory; - friend struct D3DParticleSwooshDataBindingFactory; - friend struct MetalParticleSwooshDataBindingFactory; public: enum class EShaderClass { @@ -43,19 +35,11 @@ private: static boo::ObjToken m_noTexAdditiveZWrite; static boo::ObjToken m_noTexAdditiveNoZWrite; - static boo::ObjToken m_vtxFormat; /* No OpenGL */ - - CParticleSwoosh& m_gen; - boo::ObjToken m_pipeline; - CParticleSwooshShaders(CParticleSwoosh& gen, const boo::ObjToken& pipeline) - : m_gen(gen), m_pipeline(pipeline) {} - public: + static void Initialize(); + static void Shutdown(); static EShaderClass GetShaderClass(CParticleSwoosh& gen); static void BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, CParticleSwoosh& gen); - - using _CLS = CParticleSwooshShaders; -#include "TShaderDecl.hpp" }; } diff --git a/Runtime/Graphics/Shaders/CParticleSwooshShadersGLSL.cpp b/Runtime/Graphics/Shaders/CParticleSwooshShadersGLSL.cpp deleted file mode 100644 index 77c0d73c9..000000000 --- a/Runtime/Graphics/Shaders/CParticleSwooshShadersGLSL.cpp +++ /dev/null @@ -1,235 +0,0 @@ -#include "CParticleSwooshShaders.hpp" -#include "Particle/CParticleSwoosh.hpp" -#include "Particle/CSwooshDescription.hpp" - -namespace urde -{ - -static const char* VS = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"layout(location=0) in vec4 posIn;\n" -"layout(location=1) in vec4 uvIn;\n" -"layout(location=2) in vec4 colorIn;\n" -"\n" -"UBINDING0 uniform SwooshUniform\n" -"{\n" -" mat4 mvp;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -" vec2 uv;\n" -"};\n" -"\n" -"SBINDING(0) out VertToFrag vtf;\n" -"void main()\n" -"{\n" -" vtf.color = colorIn;\n" -" vtf.uv = uvIn.xy;\n" -" gl_Position = mvp * vec4(posIn.xyz, 1.0);\n" -"}\n"; - -static const char* FS_TEX = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -" vec2 uv;\n" -"};\n" -"\n" -"SBINDING(0) in VertToFrag vtf;\n" -"layout(location=0) out vec4 colorOut;\n" -"TBINDING0 uniform sampler2D tex;\n" -"void main()\n" -"{\n" -" colorOut = vtf.color * texture(tex, vtf.uv);\n" -"}\n"; - -static const char* FS_NOTEX = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -" vec2 uv;\n" -"};\n" -"\n" -"SBINDING(0) in VertToFrag vtf;\n" -"layout(location=0) out vec4 colorOut;\n" -"void main()\n" -"{\n" -" colorOut = vtf.color;\n" -"}\n"; - -struct OGLParticleSwooshDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CParticleSwooshShaders& shaders) - { - CParticleSwoosh& gen = shaders.m_gen; - CSwooshDescription* desc = gen.GetDesc(); - - CUVElement* texr = desc->x3c_TEXR.get(); - boo::ObjToken textures[] = {texr ? texr->GetValueTexture(0).GetObj()->GetBooTexture() : nullptr}; - - const boo::VertexElementDescriptor VtxFmt[] = - { - {gen.m_vertBuf.get(), nullptr, boo::VertexSemantic::Position4}, - {gen.m_vertBuf.get(), nullptr, boo::VertexSemantic::UV4}, - {gen.m_vertBuf.get(), nullptr, boo::VertexSemantic::Color}, - }; - boo::ObjToken vtxFmt = ctx.newVertexFormat(3, VtxFmt); - - boo::ObjToken uniforms[] = {gen.m_uniformBuf.get()}; - gen.m_dataBind = ctx.newShaderDataBinding(shaders.m_pipeline, vtxFmt, gen.m_vertBuf.get(), - nullptr, nullptr, 1, uniforms, - nullptr, texr ? 1 : 0, textures, nullptr, nullptr); - return nullptr; - } -}; - -static const char* UniNames[] = {"SwooshUniform"}; -static const char* TexNames[] = {"tex"}; - -TShader::IDataBindingFactory* CParticleSwooshShaders::Initialize(boo::GLDataFactory::Context& ctx) -{ - m_texZWrite = ctx.newShaderPipeline(VS, FS_TEX, 1, TexNames, 1, UniNames, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, true, - true, false, boo::CullMode::None); - m_texNoZWrite = ctx.newShaderPipeline(VS, FS_TEX, 1, TexNames, 1, UniNames, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - m_texAdditiveZWrite = ctx.newShaderPipeline(VS, FS_TEX, 1, TexNames, 1, UniNames, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, true, - true, false, boo::CullMode::None); - m_texAdditiveNoZWrite = ctx.newShaderPipeline(VS, FS_TEX, 1, TexNames, 1, UniNames, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - - m_noTexZWrite = ctx.newShaderPipeline(VS, FS_NOTEX, 0, nullptr, 1, UniNames, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, true, - true, false, boo::CullMode::None); - m_noTexNoZWrite = ctx.newShaderPipeline(VS, FS_NOTEX, 0, nullptr, 1, UniNames, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - m_noTexAdditiveZWrite = ctx.newShaderPipeline(VS, FS_NOTEX, 0, nullptr, 1, UniNames, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, true, - true, false, boo::CullMode::None); - m_noTexAdditiveNoZWrite = ctx.newShaderPipeline(VS, FS_NOTEX, 0, nullptr, 1, UniNames, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - - return new struct OGLParticleSwooshDataBindingFactory; -} - -template <> -void CParticleSwooshShaders::Shutdown() -{ - m_texZWrite.reset(); - m_texNoZWrite.reset(); - m_texAdditiveZWrite.reset(); - m_texAdditiveNoZWrite.reset(); - - m_noTexZWrite.reset(); - m_noTexNoZWrite.reset(); - m_noTexAdditiveZWrite.reset(); - m_noTexAdditiveNoZWrite.reset(); -} - -#if BOO_HAS_VULKAN -struct VulkanParticleSwooshDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken - BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CParticleSwooshShaders& shaders) - { - CParticleSwoosh& gen = shaders.m_gen; - CSwooshDescription* desc = gen.GetDesc(); - - CUVElement* texr = desc->x3c_TEXR.get(); - boo::ObjToken textures[] = {texr ? texr->GetValueTexture(0).GetObj()->GetBooTexture() : nullptr}; - - boo::ObjToken uniforms[] = {gen.m_uniformBuf.get()}; - gen.m_dataBind = ctx.newShaderDataBinding(shaders.m_pipeline, CParticleSwooshShaders::m_vtxFormat, - gen.m_vertBuf.get(), nullptr, nullptr, 1, uniforms, - nullptr, texr ? 1 : 0, textures, nullptr, nullptr); - return nullptr; - } -}; - -TShader::IDataBindingFactory* CParticleSwooshShaders::Initialize(boo::VulkanDataFactory::Context& ctx) -{ - static const boo::VertexElementDescriptor VtxFmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::UV4}, - {nullptr, nullptr, boo::VertexSemantic::Color}, - }; - m_vtxFormat = ctx.newVertexFormat(3, VtxFmt); - - m_texZWrite = ctx.newShaderPipeline(VS, FS_TEX, m_vtxFormat, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, true, - true, false, boo::CullMode::None); - m_texNoZWrite = ctx.newShaderPipeline(VS, FS_TEX, m_vtxFormat, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - m_texAdditiveZWrite = ctx.newShaderPipeline(VS, FS_TEX, m_vtxFormat, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, true, - true, false, boo::CullMode::None); - m_texAdditiveNoZWrite = ctx.newShaderPipeline(VS, FS_TEX, m_vtxFormat, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - - m_noTexZWrite = ctx.newShaderPipeline(VS, FS_NOTEX, m_vtxFormat, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, true, - true, false, boo::CullMode::None); - m_noTexNoZWrite = ctx.newShaderPipeline(VS, FS_NOTEX, m_vtxFormat, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - m_noTexAdditiveZWrite = ctx.newShaderPipeline(VS, FS_NOTEX, m_vtxFormat, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, true, - true, false, boo::CullMode::None); - m_noTexAdditiveNoZWrite = ctx.newShaderPipeline(VS, FS_NOTEX, m_vtxFormat, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - - return new struct VulkanParticleSwooshDataBindingFactory; -} - -template <> -void CParticleSwooshShaders::Shutdown() -{ - m_vtxFormat.reset(); - - m_texZWrite.reset(); - m_texNoZWrite.reset(); - m_texAdditiveZWrite.reset(); - m_texAdditiveNoZWrite.reset(); - - m_noTexZWrite.reset(); - m_noTexNoZWrite.reset(); - m_noTexAdditiveZWrite.reset(); - m_noTexAdditiveNoZWrite.reset(); -} -#endif - -} diff --git a/Runtime/Graphics/Shaders/CParticleSwooshShadersHLSL.cpp b/Runtime/Graphics/Shaders/CParticleSwooshShadersHLSL.cpp deleted file mode 100644 index 2865191c6..000000000 --- a/Runtime/Graphics/Shaders/CParticleSwooshShadersHLSL.cpp +++ /dev/null @@ -1,147 +0,0 @@ -#include "CParticleSwooshShaders.hpp" -#include "Particle/CParticleSwoosh.hpp" -#include "Particle/CSwooshDescription.hpp" - -namespace urde -{ - -static const char* VS = -"struct VertData\n" -"{\n" -" float4 posIn : POSITION;\n" -" float4 uvIn : UV;\n" -" float4 colorIn : COLOR;\n" -"};\n" -"\n" -"cbuffer SwooshUniform : register(b0)\n" -"{\n" -" float4x4 mvp;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 pos : SV_Position;\n" -" float4 color : COLOR;\n" -" float2 uv : UV;\n" -"};\n" -"\n" -"VertToFrag main(in VertData v)\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.color = v.colorIn;\n" -" vtf.uv = v.uvIn.xy;\n" -" vtf.pos = mul(mvp, float4(v.posIn.xyz, 1.0));\n" -" return vtf;\n" -"}\n"; - -static const char* FS_TEX = -"struct VertToFrag\n" -"{\n" -" float4 pos : SV_Position;\n" -" float4 color : COLOR;\n" -" float2 uv : UV;\n" -"};\n" -"\n" -"SamplerState samp : register(s0);\n" -"Texture2D tex : register(t0);\n" -"float4 main(in VertToFrag vtf) : SV_Target0\n" -"{\n" -" return vtf.color * tex.Sample(samp, vtf.uv);\n" -"}\n"; - -static const char* FS_NOTEX = -"struct VertToFrag\n" -"{\n" -" float4 pos : SV_Position;\n" -" float4 color : COLOR;\n" -" float2 uv : UV;\n" -"};\n" -"\n" -"float4 main(in VertToFrag vtf) : SV_Target0\n" -"{\n" -" return vtf.color;\n" -"}\n"; - -struct D3DParticleSwooshDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken - BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CParticleSwooshShaders& shaders) - { - CParticleSwoosh& gen = shaders.m_gen; - CSwooshDescription* desc = gen.GetDesc(); - - CUVElement* texr = desc->x3c_TEXR.get(); - boo::ObjToken textures[] = {texr ? texr->GetValueTexture(0).GetObj()->GetBooTexture() : nullptr}; - - boo::ObjToken uniforms[] = {gen.m_uniformBuf.get()}; - gen.m_dataBind = ctx.newShaderDataBinding(shaders.m_pipeline, CParticleSwooshShaders::m_vtxFormat, - gen.m_vertBuf.get(), nullptr, nullptr, 1, uniforms, - nullptr, texr ? 1 : 0, textures, nullptr, nullptr); - return nullptr; - } -}; - -TShader::IDataBindingFactory* CParticleSwooshShaders::Initialize(boo::D3DDataFactory::Context& ctx) -{ - static const boo::VertexElementDescriptor VtxFmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::UV4}, - {nullptr, nullptr, boo::VertexSemantic::Color}, - }; - m_vtxFormat = ctx.newVertexFormat(3, VtxFmt); - - m_texZWrite = ctx.newShaderPipeline(VS, FS_TEX, nullptr, nullptr, nullptr, m_vtxFormat, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, true, - true, false, boo::CullMode::None); - m_texNoZWrite = ctx.newShaderPipeline(VS, FS_TEX, nullptr, nullptr, nullptr, m_vtxFormat, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - m_texAdditiveZWrite = ctx.newShaderPipeline(VS, FS_TEX, nullptr, nullptr, nullptr, m_vtxFormat, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, true, - true, false, boo::CullMode::None); - m_texAdditiveNoZWrite = ctx.newShaderPipeline(VS, FS_TEX, nullptr, nullptr, nullptr, m_vtxFormat, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - - m_noTexZWrite = ctx.newShaderPipeline(VS, FS_NOTEX, nullptr, nullptr, nullptr, m_vtxFormat, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, true, - true, false, boo::CullMode::None); - m_noTexNoZWrite = ctx.newShaderPipeline(VS, FS_NOTEX, nullptr, nullptr, nullptr, m_vtxFormat, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - m_noTexAdditiveZWrite = ctx.newShaderPipeline(VS, FS_NOTEX, nullptr, nullptr, nullptr, m_vtxFormat, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, true, - true, false, boo::CullMode::None); - m_noTexAdditiveNoZWrite = ctx.newShaderPipeline(VS, FS_NOTEX, nullptr, nullptr, nullptr, m_vtxFormat, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - - return new struct D3DParticleSwooshDataBindingFactory; -} - -template <> -void CParticleSwooshShaders::Shutdown() -{ - m_vtxFormat.reset(); - - m_texZWrite.reset(); - m_texNoZWrite.reset(); - m_texAdditiveZWrite.reset(); - m_texAdditiveNoZWrite.reset(); - - m_noTexZWrite.reset(); - m_noTexNoZWrite.reset(); - m_noTexAdditiveZWrite.reset(); - m_noTexAdditiveNoZWrite.reset(); -} -} diff --git a/Runtime/Graphics/Shaders/CParticleSwooshShadersMetal.cpp b/Runtime/Graphics/Shaders/CParticleSwooshShadersMetal.cpp deleted file mode 100644 index b42cc9788..000000000 --- a/Runtime/Graphics/Shaders/CParticleSwooshShadersMetal.cpp +++ /dev/null @@ -1,153 +0,0 @@ -#include "CParticleSwooshShaders.hpp" -#include "Particle/CParticleSwoosh.hpp" -#include "Particle/CSwooshDescription.hpp" - -namespace urde -{ - -static const char* VS = -"#include \n" -"using namespace metal;\n" -"struct VertData\n" -"{\n" -" float4 posIn [[ attribute(0) ]];\n" -" float4 uvIn [[ attribute(1) ]];\n" -" float4 colorIn [[ attribute(2) ]];\n" -"};\n" -"\n" -"struct SwooshUniform\n" -"{\n" -" float4x4 mvp;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 pos [[ position ]];\n" -" float4 color;\n" -" float2 uv;\n" -"};\n" -"\n" -"vertex VertToFrag vmain(VertData v [[ stage_in ]], constant SwooshUniform& su [[ buffer(2) ]])\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.color = v.colorIn;\n" -" vtf.uv = v.uvIn.xy;\n" -" vtf.pos = su.mvp * float4(v.posIn.xyz, 1.0);\n" -" return vtf;\n" -"}\n"; - -static const char* FS_TEX = -"#include \n" -"using namespace metal;\n" -"struct VertToFrag\n" -"{\n" -" float4 pos [[ position ]];\n" -" float4 color;\n" -" float2 uv;\n" -"};\n" -"\n" -"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n" -" sampler samp [[ sampler(0) ]],\n" -" texture2d tex [[ texture(0) ]])\n" -"{\n" -" return vtf.color * tex.sample(samp, vtf.uv);\n" -"}\n"; - -static const char* FS_NOTEX = -"#include \n" -"using namespace metal;\n" -"struct VertToFrag\n" -"{\n" -" float4 pos [[ position ]];\n" -" float4 color;\n" -" float2 uv;\n" -"};\n" -"\n" -"fragment float4 fmain(VertToFrag vtf [[ stage_in ]])\n" -"{\n" -" return vtf.color;\n" -"}\n"; - -struct MetalParticleSwooshDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CParticleSwooshShaders& shaders) - { - CParticleSwoosh& gen = shaders.m_gen; - CSwooshDescription* desc = gen.GetDesc(); - - CUVElement* texr = desc->x3c_TEXR.get(); - boo::ObjToken textures[] = {texr ? texr->GetValueTexture(0).GetObj()->GetBooTexture() : nullptr}; - - boo::ObjToken uniforms[] = {gen.m_uniformBuf.get()}; - gen.m_dataBind = ctx.newShaderDataBinding(shaders.m_pipeline, CParticleSwooshShaders::m_vtxFormat, - gen.m_vertBuf.get(), nullptr, nullptr, 1, uniforms, - nullptr, texr ? 1 : 0, textures, nullptr, nullptr); - return nullptr; - } -}; - -TShader::IDataBindingFactory* CParticleSwooshShaders::Initialize(boo::MetalDataFactory::Context& ctx) -{ - static const boo::VertexElementDescriptor VtxFmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::UV4}, - {nullptr, nullptr, boo::VertexSemantic::Color}, - }; - m_vtxFormat = ctx.newVertexFormat(3, VtxFmt); - - m_texZWrite = ctx.newShaderPipeline(VS, FS_TEX, nullptr, nullptr, m_vtxFormat, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, true, - true, false, boo::CullMode::None); - m_texNoZWrite = ctx.newShaderPipeline(VS, FS_TEX, nullptr, nullptr, m_vtxFormat, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - m_texAdditiveZWrite = ctx.newShaderPipeline(VS, FS_TEX, nullptr, nullptr, m_vtxFormat, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, true, - true, false, boo::CullMode::None); - m_texAdditiveNoZWrite = ctx.newShaderPipeline(VS, FS_TEX, nullptr, nullptr, m_vtxFormat, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - - m_noTexZWrite = ctx.newShaderPipeline(VS, FS_NOTEX, nullptr, nullptr, m_vtxFormat, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, true, - true, false, boo::CullMode::None); - m_noTexNoZWrite = ctx.newShaderPipeline(VS, FS_NOTEX, nullptr, nullptr, m_vtxFormat, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - m_noTexAdditiveZWrite = ctx.newShaderPipeline(VS, FS_NOTEX, nullptr, nullptr, m_vtxFormat, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, true, - true, false, boo::CullMode::None); - m_noTexAdditiveNoZWrite = ctx.newShaderPipeline(VS, FS_NOTEX, nullptr, nullptr, m_vtxFormat, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, - boo::Primitive::TriStrips, boo::ZTest::LEqual, false, - true, false, boo::CullMode::None); - - return new struct MetalParticleSwooshDataBindingFactory; -} - -template <> -void CParticleSwooshShaders::Shutdown() -{ - m_texZWrite.reset(); - m_texNoZWrite.reset(); - m_texAdditiveZWrite.reset(); - m_texAdditiveNoZWrite.reset(); - - m_noTexZWrite.reset(); - m_noTexNoZWrite.reset(); - m_noTexAdditiveZWrite.reset(); - m_noTexAdditiveNoZWrite.reset(); - - m_vtxFormat.reset(); -} - -} diff --git a/Runtime/Graphics/Shaders/CPhazonSuitFilter.cpp b/Runtime/Graphics/Shaders/CPhazonSuitFilter.cpp index fc7c7038c..f312a626f 100644 --- a/Runtime/Graphics/Shaders/CPhazonSuitFilter.cpp +++ b/Runtime/Graphics/Shaders/CPhazonSuitFilter.cpp @@ -1,8 +1,29 @@ #include "CPhazonSuitFilter.hpp" +#include "hecl/Pipeline.hpp" +#include "Graphics/CGraphics.hpp" +#include "Graphics/CTexture.hpp" namespace urde { +static boo::ObjToken s_IndPipeline; +static boo::ObjToken s_Pipeline; +static boo::ObjToken s_BlurPipeline; + +void CPhazonSuitFilter::Initialize() +{ + s_IndPipeline = hecl::conv->convert(Shader_CPhazonSuitFilterInd{}); + s_Pipeline = hecl::conv->convert(Shader_CPhazonSuitFilterNoInd{}); + s_BlurPipeline = hecl::conv->convert(Shader_CPhazonSuitFilterBlur{}); +} + +void CPhazonSuitFilter::Shutdown() +{ + s_IndPipeline.reset(); + s_Pipeline.reset(); + s_BlurPipeline.reset(); +} + #define BLUR_SCALE (1.f / 128.f) void CPhazonSuitFilter::drawBlurPasses(float radius, const CTexture* indTex) @@ -45,7 +66,50 @@ void CPhazonSuitFilter::drawBlurPasses(float radius, const CTexture* indTex) }; m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts, sizeof(Vert), 4); - m_dataBind = TShader::BuildShaderDataBinding(ctx, *this); + boo::ObjToken bufs[] = {m_uniBufBlurX.get()}; + boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; + boo::ObjToken texs[4]; + int texBindIdxs[4]; + + texs[0] = CGraphics::g_SpareTexture.get(); + texBindIdxs[0] = 1; + m_dataBindBlurX = ctx.newShaderDataBinding(s_BlurPipeline, m_blurVbo.get(), nullptr, nullptr, 1, bufs, + stages, nullptr, nullptr, 1, texs, texBindIdxs, nullptr); + + bufs[0] = m_uniBufBlurY.get(); + texs[0] = CGraphics::g_SpareTexture.get(); + texBindIdxs[0] = 2; + m_dataBindBlurY = ctx.newShaderDataBinding(s_BlurPipeline, m_blurVbo.get(), nullptr, nullptr, 1, bufs, + stages, nullptr, nullptr, 1, texs, texBindIdxs, nullptr); + + bufs[0] = m_uniBuf.get(); + size_t texCount; + if (m_indTex) + { + texs[0] = CGraphics::g_SpareTexture.get(); + texBindIdxs[0] = 0; + texs[1] = m_indTex->GetBooTexture(); + texBindIdxs[1] = 0; + texs[2] = CGraphics::g_SpareTexture.get(); + texBindIdxs[2] = 1; + texs[3] = CGraphics::g_SpareTexture.get(); + texBindIdxs[3] = 2; + texCount = 4; + } + else + { + texs[0] = CGraphics::g_SpareTexture.get(); + texBindIdxs[0] = 0; + texs[1] = CGraphics::g_SpareTexture.get(); + texBindIdxs[1] = 1; + texs[2] = CGraphics::g_SpareTexture.get(); + texBindIdxs[2] = 2; + texCount = 3; + } + + m_dataBind = ctx.newShaderDataBinding(m_indTex ? s_IndPipeline : s_Pipeline, + m_vbo.get(), nullptr, nullptr, 1, bufs, stages, + nullptr, nullptr, texCount, texs, texBindIdxs, nullptr); return true; } BooTrace); } @@ -92,6 +156,4 @@ void CPhazonSuitFilter::draw(const zeus::CColor& color, CGraphics::DrawArray(0, 4); } -URDE_SPECIALIZE_SHADER(CPhazonSuitFilter) - } diff --git a/Runtime/Graphics/Shaders/CPhazonSuitFilter.hpp b/Runtime/Graphics/Shaders/CPhazonSuitFilter.hpp index 617a2269f..c17067bc3 100644 --- a/Runtime/Graphics/Shaders/CPhazonSuitFilter.hpp +++ b/Runtime/Graphics/Shaders/CPhazonSuitFilter.hpp @@ -1,7 +1,8 @@ #ifndef __URDE_CPHAZONSUITFILTER_HPP__ #define __URDE_CPHAZONSUITFILTER_HPP__ -#include "TShader.hpp" +#include "boo/graphicsdev/IGraphicsDataFactory.hpp" +#include "zeus/CColor.hpp" namespace urde { @@ -9,11 +10,6 @@ class CTexture; class CPhazonSuitFilter { - friend struct CPhazonSuitFilterGLDataBindingFactory; - friend struct CPhazonSuitFilterVulkanDataBindingFactory; - friend struct CPhazonSuitFilterMetalDataBindingFactory; - friend struct CPhazonSuitFilterD3DDataBindingFactory; - boo::ObjToken m_uniBufBlurX; boo::ObjToken m_uniBufBlurY; boo::ObjToken m_uniBuf; @@ -25,12 +21,11 @@ class CPhazonSuitFilter boo::ObjToken m_dataBind; public: + static void Initialize(); + static void Shutdown(); void drawBlurPasses(float radius, const CTexture* indTex); void draw(const zeus::CColor& color, float indScale, float indOffX, float indOffY); - - using _CLS = CPhazonSuitFilter; -#include "TShaderDecl.hpp" }; } diff --git a/Runtime/Graphics/Shaders/CPhazonSuitFilterGLSL.cpp b/Runtime/Graphics/Shaders/CPhazonSuitFilterGLSL.cpp deleted file mode 100644 index 972b2d2b9..000000000 --- a/Runtime/Graphics/Shaders/CPhazonSuitFilterGLSL.cpp +++ /dev/null @@ -1,373 +0,0 @@ -#include "CPhazonSuitFilter.hpp" -#include "TShader.hpp" -#include "Graphics/CTexture.hpp" - -namespace urde -{ - -static const char* VS = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"layout(location=0) in vec4 posIn;\n" -"layout(location=1) in vec4 screenUvIn;\n" -"layout(location=2) in vec4 indUvIn;\n" -"layout(location=3) in vec4 maskUvIn;\n" -"\n" -"UBINDING0 uniform PhazonSuitUniform\n" -"{\n" -" vec4 color;\n" -" vec4 indScaleOff;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -" vec4 indScaleOff;\n" -" vec2 screenUv;\n" -" vec2 indUv;\n" -" vec2 maskUv;\n" -"};\n" -"\n" -"SBINDING(0) out VertToFrag vtf;\n" -"void main()\n" -"{\n" -" vtf.color = color;\n" -" vtf.indScaleOff = indScaleOff;\n" -" vtf.screenUv = screenUvIn.xy;\n" -" vtf.indUv = indUvIn.xy;\n" -" vtf.maskUv = maskUvIn.xy;\n" -" gl_Position = vec4(posIn.xyz, 1.0);\n" -"}\n"; - -static const char* IndFS = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -" vec4 indScaleOff;\n" -" vec2 screenUv;\n" -" vec2 indUv;\n" -" vec2 maskUv;\n" -"};\n" -"\n" -"SBINDING(0) in VertToFrag vtf;\n" -"layout(location=0) out vec4 colorOut;\n" -"TBINDING0 uniform sampler2D screenTex;\n" -"TBINDING1 uniform sampler2D indTex;\n" -"TBINDING2 uniform sampler2D maskTex;\n" -"TBINDING3 uniform sampler2D maskTexBlur;\n" -"void main()\n" -"{\n" -" vec2 indUv = (texture(indTex, vtf.indUv).ra - vec2(0.5, 0.5)) * \n" -" vtf.indScaleOff.xy + vtf.indScaleOff.zw;\n" -" float maskBlurAlpha = clamp(0.0, (texture(maskTexBlur, vtf.maskUv).a - texture(maskTex, vtf.maskUv).a) * 2.0, 1.0);\n" -" colorOut = vtf.color * texture(screenTex, indUv + vtf.screenUv) * maskBlurAlpha;\n" -" colorOut.a = vtf.color.a;\n" -"}\n"; - -static const char* FS = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -" vec4 indScaleOff;\n" -" vec2 screenUv;\n" -" vec2 indUv;\n" -" vec2 maskUv;\n" -"};\n" -"\n" -"SBINDING(0) in VertToFrag vtf;\n" -"layout(location=0) out vec4 colorOut;\n" -"TBINDING0 uniform sampler2D screenTex;\n" -"TBINDING1 uniform sampler2D maskTex;\n" -"TBINDING2 uniform sampler2D maskTexBlur;\n" -"void main()\n" -"{\n" -" float maskBlurAlpha = clamp(0.0, (texture(maskTexBlur, vtf.maskUv).a - texture(maskTex, vtf.maskUv).a) * 2.0, 1.0);\n" -" colorOut = vtf.color * texture(screenTex, vtf.screenUv) * maskBlurAlpha;\n" -" colorOut.a = vtf.color.a;\n" -"}\n"; - -static const char* BlurVS = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"layout(location=0) in vec4 posIn;\n" -"layout(location=1) in vec4 uvIn;\n" -"\n" -"UBINDING0 uniform PhazonSuitBlurUniform\n" -"{\n" -" vec4 blurDir;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" vec2 uv;\n" -" vec2 blurDir;\n" -"};\n" -"\n" -"SBINDING(0) out VertToFrag vtf;\n" -"void main()\n" -"{\n" -" vtf.uv = uvIn.xy;\n" -" vtf.blurDir = blurDir.xy;\n" -" gl_Position = vec4(posIn.xyz, 1.0);\n" -"}\n"; - -static const char* BlurFS = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"struct VertToFrag\n" -"{\n" -" vec2 uv;\n" -" vec2 blurDir;\n" -"};\n" -"\n" -"SBINDING(0) in VertToFrag vtf;\n" -"layout(location=0) out vec4 colorOut;\n" -"TBINDING0 uniform sampler2D maskTex;\n" -"void main()\n" -"{\n" -" //this will be our alpha sum\n" -" float sum = 0.0;\n" -"\n" -" //apply blurring, using a 23-tap filter with predefined gaussian weights\n" -" sum += texture(maskTex, vtf.uv + -11.0 * vtf.blurDir).a * 0.007249;\n" -" sum += texture(maskTex, vtf.uv + -10.0 * vtf.blurDir).a * 0.011032;\n" -" sum += texture(maskTex, vtf.uv + -9.0 * vtf.blurDir).a * 0.016133;\n" -" sum += texture(maskTex, vtf.uv + -8.0 * vtf.blurDir).a * 0.022665;\n" -" sum += texture(maskTex, vtf.uv + -7.0 * vtf.blurDir).a * 0.030595;\n" -" sum += texture(maskTex, vtf.uv + -6.0 * vtf.blurDir).a * 0.039680;\n" -" sum += texture(maskTex, vtf.uv + -5.0 * vtf.blurDir).a * 0.049444;\n" -" sum += texture(maskTex, vtf.uv + -4.0 * vtf.blurDir).a * 0.059195;\n" -" sum += texture(maskTex, vtf.uv + -3.0 * vtf.blurDir).a * 0.068091;\n" -" sum += texture(maskTex, vtf.uv + -2.0 * vtf.blurDir).a * 0.075252;\n" -" sum += texture(maskTex, vtf.uv + -1.0 * vtf.blurDir).a * 0.079905;\n" -" sum += texture(maskTex, vtf.uv + 0.0 * vtf.blurDir).a * 0.081519;\n" -" sum += texture(maskTex, vtf.uv + 1.0 * vtf.blurDir).a * 0.079905;\n" -" sum += texture(maskTex, vtf.uv + 2.0 * vtf.blurDir).a * 0.075252;\n" -" sum += texture(maskTex, vtf.uv + 3.0 * vtf.blurDir).a * 0.068091;\n" -" sum += texture(maskTex, vtf.uv + 4.0 * vtf.blurDir).a * 0.059195;\n" -" sum += texture(maskTex, vtf.uv + 5.0 * vtf.blurDir).a * 0.049444;\n" -" sum += texture(maskTex, vtf.uv + 6.0 * vtf.blurDir).a * 0.039680;\n" -" sum += texture(maskTex, vtf.uv + 7.0 * vtf.blurDir).a * 0.030595;\n" -" sum += texture(maskTex, vtf.uv + 8.0 * vtf.blurDir).a * 0.022665;\n" -" sum += texture(maskTex, vtf.uv + 9.0 * vtf.blurDir).a * 0.016133;\n" -" sum += texture(maskTex, vtf.uv + 10.0 * vtf.blurDir).a * 0.011032;\n" -" sum += texture(maskTex, vtf.uv + 11.0 * vtf.blurDir).a * 0.007249;\n" -"\n" -" colorOut = vec4(1.0, 1.0, 1.0, sum);\n" -"}\n"; - -URDE_DECL_SPECIALIZE_SHADER(CPhazonSuitFilter) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_BlurVtxFmt; -static boo::ObjToken s_IndPipeline; -static boo::ObjToken s_Pipeline; -static boo::ObjToken s_BlurPipeline; - -struct CPhazonSuitFilterGLDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CPhazonSuitFilter& filter) - { - boo::GLDataFactory::Context& cctx = static_cast(ctx); - - const boo::VertexElementDescriptor BlurVtxVmt[] = - { - {filter.m_blurVbo.get(), nullptr, boo::VertexSemantic::Position4}, - {filter.m_blurVbo.get(), nullptr, boo::VertexSemantic::UV4} - }; - boo::ObjToken blurVtxFmt = ctx.newVertexFormat(2, BlurVtxVmt); - - boo::ObjToken bufs[] = {filter.m_uniBufBlurX.get()}; - boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; - boo::ObjToken texs[4]; - int texBindIdxs[4]; - - texs[0] = CGraphics::g_SpareTexture.get(); - texBindIdxs[0] = 1; - filter.m_dataBindBlurX = cctx.newShaderDataBinding(s_BlurPipeline, - blurVtxFmt, filter.m_blurVbo.get(), nullptr, nullptr, - 1, bufs, stages, nullptr, nullptr, 1, texs, texBindIdxs, nullptr); - - bufs[0] = filter.m_uniBufBlurY.get(); - texs[0] = CGraphics::g_SpareTexture.get(); - texBindIdxs[0] = 2; - filter.m_dataBindBlurY = cctx.newShaderDataBinding(s_BlurPipeline, - blurVtxFmt, filter.m_blurVbo.get(), nullptr, nullptr, - 1, bufs, stages, nullptr, nullptr, 1, texs, texBindIdxs, nullptr); - - const boo::VertexElementDescriptor VtxVmt[] = - { - {filter.m_vbo.get(), nullptr, boo::VertexSemantic::Position4}, - {filter.m_vbo.get(), nullptr, boo::VertexSemantic::UV4, 0}, - {filter.m_vbo.get(), nullptr, boo::VertexSemantic::UV4, 1}, - {filter.m_vbo.get(), nullptr, boo::VertexSemantic::UV4, 2} - }; - boo::ObjToken vtxFmt = ctx.newVertexFormat(4, VtxVmt); - - bufs[0] = filter.m_uniBuf.get(); - size_t texCount; - if (filter.m_indTex) - { - texs[0] = CGraphics::g_SpareTexture.get(); - texBindIdxs[0] = 0; - texs[1] = filter.m_indTex->GetBooTexture(); - texBindIdxs[1] = 0; - texs[2] = CGraphics::g_SpareTexture.get(); - texBindIdxs[2] = 1; - texs[3] = CGraphics::g_SpareTexture.get(); - texBindIdxs[3] = 2; - texCount = 4; - } - else - { - texs[0] = CGraphics::g_SpareTexture.get(); - texBindIdxs[0] = 0; - texs[1] = CGraphics::g_SpareTexture.get(); - texBindIdxs[1] = 1; - texs[2] = CGraphics::g_SpareTexture.get(); - texBindIdxs[2] = 2; - texCount = 3; - } - - return cctx.newShaderDataBinding(filter.m_indTex ? s_IndPipeline : s_Pipeline, - vtxFmt, filter.m_vbo.get(), nullptr, nullptr, - 1, bufs, stages, nullptr, nullptr, texCount, texs, texBindIdxs, nullptr); - } -}; - -#if BOO_HAS_VULKAN -struct CPhazonSuitFilterVulkanDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken - BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CPhazonSuitFilter& filter) - { - boo::VulkanDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken bufs[] = {filter.m_uniBufBlurX.get()}; - boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; - boo::ObjToken texs[4]; - int texBindIdxs[4]; - - texs[0] = CGraphics::g_SpareTexture.get(); - texBindIdxs[0] = 1; - filter.m_dataBindBlurX = cctx.newShaderDataBinding(s_BlurPipeline, - s_BlurVtxFmt, filter.m_blurVbo.get(), nullptr, nullptr, - 1, bufs, stages, nullptr, nullptr, 1, texs, texBindIdxs, nullptr); - - bufs[0] = filter.m_uniBufBlurY.get(); - texs[0] = CGraphics::g_SpareTexture.get(); - texBindIdxs[0] = 2; - filter.m_dataBindBlurY = cctx.newShaderDataBinding(s_BlurPipeline, - s_BlurVtxFmt, filter.m_blurVbo.get(), nullptr, nullptr, - 1, bufs, stages, nullptr, nullptr, 1, texs, texBindIdxs, nullptr); - - bufs[0] = filter.m_uniBuf.get(); - size_t texCount; - if (filter.m_indTex) - { - texs[0] = CGraphics::g_SpareTexture.get(); - texBindIdxs[0] = 0; - texs[1] = filter.m_indTex->GetBooTexture(); - texBindIdxs[1] = 0; - texs[2] = CGraphics::g_SpareTexture.get(); - texBindIdxs[2] = 1; - texs[3] = CGraphics::g_SpareTexture.get(); - texBindIdxs[3] = 2; - texCount = 4; - } - else - { - texs[0] = CGraphics::g_SpareTexture.get(); - texBindIdxs[0] = 0; - texs[1] = CGraphics::g_SpareTexture.get(); - texBindIdxs[1] = 1; - texs[2] = CGraphics::g_SpareTexture.get(); - texBindIdxs[2] = 2; - texCount = 3; - } - - return cctx.newShaderDataBinding(filter.m_indTex ? s_IndPipeline : s_Pipeline, - s_VtxFmt, filter.m_vbo.get(), nullptr, nullptr, - 1, bufs, stages, nullptr, nullptr, texCount, texs, texBindIdxs, nullptr); - } -}; -#endif - -TShader::IDataBindingFactory* -CPhazonSuitFilter::Initialize(boo::GLDataFactory::Context& ctx) -{ - const char* uniNames[] = {"PhazonSuitUniform"}; - const char* texNames[] = {"screenTex", "indTex", "maskTex", "maskTexBlur"}; - s_IndPipeline = ctx.newShaderPipeline(VS, IndFS, 4, texNames, 1, uniNames, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - texNames[1] = "maskTex"; - texNames[2] = "maskTexBlur"; - s_Pipeline = ctx.newShaderPipeline(VS, FS, 3, texNames, 1, uniNames, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - uniNames[0] = "PhazonSuitBlurUniform"; - texNames[0] = "maskTex"; - s_BlurPipeline = ctx.newShaderPipeline(BlurVS, BlurFS, 1, texNames, 1, uniNames, boo::BlendFactor::One, - boo::BlendFactor::Zero, boo::Primitive::TriStrips, - boo::ZTest::None, false, false, true, boo::CullMode::None); - return new CPhazonSuitFilterGLDataBindingFactory; -} - -template <> -void CPhazonSuitFilter::Shutdown() -{ - s_IndPipeline.reset(); - s_Pipeline.reset(); - s_BlurPipeline.reset(); -} - -#if BOO_HAS_VULKAN -TShader::IDataBindingFactory* -CPhazonSuitFilter::Initialize(boo::VulkanDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::UV4, 0}, - {nullptr, nullptr, boo::VertexSemantic::UV4, 1}, - {nullptr, nullptr, boo::VertexSemantic::UV4, 2} - }; - s_VtxFmt = ctx.newVertexFormat(4, VtxVmt); - const boo::VertexElementDescriptor BlurVtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::UV4} - }; - s_BlurVtxFmt = ctx.newVertexFormat(2, BlurVtxVmt); - s_IndPipeline = ctx.newShaderPipeline(VS, IndFS, s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_Pipeline = ctx.newShaderPipeline(VS, FS, s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_BlurPipeline = ctx.newShaderPipeline(BlurVS, BlurFS, s_BlurVtxFmt, boo::BlendFactor::One, - boo::BlendFactor::Zero, boo::Primitive::TriStrips, - boo::ZTest::None, false, false, true, boo::CullMode::None); - return new CPhazonSuitFilterVulkanDataBindingFactory; -} - -template <> -void CPhazonSuitFilter::Shutdown() -{ - s_VtxFmt.reset(); - s_BlurVtxFmt.reset(); - - s_IndPipeline.reset(); - s_Pipeline.reset(); - s_BlurPipeline.reset(); -} -#endif - -} diff --git a/Runtime/Graphics/Shaders/CPhazonSuitFilterHLSL.cpp b/Runtime/Graphics/Shaders/CPhazonSuitFilterHLSL.cpp deleted file mode 100644 index 4c4ed111f..000000000 --- a/Runtime/Graphics/Shaders/CPhazonSuitFilterHLSL.cpp +++ /dev/null @@ -1,266 +0,0 @@ -#include "CPhazonSuitFilter.hpp" -#include "TShader.hpp" -#include "Graphics/CTexture.hpp" - -namespace urde -{ - -static const char* VS = -"struct VertData {\n" -" float4 posIn : POSITION;\n" -" float4 screenUvIn : UV0;\n" -" float4 indUvIn : UV1;\n" -" float4 maskUvIn : UV2;\n" -"};\n" -"\n" -"cbuffer PhazonSuitUniform : register(b0)\n" -"{\n" -" float4 color;\n" -" float4 indScaleOff;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float4 color : COLOR;\n" -" float4 indScaleOff : SCALEOFF;\n" -" float2 screenUv : UV0;\n" -" float2 indUv : UV1;\n" -" float2 maskUv : UV2;\n" -"};\n" -"\n" -"VertToFrag main(in VertData v)\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.color = color;\n" -" vtf.indScaleOff = indScaleOff;\n" -" vtf.screenUv = v.screenUvIn.xy;\n" -" vtf.screenUv.y = 1.0 - vtf.screenUv.y;\n" -" vtf.indUv = v.indUvIn.xy;\n" -" vtf.maskUv = v.maskUvIn.xy;\n" -" vtf.maskUv.y = 1.0 - vtf.maskUv.y;\n" -" vtf.position = float4(v.posIn.xyz, 1.0);\n" -" return vtf;\n" -"}\n"; - -static const char* IndFS = -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float4 color : COLOR;\n" -" float4 indScaleOff : SCALEOFF;\n" -" float2 screenUv : UV0;\n" -" float2 indUv : UV1;\n" -" float2 maskUv : UV2;\n" -"};\n" -"\n" -"SamplerState samp : register(s0);\n" -"Texture2D screenTex : register(t0);\n" -"Texture2D indTex : register(t1);\n" -"Texture2D maskTex : register(t2);\n" -"Texture2D maskTexBlur : register(t3);\n" -"float4 main(in VertToFrag vtf) : SV_Target0\n" -"{\n" -" float2 indUv = (indTex.Sample(samp, vtf.indUv).ra - float2(0.5, 0.5)) * \n" -" vtf.indScaleOff.xy + vtf.indScaleOff.zw;\n" -" float maskBlurAlpha = saturate((maskTexBlur.Sample(samp, vtf.maskUv).a - maskTex.Sample(samp, vtf.maskUv).a) * 2.0);\n" -" return float4((vtf.color * screenTex.Sample(samp, indUv + vtf.screenUv) * maskBlurAlpha).rgb, vtf.color.a);\n" -"}\n"; - -static const char* FS = -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float4 color : COLOR;\n" -" float4 indScaleOff : SCALEOFF;\n" -" float2 screenUv : UV0;\n" -" float2 indUv : UV1;\n" -" float2 maskUv : UV2;\n" -"};\n" -"\n" -"SamplerState samp : register(s3);\n" -"Texture2D screenTex : register(t0);\n" -"Texture2D maskTex : register(t1);\n" -"Texture2D maskTexBlur : register(t2);\n" -"float4 main(in VertToFrag vtf) : SV_Target0\n" -"{\n" -" float maskBlurAlpha = saturate((maskTexBlur.Sample(samp, vtf.maskUv).a - maskTex.Sample(samp, vtf.maskUv).a) * 2.0);\n" -" return float4((vtf.color * screenTex.Sample(samp, vtf.screenUv) * maskBlurAlpha).rgb, vtf.color.a);\n" -"}\n"; - -static const char* BlurVS = -"struct VertData {\n" -" float4 posIn : POSITION;\n" -" float4 uvIn : UV;\n" -"};\n" -"\n" -"cbuffer PhazonSuitBlurUniform : register(b0)\n" -"{\n" -" float4 blurDir;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float2 uv : UV;\n" -" float2 blurDir : BLURDIR;\n" -"};\n" -"\n" -"VertToFrag main(in VertData v)\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.uv = v.uvIn.xy;\n" -" vtf.uv.y = 1.0 - vtf.uv.y;\n" -" vtf.blurDir = blurDir.xy;\n" -" vtf.position = float4(v.posIn.xyz, 1.0);\n" -" return vtf;\n" -"}\n"; - -static const char* BlurFS = -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float2 uv : UV;\n" -" float2 blurDir : BLURDIR;\n" -"};\n" -"\n" -"SamplerState samp : register(s3);\n" -"Texture2D maskTex : register(t0);\n" -"float4 main(in VertToFrag vtf) : SV_Target0\n" -"{\n" -" //this will be our alpha sum\n" -" float sum = 0.0;\n" -"\n" -" //apply blurring, using a 23-tap filter with predefined gaussian weights\n" -" sum += maskTex.Sample(samp, vtf.uv + -11.0 * vtf.blurDir).a * 0.007249;\n" -" sum += maskTex.Sample(samp, vtf.uv + -10.0 * vtf.blurDir).a * 0.011032;\n" -" sum += maskTex.Sample(samp, vtf.uv + -9.0 * vtf.blurDir).a * 0.016133;\n" -" sum += maskTex.Sample(samp, vtf.uv + -8.0 * vtf.blurDir).a * 0.022665;\n" -" sum += maskTex.Sample(samp, vtf.uv + -7.0 * vtf.blurDir).a * 0.030595;\n" -" sum += maskTex.Sample(samp, vtf.uv + -6.0 * vtf.blurDir).a * 0.039680;\n" -" sum += maskTex.Sample(samp, vtf.uv + -5.0 * vtf.blurDir).a * 0.049444;\n" -" sum += maskTex.Sample(samp, vtf.uv + -4.0 * vtf.blurDir).a * 0.059195;\n" -" sum += maskTex.Sample(samp, vtf.uv + -3.0 * vtf.blurDir).a * 0.068091;\n" -" sum += maskTex.Sample(samp, vtf.uv + -2.0 * vtf.blurDir).a * 0.075252;\n" -" sum += maskTex.Sample(samp, vtf.uv + -1.0 * vtf.blurDir).a * 0.079905;\n" -" sum += maskTex.Sample(samp, vtf.uv + 0.0 * vtf.blurDir).a * 0.081519;\n" -" sum += maskTex.Sample(samp, vtf.uv + 1.0 * vtf.blurDir).a * 0.079905;\n" -" sum += maskTex.Sample(samp, vtf.uv + 2.0 * vtf.blurDir).a * 0.075252;\n" -" sum += maskTex.Sample(samp, vtf.uv + 3.0 * vtf.blurDir).a * 0.068091;\n" -" sum += maskTex.Sample(samp, vtf.uv + 4.0 * vtf.blurDir).a * 0.059195;\n" -" sum += maskTex.Sample(samp, vtf.uv + 5.0 * vtf.blurDir).a * 0.049444;\n" -" sum += maskTex.Sample(samp, vtf.uv + 6.0 * vtf.blurDir).a * 0.039680;\n" -" sum += maskTex.Sample(samp, vtf.uv + 7.0 * vtf.blurDir).a * 0.030595;\n" -" sum += maskTex.Sample(samp, vtf.uv + 8.0 * vtf.blurDir).a * 0.022665;\n" -" sum += maskTex.Sample(samp, vtf.uv + 9.0 * vtf.blurDir).a * 0.016133;\n" -" sum += maskTex.Sample(samp, vtf.uv + 10.0 * vtf.blurDir).a * 0.011032;\n" -" sum += maskTex.Sample(samp, vtf.uv + 11.0 * vtf.blurDir).a * 0.007249;\n" -"\n" -" return float4(1.0, 1.0, 1.0, sum);\n" -"}\n"; - -URDE_DECL_SPECIALIZE_SHADER(CPhazonSuitFilter) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_BlurVtxFmt; -static boo::ObjToken s_IndPipeline; -static boo::ObjToken s_Pipeline; -static boo::ObjToken s_BlurPipeline; - -struct CPhazonSuitFilterD3DDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken - BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CPhazonSuitFilter& filter) - { - boo::D3DDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken bufs[] = {filter.m_uniBufBlurX.get()}; - boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; - boo::ObjToken texs[4]; - int texBindIdxs[4]; - - texs[0] = CGraphics::g_SpareTexture.get(); - texBindIdxs[0] = 1; - filter.m_dataBindBlurX = cctx.newShaderDataBinding(s_BlurPipeline, - s_BlurVtxFmt, filter.m_blurVbo.get(), nullptr, nullptr, - 1, bufs, stages, nullptr, nullptr, 1, texs, texBindIdxs, nullptr); - - bufs[0] = filter.m_uniBufBlurY.get(); - texs[0] = CGraphics::g_SpareTexture.get(); - texBindIdxs[0] = 2; - filter.m_dataBindBlurY = cctx.newShaderDataBinding(s_BlurPipeline, - s_BlurVtxFmt, filter.m_blurVbo.get(), nullptr, nullptr, - 1, bufs, stages, nullptr, nullptr, 1, texs, texBindIdxs, nullptr); - - bufs[0] = filter.m_uniBuf.get(); - size_t texCount; - if (filter.m_indTex) - { - texs[0] = CGraphics::g_SpareTexture.get(); - texBindIdxs[0] = 0; - texs[1] = filter.m_indTex->GetBooTexture(); - texBindIdxs[1] = 0; - texs[2] = CGraphics::g_SpareTexture.get(); - texBindIdxs[2] = 1; - texs[3] = CGraphics::g_SpareTexture.get(); - texBindIdxs[3] = 2; - texCount = 4; - } - else - { - texs[0] = CGraphics::g_SpareTexture.get(); - texBindIdxs[0] = 0; - texs[1] = CGraphics::g_SpareTexture.get(); - texBindIdxs[1] = 1; - texs[2] = CGraphics::g_SpareTexture.get(); - texBindIdxs[2] = 2; - texCount = 3; - } - - return cctx.newShaderDataBinding(filter.m_indTex ? s_IndPipeline : s_Pipeline, - s_VtxFmt, filter.m_vbo.get(), nullptr, nullptr, - 1, bufs, stages, nullptr, nullptr, texCount, texs, texBindIdxs, nullptr); - } -}; - -TShader::IDataBindingFactory* -CPhazonSuitFilter::Initialize(boo::D3DDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::UV4, 0}, - {nullptr, nullptr, boo::VertexSemantic::UV4, 1}, - {nullptr, nullptr, boo::VertexSemantic::UV4, 2} - }; - s_VtxFmt = ctx.newVertexFormat(4, VtxVmt); - const boo::VertexElementDescriptor BlurVtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::UV4} - }; - s_BlurVtxFmt = ctx.newVertexFormat(2, BlurVtxVmt); - s_IndPipeline = ctx.newShaderPipeline(VS, IndFS, nullptr, nullptr, nullptr, s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_Pipeline = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, nullptr, s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_BlurPipeline = ctx.newShaderPipeline(BlurVS, BlurFS, nullptr, nullptr, nullptr, s_BlurVtxFmt, boo::BlendFactor::One, - boo::BlendFactor::Zero, boo::Primitive::TriStrips, - boo::ZTest::None, false, false, true, boo::CullMode::None); - return new CPhazonSuitFilterD3DDataBindingFactory; -} - -template <> -void CPhazonSuitFilter::Shutdown() -{ - s_VtxFmt.reset(); - s_BlurVtxFmt.reset(); - - s_IndPipeline.reset(); - s_Pipeline.reset(); - s_BlurPipeline.reset(); -} -} diff --git a/Runtime/Graphics/Shaders/CPhazonSuitFilterMetal.cpp b/Runtime/Graphics/Shaders/CPhazonSuitFilterMetal.cpp deleted file mode 100644 index 7a9f80c08..000000000 --- a/Runtime/Graphics/Shaders/CPhazonSuitFilterMetal.cpp +++ /dev/null @@ -1,279 +0,0 @@ -#include "CPhazonSuitFilter.hpp" -#include "TShader.hpp" -#include "Graphics/CTexture.hpp" - -namespace urde -{ - -static const char* VS = -"#include \n" -"using namespace metal;\n" -"struct VertData\n" -"{\n" -" float4 posIn [[ attribute(0) ]];\n" -" float4 screenUvIn [[ attribute(1) ]];\n" -" float4 indUvIn [[ attribute(2) ]];\n" -" float4 maskUvIn [[ attribute(3) ]];\n" -"};\n" -"\n" -"struct PhazonSuitUniform\n" -"{\n" -" float4 color;\n" -" float4 indScaleOff;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float4 color;\n" -" float4 indScaleOff;\n" -" float2 screenUv;\n" -" float2 indUv;\n" -" float2 maskUv;\n" -"};\n" -"\n" -"vertex VertToFrag vmain(VertData v [[ stage_in ]], constant PhazonSuitUniform& psu [[ buffer(2) ]])\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.color = psu.color;\n" -" vtf.indScaleOff = psu.indScaleOff;\n" -" vtf.screenUv = v.screenUvIn.xy;\n" -" vtf.screenUv.y = 1.0 - vtf.screenUv.y;\n" -" vtf.indUv = v.indUvIn.xy;\n" -" vtf.maskUv = v.maskUvIn.xy;\n" -" vtf.maskUv.y = 1.0 - vtf.maskUv.y;\n" -" vtf.position = float4(v.posIn.xyz, 1.0);\n" -" return vtf;\n" -"}\n"; - -static const char* IndFS = -"#include \n" -"using namespace metal;\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float4 color;\n" -" float4 indScaleOff;\n" -" float2 screenUv;\n" -" float2 indUv;\n" -" float2 maskUv;\n" -"};\n" -"\n" -"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n" -" sampler samp [[ sampler(0) ]],\n" -" texture2d screenTex [[ texture(0) ]],\n" -" texture2d indTex [[ texture(1) ]],\n" -" texture2d maskTex [[ texture(2) ]],\n" -" texture2d maskTexBlur [[ texture(3) ]])\n" -"{\n" -" float2 indUv = (indTex.sample(samp, vtf.indUv).ra - float2(0.5, 0.5)) * \n" -" vtf.indScaleOff.xy + vtf.indScaleOff.zw;\n" -" float maskBlurAlpha = saturate((maskTexBlur.sample(samp, vtf.maskUv).a - maskTex.sample(samp, vtf.maskUv).a) * 2.0);\n" -" return float4((vtf.color * screenTex.sample(samp, indUv + vtf.screenUv) * maskBlurAlpha).rgb, vtf.color.a);\n" -"}\n"; - -static const char* FS = -"#include \n" -"using namespace metal;\n" -"struct VertToFrag\n" -"{\n" -" float4 color;\n" -" float4 indScaleOff;\n" -" float2 screenUv;\n" -" float2 indUv;\n" -" float2 maskUv;\n" -"};\n" -"\n" -"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n" -" sampler clampSamp [[ sampler(3) ]],\n" -" texture2d screenTex [[ texture(0) ]],\n" -" texture2d maskTex [[ texture(1) ]],\n" -" texture2d maskTexBlur [[ texture(2) ]])\n" -"{\n" -" float maskBlurAlpha = saturate((maskTexBlur.sample(clampSamp, vtf.maskUv).a - maskTex.sample(clampSamp, vtf.maskUv).a) * 2.0);\n" -" return float4((vtf.color * screenTex.sample(clampSamp, vtf.screenUv) * maskBlurAlpha).rgb, vtf.color.a);\n" -"}\n"; - -static const char* BlurVS = -"#include \n" -"using namespace metal;\n" -"struct VertData\n" -"{\n" -" float4 posIn [[ attribute(0) ]];\n" -" float4 uvIn [[ attribute(1) ]];\n" -"};\n" -"\n" -"struct PhazonSuitBlurUniform\n" -"{\n" -" float4 blurDir;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float2 uv;\n" -" float2 blurDir;\n" -"};\n" -"\n" -"vertex VertToFrag vmain(VertData v [[ stage_in ]], constant PhazonSuitBlurUniform& psu [[ buffer(2) ]])\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.uv = v.uvIn.xy;\n" -" vtf.uv.y = 1.0 - vtf.uv.y;\n" -" vtf.blurDir = psu.blurDir.xy;\n" -" vtf.position = float4(v.posIn.xyz, 1.0);\n" -" return vtf;\n" -"}\n"; - -static const char* BlurFS = -"#include \n" -"using namespace metal;\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float2 uv;\n" -" float2 blurDir;\n" -"};\n" -"\n" -"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n" -" sampler clampSamp [[ sampler(3) ]],\n" -" texture2d maskTex [[ texture(0) ]])\n" -"{\n" -" //this will be our alpha sum\n" -" float sum = 0.0;\n" -"\n" -" //apply blurring, using a 23-tap filter with predefined gaussian weights\n" -" sum += maskTex.sample(clampSamp, vtf.uv + -11.0 * vtf.blurDir).a * 0.007249;\n" -" sum += maskTex.sample(clampSamp, vtf.uv + -10.0 * vtf.blurDir).a * 0.011032;\n" -" sum += maskTex.sample(clampSamp, vtf.uv + -9.0 * vtf.blurDir).a * 0.016133;\n" -" sum += maskTex.sample(clampSamp, vtf.uv + -8.0 * vtf.blurDir).a * 0.022665;\n" -" sum += maskTex.sample(clampSamp, vtf.uv + -7.0 * vtf.blurDir).a * 0.030595;\n" -" sum += maskTex.sample(clampSamp, vtf.uv + -6.0 * vtf.blurDir).a * 0.039680;\n" -" sum += maskTex.sample(clampSamp, vtf.uv + -5.0 * vtf.blurDir).a * 0.049444;\n" -" sum += maskTex.sample(clampSamp, vtf.uv + -4.0 * vtf.blurDir).a * 0.059195;\n" -" sum += maskTex.sample(clampSamp, vtf.uv + -3.0 * vtf.blurDir).a * 0.068091;\n" -" sum += maskTex.sample(clampSamp, vtf.uv + -2.0 * vtf.blurDir).a * 0.075252;\n" -" sum += maskTex.sample(clampSamp, vtf.uv + -1.0 * vtf.blurDir).a * 0.079905;\n" -" sum += maskTex.sample(clampSamp, vtf.uv).a * 0.081519;\n" -" sum += maskTex.sample(clampSamp, vtf.uv + 1.0 * vtf.blurDir).a * 0.079905;\n" -" sum += maskTex.sample(clampSamp, vtf.uv + 2.0 * vtf.blurDir).a * 0.075252;\n" -" sum += maskTex.sample(clampSamp, vtf.uv + 3.0 * vtf.blurDir).a * 0.068091;\n" -" sum += maskTex.sample(clampSamp, vtf.uv + 4.0 * vtf.blurDir).a * 0.059195;\n" -" sum += maskTex.sample(clampSamp, vtf.uv + 5.0 * vtf.blurDir).a * 0.049444;\n" -" sum += maskTex.sample(clampSamp, vtf.uv + 6.0 * vtf.blurDir).a * 0.039680;\n" -" sum += maskTex.sample(clampSamp, vtf.uv + 7.0 * vtf.blurDir).a * 0.030595;\n" -" sum += maskTex.sample(clampSamp, vtf.uv + 8.0 * vtf.blurDir).a * 0.022665;\n" -" sum += maskTex.sample(clampSamp, vtf.uv + 9.0 * vtf.blurDir).a * 0.016133;\n" -" sum += maskTex.sample(clampSamp, vtf.uv + 10.0 * vtf.blurDir).a * 0.011032;\n" -" sum += maskTex.sample(clampSamp, vtf.uv + 11.0 * vtf.blurDir).a * 0.007249;\n" -"\n" -" return float4(1.0, 1.0, 1.0, sum);\n" -"}\n"; - -URDE_DECL_SPECIALIZE_SHADER(CPhazonSuitFilter) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_BlurVtxFmt; -static boo::ObjToken s_IndPipeline; -static boo::ObjToken s_Pipeline; -static boo::ObjToken s_BlurPipeline; - -struct CPhazonSuitFilterMetalDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CPhazonSuitFilter& filter) - { - boo::MetalDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken bufs[] = {filter.m_uniBufBlurX.get()}; - boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; - boo::ObjToken texs[4]; - int texBindIdxs[4]; - - texs[0] = CGraphics::g_SpareTexture.get(); - texBindIdxs[0] = 1; - filter.m_dataBindBlurX = cctx.newShaderDataBinding(s_BlurPipeline, - s_BlurVtxFmt, filter.m_blurVbo.get(), nullptr, nullptr, - 1, bufs, stages, nullptr, nullptr, 1, texs, texBindIdxs, nullptr); - - bufs[0] = filter.m_uniBufBlurY.get(); - texs[0] = CGraphics::g_SpareTexture.get(); - texBindIdxs[0] = 2; - filter.m_dataBindBlurY = cctx.newShaderDataBinding(s_BlurPipeline, - s_BlurVtxFmt, filter.m_blurVbo.get(), nullptr, nullptr, - 1, bufs, stages, nullptr, nullptr, 1, texs, texBindIdxs, nullptr); - - bufs[0] = filter.m_uniBuf.get(); - size_t texCount; - if (filter.m_indTex) - { - texs[0] = CGraphics::g_SpareTexture.get(); - texBindIdxs[0] = 0; - texs[1] = filter.m_indTex->GetBooTexture(); - texBindIdxs[1] = 0; - texs[2] = CGraphics::g_SpareTexture.get(); - texBindIdxs[2] = 1; - texs[3] = CGraphics::g_SpareTexture.get(); - texBindIdxs[3] = 2; - texCount = 4; - } - else - { - texs[0] = CGraphics::g_SpareTexture.get(); - texBindIdxs[0] = 0; - texs[1] = CGraphics::g_SpareTexture.get(); - texBindIdxs[1] = 1; - texs[2] = CGraphics::g_SpareTexture.get(); - texBindIdxs[2] = 2; - texCount = 3; - } - - return cctx.newShaderDataBinding(filter.m_indTex ? s_IndPipeline : s_Pipeline, - s_VtxFmt, filter.m_vbo.get(), nullptr, nullptr, - 1, bufs, stages, nullptr, nullptr, texCount, texs, texBindIdxs, nullptr); - } -}; - -TShader::IDataBindingFactory* -CPhazonSuitFilter::Initialize(boo::MetalDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::UV4, 0}, - {nullptr, nullptr, boo::VertexSemantic::UV4, 1}, - {nullptr, nullptr, boo::VertexSemantic::UV4, 2} - }; - s_VtxFmt = ctx.newVertexFormat(4, VtxVmt); - const boo::VertexElementDescriptor BlurVtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::UV4} - }; - s_BlurVtxFmt = ctx.newVertexFormat(2, BlurVtxVmt); - s_IndPipeline = ctx.newShaderPipeline(VS, IndFS, nullptr, nullptr, s_VtxFmt, - boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_Pipeline = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, s_VtxFmt, - boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_BlurPipeline = ctx.newShaderPipeline(BlurVS, BlurFS, nullptr, nullptr, s_BlurVtxFmt, - boo::BlendFactor::One, - boo::BlendFactor::Zero, boo::Primitive::TriStrips, - boo::ZTest::None, false, false, true, boo::CullMode::None); - return new CPhazonSuitFilterMetalDataBindingFactory; -} - -template <> -void CPhazonSuitFilter::Shutdown() -{ - s_VtxFmt.reset(); - s_BlurVtxFmt.reset(); - s_IndPipeline.reset(); - s_Pipeline.reset(); - s_BlurPipeline.reset(); -} - -} diff --git a/Runtime/Graphics/Shaders/CRadarPaintShader.cpp b/Runtime/Graphics/Shaders/CRadarPaintShader.cpp index e181645b8..f005dde81 100644 --- a/Runtime/Graphics/Shaders/CRadarPaintShader.cpp +++ b/Runtime/Graphics/Shaders/CRadarPaintShader.cpp @@ -1,8 +1,23 @@ #include "CRadarPaintShader.hpp" +#include "hecl/Pipeline.hpp" +#include "Graphics/CGraphics.hpp" +#include "Graphics/CTexture.hpp" namespace urde { +static boo::ObjToken s_Pipeline; + +void CRadarPaintShader::Initialize() +{ + s_Pipeline = hecl::conv->convert(Shader_CRadarPaintShader{}); +} + +void CRadarPaintShader::Shutdown() +{ + s_Pipeline.reset(); +} + void CRadarPaintShader::draw(const std::vector& instances, const CTexture* tex) { if (!instances.size()) @@ -16,7 +31,11 @@ void CRadarPaintShader::draw(const std::vector& instances, const CText { m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(Instance), m_maxInsts); m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(zeus::CMatrix4f), 1); - m_dataBind = TShader::BuildShaderDataBinding(ctx, *this); + boo::ObjToken bufs[] = {m_uniBuf.get()}; + boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; + boo::ObjToken texs[] = {m_tex->GetBooTexture()}; + m_dataBind = ctx.newShaderDataBinding(s_Pipeline, nullptr, m_vbo.get(), nullptr, + 1, bufs, stages, nullptr, nullptr, 1, texs, nullptr, nullptr); return true; } BooTrace); } @@ -33,6 +52,4 @@ void CRadarPaintShader::draw(const std::vector& instances, const CText CGraphics::DrawInstances(0, 4, instances.size()); } -URDE_SPECIALIZE_SHADER(CRadarPaintShader) - } diff --git a/Runtime/Graphics/Shaders/CRadarPaintShader.hpp b/Runtime/Graphics/Shaders/CRadarPaintShader.hpp index 361fa32e5..444e2c9f3 100644 --- a/Runtime/Graphics/Shaders/CRadarPaintShader.hpp +++ b/Runtime/Graphics/Shaders/CRadarPaintShader.hpp @@ -1,7 +1,6 @@ #ifndef __URDE_CRADARPAINTSHADER_HPP__ #define __URDE_CRADARPAINTSHADER_HPP__ -#include "TShader.hpp" #include "zeus/CMatrix4f.hpp" #include "zeus/CColor.hpp" #include "zeus/CRectangle.hpp" @@ -12,11 +11,6 @@ namespace urde class CRadarPaintShader { - friend struct CRadarPaintShaderGLDataBindingFactory; - friend struct CRadarPaintShaderVulkanDataBindingFactory; - friend struct CRadarPaintShaderMetalDataBindingFactory; - friend struct CRadarPaintShaderD3DDataBindingFactory; - public: struct Instance { @@ -33,10 +27,9 @@ private: size_t m_maxInsts = 0; public: + static void Initialize(); + static void Shutdown(); void draw(const std::vector& instances, const CTexture* tex); - - using _CLS = CRadarPaintShader; -#include "TShaderDecl.hpp" }; } diff --git a/Runtime/Graphics/Shaders/CRadarPaintShaderGLSL.cpp b/Runtime/Graphics/Shaders/CRadarPaintShaderGLSL.cpp deleted file mode 100644 index 56837ea69..000000000 --- a/Runtime/Graphics/Shaders/CRadarPaintShaderGLSL.cpp +++ /dev/null @@ -1,152 +0,0 @@ -#include "CRadarPaintShader.hpp" -#include "TShader.hpp" -#include "Graphics/CTexture.hpp" - -namespace urde -{ - -static const char* VS = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"layout(location=0) in vec4 posIn[4];\n" -"layout(location=4) in vec4 uvIn[4];\n" -"layout(location=8) in vec4 colorIn;\n" -"\n" -"UBINDING0 uniform RadarPaintUniform\n" -"{\n" -" mat4 xf;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -" vec2 uv;\n" -"};\n" -"\n" -"SBINDING(0) out VertToFrag vtf;\n" -"void main()\n" -"{\n" -" vec3 pos = posIn[gl_VertexID].xyz;\n" -" vtf.uv = uvIn[gl_VertexID].xy;\n" -" vtf.color = colorIn;\n" -" gl_Position = xf * vec4(pos, 1.0);\n" -"}\n"; - -static const char* FS = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -" vec2 uv;\n" -"};\n" -"\n" -"SBINDING(0) in VertToFrag vtf;\n" -"layout(location=0) out vec4 colorOut;\n" -"TBINDING0 uniform sampler2D tex;\n" -"void main()\n" -"{\n" -" colorOut = vtf.color * texture(tex, vtf.uv);\n" -"}\n"; - -URDE_DECL_SPECIALIZE_SHADER(CRadarPaintShader) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_Pipeline; - -struct CRadarPaintShaderGLDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CRadarPaintShader& filter) - { - boo::GLDataFactory::Context& cctx = static_cast(ctx); - - const boo::VertexElementDescriptor VtxVmt[] = - { - {filter.m_vbo.get(), nullptr, boo::VertexSemantic::Position4, 0}, - {filter.m_vbo.get(), nullptr, boo::VertexSemantic::Position4, 1}, - {filter.m_vbo.get(), nullptr, boo::VertexSemantic::Position4, 2}, - {filter.m_vbo.get(), nullptr, boo::VertexSemantic::Position4, 3}, - {filter.m_vbo.get(), nullptr, boo::VertexSemantic::UV4, 0}, - {filter.m_vbo.get(), nullptr, boo::VertexSemantic::UV4, 1}, - {filter.m_vbo.get(), nullptr, boo::VertexSemantic::UV4, 2}, - {filter.m_vbo.get(), nullptr, boo::VertexSemantic::UV4, 3}, - {filter.m_vbo.get(), nullptr, boo::VertexSemantic::Color} - }; - boo::ObjToken vtxFmt = ctx.newVertexFormat(9, VtxVmt); - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; - boo::ObjToken texs[] = {filter.m_tex->GetBooTexture()}; - return cctx.newShaderDataBinding(s_Pipeline, - vtxFmt, nullptr, filter.m_vbo.get(), nullptr, - 1, bufs, stages, nullptr, nullptr, 1, texs, nullptr, nullptr); - } -}; - -#if BOO_HAS_VULKAN -struct CRadarPaintShaderVulkanDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken - BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CRadarPaintShader& filter) - { - boo::VulkanDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - boo::ObjToken texs[] = {filter.m_tex->GetBooTexture()}; - return cctx.newShaderDataBinding(s_Pipeline, s_VtxFmt, - nullptr, filter.m_vbo.get(), nullptr, 1, bufs, - nullptr, nullptr, nullptr, 1, texs, nullptr, nullptr); - } -}; -#endif - -TShader::IDataBindingFactory* -CRadarPaintShader::Initialize(boo::GLDataFactory::Context& ctx) -{ - const char* uniNames[] = {"RadarPaintUniform"}; - const char* texNames[] = {"tex"}; - s_Pipeline = ctx.newShaderPipeline(VS, FS, 1, texNames, 1, uniNames, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - return new CRadarPaintShaderGLDataBindingFactory; -} - -template <> -void CRadarPaintShader::Shutdown() -{ - s_Pipeline.reset(); -} - -#if BOO_HAS_VULKAN -TShader::IDataBindingFactory* -CRadarPaintShader::Initialize(boo::VulkanDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4, 0}, - {nullptr, nullptr, boo::VertexSemantic::Position4, 1}, - {nullptr, nullptr, boo::VertexSemantic::Position4, 2}, - {nullptr, nullptr, boo::VertexSemantic::Position4, 3}, - {nullptr, nullptr, boo::VertexSemantic::UV4, 0}, - {nullptr, nullptr, boo::VertexSemantic::UV4, 1}, - {nullptr, nullptr, boo::VertexSemantic::UV4, 2}, - {nullptr, nullptr, boo::VertexSemantic::UV4, 3}, - {nullptr, nullptr, boo::VertexSemantic::Color} - }; - s_VtxFmt = ctx.newVertexFormat(9, VtxVmt); - s_Pipeline = ctx.newShaderPipeline(VS, FS, s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - return new CRadarPaintShaderVulkanDataBindingFactory; -} - -template <> -void CRadarPaintShader::Shutdown() -{ - s_VtxFmt.reset(); - s_Pipeline.reset(); -} -#endif - -} diff --git a/Runtime/Graphics/Shaders/CRadarPaintShaderHLSL.cpp b/Runtime/Graphics/Shaders/CRadarPaintShaderHLSL.cpp deleted file mode 100644 index 5d08113f7..000000000 --- a/Runtime/Graphics/Shaders/CRadarPaintShaderHLSL.cpp +++ /dev/null @@ -1,102 +0,0 @@ -#include "CRadarPaintShader.hpp" -#include "TShader.hpp" -#include "Graphics/CTexture.hpp" - -namespace urde -{ - -static const char* VS = -"struct VertData\n" -"{\n" -" float4 posIn[4] : POSITION;\n" -" float4 uvIn[4] : UV;\n" -" float4 colorIn : COLOR;\n" -"};\n" -"\n" -"cbuffer RadarPaintUniform : register(b0)\n" -"{\n" -" float4x4 xf;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float4 color : COLOR;\n" -" float2 uv : UV;\n" -"};\n" -"\n" -"VertToFrag main(in VertData v, in uint vertId : SV_VertexID)\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.color = v.colorIn;\n" -" vtf.uv = v.uvIn[vertId].xy;\n" -" vtf.position = mul(xf, float4(v.posIn[vertId].xyz, 1.0));\n" -" return vtf;\n" -"}\n"; - -static const char* FS = -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float4 color : COLOR;\n" -" float2 uv : UV;\n" -"};\n" -"\n" -"SamplerState samp : register(s0);\n" -"Texture2D tex : register(t0);\n" -"float4 main(in VertToFrag vtf) : SV_Target0\n" -"{\n" -" return vtf.color * tex.Sample(samp, vtf.uv);\n" -"}\n"; - -URDE_DECL_SPECIALIZE_SHADER(CRadarPaintShader) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_Pipeline; - -struct CRadarPaintShaderD3DDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken - BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CRadarPaintShader& filter) - { - boo::D3DDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - boo::ObjToken texs[] = {filter.m_tex->GetBooTexture()}; - return cctx.newShaderDataBinding(s_Pipeline, s_VtxFmt, - nullptr, filter.m_vbo.get(), nullptr, 1, bufs, - nullptr, nullptr, nullptr, 1, texs, nullptr, nullptr); - } -}; - -TShader::IDataBindingFactory* -CRadarPaintShader::Initialize(boo::D3DDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4, 0}, - {nullptr, nullptr, boo::VertexSemantic::Position4, 1}, - {nullptr, nullptr, boo::VertexSemantic::Position4, 2}, - {nullptr, nullptr, boo::VertexSemantic::Position4, 3}, - {nullptr, nullptr, boo::VertexSemantic::UV4, 0}, - {nullptr, nullptr, boo::VertexSemantic::UV4, 1}, - {nullptr, nullptr, boo::VertexSemantic::UV4, 2}, - {nullptr, nullptr, boo::VertexSemantic::UV4, 3}, - {nullptr, nullptr, boo::VertexSemantic::Color} - }; - s_VtxFmt = ctx.newVertexFormat(9, VtxVmt); - s_Pipeline = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, nullptr, - s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - return new CRadarPaintShaderD3DDataBindingFactory; -} - -template <> -void CRadarPaintShader::Shutdown() -{ - s_VtxFmt.reset(); - s_Pipeline.reset(); -} -} diff --git a/Runtime/Graphics/Shaders/CRadarPaintShaderMetal.cpp b/Runtime/Graphics/Shaders/CRadarPaintShaderMetal.cpp deleted file mode 100644 index bd91269ff..000000000 --- a/Runtime/Graphics/Shaders/CRadarPaintShaderMetal.cpp +++ /dev/null @@ -1,109 +0,0 @@ -#include "CRadarPaintShader.hpp" -#include "TShader.hpp" -#include "Graphics/CTexture.hpp" - -namespace urde -{ - -static const char* VS = -"#include \n" -"using namespace metal;\n" -"struct VertData\n" -"{\n" -" float4 posIn[4];\n" -" float4 uvIn[4];\n" -" float4 colorIn;\n" -"};\n" -"\n" -"struct RadarPaintUniform\n" -"{\n" -" float4x4 xf;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float4 color;\n" -" float2 uv;\n" -"};\n" -"\n" -"vertex VertToFrag vmain(constant VertData* va [[ buffer(1) ]],\n" -" uint vertId [[ vertex_id ]], uint instId [[ instance_id ]],\n" -" constant RadarPaintUniform& rpu [[ buffer(2) ]])\n" -"{\n" -" VertToFrag vtf;\n" -" constant VertData& v = va[instId];\n" -" vtf.color = v.colorIn;\n" -" vtf.uv = v.uvIn[vertId].xy;\n" -" vtf.position = rpu.xf * float4(v.posIn[vertId].xyz, 1.0);\n" -" return vtf;\n" -"}\n"; - -static const char* FS = -"#include \n" -"using namespace metal;\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float4 color;\n" -" float2 uv;\n" -"};\n" -"\n" -"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n" -" sampler samp [[ sampler(0) ]],\n" -" texture2d tex [[ texture(0) ]])\n" -"{\n" -" return vtf.color * tex.sample(samp, vtf.uv);\n" -"}\n"; - -URDE_DECL_SPECIALIZE_SHADER(CRadarPaintShader) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_Pipeline; - -struct CRadarPaintShaderMetalDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CRadarPaintShader& filter) - { - boo::MetalDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - boo::ObjToken texs[] = {filter.m_tex->GetBooTexture()}; - return cctx.newShaderDataBinding(s_Pipeline, s_VtxFmt, - nullptr, filter.m_vbo.get(), nullptr, 1, bufs, - nullptr, nullptr, nullptr, 1, texs, nullptr, nullptr); - } -}; - -TShader::IDataBindingFactory* -CRadarPaintShader::Initialize(boo::MetalDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4, 0}, - {nullptr, nullptr, boo::VertexSemantic::Position4, 1}, - {nullptr, nullptr, boo::VertexSemantic::Position4, 2}, - {nullptr, nullptr, boo::VertexSemantic::Position4, 3}, - {nullptr, nullptr, boo::VertexSemantic::UV4, 0}, - {nullptr, nullptr, boo::VertexSemantic::UV4, 1}, - {nullptr, nullptr, boo::VertexSemantic::UV4, 2}, - {nullptr, nullptr, boo::VertexSemantic::UV4, 3}, - {nullptr, nullptr, boo::VertexSemantic::Color} - }; - s_VtxFmt = ctx.newVertexFormat(9, VtxVmt); - s_Pipeline = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, s_VtxFmt, - boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - return new CRadarPaintShaderMetalDataBindingFactory; -} - -template <> -void CRadarPaintShader::Shutdown() -{ - s_VtxFmt.reset(); - s_Pipeline.reset(); -} - -} diff --git a/Runtime/Graphics/Shaders/CRandomStaticFilter.cpp b/Runtime/Graphics/Shaders/CRandomStaticFilter.cpp index 30ed54134..4ab02e9c4 100644 --- a/Runtime/Graphics/Shaders/CRandomStaticFilter.cpp +++ b/Runtime/Graphics/Shaders/CRandomStaticFilter.cpp @@ -2,10 +2,47 @@ #include "Graphics/CBooRenderer.hpp" #include "GameGlobalObjects.hpp" #include "CSimplePool.hpp" +#include "hecl/Pipeline.hpp" namespace urde { +static boo::ObjToken s_AlphaPipeline; +static boo::ObjToken s_AddPipeline; +static boo::ObjToken s_MultPipeline; +static boo::ObjToken s_CookieCutterPipeline; + +void CRandomStaticFilter::Initialize() +{ + s_AlphaPipeline = hecl::conv->convert(Shader_CRandomStaticFilterAlpha{}); + s_AddPipeline = hecl::conv->convert(Shader_CRandomStaticFilterAdd{}); + s_MultPipeline = hecl::conv->convert(Shader_CRandomStaticFilterMult{}); + s_CookieCutterPipeline = hecl::conv->convert(Shader_CRandomStaticFilterCookieCutter{}); +} + +void CRandomStaticFilter::Shutdown() +{ + s_AlphaPipeline.reset(); + s_AddPipeline.reset(); + s_MultPipeline.reset(); + s_CookieCutterPipeline.reset(); +} + +static boo::ObjToken SelectPipeline(EFilterType type) +{ + switch (type) + { + case EFilterType::Blend: + return s_AlphaPipeline; + case EFilterType::Add: + return s_AddPipeline; + case EFilterType::Multiply: + return s_MultPipeline; + default: + return {}; + } +} + CRandomStaticFilter::CRandomStaticFilter(EFilterType type, bool cookieCutter) : m_cookieCutter(cookieCutter) { @@ -24,7 +61,12 @@ CRandomStaticFilter::CRandomStaticFilter(EFilterType type, bool cookieCutter) }; m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts, sizeof(Vert), 4); m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); - m_dataBind = TMultiBlendShader::BuildShaderDataBinding(ctx, type, *this); + boo::ObjToken bufs[] = {m_uniBuf.get()}; + boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; + boo::ObjToken texs[] = {g_Renderer->GetRandomStaticEntropyTex()}; + m_dataBind = ctx.newShaderDataBinding(m_cookieCutter ? s_CookieCutterPipeline : SelectPipeline(type), + m_vbo.get(), nullptr, nullptr, 1, bufs, stages, nullptr, nullptr, + 1, texs, nullptr, nullptr); return true; } BooTrace); } @@ -41,6 +83,4 @@ void CRandomStaticFilter::draw(const zeus::CColor& color, float t) CGraphics::DrawArray(0, 4); } -URDE_SPECIALIZE_MULTI_BLEND_SHADER(CRandomStaticFilter) - } diff --git a/Runtime/Graphics/Shaders/CRandomStaticFilter.hpp b/Runtime/Graphics/Shaders/CRandomStaticFilter.hpp index c1e9bf7b3..b2d5196d1 100644 --- a/Runtime/Graphics/Shaders/CRandomStaticFilter.hpp +++ b/Runtime/Graphics/Shaders/CRandomStaticFilter.hpp @@ -1,7 +1,6 @@ #ifndef __URDE_CRANDOMSTATICFILTER_HPP__ #define __URDE_CRANDOMSTATICFILTER_HPP__ -#include "TMultiBlendShader.hpp" #include "zeus/CMatrix4f.hpp" #include "zeus/CColor.hpp" #include "zeus/CRectangle.hpp" @@ -12,11 +11,6 @@ namespace urde class CRandomStaticFilter { - friend struct CRandomStaticFilterGLDataBindingFactory; - friend struct CRandomStaticFilterVulkanDataBindingFactory; - friend struct CRandomStaticFilterMetalDataBindingFactory; - friend struct CRandomStaticFilterD3DDataBindingFactory; - struct Uniform { zeus::CColor color; @@ -30,14 +24,13 @@ class CRandomStaticFilter bool m_cookieCutter; public: + static void Initialize(); + static void Shutdown(); CRandomStaticFilter(EFilterType type, bool cookieCutter=false); CRandomStaticFilter(EFilterType type, const TLockedToken&) : CRandomStaticFilter(type) {} void draw(const zeus::CColor& color, float t); void DrawFilter(EFilterShape, const zeus::CColor& color, float t) { draw(color, t); } - - using _CLS = CRandomStaticFilter; -#include "TMultiBlendShaderDecl.hpp" }; class CCookieCutterDepthRandomStaticFilter : public CRandomStaticFilter diff --git a/Runtime/Graphics/Shaders/CRandomStaticFilterGLSL.cpp b/Runtime/Graphics/Shaders/CRandomStaticFilterGLSL.cpp deleted file mode 100644 index 7be6e009d..000000000 --- a/Runtime/Graphics/Shaders/CRandomStaticFilterGLSL.cpp +++ /dev/null @@ -1,234 +0,0 @@ -#include "CRandomStaticFilter.hpp" -#include "TMultiBlendShader.hpp" -#include "Graphics/CBooRenderer.hpp" -#include "GameGlobalObjects.hpp" - -namespace urde -{ - -static const char* VS = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"layout(location=0) in vec4 posIn;\n" -"layout(location=1) in vec4 uvIn;\n" -"\n" -"UBINDING0 uniform RandomStaticUniform\n" -"{\n" -" vec4 color;\n" -" float randOff;\n" -" float discardThres;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -" vec2 uv;\n" -" float randOff;\n" -" float discardThres;\n" -"};\n" -"\n" -"SBINDING(0) out VertToFrag vtf;\n" -"void main()\n" -"{\n" -" vtf.color = color;\n" -" vtf.uv = uvIn.xy;\n" -" vtf.randOff = randOff;\n" -" vtf.discardThres = discardThres;\n" -" gl_Position = vec4(posIn.xyz, 1.0);\n" -"}\n"; - -static const char* FS = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -" vec2 uv;\n" -" float randOff;\n" -" float discardThres;\n" -"};\n" -"\n" -"ivec2 Lookup8BPP(in vec2 uv, in float randOff)\n" -"{\n" -" float bx;\n" -" float rx = modf(uv.x / 8.0, bx) * 8.0;\n" -" float by;\n" -" float ry = modf(uv.y / 4.0, by) * 4.0;\n" -" float bidx = by * 80.0 + bx;\n" -" float addr = bidx * 32.0 + ry * 8.0 + rx + randOff;\n" -" float y;\n" -" float x = modf(addr / 1024.0, y) * 1024.0;\n" -" return ivec2(x, y);\n" -"}\n" -"\n" -"SBINDING(0) in VertToFrag vtf;\n" -"layout(location=0) out vec4 colorOut;\n" -"TBINDING0 uniform sampler2D tex;\n" -"void main()\n" -"{\n" -" colorOut = texelFetch(tex, Lookup8BPP(vtf.uv, vtf.randOff), 0) * vtf.color;\n" -" colorOut.a = vtf.color.a;\n" -"}\n"; - -static const char* FSCookieCutter = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -" vec2 uv;\n" -" float randOff;\n" -" float discardThres;\n" -"};\n" -"\n" -"ivec2 Lookup8BPP(in vec2 uv, in float randOff)\n" -"{\n" -" float bx;\n" -" float rx = modf(uv.x / 8.0, bx) * 8.0;\n" -" float by;\n" -" float ry = modf(uv.y / 4.0, by) * 4.0;\n" -" float bidx = by * 80.0 + bx;\n" -" float addr = bidx * 32.0 + ry * 8.0 + rx + randOff;\n" -" float y;\n" -" float x = modf(addr / 1024.0, y) * 1024.0;\n" -" return ivec2(x, y);\n" -"}\n" -"\n" -"SBINDING(0) in VertToFrag vtf;\n" -"layout(location=0) out vec4 colorOut;\n" -"TBINDING0 uniform sampler2D tex;\n" -"void main()\n" -"{\n" -" colorOut = texelFetch(tex, Lookup8BPP(vtf.uv, vtf.randOff), 0) * vtf.color;\n" -" if (colorOut.a < vtf.discardThres)\n" -" discard;\n" -"}\n"; - -URDE_DECL_SPECIALIZE_MULTI_BLEND_SHADER(CRandomStaticFilter) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_AlphaPipeline; -static boo::ObjToken s_AddPipeline; -static boo::ObjToken s_MultPipeline; -static boo::ObjToken s_CookieCutterPipeline; - -static boo::ObjToken SelectPipeline(EFilterType type) -{ - switch (type) - { - case EFilterType::Blend: - return s_AlphaPipeline; - case EFilterType::Add: - return s_AddPipeline; - case EFilterType::Multiply: - return s_MultPipeline; - default: - return {}; - } -} - -struct CRandomStaticFilterGLDataBindingFactory : TMultiBlendShader::IDataBindingFactory -{ - boo::ObjToken BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - EFilterType type, CRandomStaticFilter& filter) - { - boo::GLDataFactory::Context& cctx = static_cast(ctx); - - const boo::VertexElementDescriptor VtxVmt[] = - { - {filter.m_vbo.get(), nullptr, boo::VertexSemantic::Position4}, - {filter.m_vbo.get(), nullptr, boo::VertexSemantic::UV4} - }; - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; - boo::ObjToken texs[] = {g_Renderer->GetRandomStaticEntropyTex()}; - return cctx.newShaderDataBinding(filter.m_cookieCutter ? s_CookieCutterPipeline : SelectPipeline(type), - ctx.newVertexFormat(2, VtxVmt), filter.m_vbo.get(), nullptr, nullptr, - 1, bufs, stages, nullptr, nullptr, 1, texs, nullptr, nullptr); - } -}; - -#if BOO_HAS_VULKAN -struct CRandomStaticFilterVulkanDataBindingFactory : TMultiBlendShader::IDataBindingFactory -{ - boo::ObjToken - BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - EFilterType type, CRandomStaticFilter& filter) - { - boo::VulkanDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - boo::ObjToken texs[] = {g_Renderer->GetRandomStaticEntropyTex().get()}; - return cctx.newShaderDataBinding(filter.m_cookieCutter ? s_CookieCutterPipeline : SelectPipeline(type), - s_VtxFmt, filter.m_vbo.get(), nullptr, nullptr, 1, bufs, - nullptr, nullptr, nullptr, 1, texs, nullptr, nullptr); - } -}; -#endif - -TMultiBlendShader::IDataBindingFactory* -CRandomStaticFilter::Initialize(boo::GLDataFactory::Context& ctx) -{ - const char* texNames[] = {"tex"}; - const char* uniNames[] = {"RandomStaticUniform"}; - s_AlphaPipeline = ctx.newShaderPipeline(VS, FS, 1, texNames, 1, uniNames, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_AddPipeline = ctx.newShaderPipeline(VS, FS, 1, texNames, 1, uniNames, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_MultPipeline = ctx.newShaderPipeline(VS, FS, 1, texNames, 1, uniNames, boo::BlendFactor::Zero, - boo::BlendFactor::SrcColor, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_CookieCutterPipeline = ctx.newShaderPipeline(VS, FSCookieCutter, 1, texNames, 1, uniNames, boo::BlendFactor::Zero, - boo::BlendFactor::SrcColor, boo::Primitive::TriStrips, - boo::ZTest::LEqual, true, false, false, boo::CullMode::None); - return new CRandomStaticFilterGLDataBindingFactory; -} - -template <> -void CRandomStaticFilter::Shutdown() -{ - s_AlphaPipeline.reset(); - s_AddPipeline.reset(); - s_MultPipeline.reset(); - s_CookieCutterPipeline.reset(); -} - -#if BOO_HAS_VULKAN -TMultiBlendShader::IDataBindingFactory* -CRandomStaticFilter::Initialize(boo::VulkanDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::UV4} - }; - s_VtxFmt = ctx.newVertexFormat(2, VtxVmt); - s_AlphaPipeline = ctx.newShaderPipeline(VS, FS, s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_AddPipeline = ctx.newShaderPipeline(VS, FS, s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_MultPipeline = ctx.newShaderPipeline(VS, FS, s_VtxFmt, boo::BlendFactor::SrcColor, - boo::BlendFactor::DstColor, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_CookieCutterPipeline = ctx.newShaderPipeline(VS, FSCookieCutter, s_VtxFmt, boo::BlendFactor::SrcColor, - boo::BlendFactor::DstColor, boo::Primitive::TriStrips, - boo::ZTest::LEqual, true, false, false, boo::CullMode::None); - return new CRandomStaticFilterVulkanDataBindingFactory; -} - -template <> -void CRandomStaticFilter::Shutdown() -{ - s_VtxFmt.reset(); - s_AlphaPipeline.reset(); - s_AddPipeline.reset(); - s_MultPipeline.reset(); - s_CookieCutterPipeline.reset(); -} -#endif - -} diff --git a/Runtime/Graphics/Shaders/CRandomStaticFilterHLSL.cpp b/Runtime/Graphics/Shaders/CRandomStaticFilterHLSL.cpp deleted file mode 100644 index c0f85ecbb..000000000 --- a/Runtime/Graphics/Shaders/CRandomStaticFilterHLSL.cpp +++ /dev/null @@ -1,182 +0,0 @@ -#include "CRandomStaticFilter.hpp" -#include "TMultiBlendShader.hpp" -#include "Graphics/CBooRenderer.hpp" -#include "GameGlobalObjects.hpp" - -namespace urde -{ - -static const char* VS = -"struct VertData\n" -"{\n" -" float4 posIn : POSITION;\n" -" float2 uvIn : UV;\n" -"};\n" -"\n" -"cbuffer RandomStaticUniform : register(b0)\n" -"{\n" -" float4 color;\n" -" float randOff;\n" -" float discardThres;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 pos : SV_Position;\n" -" float4 color : COLOR;\n" -" float2 uv : UV;\n" -" float randOff : RANDOFF;\n" -" float discardThres : DISCARDTHRES;\n" -"};\n" -"\n" -"VertToFrag main(in VertData v)\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.color = color;\n" -" vtf.uv = v.uvIn.xy;\n" -" vtf.randOff = randOff;\n" -" vtf.discardThres = discardThres;\n" -" vtf.pos = float4(v.posIn.xyz, 1.0);\n" -" return vtf;\n" -"}\n"; - -static const char* FS = -"struct VertToFrag\n" -"{\n" -" float4 pos : SV_Position;\n" -" float4 color : COLOR;\n" -" float2 uv : UV;\n" -" float randOff : RANDOFF;\n" -" float discardThres : DISCARDTHRES;\n" -"};\n" -"\n" -"static int3 Lookup8BPP(float2 uv, float randOff)\n" -"{\n" -" float bx;\n" -" float rx = modf(uv.x / 8.0, bx) * 8.0;\n" -" float by;\n" -" float ry = modf(uv.y / 4.0, by) * 4.0;\n" -" float bidx = by * 80.0 + bx;\n" -" float addr = bidx * 32.0 + ry * 8.0 + rx + randOff;\n" -" float y;\n" -" float x = modf(addr / 1024.0, y) * 1024.0;\n" -" return int3(x, y, 0);\n" -"}\n" -"\n" -"Texture2D tex : register(t0);\n" -"float4 main(in VertToFrag vtf) : SV_Target0\n" -"{\n" -" float4 colorOut = tex.Load(Lookup8BPP(vtf.uv, vtf.randOff)) * vtf.color;\n" -" colorOut.a = vtf.color.a;\n" -" return colorOut;\n" -"}\n"; - -static const char* FSCookieCutter = -"struct VertToFrag\n" -"{\n" -" float4 pos : SV_Position;\n" -" float4 color : COLOR;\n" -" float2 uv : UV;\n" -" float randOff : RANDOFF;\n" -" float discardThres : DISCARDTHRES;\n" -"};\n" -"\n" -"static int3 Lookup8BPP(float2 uv, float randOff)\n" -"{\n" -" float bx;\n" -" float rx = modf(uv.x / 8.0, bx) * 8.0;\n" -" float by;\n" -" float ry = modf(uv.y / 4.0, by) * 4.0;\n" -" float bidx = by * 80.0 + bx;\n" -" float addr = bidx * 32.0 + ry * 8.0 + rx + randOff;\n" -" float y;\n" -" float x = modf(addr / 1024.0, y) * 1024.0;\n" -" return int3(x, y, 0);\n" -"}\n" -"\n" -"Texture2D tex : register(t0);\n" -"float4 main(in VertToFrag vtf) : SV_Target0\n" -"{\n" -" float4 colorOut = tex.Load(Lookup8BPP(vtf.uv, vtf.randOff)) * vtf.color;\n" -" if (colorOut.a < vtf.discardThres)\n" -" discard;\n" -" return colorOut;\n" -"}\n"; - -URDE_DECL_SPECIALIZE_MULTI_BLEND_SHADER(CRandomStaticFilter) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_AlphaPipeline; -static boo::ObjToken s_AddPipeline; -static boo::ObjToken s_MultPipeline; -static boo::ObjToken s_CookieCutterPipeline; - -static boo::ObjToken SelectPipeline(EFilterType type) -{ - switch (type) - { - case EFilterType::Blend: - return s_AlphaPipeline; - case EFilterType::Add: - return s_AddPipeline; - case EFilterType::Multiply: - return s_MultPipeline; - default: - return {}; - } -} - -struct CRandomStaticFilterD3DDataBindingFactory : TMultiBlendShader::IDataBindingFactory -{ - boo::ObjToken - BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - EFilterType type, CRandomStaticFilter& filter) - { - boo::D3DDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - boo::ObjToken texs[] = {g_Renderer->GetRandomStaticEntropyTex().get()}; - return cctx.newShaderDataBinding(filter.m_cookieCutter ? s_CookieCutterPipeline : SelectPipeline(type), - s_VtxFmt, filter.m_vbo.get(), nullptr, nullptr, 1, bufs, - nullptr, nullptr, nullptr, 1, texs, nullptr, nullptr); - } -}; - -TMultiBlendShader::IDataBindingFactory* -CRandomStaticFilter::Initialize(boo::D3DDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::UV4} - }; - s_VtxFmt = ctx.newVertexFormat(2, VtxVmt); - s_AlphaPipeline = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, nullptr, s_VtxFmt, - boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_AddPipeline = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, nullptr, s_VtxFmt, - boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_MultPipeline = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, nullptr, s_VtxFmt, - boo::BlendFactor::Zero, - boo::BlendFactor::SrcColor, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_CookieCutterPipeline = ctx.newShaderPipeline(VS, FSCookieCutter, nullptr, nullptr, nullptr, s_VtxFmt, - boo::BlendFactor::Zero, - boo::BlendFactor::SrcColor, boo::Primitive::TriStrips, - boo::ZTest::LEqual, true, false, false, boo::CullMode::None); - return new CRandomStaticFilterD3DDataBindingFactory; -} - -template <> -void CRandomStaticFilter::Shutdown() -{ - s_VtxFmt.reset(); - s_AlphaPipeline.reset(); - s_AddPipeline.reset(); - s_MultPipeline.reset(); - s_CookieCutterPipeline.reset(); -} -} diff --git a/Runtime/Graphics/Shaders/CRandomStaticFilterMetal.cpp b/Runtime/Graphics/Shaders/CRandomStaticFilterMetal.cpp deleted file mode 100644 index d19b62fd9..000000000 --- a/Runtime/Graphics/Shaders/CRandomStaticFilterMetal.cpp +++ /dev/null @@ -1,189 +0,0 @@ -#include "CRandomStaticFilter.hpp" -#include "TMultiBlendShader.hpp" -#include "Graphics/CBooRenderer.hpp" -#include "GameGlobalObjects.hpp" - -namespace urde -{ - -static const char* VS = -"#include \n" -"using namespace metal;\n" -"struct VertData\n" -"{\n" -" float4 posIn [[ attribute(0) ]];\n" -" float2 uvIn [[ attribute(1) ]];\n" -"};\n" -"\n" -"struct RandomStaticUniform\n" -"{\n" -" float4 color;\n" -" float randOff;\n" -" float discardThres;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 pos [[ position ]];\n" -" float4 color;\n" -" float2 uv;\n" -" float randOff;\n" -" float discardThres;\n" -"};\n" -"\n" -"vertex VertToFrag vmain(VertData v [[ stage_in ]],\n" -" constant RandomStaticUniform& su [[ buffer(2) ]])\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.color = su.color;\n" -" vtf.uv = v.uvIn.xy;\n" -" vtf.randOff = su.randOff;\n" -" vtf.discardThres = su.discardThres;\n" -" vtf.pos = float4(v.posIn.xyz, 1.0);\n" -" return vtf;\n" -"}\n"; - -static const char* FS = -"#include \n" -"using namespace metal;\n" -"struct VertToFrag\n" -"{\n" -" float4 pos [[ position ]];\n" -" float4 color;\n" -" float2 uv;\n" -" float randOff;\n" -" float discardThres;\n" -"};\n" -"\n" -"static uint2 Lookup8BPP(float2 uv, float randOff)\n" -"{\n" -" float bx;\n" -" float rx = modf(uv.x / 8.0, bx) * 8.0;\n" -" float by;\n" -" float ry = modf(uv.y / 4.0, by) * 4.0;\n" -" float bidx = by * 80.0 + bx;\n" -" float addr = bidx * 32.0 + ry * 8.0 + rx + randOff;\n" -" float y;\n" -" float x = modf(addr / 1024.0, y) * 1024.0;\n" -" return uint2(x, y);\n" -"}\n" -"\n" -"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n" -" texture2d tex [[ texture(0) ]])\n" -"{\n" -" float4 colorOut = tex.read(Lookup8BPP(vtf.uv, vtf.randOff)) * vtf.color;\n" -" colorOut.a = vtf.color.a;\n" -" return colorOut;\n" -"}\n"; - -static const char* FSCookieCutter = -"#include \n" -"using namespace metal;\n" -"struct VertToFrag\n" -"{\n" -" float4 pos [[ position ]];\n" -" float4 color;\n" -" float2 uv;\n" -" float randOff;\n" -" float discardThres;\n" -"};\n" -"\n" -"static uint2 Lookup8BPP(float2 uv, float randOff)\n" -"{\n" -" float bx;\n" -" float rx = modf(uv.x / 8.0, bx) * 8.0;\n" -" float by;\n" -" float ry = modf(uv.y / 4.0, by) * 4.0;\n" -" float bidx = by * 80.0 + bx;\n" -" float addr = bidx * 32.0 + ry * 8.0 + rx + randOff;\n" -" float y;\n" -" float x = modf(addr / 1024.0, y) * 1024.0;\n" -" return uint2(x, y);\n" -"}\n" -"\n" -"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n" -" texture2d tex [[ texture(0) ]])\n" -"{\n" -" float4 colorOut = tex.read(Lookup8BPP(vtf.uv, vtf.randOff)) * vtf.color;\n" -" if (colorOut.a < vtf.discardThres)\n" -" discard_fragment();\n" -" return colorOut;\n" -"}\n"; - -URDE_DECL_SPECIALIZE_MULTI_BLEND_SHADER(CRandomStaticFilter) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_AlphaPipeline; -static boo::ObjToken s_AddPipeline; -static boo::ObjToken s_MultPipeline; -static boo::ObjToken s_CookieCutterPipeline; - -static boo::ObjToken SelectPipeline(EFilterType type) -{ - switch (type) - { - case EFilterType::Blend: - return s_AlphaPipeline; - case EFilterType::Add: - return s_AddPipeline; - case EFilterType::Multiply: - return s_MultPipeline; - default: - return {}; - } -} - -struct CRandomStaticFilterMetalDataBindingFactory : TMultiBlendShader::IDataBindingFactory -{ - boo::ObjToken BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - EFilterType type, CRandomStaticFilter& filter) - { - boo::MetalDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - boo::ObjToken texs[] = {g_Renderer->GetRandomStaticEntropyTex()}; - return cctx.newShaderDataBinding(filter.m_cookieCutter ? s_CookieCutterPipeline : SelectPipeline(type), - s_VtxFmt, filter.m_vbo.get(), nullptr, nullptr, 1, bufs, - nullptr, nullptr, nullptr, 1, texs, nullptr, nullptr); - } -}; - -TMultiBlendShader::IDataBindingFactory* -CRandomStaticFilter::Initialize(boo::MetalDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::UV4} - }; - s_VtxFmt = ctx.newVertexFormat(2, VtxVmt); - s_AlphaPipeline = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, s_VtxFmt, - boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_AddPipeline = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, s_VtxFmt, - boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_MultPipeline = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, s_VtxFmt, - boo::BlendFactor::Zero, - boo::BlendFactor::SrcColor, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_CookieCutterPipeline = ctx.newShaderPipeline(VS, FSCookieCutter, nullptr, nullptr, s_VtxFmt, - boo::BlendFactor::SrcColor, - boo::BlendFactor::DstColor, boo::Primitive::TriStrips, - boo::ZTest::LEqual, true, false, false, boo::CullMode::None); - return new CRandomStaticFilterMetalDataBindingFactory; -} - -template <> -void CRandomStaticFilter::Shutdown() -{ - s_VtxFmt.reset(); - s_AlphaPipeline.reset(); - s_AddPipeline.reset(); - s_MultPipeline.reset(); - s_CookieCutterPipeline.reset(); -} - -} diff --git a/Runtime/Graphics/Shaders/CScanLinesFilter.cpp b/Runtime/Graphics/Shaders/CScanLinesFilter.cpp index 16ad64fab..776de21ae 100644 --- a/Runtime/Graphics/Shaders/CScanLinesFilter.cpp +++ b/Runtime/Graphics/Shaders/CScanLinesFilter.cpp @@ -1,15 +1,57 @@ #include "CScanLinesFilter.hpp" +#include "hecl/Pipeline.hpp" +#include "Graphics/CGraphics.hpp" +#include "GameGlobalObjects.hpp" +#include "Graphics/CBooRenderer.hpp" namespace urde { +static boo::ObjToken s_AlphaPipeline; +static boo::ObjToken s_AddPipeline; +static boo::ObjToken s_MultPipeline; + +void CScanLinesFilter::Initialize() +{ + s_AlphaPipeline = hecl::conv->convert(Shader_CScanLinesFilterAlpha{}); + s_AddPipeline = hecl::conv->convert(Shader_CScanLinesFilterAdd{}); + s_MultPipeline = hecl::conv->convert(Shader_CScanLinesFilterMult{}); +} + +void CScanLinesFilter::Shutdown() +{ + s_AlphaPipeline.reset(); + s_AddPipeline.reset(); + s_MultPipeline.reset(); +} + +static boo::ObjToken SelectPipeline(EFilterType type) +{ + switch (type) + { + case EFilterType::Blend: + return s_AlphaPipeline; + case EFilterType::Add: + return s_AddPipeline; + case EFilterType::Multiply: + return s_MultPipeline; + default: + return {}; + } +} + CScanLinesFilter::CScanLinesFilter(EFilterType type, bool even) : m_even(even) { CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); - m_dataBind = TMultiBlendShader::BuildShaderDataBinding(ctx, type, *this); + boo::ObjToken vbo = m_even ? + g_Renderer->GetScanLinesEvenVBO().get() : g_Renderer->GetScanLinesOddVBO().get(); + boo::ObjToken bufs[] = {m_uniBuf.get()}; + boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; + m_dataBind = ctx.newShaderDataBinding(SelectPipeline(type), vbo, nullptr, nullptr, + 1, bufs, stages, nullptr, nullptr, 0, nullptr, nullptr, nullptr); return true; } BooTrace); } @@ -23,6 +65,4 @@ void CScanLinesFilter::draw(const zeus::CColor& color) CGraphics::DrawArray(0, 670); } -URDE_SPECIALIZE_MULTI_BLEND_SHADER(CScanLinesFilter) - } diff --git a/Runtime/Graphics/Shaders/CScanLinesFilter.hpp b/Runtime/Graphics/Shaders/CScanLinesFilter.hpp index dc1a7c6d5..40a013cbc 100644 --- a/Runtime/Graphics/Shaders/CScanLinesFilter.hpp +++ b/Runtime/Graphics/Shaders/CScanLinesFilter.hpp @@ -1,7 +1,6 @@ #ifndef __URDE_CSCANLINESFILTER_HPP__ #define __URDE_CSCANLINESFILTER_HPP__ -#include "TMultiBlendShader.hpp" #include "zeus/CMatrix4f.hpp" #include "zeus/CColor.hpp" #include "zeus/CRectangle.hpp" @@ -12,11 +11,6 @@ namespace urde class CScanLinesFilter { - friend struct CScanLinesFilterGLDataBindingFactory; - friend struct CScanLinesFilterVulkanDataBindingFactory; - friend struct CScanLinesFilterMetalDataBindingFactory; - friend struct CScanLinesFilterD3DDataBindingFactory; - struct Uniform { zeus::CColor color; @@ -27,12 +21,11 @@ class CScanLinesFilter bool m_even; public: + static void Initialize(); + static void Shutdown(); CScanLinesFilter(EFilterType type, bool even); void draw(const zeus::CColor& color); void DrawFilter(EFilterShape, const zeus::CColor& color, float) { draw(color); } - - using _CLS = CScanLinesFilter; -#include "TMultiBlendShaderDecl.hpp" }; class CScanLinesFilterEven : public CScanLinesFilter diff --git a/Runtime/Graphics/Shaders/CScanLinesFilterGLSL.cpp b/Runtime/Graphics/Shaders/CScanLinesFilterGLSL.cpp deleted file mode 100644 index 531eef997..000000000 --- a/Runtime/Graphics/Shaders/CScanLinesFilterGLSL.cpp +++ /dev/null @@ -1,163 +0,0 @@ -#include "CScanLinesFilter.hpp" -#include "TMultiBlendShader.hpp" -#include "GameGlobalObjects.hpp" -#include "Graphics/CBooRenderer.hpp" - -namespace urde -{ - -static const char* VS = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"layout(location=0) in vec4 posIn;\n" -"\n" -"UBINDING0 uniform ScanLinesUniform\n" -"{\n" -" vec4 color;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -"};\n" -"\n" -"SBINDING(0) out VertToFrag vtf;\n" -"void main()\n" -"{\n" -" vtf.color = color;\n" -" gl_Position = vec4(posIn.xyz, 1.0);\n" -"}\n"; - -static const char* FS = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -"};\n" -"\n" -"SBINDING(0) in VertToFrag vtf;\n" -"layout(location=0) out vec4 colorOut;\n" -"void main()\n" -"{\n" -" colorOut = vtf.color;\n" -"}\n"; - -URDE_DECL_SPECIALIZE_MULTI_BLEND_SHADER(CScanLinesFilter) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_AlphaPipeline; -static boo::ObjToken s_AddPipeline; -static boo::ObjToken s_MultPipeline; - -static boo::ObjToken SelectPipeline(EFilterType type) -{ - switch (type) - { - case EFilterType::Blend: - return s_AlphaPipeline; - case EFilterType::Add: - return s_AddPipeline; - case EFilterType::Multiply: - return s_MultPipeline; - default: - return {}; - } -} - -struct CScanLinesFilterGLDataBindingFactory : TMultiBlendShader::IDataBindingFactory -{ - boo::ObjToken BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - EFilterType type, CScanLinesFilter& filter) - { - boo::GLDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken vbo = filter.m_even ? - g_Renderer->GetScanLinesEvenVBO().get() : g_Renderer->GetScanLinesOddVBO().get(); - const boo::VertexElementDescriptor VtxVmt[] = - { - {vbo, nullptr, boo::VertexSemantic::Position4} - }; - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; - return cctx.newShaderDataBinding(SelectPipeline(type), - ctx.newVertexFormat(1, VtxVmt), vbo, nullptr, nullptr, - 1, bufs, stages, nullptr, nullptr, 0, nullptr, nullptr, nullptr); - } -}; - -#if BOO_HAS_VULKAN -struct CScanLinesFilterVulkanDataBindingFactory : TMultiBlendShader::IDataBindingFactory -{ - boo::ObjToken - BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - EFilterType type, CScanLinesFilter& filter) - { - boo::VulkanDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken vbo = filter.m_even ? - g_Renderer->GetScanLinesEvenVBO().get() : g_Renderer->GetScanLinesOddVBO().get(); - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - return cctx.newShaderDataBinding(SelectPipeline(type), s_VtxFmt, - vbo, nullptr, nullptr, 1, bufs, - nullptr, nullptr, nullptr, 0, nullptr, nullptr, nullptr); - } -}; -#endif - -TMultiBlendShader::IDataBindingFactory* -CScanLinesFilter::Initialize(boo::GLDataFactory::Context& ctx) -{ - const char* uniNames[] = {"ScanLinesUniform"}; - s_AlphaPipeline = ctx.newShaderPipeline(VS, FS, 0, nullptr, 1, uniNames, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_AddPipeline = ctx.newShaderPipeline(VS, FS, 0, nullptr, 1, uniNames, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_MultPipeline = ctx.newShaderPipeline(VS, FS, 0, nullptr, 1, uniNames, boo::BlendFactor::Zero, - boo::BlendFactor::SrcColor, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - return new CScanLinesFilterGLDataBindingFactory; -} - -template <> -void CScanLinesFilter::Shutdown() -{ - s_AlphaPipeline.reset(); - s_AddPipeline.reset(); - s_MultPipeline.reset(); -} - -#if BOO_HAS_VULKAN -TMultiBlendShader::IDataBindingFactory* -CScanLinesFilter::Initialize(boo::VulkanDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4} - }; - s_VtxFmt = ctx.newVertexFormat(1, VtxVmt); - s_AlphaPipeline = ctx.newShaderPipeline(VS, FS, s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_AddPipeline = ctx.newShaderPipeline(VS, FS, s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_MultPipeline = ctx.newShaderPipeline(VS, FS, s_VtxFmt, boo::BlendFactor::Zero, - boo::BlendFactor::SrcColor, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - return new CScanLinesFilterVulkanDataBindingFactory; -} - -template <> -void CScanLinesFilter::Shutdown() -{ - s_VtxFmt.reset(); - s_AlphaPipeline.reset(); - s_AddPipeline.reset(); - s_MultPipeline.reset(); -} -#endif - -} diff --git a/Runtime/Graphics/Shaders/CScanLinesFilterHLSL.cpp b/Runtime/Graphics/Shaders/CScanLinesFilterHLSL.cpp deleted file mode 100644 index c586de3e2..000000000 --- a/Runtime/Graphics/Shaders/CScanLinesFilterHLSL.cpp +++ /dev/null @@ -1,118 +0,0 @@ -#include "CScanLinesFilter.hpp" -#include "TMultiBlendShader.hpp" -#include "Graphics/CTexture.hpp" -#include "GameGlobalObjects.hpp" -#include "Graphics/CBooRenderer.hpp" - -namespace urde -{ - -static const char* VS = -"struct VertData\n" -"{\n" -" float4 posIn : POSITION;\n" -"};\n" -"\n" -"cbuffer ScanLinesUniform : register(b0)\n" -"{\n" -" float4 color;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float4 color : COLOR;\n" -"};\n" -"\n" -"VertToFrag main(in VertData v)\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.color = color;\n" -" vtf.position = float4(v.posIn.xyz, 1.0);\n" -" return vtf;\n" -"}\n"; - -static const char* FS = -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float4 color : COLOR;\n" -"};\n" -"\n" -"float4 main(in VertToFrag vtf) : SV_Target0\n" -"{\n" -" return vtf.color;\n" -"}\n"; - -URDE_DECL_SPECIALIZE_MULTI_BLEND_SHADER(CScanLinesFilter) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_AlphaPipeline; -static boo::ObjToken s_AddPipeline; -static boo::ObjToken s_MultPipeline; - -static boo::ObjToken SelectPipeline(EFilterType type) -{ - switch (type) - { - case EFilterType::Blend: - return s_AlphaPipeline; - case EFilterType::Add: - return s_AddPipeline; - case EFilterType::Multiply: - return s_MultPipeline; - default: - return nullptr; - } -} - -struct CScanLinesFilterD3DDataBindingFactory : TMultiBlendShader::IDataBindingFactory -{ - boo::ObjToken - BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - EFilterType type, CScanLinesFilter& filter) - { - boo::D3DDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken vbo = filter.m_even ? - g_Renderer->GetScanLinesEvenVBO().get() : g_Renderer->GetScanLinesOddVBO().get(); - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - return cctx.newShaderDataBinding(SelectPipeline(type), s_VtxFmt, - vbo, nullptr, nullptr, 1, bufs, - nullptr, nullptr, nullptr, 0, nullptr, nullptr, nullptr); - } -}; - -TMultiBlendShader::IDataBindingFactory* -CScanLinesFilter::Initialize(boo::D3DDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4} - }; - s_VtxFmt = ctx.newVertexFormat(1, VtxVmt); - s_AlphaPipeline = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, nullptr, - s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_AddPipeline = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, nullptr, - s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_MultPipeline = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, nullptr, - s_VtxFmt, boo::BlendFactor::Zero, - boo::BlendFactor::SrcColor, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - return new CScanLinesFilterD3DDataBindingFactory; -} - -template <> -void CScanLinesFilter::Shutdown() -{ - s_VtxFmt.reset(); - s_AlphaPipeline.reset(); - s_AddPipeline.reset(); - s_MultPipeline.reset(); -} - -} diff --git a/Runtime/Graphics/Shaders/CScanLinesFilterMetal.cpp b/Runtime/Graphics/Shaders/CScanLinesFilterMetal.cpp deleted file mode 100644 index c0acfbe6a..000000000 --- a/Runtime/Graphics/Shaders/CScanLinesFilterMetal.cpp +++ /dev/null @@ -1,120 +0,0 @@ -#include "CScanLinesFilter.hpp" -#include "TMultiBlendShader.hpp" -#include "GameGlobalObjects.hpp" -#include "Graphics/CBooRenderer.hpp" - -namespace urde -{ - -static const char* VS = -"#include \n" -"using namespace metal;\n" -"struct VertData\n" -"{\n" -" float4 posIn [[ attribute(0) ]];\n" -"};\n" -"\n" -"struct ScanLinesUniform\n" -"{\n" -" float4 color;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float4 color;\n" -"};\n" -"\n" -"vertex VertToFrag vmain(VertData v [[ stage_in ]], constant ScanLinesUniform& cqu [[ buffer(2) ]])\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.color = cqu.color;\n" -" vtf.position = float4(v.posIn.xyz, 1.0);\n" -" return vtf;\n" -"}\n"; - -static const char* FS = -"#include \n" -"using namespace metal;\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float4 color;\n" -"};\n" -"\n" -"fragment float4 fmain(VertToFrag vtf [[ stage_in ]])\n" -"{\n" -" return vtf.color;\n" -"}\n"; - -URDE_DECL_SPECIALIZE_MULTI_BLEND_SHADER(CScanLinesFilter) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_AlphaPipeline; -static boo::ObjToken s_AddPipeline; -static boo::ObjToken s_MultPipeline; - -static boo::ObjToken SelectPipeline(EFilterType type) -{ - switch (type) - { - case EFilterType::Blend: - return s_AlphaPipeline; - case EFilterType::Add: - return s_AddPipeline; - case EFilterType::Multiply: - return s_MultPipeline; - default: - return {}; - } -} - -struct CScanLinesFilterMetalDataBindingFactory : TMultiBlendShader::IDataBindingFactory -{ - boo::ObjToken BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - EFilterType type, CScanLinesFilter& filter) - { - boo::MetalDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken vbo = filter.m_even ? - g_Renderer->GetScanLinesEvenVBO().get() : g_Renderer->GetScanLinesOddVBO().get(); - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - return cctx.newShaderDataBinding(SelectPipeline(type), s_VtxFmt, - vbo, nullptr, nullptr, 1, bufs, - nullptr, nullptr, nullptr, 0, nullptr, nullptr, nullptr); - } -}; - -TMultiBlendShader::IDataBindingFactory* -CScanLinesFilter::Initialize(boo::MetalDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4} - }; - s_VtxFmt = ctx.newVertexFormat(1, VtxVmt); - s_AlphaPipeline = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, - s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_AddPipeline = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, - s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_MultPipeline = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, - s_VtxFmt, boo::BlendFactor::Zero, - boo::BlendFactor::SrcColor, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - return new CScanLinesFilterMetalDataBindingFactory; -} - -template <> -void CScanLinesFilter::Shutdown() -{ - s_VtxFmt.reset(); - s_AlphaPipeline.reset(); - s_AddPipeline.reset(); - s_MultPipeline.reset(); -} - -} diff --git a/Runtime/Graphics/Shaders/CSpaceWarpFilter.cpp b/Runtime/Graphics/Shaders/CSpaceWarpFilter.cpp index d2ffccd6f..abceddde7 100644 --- a/Runtime/Graphics/Shaders/CSpaceWarpFilter.cpp +++ b/Runtime/Graphics/Shaders/CSpaceWarpFilter.cpp @@ -1,12 +1,25 @@ #include "CSpaceWarpFilter.hpp" #include "Graphics/CGraphics.hpp" #include "Graphics/CBooRenderer.hpp" +#include "hecl/Pipeline.hpp" #define WARP_RAMP_RES 32 namespace urde { +static boo::ObjToken s_Pipeline; + +void CSpaceWarpFilter::Initialize() +{ + s_Pipeline = hecl::conv->convert(Shader_CSpaceWarpFilter{}); +} + +void CSpaceWarpFilter::Shutdown() +{ + s_Pipeline.reset(); +} + void CSpaceWarpFilter::GenerateWarpRampTex(boo::IGraphicsDataFactory::Context& ctx) { u8 data[WARP_RAMP_RES+1][WARP_RAMP_RES+1][4] = {}; @@ -49,7 +62,11 @@ CSpaceWarpFilter::CSpaceWarpFilter() }; m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts, 32, 4); m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); - m_dataBind = TShader::BuildShaderDataBinding(ctx, *this); + boo::ObjToken bufs[] = {m_uniBuf.get()}; + boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; + boo::ObjToken texs[] = {CGraphics::g_SpareTexture.get(), m_warpTex.get()}; + m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, + 1, bufs, stages, nullptr, nullptr, 2, texs, nullptr, nullptr); return true; } BooTrace); } @@ -153,6 +170,4 @@ void CSpaceWarpFilter::draw(const zeus::CVector3f& pt) CGraphics::DrawArray(0, 4); } -URDE_SPECIALIZE_SHADER(CSpaceWarpFilter) - } diff --git a/Runtime/Graphics/Shaders/CSpaceWarpFilter.hpp b/Runtime/Graphics/Shaders/CSpaceWarpFilter.hpp index 0336f40ce..3dab376cf 100644 --- a/Runtime/Graphics/Shaders/CSpaceWarpFilter.hpp +++ b/Runtime/Graphics/Shaders/CSpaceWarpFilter.hpp @@ -1,7 +1,8 @@ #ifndef __URDE_CSPACEWARPFILTER_HPP__ #define __URDE_CSPACEWARPFILTER_HPP__ -#include "TShader.hpp" +#include "boo/graphicsdev/IGraphicsDataFactory.hpp" +#include "RetroTypes.hpp" #include "zeus/CMatrix4f.hpp" #include "zeus/CColor.hpp" @@ -10,11 +11,6 @@ namespace urde class CSpaceWarpFilter { - friend struct CSpaceWarpFilterGLDataBindingFactory; - friend struct CSpaceWarpFilterVulkanDataBindingFactory; - friend struct CSpaceWarpFilterMetalDataBindingFactory; - friend struct CSpaceWarpFilterD3DDataBindingFactory; - struct Uniform { zeus::CMatrix4f m_matrix; @@ -32,12 +28,11 @@ class CSpaceWarpFilter void GenerateWarpRampTex(boo::IGraphicsDataFactory::Context& ctx); public: + static void Initialize(); + static void Shutdown(); CSpaceWarpFilter(); void setStrength(float strength) { m_strength = strength; } void draw(const zeus::CVector3f& pt); - - using _CLS = CSpaceWarpFilter; -#include "TShaderDecl.hpp" }; } diff --git a/Runtime/Graphics/Shaders/CSpaceWarpFilterGLSL.cpp b/Runtime/Graphics/Shaders/CSpaceWarpFilterGLSL.cpp deleted file mode 100644 index 3ddf7b98a..000000000 --- a/Runtime/Graphics/Shaders/CSpaceWarpFilterGLSL.cpp +++ /dev/null @@ -1,138 +0,0 @@ -#include "CSpaceWarpFilter.hpp" - -namespace urde -{ - -static const char* VS = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"layout(location=0) in vec4 posIn;\n" -"layout(location=1) in vec4 uvIn;\n" -"\n" -"UBINDING0 uniform SpaceWarpUniform\n" -"{\n" -" mat4 mainMtx;\n" -" mat4 indMtx;\n" -" vec4 strength;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" vec2 sceneUv;\n" -" vec2 indUv;\n" -" vec2 strength;\n" -"};\n" -"\n" -"SBINDING(0) out VertToFrag vtf;\n" -"void main()\n" -"{\n" -" gl_Position = mainMtx * vec4(posIn.xy, 0.0, 1.0);\n" -" vtf.sceneUv = gl_Position.xy * vec2(0.5) + vec2(0.5);\n" -" vtf.indUv = (mat3(indMtx) * vec3(uvIn.xy, 1.0)).xy;\n" -" vtf.strength = strength.xy;\n" -"}\n"; - -static const char* FS = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"struct VertToFrag\n" -"{\n" -" vec2 sceneUv;\n" -" vec2 indUv;\n" -" vec2 strength;\n" -"};\n" -"\n" -"SBINDING(0) in VertToFrag vtf;\n" -"layout(location=0) out vec4 colorOut;\n" -"TBINDING0 uniform sampler2D sceneTex;\n" -"TBINDING1 uniform sampler2D indTex;\n" -"void main()\n" -"{\n" -" vec2 indUv = texture(indTex, vtf.indUv).xy * vec2(2.0) - vec2(1.0 - 1.0 / 256.0);\n" -" colorOut = vec4(texture(sceneTex, vtf.sceneUv + indUv * vtf.strength.xy).rgb, 1.0);\n" -"}\n"; - -URDE_DECL_SPECIALIZE_SHADER(CSpaceWarpFilter) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_Pipeline; - -struct CSpaceWarpFilterGLDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CSpaceWarpFilter& filter) - { - boo::GLDataFactory::Context& cctx = static_cast(ctx); - - const boo::VertexElementDescriptor VtxVmt[] = - { - {filter.m_vbo.get(), nullptr, boo::VertexSemantic::Position4}, - {filter.m_vbo.get(), nullptr, boo::VertexSemantic::UV4} - }; - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; - boo::ObjToken texs[] = {CGraphics::g_SpareTexture.get(), filter.m_warpTex.get()}; - return cctx.newShaderDataBinding(s_Pipeline, - ctx.newVertexFormat(2, VtxVmt), filter.m_vbo.get(), nullptr, nullptr, - 1, bufs, stages, nullptr, nullptr, 2, texs, nullptr, nullptr); - } -}; - -#if BOO_HAS_VULKAN -struct CSpaceWarpFilterVulkanDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken - BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CSpaceWarpFilter& filter) - { - boo::VulkanDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - boo::ObjToken texs[] = {CGraphics::g_SpareTexture.get(), filter.m_warpTex.get()}; - return cctx.newShaderDataBinding(s_Pipeline, s_VtxFmt, - filter.m_vbo.get(), nullptr, nullptr, 1, bufs, - nullptr, nullptr, nullptr, 2, texs, nullptr, nullptr); - } -}; -#endif - -TShader::IDataBindingFactory* CSpaceWarpFilter::Initialize(boo::GLDataFactory::Context& ctx) -{ - const char* texNames[] = {"sceneTex", "indTex"}; - const char* uniNames[] = {"SpaceWarpUniform"}; - s_Pipeline = ctx.newShaderPipeline(VS, FS, 2, texNames, 1, uniNames, boo::BlendFactor::One, - boo::BlendFactor::Zero, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - return new CSpaceWarpFilterGLDataBindingFactory; -} - -template <> -void CSpaceWarpFilter::Shutdown() -{ - s_Pipeline.reset(); -} - -#if BOO_HAS_VULKAN -TShader::IDataBindingFactory* CSpaceWarpFilter::Initialize(boo::VulkanDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::UV4} - }; - s_VtxFmt = ctx.newVertexFormat(2, VtxVmt); - s_Pipeline = ctx.newShaderPipeline(VS, FS, s_VtxFmt, boo::BlendFactor::One, - boo::BlendFactor::Zero, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - return new CSpaceWarpFilterVulkanDataBindingFactory; -} - -template <> -void CSpaceWarpFilter::Shutdown() -{ - s_VtxFmt.reset(); - s_Pipeline.reset(); -} -#endif - -} diff --git a/Runtime/Graphics/Shaders/CSpaceWarpFilterHLSL.cpp b/Runtime/Graphics/Shaders/CSpaceWarpFilterHLSL.cpp deleted file mode 100644 index b1bbc1641..000000000 --- a/Runtime/Graphics/Shaders/CSpaceWarpFilterHLSL.cpp +++ /dev/null @@ -1,99 +0,0 @@ -#include "CSpaceWarpFilter.hpp" - -namespace urde -{ - -static const char* VS = -"struct VertData\n" -"{\n" -" float4 posIn : POSITION;\n" -" float4 uvIn : UV;\n" -"};\n" -"cbuffer SpaceWarpUniform : register(b0)\n" -"{\n" -" float4x4 mainMtx;\n" -" float4x4 indMtx;\n" -" float4 strength;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float2 sceneUv : SCENEUV;\n" -" float2 indUv : INDV;\n" -" float2 strength : STRENGTH;\n" -"};\n" -"\n" -"VertToFrag main(in VertData v)\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.position = mul(mainMtx, float4(v.posIn.xy, 0.0, 1.0));\n" -" vtf.sceneUv = vtf.position.xy * float2(0.5, 0.5) + float2(0.5, 0.5);\n" -" vtf.sceneUv.y = 1.0 - vtf.sceneUv.y;\n" -" vtf.indUv = mul(float3x3(indMtx[0].xyz, indMtx[1].xyz, indMtx[2].xyz), float3(v.uvIn.xy, 1.0)).xy;\n" -" vtf.indUv.y = 1.0 - vtf.indUv.y;\n" -" vtf.strength = strength.xy;\n" -" return vtf;\n" -"}\n"; - -static const char* FS = -"Texture2D sceneTex : register(t0);\n" -"Texture2D indTex : register(t1);\n" -"SamplerState samp : register(s0);\n" -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float2 sceneUv : SCENEUV;\n" -" float2 indUv : INDV;\n" -" float2 strength : STRENGTH;\n" -"};\n" -"\n" -"float4 main(in VertToFrag vtf) : SV_Target0\n" -"{\n" -" float2 indUv = indTex.Sample(samp, vtf.indUv).xy * float2(2.0, 2.0) - float2(1.0 - 1.0 / 256.0, 1.0 - 1.0 / 256.0);\n" -" return float4(sceneTex.Sample(samp, vtf.sceneUv + indUv * vtf.strength.xy).rgb, 1.0);\n" -"}\n"; - -URDE_DECL_SPECIALIZE_SHADER(CSpaceWarpFilter) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_Pipeline; - -struct CSpaceWarpFilterD3DDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken - BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CSpaceWarpFilter& filter) - { - boo::D3DDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - boo::ObjToken texs[] = {CGraphics::g_SpareTexture.get(), filter.m_warpTex.get()}; - return cctx.newShaderDataBinding(s_Pipeline, s_VtxFmt, - filter.m_vbo.get(), nullptr, nullptr, 1, bufs, - nullptr, nullptr, nullptr, 2, texs, nullptr, nullptr); - } -}; - -TShader::IDataBindingFactory* CSpaceWarpFilter::Initialize(boo::D3DDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::UV4} - }; - s_VtxFmt = ctx.newVertexFormat(2, VtxVmt); - s_Pipeline = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, nullptr, - s_VtxFmt, boo::BlendFactor::One, - boo::BlendFactor::Zero, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - return new CSpaceWarpFilterD3DDataBindingFactory; -} - -template <> -void CSpaceWarpFilter::Shutdown() -{ - s_VtxFmt.reset(); - s_Pipeline.reset(); -} -} diff --git a/Runtime/Graphics/Shaders/CSpaceWarpFilterMetal.cpp b/Runtime/Graphics/Shaders/CSpaceWarpFilterMetal.cpp deleted file mode 100644 index 27ae6ece4..000000000 --- a/Runtime/Graphics/Shaders/CSpaceWarpFilterMetal.cpp +++ /dev/null @@ -1,103 +0,0 @@ -#include "CSpaceWarpFilter.hpp" - -namespace urde -{ - -static const char* VS = -"#include \n" -"using namespace metal;\n" -"struct VertData\n" -"{\n" -" float4 posIn [[ attribute(0) ]];\n" -" float4 uvIn [[ attribute(1) ]];\n" -"};\n" -"struct SpaceWarpUniform\n" -"{\n" -" float4x4 mainMtx;\n" -" float4x4 indMtx;\n" -" float4 strength;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float2 sceneUv;\n" -" float2 indUv;\n" -" float2 strength;\n" -"};\n" -"\n" -"vertex VertToFrag vmain(VertData v [[ stage_in ]], constant SpaceWarpUniform& swu [[ buffer(2) ]])\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.position = swu.mainMtx * float4(v.posIn.xy, 0.0, 1.0);\n" -" vtf.sceneUv = vtf.position.xy * float2(0.5) + float2(0.5);\n" -" vtf.sceneUv.y = 1.0 - vtf.sceneUv.y;\n" -" vtf.indUv = (float3x3(swu.indMtx[0].xyz, swu.indMtx[1].xyz, swu.indMtx[2].xyz) * float3(v.uvIn.xy, 1.0)).xy;\n" -" vtf.indUv.y = 1.0 - vtf.indUv.y;\n" -" vtf.strength = swu.strength.xy;\n" -" return vtf;\n" -"}\n"; - -static const char* FS = -"#include \n" -"using namespace metal;\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float2 sceneUv;\n" -" float2 indUv;\n" -" float2 strength;\n" -"};\n" -"\n" -"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n" -" sampler samp [[ sampler(0) ]],\n" -" texture2d sceneTex [[ texture(0) ]],\n" -" texture2d indTex [[ texture(1) ]])\n" -"{\n" -" float2 indUv = indTex.sample(samp, vtf.indUv).xy * float2(2.0) - float2(1.0 - 1.0 / 256.0);\n" -" return float4(sceneTex.sample(samp, vtf.sceneUv + indUv * vtf.strength.xy).rgb, 1.0);\n" -"}\n"; - -URDE_DECL_SPECIALIZE_SHADER(CSpaceWarpFilter) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_Pipeline; - -struct CSpaceWarpFilterMetalDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CSpaceWarpFilter& filter) - { - boo::MetalDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - boo::ObjToken texs[] = {CGraphics::g_SpareTexture.get(), filter.m_warpTex}; - return cctx.newShaderDataBinding(s_Pipeline, s_VtxFmt, - filter.m_vbo.get(), nullptr, nullptr, 1, bufs, - nullptr, nullptr, nullptr, 2, texs, nullptr, nullptr); - } -}; - -TShader::IDataBindingFactory* CSpaceWarpFilter::Initialize(boo::MetalDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::UV4} - }; - s_VtxFmt = ctx.newVertexFormat(2, VtxVmt); - s_Pipeline = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, - s_VtxFmt, boo::BlendFactor::One, - boo::BlendFactor::Zero, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - return new CSpaceWarpFilterMetalDataBindingFactory; -} - -template <> -void CSpaceWarpFilter::Shutdown() -{ - s_VtxFmt.reset(); - s_Pipeline.reset(); -} - -} diff --git a/Runtime/Graphics/Shaders/CTextSupportShader.cpp b/Runtime/Graphics/Shaders/CTextSupportShader.cpp index 4577c6f8c..c078ebab8 100644 --- a/Runtime/Graphics/Shaders/CTextSupportShader.cpp +++ b/Runtime/Graphics/Shaders/CTextSupportShader.cpp @@ -1,15 +1,14 @@ #include "CTextSupportShader.hpp" #include "GuiSys/CRasterFont.hpp" +#include "hecl/Pipeline.hpp" namespace urde { -boo::ObjToken CTextSupportShader::s_TextVtxFmt; boo::ObjToken CTextSupportShader::s_TextAlphaPipeline; boo::ObjToken CTextSupportShader::s_TextAddPipeline; boo::ObjToken CTextSupportShader::s_TextAddOverdrawPipeline; -boo::ObjToken CTextSupportShader::s_ImageVtxFmt; boo::ObjToken CTextSupportShader::s_ImageAlphaPipeline; boo::ObjToken CTextSupportShader::s_ImageAddPipeline; boo::ObjToken CTextSupportShader::s_ImageAddOverdrawPipeline; @@ -18,6 +17,30 @@ hecl::VertexBufferPool CTextSupportShader hecl::VertexBufferPool CTextSupportShader::s_ImgInsts; hecl::UniformBufferPool CTextSupportShader::s_Uniforms; +void CTextSupportShader::Initialize() +{ + s_TextAlphaPipeline = hecl::conv->convert(Shader_CTextSupportShaderAlpha{}); + s_TextAddPipeline = hecl::conv->convert(Shader_CTextSupportShaderAdd{}); + s_TextAddOverdrawPipeline = hecl::conv->convert(Shader_CTextSupportShaderAddOverdraw{}); + s_ImageAlphaPipeline = hecl::conv->convert(Shader_CTextSupportShaderImageAlpha{}); + s_ImageAddPipeline = hecl::conv->convert(Shader_CTextSupportShaderImageAdd{}); + s_ImageAddOverdrawPipeline = hecl::conv->convert(Shader_CTextSupportShaderImageAddOverdraw{}); +} + +void CTextSupportShader::Shutdown() +{ + s_TextAlphaPipeline.reset(); + s_TextAddPipeline.reset(); + s_TextAddOverdrawPipeline.reset(); + s_ImageAlphaPipeline.reset(); + s_ImageAddPipeline.reset(); + s_ImageAddOverdrawPipeline.reset(); + + s_CharInsts.doDestroy(); + s_ImgInsts.doDestroy(); + s_Uniforms.doDestroy(); +} + void CTextSupportShader::CharacterInstance::SetMetrics(const CGlyph& glyph, const zeus::CVector2i& offset) { @@ -61,22 +84,4 @@ void CTextSupportShader::ImageInstance::SetMetrics(const CFontImageDef& imgDef, m_uv[3].assign(0.5f + cropPad.x, 0.5f - cropPad.y); } -void CTextSupportShader::Shutdown() -{ - s_TextVtxFmt.reset(); - s_TextAlphaPipeline.reset(); - s_TextAddPipeline.reset(); - s_TextAddOverdrawPipeline.reset(); - s_ImageVtxFmt.reset(); - s_ImageAlphaPipeline.reset(); - s_ImageAddPipeline.reset(); - s_ImageAddOverdrawPipeline.reset(); - - s_CharInsts.doDestroy(); - s_ImgInsts.doDestroy(); - s_Uniforms.doDestroy(); -} - -URDE_SPECIALIZE_MULTI_BLEND_SHADER(CTextSupportShader) - } diff --git a/Runtime/Graphics/Shaders/CTextSupportShader.hpp b/Runtime/Graphics/Shaders/CTextSupportShader.hpp index ef0dbf673..57c814684 100644 --- a/Runtime/Graphics/Shaders/CTextSupportShader.hpp +++ b/Runtime/Graphics/Shaders/CTextSupportShader.hpp @@ -1,10 +1,10 @@ #ifndef __URDE_CTEXTSUPPORTSHADER_HPP__ #define __URDE_CTEXTSUPPORTSHADER_HPP__ -#include "TMultiBlendShader.hpp" #include "GuiSys/CGuiWidget.hpp" #include "hecl/VertexBufferPool.hpp" #include "hecl/UniformBufferPool.hpp" +#include "zeus/CVector2i.hpp" namespace urde { @@ -14,18 +14,12 @@ class CFontImageDef; class CTextSupportShader { - friend struct CTextSupportShaderGLDataBindingFactory; - friend struct CTextSupportShaderVulkanDataBindingFactory; - friend struct CTextSupportShaderMetalDataBindingFactory; - friend struct CTextSupportShaderD3DDataBindingFactory; friend class CTextRenderBuffer; - static boo::ObjToken s_TextVtxFmt; static boo::ObjToken s_TextAlphaPipeline; static boo::ObjToken s_TextAddPipeline; static boo::ObjToken s_TextAddOverdrawPipeline; - static boo::ObjToken s_ImageVtxFmt; static boo::ObjToken s_ImageAlphaPipeline; static boo::ObjToken s_ImageAddPipeline; static boo::ObjToken s_ImageAddOverdrawPipeline; @@ -59,8 +53,6 @@ class CTextSupportShader static hecl::UniformBufferPool s_Uniforms; public: - using _CLS = CTextSupportShader; -#include "TMultiBlendShaderDecl.hpp" static boo::ObjToken SelectTextPipeline(CGuiWidget::EGuiModelDrawFlags df) { @@ -111,6 +103,7 @@ public: s_Uniforms.updateBuffers(); } + static void Initialize(); static void Shutdown(); }; diff --git a/Runtime/Graphics/Shaders/CTextSupportShaderGLSL.cpp b/Runtime/Graphics/Shaders/CTextSupportShaderGLSL.cpp deleted file mode 100644 index 2ad023a91..000000000 --- a/Runtime/Graphics/Shaders/CTextSupportShaderGLSL.cpp +++ /dev/null @@ -1,218 +0,0 @@ -#include "CTextSupportShader.hpp" -#include "GuiSys/CTextRenderBuffer.hpp" -#include "TMultiBlendShader.hpp" -#include "Graphics/CTexture.hpp" - -namespace urde -{ - -static const char* TextVS = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"layout(location=0) in vec4 posIn[4];\n" -"layout(location=4) in vec4 uvIn[4];\n" -"layout(location=8) in vec4 fontColorIn;\n" -"layout(location=9) in vec4 outlineColorIn;\n" -"layout(location=10) in vec4 mulColorIn;\n" -"\n" -"UBINDING0 uniform TextSupportUniform\n" -"{\n" -" mat4 mtx;\n" -" vec4 color;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" vec4 fontColor;\n" -" vec4 outlineColor;\n" -" vec4 mulColor;\n" -" vec3 uv;\n" -"};\n" -"\n" -"SBINDING(0) out VertToFrag vtf;\n" -"void main()\n" -"{\n" -" vec3 pos = posIn[gl_VertexID].xyz;\n" -" vtf.uv = uvIn[gl_VertexID].xyz;\n" -" vtf.fontColor = color * fontColorIn;\n" -" vtf.outlineColor = color * outlineColorIn;\n" -" vtf.mulColor = mulColorIn;\n" -" gl_Position = mtx * vec4(pos, 1.0);\n" -"}\n"; - -static const char* TextFS = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"struct VertToFrag\n" -"{\n" -" vec4 fontColor;\n" -" vec4 outlineColor;\n" -" vec4 mulColor;\n" -" vec3 uv;\n" -"};\n" -"\n" -"SBINDING(0) in VertToFrag vtf;\n" -"layout(location=0) out vec4 colorOut;\n" -"TBINDING0 uniform sampler2DArray tex;\n" -"void main()\n" -"{\n" -" vec4 texel = texture(tex, vtf.uv);\n" -" colorOut = (vtf.fontColor * texel.r + vtf.outlineColor * texel.g) * vtf.mulColor;\n" -"}\n"; - -static const char* ImgVS = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"layout(location=0) in vec3 posIn[4];\n" -"layout(location=4) in vec2 uvIn[4];\n" -"layout(location=8) in vec4 colorIn;\n" -"\n" -"UBINDING0 uniform TextSupportUniform\n" -"{\n" -" mat4 mtx;\n" -" vec4 color;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -" vec2 uv;\n" -"};\n" -"\n" -"SBINDING(0) out VertToFrag vtf;\n" -"void main()\n" -"{\n" -" vec3 pos = posIn[gl_VertexID].xyz;\n" -" vtf.uv = uvIn[gl_VertexID];\n" -" vtf.color = color * colorIn;\n" -" gl_Position = mtx * vec4(pos, 1.0);\n" -"}\n"; - -static const char* ImgFS = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -" vec2 uv;\n" -"};\n" -"\n" -"SBINDING(0) in VertToFrag vtf;\n" -"layout(location=0) out vec4 colorOut;\n" -"TBINDING0 uniform sampler2D tex;\n" -"void main()\n" -"{\n" -" vec4 texel = texture(tex, vtf.uv);\n" -" colorOut = vtf.color * texel;\n" -"}\n"; - -TMultiBlendShader::IDataBindingFactory* -CTextSupportShader::Initialize(boo::GLDataFactory::Context& ctx) -{ - const char* texNames[] = {"tex"}; - const char* uniNames[] = {"TextSupportUniform"}; - - s_TextAlphaPipeline = ctx.newShaderPipeline(TextVS, TextFS, 1, texNames, 1, uniNames, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::LEqual, false, true, false, boo::CullMode::None); - s_TextAddPipeline = ctx.newShaderPipeline(TextVS, TextFS, 1, texNames, 1, uniNames, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::LEqual, false, true, false, boo::CullMode::None); - s_TextAddOverdrawPipeline = ctx.newShaderPipeline(TextVS, TextFS, 1, texNames, 1, uniNames, boo::BlendFactor::One, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::LEqual, false, true, false, boo::CullMode::None); - - s_ImageAlphaPipeline = ctx.newShaderPipeline(ImgVS, ImgFS, 1, texNames, 1, uniNames, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::LEqual, false, true, false, boo::CullMode::None); - s_ImageAddPipeline = ctx.newShaderPipeline(ImgVS, ImgFS, 1, texNames, 1, uniNames, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::LEqual, false, true, false, boo::CullMode::None); - s_ImageAddOverdrawPipeline = ctx.newShaderPipeline(ImgVS, ImgFS, 1, texNames, 1, uniNames, boo::BlendFactor::One, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::LEqual, false, true, false, boo::CullMode::None); - - return nullptr; -} - -template <> -void CTextSupportShader::Shutdown() -{ - s_TextAlphaPipeline.reset(); - s_TextAddPipeline.reset(); - s_TextAddOverdrawPipeline.reset(); - s_ImageAlphaPipeline.reset(); - s_ImageAddPipeline.reset(); - s_ImageAddOverdrawPipeline.reset(); -} - -#if BOO_HAS_VULKAN -TMultiBlendShader::IDataBindingFactory* -CTextSupportShader::Initialize(boo::VulkanDataFactory::Context& ctx) -{ - boo::VertexElementDescriptor TextVtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 0}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 1}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 2}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 3}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 0}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 1}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 2}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 3}, - {nullptr, nullptr, boo::VertexSemantic::Color | boo::VertexSemantic::Instanced, 0}, - {nullptr, nullptr, boo::VertexSemantic::Color | boo::VertexSemantic::Instanced, 1}, - {nullptr, nullptr, boo::VertexSemantic::Color | boo::VertexSemantic::Instanced, 2}, - }; - s_TextVtxFmt = ctx.newVertexFormat(11, TextVtxVmt); - s_TextAlphaPipeline = ctx.newShaderPipeline(TextVS, TextFS, s_TextVtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::LEqual, false, true, false, boo::CullMode::None); - s_TextAddPipeline = ctx.newShaderPipeline(TextVS, TextFS, s_TextVtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::LEqual, false, true, false, boo::CullMode::None); - s_TextAddOverdrawPipeline = ctx.newShaderPipeline(TextVS, TextFS, s_TextVtxFmt, boo::BlendFactor::One, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::LEqual, false, true, false, boo::CullMode::None); - - boo::VertexElementDescriptor ImageVtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 0}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 1}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 2}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 3}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 0}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 1}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 2}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 3}, - {nullptr, nullptr, boo::VertexSemantic::Color | boo::VertexSemantic::Instanced, 0}, - }; - s_ImageVtxFmt = ctx.newVertexFormat(9, ImageVtxVmt); - s_ImageAlphaPipeline = ctx.newShaderPipeline(ImgVS, ImgFS, s_ImageVtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::LEqual, false, true, false, boo::CullMode::None); - s_ImageAddPipeline = ctx.newShaderPipeline(ImgVS, ImgFS, s_ImageVtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::LEqual, false, true, false, boo::CullMode::None); - s_ImageAddOverdrawPipeline = ctx.newShaderPipeline(ImgVS, ImgFS, s_ImageVtxFmt, boo::BlendFactor::One, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::LEqual, false, true, false, boo::CullMode::None); - - return nullptr; -} - -template <> -void CTextSupportShader::Shutdown() -{ - s_TextVtxFmt.reset(); - s_TextAlphaPipeline.reset(); - s_TextAddPipeline.reset(); - s_TextAddOverdrawPipeline.reset(); - s_ImageVtxFmt.reset(); - s_ImageAlphaPipeline.reset(); - s_ImageAddPipeline.reset(); - s_ImageAddOverdrawPipeline.reset(); -} -#endif - -} diff --git a/Runtime/Graphics/Shaders/CTextSupportShaderHLSL.cpp b/Runtime/Graphics/Shaders/CTextSupportShaderHLSL.cpp deleted file mode 100644 index 7752f946e..000000000 --- a/Runtime/Graphics/Shaders/CTextSupportShaderHLSL.cpp +++ /dev/null @@ -1,183 +0,0 @@ -#include "CTextSupportShader.hpp" -#include "GuiSys/CTextRenderBuffer.hpp" -#include "TMultiBlendShader.hpp" -#include "Graphics/CTexture.hpp" - -namespace urde -{ - -static const char* TextVS = -"struct InstData\n" -"{\n" -" float4 posIn[4] : POSITION;\n" -" float4 uvIn[4] : UV;\n" -" float4 fontColorIn : COLOR0;\n" -" float4 outlineColorIn : COLOR1;\n" -" float4 mulColorIn : COLOR2;\n" -"};\n" -"\n" -"cbuffer TextSupportUniform : register(b0)\n" -"{\n" -" float4x4 mtx;\n" -" float4 color;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 pos : SV_Position;\n" -" float4 fontColor : COLOR0;\n" -" float4 outlineColor : COLOR1;\n" -" float4 mulColor : COLOR2;\n" -" float3 uv : UV;\n" -"};\n" -"\n" -"VertToFrag main(in InstData inst, in uint vertId : SV_VertexID)\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.fontColor = color * inst.fontColorIn;\n" -" vtf.outlineColor = color * inst.outlineColorIn;\n" -" vtf.mulColor = inst.mulColorIn;\n" -" vtf.uv = inst.uvIn[vertId].xyz;\n" -" vtf.pos = mul(mtx, float4(inst.posIn[vertId].xyz, 1.0));\n" -" return vtf;\n" -"}\n"; - -static const char* TextFS = -"struct VertToFrag\n" -"{\n" -" float4 pos : SV_Position;\n" -" float4 fontColor : COLOR0;\n" -" float4 outlineColor : COLOR1;\n" -" float4 mulColor : COLOR2;\n" -" float3 uv : UV;\n" -"};\n" -"\n" -"Texture2DArray tex : register(t0);\n" -"SamplerState samp : register(s3);\n" -"\n" -"float4 main(in VertToFrag vtf) : SV_Target0\n" -"{\n" -" float4 texel = tex.Sample(samp, vtf.uv.xyz);\n" -" return (vtf.fontColor * texel.r + vtf.outlineColor * texel.g) * vtf.mulColor;\n" -"}\n"; - -static const char* ImgVS = -"struct InstData\n" -"{\n" -" float4 posIn[4] : POSITION;\n" -" float4 uvIn[4] : UV;\n" -" float4 colorIn : COLOR;\n" -"};\n" -"\n" -"cbuffer TextSupportUniform : register(b0)\n" -"{\n" -" float4x4 mtx;\n" -" float4 color;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 pos : SV_Position;\n" -" float4 color : COLOR;\n" -" float2 uv : UV;\n" -"};\n" -"\n" -"VertToFrag main(in InstData inst, in uint vertId : SV_VertexID)\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.color = color * inst.colorIn;\n" -" vtf.uv = inst.uvIn[vertId].xy;\n" -" vtf.pos = mul(mtx, float4(inst.posIn[vertId].xyz, 1.0));\n" -" return vtf;\n" -"}\n"; - -static const char* ImgFS = -"struct VertToFrag\n" -"{\n" -" float4 pos : SV_Position;\n" -" float4 color : COLOR;\n" -" float2 uv : UV;\n" -"};\n" -"\n" -"Texture2D tex : register(t0);\n" -"SamplerState samp : register(s3);\n" -"\n" -"float4 main(in VertToFrag vtf) : SV_Target0\n" -"{\n" -" float4 texel = tex.Sample(samp, vtf.uv);\n" -" return vtf.color * texel;\n" -"}\n"; - -TMultiBlendShader::IDataBindingFactory* -CTextSupportShader::Initialize(boo::D3DDataFactory::Context& ctx) -{ - boo::VertexElementDescriptor TextVtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 0}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 1}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 2}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 3}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 0}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 1}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 2}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 3}, - {nullptr, nullptr, boo::VertexSemantic::Color | boo::VertexSemantic::Instanced, 0}, - {nullptr, nullptr, boo::VertexSemantic::Color | boo::VertexSemantic::Instanced, 1}, - {nullptr, nullptr, boo::VertexSemantic::Color | boo::VertexSemantic::Instanced, 2}, - }; - s_TextVtxFmt = ctx.newVertexFormat(11, TextVtxVmt); - s_TextAlphaPipeline = ctx.newShaderPipeline(TextVS, TextFS, nullptr, nullptr, nullptr, - s_TextVtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::LEqual, false, true, false, boo::CullMode::None); - s_TextAddPipeline = ctx.newShaderPipeline(TextVS, TextFS, nullptr, nullptr, nullptr, - s_TextVtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::LEqual, false, true, false, boo::CullMode::None); - s_TextAddOverdrawPipeline = ctx.newShaderPipeline(TextVS, TextFS, nullptr, nullptr, nullptr, - s_TextVtxFmt, boo::BlendFactor::One, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::LEqual, false, true, false, boo::CullMode::None); - - boo::VertexElementDescriptor ImageVtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 0}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 1}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 2}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 3}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 0}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 1}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 2}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 3}, - {nullptr, nullptr, boo::VertexSemantic::Color | boo::VertexSemantic::Instanced, 0}, - }; - s_ImageVtxFmt = ctx.newVertexFormat(9, ImageVtxVmt); - s_ImageAlphaPipeline = ctx.newShaderPipeline(ImgVS, ImgFS, nullptr, nullptr, nullptr, - s_ImageVtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::LEqual, false, true, false, boo::CullMode::None); - s_ImageAddPipeline = ctx.newShaderPipeline(ImgVS, ImgFS, nullptr, nullptr, nullptr, - s_ImageVtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::LEqual, false, true, false, boo::CullMode::None); - s_ImageAddOverdrawPipeline = ctx.newShaderPipeline(ImgVS, ImgFS, nullptr, nullptr, nullptr, - s_ImageVtxFmt, boo::BlendFactor::One, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::LEqual, false, true, false, boo::CullMode::None); - - return nullptr; -} - -template <> -void CTextSupportShader::Shutdown() -{ - s_TextVtxFmt.reset(); - s_TextAlphaPipeline.reset(); - s_TextAddPipeline.reset(); - s_TextAddOverdrawPipeline.reset(); - s_ImageVtxFmt.reset(); - s_ImageAlphaPipeline.reset(); - s_ImageAddPipeline.reset(); - s_ImageAddOverdrawPipeline.reset(); -} -} diff --git a/Runtime/Graphics/Shaders/CTextSupportShaderMetal.cpp b/Runtime/Graphics/Shaders/CTextSupportShaderMetal.cpp deleted file mode 100644 index a159b1fa9..000000000 --- a/Runtime/Graphics/Shaders/CTextSupportShaderMetal.cpp +++ /dev/null @@ -1,190 +0,0 @@ -#include "CTextSupportShader.hpp" -#include "GuiSys/CTextRenderBuffer.hpp" -#include "TMultiBlendShader.hpp" -#include "Graphics/CTexture.hpp" - -namespace urde -{ - -static const char* TextVS = -"#include \n" -"using namespace metal;\n" -"struct InstData\n" -"{\n" -" float4 posIn[4];\n" -" float4 uvIn[4];\n" -" float4 fontColorIn;\n" -" float4 outlineColorIn;\n" -" float4 mulColorIn;\n" -"};\n" -"\n" -"struct TextSupportUniform\n" -"{\n" -" float4x4 mtx;\n" -" float4 color;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 pos [[ position ]];\n" -" float4 fontColor;\n" -" float4 outlineColor;\n" -" float4 mulColor;\n" -" float3 uv;\n" -"};\n" -"\n" -"vertex VertToFrag vmain(constant InstData* instArr [[ buffer(1) ]],\n" -" uint vertId [[ vertex_id ]], uint instId [[ instance_id ]],\n" -" constant TextSupportUniform& uData [[ buffer(2) ]])\n" -"{\n" -" VertToFrag vtf;\n" -" constant InstData& inst = instArr[instId];\n" -" vtf.fontColor = inst.fontColorIn * uData.color;\n" -" vtf.outlineColor = inst.outlineColorIn * uData.color;\n" -" vtf.mulColor = inst.mulColorIn;\n" -" vtf.uv = inst.uvIn[vertId].xyz;\n" -" vtf.pos = uData.mtx * float4(inst.posIn[vertId].xyz, 1.0);\n" -" return vtf;\n" -"}\n"; - -static const char* TextFS = -"#include \n" -"using namespace metal;\n" -"struct VertToFrag\n" -"{\n" -" float4 pos [[ position ]];\n" -" float4 fontColor;\n" -" float4 outlineColor;\n" -" float4 mulColor;\n" -" float3 uv;\n" -"};\n" -"\n" -"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n" -" sampler clampSamp [[ sampler(3) ]],\n" -" texture2d_array tex [[ texture(0) ]])\n" -"{\n" -" float4 texel = tex.sample(clampSamp, vtf.uv.xy, vtf.uv.z);\n" -" return (vtf.fontColor * texel.r + vtf.outlineColor * texel.g) * vtf.mulColor;\n" -"}\n"; - -static const char* ImgVS = -"#include \n" -"using namespace metal;\n" -"struct InstData\n" -"{\n" -" float4 posIn[4];\n" -" float4 uvIn[4];\n" -" float4 colorIn;\n" -"};\n" -"\n" -"struct TextSupportUniform\n" -"{\n" -" float4x4 mtx;\n" -" float4 color;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 pos [[ position ]];\n" -" float4 color;\n" -" float2 uv;\n" -"};\n" -"\n" -"vertex VertToFrag vmain(constant InstData* instArr [[ buffer(1) ]],\n" -" uint vertId [[ vertex_id ]], uint instId [[ instance_id ]],\n" -" constant TextSupportUniform& uData [[ buffer(2) ]])\n" -"{\n" -" VertToFrag vtf;\n" -" constant InstData& inst = instArr[instId];\n" -" vtf.color = uData.color * inst.colorIn;\n" -" vtf.uv = inst.uvIn[vertId].xy;\n" -" vtf.pos = uData.mtx * float4(inst.posIn[vertId].xyz, 1.0);\n" -" return vtf;\n" -"}\n"; - -static const char* ImgFS = -"#include \n" -"using namespace metal;\n" -"struct VertToFrag\n" -"{\n" -" float4 pos [[ position ]];\n" -" float4 color;\n" -" float2 uv;\n" -"};\n" -"\n" -"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n" -" sampler clampSamp [[ sampler(3) ]],\n" -" texture2d tex [[ texture(0) ]])\n" -"{\n" -" float4 texel = tex.sample(clampSamp, vtf.uv);\n" -" return vtf.color * texel;\n" -"}\n"; - -TMultiBlendShader::IDataBindingFactory* -CTextSupportShader::Initialize(boo::MetalDataFactory::Context& ctx) -{ - boo::VertexElementDescriptor TextVtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 0}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 1}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 2}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 3}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 0}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 1}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 2}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 3}, - {nullptr, nullptr, boo::VertexSemantic::Color | boo::VertexSemantic::Instanced, 0}, - {nullptr, nullptr, boo::VertexSemantic::Color | boo::VertexSemantic::Instanced, 1}, - {nullptr, nullptr, boo::VertexSemantic::Color | boo::VertexSemantic::Instanced, 2}, - }; - s_TextVtxFmt = ctx.newVertexFormat(11, TextVtxVmt); - s_TextAlphaPipeline = ctx.newShaderPipeline(TextVS, TextFS, nullptr, nullptr, s_TextVtxFmt, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::LEqual, false, true, false, boo::CullMode::None); - s_TextAddPipeline = ctx.newShaderPipeline(TextVS, TextFS, nullptr, nullptr, s_TextVtxFmt, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::LEqual, false, true, false, boo::CullMode::None); - s_TextAddOverdrawPipeline = ctx.newShaderPipeline(TextVS, TextFS, nullptr, nullptr, s_TextVtxFmt, - boo::BlendFactor::One, boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::LEqual, false, true, false, boo::CullMode::None); - - boo::VertexElementDescriptor ImageVtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 0}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 1}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 2}, - {nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 3}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 0}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 1}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 2}, - {nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 3}, - {nullptr, nullptr, boo::VertexSemantic::Color | boo::VertexSemantic::Instanced, 0}, - }; - s_ImageVtxFmt = ctx.newVertexFormat(9, ImageVtxVmt); - s_ImageAlphaPipeline = ctx.newShaderPipeline(ImgVS, ImgFS, nullptr, nullptr, s_ImageVtxFmt, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::LEqual, false, true, false, boo::CullMode::None); - s_ImageAddPipeline = ctx.newShaderPipeline(ImgVS, ImgFS, nullptr, nullptr, s_ImageVtxFmt, - boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::LEqual, false, true, false, boo::CullMode::None); - s_ImageAddOverdrawPipeline = ctx.newShaderPipeline(ImgVS, ImgFS, nullptr, nullptr, s_ImageVtxFmt, - boo::BlendFactor::One, boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::LEqual, false, true, false, boo::CullMode::None); - - return nullptr; -} - -template <> -void CTextSupportShader::Shutdown() -{ - s_TextVtxFmt.reset(); - s_TextAlphaPipeline.reset(); - s_TextAddPipeline.reset(); - s_TextAddOverdrawPipeline.reset(); - s_ImageVtxFmt.reset(); - s_ImageAlphaPipeline.reset(); - s_ImageAddPipeline.reset(); - s_ImageAddOverdrawPipeline.reset(); -} - -} diff --git a/Runtime/Graphics/Shaders/CTexturedQuadFilter.cpp b/Runtime/Graphics/Shaders/CTexturedQuadFilter.cpp index 4407f9332..f4b37aaae 100644 --- a/Runtime/Graphics/Shaders/CTexturedQuadFilter.cpp +++ b/Runtime/Graphics/Shaders/CTexturedQuadFilter.cpp @@ -1,9 +1,162 @@ #include "CTexturedQuadFilter.hpp" #include "Graphics/CTexture.hpp" +#include "hecl/Pipeline.hpp" namespace urde { +static boo::ObjToken s_AlphaPipeline; +static boo::ObjToken s_AlphaGEqualPipeline; +static boo::ObjToken s_AlphaLEqualPipeline; +static boo::ObjToken s_AddPipeline; +static boo::ObjToken s_AddGEqualPipeline; +static boo::ObjToken s_AddLEqualPipeline; +static boo::ObjToken s_SubtractPipeline; +static boo::ObjToken s_SubtractGEqualPipeline; +static boo::ObjToken s_SubtractLEqualPipeline; +static boo::ObjToken s_MultPipeline; +static boo::ObjToken s_MultGEqualPipeline; +static boo::ObjToken s_MultLEqualPipeline; +static boo::ObjToken s_InvDstMultPipeline; +static boo::ObjToken s_InvDstMultGEqualPipeline; +static boo::ObjToken s_InvDstMultLEqualPipeline; + +static boo::ObjToken s_AAlphaPipeline; +static boo::ObjToken s_AAddPipeline; +static boo::ObjToken s_ASubtractPipeline; +static boo::ObjToken s_AMultPipeline; +static boo::ObjToken s_AInvDstMultPipeline; + +void CTexturedQuadFilter::Initialize() +{ + s_AlphaPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAlpha{}); + s_AlphaGEqualPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAlphaGEqual{}); + s_AlphaLEqualPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAlphaLEqual{}); + s_AddPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAdd{}); + s_AddGEqualPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAddGEqual{}); + s_AddLEqualPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAddLEqual{}); + s_SubtractPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterSubtract{}); + s_SubtractGEqualPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterSubtractGEqual{}); + s_SubtractLEqualPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterSubtractLEqual{}); + s_MultPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterMult{}); + s_MultGEqualPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterMultGEqual{}); + s_MultLEqualPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterMultLEqual{}); + s_InvDstMultPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterInvDstMult{}); + s_InvDstMultGEqualPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterInvDstMultGEqual{}); + s_InvDstMultLEqualPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterInvDstMultLEqual{}); +} + +void CTexturedQuadFilter::Shutdown() +{ + s_AlphaPipeline.reset(); + s_AlphaGEqualPipeline.reset(); + s_AlphaLEqualPipeline.reset(); + s_AddPipeline.reset(); + s_AddGEqualPipeline.reset(); + s_AddLEqualPipeline.reset(); + s_SubtractPipeline.reset(); + s_SubtractGEqualPipeline.reset(); + s_SubtractLEqualPipeline.reset(); + s_MultPipeline.reset(); + s_MultGEqualPipeline.reset(); + s_MultLEqualPipeline.reset(); + s_InvDstMultPipeline.reset(); + s_InvDstMultGEqualPipeline.reset(); + s_InvDstMultLEqualPipeline.reset(); +} + +void CTexturedQuadFilterAlpha::Initialize() +{ + s_AAlphaPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAlphaTexAlpha{}); + s_AAddPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAlphaTexAdd{}); + s_ASubtractPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAlphaTexSubtract{}); + s_AMultPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAlphaTexMult{}); + s_AInvDstMultPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAlphaTexInvDstMult{}); +} + +void CTexturedQuadFilterAlpha::Shutdown() +{ + s_AAlphaPipeline.reset(); + s_AAddPipeline.reset(); + s_ASubtractPipeline.reset(); + s_AMultPipeline.reset(); + s_AInvDstMultPipeline.reset(); +} + +static boo::ObjToken SelectPipeline(EFilterType type, CTexturedQuadFilter::ZTest zTest) +{ + switch (zTest) + { + case CTexturedQuadFilter::ZTest::GEqual: + switch (type) + { + case EFilterType::Blend: + return s_AlphaGEqualPipeline; + case EFilterType::Add: + return s_AddGEqualPipeline; + case EFilterType::Subtract: + return s_SubtractGEqualPipeline; + case EFilterType::Multiply: + return s_MultGEqualPipeline; + default: + break; + } + case CTexturedQuadFilter::ZTest::LEqual: + switch (type) + { + case EFilterType::Blend: + return s_AlphaLEqualPipeline; + case EFilterType::Add: + return s_AddLEqualPipeline; + case EFilterType::Subtract: + return s_SubtractLEqualPipeline; + case EFilterType::Multiply: + return s_MultLEqualPipeline; + case EFilterType::InvDstMultiply: + return s_InvDstMultLEqualPipeline; + default: + break; + } + default: + break; + } + + switch (type) + { + case EFilterType::Blend: + return s_AlphaPipeline; + case EFilterType::Add: + return s_AddPipeline; + case EFilterType::Subtract: + return s_SubtractPipeline; + case EFilterType::Multiply: + return s_MultPipeline; + case EFilterType::InvDstMultiply: + return s_InvDstMultPipeline; + default: + return {}; + } +} + +static boo::ObjToken SelectAlphaPipeline(EFilterType type) +{ + switch (type) + { + case EFilterType::Blend: + return s_AAlphaPipeline; + case EFilterType::Add: + return s_AAddPipeline; + case EFilterType::Subtract: + return s_ASubtractPipeline; + case EFilterType::Multiply: + return s_AMultPipeline; + case EFilterType::InvDstMultiply: + return s_AInvDstMultPipeline; + default: + return {}; + } +} + CTexturedQuadFilter::CTexturedQuadFilter(const boo::ObjToken& tex) : m_booTex(tex) { @@ -19,7 +172,11 @@ CTexturedQuadFilter::CTexturedQuadFilter(EFilterType type, const boo::ObjToken::BuildShaderDataBinding(ctx, type, *this); + boo::ObjToken bufs[] = {m_uniBuf.get()}; + boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; + boo::ObjToken texs[] = {m_booTex.get()}; + m_dataBind = ctx.newShaderDataBinding(SelectPipeline(type, m_zTest), m_vbo.get(), nullptr, nullptr, + 1, bufs, stages, nullptr, nullptr, 1, texs, nullptr, nullptr); return true; } BooTrace); } @@ -152,8 +309,6 @@ void CTexturedQuadFilter::DrawFilter(EFilterShape shape, const zeus::CColor& col const zeus::CRectangle CTexturedQuadFilter::DefaultRect = {0.f, 0.f, 1.f, 1.f}; -URDE_SPECIALIZE_MULTI_BLEND_SHADER(CTexturedQuadFilter) - CTexturedQuadFilterAlpha::CTexturedQuadFilterAlpha(EFilterType type, const boo::ObjToken& tex) : CTexturedQuadFilter(tex) { @@ -161,7 +316,11 @@ CTexturedQuadFilterAlpha::CTexturedQuadFilterAlpha(EFilterType type, const boo:: { m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, 32, 4); m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); - m_dataBind = TMultiBlendShader::BuildShaderDataBinding(ctx, type, *this); + boo::ObjToken bufs[] = {m_uniBuf.get()}; + boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; + boo::ObjToken texs[] = {m_booTex.get()}; + m_dataBind = ctx.newShaderDataBinding(SelectAlphaPipeline(type), m_vbo.get(), nullptr, nullptr, + 1, bufs, stages, nullptr, nullptr, 1, texs, nullptr, nullptr); return true; } BooTrace); } @@ -173,6 +332,4 @@ CTexturedQuadFilterAlpha::CTexturedQuadFilterAlpha(EFilterType type, m_tex = tex; } -URDE_SPECIALIZE_MULTI_BLEND_SHADER(CTexturedQuadFilterAlpha) - } diff --git a/Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp b/Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp index 0a3567cc9..23040b968 100644 --- a/Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp +++ b/Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp @@ -1,7 +1,6 @@ #ifndef __URDE_CTEXTUREDQUADFILTER_HPP__ #define __URDE_CTEXTUREDQUADFILTER_HPP__ -#include "TMultiBlendShader.hpp" #include "zeus/CMatrix4f.hpp" #include "zeus/CColor.hpp" #include "zeus/CRectangle.hpp" @@ -13,15 +12,6 @@ namespace urde class CTexturedQuadFilter { - friend struct CTexturedQuadFilterGLDataBindingFactory; - friend struct CTexturedQuadFilterAlphaGLDataBindingFactory; - friend struct CTexturedQuadFilterVulkanDataBindingFactory; - friend struct CTexturedQuadFilterAlphaVulkanDataBindingFactory; - friend struct CTexturedQuadFilterMetalDataBindingFactory; - friend struct CTexturedQuadFilterAlphaMetalDataBindingFactory; - friend struct CTexturedQuadFilterD3DDataBindingFactory; - friend struct CTexturedQuadFilterAlphaD3DDataBindingFactory; - public: enum class ZTest { @@ -54,7 +44,8 @@ public: zeus::CVector3f m_pos; zeus::CVector2f m_uv; }; - + static void Initialize(); + static void Shutdown(); static const zeus::CRectangle DefaultRect; CTexturedQuadFilter(EFilterType type, TLockedToken tex, ZTest zTest = ZTest::None); CTexturedQuadFilter(EFilterType type, const boo::ObjToken& tex, ZTest zTest = ZTest::None); @@ -68,23 +59,15 @@ public: void DrawFilter(EFilterShape shape, const zeus::CColor& color, float t); const TLockedToken& GetTex() const { return m_tex; } const boo::ObjToken& GetBooTex() const { return m_booTex; } - - using _CLS = CTexturedQuadFilter; -#include "TMultiBlendShaderDecl.hpp" }; class CTexturedQuadFilterAlpha : public CTexturedQuadFilter { - friend struct CTexturedQuadFilterAlphaGLDataBindingFactory; - friend struct CTexturedQuadFilterAlphaVulkanDataBindingFactory; - friend struct CTexturedQuadFilterAlphaMetalDataBindingFactory; - friend struct CTexturedQuadFilterAlphaD3DDataBindingFactory; - public: + static void Initialize(); + static void Shutdown(); CTexturedQuadFilterAlpha(EFilterType type, TLockedToken tex); CTexturedQuadFilterAlpha(EFilterType type, const boo::ObjToken& tex); - using _CLS = CTexturedQuadFilterAlpha; -#include "TMultiBlendShaderDecl.hpp" }; } diff --git a/Runtime/Graphics/Shaders/CTexturedQuadFilterGLSL.cpp b/Runtime/Graphics/Shaders/CTexturedQuadFilterGLSL.cpp deleted file mode 100644 index ea3de1503..000000000 --- a/Runtime/Graphics/Shaders/CTexturedQuadFilterGLSL.cpp +++ /dev/null @@ -1,649 +0,0 @@ -#include "CTexturedQuadFilter.hpp" -#include "TMultiBlendShader.hpp" -#include "Graphics/CTexture.hpp" - -namespace urde -{ - -static const char* VSFlip = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"layout(location=0) in vec4 posIn;\n" -"layout(location=1) in vec4 uvIn;\n" -"\n" -"UBINDING0 uniform TexuredQuadUniform\n" -"{\n" -" mat4 mtx;\n" -" vec4 color;\n" -" float lod;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -" vec2 uv;\n" -" float lod;\n" -"};\n" -"\n" -"SBINDING(0) out VertToFrag vtf;\n" -"void main()\n" -"{\n" -" vtf.color = color;\n" -" vtf.uv = uvIn.xy;\n" -" vtf.uv.y = 1.0 - vtf.uv.y;\n" -" vtf.lod = lod;\n" -" gl_Position = mtx * vec4(posIn.xyz, 1.0);\n" -" gl_Position = FLIPFROMGL(gl_Position);\n" -"}\n"; - -static const char* VSNoFlip = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"layout(location=0) in vec4 posIn;\n" -"layout(location=1) in vec4 uvIn;\n" -"\n" -"UBINDING0 uniform TexuredQuadUniform\n" -"{\n" -" mat4 mtx;\n" -" vec4 color;\n" -" float lod;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -" vec2 uv;\n" -" float lod;\n" -"};\n" -"\n" -"SBINDING(0) out VertToFrag vtf;\n" -"void main()\n" -"{\n" -" vtf.color = color;\n" -" vtf.uv = uvIn.xy;\n" -" vtf.lod = lod;\n" -" gl_Position = mtx * vec4(posIn.xyz, 1.0);\n" -" gl_Position = FLIPFROMGL(gl_Position);\n" -"}\n"; - -static const char* FS = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -" vec2 uv;\n" -" float lod;\n" -"};\n" -"\n" -"SBINDING(0) in VertToFrag vtf;\n" -"layout(location=0) out vec4 colorOut;\n" -"TBINDING0 uniform sampler2D tex;\n" -"void main()\n" -"{\n" -" colorOut = vtf.color * vec4(texture(tex, vtf.uv, vtf.lod).rgb, 1.0);\n" -"}\n"; - -static const char* FSAlpha = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -" vec2 uv;\n" -" float lod;\n" -"};\n" -"\n" -"SBINDING(0) in VertToFrag vtf;\n" -"layout(location=0) out vec4 colorOut;\n" -"TBINDING0 uniform sampler2D tex;\n" -"void main()\n" -"{\n" -" colorOut = vtf.color * texture(tex, vtf.uv, vtf.lod);\n" -"}\n"; - -URDE_DECL_SPECIALIZE_MULTI_BLEND_SHADER(CTexturedQuadFilter) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_AlphaPipeline; -static boo::ObjToken s_AlphaGEqualPipeline; -static boo::ObjToken s_AlphaLEqualPipeline; -static boo::ObjToken s_AddPipeline; -static boo::ObjToken s_AddGEqualPipeline; -static boo::ObjToken s_AddLEqualPipeline; -static boo::ObjToken s_SubtractPipeline; -static boo::ObjToken s_SubtractGEqualPipeline; -static boo::ObjToken s_SubtractLEqualPipeline; -static boo::ObjToken s_MultPipeline; -static boo::ObjToken s_MultGEqualPipeline; -static boo::ObjToken s_MultLEqualPipeline; -static boo::ObjToken s_InvDstMultPipeline; -static boo::ObjToken s_InvDstMultGEqualPipeline; -static boo::ObjToken s_InvDstMultLEqualPipeline; -static boo::ObjToken s_AlphaFlipPipeline; -static boo::ObjToken s_AlphaGEqualFlipPipeline; -static boo::ObjToken s_AlphaLEqualFlipPipeline; -static boo::ObjToken s_AddFlipPipeline; -static boo::ObjToken s_AddGEqualFlipPipeline; -static boo::ObjToken s_AddLEqualFlipPipeline; -static boo::ObjToken s_SubtractFlipPipeline; -static boo::ObjToken s_SubtractGEqualFlipPipeline; -static boo::ObjToken s_SubtractLEqualFlipPipeline; -static boo::ObjToken s_MultFlipPipeline; -static boo::ObjToken s_MultGEqualFlipPipeline; -static boo::ObjToken s_MultLEqualFlipPipeline; -static boo::ObjToken s_InvDstMultFlipPipeline; -static boo::ObjToken s_InvDstMultGEqualFlipPipeline; -static boo::ObjToken s_InvDstMultLEqualFlipPipeline; - -static boo::ObjToken SelectPipeline(EFilterType type, - CTexturedQuadFilter::ZTest zTest, bool flip) -{ - switch (zTest) - { - case CTexturedQuadFilter::ZTest::GEqual: - switch (type) - { - case EFilterType::Blend: - return flip ? s_AlphaGEqualFlipPipeline : s_AlphaGEqualPipeline; - case EFilterType::Add: - return flip ? s_AddGEqualFlipPipeline : s_AddGEqualPipeline; - case EFilterType::Subtract: - return flip ? s_SubtractGEqualFlipPipeline : s_SubtractGEqualPipeline; - case EFilterType::Multiply: - return flip ? s_MultGEqualFlipPipeline : s_MultGEqualPipeline; - default: - break; - } - case CTexturedQuadFilter::ZTest::LEqual: - switch (type) - { - case EFilterType::Blend: - return flip ? s_AlphaLEqualFlipPipeline : s_AlphaLEqualPipeline; - case EFilterType::Add: - return flip ? s_AddLEqualFlipPipeline : s_AddLEqualPipeline; - case EFilterType::Subtract: - return flip ? s_SubtractLEqualFlipPipeline : s_SubtractLEqualPipeline; - case EFilterType::Multiply: - return flip ? s_MultLEqualFlipPipeline : s_MultLEqualPipeline; - case EFilterType::InvDstMultiply: - return flip ? s_InvDstMultLEqualFlipPipeline : s_InvDstMultLEqualPipeline; - default: - break; - } - default: - break; - } - - switch (type) - { - case EFilterType::Blend: - return flip ? s_AlphaFlipPipeline : s_AlphaPipeline; - case EFilterType::Add: - return flip ? s_AddFlipPipeline : s_AddPipeline; - case EFilterType::Subtract: - return flip ? s_SubtractFlipPipeline : s_SubtractPipeline; - case EFilterType::Multiply: - return flip ? s_MultFlipPipeline : s_MultPipeline; - case EFilterType::InvDstMultiply: - return flip ? s_InvDstMultFlipPipeline : s_InvDstMultPipeline; - default: - return {}; - } -} - -static boo::ObjToken s_AVtxFmt; -static boo::ObjToken s_AAlphaPipeline; -static boo::ObjToken s_AAddPipeline; -static boo::ObjToken s_ASubtractPipeline; -static boo::ObjToken s_AMultPipeline; -static boo::ObjToken s_AInvDstMultPipeline; - -static boo::ObjToken SelectAlphaPipeline(EFilterType type) -{ - switch (type) - { - case EFilterType::Blend: - return s_AAlphaPipeline; - case EFilterType::Add: - return s_AAddPipeline; - case EFilterType::Subtract: - return s_ASubtractPipeline; - case EFilterType::Multiply: - return s_AMultPipeline; - case EFilterType::InvDstMultiply: - return s_AInvDstMultPipeline; - default: - return {}; - } -} - -struct CTexturedQuadFilterGLDataBindingFactory : TMultiBlendShader::IDataBindingFactory -{ - boo::ObjToken BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - EFilterType type, CTexturedQuadFilter& filter) - { - boo::GLDataFactory::Context& cctx = static_cast(ctx); - - const boo::VertexElementDescriptor VtxVmt[] = - { - {filter.m_vbo.get(), nullptr, boo::VertexSemantic::Position4}, - {filter.m_vbo.get(), nullptr, boo::VertexSemantic::UV4} - }; - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; - boo::ObjToken texs[] = {filter.m_booTex.get()}; - return cctx.newShaderDataBinding(SelectPipeline(type, filter.m_zTest, - filter.m_booTex->type() == boo::TextureType::Render), - ctx.newVertexFormat(2, VtxVmt), filter.m_vbo.get(), nullptr, nullptr, - 1, bufs, stages, nullptr, nullptr, 1, texs, nullptr, nullptr); - } -}; - -#if BOO_HAS_VULKAN -struct CTexturedQuadFilterVulkanDataBindingFactory : TMultiBlendShader::IDataBindingFactory -{ - boo::ObjToken - BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - EFilterType type, CTexturedQuadFilter& filter) - { - boo::VulkanDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - boo::ObjToken texs[] = {filter.m_booTex.get()}; - return cctx.newShaderDataBinding(SelectPipeline(type, filter.m_zTest, - filter.m_booTex->type() == boo::TextureType::Render), s_VtxFmt, - filter.m_vbo.get(), nullptr, nullptr, 1, bufs, - nullptr, nullptr, nullptr, 1, texs, nullptr, nullptr); - } -}; -#endif - -TMultiBlendShader::IDataBindingFactory* -CTexturedQuadFilter::Initialize(boo::GLDataFactory::Context& ctx) -{ - const char* texNames[] = {"tex"}; - const char* uniNames[] = {"TexuredQuadUniform"}; - s_AlphaPipeline = ctx.newShaderPipeline(VSNoFlip, FS, 1, texNames, 1, uniNames, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_AlphaGEqualPipeline = ctx.newShaderPipeline(VSNoFlip, FS, 1, texNames, 1, uniNames, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::GEqual, true, true, false, boo::CullMode::None); - s_AlphaLEqualPipeline = ctx.newShaderPipeline(VSNoFlip, FS, 1, texNames, 1, uniNames, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::LEqual, true, true, false, boo::CullMode::None); - s_AddPipeline = ctx.newShaderPipeline(VSNoFlip, FS, 1, texNames, 1, uniNames, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_AddGEqualPipeline = ctx.newShaderPipeline(VSNoFlip, FS, 1, texNames, 1, uniNames, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::GEqual, true, true, false, boo::CullMode::None); - s_AddLEqualPipeline = ctx.newShaderPipeline(VSNoFlip, FS, 1, texNames, 1, uniNames, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::LEqual, true, true, false, boo::CullMode::None); - s_SubtractPipeline = ctx.newShaderPipeline(VSNoFlip, FS, 1, texNames, 1, uniNames, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::Subtract, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_SubtractGEqualPipeline = ctx.newShaderPipeline(VSNoFlip, FS, 1, texNames, 1, uniNames, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::Subtract, boo::Primitive::TriStrips, - boo::ZTest::GEqual, true, true, false, boo::CullMode::None); - s_SubtractLEqualPipeline = ctx.newShaderPipeline(VSNoFlip, FS, 1, texNames, 1, uniNames, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::Subtract, boo::Primitive::TriStrips, - boo::ZTest::LEqual, true, true, false, boo::CullMode::None); - s_MultPipeline = ctx.newShaderPipeline(VSNoFlip, FS, 1, texNames, 1, uniNames, boo::BlendFactor::Zero, - boo::BlendFactor::SrcColor, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_MultGEqualPipeline = ctx.newShaderPipeline(VSNoFlip, FS, 1, texNames, 1, uniNames, boo::BlendFactor::Zero, - boo::BlendFactor::SrcColor, boo::Primitive::TriStrips, - boo::ZTest::GEqual, true, true, false, boo::CullMode::None); - s_MultLEqualPipeline = ctx.newShaderPipeline(VSNoFlip, FS, 1, texNames, 1, uniNames, boo::BlendFactor::Zero, - boo::BlendFactor::SrcColor, boo::Primitive::TriStrips, - boo::ZTest::LEqual, true, true, false, boo::CullMode::None); - s_InvDstMultPipeline = ctx.newShaderPipeline(VSNoFlip, FS, 1, texNames, 1, uniNames, boo::BlendFactor::Zero, - boo::BlendFactor::InvSrcColor, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_InvDstMultGEqualPipeline = ctx.newShaderPipeline(VSNoFlip, FS, 1, texNames, 1, uniNames, boo::BlendFactor::Zero, - boo::BlendFactor::InvSrcColor, boo::Primitive::TriStrips, - boo::ZTest::GEqual, true, true, false, boo::CullMode::None); - s_InvDstMultLEqualPipeline = ctx.newShaderPipeline(VSNoFlip, FS, 1, texNames, 1, uniNames, boo::BlendFactor::Zero, - boo::BlendFactor::InvSrcColor, boo::Primitive::TriStrips, - boo::ZTest::LEqual, true, true, false, boo::CullMode::None); - s_AlphaFlipPipeline = ctx.newShaderPipeline(VSFlip, FS, 1, texNames, 1, uniNames, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_AlphaGEqualFlipPipeline = ctx.newShaderPipeline(VSFlip, FS, 1, texNames, 1, uniNames, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::GEqual, true, true, false, boo::CullMode::None); - s_AlphaLEqualFlipPipeline = ctx.newShaderPipeline(VSFlip, FS, 1, texNames, 1, uniNames, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::LEqual, true, true, false, boo::CullMode::None); - s_AddFlipPipeline = ctx.newShaderPipeline(VSFlip, FS, 1, texNames, 1, uniNames, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_AddGEqualFlipPipeline = ctx.newShaderPipeline(VSFlip, FS, 1, texNames, 1, uniNames, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::GEqual, true, true, false, boo::CullMode::None); - s_AddLEqualFlipPipeline = ctx.newShaderPipeline(VSFlip, FS, 1, texNames, 1, uniNames, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::LEqual, true, true, false, boo::CullMode::None); - s_SubtractFlipPipeline = ctx.newShaderPipeline(VSFlip, FS, 1, texNames, 1, uniNames, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::Subtract, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_SubtractGEqualFlipPipeline = ctx.newShaderPipeline(VSFlip, FS, 1, texNames, 1, uniNames, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::Subtract, boo::Primitive::TriStrips, - boo::ZTest::GEqual, true, true, false, boo::CullMode::None); - s_SubtractLEqualFlipPipeline = ctx.newShaderPipeline(VSFlip, FS, 1, texNames, 1, uniNames, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::Subtract, boo::Primitive::TriStrips, - boo::ZTest::LEqual, true, true, false, boo::CullMode::None); - s_MultFlipPipeline = ctx.newShaderPipeline(VSFlip, FS, 1, texNames, 1, uniNames, boo::BlendFactor::Zero, - boo::BlendFactor::SrcColor, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_MultGEqualFlipPipeline = ctx.newShaderPipeline(VSFlip, FS, 1, texNames, 1, uniNames, boo::BlendFactor::Zero, - boo::BlendFactor::SrcColor, boo::Primitive::TriStrips, - boo::ZTest::GEqual, true, true, false, boo::CullMode::None); - s_MultLEqualFlipPipeline = ctx.newShaderPipeline(VSFlip, FS, 1, texNames, 1, uniNames, boo::BlendFactor::Zero, - boo::BlendFactor::SrcColor, boo::Primitive::TriStrips, - boo::ZTest::LEqual, true, true, false, boo::CullMode::None); - s_InvDstMultFlipPipeline = ctx.newShaderPipeline(VSFlip, FS, 1, texNames, 1, uniNames, boo::BlendFactor::Zero, - boo::BlendFactor::InvSrcColor, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_InvDstMultGEqualFlipPipeline = ctx.newShaderPipeline(VSFlip, FS, 1, texNames, 1, uniNames, boo::BlendFactor::Zero, - boo::BlendFactor::InvSrcColor, boo::Primitive::TriStrips, - boo::ZTest::GEqual, true, true, false, boo::CullMode::None); - s_InvDstMultLEqualFlipPipeline = ctx.newShaderPipeline(VSFlip, FS, 1, texNames, 1, uniNames, boo::BlendFactor::Zero, - boo::BlendFactor::InvSrcColor, boo::Primitive::TriStrips, - boo::ZTest::LEqual, true, true, false, boo::CullMode::None); - return new CTexturedQuadFilterGLDataBindingFactory; -} - -template <> -void CTexturedQuadFilter::Shutdown() -{ - s_AlphaPipeline.reset(); - s_AlphaGEqualPipeline.reset(); - s_AlphaLEqualPipeline.reset(); - s_AddPipeline.reset(); - s_AddGEqualPipeline.reset(); - s_AddLEqualPipeline.reset(); - s_SubtractPipeline.reset(); - s_SubtractGEqualPipeline.reset(); - s_SubtractLEqualPipeline.reset(); - s_MultPipeline.reset(); - s_MultGEqualPipeline.reset(); - s_MultLEqualPipeline.reset(); - s_InvDstMultPipeline.reset(); - s_InvDstMultGEqualPipeline.reset(); - s_InvDstMultLEqualPipeline.reset(); - s_AlphaFlipPipeline.reset(); - s_AlphaGEqualFlipPipeline.reset(); - s_AlphaLEqualFlipPipeline.reset(); - s_AddFlipPipeline.reset(); - s_AddGEqualFlipPipeline.reset(); - s_AddLEqualFlipPipeline.reset(); - s_SubtractFlipPipeline.reset(); - s_SubtractGEqualFlipPipeline.reset(); - s_SubtractLEqualFlipPipeline.reset(); - s_MultFlipPipeline.reset(); - s_MultGEqualFlipPipeline.reset(); - s_MultLEqualFlipPipeline.reset(); - s_InvDstMultFlipPipeline.reset(); - s_InvDstMultGEqualFlipPipeline.reset(); - s_InvDstMultLEqualFlipPipeline.reset(); -} - -#if BOO_HAS_VULKAN -TMultiBlendShader::IDataBindingFactory* -CTexturedQuadFilter::Initialize(boo::VulkanDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::UV4} - }; - s_VtxFmt = ctx.newVertexFormat(2, VtxVmt); - s_AlphaPipeline = ctx.newShaderPipeline(VSNoFlip, FS, s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_AlphaGEqualPipeline = ctx.newShaderPipeline(VSNoFlip, FS, s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::GEqual, true, true, false, boo::CullMode::None); - s_AlphaLEqualPipeline = ctx.newShaderPipeline(VSNoFlip, FS, s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::LEqual, true, true, false, boo::CullMode::None); - s_AddPipeline = ctx.newShaderPipeline(VSNoFlip, FS, s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_AddGEqualPipeline = ctx.newShaderPipeline(VSNoFlip, FS, s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::GEqual, true, true, false, boo::CullMode::None); - s_AddLEqualPipeline = ctx.newShaderPipeline(VSNoFlip, FS, s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::LEqual, true, true, false, boo::CullMode::None); - s_SubtractPipeline = ctx.newShaderPipeline(VSNoFlip, FS, s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::Subtract, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_SubtractGEqualPipeline = ctx.newShaderPipeline(VSNoFlip, FS, s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::Subtract, boo::Primitive::TriStrips, - boo::ZTest::GEqual, true, true, false, boo::CullMode::None); - s_SubtractLEqualPipeline = ctx.newShaderPipeline(VSNoFlip, FS, s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::Subtract, boo::Primitive::TriStrips, - boo::ZTest::LEqual, true, true, false, boo::CullMode::None); - s_MultPipeline = ctx.newShaderPipeline(VSNoFlip, FS, s_VtxFmt, boo::BlendFactor::Zero, - boo::BlendFactor::SrcColor, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_MultGEqualPipeline = ctx.newShaderPipeline(VSNoFlip, FS, s_VtxFmt, boo::BlendFactor::Zero, - boo::BlendFactor::SrcColor, boo::Primitive::TriStrips, - boo::ZTest::GEqual, true, true, false, boo::CullMode::None); - s_MultLEqualPipeline = ctx.newShaderPipeline(VSNoFlip, FS, s_VtxFmt, boo::BlendFactor::Zero, - boo::BlendFactor::SrcColor, boo::Primitive::TriStrips, - boo::ZTest::LEqual, true, true, false, boo::CullMode::None); - s_InvDstMultPipeline = ctx.newShaderPipeline(VSNoFlip, FS, s_VtxFmt, boo::BlendFactor::Zero, - boo::BlendFactor::InvSrcColor, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_InvDstMultGEqualPipeline = ctx.newShaderPipeline(VSNoFlip, FS, s_VtxFmt, boo::BlendFactor::Zero, - boo::BlendFactor::InvSrcColor, boo::Primitive::TriStrips, - boo::ZTest::GEqual, true, true, false, boo::CullMode::None); - s_InvDstMultLEqualPipeline = ctx.newShaderPipeline(VSNoFlip, FS, s_VtxFmt, boo::BlendFactor::Zero, - boo::BlendFactor::InvSrcColor, boo::Primitive::TriStrips, - boo::ZTest::LEqual, true, true, false, boo::CullMode::None); - s_AlphaFlipPipeline = ctx.newShaderPipeline(VSFlip, FS, s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_AlphaGEqualFlipPipeline = ctx.newShaderPipeline(VSFlip, FS, s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::GEqual, true, true, false, boo::CullMode::None); - s_AlphaLEqualFlipPipeline = ctx.newShaderPipeline(VSFlip, FS, s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::LEqual, true, true, false, boo::CullMode::None); - s_AddFlipPipeline = ctx.newShaderPipeline(VSFlip, FS, s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_AddGEqualFlipPipeline = ctx.newShaderPipeline(VSFlip, FS, s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::GEqual, true, true, false, boo::CullMode::None); - s_AddLEqualFlipPipeline = ctx.newShaderPipeline(VSFlip, FS, s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::LEqual, true, true, false, boo::CullMode::None); - s_SubtractFlipPipeline = ctx.newShaderPipeline(VSNoFlip, FS, s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::Subtract, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_SubtractGEqualFlipPipeline = ctx.newShaderPipeline(VSNoFlip, FS, s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::Subtract, boo::Primitive::TriStrips, - boo::ZTest::GEqual, true, true, false, boo::CullMode::None); - s_SubtractLEqualFlipPipeline = ctx.newShaderPipeline(VSNoFlip, FS, s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::Subtract, boo::Primitive::TriStrips, - boo::ZTest::LEqual, true, true, false, boo::CullMode::None); - s_MultFlipPipeline = ctx.newShaderPipeline(VSFlip, FS, s_VtxFmt, boo::BlendFactor::Zero, - boo::BlendFactor::SrcColor, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_MultGEqualFlipPipeline = ctx.newShaderPipeline(VSFlip, FS, s_VtxFmt, boo::BlendFactor::Zero, - boo::BlendFactor::SrcColor, boo::Primitive::TriStrips, - boo::ZTest::GEqual, true, true, false, boo::CullMode::None); - s_MultLEqualFlipPipeline = ctx.newShaderPipeline(VSFlip, FS, s_VtxFmt, boo::BlendFactor::Zero, - boo::BlendFactor::SrcColor, boo::Primitive::TriStrips, - boo::ZTest::LEqual, true, true, false, boo::CullMode::None); - s_InvDstMultFlipPipeline = ctx.newShaderPipeline(VSFlip, FS, s_VtxFmt, boo::BlendFactor::Zero, - boo::BlendFactor::InvSrcColor, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_InvDstMultGEqualFlipPipeline = ctx.newShaderPipeline(VSFlip, FS, s_VtxFmt, boo::BlendFactor::Zero, - boo::BlendFactor::InvSrcColor, boo::Primitive::TriStrips, - boo::ZTest::GEqual, true, true, false, boo::CullMode::None); - s_InvDstMultLEqualFlipPipeline = ctx.newShaderPipeline(VSFlip, FS, s_VtxFmt, boo::BlendFactor::Zero, - boo::BlendFactor::InvSrcColor, boo::Primitive::TriStrips, - boo::ZTest::LEqual, true, true, false, boo::CullMode::None); - return new CTexturedQuadFilterVulkanDataBindingFactory; -} - -template <> -void CTexturedQuadFilter::Shutdown() -{ - s_VtxFmt.reset(); - s_AlphaPipeline.reset(); - s_AlphaGEqualPipeline.reset(); - s_AlphaLEqualPipeline.reset(); - s_AddPipeline.reset(); - s_AddGEqualPipeline.reset(); - s_AddLEqualPipeline.reset(); - s_SubtractPipeline.reset(); - s_SubtractGEqualPipeline.reset(); - s_SubtractLEqualPipeline.reset(); - s_MultPipeline.reset(); - s_MultGEqualPipeline.reset(); - s_MultLEqualPipeline.reset(); - s_InvDstMultPipeline.reset(); - s_InvDstMultGEqualPipeline.reset(); - s_InvDstMultLEqualPipeline.reset(); - s_AlphaFlipPipeline.reset(); - s_AlphaGEqualFlipPipeline.reset(); - s_AlphaLEqualFlipPipeline.reset(); - s_AddFlipPipeline.reset(); - s_AddGEqualFlipPipeline.reset(); - s_AddLEqualFlipPipeline.reset(); - s_SubtractFlipPipeline.reset(); - s_SubtractGEqualFlipPipeline.reset(); - s_SubtractLEqualFlipPipeline.reset(); - s_MultFlipPipeline.reset(); - s_MultGEqualFlipPipeline.reset(); - s_MultLEqualFlipPipeline.reset(); - s_InvDstMultFlipPipeline.reset(); - s_InvDstMultGEqualFlipPipeline.reset(); - s_InvDstMultLEqualFlipPipeline.reset(); -} -#endif - -URDE_DECL_SPECIALIZE_MULTI_BLEND_SHADER(CTexturedQuadFilterAlpha) - -struct CTexturedQuadFilterAlphaGLDataBindingFactory : TMultiBlendShader::IDataBindingFactory -{ - boo::ObjToken BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - EFilterType type, CTexturedQuadFilterAlpha& filter) - { - boo::GLDataFactory::Context& cctx = static_cast(ctx); - - const boo::VertexElementDescriptor VtxVmt[] = - { - {filter.m_vbo.get(), nullptr, boo::VertexSemantic::Position4}, - {filter.m_vbo.get(), nullptr, boo::VertexSemantic::UV4} - }; - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; - boo::ObjToken texs[] = {filter.m_booTex.get()}; - return cctx.newShaderDataBinding(SelectAlphaPipeline(type), - ctx.newVertexFormat(2, VtxVmt), filter.m_vbo.get(), nullptr, nullptr, - 1, bufs, stages, nullptr, nullptr, 1, texs, nullptr, nullptr); - } -}; - -#if BOO_HAS_VULKAN -struct CTexturedQuadFilterAlphaVulkanDataBindingFactory : TMultiBlendShader::IDataBindingFactory -{ - boo::ObjToken - BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - EFilterType type, CTexturedQuadFilterAlpha& filter) - { - boo::VulkanDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - boo::ObjToken texs[] = {filter.m_booTex.get()}; - return cctx.newShaderDataBinding(SelectAlphaPipeline(type), s_AVtxFmt, - filter.m_vbo.get(), nullptr, nullptr, 1, bufs, - nullptr, nullptr, nullptr, 1, texs, nullptr, nullptr); - } -}; -#endif - -TMultiBlendShader::IDataBindingFactory* -CTexturedQuadFilterAlpha::Initialize(boo::GLDataFactory::Context& ctx) -{ - const char* texNames[] = {"tex"}; - const char* uniNames[] = {"TexuredQuadUniform"}; - s_AAlphaPipeline = ctx.newShaderPipeline(VSNoFlip, FSAlpha, 1, texNames, 1, uniNames, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_AAddPipeline = ctx.newShaderPipeline(VSNoFlip, FSAlpha, 1, texNames, 1, uniNames, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_ASubtractPipeline = ctx.newShaderPipeline(VSNoFlip, FSAlpha, 1, texNames, 1, uniNames, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::Subtract, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_AMultPipeline = ctx.newShaderPipeline(VSNoFlip, FSAlpha, 1, texNames, 1, uniNames, boo::BlendFactor::Zero, - boo::BlendFactor::SrcColor, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_AInvDstMultPipeline = ctx.newShaderPipeline(VSNoFlip, FSAlpha, 1, texNames, 1, uniNames, boo::BlendFactor::Zero, - boo::BlendFactor::InvSrcColor, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - return new CTexturedQuadFilterAlphaGLDataBindingFactory; -} - -template <> -void CTexturedQuadFilterAlpha::Shutdown() -{ - s_AAlphaPipeline.reset(); - s_AAddPipeline.reset(); - s_ASubtractPipeline.reset(); - s_AMultPipeline.reset(); - s_AInvDstMultPipeline.reset(); -} - -#if BOO_HAS_VULKAN -TMultiBlendShader::IDataBindingFactory* -CTexturedQuadFilterAlpha::Initialize(boo::VulkanDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::UV4} - }; - s_AVtxFmt = ctx.newVertexFormat(2, VtxVmt); - s_AAlphaPipeline = ctx.newShaderPipeline(VSNoFlip, FSAlpha, s_AVtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, true, boo::CullMode::None); - s_AAddPipeline = ctx.newShaderPipeline(VSNoFlip, FSAlpha, s_AVtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, true, boo::CullMode::None); - s_ASubtractPipeline = ctx.newShaderPipeline(VSNoFlip, FSAlpha, s_AVtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::Subtract, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, true, boo::CullMode::None); - s_AMultPipeline = ctx.newShaderPipeline(VSNoFlip, FSAlpha, s_AVtxFmt, boo::BlendFactor::Zero, - boo::BlendFactor::SrcColor, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, true, boo::CullMode::None); - s_AInvDstMultPipeline = ctx.newShaderPipeline(VSNoFlip, FSAlpha, s_AVtxFmt, boo::BlendFactor::Zero, - boo::BlendFactor::InvSrcColor, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, true, boo::CullMode::None); - return new CTexturedQuadFilterAlphaVulkanDataBindingFactory; -} - -template <> -void CTexturedQuadFilterAlpha::Shutdown() -{ - s_AVtxFmt.reset(); - s_AAlphaPipeline.reset(); - s_AAddPipeline.reset(); - s_ASubtractPipeline.reset(); - s_AMultPipeline.reset(); - s_AInvDstMultPipeline.reset(); -} -#endif - -} diff --git a/Runtime/Graphics/Shaders/CTexturedQuadFilterHLSL.cpp b/Runtime/Graphics/Shaders/CTexturedQuadFilterHLSL.cpp deleted file mode 100644 index 6a67bd5fe..000000000 --- a/Runtime/Graphics/Shaders/CTexturedQuadFilterHLSL.cpp +++ /dev/null @@ -1,266 +0,0 @@ -#include "CTexturedQuadFilter.hpp" -#include "TMultiBlendShader.hpp" -#include "Graphics/CTexture.hpp" - -namespace urde -{ - -static const char* VSFlip = -"struct VertData\n" -"{\n" -" float4 posIn : POSITION;\n" -" float4 uvIn : UV;\n" -"};\n" -"\n" -"cbuffer TexuredQuadUniform : register(b0)\n" -"{\n" -" float4x4 mat;\n" -" float4 color;\n" -" float lod;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float4 color : COLOR;\n" -" float2 uv : UV;\n" -" float lod : LOD;\n" -"};\n" -"\n" -"VertToFrag main(in VertData v)\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.color = color;\n" -" vtf.uv = v.uvIn.xy;\n" -" vtf.lod = lod;\n" -" vtf.position = mul(mat, float4(v.posIn.xyz, 1.0));\n" -" return vtf;\n" -"}\n"; - -static const char* VSNoFlip = -"struct VertData\n" -"{\n" -" float4 posIn : POSITION;\n" -" float4 uvIn : UV;\n" -"};\n" -"\n" -"cbuffer TexuredQuadUniform : register(b0)\n" -"{\n" -" float4x4 mat;\n" -" float4 color;\n" -" float lod;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float4 color : COLOR;\n" -" float2 uv : UV;\n" -" float lod : LOD;\n" -"};\n" -"\n" -"VertToFrag main(in VertData v)\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.color = color;\n" -" vtf.uv = v.uvIn.xy;\n" -" vtf.lod = lod;\n" -" vtf.position = mul(mat, float4(v.posIn.xyz, 1.0));\n" -" return vtf;\n" -"}\n"; - -static const char* FS = -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float4 color : COLOR;\n" -" float2 uv : UV;\n" -" float lod : LOD;\n" -"};\n" -"\n" -"Texture2D tex : register(t0);\n" -"SamplerState samp : register(s3);\n" -"\n" -"float4 main(in VertToFrag vtf) : SV_Target0\n" -"{\n" -" return vtf.color * float4(tex.SampleBias(samp, vtf.uv, vtf.lod).rgb, 1.0);\n" -"}\n"; - -static const char* FSAlpha = -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float4 color : COLOR;\n" -" float2 uv : UV;\n" -" float lod : LOD;\n" -"};\n" -"\n" -"Texture2D tex : register(t0);\n" -"SamplerState samp : register(s3);\n" -"\n" -"float4 main(in VertToFrag vtf) : SV_Target0\n" -"{\n" -" return vtf.color * tex.SampleBias(samp, vtf.uv, vtf.lod);\n" -"}\n"; - -URDE_DECL_SPECIALIZE_MULTI_BLEND_SHADER(CTexturedQuadFilter) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_AlphaPipeline; -static boo::ObjToken s_AlphaGEqualPipeline; -static boo::ObjToken s_AlphaLEqualPipeline; -static boo::ObjToken s_AddPipeline; -static boo::ObjToken s_MultPipeline; - -static boo::ObjToken SelectPipeline(EFilterType type, CTexturedQuadFilter::ZTest zTest) -{ - switch (zTest) - { - case CTexturedQuadFilter::ZTest::GEqual: - return s_AlphaGEqualPipeline; - case CTexturedQuadFilter::ZTest::LEqual: - return s_AlphaLEqualPipeline; - default: - break; - } - switch (type) - { - case EFilterType::Blend: - return s_AlphaPipeline; - case EFilterType::Add: - return s_AddPipeline; - case EFilterType::Multiply: - return s_MultPipeline; - default: - return {}; - } -} - -struct CTexturedQuadFilterD3DDataBindingFactory : TMultiBlendShader::IDataBindingFactory -{ - boo::ObjToken - BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - EFilterType type, CTexturedQuadFilter& filter) - { - boo::D3DDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - boo::ObjToken texs[] = {filter.m_booTex.get()}; - return cctx.newShaderDataBinding(SelectPipeline(type, filter.m_zTest), s_VtxFmt, - filter.m_vbo.get(), nullptr, nullptr, 1, bufs, - nullptr, nullptr, nullptr, 1, texs, nullptr, nullptr); - } -}; - -TMultiBlendShader::IDataBindingFactory* -CTexturedQuadFilter::Initialize(boo::D3DDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::UV4} - }; - s_VtxFmt = ctx.newVertexFormat(2, VtxVmt); - s_AlphaPipeline = ctx.newShaderPipeline(VSNoFlip, FS, nullptr, nullptr, nullptr, - s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_AlphaGEqualPipeline = ctx.newShaderPipeline(VSNoFlip, FS, nullptr, nullptr, nullptr, - s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::GEqual, true, true, false, boo::CullMode::None); - s_AlphaLEqualPipeline = ctx.newShaderPipeline(VSNoFlip, FS, nullptr, nullptr, nullptr, - s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::LEqual, true, true, false, boo::CullMode::None); - s_AddPipeline = ctx.newShaderPipeline(VSNoFlip, FS, nullptr, nullptr, nullptr, - s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_MultPipeline = ctx.newShaderPipeline(VSNoFlip, FS, nullptr, nullptr, nullptr, - s_VtxFmt, boo::BlendFactor::Zero, - boo::BlendFactor::SrcColor, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - return new CTexturedQuadFilterD3DDataBindingFactory; -} - -template <> -void CTexturedQuadFilter::Shutdown() -{ - s_VtxFmt.reset(); - s_AlphaPipeline.reset(); - s_AlphaGEqualPipeline.reset(); - s_AlphaLEqualPipeline.reset(); - s_AddPipeline.reset(); - s_MultPipeline.reset(); -} - -static boo::ObjToken s_AVtxFmt; -static boo::ObjToken s_AAlphaPipeline; -static boo::ObjToken s_AAddPipeline; -static boo::ObjToken s_AMultPipeline; - -static boo::ObjToken SelectAlphaPipeline(EFilterType type) -{ - switch (type) - { - case EFilterType::Blend: - return s_AAlphaPipeline; - case EFilterType::Add: - return s_AAddPipeline; - case EFilterType::Multiply: - return s_AMultPipeline; - default: - return {}; - } -} - -struct CTexturedQuadFilterAlphaD3DDataBindingFactory : TMultiBlendShader::IDataBindingFactory -{ - boo::ObjToken - BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - EFilterType type, CTexturedQuadFilterAlpha& filter) - { - boo::D3DDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - boo::ObjToken texs[] = {filter.m_booTex.get()}; - return cctx.newShaderDataBinding(SelectAlphaPipeline(type), s_AVtxFmt, - filter.m_vbo.get(), nullptr, nullptr, 1, bufs, - nullptr, nullptr, nullptr, 1, texs, nullptr, nullptr); - } -}; - -TMultiBlendShader::IDataBindingFactory* -CTexturedQuadFilterAlpha::Initialize(boo::D3DDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::UV4} - }; - s_AVtxFmt = ctx.newVertexFormat(2, VtxVmt); - s_AAlphaPipeline = ctx.newShaderPipeline(VSFlip, FSAlpha, nullptr, nullptr, nullptr, - s_AVtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_AAddPipeline = ctx.newShaderPipeline(VSFlip, FSAlpha, nullptr, nullptr, nullptr, - s_AVtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_AMultPipeline = ctx.newShaderPipeline(VSFlip, FSAlpha, nullptr, nullptr, nullptr, - s_AVtxFmt, boo::BlendFactor::Zero, - boo::BlendFactor::SrcColor, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - return new CTexturedQuadFilterAlphaD3DDataBindingFactory; -} - -template <> -void CTexturedQuadFilterAlpha::Shutdown() -{ - s_AVtxFmt.reset(); - s_AAlphaPipeline.reset(); - s_AAddPipeline.reset(); - s_AMultPipeline.reset(); -} -} diff --git a/Runtime/Graphics/Shaders/CTexturedQuadFilterMetal.cpp b/Runtime/Graphics/Shaders/CTexturedQuadFilterMetal.cpp deleted file mode 100644 index 219740e15..000000000 --- a/Runtime/Graphics/Shaders/CTexturedQuadFilterMetal.cpp +++ /dev/null @@ -1,277 +0,0 @@ -#include "CTexturedQuadFilter.hpp" -#include "TMultiBlendShader.hpp" -#include "Graphics/CTexture.hpp" - -namespace urde -{ - -static const char* VSFlip = -"#include \n" -"using namespace metal;\n" -"struct VertData\n" -"{\n" -" float4 posIn [[ attribute(0) ]];\n" -" float4 uvIn [[ attribute(1) ]];\n" -"};\n" -"\n" -"struct TexuredQuadUniform\n" -"{\n" -" float4x4 mat;\n" -" float4 color;\n" -" float lod;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float4 color;\n" -" float2 uv;\n" -" float lod;\n" -"};\n" -"\n" -"vertex VertToFrag vmain(VertData v [[ stage_in ]], constant TexuredQuadUniform& tqu [[ buffer(2) ]])\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.color = tqu.color;\n" -" vtf.uv = v.uvIn.xy;\n" -" vtf.lod = tqu.lod;\n" -" vtf.position = tqu.mat * float4(v.posIn.xyz, 1.0);\n" -" return vtf;\n" -"}\n"; - -static const char* VSNoFlip = -"#include \n" -"using namespace metal;\n" -"struct VertData\n" -"{\n" -" float4 posIn [[ attribute(0) ]];\n" -" float4 uvIn [[ attribute(1) ]];\n" -"};\n" -"\n" -"struct TexuredQuadUniform\n" -"{\n" -" float4x4 mat;\n" -" float4 color;\n" -" float lod;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float4 color;\n" -" float2 uv;\n" -" float lod;\n" -"};\n" -"\n" -"vertex VertToFrag vmain(VertData v [[ stage_in ]], constant TexuredQuadUniform& tqu [[ buffer(2) ]])\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.color = tqu.color;\n" -" vtf.uv = v.uvIn.xy;\n" -" vtf.lod = tqu.lod;\n" -" vtf.position = tqu.mat * float4(v.posIn.xyz, 1.0);\n" -" return vtf;\n" -"}\n"; - - -static const char* FS = -"#include \n" -"using namespace metal;\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float4 color;\n" -" float2 uv;\n" -" float lod;\n" -"};\n" -"\n" -"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n" -" sampler clampSamp [[ sampler(3) ]],\n" -" texture2d tex [[ texture(0) ]])\n" -"{\n" -" return vtf.color * float4(tex.sample(clampSamp, vtf.uv, bias(vtf.lod)).rgb, 1.0);\n" -"}\n"; - -static const char* FSAlpha = -"#include \n" -"using namespace metal;\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float4 color;\n" -" float2 uv;\n" -" float lod;\n" -"};\n" -"\n" -"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n" -" sampler clampSamp [[ sampler(3) ]],\n" -" texture2d tex [[ texture(0) ]])\n" -"{\n" -" return vtf.color * tex.sample(clampSamp, vtf.uv, bias(vtf.lod));\n" -"}\n"; - -URDE_DECL_SPECIALIZE_MULTI_BLEND_SHADER(CTexturedQuadFilter) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_AlphaPipeline; -static boo::ObjToken s_AlphaGEqualPipeline; -static boo::ObjToken s_AlphaLEqualPipeline; -static boo::ObjToken s_AddPipeline; -static boo::ObjToken s_MultPipeline; - -static boo::ObjToken SelectPipeline(EFilterType type, CTexturedQuadFilter::ZTest zTest) -{ - switch (zTest) - { - case CTexturedQuadFilter::ZTest::GEqual: - return s_AlphaGEqualPipeline; - case CTexturedQuadFilter::ZTest::LEqual: - return s_AlphaLEqualPipeline; - default: - break; - } - switch (type) - { - case EFilterType::Blend: - return s_AlphaPipeline; - case EFilterType::Add: - return s_AddPipeline; - case EFilterType::Multiply: - return s_MultPipeline; - default: - return {}; - } -} - -struct CTexturedQuadFilterMetalDataBindingFactory : TMultiBlendShader::IDataBindingFactory -{ - boo::ObjToken BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - EFilterType type, CTexturedQuadFilter& filter) - { - boo::MetalDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - boo::ObjToken texs[] = {filter.m_booTex.get()}; - return cctx.newShaderDataBinding(SelectPipeline(type, filter.m_zTest), s_VtxFmt, - filter.m_vbo.get(), nullptr, nullptr, 1, bufs, - nullptr, nullptr, nullptr, 1, texs, nullptr, nullptr); - } -}; - -TMultiBlendShader::IDataBindingFactory* -CTexturedQuadFilter::Initialize(boo::MetalDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::UV4} - }; - s_VtxFmt = ctx.newVertexFormat(2, VtxVmt); - s_AlphaPipeline = ctx.newShaderPipeline(VSNoFlip, FS, nullptr, nullptr, - s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::None, false, - true, false, boo::CullMode::None); - s_AlphaGEqualPipeline = ctx.newShaderPipeline(VSNoFlip, FS, nullptr, nullptr, - s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::GEqual, true, - true, false, boo::CullMode::None); - s_AlphaLEqualPipeline = ctx.newShaderPipeline(VSNoFlip, FS, nullptr, nullptr, - s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::LEqual, true, - true, false, boo::CullMode::None); - s_AddPipeline = ctx.newShaderPipeline(VSNoFlip, FS, nullptr, nullptr, - s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::None, false, - true, false, boo::CullMode::None); - s_MultPipeline = ctx.newShaderPipeline(VSNoFlip, FS, nullptr, nullptr, - s_VtxFmt, boo::BlendFactor::Zero, - boo::BlendFactor::SrcColor, boo::Primitive::TriStrips, - boo::ZTest::None, false, - true, false, boo::CullMode::None); - return new CTexturedQuadFilterMetalDataBindingFactory; -} - -template <> -void CTexturedQuadFilter::Shutdown() -{ - s_VtxFmt.reset(); - s_AlphaPipeline.reset(); - s_AlphaGEqualPipeline.reset(); - s_AlphaLEqualPipeline.reset(); - s_AddPipeline.reset(); - s_MultPipeline.reset(); -} - -static boo::ObjToken s_AVtxFmt; -static boo::ObjToken s_AAlphaPipeline; -static boo::ObjToken s_AAddPipeline; -static boo::ObjToken s_AMultPipeline; - -static boo::ObjToken SelectAlphaPipeline(EFilterType type) -{ - switch (type) - { - case EFilterType::Blend: - return s_AAlphaPipeline; - case EFilterType::Add: - return s_AAddPipeline; - case EFilterType::Multiply: - return s_AMultPipeline; - default: - return {}; - } -} - -struct CTexturedQuadFilterAlphaMetalDataBindingFactory : TMultiBlendShader::IDataBindingFactory -{ - boo::ObjToken BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - EFilterType type, CTexturedQuadFilterAlpha& filter) - { - boo::MetalDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - boo::ObjToken texs[] = {filter.m_booTex.get()}; - return cctx.newShaderDataBinding(SelectAlphaPipeline(type), s_AVtxFmt, - filter.m_vbo.get(), nullptr, nullptr, 1, bufs, - nullptr, nullptr, nullptr, 1, texs, nullptr, nullptr); - } -}; - -TMultiBlendShader::IDataBindingFactory* -CTexturedQuadFilterAlpha::Initialize(boo::MetalDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::UV4} - }; - s_AVtxFmt = ctx.newVertexFormat(2, VtxVmt); - s_AAlphaPipeline = ctx.newShaderPipeline(VSFlip, FSAlpha, nullptr, nullptr, - s_AVtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_AAddPipeline = ctx.newShaderPipeline(VSFlip, FSAlpha, nullptr, nullptr, - s_AVtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::One, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_AMultPipeline = ctx.newShaderPipeline(VSFlip, FSAlpha, nullptr, nullptr, - s_AVtxFmt, boo::BlendFactor::Zero, - boo::BlendFactor::SrcColor, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - return new CTexturedQuadFilterAlphaMetalDataBindingFactory; -} - -template <> -void CTexturedQuadFilterAlpha::Shutdown() -{ - s_AVtxFmt.reset(); - s_AAlphaPipeline.reset(); - s_AAddPipeline.reset(); - s_AMultPipeline.reset(); -} - -} diff --git a/Runtime/Graphics/Shaders/CThermalColdFilter.cpp b/Runtime/Graphics/Shaders/CThermalColdFilter.cpp index 4f4cade75..bf0a93f8b 100644 --- a/Runtime/Graphics/Shaders/CThermalColdFilter.cpp +++ b/Runtime/Graphics/Shaders/CThermalColdFilter.cpp @@ -1,9 +1,22 @@ #include "CThermalColdFilter.hpp" #include "Graphics/CGraphics.hpp" +#include "hecl/Pipeline.hpp" namespace urde { +static boo::ObjToken s_Pipeline; + +void CThermalColdFilter::Initialize() +{ + s_Pipeline = hecl::conv->convert(Shader_CThermalColdFilter{}); +} + +void CThermalColdFilter::Shutdown() +{ + s_Pipeline.reset(); +} + CThermalColdFilter::CThermalColdFilter() { CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) @@ -23,7 +36,11 @@ CThermalColdFilter::CThermalColdFilter() }; m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts, 32, 4); m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); - m_dataBind = TShader::BuildShaderDataBinding(ctx, *this); + boo::ObjToken bufs[] = {m_uniBuf.get()}; + boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; + boo::ObjToken texs[] = {CGraphics::g_SpareTexture.get(), m_shiftTex.get()}; + m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, + 1, bufs, stages, nullptr, nullptr, 2, texs, nullptr, nullptr); return true; } BooTrace); @@ -66,6 +83,4 @@ void CThermalColdFilter::draw() CGraphics::DrawArray(0, 4); } -URDE_SPECIALIZE_SHADER(CThermalColdFilter) - } diff --git a/Runtime/Graphics/Shaders/CThermalColdFilter.hpp b/Runtime/Graphics/Shaders/CThermalColdFilter.hpp index 761730032..d4f3de681 100644 --- a/Runtime/Graphics/Shaders/CThermalColdFilter.hpp +++ b/Runtime/Graphics/Shaders/CThermalColdFilter.hpp @@ -1,20 +1,16 @@ #ifndef __URDE_CTHERMALCOLDFILTER_HPP__ #define __URDE_CTHERMALCOLDFILTER_HPP__ -#include "TShader.hpp" +#include "RetroTypes.hpp" #include "zeus/CMatrix4f.hpp" #include "zeus/CColor.hpp" +#include "boo/graphicsdev/IGraphicsDataFactory.hpp" namespace urde { class CThermalColdFilter { - friend struct CThermalColdFilterGLDataBindingFactory; - friend struct CThermalColdFilterVulkanDataBindingFactory; - friend struct CThermalColdFilterMetalDataBindingFactory; - friend struct CThermalColdFilterD3DDataBindingFactory; - struct Uniform { zeus::CMatrix4f m_shiftTexMtx; @@ -30,6 +26,8 @@ class CThermalColdFilter Uniform m_uniform; public: + static void Initialize(); + static void Shutdown(); CThermalColdFilter(); void setShift(unsigned shift); void setColorA(const zeus::CColor& color) {m_uniform.m_colorRegs[0] = color;} @@ -42,9 +40,6 @@ public: m_uniform.m_indMtx[1][1] = scale; } void draw(); - - using _CLS = CThermalColdFilter; -#include "TShaderDecl.hpp" }; } diff --git a/Runtime/Graphics/Shaders/CThermalColdFilterGLSL.cpp b/Runtime/Graphics/Shaders/CThermalColdFilterGLSL.cpp deleted file mode 100644 index ac2a764f3..000000000 --- a/Runtime/Graphics/Shaders/CThermalColdFilterGLSL.cpp +++ /dev/null @@ -1,159 +0,0 @@ -#include "CThermalColdFilter.hpp" - -namespace urde -{ - -static const char* VS = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"layout(location=0) in vec4 posIn;\n" -"layout(location=1) in vec4 uvIn;\n" -"\n" -"UBINDING0 uniform ThermalColdUniform\n" -"{\n" -" mat4 shiftMtx;\n" -" mat4 indMtx;\n" -" vec4 shiftScale;\n" -" vec4 colorReg0;\n" -" vec4 colorReg1;\n" -" vec4 colorReg2;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" mat3 indMtx;\n" -" vec4 colorReg0;\n" -" vec4 colorReg1;\n" -" vec4 colorReg2;\n" -" vec2 sceneUv;\n" -" vec2 shiftUv;\n" -" vec2 shiftScale;\n" -"};\n" -"\n" -"SBINDING(0) out VertToFrag vtf;\n" -"void main()\n" -"{\n" -" vtf.indMtx = mat3(indMtx);\n" -" vtf.colorReg0 = colorReg0;\n" -" vtf.colorReg1 = colorReg1;\n" -" vtf.colorReg2 = colorReg2;\n" -" vtf.sceneUv = uvIn.xy;\n" -" vtf.shiftUv = (mat3(shiftMtx) * uvIn.xyz).xy;\n" -" vtf.shiftScale = shiftScale.xy;\n" -" gl_Position = vec4(posIn.xyz, 1.0);\n" -"}\n"; - -static const char* FS = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"struct VertToFrag\n" -"{\n" -" mat3 indMtx;\n" -" vec4 colorReg0;\n" -" vec4 colorReg1;\n" -" vec4 colorReg2;\n" -" vec2 sceneUv;\n" -" vec2 shiftUv;\n" -" vec2 shiftScale;\n" -"};\n" -"\n" -"SBINDING(0) in VertToFrag vtf;\n" -"layout(location=0) out vec4 colorOut;\n" -"TBINDING0 uniform sampler2D sceneTex;\n" -"TBINDING1 uniform sampler2D shiftTex;\n" -"const vec4 kRGBToYPrime = vec4(0.299, 0.587, 0.114, 0.0);\n" -"void main()\n" -"{\n" -" vec2 shiftCoordTexel = texture(shiftTex, vtf.shiftUv).xy;\n" -" vec2 shiftCoord = vtf.sceneUv + shiftCoordTexel * vtf.shiftScale;\n" -" float shiftScene0 = dot(texture(sceneTex, shiftCoord), kRGBToYPrime);\n" -" float shiftScene1 = dot(texture(sceneTex, shiftCoord + vec2(vtf.shiftScale.x / 8.0, 0.0)), kRGBToYPrime);\n" -" vec2 indCoord = (vtf.indMtx * vec3(shiftScene0 - 0.5, shiftScene1 - 0.5, 1.0)).xy;\n" -" float indScene = dot(texture(sceneTex, vtf.sceneUv + indCoord), kRGBToYPrime);\n" -" colorOut = vtf.colorReg0 * indScene + vtf.colorReg1 * shiftScene0 + vtf.colorReg2;\n" -"}\n"; - -URDE_DECL_SPECIALIZE_SHADER(CThermalColdFilter) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_Pipeline; - -struct CThermalColdFilterGLDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CThermalColdFilter& filter) - { - boo::GLDataFactory::Context& cctx = static_cast(ctx); - - const boo::VertexElementDescriptor VtxVmt[] = - { - {filter.m_vbo.get(), nullptr, boo::VertexSemantic::Position4}, - {filter.m_vbo.get(), nullptr, boo::VertexSemantic::UV4} - }; - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; - boo::ObjToken texs[] = {CGraphics::g_SpareTexture.get(), filter.m_shiftTex.get()}; - return cctx.newShaderDataBinding(s_Pipeline, - ctx.newVertexFormat(2, VtxVmt), filter.m_vbo.get(), nullptr, nullptr, - 1, bufs, stages, nullptr, nullptr, 2, texs, nullptr, nullptr); - } -}; - -#if BOO_HAS_VULKAN -struct CThermalColdFilterVulkanDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken - BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CThermalColdFilter& filter) - { - boo::VulkanDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - boo::ObjToken texs[] = {CGraphics::g_SpareTexture.get(), filter.m_shiftTex.get()}; - return cctx.newShaderDataBinding(s_Pipeline, s_VtxFmt, - filter.m_vbo.get(), nullptr, nullptr, 1, bufs, - nullptr, nullptr, nullptr, 2, texs, nullptr, nullptr); - } -}; -#endif - -TShader::IDataBindingFactory* CThermalColdFilter::Initialize(boo::GLDataFactory::Context& ctx) -{ - const char* texNames[] = {"sceneTex", "shiftTex"}; - const char* uniNames[] = {"ThermalColdUniform"}; - s_Pipeline = ctx.newShaderPipeline(VS, FS, 2, texNames, 1, uniNames, boo::BlendFactor::One, - boo::BlendFactor::Zero, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - return new CThermalColdFilterGLDataBindingFactory; -} - -template <> -void CThermalColdFilter::Shutdown() -{ - s_Pipeline.reset(); -} - -#if BOO_HAS_VULKAN -TShader::IDataBindingFactory* CThermalColdFilter::Initialize(boo::VulkanDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::UV4} - }; - s_VtxFmt = ctx.newVertexFormat(2, VtxVmt); - s_Pipeline = ctx.newShaderPipeline(VS, FS, s_VtxFmt, boo::BlendFactor::One, - boo::BlendFactor::Zero, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, true, boo::CullMode::None); - return new CThermalColdFilterVulkanDataBindingFactory; -} - -template <> -void CThermalColdFilter::Shutdown() -{ - s_VtxFmt.reset(); - s_Pipeline.reset(); -} -#endif - -} diff --git a/Runtime/Graphics/Shaders/CThermalColdFilterHLSL.cpp b/Runtime/Graphics/Shaders/CThermalColdFilterHLSL.cpp deleted file mode 100644 index 0b78f5582..000000000 --- a/Runtime/Graphics/Shaders/CThermalColdFilterHLSL.cpp +++ /dev/null @@ -1,120 +0,0 @@ -#include "CThermalColdFilter.hpp" - -namespace urde -{ - -static const char* VS = -"struct VertData\n" -"{\n" -" float4 posIn : POSITION;\n" -" float4 uvIn : UV;\n" -"};\n" -"\n" -"cbuffer ThermalColdUniform : register(b0)\n" -"{\n" -" float4x4 shiftMtx;\n" -" float4x4 indMtx;\n" -" float4 shiftScale;\n" -" float4 colorReg0;\n" -" float4 colorReg1;\n" -" float4 colorReg2;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float3x3 indMtx : INDMTX;\n" -" float4 colorReg0 : COLORREG0;\n" -" float4 colorReg1 : COLORREG1;\n" -" float4 colorReg2 : COLORREG2;\n" -" float2 sceneUv : SCENEUV;\n" -" float2 shiftUv : SHIFTUV;\n" -" float2 shiftScale : SHIFTSCALE;\n" -"};\n" -"\n" -"VertToFrag main(in VertData v)\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.indMtx = float3x3(indMtx[0].xyz, indMtx[1].xyz, indMtx[2].xyz);\n" -" vtf.colorReg0 = colorReg0;\n" -" vtf.colorReg1 = colorReg1;\n" -" vtf.colorReg2 = colorReg2;\n" -" vtf.sceneUv = v.uvIn.xy;\n" -" vtf.sceneUv.y = 1.0 - vtf.sceneUv.y;\n" -" vtf.shiftUv = (mul(float3x3(shiftMtx[0].xyz, shiftMtx[1].xyz, shiftMtx[2].xyz), v.uvIn.xyz)).xy;\n" -" vtf.shiftScale = shiftScale.xy;\n" -" vtf.position = float4(v.posIn.xyz, 1.0);\n" -" return vtf;\n" -"}\n"; - -static const char* FS = -"Texture2D sceneTex : register(t0);\n" -"Texture2D shiftTex : register(t1);\n" -"SamplerState samp : register(s3);\n" -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float3x3 indMtx : INDMTX;\n" -" float4 colorReg0 : COLORREG0;\n" -" float4 colorReg1 : COLORREG1;\n" -" float4 colorReg2 : COLORREG2;\n" -" float2 sceneUv : SCENEUV;\n" -" float2 shiftUv : SHIFTUV;\n" -" float2 shiftScale : SHIFTSCALE;\n" -"};\n" -"\n" -"static const float4 kRGBToYPrime = {0.299, 0.587, 0.114, 0.0};\n" -"float4 main(in VertToFrag vtf) : SV_Target0\n" -"{\n" -" float2 shiftCoordTexel = shiftTex.Sample(samp, vtf.shiftUv).xy;\n" -" float2 shiftCoord = vtf.sceneUv + shiftCoordTexel * vtf.shiftScale;\n" -" float shiftScene0 = dot(sceneTex.Sample(samp, shiftCoord), kRGBToYPrime);\n" -" float shiftScene1 = dot(sceneTex.Sample(samp, shiftCoord + float2(vtf.shiftScale.x / 8.0, 0.0)), kRGBToYPrime);\n" -" float2 indCoord = (mul(vtf.indMtx, float3(shiftScene0 - 0.5, shiftScene1 - 0.5, 1.0))).xy;\n" -" float indScene = dot(sceneTex.Sample(samp, vtf.sceneUv + indCoord), kRGBToYPrime);\n" -" return vtf.colorReg0 * indScene + vtf.colorReg1 * shiftScene0 + vtf.colorReg2;\n" -"}\n"; - -URDE_DECL_SPECIALIZE_SHADER(CThermalColdFilter) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_Pipeline; - -struct CThermalColdFilterD3DDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken - BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CThermalColdFilter& filter) - { - boo::D3DDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - boo::ObjToken texs[] = {CGraphics::g_SpareTexture.get(), filter.m_shiftTex.get()}; - return cctx.newShaderDataBinding(s_Pipeline, s_VtxFmt, - filter.m_vbo.get(), nullptr, nullptr, 1, bufs, - nullptr, nullptr, nullptr, 2, texs, nullptr, nullptr); - } -}; - -TShader::IDataBindingFactory* CThermalColdFilter::Initialize(boo::D3DDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::UV4} - }; - s_VtxFmt = ctx.newVertexFormat(2, VtxVmt); - s_Pipeline = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, nullptr, - s_VtxFmt, boo::BlendFactor::One, - boo::BlendFactor::Zero, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - return new CThermalColdFilterD3DDataBindingFactory; -} - -template <> -void CThermalColdFilter::Shutdown() -{ - s_VtxFmt.reset(); - s_Pipeline.reset(); -} -} diff --git a/Runtime/Graphics/Shaders/CThermalColdFilterMetal.cpp b/Runtime/Graphics/Shaders/CThermalColdFilterMetal.cpp deleted file mode 100644 index 55c675c3f..000000000 --- a/Runtime/Graphics/Shaders/CThermalColdFilterMetal.cpp +++ /dev/null @@ -1,130 +0,0 @@ -#include "CThermalColdFilter.hpp" - -namespace urde -{ - -static const char* VS = -"#include \n" -"using namespace metal;\n" -"struct VertData\n" -"{\n" -" float4 posIn [[ attribute(0) ]];\n" -" float4 uvIn [[ attribute(1) ]];\n" -"};\n" -"\n" -"struct ThermalColdUniform\n" -"{\n" -" float4x4 shiftMtx;\n" -" float4x4 indMtx;\n" -" float4 shiftScale;\n" -" float4 colorReg0;\n" -" float4 colorReg1;\n" -" float4 colorReg2;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float3 indMtx0;\n" -" float3 indMtx1;\n" -" float3 indMtx2;\n" -" float4 colorReg0;\n" -" float4 colorReg1;\n" -" float4 colorReg2;\n" -" float2 sceneUv;\n" -" float2 shiftUv;\n" -" float2 shiftScale;\n" -"};\n" -"\n" -"vertex VertToFrag vmain(VertData v [[ stage_in ]], constant ThermalColdUniform& tcu [[ buffer(2) ]])\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.indMtx0 = tcu.indMtx[0].xyz;\n" -" vtf.indMtx1 = tcu.indMtx[1].xyz;\n" -" vtf.indMtx2 = tcu.indMtx[2].xyz;\n" -" vtf.colorReg0 = tcu.colorReg0;\n" -" vtf.colorReg1 = tcu.colorReg1;\n" -" vtf.colorReg2 = tcu.colorReg2;\n" -" vtf.sceneUv = v.uvIn.xy;\n" -" vtf.sceneUv.y = 1.0 - vtf.sceneUv.y;\n" -" vtf.shiftUv = (float3x3(tcu.shiftMtx[0].xyz, tcu.shiftMtx[1].xyz, tcu.shiftMtx[2].xyz) * v.uvIn.xyz).xy;\n" -" vtf.shiftScale = tcu.shiftScale.xy;\n" -" vtf.position = float4(v.posIn.xyz, 1.0);\n" -" return vtf;\n" -"}\n"; - -static const char* FS = -"#include \n" -"using namespace metal;\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float3 indMtx0;\n" -" float3 indMtx1;\n" -" float3 indMtx2;\n" -" float4 colorReg0;\n" -" float4 colorReg1;\n" -" float4 colorReg2;\n" -" float2 sceneUv;\n" -" float2 shiftUv;\n" -" float2 shiftScale;\n" -"};\n" -"\n" -"constant float4 kRGBToYPrime = {0.299, 0.587, 0.114, 0.0};\n" -"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n" -" sampler samp [[ sampler(3) ]],\n" -" texture2d sceneTex [[ texture(0) ]],\n" -" texture2d shiftTex [[ texture(1) ]])\n" -"{\n" -" float2 shiftCoordTexel = shiftTex.sample(samp, vtf.shiftUv).xy;\n" -" float2 shiftCoord = vtf.sceneUv + shiftCoordTexel * vtf.shiftScale;\n" -" float shiftScene0 = dot(sceneTex.sample(samp, shiftCoord), kRGBToYPrime);\n" -" float shiftScene1 = dot(sceneTex.sample(samp, shiftCoord + float2(vtf.shiftScale.x / 8.0, 0.0)), kRGBToYPrime);\n" -" float2 indCoord = (float3x3(vtf.indMtx0, vtf.indMtx1, vtf.indMtx2) * float3(shiftScene0 - 0.5, shiftScene1 - 0.5, 1.0)).xy;\n" -" float indScene = dot(sceneTex.sample(samp, vtf.sceneUv + indCoord), kRGBToYPrime);\n" -" return vtf.colorReg0 * indScene + vtf.colorReg1 * shiftScene0 + vtf.colorReg2;\n" -"}\n"; - -URDE_DECL_SPECIALIZE_SHADER(CThermalColdFilter) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_Pipeline; - -struct CThermalColdFilterMetalDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CThermalColdFilter& filter) - { - boo::MetalDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - boo::ObjToken texs[] = {CGraphics::g_SpareTexture.get(), filter.m_shiftTex.get()}; - return cctx.newShaderDataBinding(s_Pipeline, s_VtxFmt, - filter.m_vbo.get(), nullptr, nullptr, 1, bufs, - nullptr, nullptr, nullptr, 2, texs, nullptr, nullptr); - } -}; - -TShader::IDataBindingFactory* CThermalColdFilter::Initialize(boo::MetalDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::UV4} - }; - s_VtxFmt = ctx.newVertexFormat(2, VtxVmt); - s_Pipeline = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, - s_VtxFmt, boo::BlendFactor::One, - boo::BlendFactor::Zero, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - return new CThermalColdFilterMetalDataBindingFactory; -} - -template <> -void CThermalColdFilter::Shutdown() -{ - s_VtxFmt.reset(); - s_Pipeline.reset(); -} - -} diff --git a/Runtime/Graphics/Shaders/CThermalHotFilter.cpp b/Runtime/Graphics/Shaders/CThermalHotFilter.cpp index 813564f6e..49acb4c8e 100644 --- a/Runtime/Graphics/Shaders/CThermalHotFilter.cpp +++ b/Runtime/Graphics/Shaders/CThermalHotFilter.cpp @@ -1,9 +1,24 @@ #include "CThermalHotFilter.hpp" #include "Graphics/CGraphics.hpp" +#include "hecl/Pipeline.hpp" +#include "GameGlobalObjects.hpp" +#include "Graphics/CBooRenderer.hpp" namespace urde { +static boo::ObjToken s_Pipeline; + +void CThermalHotFilter::Initialize() +{ + s_Pipeline = hecl::conv->convert(Shader_CThermalHotFilter{}); +} + +void CThermalHotFilter::Shutdown() +{ + s_Pipeline.reset(); +} + CThermalHotFilter::CThermalHotFilter() { CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) @@ -21,7 +36,11 @@ CThermalHotFilter::CThermalHotFilter() }; m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts, 32, 4); m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); - m_dataBind = TShader::BuildShaderDataBinding(ctx, *this); + boo::ObjToken bufs[] = {m_uniBuf.get()}; + boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; + boo::ObjToken texs[] = {CGraphics::g_SpareTexture.get(), g_Renderer->GetThermoPalette()}; + m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, + 1, bufs, stages, nullptr, nullptr, 2, texs, nullptr, nullptr); return true; } BooTrace); } @@ -36,6 +55,4 @@ void CThermalHotFilter::draw() CGraphics::DrawArray(0, 4); } -URDE_SPECIALIZE_SHADER(CThermalHotFilter) - } diff --git a/Runtime/Graphics/Shaders/CThermalHotFilter.hpp b/Runtime/Graphics/Shaders/CThermalHotFilter.hpp index dd6626205..93145cb5a 100644 --- a/Runtime/Graphics/Shaders/CThermalHotFilter.hpp +++ b/Runtime/Graphics/Shaders/CThermalHotFilter.hpp @@ -1,20 +1,15 @@ #ifndef __URDE_CTHERMALHOTFILTER_HPP__ #define __URDE_CTHERMALHOTFILTER_HPP__ -#include "TShader.hpp" #include "zeus/CMatrix4f.hpp" #include "zeus/CColor.hpp" +#include "boo/graphicsdev/IGraphicsDataFactory.hpp" namespace urde { class CThermalHotFilter { - friend struct CThermalHotFilterGLDataBindingFactory; - friend struct CThermalHotFilterVulkanDataBindingFactory; - friend struct CThermalHotFilterMetalDataBindingFactory; - friend struct CThermalHotFilterD3DDataBindingFactory; - struct Uniform { zeus::CColor m_colorRegs[3]; @@ -25,14 +20,13 @@ class CThermalHotFilter Uniform m_uniform; public: + static void Initialize(); + static void Shutdown(); CThermalHotFilter(); void setColorA(const zeus::CColor& color) {m_uniform.m_colorRegs[0] = color;} void setColorB(const zeus::CColor& color) {m_uniform.m_colorRegs[1] = color;} void setColorC(const zeus::CColor& color) {m_uniform.m_colorRegs[2] = color;} void draw(); - - using _CLS = CThermalHotFilter; -#include "TShaderDecl.hpp" }; } diff --git a/Runtime/Graphics/Shaders/CThermalHotFilterGLSL.cpp b/Runtime/Graphics/Shaders/CThermalHotFilterGLSL.cpp deleted file mode 100644 index a0495d2f0..000000000 --- a/Runtime/Graphics/Shaders/CThermalHotFilterGLSL.cpp +++ /dev/null @@ -1,136 +0,0 @@ -#include "CThermalHotFilter.hpp" -#include "Graphics/CBooRenderer.hpp" -#include "GameGlobalObjects.hpp" - -namespace urde -{ - -static const char* VS = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"layout(location=0) in vec4 posIn;\n" -"layout(location=1) in vec4 uvIn;\n" -"\n" -"UBINDING0 uniform ThermalHotUniform\n" -"{\n" -" vec4 colorReg0;\n" -" vec4 colorReg1;\n" -" vec4 colorReg2;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" vec2 sceneUv;\n" -"};\n" -"\n" -"SBINDING(0) out VertToFrag vtf;\n" -"void main()\n" -"{\n" -" vtf.sceneUv = uvIn.xy;\n" -" gl_Position = vec4(posIn.xyz, 1.0);\n" -"}\n"; - -static const char* FS = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"struct VertToFrag\n" -"{\n" -" vec2 sceneUv;\n" -"};\n" -"\n" -"SBINDING(0) in VertToFrag vtf;\n" -"layout(location=0) out vec4 colorOut;\n" -"TBINDING0 uniform sampler2D sceneTex;\n" -"TBINDING1 uniform sampler2D paletteTex;\n" -"const vec4 kRGBToYPrime = vec4(0.299, 0.587, 0.114, 0.0);\n" -"void main()\n" -"{\n" -" float sceneSample = dot(texture(sceneTex, vtf.sceneUv), kRGBToYPrime);\n" -" vec4 colorSample = texture(paletteTex, vec2(sceneSample / 17.0, 0.5));\n" -" colorOut = vec4((colorSample * sceneSample).rgb, 0.0);\n" -"}\n"; - -URDE_DECL_SPECIALIZE_SHADER(CThermalHotFilter) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_Pipeline; - -struct CThermalHotFilterGLDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CThermalHotFilter& filter) - { - boo::GLDataFactory::Context& cctx = static_cast(ctx); - - const boo::VertexElementDescriptor VtxVmt[] = - { - {filter.m_vbo.get(), nullptr, boo::VertexSemantic::Position4}, - {filter.m_vbo.get(), nullptr, boo::VertexSemantic::UV4} - }; - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; - boo::ObjToken texs[] = {CGraphics::g_SpareTexture.get(), g_Renderer->GetThermoPalette()}; - return cctx.newShaderDataBinding(s_Pipeline, - ctx.newVertexFormat(2, VtxVmt), filter.m_vbo.get(), nullptr, nullptr, - 1, bufs, stages, nullptr, nullptr, 2, texs, nullptr, nullptr); - } -}; - -#if BOO_HAS_VULKAN -struct CThermalHotFilterVulkanDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken - BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CThermalHotFilter& filter) - { - boo::VulkanDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - boo::ObjToken texs[] = {CGraphics::g_SpareTexture.get(), g_Renderer->GetThermoPalette()}; - return cctx.newShaderDataBinding(s_Pipeline, s_VtxFmt, - filter.m_vbo.get(), nullptr, nullptr, 1, bufs, - nullptr, nullptr, nullptr, 2, texs, nullptr, nullptr); - } -}; -#endif - -TShader::IDataBindingFactory* CThermalHotFilter::Initialize(boo::GLDataFactory::Context& ctx) -{ - const char* texNames[] = {"sceneTex", "paletteTex"}; - const char* uniNames[] = {"ThermalHotUniform"}; - s_Pipeline = ctx.newShaderPipeline(VS, FS, 2, texNames, 1, uniNames, boo::BlendFactor::DstAlpha, - boo::BlendFactor::InvDstAlpha, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, true, boo::CullMode::None); - return new CThermalHotFilterGLDataBindingFactory; -} - -template <> -void CThermalHotFilter::Shutdown() -{ - s_Pipeline.reset(); -} - -#if BOO_HAS_VULKAN -TShader::IDataBindingFactory* CThermalHotFilter::Initialize(boo::VulkanDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::UV4} - }; - s_VtxFmt = ctx.newVertexFormat(2, VtxVmt); - s_Pipeline = ctx.newShaderPipeline(VS, FS, s_VtxFmt, boo::BlendFactor::DstAlpha, - boo::BlendFactor::InvDstAlpha, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, true, boo::CullMode::None); - return new CThermalHotFilterVulkanDataBindingFactory; -} - -template <> -void CThermalHotFilter::Shutdown() -{ - s_VtxFmt.reset(); - s_Pipeline.reset(); -} -#endif - -} diff --git a/Runtime/Graphics/Shaders/CThermalHotFilterHLSL.cpp b/Runtime/Graphics/Shaders/CThermalHotFilterHLSL.cpp deleted file mode 100644 index 9a2bb32f0..000000000 --- a/Runtime/Graphics/Shaders/CThermalHotFilterHLSL.cpp +++ /dev/null @@ -1,97 +0,0 @@ -#include "CThermalHotFilter.hpp" -#include "Graphics/CBooRenderer.hpp" -#include "GameGlobalObjects.hpp" - -namespace urde -{ - -static const char* VS = -"struct VertData\n" -"{\n" -" float4 posIn : POSITION;\n" -" float4 uvIn : UV;\n" -"};\n" -"\n" -"cbuffer ThermalHotUniform : register(b0)\n" -"{\n" -" float4 colorReg0;\n" -" float4 colorReg1;\n" -" float4 colorReg2;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float2 sceneUv : UV;\n" -"};\n" -"\n" -"VertToFrag main(in VertData v)\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.sceneUv = v.uvIn.xy;\n" -" vtf.sceneUv.y = 1.0 - vtf.sceneUv.y;\n" -" vtf.position = float4(v.posIn.xyz, 1.0);\n" -" return vtf;\n" -"}\n"; - -static const char* FS = -"Texture2D sceneTex : register(t0);\n" -"Texture2D paletteTex : register(t1);\n" -"SamplerState samp : register(s0);\n" -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float2 sceneUv : UV;\n" -"};\n" -"\n" -"static const float4 kRGBToYPrime = float4(0.299, 0.587, 0.114, 0.0);\n" -"float4 main(in VertToFrag vtf) : SV_Target0\n" -"{\n" -" float sceneSample = dot(sceneTex.Sample(samp, vtf.sceneUv), kRGBToYPrime);\n" -" float4 colorSample = paletteTex.Sample(samp, float2(sceneSample / 17.0, 0.5));\n" -" return float4((colorSample * sceneSample).rgb, 0.0);\n" -"}\n"; - -URDE_DECL_SPECIALIZE_SHADER(CThermalHotFilter) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_Pipeline; - -struct CThermalHotFilterD3DDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken - BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CThermalHotFilter& filter) - { - boo::D3DDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - boo::ObjToken texs[] = {CGraphics::g_SpareTexture.get(), g_Renderer->GetThermoPalette().get()}; - return cctx.newShaderDataBinding(s_Pipeline, s_VtxFmt, - filter.m_vbo.get(), nullptr, nullptr, 1, bufs, - nullptr, nullptr, nullptr, 2, texs, nullptr, nullptr); - } -}; - -TShader::IDataBindingFactory* CThermalHotFilter::Initialize(boo::D3DDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::UV4} - }; - s_VtxFmt = ctx.newVertexFormat(2, VtxVmt); - s_Pipeline = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, nullptr, - s_VtxFmt, boo::BlendFactor::DstAlpha, boo::BlendFactor::InvDstAlpha, - boo::Primitive::TriStrips, boo::ZTest::None, - false, true, true, boo::CullMode::None); - return new CThermalHotFilterD3DDataBindingFactory; -} - -template <> -void CThermalHotFilter::Shutdown() -{ - s_VtxFmt.reset(); - s_Pipeline.reset(); -} -} diff --git a/Runtime/Graphics/Shaders/CThermalHotFilterMetal.cpp b/Runtime/Graphics/Shaders/CThermalHotFilterMetal.cpp deleted file mode 100644 index 5f6808eae..000000000 --- a/Runtime/Graphics/Shaders/CThermalHotFilterMetal.cpp +++ /dev/null @@ -1,101 +0,0 @@ -#include "CThermalHotFilter.hpp" -#include "Graphics/CBooRenderer.hpp" -#include "GameGlobalObjects.hpp" - -namespace urde -{ - -static const char* VS = -"#include \n" -"using namespace metal;\n" -"struct VertData\n" -"{\n" -" float4 posIn [[ attribute(0) ]];\n" -" float4 uvIn [[ attribute(1) ]];\n" -"};\n" -"\n" -"struct ThermalHotUniform\n" -"{\n" -" float4 colorReg0;\n" -" float4 colorReg1;\n" -" float4 colorReg2;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float2 sceneUv;\n" -"};\n" -"\n" -"vertex VertToFrag vmain(VertData v [[ stage_in ]], constant ThermalHotUniform& thu [[ buffer(2) ]])\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.sceneUv = v.uvIn.xy;\n" -" vtf.sceneUv.y = 1.0 - vtf.sceneUv.y;\n" -" vtf.position = float4(v.posIn.xyz, 1.0);\n" -" return vtf;\n" -"}\n"; - -static const char* FS = -"#include \n" -"using namespace metal;\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float2 sceneUv;\n" -"};\n" -"\n" -"constant float4 kRGBToYPrime = float4(0.299, 0.587, 0.114, 0.0);\n" -"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n" -" sampler samp [[ sampler(0) ]],\n" -" texture2d sceneTex [[ texture(0) ]],\n" -" texture2d paletteTex [[ texture(1) ]])\n" -"{\n" -" float sceneSample = dot(sceneTex.sample(samp, vtf.sceneUv), kRGBToYPrime);\n" -" float4 colorSample = paletteTex.sample(samp, float2(sceneSample / 17.0, 0.5));\n" -" return float4((colorSample * sceneSample).rgb, 0.0);\n" -"}\n"; - -URDE_DECL_SPECIALIZE_SHADER(CThermalHotFilter) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_Pipeline; - -struct CThermalHotFilterMetalDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CThermalHotFilter& filter) - { - boo::MetalDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - boo::ObjToken texs[] = {CGraphics::g_SpareTexture.get(), g_Renderer->GetThermoPalette()}; - return cctx.newShaderDataBinding(s_Pipeline, s_VtxFmt, - filter.m_vbo.get(), nullptr, nullptr, 1, bufs, - nullptr, nullptr, nullptr, 2, texs, nullptr, nullptr); - } -}; - -TShader::IDataBindingFactory* CThermalHotFilter::Initialize(boo::MetalDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::UV4} - }; - s_VtxFmt = ctx.newVertexFormat(2, VtxVmt); - s_Pipeline = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, s_VtxFmt, - boo::BlendFactor::DstAlpha, boo::BlendFactor::InvDstAlpha, - boo::Primitive::TriStrips, boo::ZTest::None, false, - true, true, boo::CullMode::None); - return new CThermalHotFilterMetalDataBindingFactory; -} - -template <> -void CThermalHotFilter::Shutdown() -{ - s_VtxFmt.reset(); - s_Pipeline.reset(); -} - -} diff --git a/Runtime/Graphics/Shaders/CWorldShadowShader.cpp b/Runtime/Graphics/Shaders/CWorldShadowShader.cpp index 0b1118807..3d2a5c986 100644 --- a/Runtime/Graphics/Shaders/CWorldShadowShader.cpp +++ b/Runtime/Graphics/Shaders/CWorldShadowShader.cpp @@ -1,8 +1,25 @@ #include "CWorldShadowShader.hpp" +#include "hecl/Pipeline.hpp" +#include "Graphics/CGraphics.hpp" namespace urde { +static boo::ObjToken s_Pipeline; +static boo::ObjToken s_ZPipeline; + +void CWorldShadowShader::Initialize() +{ + s_Pipeline = hecl::conv->convert(Shader_CWorldShadowShader{}); + s_ZPipeline = hecl::conv->convert(Shader_CWorldShadowShaderZ{}); +} + +void CWorldShadowShader::Shutdown() +{ + s_Pipeline.reset(); + s_ZPipeline.reset(); +} + CWorldShadowShader::CWorldShadowShader(u32 w, u32 h) : m_w(w), m_h(h) { @@ -10,7 +27,12 @@ CWorldShadowShader::CWorldShadowShader(u32 w, u32 h) { m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, 16, 4); m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); - TShader::BuildShaderDataBinding(ctx, *this); + boo::ObjToken bufs[] = {m_uniBuf.get()}; + boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; + m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, + 1, bufs, stages, nullptr, nullptr, 0, nullptr, nullptr, nullptr); + m_zDataBind = ctx.newShaderDataBinding(s_ZPipeline, m_vbo.get(), nullptr, nullptr, + 1, bufs, stages, nullptr, nullptr, 0, nullptr, nullptr, nullptr); m_tex = ctx.newRenderTexture(m_w, m_h, boo::TextureClampMode::ClampToWhite, 1, 0); return true; } BooTrace); @@ -58,6 +80,4 @@ void CWorldShadowShader::resolveTexture() CGraphics::g_BooMainCommandQueue->resolveBindTexture(m_tex, rect, false, 0, true, false, true); } -URDE_SPECIALIZE_SHADER(CWorldShadowShader) - } diff --git a/Runtime/Graphics/Shaders/CWorldShadowShader.hpp b/Runtime/Graphics/Shaders/CWorldShadowShader.hpp index 3ef514267..c86cb5385 100644 --- a/Runtime/Graphics/Shaders/CWorldShadowShader.hpp +++ b/Runtime/Graphics/Shaders/CWorldShadowShader.hpp @@ -1,7 +1,6 @@ #ifndef URDE_CWORLDSHADOWSHADER_HPP #define URDE_CWORLDSHADOWSHADER_HPP -#include "TShader.hpp" #include "CColoredQuadFilter.hpp" #include "CTexturedQuadFilter.hpp" @@ -10,11 +9,6 @@ namespace urde class CWorldShadowShader { - friend struct CWorldShadowShaderGLDataBindingFactory; - friend struct CWorldShadowShaderVulkanDataBindingFactory; - friend struct CWorldShadowShaderD3DDataBindingFactory; - friend struct CWorldShadowShaderMetalDataBindingFactory; - boo::ObjToken m_tex; std::experimental::optional m_prevQuad; u32 m_w, m_h; @@ -31,6 +25,8 @@ class CWorldShadowShader Uniform m_uniform; public: + static void Initialize(); + static void Shutdown(); CWorldShadowShader(u32 w, u32 h); void bindRenderTarget(); void drawBase(float extent); @@ -42,9 +38,6 @@ public: u32 GetHeight() const { return m_h; } const boo::ObjToken& GetTexture() const { return m_tex; } - - using _CLS = CWorldShadowShader; -#include "TShaderDecl.hpp" }; } diff --git a/Runtime/Graphics/Shaders/CWorldShadowShaderGLSL.cpp b/Runtime/Graphics/Shaders/CWorldShadowShaderGLSL.cpp deleted file mode 100644 index 4ace92216..000000000 --- a/Runtime/Graphics/Shaders/CWorldShadowShaderGLSL.cpp +++ /dev/null @@ -1,143 +0,0 @@ -#include "CWorldShadowShader.hpp" - -namespace urde -{ - -static const char* VS = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"layout(location=0) in vec4 posIn;\n" -"\n" -"UBINDING0 uniform ColoredQuadUniform\n" -"{\n" -" mat4 xf;\n" -" vec4 color;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -"};\n" -"\n" -"SBINDING(0) out VertToFrag vtf;\n" -"void main()\n" -"{\n" -" vtf.color = color;\n" -" gl_Position = xf * vec4(posIn.xyz, 1.0);\n" -"}\n"; - -static const char* FS = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"struct VertToFrag\n" -"{\n" -" vec4 color;\n" -"};\n" -"\n" -"SBINDING(0) in VertToFrag vtf;\n" -"layout(location=0) out vec4 colorOut;\n" -"void main()\n" -"{\n" -" colorOut = vtf.color;\n" -"}\n"; - -URDE_DECL_SPECIALIZE_SHADER(CWorldShadowShader) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_Pipeline; -static boo::ObjToken s_ZPipeline; - -struct CWorldShadowShaderGLDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CWorldShadowShader& filter) - { - boo::GLDataFactory::Context& cctx = static_cast(ctx); - - const boo::VertexElementDescriptor VtxVmt[] = - { - {filter.m_vbo.get(), nullptr, boo::VertexSemantic::Position4} - }; - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; - boo::ObjToken vtxFmt = ctx.newVertexFormat(1, VtxVmt); - filter.m_dataBind = cctx.newShaderDataBinding(s_Pipeline, - vtxFmt, filter.m_vbo.get(), nullptr, nullptr, - 1, bufs, stages, nullptr, nullptr, 0, nullptr, nullptr, nullptr); - filter.m_zDataBind = cctx.newShaderDataBinding(s_ZPipeline, - vtxFmt, filter.m_vbo.get(), nullptr, nullptr, - 1, bufs, stages, nullptr, nullptr, 0, nullptr, nullptr, nullptr); - return nullptr; - } -}; - -#if BOO_HAS_VULKAN -struct CWorldShadowShaderVulkanDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken - BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CWorldShadowShader& filter) - { - boo::VulkanDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - filter.m_dataBind = cctx.newShaderDataBinding(s_Pipeline, s_VtxFmt, - filter.m_vbo.get(), nullptr, nullptr, 1, bufs, - nullptr, nullptr, nullptr, 0, nullptr, nullptr, nullptr); - filter.m_zDataBind = cctx.newShaderDataBinding(s_ZPipeline, s_VtxFmt, - filter.m_vbo.get(), nullptr, nullptr, 1, bufs, - nullptr, nullptr, nullptr, 0, nullptr, nullptr, nullptr); - return nullptr; - } -}; -#endif - -TShader::IDataBindingFactory* -CWorldShadowShader::Initialize(boo::GLDataFactory::Context& ctx) -{ - const char* uniNames[] = {"ColoredQuadUniform"}; - s_Pipeline = ctx.newShaderPipeline(VS, FS, 0, nullptr, 1, uniNames, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_ZPipeline = ctx.newShaderPipeline(VS, FS, 0, nullptr, 1, uniNames, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::LEqual, true, true, false, boo::CullMode::None); - return new CWorldShadowShaderGLDataBindingFactory; -} - -template <> -void CWorldShadowShader::Shutdown() -{ - s_Pipeline.reset(); - s_ZPipeline.reset(); -} - -#if BOO_HAS_VULKAN -TShader::IDataBindingFactory* -CWorldShadowShader::Initialize(boo::VulkanDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4} - }; - s_VtxFmt = ctx.newVertexFormat(1, VtxVmt); - s_Pipeline = ctx.newShaderPipeline(VS, FS, s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_ZPipeline = ctx.newShaderPipeline(VS, FS, s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::LEqual, true, true, false, boo::CullMode::None); - return new CWorldShadowShaderVulkanDataBindingFactory; -} - -template <> -void CWorldShadowShader::Shutdown() -{ - s_VtxFmt.reset(); - s_Pipeline.reset(); - s_ZPipeline.reset(); -} -#endif - -} - diff --git a/Runtime/Graphics/Shaders/CWorldShadowShaderHLSL.cpp b/Runtime/Graphics/Shaders/CWorldShadowShaderHLSL.cpp deleted file mode 100644 index ab391e0a1..000000000 --- a/Runtime/Graphics/Shaders/CWorldShadowShaderHLSL.cpp +++ /dev/null @@ -1,94 +0,0 @@ -#include "CWorldShadowShader.hpp" - -namespace urde -{ - -static const char* VS = -"struct VertData\n" -"{\n" -" float4 posIn : POSITION;\n" -"};\n" -"\n" -"cbuffer ColoredQuadUniform : register(b0)\n" -"{\n" -" float4x4 xf;\n" -" float4 color;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float4 color : COLOR;\n" -"};\n" -"\n" -"VertToFrag main(in VertData v)\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.color = color;\n" -" vtf.position = mul(xf, float4(v.posIn.xyz, 1.0));\n" -" return vtf;\n" -"}\n"; - -static const char* FS = -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float4 color : COLOR;\n" -"};\n" -"\n" -"float4 main(in VertToFrag vtf) : SV_Target0\n" -"{\n" -" return vtf.color;\n" -"}\n"; - -URDE_DECL_SPECIALIZE_SHADER(CWorldShadowShader) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_Pipeline; -static boo::ObjToken s_ZPipeline; - -struct CWorldShadowShaderD3DDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken - BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CWorldShadowShader& filter) - { - boo::D3DDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - filter.m_dataBind = cctx.newShaderDataBinding(s_Pipeline, s_VtxFmt, - filter.m_vbo.get(), nullptr, nullptr, 1, bufs, - nullptr, nullptr, nullptr, 0, nullptr, nullptr, nullptr); - filter.m_zDataBind = cctx.newShaderDataBinding(s_ZPipeline, s_VtxFmt, - filter.m_vbo.get(), nullptr, nullptr, 1, bufs, - nullptr, nullptr, nullptr, 0, nullptr, nullptr, nullptr); - return nullptr; - } -}; - -TShader::IDataBindingFactory* -CWorldShadowShader::Initialize(boo::D3DDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4} - }; - s_VtxFmt = ctx.newVertexFormat(1, VtxVmt); - s_Pipeline = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, nullptr, s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_ZPipeline = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, nullptr, s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::LEqual, true, true, false, boo::CullMode::None); - return new CWorldShadowShaderD3DDataBindingFactory; -} - -template <> -void CWorldShadowShader::Shutdown() -{ - s_VtxFmt.reset(); - s_Pipeline.reset(); - s_ZPipeline.reset(); -} -} - diff --git a/Runtime/Graphics/Shaders/CWorldShadowShaderMetal.cpp b/Runtime/Graphics/Shaders/CWorldShadowShaderMetal.cpp deleted file mode 100644 index 29b43b5c2..000000000 --- a/Runtime/Graphics/Shaders/CWorldShadowShaderMetal.cpp +++ /dev/null @@ -1,100 +0,0 @@ -#include "CWorldShadowShader.hpp" - -namespace urde -{ - -static const char* VS = -"#include \n" -"using namespace metal;\n" -"struct VertData\n" -"{\n" -" float4 posIn [[ attribute(0) ]];\n" -"};\n" -"\n" -"struct ColoredQuadUniform\n" -"{\n" -" float4x4 xf;\n" -" float4 color;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float4 color;\n" -"};\n" -"\n" -"vertex VertToFrag vmain(VertData v [[ stage_in ]], constant ColoredQuadUniform& cqu [[ buffer(2) ]])\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.color = cqu.color;\n" -" vtf.position = cqu.xf * float4(v.posIn.xyz, 1.0);\n" -" return vtf;\n" -"}\n"; - -static const char* FS = -"#include \n" -"using namespace metal;\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float4 color;\n" -"};\n" -"\n" -"fragment float4 fmain(VertToFrag vtf [[ stage_in ]])\n" -"{\n" -" return vtf.color;\n" -"}\n"; - -URDE_DECL_SPECIALIZE_SHADER(CWorldShadowShader) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_Pipeline; -static boo::ObjToken s_ZPipeline; - -struct CWorldShadowShaderMetalDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CWorldShadowShader& filter) - { - boo::MetalDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - filter.m_dataBind = cctx.newShaderDataBinding(s_Pipeline, s_VtxFmt, - filter.m_vbo.get(), nullptr, nullptr, 1, bufs, - nullptr, nullptr, nullptr, 0, nullptr, nullptr, nullptr); - filter.m_zDataBind = cctx.newShaderDataBinding(s_ZPipeline, s_VtxFmt, - filter.m_vbo.get(), nullptr, nullptr, 1, bufs, - nullptr, nullptr, nullptr, 0, nullptr, nullptr, nullptr); - return nullptr; - } -}; - -TShader::IDataBindingFactory* -CWorldShadowShader::Initialize(boo::MetalDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4} - }; - s_VtxFmt = ctx.newVertexFormat(1, VtxVmt); - s_Pipeline = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, - s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - s_ZPipeline = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, - s_VtxFmt, boo::BlendFactor::SrcAlpha, - boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, - boo::ZTest::LEqual, true, true, false, boo::CullMode::None); - return new CWorldShadowShaderMetalDataBindingFactory; -} - -template <> -void CWorldShadowShader::Shutdown() -{ - s_VtxFmt.reset(); - s_Pipeline.reset(); - s_ZPipeline.reset(); -} - -} - diff --git a/Runtime/Graphics/Shaders/CXRayBlurFilter.cpp b/Runtime/Graphics/Shaders/CXRayBlurFilter.cpp index a2b1df255..8e54ca9f4 100644 --- a/Runtime/Graphics/Shaders/CXRayBlurFilter.cpp +++ b/Runtime/Graphics/Shaders/CXRayBlurFilter.cpp @@ -2,10 +2,23 @@ #include "Graphics/CGraphics.hpp" #include "Graphics/CTexture.hpp" #include "GameGlobalObjects.hpp" +#include "hecl/Pipeline.hpp" namespace urde { +static boo::ObjToken s_Pipeline; + +void CXRayBlurFilter::Initialize() +{ + s_Pipeline = hecl::conv->convert(Shader_CXRayBlurFilter{}); +} + +void CXRayBlurFilter::Shutdown() +{ + s_Pipeline.reset(); +} + CXRayBlurFilter::CXRayBlurFilter(TLockedToken& tex) : m_paletteTex(tex), m_booTex(tex->GetPaletteTexture()) { @@ -24,7 +37,11 @@ CXRayBlurFilter::CXRayBlurFilter(TLockedToken& tex) }; m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts, 32, 4); m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); - m_dataBind = TShader::BuildShaderDataBinding(ctx, *this); + boo::ObjToken bufs[] = {m_uniBuf.get()}; + boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; + boo::ObjToken texs[] = {CGraphics::g_SpareTexture.get(), m_booTex}; + m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, + 1, bufs, stages, nullptr, nullptr, 2, texs, nullptr, nullptr); return true; } BooTrace); } @@ -52,6 +69,4 @@ void CXRayBlurFilter::draw(float amount) CGraphics::DrawArray(0, 4); } -URDE_SPECIALIZE_SHADER(CXRayBlurFilter) - } diff --git a/Runtime/Graphics/Shaders/CXRayBlurFilter.hpp b/Runtime/Graphics/Shaders/CXRayBlurFilter.hpp index 80857f7de..96285eab6 100644 --- a/Runtime/Graphics/Shaders/CXRayBlurFilter.hpp +++ b/Runtime/Graphics/Shaders/CXRayBlurFilter.hpp @@ -1,7 +1,7 @@ #ifndef __URDE_CXRAYBLURFILTER_HPP__ #define __URDE_CXRAYBLURFILTER_HPP__ -#include "TShader.hpp" +#include "boo/graphicsdev/IGraphicsDataFactory.hpp" #include "zeus/CMatrix4f.hpp" #include "zeus/CColor.hpp" #include "CToken.hpp" @@ -12,11 +12,6 @@ class CTexture; class CXRayBlurFilter { - friend struct CXRayBlurFilterGLDataBindingFactory; - friend struct CXRayBlurFilterVulkanDataBindingFactory; - friend struct CXRayBlurFilterMetalDataBindingFactory; - friend struct CXRayBlurFilterD3DDataBindingFactory; - struct Uniform { zeus::CMatrix4f m_uv[8]; @@ -29,11 +24,10 @@ class CXRayBlurFilter Uniform m_uniform; public: + static void Initialize(); + static void Shutdown(); CXRayBlurFilter(TLockedToken& tex); void draw(float amount); - - using _CLS = CXRayBlurFilter; -#include "TShaderDecl.hpp" }; } diff --git a/Runtime/Graphics/Shaders/CXRayBlurFilterGLSL.cpp b/Runtime/Graphics/Shaders/CXRayBlurFilterGLSL.cpp deleted file mode 100644 index c7ce93ae2..000000000 --- a/Runtime/Graphics/Shaders/CXRayBlurFilterGLSL.cpp +++ /dev/null @@ -1,168 +0,0 @@ -#include "CXRayBlurFilter.hpp" -#include "Graphics/CBooRenderer.hpp" -#include "GameGlobalObjects.hpp" - -namespace urde -{ - -static const char* VS = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"layout(location=0) in vec4 posIn;\n" -"layout(location=1) in vec4 uvIn;\n" -"\n" -"UBINDING0 uniform XRayBlurUniform\n" -"{\n" -" mat4 uv0;\n" -" mat4 uv1;\n" -" mat4 uv2;\n" -" mat4 uv3;\n" -" mat4 uv4;\n" -" mat4 uv5;\n" -" mat4 uv6;\n" -" mat4 uv7;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" vec2 uv0;\n" -" vec2 uv1;\n" -" vec2 uv2;\n" -" vec2 uv3;\n" -" vec2 uv4;\n" -" vec2 uv5;\n" -" vec2 uv6;\n" -" vec2 uv7;\n" -"};\n" -"\n" -"SBINDING(0) out VertToFrag vtf;\n" -"void main()\n" -"{\n" -" vtf.uv0 = (uv0 * vec4(uvIn.xy, 0.0, 1.0)).xy;\n" -" vtf.uv1 = (uv1 * vec4(uvIn.xy, 0.0, 1.0)).xy;\n" -" vtf.uv2 = (uv2 * vec4(uvIn.xy, 0.0, 1.0)).xy;\n" -" vtf.uv3 = (uv3 * vec4(uvIn.xy, 0.0, 1.0)).xy;\n" -" vtf.uv4 = (uv4 * vec4(uvIn.xy, 0.0, 1.0)).xy;\n" -" vtf.uv5 = (uv5 * vec4(uvIn.xy, 0.0, 1.0)).xy;\n" -" vtf.uv6 = (uv6 * vec4(uvIn.xy, 0.0, 1.0)).xy;\n" -" vtf.uv7 = (uv7 * vec4(uvIn.xy, 0.0, 1.0)).xy;\n" -" gl_Position = vec4(posIn.xyz, 1.0);\n" -"}\n"; - -static const char* FS = -"#version 330\n" -BOO_GLSL_BINDING_HEAD -"struct VertToFrag\n" -"{\n" -" vec2 uv0;\n" -" vec2 uv1;\n" -" vec2 uv2;\n" -" vec2 uv3;\n" -" vec2 uv4;\n" -" vec2 uv5;\n" -" vec2 uv6;\n" -" vec2 uv7;\n" -"};\n" -"\n" -"SBINDING(0) in VertToFrag vtf;\n" -"layout(location=0) out vec4 colorOut;\n" -"TBINDING0 uniform sampler2D sceneTex;\n" -"TBINDING1 uniform sampler2D paletteTex;\n" -"const vec4 kRGBToYPrime = vec4(0.299, 0.587, 0.114, 0.0);\n" -"void main()\n" -"{\n" -" vec4 colorSample = texture(paletteTex, vec2(dot(texture(sceneTex, vtf.uv0), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125;\n" -" colorSample += texture(paletteTex, vec2(dot(texture(sceneTex, vtf.uv1), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125;\n" -" colorSample += texture(paletteTex, vec2(dot(texture(sceneTex, vtf.uv2), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125;\n" -" colorSample += texture(paletteTex, vec2(dot(texture(sceneTex, vtf.uv3), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125;\n" -" colorSample += texture(paletteTex, vec2(dot(texture(sceneTex, vtf.uv4), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125;\n" -" colorSample += texture(paletteTex, vec2(dot(texture(sceneTex, vtf.uv5), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125;\n" -" colorSample += texture(paletteTex, vec2(dot(texture(sceneTex, vtf.uv6), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125;\n" -" colorSample += texture(paletteTex, vec2(dot(texture(sceneTex, vtf.uv7), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125;\n" -" colorOut = colorSample;\n" -"}\n"; - -URDE_DECL_SPECIALIZE_SHADER(CXRayBlurFilter) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_Pipeline; - -struct CXRayBlurFilterGLDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CXRayBlurFilter& filter) - { - boo::GLDataFactory::Context& cctx = static_cast(ctx); - - const boo::VertexElementDescriptor VtxVmt[] = - { - {filter.m_vbo.get(), nullptr, boo::VertexSemantic::Position4}, - {filter.m_vbo.get(), nullptr, boo::VertexSemantic::UV4} - }; - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; - boo::ObjToken texs[] = {CGraphics::g_SpareTexture.get(), filter.m_booTex}; - return cctx.newShaderDataBinding(s_Pipeline, - ctx.newVertexFormat(2, VtxVmt), filter.m_vbo.get(), nullptr, nullptr, - 1, bufs, stages, nullptr, nullptr, 2, texs, nullptr, nullptr); - } -}; - -#if BOO_HAS_VULKAN -struct CXRayBlurFilterVulkanDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken - BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CXRayBlurFilter& filter) - { - boo::VulkanDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - boo::ObjToken texs[] = {CGraphics::g_SpareTexture.get(), filter.m_booTex.get()}; - return cctx.newShaderDataBinding(s_Pipeline, s_VtxFmt, - filter.m_vbo.get(), nullptr, nullptr, 1, bufs, - nullptr, nullptr, nullptr, 2, texs, nullptr, nullptr); - } -}; -#endif - -TShader::IDataBindingFactory* CXRayBlurFilter::Initialize(boo::GLDataFactory::Context& ctx) -{ - const char* texNames[] = {"sceneTex", "paletteTex"}; - const char* uniNames[] = {"XRayBlurUniform"}; - s_Pipeline = ctx.newShaderPipeline(VS, FS, 2, texNames, 1, uniNames, boo::BlendFactor::One, - boo::BlendFactor::Zero, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - return new CXRayBlurFilterGLDataBindingFactory; -} - -template <> -void CXRayBlurFilter::Shutdown() -{ - s_Pipeline.reset(); -} - -#if BOO_HAS_VULKAN -TShader::IDataBindingFactory* CXRayBlurFilter::Initialize(boo::VulkanDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::UV4} - }; - s_VtxFmt = ctx.newVertexFormat(2, VtxVmt); - s_Pipeline = ctx.newShaderPipeline(VS, FS, s_VtxFmt, boo::BlendFactor::One, - boo::BlendFactor::Zero, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - return new CXRayBlurFilterVulkanDataBindingFactory; -} - -template <> -void CXRayBlurFilter::Shutdown() -{ - s_VtxFmt.reset(); - s_Pipeline.reset(); -} -#endif - -} diff --git a/Runtime/Graphics/Shaders/CXRayBlurFilterHLSL.cpp b/Runtime/Graphics/Shaders/CXRayBlurFilterHLSL.cpp deleted file mode 100644 index 24a13f659..000000000 --- a/Runtime/Graphics/Shaders/CXRayBlurFilterHLSL.cpp +++ /dev/null @@ -1,136 +0,0 @@ -#include "CXRayBlurFilter.hpp" -#include "Graphics/CBooRenderer.hpp" -#include "GameGlobalObjects.hpp" - -namespace urde -{ - -static const char* VS = -"struct VertData\n" -"{\n" -" float4 posIn : POSITION;\n" -" float4 uvIn : UV;\n" -"};\n" -"\n" -"cbuffer XRayBlurUniform : register(b0)\n" -"{\n" -" float4x4 uv0;\n" -" float4x4 uv1;\n" -" float4x4 uv2;\n" -" float4x4 uv3;\n" -" float4x4 uv4;\n" -" float4x4 uv5;\n" -" float4x4 uv6;\n" -" float4x4 uv7;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float2 uv0 : UV0;\n" -" float2 uv1 : UV1;\n" -" float2 uv2 : UV2;\n" -" float2 uv3 : UV3;\n" -" float2 uv4 : UV4;\n" -" float2 uv5 : UV5;\n" -" float2 uv6 : UV6;\n" -" float2 uv7 : UV7;\n" -"};\n" -"\n" -"VertToFrag main(in VertData v)\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.uv0 = mul(uv0, float4(v.uvIn.xy, 0.0, 1.0)).xy;\n" -" vtf.uv0.y = 1.0 - vtf.uv0.y;\n" -" vtf.uv1 = mul(uv1, float4(v.uvIn.xy, 0.0, 1.0)).xy;\n" -" vtf.uv1.y = 1.0 - vtf.uv1.y;\n" -" vtf.uv2 = mul(uv2, float4(v.uvIn.xy, 0.0, 1.0)).xy;\n" -" vtf.uv2.y = 1.0 - vtf.uv2.y;\n" -" vtf.uv3 = mul(uv3, float4(v.uvIn.xy, 0.0, 1.0)).xy;\n" -" vtf.uv3.y = 1.0 - vtf.uv3.y;\n" -" vtf.uv4 = mul(uv4, float4(v.uvIn.xy, 0.0, 1.0)).xy;\n" -" vtf.uv4.y = 1.0 - vtf.uv4.y;\n" -" vtf.uv5 = mul(uv5, float4(v.uvIn.xy, 0.0, 1.0)).xy;\n" -" vtf.uv5.y = 1.0 - vtf.uv5.y;\n" -" vtf.uv6 = mul(uv6, float4(v.uvIn.xy, 0.0, 1.0)).xy;\n" -" vtf.uv6.y = 1.0 - vtf.uv6.y;\n" -" vtf.uv7 = mul(uv7, float4(v.uvIn.xy, 0.0, 1.0)).xy;\n" -" vtf.uv7.y = 1.0 - vtf.uv7.y;\n" -" vtf.position = float4(v.posIn.xyz, 1.0);\n" -" return vtf;\n" -"}\n"; - -static const char* FS = -"Texture2D sceneTex : register(t0);\n" -"Texture2D paletteTex : register(t1);\n" -"SamplerState samp : register(s3);\n" -"struct VertToFrag\n" -"{\n" -" float4 position : SV_Position;\n" -" float2 uv0 : UV0;\n" -" float2 uv1 : UV1;\n" -" float2 uv2 : UV2;\n" -" float2 uv3 : UV3;\n" -" float2 uv4 : UV4;\n" -" float2 uv5 : UV5;\n" -" float2 uv6 : UV6;\n" -" float2 uv7 : UV7;\n" -"};\n" -"\n" -"static const float4 kRGBToYPrime = float4(0.299, 0.587, 0.114, 0.0);\n" -"float4 main(in VertToFrag vtf) : SV_Target0\n" -"{\n" -" float4 colorSample = paletteTex.Sample(samp, float2(dot(sceneTex.Sample(samp, vtf.uv0), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125;\n" -" colorSample += paletteTex.Sample(samp, float2(dot(sceneTex.Sample(samp, vtf.uv1), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125;\n" -" colorSample += paletteTex.Sample(samp, float2(dot(sceneTex.Sample(samp, vtf.uv2), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125;\n" -" colorSample += paletteTex.Sample(samp, float2(dot(sceneTex.Sample(samp, vtf.uv3), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125;\n" -" colorSample += paletteTex.Sample(samp, float2(dot(sceneTex.Sample(samp, vtf.uv4), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125;\n" -" colorSample += paletteTex.Sample(samp, float2(dot(sceneTex.Sample(samp, vtf.uv5), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125;\n" -" colorSample += paletteTex.Sample(samp, float2(dot(sceneTex.Sample(samp, vtf.uv6), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125;\n" -" colorSample += paletteTex.Sample(samp, float2(dot(sceneTex.Sample(samp, vtf.uv7), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125;\n" -" return colorSample;\n" -"}\n"; - -URDE_DECL_SPECIALIZE_SHADER(CXRayBlurFilter) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_Pipeline; - -struct CXRayBlurFilterD3DDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken - BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CXRayBlurFilter& filter) - { - boo::D3DDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - boo::ObjToken texs[] = {CGraphics::g_SpareTexture.get(), filter.m_booTex.get()}; - return cctx.newShaderDataBinding(s_Pipeline, s_VtxFmt, - filter.m_vbo.get(), nullptr, nullptr, 1, bufs, - nullptr, nullptr, nullptr, 2, texs, nullptr, nullptr); - } -}; - -TShader::IDataBindingFactory* CXRayBlurFilter::Initialize(boo::D3DDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::UV4} - }; - s_VtxFmt = ctx.newVertexFormat(2, VtxVmt); - s_Pipeline = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, nullptr, - s_VtxFmt, boo::BlendFactor::One, - boo::BlendFactor::Zero, boo::Primitive::TriStrips, - boo::ZTest::None, false, true, false, boo::CullMode::None); - return new CXRayBlurFilterD3DDataBindingFactory; -} - -template <> -void CXRayBlurFilter::Shutdown() -{ - s_VtxFmt.reset(); - s_Pipeline.reset(); -} -} diff --git a/Runtime/Graphics/Shaders/CXRayBlurFilterMetal.cpp b/Runtime/Graphics/Shaders/CXRayBlurFilterMetal.cpp deleted file mode 100644 index 6e99054ff..000000000 --- a/Runtime/Graphics/Shaders/CXRayBlurFilterMetal.cpp +++ /dev/null @@ -1,140 +0,0 @@ -#include "CXRayBlurFilter.hpp" -#include "Graphics/CBooRenderer.hpp" -#include "GameGlobalObjects.hpp" - -namespace urde -{ - -static const char* VS = -"#include \n" -"using namespace metal;\n" -"struct VertData\n" -"{\n" -" float4 posIn [[ attribute(0) ]];\n" -" float4 uvIn [[ attribute(1) ]];\n" -"};\n" -"\n" -"struct XRayBlurUniform\n" -"{\n" -" float4x4 uv0;\n" -" float4x4 uv1;\n" -" float4x4 uv2;\n" -" float4x4 uv3;\n" -" float4x4 uv4;\n" -" float4x4 uv5;\n" -" float4x4 uv6;\n" -" float4x4 uv7;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float2 uv0;\n" -" float2 uv1;\n" -" float2 uv2;\n" -" float2 uv3;\n" -" float2 uv4;\n" -" float2 uv5;\n" -" float2 uv6;\n" -" float2 uv7;\n" -"};\n" -"\n" -"vertex VertToFrag vmain(VertData v [[ stage_in ]], constant XRayBlurUniform& xbu [[ buffer(2) ]])\n" -"{\n" -" VertToFrag vtf;\n" -" vtf.uv0 = (xbu.uv0 * float4(v.uvIn.xy, 0.0, 1.0)).xy;\n" -" vtf.uv0.y = 1.0 - vtf.uv0.y;\n" -" vtf.uv1 = (xbu.uv1 * float4(v.uvIn.xy, 0.0, 1.0)).xy;\n" -" vtf.uv1.y = 1.0 - vtf.uv1.y;\n" -" vtf.uv2 = (xbu.uv2 * float4(v.uvIn.xy, 0.0, 1.0)).xy;\n" -" vtf.uv2.y = 1.0 - vtf.uv2.y;\n" -" vtf.uv3 = (xbu.uv3 * float4(v.uvIn.xy, 0.0, 1.0)).xy;\n" -" vtf.uv3.y = 1.0 - vtf.uv3.y;\n" -" vtf.uv4 = (xbu.uv4 * float4(v.uvIn.xy, 0.0, 1.0)).xy;\n" -" vtf.uv4.y = 1.0 - vtf.uv4.y;\n" -" vtf.uv5 = (xbu.uv5 * float4(v.uvIn.xy, 0.0, 1.0)).xy;\n" -" vtf.uv5.y = 1.0 - vtf.uv5.y;\n" -" vtf.uv6 = (xbu.uv6 * float4(v.uvIn.xy, 0.0, 1.0)).xy;\n" -" vtf.uv6.y = 1.0 - vtf.uv6.y;\n" -" vtf.uv7 = (xbu.uv7 * float4(v.uvIn.xy, 0.0, 1.0)).xy;\n" -" vtf.uv7.y = 1.0 - vtf.uv7.y;\n" -" vtf.position = float4(v.posIn.xyz, 1.0);\n" -" return vtf;\n" -"}\n"; - -static const char* FS = -"#include \n" -"using namespace metal;\n" -"struct VertToFrag\n" -"{\n" -" float4 position [[ position ]];\n" -" float2 uv0;\n" -" float2 uv1;\n" -" float2 uv2;\n" -" float2 uv3;\n" -" float2 uv4;\n" -" float2 uv5;\n" -" float2 uv6;\n" -" float2 uv7;\n" -"};\n" -"\n" -"constant float4 kRGBToYPrime = float4(0.299, 0.587, 0.114, 0.0);\n" -"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n" -" sampler samp [[ sampler(3) ]],\n" -" texture2d sceneTex [[ texture(0) ]],\n" -" texture2d paletteTex [[ texture(1) ]])\n" -"{\n" -" float4 colorSample = paletteTex.sample(samp, float2(dot(sceneTex.sample(samp, vtf.uv0), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125;\n" -" colorSample += paletteTex.sample(samp, float2(dot(sceneTex.sample(samp, vtf.uv1), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125;\n" -" colorSample += paletteTex.sample(samp, float2(dot(sceneTex.sample(samp, vtf.uv2), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125;\n" -" colorSample += paletteTex.sample(samp, float2(dot(sceneTex.sample(samp, vtf.uv3), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125;\n" -" colorSample += paletteTex.sample(samp, float2(dot(sceneTex.sample(samp, vtf.uv4), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125;\n" -" colorSample += paletteTex.sample(samp, float2(dot(sceneTex.sample(samp, vtf.uv5), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125;\n" -" colorSample += paletteTex.sample(samp, float2(dot(sceneTex.sample(samp, vtf.uv6), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125;\n" -" colorSample += paletteTex.sample(samp, float2(dot(sceneTex.sample(samp, vtf.uv7), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125;\n" -" return colorSample;\n" -"}\n"; - -URDE_DECL_SPECIALIZE_SHADER(CXRayBlurFilter) - -static boo::ObjToken s_VtxFmt; -static boo::ObjToken s_Pipeline; - -struct CXRayBlurFilterMetalDataBindingFactory : TShader::IDataBindingFactory -{ - boo::ObjToken BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CXRayBlurFilter& filter) - { - boo::MetalDataFactory::Context& cctx = static_cast(ctx); - - boo::ObjToken bufs[] = {filter.m_uniBuf.get()}; - boo::ObjToken texs[] = {CGraphics::g_SpareTexture.get(), filter.m_booTex}; - return cctx.newShaderDataBinding(s_Pipeline, s_VtxFmt, - filter.m_vbo.get(), nullptr, nullptr, 1, bufs, - nullptr, nullptr, nullptr, 2, texs, nullptr, nullptr); - } -}; - -TShader::IDataBindingFactory* CXRayBlurFilter::Initialize(boo::MetalDataFactory::Context& ctx) -{ - const boo::VertexElementDescriptor VtxVmt[] = - { - {nullptr, nullptr, boo::VertexSemantic::Position4}, - {nullptr, nullptr, boo::VertexSemantic::UV4} - }; - s_VtxFmt = ctx.newVertexFormat(2, VtxVmt); - s_Pipeline = ctx.newShaderPipeline(VS, FS, nullptr, nullptr, - s_VtxFmt, boo::BlendFactor::One, - boo::BlendFactor::Zero, boo::Primitive::TriStrips, boo::ZTest::None, false, - true, false, boo::CullMode::None); - return new CXRayBlurFilterMetalDataBindingFactory; -} - -template <> -void CXRayBlurFilter::Shutdown() -{ - s_VtxFmt.reset(); - s_Pipeline.reset(); -} - -} diff --git a/Runtime/Graphics/Shaders/TMultiBlendShader.hpp b/Runtime/Graphics/Shaders/TMultiBlendShader.hpp deleted file mode 100644 index 586e3d6bc..000000000 --- a/Runtime/Graphics/Shaders/TMultiBlendShader.hpp +++ /dev/null @@ -1,111 +0,0 @@ -#ifndef __URDE_TMULTIBLENDSHADER_HPP__ -#define __URDE_TMULTIBLENDSHADER_HPP__ - -#include "Graphics/CGraphics.hpp" -#include "boo/graphicsdev/GL.hpp" -#include "boo/graphicsdev/D3D.hpp" -#include "boo/graphicsdev/Metal.hpp" -#include "boo/graphicsdev/Vulkan.hpp" -#include "Camera/CCameraFilter.hpp" - -namespace urde -{ - -template -class TMultiBlendShader -{ -public: - struct IDataBindingFactory - { - virtual boo::ObjToken BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - EFilterType type, ShaderImp& filter)=0; - virtual ~IDataBindingFactory() = default; - }; - - static std::unique_ptr m_bindFactory; - - static void Initialize() - { - if (!CGraphics::g_BooFactory) - return; - - CGraphics::CommitResources( - [&](boo::IGraphicsDataFactory::Context& ctx) - { - switch (ctx.platform()) - { -#if BOO_HAS_GL - case boo::IGraphicsDataFactory::Platform::OpenGL: - m_bindFactory.reset(ShaderImp::Initialize(static_cast(ctx))); - break; -#endif -#if _WIN32 - case boo::IGraphicsDataFactory::Platform::D3D11: - m_bindFactory.reset(ShaderImp::Initialize(static_cast(ctx))); - break; -#endif -#if BOO_HAS_METAL - case boo::IGraphicsDataFactory::Platform::Metal: - m_bindFactory.reset(ShaderImp::Initialize(static_cast(ctx))); - break; -#endif -#if BOO_HAS_VULKAN - case boo::IGraphicsDataFactory::Platform::Vulkan: - m_bindFactory.reset(ShaderImp::Initialize(static_cast(ctx))); - break; -#endif - default: break; - } - return true; - } BooTrace); - } - - static void Shutdown() - { - switch (CGraphics::g_BooFactory->platform()) - { -#if BOO_HAS_GL - case boo::IGraphicsDataFactory::Platform::OpenGL: - ShaderImp::template Shutdown(); - break; -#endif -#if _WIN32 - case boo::IGraphicsDataFactory::Platform::D3D11: - ShaderImp::template Shutdown(); - break; -#endif -#if BOO_HAS_METAL - case boo::IGraphicsDataFactory::Platform::Metal: - ShaderImp::template Shutdown(); - break; -#endif -#if BOO_HAS_VULKAN - case boo::IGraphicsDataFactory::Platform::Vulkan: - ShaderImp::template Shutdown(); - break; -#endif - default: break; - } - } - - static boo::ObjToken - BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - EFilterType type, ShaderImp& filter) - { - return m_bindFactory->BuildShaderDataBinding(ctx, type, filter); - } -}; - -#define URDE_DECL_SPECIALIZE_MULTI_BLEND_SHADER(cls) \ -template <> std::unique_ptr::IDataBindingFactory> \ -TMultiBlendShader::m_bindFactory; \ - -#define URDE_SPECIALIZE_MULTI_BLEND_SHADER(cls) \ -template <> std::unique_ptr::IDataBindingFactory> \ -TMultiBlendShader::m_bindFactory = {}; \ -\ -template class TMultiBlendShader; - -} - -#endif // __URDE_TMULTIBLENDSHADER_HPP__ diff --git a/Runtime/Graphics/Shaders/TMultiBlendShaderDecl.hpp b/Runtime/Graphics/Shaders/TMultiBlendShaderDecl.hpp deleted file mode 100644 index 3a41aee18..000000000 --- a/Runtime/Graphics/Shaders/TMultiBlendShaderDecl.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#if BOO_HAS_GL -static TMultiBlendShader<_CLS>::IDataBindingFactory* Initialize(boo::GLDataFactory::Context& ctx); -#endif -#if _WIN32 -static TMultiBlendShader<_CLS>::IDataBindingFactory* Initialize(boo::D3DDataFactory::Context& ctx); -#endif -#if BOO_HAS_METAL -static TMultiBlendShader<_CLS>::IDataBindingFactory* Initialize(boo::MetalDataFactory::Context& ctx); -#endif -#if BOO_HAS_VULKAN -static TMultiBlendShader<_CLS>::IDataBindingFactory* Initialize(boo::VulkanDataFactory::Context& ctx); -#endif -template static void Shutdown(); diff --git a/Runtime/Graphics/Shaders/TShader.hpp b/Runtime/Graphics/Shaders/TShader.hpp deleted file mode 100644 index 8fc6aa9f1..000000000 --- a/Runtime/Graphics/Shaders/TShader.hpp +++ /dev/null @@ -1,109 +0,0 @@ -#ifndef __URDE_TSHADER_HPP__ -#define __URDE_TSHADER_HPP__ - -#include "Graphics/CGraphics.hpp" -#include "boo/graphicsdev/GL.hpp" -#include "boo/graphicsdev/D3D.hpp" -#include "boo/graphicsdev/Metal.hpp" -#include "boo/graphicsdev/Vulkan.hpp" - -namespace urde -{ - -template -class TShader -{ -public: - struct IDataBindingFactory - { - virtual boo::ObjToken BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - ShaderImp& filter)=0; - virtual ~IDataBindingFactory() = default; - }; - - static std::unique_ptr m_bindFactory; - - static void Initialize() - { - if (!CGraphics::g_BooFactory) - return; - - CGraphics::CommitResources( - [&](boo::IGraphicsDataFactory::Context& ctx) - { - switch (ctx.platform()) - { -#if BOO_HAS_GL - case boo::IGraphicsDataFactory::Platform::OpenGL: - m_bindFactory.reset(ShaderImp::Initialize(static_cast(ctx))); - break; -#endif -#if _WIN32 - case boo::IGraphicsDataFactory::Platform::D3D11: - m_bindFactory.reset(ShaderImp::Initialize(static_cast(ctx))); - break; -#endif -#if BOO_HAS_METAL - case boo::IGraphicsDataFactory::Platform::Metal: - m_bindFactory.reset(ShaderImp::Initialize(static_cast(ctx))); - break; -#endif -#if BOO_HAS_VULKAN - case boo::IGraphicsDataFactory::Platform::Vulkan: - m_bindFactory.reset(ShaderImp::Initialize(static_cast(ctx))); - break; -#endif - default: break; - } - return true; - } BooTrace); - } - - static void Shutdown() - { - switch (CGraphics::g_BooFactory->platform()) - { -#if BOO_HAS_GL - case boo::IGraphicsDataFactory::Platform::OpenGL: - ShaderImp::template Shutdown(); - break; -#endif -#if _WIN32 - case boo::IGraphicsDataFactory::Platform::D3D11: - ShaderImp::template Shutdown(); - break; -#endif -#if BOO_HAS_METAL - case boo::IGraphicsDataFactory::Platform::Metal: - ShaderImp::template Shutdown(); - break; -#endif -#if BOO_HAS_VULKAN - case boo::IGraphicsDataFactory::Platform::Vulkan: - ShaderImp::template Shutdown(); - break; -#endif - default: break; - } - } - - static boo::ObjToken - BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, ShaderImp& filter) - { - return m_bindFactory->BuildShaderDataBinding(ctx, filter); - } -}; - -#define URDE_DECL_SPECIALIZE_SHADER(cls) \ -template <> std::unique_ptr::IDataBindingFactory> \ -TShader::m_bindFactory; - -#define URDE_SPECIALIZE_SHADER(cls) \ -template <> std::unique_ptr::IDataBindingFactory> \ -TShader::m_bindFactory = {}; \ -\ -template class TShader; - -} - -#endif // __URDE_TSHADER_HPP__ diff --git a/Runtime/Graphics/Shaders/TShaderDecl.hpp b/Runtime/Graphics/Shaders/TShaderDecl.hpp deleted file mode 100644 index 60517250b..000000000 --- a/Runtime/Graphics/Shaders/TShaderDecl.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#if BOO_HAS_GL -static TShader<_CLS>::IDataBindingFactory* Initialize(boo::GLDataFactory::Context& ctx); -#endif -#if _WIN32 -static TShader<_CLS>::IDataBindingFactory* Initialize(boo::D3DDataFactory::Context& ctx); -#endif -#if BOO_HAS_METAL -static TShader<_CLS>::IDataBindingFactory* Initialize(boo::MetalDataFactory::Context& ctx); -#endif -#if BOO_HAS_VULKAN -static TShader<_CLS>::IDataBindingFactory* Initialize(boo::VulkanDataFactory::Context& ctx); -#endif -template static void Shutdown(); diff --git a/Runtime/GuiSys/CTextRenderBuffer.cpp b/Runtime/GuiSys/CTextRenderBuffer.cpp index 9f0fee1ad..5ceaff363 100644 --- a/Runtime/GuiSys/CTextRenderBuffer.cpp +++ b/Runtime/GuiSys/CTextRenderBuffer.cpp @@ -70,34 +70,13 @@ void CTextRenderBuffer::CommitResources() chs.m_instBuf = CTextSupportShader::s_CharInsts.allocateBlock(CGraphics::g_BooFactory, chs.m_charCount); auto iBufInfo = chs.m_instBuf.getBufferInfo(); - boo::ObjToken vFmt = CTextSupportShader::s_TextVtxFmt; - if (ctx.bindingNeedsVertexFormat()) - { - boo::ObjToken buf = iBufInfo.first; - boo::VertexElementDescriptor elems[] = - { - {buf.get(), nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 0}, - {buf.get(), nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 1}, - {buf.get(), nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 2}, - {buf.get(), nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 3}, - {buf.get(), nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 0}, - {buf.get(), nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 1}, - {buf.get(), nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 2}, - {buf.get(), nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 3}, - {buf.get(), nullptr, boo::VertexSemantic::Color | boo::VertexSemantic::Instanced, 0}, - {buf.get(), nullptr, boo::VertexSemantic::Color | boo::VertexSemantic::Instanced, 1}, - {buf.get(), nullptr, boo::VertexSemantic::Color | boo::VertexSemantic::Instanced, 2}, - }; - vFmt = ctx.newVertexFormat(11, elems, 0, iBufInfo.second); - } - boo::ObjToken uniforms[] = {uBufInfo.first.get()}; boo::PipelineStage unistages[] = {boo::PipelineStage::Vertex}; size_t unioffs[] = {size_t(uBufInfo.second)}; size_t unisizes[] = {sizeof(CTextSupportShader::Uniform)}; boo::ObjToken texs[] = {chs.m_font->GetTexture()}; chs.m_dataBinding = ctx.newShaderDataBinding(CTextSupportShader::SelectTextPipeline(m_drawFlags), - vFmt, nullptr, iBufInfo.first.get(), nullptr, + nullptr, iBufInfo.first.get(), nullptr, 1, uniforms, unistages, unioffs, unisizes, 1, texs, nullptr, nullptr, 0, iBufInfo.second); @@ -106,7 +85,7 @@ void CTextRenderBuffer::CommitResources() uniforms[0] = uBufInfo2.first.get(); unioffs[0] = size_t(uBufInfo2.second); chs.m_dataBinding2 = ctx.newShaderDataBinding(CTextSupportShader::GetTextAdditiveOverdrawPipeline(), - vFmt, nullptr, iBufInfo.first.get(), nullptr, + nullptr, iBufInfo.first.get(), nullptr, 1, uniforms, unistages, unioffs, unisizes, 1, texs, nullptr, nullptr, 0, iBufInfo.second); } @@ -117,25 +96,6 @@ void CTextRenderBuffer::CommitResources() img.m_instBuf = CTextSupportShader::s_ImgInsts.allocateBlock(CGraphics::g_BooFactory, 1); auto iBufInfo = img.m_instBuf.getBufferInfo(); - boo::ObjToken vFmt = CTextSupportShader::s_ImageVtxFmt; - if (ctx.bindingNeedsVertexFormat()) - { - boo::ObjToken buf = iBufInfo.first; - boo::VertexElementDescriptor elems[] = - { - {buf.get(), nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 0}, - {buf.get(), nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 1}, - {buf.get(), nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 2}, - {buf.get(), nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 3}, - {buf.get(), nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 0}, - {buf.get(), nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 1}, - {buf.get(), nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 2}, - {buf.get(), nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 3}, - {buf.get(), nullptr, boo::VertexSemantic::Color | boo::VertexSemantic::Instanced, 0}, - }; - vFmt = ctx.newVertexFormat(9, elems, 0, iBufInfo.second); - } - boo::ObjToken uniforms[] = {uBufInfo.first.get()}; boo::PipelineStage unistages[] = {boo::PipelineStage::Vertex}; size_t unioffs[] = {size_t(uBufInfo.second)}; @@ -146,7 +106,7 @@ void CTextRenderBuffer::CommitResources() boo::ObjToken texs[] = {tex->GetBooTexture()}; texs[0]->setClampMode(boo::TextureClampMode::ClampToEdge); img.m_dataBinding.push_back(ctx.newShaderDataBinding(CTextSupportShader::SelectImagePipeline(m_drawFlags), - vFmt, nullptr, iBufInfo.first.get(), nullptr, + nullptr, iBufInfo.first.get(), nullptr, 1, uniforms, unistages, unioffs, unisizes, 1, texs, nullptr, nullptr, 0, iBufInfo.second)); } @@ -160,7 +120,7 @@ void CTextRenderBuffer::CommitResources() { boo::ObjToken texs[] = {tex->GetBooTexture()}; img.m_dataBinding2.push_back(ctx.newShaderDataBinding(CTextSupportShader::GetImageAdditiveOverdrawPipeline(), - vFmt, nullptr, iBufInfo.first.get(), nullptr, + nullptr, iBufInfo.first.get(), nullptr, 1, uniforms, unistages, unioffs, unisizes, 1, texs, nullptr, nullptr, 0, iBufInfo.second)); } diff --git a/Runtime/IMain.hpp b/Runtime/IMain.hpp index 0c90571fd..4d4211514 100644 --- a/Runtime/IMain.hpp +++ b/Runtime/IMain.hpp @@ -1,10 +1,9 @@ #ifndef __URDE_IMAIN_HPP__ #define __URDE_IMAIN_HPP__ -#include -#include -#include -#include -#include +#include "boo/boo.hpp" +#include "boo/audiodev/IAudioVoiceEngine.hpp" +#include "hecl/Runtime.hpp" +#include "amuse/amuse.hpp" #include "RetroTypes.hpp" namespace hecl @@ -15,7 +14,7 @@ class Console; namespace urde { -class CStopWatch; +class CStopwatch; enum class EGameplayResult { None, diff --git a/Runtime/Input/CInputGenerator.hpp b/Runtime/Input/CInputGenerator.hpp index e98a2873b..82b0a7174 100644 --- a/Runtime/Input/CInputGenerator.hpp +++ b/Runtime/Input/CInputGenerator.hpp @@ -51,7 +51,7 @@ class CInputGenerator : public boo::DeviceFinder bool m_firstFrame = true; public: CInputGenerator(float leftDiv, float rightDiv) - : boo::DeviceFinder({typeid(boo::DolphinSmashAdapter)}), + : boo::DeviceFinder({dev_typeid(DolphinSmashAdapter)}), m_leftDiv(leftDiv), m_rightDiv(rightDiv) {} @@ -184,9 +184,12 @@ public: /* Device listener thread */ if (!smashAdapter) { - smashAdapter = std::dynamic_pointer_cast(tok.openAndGetDevice()); - if (smashAdapter) + auto dev = tok.openAndGetDevice(); + if (dev && dev->getTypeHash() == dev_typeid(DolphinSmashAdapter)) + { + smashAdapter = std::static_pointer_cast(tok.openAndGetDevice()); smashAdapter->setCallback(&m_dolphinCb); + } } } void deviceDisconnected(boo::DeviceToken&, boo::DeviceBase* device) diff --git a/Runtime/MP1/MP1.cpp b/Runtime/MP1/MP1.cpp index 2bb2d3799..caf16e8b0 100644 --- a/Runtime/MP1/MP1.cpp +++ b/Runtime/MP1/MP1.cpp @@ -57,6 +57,7 @@ #include "MP1OriginalIDs.hpp" #include "CStateManager.hpp" #include "World/CPlayer.hpp" +#include "CStopwatch.hpp" #include namespace hecl @@ -67,27 +68,6 @@ namespace hecl namespace urde { -URDE_DECL_SPECIALIZE_SHADER(CParticleSwooshShaders) -URDE_DECL_SPECIALIZE_SHADER(CThermalColdFilter) -URDE_DECL_SPECIALIZE_SHADER(CThermalHotFilter) -URDE_DECL_SPECIALIZE_SHADER(CSpaceWarpFilter) -URDE_DECL_SPECIALIZE_SHADER(CCameraBlurFilter) -URDE_DECL_SPECIALIZE_SHADER(CXRayBlurFilter) -URDE_DECL_SPECIALIZE_SHADER(CFogVolumePlaneShader) -URDE_DECL_SPECIALIZE_SHADER(CFogVolumeFilter) -URDE_DECL_SPECIALIZE_SHADER(CEnergyBarShader) -URDE_DECL_SPECIALIZE_SHADER(CRadarPaintShader) -URDE_DECL_SPECIALIZE_SHADER(CMapSurfaceShader) -URDE_DECL_SPECIALIZE_SHADER(CPhazonSuitFilter) -URDE_DECL_SPECIALIZE_SHADER(CAABoxShader) -URDE_DECL_SPECIALIZE_SHADER(CWorldShadowShader) -URDE_DECL_SPECIALIZE_MULTI_BLEND_SHADER(CColoredQuadFilter) -URDE_DECL_SPECIALIZE_MULTI_BLEND_SHADER(CTexturedQuadFilter) -URDE_DECL_SPECIALIZE_MULTI_BLEND_SHADER(CTexturedQuadFilterAlpha) -URDE_DECL_SPECIALIZE_MULTI_BLEND_SHADER(CTextSupportShader) -URDE_DECL_SPECIALIZE_MULTI_BLEND_SHADER(CScanLinesFilter) -URDE_DECL_SPECIALIZE_MULTI_BLEND_SHADER(CRandomStaticFilter) - namespace MP1 { @@ -286,27 +266,29 @@ CMain::BooSetter::BooSetter(boo::IGraphicsDataFactory* factory, const boo::ObjToken& spareTex) { CGraphics::InitializeBoo(factory, cmdQ, spareTex); - TShader::Initialize(); - TShader::Initialize(); - TShader::Initialize(); - TShader::Initialize(); - TShader::Initialize(); - TShader::Initialize(); - TShader::Initialize(); - TShader::Initialize(); - TShader::Initialize(); - TShader::Initialize(); - TShader::Initialize(); - TShader::Initialize(); - TShader::Initialize(); - TShader::Initialize(); - TMultiBlendShader::Initialize(); - TMultiBlendShader::Initialize(); - TMultiBlendShader::Initialize(); - TMultiBlendShader::Initialize(); - TMultiBlendShader::Initialize(); - TMultiBlendShader::Initialize(); + CStopwatch sw; + CParticleSwooshShaders::Initialize(); + CThermalColdFilter::Initialize(); + CThermalHotFilter::Initialize(); + CSpaceWarpFilter::Initialize(); + CCameraBlurFilter::Initialize(); + CXRayBlurFilter::Initialize(); + CFogVolumePlaneShader::Initialize(); + CFogVolumeFilter::Initialize(); + CEnergyBarShader::Initialize(); + CRadarPaintShader::Initialize(); + CMapSurfaceShader::Initialize(); + CPhazonSuitFilter::Initialize(); + CAABoxShader::Initialize(); + CWorldShadowShader::Initialize(); + CColoredQuadFilter::Initialize(); + CTexturedQuadFilter::Initialize(); + CTexturedQuadFilterAlpha::Initialize(); + CTextSupportShader::Initialize(); + CScanLinesFilter::Initialize(); + CRandomStaticFilter::Initialize(); CNESShader::Initialize(); + sw.report("shad init"); } void CMain::RegisterResourceTweaks() @@ -404,10 +386,10 @@ void CMain::ResetGameState() g_GameState->GetPlayerState()->SetIsFusionEnabled(g_GameState->SystemOptions().GetPlayerFusionSuitActive()); } -void CMain::InitializeSubsystems(const hecl::Runtime::FileStoreManager& storeMgr) +void CMain::InitializeSubsystems() { CBasics::Initialize(); - CModelShaders::Initialize(storeMgr, CGraphics::g_BooFactory); + CModelShaders::Initialize(); CMoviePlayer::Initialize(); CLineRenderer::Initialize(); CElementGen::Initialize(); @@ -670,7 +652,7 @@ void CMain::Init(const hecl::Runtime::FileStoreManager& storeMgr, m_console->registerCommand("God"sv, "Disables damage given by enemies and objects"sv, ""sv, std::bind(&CMain::God, this, std::placeholders::_1, std::placeholders::_2), hecl::SConsoleCommand::ECommandFlags::Cheat); m_console->registerCommand("listWorlds"sv, "Lists loaded worlds"sv, ""sv, std::bind(&CMain::ListWorlds, this, std::placeholders::_1, std::placeholders::_2), hecl::SConsoleCommand::ECommandFlags::Normal); - InitializeSubsystems(storeMgr); + InitializeSubsystems(); x128_globalObjects.PostInitialize(); x70_tweaks.RegisterTweaks(m_cvarMgr); x70_tweaks.RegisterResourceTweaks(m_cvarMgr); @@ -811,26 +793,26 @@ void CMain::Shutdown() m_console->unregisterCommand("Give"); x164_archSupport.reset(); ShutdownSubsystems(); - TShader::Shutdown(); - TShader::Shutdown(); - TShader::Shutdown(); - TShader::Shutdown(); - TShader::Shutdown(); - TShader::Shutdown(); - TShader::Shutdown(); - TShader::Shutdown(); - TShader::Shutdown(); - TShader::Shutdown(); - TShader::Shutdown(); - TShader::Shutdown(); - TShader::Shutdown(); - TShader::Shutdown(); - TMultiBlendShader::Shutdown(); - TMultiBlendShader::Shutdown(); - TMultiBlendShader::Shutdown(); - TMultiBlendShader::Shutdown(); - TMultiBlendShader::Shutdown(); - TMultiBlendShader::Shutdown(); + CParticleSwooshShaders::Shutdown(); + CThermalColdFilter::Shutdown(); + CThermalHotFilter::Shutdown(); + CSpaceWarpFilter::Shutdown(); + CCameraBlurFilter::Shutdown(); + CXRayBlurFilter::Shutdown(); + CFogVolumePlaneShader::Shutdown(); + CFogVolumeFilter::Shutdown(); + CEnergyBarShader::Shutdown(); + CRadarPaintShader::Shutdown(); + CMapSurfaceShader::Shutdown(); + CPhazonSuitFilter::Shutdown(); + CAABoxShader::Shutdown(); + CWorldShadowShader::Shutdown(); + CColoredQuadFilter::Shutdown(); + CTexturedQuadFilter::Shutdown(); + CTexturedQuadFilterAlpha::Shutdown(); + CTextSupportShader::Shutdown(); + CScanLinesFilter::Shutdown(); + CRandomStaticFilter::Shutdown(); CFluidPlaneShader::Shutdown(); CFluidPlaneManager::RippleMapTex.reset(); CNESShader::Shutdown(); diff --git a/Runtime/MP1/MP1.hpp b/Runtime/MP1/MP1.hpp index bcd8193d4..5838abddd 100644 --- a/Runtime/MP1/MP1.hpp +++ b/Runtime/MP1/MP1.hpp @@ -266,7 +266,7 @@ private: bool m_needsWarmupClear = false; bool m_doQuit = false; - void InitializeSubsystems(const hecl::Runtime::FileStoreManager& storeMgr); + void InitializeSubsystems(); static void InitializeDiscord(); static void ShutdownDiscord(); static void HandleDiscordReady(const DiscordUser* request); @@ -305,7 +305,7 @@ public: bool CheckReset() { return m_doQuit; } bool CheckTerminate() { return m_doQuit; } - void DrawDebugMetrics(double, CStopWatch&) {} + void DrawDebugMetrics(double, CStopwatch&) {} void DoPredrawMetrics() {} void FillInAssetIDs(); bool LoadAudio(); diff --git a/Runtime/Particle/CDecalManager.cpp b/Runtime/Particle/CDecalManager.cpp index d1cbe1072..8dbf3b247 100644 --- a/Runtime/Particle/CDecalManager.cpp +++ b/Runtime/Particle/CDecalManager.cpp @@ -16,8 +16,6 @@ CAssetId CDecalManager::m_LastDecalCreatedAssetId = -1; rstl::reserved_vector CDecalManager::m_DecalPool; rstl::reserved_vector CDecalManager::m_ActiveIndexList; -URDE_DECL_SPECIALIZE_SHADER(CDecalShaders) - void CDecalManager::Initialize() { if (m_PoolInitialized) @@ -34,7 +32,7 @@ void CDecalManager::Initialize() m_LastDecalCreatedAssetId = -1; /* Compile shaders */ - TShader::Initialize(); + CDecalShaders::Initialize(); } void CDecalManager::Reinitialize() @@ -55,7 +53,7 @@ void CDecalManager::Shutdown() { m_ActiveIndexList.clear(); m_DecalPool.clear(); - TShader::Shutdown(); + CDecalShaders::Shutdown(); } void CDecalManager::AddToRenderer(const zeus::CFrustum& frustum, const CStateManager& mgr) diff --git a/Runtime/Particle/CElementGen.cpp b/Runtime/Particle/CElementGen.cpp index bb2c56d0c..38b3156c1 100644 --- a/Runtime/Particle/CElementGen.cpp +++ b/Runtime/Particle/CElementGen.cpp @@ -16,8 +16,6 @@ namespace urde { static logvisor::Module Log("urde::CElementGen"); -URDE_DECL_SPECIALIZE_SHADER(CElementGenShaders) - u16 CElementGen::g_GlobalSeed = 99; bool CElementGen::g_subtractBlend = false; @@ -41,12 +39,12 @@ void CElementGen::Initialize() g_ParticleSystemInitialized = true; /* Compile shaders */ - TShader::Initialize(); + CElementGenShaders::Initialize(); } void CElementGen::Shutdown() { - TShader::Shutdown(); + CElementGenShaders::Shutdown(); } static const size_t ShadClsSizes[] = diff --git a/Runtime/Particle/CParticleSwoosh.cpp b/Runtime/Particle/CParticleSwoosh.cpp index 5f0b6ec99..4b9b38b7b 100644 --- a/Runtime/Particle/CParticleSwoosh.cpp +++ b/Runtime/Particle/CParticleSwoosh.cpp @@ -6,8 +6,6 @@ namespace urde { -URDE_DECL_SPECIALIZE_SHADER(CParticleSwooshShaders) - int CParticleSwoosh::g_ParticleSystemAliveCount = 0; CParticleSwoosh::CParticleSwoosh(const TToken& desc, int leng) diff --git a/Runtime/Particle/CParticleSwoosh.hpp b/Runtime/Particle/CParticleSwoosh.hpp index 81fa984d9..e59e3130c 100644 --- a/Runtime/Particle/CParticleSwoosh.hpp +++ b/Runtime/Particle/CParticleSwoosh.hpp @@ -16,10 +16,7 @@ class CSwooshDescription; class CParticleSwoosh : public CParticleGen { - friend struct OGLParticleSwooshDataBindingFactory; - friend struct VulkanParticleSwooshDataBindingFactory; - friend struct D3DParticleSwooshDataBindingFactory; - friend struct MetalParticleSwooshDataBindingFactory; + friend class CParticleSwooshShaders; struct SSwooshData { diff --git a/Runtime/World/CFluidPlaneManager.hpp b/Runtime/World/CFluidPlaneManager.hpp index 28ac9a20d..f311f0b03 100644 --- a/Runtime/World/CFluidPlaneManager.hpp +++ b/Runtime/World/CFluidPlaneManager.hpp @@ -8,16 +8,6 @@ namespace urde { -enum class EFluidType -{ - NormalWater, - PoisonWater, - Lava, - PhazonFluid, - Four, - ThickLava -}; - class CStateManager; class CScriptWater; diff --git a/Runtime/World/CGameArea.cpp b/Runtime/World/CGameArea.cpp index 5c3ce2396..101fe00aa 100644 --- a/Runtime/World/CGameArea.cpp +++ b/Runtime/World/CGameArea.cpp @@ -1260,13 +1260,11 @@ void CGameArea::FillInStaticGeometry(bool textures) boo::ObjToken vbo; boo::ObjToken ibo; - boo::ObjToken vtxFmt; vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, secIt->first, inst.m_hmdlMeta.vertStride, inst.m_hmdlMeta.vertCount); ++secIt; ibo = ctx.newStaticBuffer(boo::BufferUse::Index, secIt->first, 4, inst.m_hmdlMeta.indexCount); ++secIt; - vtxFmt = hecl::Runtime::HMDLData::NewVertexFormat(ctx, inst.m_hmdlMeta, vbo.get(), ibo.get()); u32 surfCount = hecl::SBig(*reinterpret_cast(secIt->first)); inst.m_surfaces.reserve(surfCount); @@ -1284,7 +1282,7 @@ void CGameArea::FillInStaticGeometry(bool textures) TToken nullModel; inst.m_instance = std::make_unique - (nullModel, nullptr, &inst.m_surfaces, matSet, vtxFmt, vbo, ibo, + (nullModel, nullptr, &inst.m_surfaces, matSet, vbo, ibo, inst.x34_aabb, inst.x0_visorFlags, 0, nullptr); } diff --git a/Shaders/CAABoxShader.shader b/Shaders/CAABoxShader.shader new file mode 100644 index 000000000..fe7287639 --- /dev/null +++ b/Shaders/CAABoxShader.shader @@ -0,0 +1,125 @@ +#shader CAABoxShader +#attribute position4 +#srcfac srcalpha +#dstfac invsrcalpha +#primitive tristrips +#depthtest lequal +#depthwrite true +#culling none + + +#vertex glsl +layout(location=0) in vec4 posIn; + +UBINDING0 uniform CAABoxUniform +{ + mat4 xf; + vec4 color; +}; + +struct VertToFrag +{ + vec4 color; +}; + +SBINDING(0) out VertToFrag vtf; +void main() +{ + vtf.color = color; + gl_Position = xf * vec4(posIn.xyz, 1.0); +} + +#fragment glsl +struct VertToFrag +{ + vec4 color; +}; + +SBINDING(0) in VertToFrag vtf; +layout(location=0) out vec4 colorOut; +void main() +{ + colorOut = vtf.color; +} + + +#vertex hlsl +struct VertData +{ + float4 posIn : POSITION; +}; + +cbuffer CAABoxUniform : register(b0) +{ + float4x4 xf; + float4 color; +}; + +struct VertToFrag +{ + float4 pos : SV_Position; + float4 color : COLOR; +}; + +VertToFrag main(in VertData v) +{ + VertToFrag vtf; + vtf.color = color; + vtf.pos = mul(xf, float4(v.posIn.xyz, 1.0)); + return vtf; +} + +#fragment hlsl +struct VertToFrag +{ + float4 pos : SV_Position; + float4 color : COLOR; +}; + +float4 main(in VertToFrag vtf) : SV_Target0 +{ + return vtf.color; +} + + +#vertex metal +struct VertData +{ + float4 posIn [[ attribute(0) ]]; +}; + +struct CAABoxUniform +{ + float4x4 xf; + float4 color; +}; + +struct VertToFrag +{ + float4 pos [[ position ]]; + float4 color; +}; + +vertex VertToFrag vmain(VertData v [[ stage_in ]], constant CAABoxUniform& bu [[ buffer(2) ]]) +{ + VertToFrag vtf; + vtf.color = bu.color; + vtf.pos = bu.xf * float4(v.posIn.xyz, 1.0); + return vtf; +} + +#fragment metal +"struct VertToFrag +{ + float4 pos [[ position ]]; + float4 color; +}; + +fragment float4 fmain(VertToFrag vtf [[ stage_in ]]) +{ + return vtf.color; +} + + +#shader CAABoxShaderZOnly : CAABoxShader +#colorwrite false diff --git a/Shaders/CCameraBlurFilter.shader b/Shaders/CCameraBlurFilter.shader new file mode 100644 index 000000000..d9f7dac3d --- /dev/null +++ b/Shaders/CCameraBlurFilter.shader @@ -0,0 +1,242 @@ +#shader CCameraBlurFilter +#attribute position4 +#attribute uv4 +#srcfac srcalpha +#dstfac invsrcalpha +#primitive tristrips +#depthtest none +#depthwrite false +#culling none + + +#vertex glsl +layout(location=0) in vec4 posIn; +layout(location=1) in vec4 uvIn; + +UBINDING0 uniform CameraBlurUniform +{ + vec4 uv0; + vec4 uv1; + vec4 uv2; + vec4 uv3; + vec4 uv4; + vec4 uv5; + float opacity; +}; + +struct VertToFrag +{ + vec2 uvReg; + vec2 uv0; + vec2 uv1; + vec2 uv2; + vec2 uv3; + vec2 uv4; + vec2 uv5; + float opacity; +}; + +SBINDING(0) out VertToFrag vtf; +void main() +{ + vtf.uvReg = uvIn.xy; + vtf.uv0 = uv0.xy + uvIn.xy; + vtf.uv1 = uv1.xy + uvIn.xy; + vtf.uv2 = uv2.xy + uvIn.xy; + vtf.uv3 = uv3.xy + uvIn.xy; + vtf.uv4 = uv4.xy + uvIn.xy; + vtf.uv5 = uv5.xy + uvIn.xy; + vtf.opacity = opacity; + gl_Position = vec4(posIn.xyz, 1.0); +} + +#fragment glsl +struct VertToFrag +{ + vec2 uvReg; + vec2 uv0; + vec2 uv1; + vec2 uv2; + vec2 uv3; + vec2 uv4; + vec2 uv5; + float opacity; +}; + +SBINDING(0) in VertToFrag vtf; +layout(location=0) out vec4 colorOut; +TBINDING0 uniform sampler2D sceneTex; +void main() +{ + vec4 colorSample = texture(sceneTex, vtf.uvReg) * 0.14285715; + colorSample += texture(sceneTex, vtf.uv0) * 0.14285715; + colorSample += texture(sceneTex, vtf.uv1) * 0.14285715; + colorSample += texture(sceneTex, vtf.uv2) * 0.14285715; + colorSample += texture(sceneTex, vtf.uv3) * 0.14285715; + colorSample += texture(sceneTex, vtf.uv4) * 0.14285715; + colorSample += texture(sceneTex, vtf.uv5) * 0.14285715; + colorOut = vec4(colorSample.rgb, vtf.opacity); +} + + +#vertex hlsl +struct VertData +{ + float4 posIn : POSITION; + float4 uvIn : UV; +}; + +cbuffer CameraBlurUniform : register(b0) +{ + float4 uv0; + float4 uv1; + float4 uv2; + float4 uv3; + float4 uv4; + float4 uv5; + float opacity; +}; + +struct VertToFrag +{ + float4 position : SV_Position; + float2 uvReg : UV6; + float2 uv0 : UV0; + float2 uv1 : UV1; + float2 uv2 : UV2; + float2 uv3 : UV3; + float2 uv4 : UV4; + float2 uv5 : UV5; + float opacity : OPACITY; +}; + +VertToFrag main(in VertData v) +{ + VertToFrag vtf; + vtf.uvReg = v.uvIn.xy; + vtf.uvReg.y = 1.0 - vtf.uvReg.y; + vtf.uv0 = uv0.xy + v.uvIn.xy; + vtf.uv0.y = 1.0 - vtf.uv0.y; + vtf.uv1 = uv1.xy + v.uvIn.xy; + vtf.uv1.y = 1.0 - vtf.uv1.y; + vtf.uv2 = uv2.xy + v.uvIn.xy; + vtf.uv2.y = 1.0 - vtf.uv2.y; + vtf.uv3 = uv3.xy + v.uvIn.xy; + vtf.uv3.y = 1.0 - vtf.uv3.y; + vtf.uv4 = uv4.xy + v.uvIn.xy; + vtf.uv4.y = 1.0 - vtf.uv4.y; + vtf.uv5 = uv5.xy + v.uvIn.xy; + vtf.uv5.y = 1.0 - vtf.uv5.y; + vtf.opacity = opacity; + vtf.position = float4(v.posIn.xyz, 1.0); + return vtf; +} + +#fragment hlsl +Texture2D sceneTex : register(t0); +SamplerState samp : register(s0); +struct VertToFrag +{ + float4 position : SV_Position; + float2 uvReg : UV6; + float2 uv0 : UV0; + float2 uv1 : UV1; + float2 uv2 : UV2; + float2 uv3 : UV3; + float2 uv4 : UV4; + float2 uv5 : UV5; + float opacity : OPACITY; +}; + +float4 main(in VertToFrag vtf) : SV_Target0 +{ + float4 colorSample = sceneTex.Sample(samp, vtf.uvReg) * 0.14285715; + colorSample += sceneTex.Sample(samp, vtf.uv0) * 0.14285715; + colorSample += sceneTex.Sample(samp, vtf.uv1) * 0.14285715; + colorSample += sceneTex.Sample(samp, vtf.uv2) * 0.14285715; + colorSample += sceneTex.Sample(samp, vtf.uv3) * 0.14285715; + colorSample += sceneTex.Sample(samp, vtf.uv4) * 0.14285715; + colorSample += sceneTex.Sample(samp, vtf.uv5) * 0.14285715; + return float4(colorSample.rgb, vtf.opacity); +} + + +#vertex metal +struct VertData +{ + float4 posIn [[ attribute(0) ]]; + float4 uvIn [[ attribute(1) ]]; +}; + +struct CameraBlurUniform +{ + float4 uv0; + float4 uv1; + float4 uv2; + float4 uv3; + float4 uv4; + float4 uv5; + float opacity; +}; + +struct VertToFrag +{ + float4 position [[ position ]]; + float2 uvReg; + float2 uv0; + float2 uv1; + float2 uv2; + float2 uv3; + float2 uv4; + float2 uv5; + float opacity; +}; + +vertex VertToFrag vmain(VertData v [[ stage_in ]], constant CameraBlurUniform& cbu [[ buffer(2) ]]) +{ + VertToFrag vtf; + vtf.uvReg = v.uvIn.xy; + vtf.uvReg.y = 1.0 - vtf.uvReg.y; + vtf.uv0 = cbu.uv0.xy + v.uvIn.xy; + vtf.uv0.y = 1.0 - vtf.uv0.y; + vtf.uv1 = cbu.uv1.xy + v.uvIn.xy; + vtf.uv1.y = 1.0 - vtf.uv1.y; + vtf.uv2 = cbu.uv2.xy + v.uvIn.xy; + vtf.uv2.y = 1.0 - vtf.uv2.y; + vtf.uv3 = cbu.uv3.xy + v.uvIn.xy; + vtf.uv3.y = 1.0 - vtf.uv3.y; + vtf.uv4 = cbu.uv4.xy + v.uvIn.xy; + vtf.uv4.y = 1.0 - vtf.uv4.y; + vtf.uv5 = cbu.uv5.xy + v.uvIn.xy; + vtf.uv5.y = 1.0 - vtf.uv5.y; + vtf.opacity = cbu.opacity; + vtf.position = float4(v.posIn.xyz, 1.0); + return vtf; +} + +#fragment metal +struct VertToFrag +{ + float4 position [[ position ]]; + float2 uvReg; + float2 uv0; + float2 uv1; + float2 uv2; + float2 uv3; + float2 uv4; + float2 uv5; + float opacity; +}; + +fragment float4 fmain(VertToFrag vtf [[ stage_in ]], sampler samp [[ sampler(0) ]], + texture2d sceneTex [[ texture(0) ]]) +{ + float4 colorSample = sceneTex.sample(samp, vtf.uvReg) * 0.14285715; + colorSample += sceneTex.sample(samp, vtf.uv0) * 0.14285715; + colorSample += sceneTex.sample(samp, vtf.uv1) * 0.14285715; + colorSample += sceneTex.sample(samp, vtf.uv2) * 0.14285715; + colorSample += sceneTex.sample(samp, vtf.uv3) * 0.14285715; + colorSample += sceneTex.sample(samp, vtf.uv4) * 0.14285715; + colorSample += sceneTex.sample(samp, vtf.uv5) * 0.14285715; + return float4(colorSample.rgb, vtf.opacity); +} diff --git a/Shaders/CColoredQuadFilter.shader b/Shaders/CColoredQuadFilter.shader new file mode 100644 index 000000000..19dd93e39 --- /dev/null +++ b/Shaders/CColoredQuadFilter.shader @@ -0,0 +1,130 @@ +#shader CColoredQuadFilter +#attribute position4 +#srcfac srcalpha +#dstfac invsrcalpha +#primitive tristrips +#depthtest none +#depthwrite false +#culling none + + +#vertex glsl +layout(location=0) in vec4 posIn; + +UBINDING0 uniform ColoredQuadUniform +{ + mat4 xf; + vec4 color; +}; + +struct VertToFrag +{ + vec4 color; +}; + +SBINDING(0) out VertToFrag vtf; +void main() +{ + vtf.color = color; + gl_Position = xf * vec4(posIn.xyz, 1.0); +} + +#fragment glsl +struct VertToFrag +{ + vec4 color; +}; + +SBINDING(0) in VertToFrag vtf; +layout(location=0) out vec4 colorOut; +void main() +{ + colorOut = vtf.color; +} + + +#vertex hlsl +struct VertData +{ + float4 posIn : POSITION; +}; + +cbuffer ColoredQuadUniform : register(b0) +{ + float4x4 xf; + float4 color; +}; + +struct VertToFrag +{ + float4 position : SV_Position; + float4 color : COLOR; +}; + +VertToFrag main(in VertData v) +{ + VertToFrag vtf; + vtf.color = color; + vtf.position = mul(xf, float4(v.posIn.xyz, 1.0)); + return vtf; +} + +#fragment hlsl +struct VertToFrag +{ + float4 position : SV_Position; + float4 color : COLOR; +}; + +float4 main(in VertToFrag vtf) : SV_Target0 +{ + return vtf.color; +} + + +#vertex metal +struct VertData +{ + float4 posIn [[ attribute(0) ]]; +}; + +struct ColoredQuadUniform +{ + float4x4 xf; + float4 color; +}; + +struct VertToFrag +{ + float4 position [[ position ]]; + float4 color; +}; + +vertex VertToFrag vmain(VertData v [[ stage_in ]], constant ColoredQuadUniform& cqu [[ buffer(2) ]]) +{ + VertToFrag vtf; + vtf.color = cqu.color; + vtf.position = cqu.xf * float4(v.posIn.xyz, 1.0); + return vtf; +} + +#fragment metal +struct VertToFrag +{ + float4 position [[ position ]]; + float4 color; +}; + +fragment float4 fmain(VertToFrag vtf [[ stage_in ]]) +{ + return vtf.color; +} + + +#shader CColoredQuadFilterAdd : CColoredQuadFilter +#srcfac srcalpha +#dstfac one + +#shader CColoredQuadFilterMul : CColoredQuadFilter +#srcfac zero +#dstfac srccolor diff --git a/Shaders/CDecalShaders.shader b/Shaders/CDecalShaders.shader new file mode 100644 index 000000000..6282282c4 --- /dev/null +++ b/Shaders/CDecalShaders.shader @@ -0,0 +1,346 @@ +#shader CDecalShaderTexZTest +#instattribute position4 0 +#instattribute position4 1 +#instattribute position4 2 +#instattribute position4 3 +#instattribute color +#instattribute uv4 0 +#instattribute uv4 1 +#instattribute uv4 2 +#instattribute uv4 3 +#srcfac srcalpha +#dstfac invsrcalpha +#primitive tristrips +#depthtest lequal +#depthwrite false +#culling none + +#vertex glsl +layout(location=0) in vec4 posIn[4]; +layout(location=4) in vec4 colorIn; +layout(location=5) in vec4 uvsIn[4]; + +UBINDING0 uniform DecalUniform +{ + mat4 mvp; + vec4 moduColor; +}; + +struct VertToFrag +{ + vec4 color; + vec2 uv; +}; + +SBINDING(0) out VertToFrag vtf; +void main() +{ + vtf.color = colorIn * moduColor; + vtf.uv = uvsIn[gl_VertexID].xy; + gl_Position = mvp * posIn[gl_VertexID]; +} + +#fragment glsl +struct VertToFrag +{ + vec4 color; + vec2 uv; +}; + +SBINDING(0) in VertToFrag vtf; +layout(location=0) out vec4 colorOut; +TBINDING0 uniform sampler2D tex; +void main() +{ + colorOut = vtf.color * texture(tex, vtf.uv); +} + + +#vertex hlsl +struct VertData +{ + float4 posIn[4] : POSITION; + float4 colorIn : COLOR; + float4 uvsIn[4] : UV; +}; + +cbuffer DecalUniform : register(b0) +{ + float4x4 mvp; + float4 moduColor; +}; + +struct VertToFrag +{ + float4 position : SV_Position; + float4 color : COLOR; + float2 uv : UV; +}; + +VertToFrag main(in VertData v, in uint vertId : SV_VertexID) +{ + VertToFrag vtf; + vtf.color = v.colorIn * moduColor; + vtf.uv = v.uvsIn[vertId].xy; + vtf.position = mul(mvp, v.posIn[vertId]); + return vtf; +} + +#fragment hlsl +SamplerState samp : register(s0); +Texture2D tex0 : register(t0); +struct VertToFrag +{ + float4 position : SV_Position; + float4 color : COLOR; + float2 uv : UV; +}; + +float4 main(in VertToFrag vtf) : SV_Target0 +{ + return vtf.color * tex0.Sample(samp, vtf.uv); +} + + +#vertex metal +struct VertData +{ + float4 posIn[4]; + float4 colorIn; + float4 uvsIn[4]; +}; + +struct DecalUniform +{ + float4x4 mvp; + float4 moduColor; +}; + +struct VertToFrag +{ + float4 position [[ position ]]; + float4 color; + float2 uv; +}; + +vertex VertToFrag vmain(constant VertData* va [[ buffer(1) ]], + uint vertId [[ vertex_id ]], uint instId [[ instance_id ]], + constant DecalUniform& decal [[ buffer(2) ]]) +{ + VertToFrag vtf; + constant VertData& v = va[instId]; + vtf.color = v.colorIn * decal.moduColor; + vtf.uv = v.uvsIn[vertId].xy; + vtf.position = decal.mvp * v.posIn[vertId]; + return vtf; +} + +#fragment metal +struct VertToFrag +{ + float4 position [[ position ]]; + float4 color; + float2 uv; +}; + +fragment float4 fmain(VertToFrag vtf [[ stage_in ]], + sampler samp [[ sampler(0) ]], + texture2d tex0 [[ texture(0) ]]) +{ + return vtf.color * tex0.sample(samp, vtf.uv); +} + + +#shader CDecalShaderTexAdditiveZTest : CDecalShaderTexZTest +#srcfac srcalpha +#dstfac one + +#shader CDecalShaderTexRedToAlphaZTest : CDecalShaderTexZTest +#srcfac one +#dstfac one +#alphawrite true + +#fragment glsl +struct VertToFrag +{ + vec4 color; + vec2 uv; +}; + +SBINDING(0) in VertToFrag vtf; +layout(location=0) out vec4 colorOut; +TBINDING0 uniform sampler2D tex; +void main() +{ + colorOut = vtf.color; + colorOut.a = texture(tex, vtf.uv).r; +} + + +#fragment hlsl +SamplerState samp : register(s0); +Texture2D tex0 : register(t0); +struct VertToFrag +{ + float4 position : SV_Position; + float4 color : COLOR; + float2 uv : UV; +}; + +float4 main(in VertToFrag vtf) : SV_Target0 +{ + return float4(vtf.color.rgb, tex0.Sample(samp, vtf.uv).r); +} + + +#fragment metal +struct VertToFrag +{ + float4 position [[ position ]]; + float4 color; + float2 uv; +}; + +fragment float4 fmain(VertToFrag vtf [[ stage_in ]], + sampler samp [[ sampler(0) ]], + texture2d tex0 [[ texture(0) ]]) +{ + return float4(vtf.color.rgb, tex0.sample(samp, vtf.uv).r); +} + + +#shader CDecalShaderNoTexZTest +#instattribute position4 0 +#instattribute position4 1 +#instattribute position4 2 +#instattribute position4 3 +#instattribute color +#srcfac srcalpha +#dstfac invsrcalpha +#primitive tristrips +#depthtest lequal +#depthwrite false +#alphawrite false +#culling none + +#vertex glsl +layout(location=0) in vec4 posIn[4]; +layout(location=4) in vec4 colorIn; + +UBINDING0 uniform DecalUniform +{ + mat4 mvp; + vec4 moduColor; +}; + +struct VertToFrag +{ + vec4 color; +}; + +SBINDING(0) out VertToFrag vtf; +void main() +{ + vtf.color = colorIn * moduColor; + gl_Position = mvp * posIn[gl_VertexID]; +} + +#fragment glsl +struct VertToFrag +{ + vec4 color; +}; + +SBINDING(0) in VertToFrag vtf; +layout(location=0) out vec4 colorOut; +void main() +{ + colorOut = vtf.color; +} + + +#vertex hlsl +struct VertData +{ + float4 posIn[4] : POSITION; + float4 colorIn : COLOR; +}; + +cbuffer DecalUniform : register(b0) +{ + float4x4 mvp; + float4 moduColor; +}; + +struct VertToFrag +{ + float4 position : SV_Position; + float4 color : COLOR; +}; + +VertToFrag main(in VertData v, in uint vertId : SV_VertexID) +{ + VertToFrag vtf; + vtf.color = v.colorIn * moduColor; + vtf.position = mul(mvp, v.posIn[vertId]); + return vtf; +} + +#fragment hlsl +struct VertToFrag +{ + float4 position : SV_Position; + float4 color : COLOR; +}; + +float4 main(in VertToFrag vtf) : SV_Target0 +{ + return vtf.color; +} + + +#vertex metal +struct VertData +{ + float4 posIn[4]; + float4 colorIn; +}; + +struct DecalUniform +{ + float4x4 mvp; + float4 moduColor; +}; + +struct VertToFrag +{ + float4 position [[ position ]]; + float4 color; +}; + +vertex VertToFrag vmain(constant VertData* va [[ buffer(1) ]], + uint vertId [[ vertex_id ]], uint instId [[ instance_id ]], + constant DecalUniform& decal [[ buffer(2) ]]) +{ + VertToFrag vtf; + constant VertData& v = va[instId]; + vtf.color = v.colorIn * decal.moduColor; + vtf.position = decal.mvp * v.posIn[vertId]; + return vtf; +} + +#fragment metal +struct VertToFrag +{ + float4 position [[ position ]]; + float4 color; +}; + +fragment float4 fmain(VertToFrag vtf [[ stage_in ]]) +{ + return vtf.color; +} + +#shader CDecalShaderNoTexAdditiveZTest : CDecalShaderNoTexZTest +#srcfac srcalpha +#dstfac one diff --git a/Shaders/CElementGenShaders.shader b/Shaders/CElementGenShaders.shader new file mode 100644 index 000000000..db8c6223a --- /dev/null +++ b/Shaders/CElementGenShaders.shader @@ -0,0 +1,687 @@ +#shader CElementGenShaderTexZTestZWrite +#instattribute position4 0 +#instattribute position4 1 +#instattribute position4 2 +#instattribute position4 3 +#instattribute color +#instattribute uv4 0 +#instattribute uv4 1 +#instattribute uv4 2 +#instattribute uv4 3 +#srcfac srcalpha +#dstfac invsrcalpha +#primitive tristrips +#depthtest lequal +#depthwrite true +#culling none + +#vertex glsl +layout(location=0) in vec4 posIn[4]; +layout(location=4) in vec4 colorIn; +layout(location=5) in vec4 uvsIn[4]; + +UBINDING0 uniform ParticleUniform +{ + mat4 mvp; + vec4 moduColor; +}; + +struct VertToFrag +{ + vec4 color; + vec2 uv; +}; + +SBINDING(0) out VertToFrag vtf; +void main() +{ + vec4 pos = posIn[gl_VertexID]; + vtf.color = colorIn * moduColor; + vtf.uv = uvsIn[gl_VertexID].xy; + gl_Position = mvp * pos; +} + +#fragment glsl +struct VertToFrag +{ + vec4 color; + vec2 uv; +}; + +SBINDING(0) in VertToFrag vtf; +layout(location=0) out vec4 colorOut; +TBINDING0 uniform sampler2D tex; +void main() +{ + colorOut = vtf.color * texture(tex, vtf.uv); +} + +#vertex hlsl +struct VertData +{ + float4 posIn[4] : POSITION; + float4 colorIn : COLOR; + float4 uvsIn[4] : UV; +}; + +cbuffer ParticleUniform : register(b0) +{ + float4x4 mvp; + float4 moduColor; +}; + +struct VertToFrag +{ + float4 position : SV_Position; + float4 color : COLOR; + float2 uv : UV; +}; + +VertToFrag main(in VertData v, in uint vertId : SV_VertexID) +{ + VertToFrag vtf; + vtf.color = v.colorIn * moduColor; + vtf.uv = v.uvsIn[vertId].xy; + vtf.position = mul(mvp, v.posIn[vertId]); + return vtf; +} + +#fragment hlsl +SamplerState samp : register(s0); +Texture2D tex0 : register(t0); +struct VertToFrag +{ + float4 position : SV_Position; + float4 color : COLOR; + float2 uv : UV; +}; + +float4 main(in VertToFrag vtf) : SV_Target0 +{ + return vtf.color * tex0.Sample(samp, vtf.uv); +} + +#vertex metal +struct VertData +{ + float4 posIn[4]; + float4 colorIn; + float4 uvsIn[4]; +}; + +struct ParticleUniform +{ + float4x4 mvp; + float4 moduColor; +}; + +struct VertToFrag +{ + float4 position [[ position ]]; + float4 color; + float2 uv; +}; + +vertex VertToFrag vmain(constant VertData* va [[ buffer(1) ]], + uint vertId [[ vertex_id ]], uint instId [[ instance_id ]], + constant ParticleUniform& particle [[ buffer(2) ]]) +{ + VertToFrag vtf; + constant VertData& v = va[instId]; + vtf.color = v.colorIn * particle.moduColor; + vtf.uv = v.uvsIn[vertId].xy; + vtf.position = particle.mvp * v.posIn[vertId]; + return vtf; +} + +#fragment metal +struct VertToFrag +{ + float4 position [[ position ]]; + float4 color; + float2 uv; +}; + +fragment float4 fmain(VertToFrag vtf [[ stage_in ]], + sampler samp [[ sampler(0) ]], + texture2d tex0 [[ texture(0) ]]) +{ + return vtf.color * tex0.sample(samp, vtf.uv); +} + +#shader CElementGenShaderTexNoZTestZWrite : CElementGenShaderTexZTestZWrite +#depthtest none +#depthwrite true + +#shader CElementGenShaderTexZTestNoZWrite : CElementGenShaderTexZTestZWrite +#depthtest lequal +#depthwrite false + +#shader CElementGenShaderTexNoZTestNoZWrite : CElementGenShaderTexZTestZWrite +#depthtest none +#depthwrite false + +#shader CElementGenShaderTexAdditiveZTest : CElementGenShaderTexZTestZWrite +#srcfac srcalpha +#dstfac one +#depthtest lequal +#depthwrite false + +#shader CElementGenShaderTexAdditiveNoZTest : CElementGenShaderTexZTestZWrite +#srcfac srcalpha +#dstfac one +#depthtest none +#depthwrite false + +#shader CElementGenShaderTexZTestNoZWriteSub : CElementGenShaderTexZTestZWrite +#srcfac subtract +#dstfac subtract +#depthtest lequal +#depthwrite false + +#shader CElementGenShaderTexNoZTestNoZWriteSub : CElementGenShaderTexZTestZWrite +#srcfac subtract +#dstfac subtract +#depthtest none +#depthwrite false + +#shader CElementGenShaderTexRedToAlphaZTest : CElementGenShaderTexZTestZWrite +#srcfac srcalpha +#dstfac invsrcalpha +#depthtest lequal +#depthwrite false + +#fragment glsl +struct VertToFrag +{ + vec4 color; + vec2 uv; +}; + +SBINDING(0) in VertToFrag vtf; +layout(location=0) out vec4 colorOut; +TBINDING0 uniform sampler2D tex; +void main() +{ + colorOut = vtf.color; + colorOut.a = texture(tex, vtf.uv).r; +} + +#fragment hlsl +SamplerState samp : register(s0); +Texture2D tex0 : register(t0); +struct VertToFrag +{ + float4 position : SV_Position; + float4 color : COLOR; + float2 uv : UV; +}; + +float4 main(in VertToFrag vtf) : SV_Target0 +{ + return float4(vtf.color.rgb, tex0.Sample(samp, vtf.uv).r); +} + +#fragment metal +struct VertToFrag +{ + float4 position [[ position ]]; + float4 color; + float2 uv; +}; + +fragment float4 fmain(VertToFrag vtf [[ stage_in ]], + sampler samp [[ sampler(0) ]], + texture2d tex0 [[ texture(0) ]]) +{ + return float4(vtf.color.rgb, tex0.sample(samp, vtf.uv).r); +} + +#shader CElementGenShaderTexRedToAlphaNoZTest : CElementGenShaderTexRedToAlphaZTest +#depthtest none + +#shader CElementGenShaderTexRedToAlphaZTestSub : CElementGenShaderTexRedToAlphaZTest +#srcfac subtract +#dstfac subtract +#depthtest lequal + +#shader CElementGenShaderTexRedToAlphaNoZTestSub : CElementGenShaderTexRedToAlphaZTest +#srcfac subtract +#dstfac subtract +#depthtest none + +#shader CElementGenShaderIndTexZWrite +#instattribute position4 0 +#instattribute position4 1 +#instattribute position4 2 +#instattribute position4 3 +#instattribute color +#instattribute uv4 0 +#instattribute uv4 1 +#instattribute uv4 2 +#instattribute uv4 3 +#instattribute uv4 4 +#instattribute uv4 5 +#instattribute uv4 6 +#instattribute uv4 7 +#srcfac srcalpha +#dstfac invsrcalpha +#depthtest none +#depthwrite true + +#vertex glsl +layout(location=0) in vec4 posIn[4]; +layout(location=4) in vec4 colorIn; +layout(location=5) in vec4 uvsInTexrTind[4]; +layout(location=9) in vec4 uvsInScene; + +UBINDING0 uniform ParticleUniform +{ + mat4 mvp; + vec4 moduColor; +}; + +struct VertToFrag +{ + vec4 color; + vec4 uvScene; + vec2 uvTexr; + vec2 uvTind; +}; + +SBINDING(0) out VertToFrag vtf; +void main() +{ + vec4 pos = posIn[gl_VertexID]; + vtf.color = colorIn * moduColor; + vtf.uvScene = uvsInScene; + vtf.uvTexr = uvsInTexrTind[gl_VertexID].xy; + vtf.uvTind = uvsInTexrTind[gl_VertexID].zw; + gl_Position = mvp * pos; + gl_Position = FLIPFROMGL(gl_Position); +} + +#fragment glsl +struct VertToFrag +{ + vec4 color; + vec4 uvScene; + vec2 uvTexr; + vec2 uvTind; +}; + +SBINDING(0) in VertToFrag vtf; +layout(location=0) out vec4 colorOut; +TBINDING0 uniform sampler2D texrMap; +TBINDING1 uniform sampler2D sceneMap; +TBINDING2 uniform sampler2D tindMap; +void main() +{ + vec2 tindTexel = texture(tindMap, vtf.uvTind).zw; + vec4 sceneTexel = texture(sceneMap, mix(vtf.uvScene.xy, vtf.uvScene.zw, tindTexel)); + vec4 texrTexel = texture(texrMap, vtf.uvTexr); + colorOut = vtf.color * vec4(sceneTexel.rgb, 1.0) + texrTexel; +} + +#vertex hlsl +struct VertData +{ + float4 posIn[4] : POSITION; + float4 colorIn : COLOR; + float4 uvsInTexrTind[4] : UV0; + float4 uvsInScene : UV4; +}; + +cbuffer ParticleUniform : register(b0) +{ + float4x4 mvp; + float4 moduColor; +}; + +struct VertToFrag +{ + float4 position : SV_Position; + float4 color : COLOR; + float4 uvScene : UV0; + float2 uvTexr : UV1; + float2 uvTind : UV2; +}; + +VertToFrag main(in VertData v, in uint vertId : SV_VertexID) +{ + VertToFrag vtf; + vtf.color = v.colorIn * moduColor; + vtf.uvScene = v.uvsInScene; + vtf.uvScene.y = 1.0 - vtf.uvScene.y; + vtf.uvScene.w = 1.0 - vtf.uvScene.w; + vtf.uvTexr = v.uvsInTexrTind[vertId].xy; + vtf.uvTind = v.uvsInTexrTind[vertId].zw; + vtf.position = mul(mvp, v.posIn[vertId]); + return vtf; +} + +#fragment hlsl +SamplerState samp : register(s0); +Texture2D tex0 : register(t0); +Texture2D tex1 : register(t1); +Texture2D tex2 : register(t2); +struct VertToFrag +{ + float4 position : SV_Position; + float4 color : COLOR; + float4 uvScene : UV0; + float2 uvTexr : UV1; + float2 uvTind : UV2; +}; + +float4 main(in VertToFrag vtf) : SV_Target0 +{ + float2 tindTexel = tex2.Sample(samp, vtf.uvTind).zw; + float4 sceneTexel = tex1.Sample(samp, lerp(vtf.uvScene.xy, vtf.uvScene.zw, tindTexel)); + float4 texrTexel = tex0.Sample(samp, vtf.uvTexr); + float4 colorOut = vtf.color * float4(sceneTexel.rgb, 1.0) + texrTexel; + colorOut.a = vtf.color.a * texrTexel.a; + return colorOut; +} + +#vertex metal +struct VertData +{ + float4 posIn[4]; + float4 colorIn; + float4 uvsInTexrTind[4]; + float4 uvsInScene; +}; + +struct ParticleUniform +{ + float4x4 mvp; + float4 moduColor; +}; + +struct VertToFrag +{ + float4 position [[ position ]]; + float4 color; + float4 uvScene; + float2 uvTexr; + float2 uvTind; +}; + +vertex VertToFrag vmain(constant VertData* va [[ buffer(1) ]], + uint vertId [[ vertex_id ]], uint instId [[ instance_id ]], + constant ParticleUniform& particle [[ buffer(2) ]]) +{ + VertToFrag vtf; + constant VertData& v = va[instId]; + vtf.color = v.colorIn * particle.moduColor; + vtf.uvScene = v.uvsInScene; + vtf.uvScene.y = 1.0 - vtf.uvScene.y; + vtf.uvScene.w = 1.0 - vtf.uvScene.w; + vtf.uvTexr = v.uvsInTexrTind[vertId].xy; + vtf.uvTind = v.uvsInTexrTind[vertId].zw; + vtf.position = particle.mvp * v.posIn[vertId]; + return vtf; +} + +#fragment metal +struct VertToFrag +{ + float4 position [[ position ]]; + float4 color; + float4 uvScene; + float2 uvTexr; + float2 uvTind; +}; + +fragment float4 fmain(VertToFrag vtf [[ stage_in ]], + sampler samp [[ sampler(0) ]]," + texture2d tex0 [[ texture(0) ]], + texture2d tex1 [[ texture(1) ]], + texture2d tex2 [[ texture(2) ]]) +{ + float2 tindTexel = tex2.sample(samp, vtf.uvTind).ba; + float4 sceneTexel = tex1.sample(samp, mix(vtf.uvScene.xy, vtf.uvScene.zw, tindTexel)); + float4 texrTexel = tex0.sample(samp, vtf.uvTexr); + float4 colr = vtf.color * float4(sceneTexel.rgb, 1.0) + texrTexel; + return float4(colr.rgb, vtf.color.a * texrTexel.a);" +} + +#shader CElementGenShaderIndTexNoZWrite : CElementGenShaderIndTexZWrite +#depthwrite false + +#shader CElementGenShaderIndTexAdditive : CElementGenShaderIndTexZWrite +#depthwrite true +#srcfac srcalpha +#dstfac one + +#shader CElementGenShaderCindTexZWrite : CElementGenShaderIndTexZWrite +#srcfac srcalpha +#dstfac invsrcalpha +#depthtest none +#depthwrite true + +#fragment glsl +struct VertToFrag +{ + vec4 color; + vec4 uvScene; + vec2 uvTexr; + vec2 uvTind; +}; + +SBINDING(0) in VertToFrag vtf; +layout(location=0) out vec4 colorOut; +TBINDING0 uniform sampler2D texrMap; +TBINDING1 uniform sampler2D sceneMap; +TBINDING2 uniform sampler2D tindMap; +void main() +{ + vec2 tindTexel = texture(tindMap, vtf.uvTind).zw; + vec4 sceneTexel = texture(sceneMap, mix(vtf.uvScene.xy, vtf.uvScene.zw, tindTexel)); + colorOut = vtf.color * vec4(sceneTexel.rgb, 1.0) * texture(texrMap, vtf.uvTexr); +} + +#fragment hlsl +SamplerState samp : register(s0); +Texture2D tex0 : register(t0); +Texture2D tex1 : register(t1); +Texture2D tex2 : register(t2); +struct VertToFrag +{ + float4 position : SV_Position; + float4 color : COLOR; + float4 uvScene : UV0; + float2 uvTexr : UV1; + float2 uvTind : UV2; +}; + +float4 main(in VertToFrag vtf) : SV_Target0 +{ + float2 tindTexel = tex2.Sample(samp, vtf.uvTind).ba; + float4 sceneTexel = tex1.Sample(samp, lerp(vtf.uvScene.xy, vtf.uvScene.zw, tindTexel)); + return vtf.color * float4(sceneTexel.rgb, 1.0) * tex0.Sample(samp, vtf.uvTexr); +} + +#fragment metal +struct VertToFrag +{ + float4 position [[ position ]]; + float4 color; + float4 uvScene; + float2 uvTexr; + float2 uvTind; +}; + +fragment float4 fmain(VertToFrag vtf [[ stage_in ]], + sampler samp [[ sampler(0) ]], + texture2d tex0 [[ texture(0) ]], + texture2d tex1 [[ texture(1) ]], + texture2d tex2 [[ texture(2) ]]) +{ + float2 tindTexel = tex2.sample(samp, vtf.uvTind).ba; + float4 sceneTexel = tex1.sample(samp, mix(vtf.uvScene.xy, vtf.uvScene.zw, tindTexel)); + return vtf.color * float4(sceneTexel.rgb, 1.0) * tex0.sample(samp, vtf.uvTexr); +} + +#shader CElementGenShaderCindTexNoZWrite : CElementGenShaderCindTexZWrite +#depthwrite false + +#shader CElementGenShaderCindTexAdditive : CElementGenShaderCindTexZWrite +#depthwrite true +#srcfac srcalpha +#dstfac one + +#shader CElementGenShaderNoTexZTestZWrite +#instattribute position4 0 +#instattribute position4 1 +#instattribute position4 2 +#instattribute position4 3 +#instattribute color +#srcfac srcalpha +#dstfac invsrcalpha +#primitive tristrips +#depthtest lequal +#depthwrite true +#culling none + +#vertex glsl +layout(location=0) in vec4 posIn[4]; +layout(location=4) in vec4 colorIn; + +UBINDING0 uniform ParticleUniform +{ + mat4 mvp; + vec4 moduColor; +}; + +struct VertToFrag +{ + vec4 color; +}; + +SBINDING(0) out VertToFrag vtf; +void main() +{ + vec4 pos = posIn[gl_VertexID]; + vtf.color = colorIn * moduColor; + gl_Position = mvp * pos; +} + +#fragment glsl +struct VertToFrag +{ + vec4 color; +}; + +SBINDING(0) in VertToFrag vtf; +layout(location=0) out vec4 colorOut; +void main() +{ + colorOut = vtf.color; +} + +#vertex hlsl +struct VertData +{ + float4 posIn[4] : POSITION; + float4 colorIn : COLOR; +}; + +cbuffer ParticleUniform : register(b0) +{ + float4x4 mvp; + float4 moduColor; +}; + +struct VertToFrag +{ + float4 position : SV_Position; + float4 color : COLOR; +}; + +VertToFrag main(in VertData v, in uint vertId : SV_VertexID) +{ + VertToFrag vtf; + vtf.color = v.colorIn * moduColor; + vtf.position = mul(mvp, v.posIn[vertId]); + return vtf; +} + +#fragment hlsl +struct VertToFrag +{ + float4 position : SV_Position; + float4 color : COLOR; +}; + +float4 main(in VertToFrag vtf) : SV_Target0 +{ + return vtf.color; +} + +#vertex metal +struct VertData +{ + float4 posIn[4]; + float4 colorIn; +}; + +struct ParticleUniform +{ + float4x4 mvp; + float4 moduColor; +}; + +struct VertToFrag +{ + float4 position [[ position ]]; + float4 color; +}; + +vertex VertToFrag vmain(constant VertData* va [[ buffer(1) ]], + uint vertId [[ vertex_id ]], uint instId [[ instance_id ]], + constant ParticleUniform& particle [[ buffer(2) ]]) +{ + VertToFrag vtf; + constant VertData& v = va[instId]; + vtf.color = v.colorIn * particle.moduColor; + vtf.position = particle.mvp * v.posIn[vertId]; + return vtf; +} + +#fragment metal +struct VertToFrag +{ + float4 position [[ position ]]; + float4 color; +}; + +fragment float4 fmain(VertToFrag vtf [[ stage_in ]]) +{ + return vtf.color; +} + +#shader CElementGenShaderNoTexNoZTestZWrite : CElementGenShaderNoTexZTestZWrite +#depthtest none +#depthwrite true + +#shader CElementGenShaderNoTexZTestNoZWrite : CElementGenShaderNoTexZTestZWrite +#depthtest lequal +#depthwrite false + +#shader CElementGenShaderNoTexNoZTestNoZWrite : CElementGenShaderNoTexZTestZWrite +#depthtest none +#depthwrite false + +#shader CElementGenShaderNoTexAdditiveZTest : CElementGenShaderNoTexZTestZWrite +#srcfac srcalpha +#dstfac one +#depthtest lequal +#depthwrite false + +#shader CElementGenShaderNoTexAdditiveNoZTest : CElementGenShaderNoTexZTestZWrite +#srcfac srcalpha +#dstfac one +#depthtest none +#depthwrite false diff --git a/Shaders/CEnergyBarShader.shader b/Shaders/CEnergyBarShader.shader new file mode 100644 index 000000000..93d3de21e --- /dev/null +++ b/Shaders/CEnergyBarShader.shader @@ -0,0 +1,138 @@ +#shader CEnergyBarShader +#attribute position4 +#attribute uv4 +#srcfac srcalpha +#dstfac one +#primitive tristrips +#depthtest lequal +#depthwrite false +#culling none + +#vertex glsl +layout(location=0) in vec4 posIn; +layout(location=1) in vec4 uvIn; + +UBINDING0 uniform EnergyBarUniform +{ + mat4 xf; + vec4 color; +}; + +struct VertToFrag +{ + vec4 color; + vec2 uv; +}; + +SBINDING(0) out VertToFrag vtf; +void main() +{ + vtf.color = color; + vtf.uv = uvIn.xy; + gl_Position = xf * vec4(posIn.xyz, 1.0); +} + +#fragment glsl +struct VertToFrag +{ + vec4 color; + vec2 uv; +}; + +SBINDING(0) in VertToFrag vtf; +layout(location=0) out vec4 colorOut; +TBINDING0 uniform sampler2D tex; +void main() +{ + colorOut = vtf.color * texture(tex, vtf.uv); +} + +#vertex hlsl +struct VertData +{ + float4 posIn : POSITION; + float4 uvIn : UV; +}; + +cbuffer EnergyBarUniform : register(b0) +{ + float4x4 xf; + float4 color; +}; + +struct VertToFrag +{ + float4 position : SV_Position; + float4 color : COLOR; + float2 uv : UV; +}; + +VertToFrag main(in VertData v) +{ + VertToFrag vtf; + vtf.color = color; + vtf.uv = v.uvIn.xy; + vtf.position = mul(xf, float4(v.posIn.xyz, 1.0)); + return vtf; +} + +#fragment hlsl +struct VertToFrag +{ + float4 position : SV_Position; + float4 color : COLOR; + float2 uv : UV; +}; + +Texture2D tex : register(t0); +SamplerState samp : register(s0); + +float4 main(in VertToFrag vtf) : SV_Target0 +{ + return vtf.color * tex.Sample(samp, vtf.uv); +} + +#vertex metal +struct VertData +{ + float4 posIn [[ attribute(0) ]]; + float4 uvIn [[ attribute(1) ]]; +}; + +struct EnergyBarUniform +{ + float4x4 xf; + float4 color; +}; + +struct VertToFrag +{ + float4 position [[ position ]]; + float4 color; + float2 uv; +}; + +vertex VertToFrag vmain(VertData v [[ stage_in ]], constant EnergyBarUniform& ebu [[ buffer(2) ]]) +{ + VertToFrag vtf; + vtf.color = ebu.color; + vtf.uv = v.uvIn.xy; + vtf.position = ebu.xf * float4(v.posIn.xyz, 1.0); + return vtf; +} + +#fragment metal +struct VertToFrag +{ + float4 position [[ position ]]; + float4 color; + float2 uv; +}; + +fragment float4 fmain(VertToFrag vtf [[ stage_in ]], + sampler samp [[ sampler(0) ]], + texture2d tex [[ texture(0) ]]) +{ + return vtf.color * tex.sample(samp, vtf.uv); +} + diff --git a/Shaders/CFogVolumeFilter.shader b/Shaders/CFogVolumeFilter.shader new file mode 100644 index 000000000..1cb7652c6 --- /dev/null +++ b/Shaders/CFogVolumeFilter.shader @@ -0,0 +1,235 @@ +#shader CFogVolumeFilter1Way +#attribute position4 +#attribute uv4 +#srcfac dstalpha +#dstfac one +#primitive tristrips +#depthtest none +#depthwrite false +#culling none + +#vertex glsl +layout(location=0) in vec4 posIn; +layout(location=1) in vec2 uvIn; + +UBINDING0 uniform FogVolumeFilterUniform +{ + vec4 color; +}; + +struct VertToFrag +{ + vec4 color; + vec2 uv; +}; + +SBINDING(0) out VertToFrag vtf; +void main() +{ + gl_Position = vec4(posIn.xy, 0.0, 1.0); + vtf.color = color; + vtf.uv = uvIn; +} + +#fragment glsl +struct VertToFrag +{ + vec4 color; + vec2 uv; +}; + +SBINDING(0) in VertToFrag vtf; +layout(location=0) out vec4 colorOut; +TBINDING0 uniform sampler2D zFrontfaceTex; +TBINDING1 uniform sampler2D zBackfaceTex; +TBINDING2 uniform sampler2D zLinearizer; +void main() +{ + float y; + const float linScale = 65535.0 / 65536.0 * 256.0; + float x = modf(texture(zFrontfaceTex, vtf.uv).r * linScale, y); + const float uvBias = 0.5 / 256.0; + float alpha = texture(zLinearizer, vec2(x * 255.0 / 256.0 + uvBias, y / 256.0 + uvBias)).r * 10.0; + colorOut = vtf.color * alpha; +} + +#vertex hlsl +struct VertData +{ + float4 posIn : POSITION; + float2 uvIn : UV; +}; + +cbuffer FogVolumeFilterUniform : register(b0) +{ + float4 color; +}; + +struct VertToFrag +{ + float4 position : SV_Position; + float4 color : COLOR; + float2 uv : UV; +}; + +VertToFrag main(in VertData v) +{ + VertToFrag vtf; + vtf.position = float4(v.posIn.x, -v.posIn.y, 0.0, 1.0); + vtf.color = color; + vtf.uv = v.uvIn; + return vtf; +} + +#fragment hlsl +struct VertToFrag +{ + float4 position : SV_Position; + float4 color : COLOR; + float2 uv : UV; +}; + +Texture2D zFrontfaceTex : register(t0); +Texture2D zBackfaceTex : register(t1); +Texture2D zLinearizer : register(t2); +SamplerState samp : register(s0); +float4 main(in VertToFrag vtf) : SV_Target0 +{ + float y; + const float linScale = 65535.0 / 65536.0 * 256.0; + float x = modf((1.0 - zFrontfaceTex.Sample(samp, vtf.uv).r) * linScale, y); + const float uvBias = 0.5 / 256.0; + float alpha = zLinearizer.Sample(samp, float2(x * 255.0 / 256.0 + uvBias, y / 256.0 + uvBias)).r * 10.0; + return vtf.color * alpha; +} + +#vertex metal +struct VertData +{ + float4 posIn [[ attribute(0) ]]; + float2 uvIn [[ attribute(1) ]]; +}; + +struct FogVolumeFilterUniform +{ + float4 color; +}; + +struct VertToFrag +{ + float4 pos [[ position ]]; + float4 color; + float2 uv; +}; + +vertex VertToFrag vmain(VertData v [[ stage_in ]], + constant FogVolumeFilterUniform& fu [[ buffer(2) ]]) +{ + VertToFrag vtf; + vtf.pos = float4(v.posIn.x, -v.posIn.y, 0.0, 1.0); + vtf.color = fu.color; + vtf.uv = v.uvIn; + return vtf; +} + +#fragment metal +struct VertToFrag +{ + float4 pos [[ position ]]; + float4 color; + float2 uv; +}; + +fragment float4 fmain(VertToFrag vtf [[ stage_in ]], + sampler samp [[ sampler(0) ]], + texture2d zFrontfaceTex [[ texture(0) ]], + texture2d zBackfaceTex [[ texture(1) ]], + texture2d zLinearizer [[ texture(2) ]]) +{ + float y; + const float linScale = 65535.0 / 65536.0 * 256.0; + float x = modf((1.0 - zFrontfaceTex.sample(samp, vtf.uv).r) * linScale, y); + const float uvBias = 0.5 / 256.0; + float alpha = zLinearizer.sample(samp, float2(x * 255.0 / 256.0 + uvBias, y / 256.0 + uvBias)).r * 10.0; + return vtf.color * alpha; +} + + +#shader CFogVolumeFilter2Way : CFogVolumeFilter1Way +#srcfac srcalpha +#dstfac one + +#fragment glsl +struct VertToFrag +{ + vec4 color; + vec2 uv; +}; + +SBINDING(0) in VertToFrag vtf; +layout(location=0) out vec4 colorOut; +TBINDING0 uniform sampler2D zFrontfaceTex; +TBINDING1 uniform sampler2D zBackfaceTex; +TBINDING2 uniform sampler2D zLinearizer; +void main() +{ + float frontY; + float backY; + const float linScale = 65535.0 / 65536.0 * 256.0; + float frontX = modf(texture(zFrontfaceTex, vtf.uv).r * linScale, frontY); + float backX = modf(texture(zBackfaceTex, vtf.uv).r * linScale, backY); + const float uvBias = 0.5 / 256.0; + float frontLin = texture(zLinearizer, vec2(frontX * 255.0 / 256.0 + uvBias, frontY / 256.0 + uvBias)).r; + float backLin = texture(zLinearizer, vec2(backX * 255.0 / 256.0 + uvBias, backY / 256.0 + uvBias)).r; + colorOut = vec4(vtf.color.rgb, (frontLin - backLin) * 10.0); +} + +#fragment hlsl +struct VertToFrag +{ + float4 position : SV_Position; + float4 color : COLOR; + float2 uv : UV; +}; + +Texture2D zFrontfaceTex : register(t0); +Texture2D zBackfaceTex : register(t1); +Texture2D zLinearizer : register(t2); +SamplerState samp : register(s0); +float4 main(in VertToFrag vtf) : SV_Target0 +{ + float frontY; + float backY; + const float linScale = 65535.0 / 65536.0 * 256.0; + float frontX = modf((1.0 - zFrontfaceTex.Sample(samp, vtf.uv).r) * linScale, frontY); + float backX = modf((1.0 - zBackfaceTex.Sample(samp, vtf.uv).r) * linScale, backY); + const float uvBias = 0.5 / 256.0; + float frontLin = zLinearizer.Sample(samp, float2(frontX * 255.0 / 256.0 + uvBias, frontY / 256.0 + uvBias)).r; + float backLin = zLinearizer.Sample(samp, float2(backX * 255.0 / 256.0 + uvBias, backY / 256.0 + uvBias)).r; + return float4(vtf.color.rgb, (frontLin - backLin) * 10.0); +} + +#fragment metal +struct VertToFrag +{ + float4 pos [[ position ]]; + float4 color; + float2 uv; +}; + +fragment float4 fmain(VertToFrag vtf [[ stage_in ]], + sampler samp [[ sampler(0) ]], + texture2d zFrontfaceTex [[ texture(0) ]], + texture2d zBackfaceTex [[ texture(1) ]], + texture2d zLinearizer [[ texture(2) ]]) +{ + float frontY; + float backY; + const float linScale = 65535.0 / 65536.0 * 256.0; + float frontX = modf((1.0 - zFrontfaceTex.sample(samp, vtf.uv).r) * linScale, frontY); + float backX = modf((1.0 - zBackfaceTex.sample(samp, vtf.uv).r) * linScale, backY); + const float uvBias = 0.5 / 256.0; + float frontLin = zLinearizer.sample(samp, float2(frontX * 255.0 / 256.0 + uvBias, frontY / 256.0 + uvBias)).r; + float backLin = zLinearizer.sample(samp, float2(backX * 255.0 / 256.0 + uvBias, backY / 256.0 + uvBias)).r; + return float4(vtf.color.rgb, (frontLin - backLin) * 10.0); +} diff --git a/Shaders/CFogVolumePlaneShader.shader b/Shaders/CFogVolumePlaneShader.shader new file mode 100644 index 000000000..b1988cb17 --- /dev/null +++ b/Shaders/CFogVolumePlaneShader.shader @@ -0,0 +1,87 @@ +#shader CFogVolumePlaneShader0 +#attribute position4 +#srcfac zero +#dstfac zero +#primitive tristrips +#depthtest lequal +#depthwrite true +#colorwrite false +#culling frontface + +#vertex glsl +layout(location=0) in vec4 posIn; +void main() +{ + gl_Position = posIn; +} + +#fragment glsl +layout(location=0) out vec4 colorOut; +void main() +{ + colorOut = vec4(1.0); +} + +#vertex hlsl +struct VertData +{ + float4 posIn : POSITION; +}; + +float4 main(in VertData v) : SV_Position +{ + return v.posIn; +} + +#fragment hlsl +float4 main() : SV_Target0 +{ + return float4(1.0, 1.0, 1.0, 1.0); +} + +#vertex metal +struct VertData +{ + float4 posIn [[ attribute(0) ]]; +}; + +struct VertToFrag +{ + float4 position [[ position ]]; +}; + +vertex VertToFrag vmain(VertData v [[ stage_in ]]) +{ + VertToFrag vtf; + vtf.position = v.posIn; + return vtf; +} + +#fragment metal +struct VertToFrag +{ + float4 position [[ position ]]; +}; + +fragment float4 fmain(VertToFrag vtf [[ stage_in ]]) +{ + return float4(1.0, 1.0, 1.0, 1.0); +} + +#shader CFogVolumePlaneShader1 : CFogVolumePlaneShader0 +#depthtest none +#depthwrite false +#colorwrite false +#culling frontface + +#shader CFogVolumePlaneShader2 : CFogVolumePlaneShader0 +#depthtest lequal +#depthwrite true +#colorwrite false +#culling backface + +#shader CFogVolumePlaneShader3 : CFogVolumePlaneShader0 +#depthtest greater +#depthwrite false +#colorwrite false +#culling backface diff --git a/Shaders/CLineRendererShaders.shader b/Shaders/CLineRendererShaders.shader new file mode 100644 index 000000000..89bf49fb4 --- /dev/null +++ b/Shaders/CLineRendererShaders.shader @@ -0,0 +1,298 @@ +#shader CLineRendererShaderTexAlpha +#attribute position4 +#attribute color +#attribute uv4 +#srcfac srcalpha +#dstfac invsrcalpha +#primitive tristrips +#depthtest none +#depthwrite false +#culling none + +#vertex glsl +layout(location=0) in vec4 posIn; +layout(location=1) in vec4 colorIn; +layout(location=2) in vec4 uvIn; + +UBINDING0 uniform LineUniform +{ + vec4 moduColor; +}; + +struct VertToFrag +{ + vec4 color; + vec2 uv; +}; + +SBINDING(0) out VertToFrag vtf; +void main() +{ + vtf.color = colorIn * moduColor; + vtf.uv = uvIn.xy; + gl_Position = posIn; +} + +#fragment glsl +struct VertToFrag +{ + vec4 color; + vec2 uv; +}; + +SBINDING(0) in VertToFrag vtf; +layout(location=0) out vec4 colorOut; +TBINDING0 uniform sampler2D tex; +void main() +{ + colorOut = vtf.color * texture(tex, vtf.uv); +} + +#vertex hlsl +struct VertData +{ + float4 posIn : POSITION; + float4 colorIn : COLOR; + float4 uvIn : UV; +}; + +cbuffer LineUniform : register(b0) +{ + float4 moduColor; +}; + +struct VertToFrag +{ + float4 position : SV_Position; + float4 color : COLOR; + float2 uv : UV; +}; + +VertToFrag main(in VertData v) +{ + VertToFrag vtf; + vtf.color = v.colorIn * moduColor; + vtf.uv = v.uvIn.xy; + vtf.position = v.posIn; + return vtf; +} + +#fragment hlsl +SamplerState samp : register(s0); +Texture2D tex0 : register(t0); +struct VertToFrag +{ + float4 position : SV_Position; + float4 color : COLOR; + float2 uv : UV; +}; + +float4 main(in VertToFrag vtf) : SV_Target0 +{ + return vtf.color * tex0.Sample(samp, vtf.uv); +} + +#vertex metal +struct VertData +{ + float4 posIn; + float4 colorIn; + float4 uvIn; +}; + +struct LineUniform +{ + float4 moduColor; +}; + +struct VertToFrag +{ + float4 position [[ position ]]; + float4 color; + float2 uv; +}; + +vertex VertToFrag vmain(constant VertData* va [[ buffer(0) ]], + uint vertId [[ vertex_id ]], + constant LineUniform& line [[ buffer(2) ]]) +{ + VertToFrag vtf; + constant VertData& v = va[vertId]; + vtf.color = v.colorIn * line.moduColor; + vtf.uv = v.uvIn.xy; + vtf.position = v.posIn; + return vtf; +} + +#fragment metal +struct VertToFrag +{ + float4 position [[ position ]]; + float4 color; + float2 uv; +}; + +fragment float4 fmain(VertToFrag vtf [[ stage_in ]], + sampler samp [[ sampler(0) ]], + texture2d tex0 [[ texture(0) ]]) +{ + return vtf.color * tex0.sample(samp, vtf.uv); +} + +#shader CLineRendererShaderTexAdditive : CLineRendererShaderTexAlpha +#srcfac srcalpha +#dstfac one +#depthtest none + +#shader CLineRendererShaderTexAlphaZ : CLineRendererShaderTexAlpha +#srcfac srcalpha +#dstfac invsrcalpha +#depthtest lequal + +#shader CLineRendererShaderTexAdditiveZ : CLineRendererShaderTexAlpha +#srcfac srcalpha +#dstfac one +#depthtest lequal + +#shader CLineRendererShaderNoTexAlpha +#attribute position4 +#attribute color +#srcfac srcalpha +#dstfac invsrcalpha +#primitive tristrips +#depthtest none +#depthwrite false +#culling none + +#vertex glsl +layout(location=0) in vec4 posIn; +layout(location=1) in vec4 colorIn; + +UBINDING0 uniform LineUniform +{ + vec4 moduColor; +}; + +struct VertToFrag +{ + vec4 color; +}; + +SBINDING(0) out VertToFrag vtf; +void main() +{ + vtf.color = colorIn * moduColor; + gl_Position = posIn; +} + +#fragment glsl +struct VertToFrag +{ + vec4 color; +}; + +SBINDING(0) in VertToFrag vtf; +layout(location=0) out vec4 colorOut; +void main() +{ + colorOut = vtf.color; +} + +#vertex hlsl +struct VertData +{ + float4 posIn : POSITION; + float4 colorIn : COLOR; +}; + +cbuffer LineUniform : register(b0) +{ + float4 moduColor; +}; + +struct VertToFrag +{ + float4 position : SV_Position; + float4 color : COLOR; +}; + +VertToFrag main(in VertData v) +{ + VertToFrag vtf; + vtf.color = v.colorIn * moduColor; + vtf.position = v.posIn; + return vtf; +} + +#fragment hlsl +struct VertToFrag +{ + float4 position : SV_Position; + float4 color : COLOR; +}; + +float4 main(in VertToFrag vtf) : SV_Target0 +{ + return vtf.color; +} + +#vertex metal +struct VertData +{ + float4 posIn; + float4 colorIn; +}; + +struct LineUniform +{ + float4 moduColor; +}; + +struct VertToFrag +{ + float4 position [[ position ]]; + float4 color; +}; + +vertex VertToFrag vmain(constant VertData* va [[ buffer(0) ]], + uint vertId [[ vertex_id ]], + constant LineUniform& line [[ buffer(2) ]]) +{ + VertToFrag vtf; + constant VertData& v = va[vertId]; + vtf.color = v.colorIn * line.moduColor; + vtf.position = v.posIn; + return vtf; +} + +#fragment metal +struct VertToFrag +{ + float4 position [[ position ]]; + float4 color; +}; + +fragment float4 fmain(VertToFrag vtf [[ stage_in ]]) +{ + return vtf.color; +} + +#shader CLineRendererShaderNoTexAdditive : CLineRendererShaderNoTexAlpha +#srcfac srcalpha +#dstfac one +#depthtest none + +#shader CLineRendererShaderNoTexAlphaZ : CLineRendererShaderNoTexAlpha +#srcfac srcalpha +#dstfac invsrcalpha +#depthtest lequal + +#shader CLineRendererShaderNoTexAdditiveZ : CLineRendererShaderNoTexAlpha +#srcfac srcalpha +#dstfac one +#depthtest lequal + +#shader CLineRendererShaderNoTexAlphaZGEqual : CLineRendererShaderNoTexAlpha +#srcfac srcalpha +#dstfac invsrcalpha +#depthtest gequal diff --git a/Shaders/CMakeLists.txt b/Shaders/CMakeLists.txt new file mode 100644 index 000000000..98f9c9f94 --- /dev/null +++ b/Shaders/CMakeLists.txt @@ -0,0 +1,35 @@ +include_directories(../hecl/include + ../hecl/extern/boo/include + ../hecl/extern/boo/logvisor/include + ../hecl/extern/athena/include + ../specter/zeus/include + ../Runtime) +add_shader(CAABoxShader) +add_shader(CCameraBlurFilter) +add_shader(CColoredQuadFilter) +add_shader(CDecalShaders) +add_shader(CElementGenShaders) +add_shader(CEnergyBarShader) +add_shader(CFogVolumeFilter) +add_shader(CFogVolumePlaneShader) +add_shader(CLineRendererShaders) +add_shader(CMapSurfaceShader) +add_shader(CMoviePlayerShader) +add_shader(CNESShader) +add_shader(CParticleSwooshShaders) +add_shader(CPhazonSuitFilter) +add_shader(CRadarPaintShader) +add_shader(CRandomStaticFilter) +add_shader(CScanLinesFilter) +add_shader(CSpaceWarpFilter) +add_shader(CTextSupportShader) +add_shader(CTexturedQuadFilter) +add_shader(CThermalColdFilter) +add_shader(CThermalHotFilter) +add_shader(CWorldShadowShader) +add_shader(CXRayBlurFilter) +add_special_shader(shader_CFluidPlaneShader + shader_CFluidPlaneShader.cpp + shader_CFluidPlaneShaderGLSL.cpp + shader_CFluidPlaneShaderHLSL.cpp + shader_CFluidPlaneShaderMetal.cpp) diff --git a/Shaders/CMapSurfaceShader.shader b/Shaders/CMapSurfaceShader.shader new file mode 100644 index 000000000..645b3cbd4 --- /dev/null +++ b/Shaders/CMapSurfaceShader.shader @@ -0,0 +1,118 @@ +#shader CMapSurfaceShader +#attribute position4 +#srcfac srcalpha +#dstfac invsrcalpha +#primitive tristrips +#depthtest gequal +#depthwrite false +#culling backface + +#vertex glsl +layout(location=0) in vec4 posIn; + +UBINDING0 uniform MapSurfaceUniform +{ + mat4 xf; + vec4 color; +}; + +struct VertToFrag +{ + vec4 color; +}; + +SBINDING(0) out VertToFrag vtf; +void main() +{ + vtf.color = color; + gl_Position = xf * vec4(posIn.xyz, 1.0); +} + +#fragment glsl +struct VertToFrag +{ + vec4 color; +}; + +SBINDING(0) in VertToFrag vtf; +layout(location=0) out vec4 colorOut; +void main() +{ + colorOut = vtf.color; +} + +#vertex hlsl +struct VertData +{ + float4 posIn : POSITION; +}; + +cbuffer MapSurfaceUniform : register(b0) +{ + float4x4 xf; + float4 color; +}; + +struct VertToFrag +{ + float4 position : SV_Position; + float4 color : COLOR; +}; + +VertToFrag main(in VertData v) +{ + VertToFrag vtf; + vtf.color = color; + vtf.position = mul(xf, float4(v.posIn.xyz, 1.0)); + return vtf; +} + +#fragment hlsl +struct VertToFrag +{ + float4 position : SV_Position; + float4 color : COLOR; +}; + +float4 main(in VertToFrag vtf) : SV_Target0 +{ + return vtf.color; +} + +#vertex metal +struct VertData +{ + float4 posIn [[ attribute(0) ]]; +}; + +struct MapSurfaceUniform +{ + float4x4 xf; + float4 color; +}; + +struct VertToFrag +{ + float4 position [[ position ]]; + float4 color; +}; + +vertex VertToFrag vmain(VertData v [[ stage_in ]], constant MapSurfaceUniform& msu [[ buffer(2) ]]) +{ + VertToFrag vtf; + vtf.color = msu.color; + vtf.position = msu.xf * float4(v.posIn.xyz, 1.0); + return vtf; +} + +#fragment metal +struct VertToFrag +{ + float4 position [[ position ]]; + float4 color; +}; + +fragment float4 fmain(VertToFrag vtf [[ stage_in ]]) +{ + return vtf.color; +} diff --git a/Shaders/CMoviePlayerShader.shader b/Shaders/CMoviePlayerShader.shader new file mode 100644 index 000000000..0bdd7906f --- /dev/null +++ b/Shaders/CMoviePlayerShader.shader @@ -0,0 +1,156 @@ +#shader CMoviePlayerShader +#attribute position4 +#attribute uv4 +#srcfac srcalpha +#dstfac invsrcalpha +#primitive tristrips +#depthtest none +#depthwrite false +#culling none + +#vertex glsl +layout(location=0) in vec3 posIn; +layout(location=1) in vec2 uvIn; +UBINDING0 uniform ViewBlock +{ + mat4 mv; + vec4 mulColor; +}; +struct VertToFrag +{ + vec4 color; + vec2 uv; +}; +SBINDING(0) out VertToFrag vtf; +void main() +{ + vtf.uv = uvIn; + vtf.color = mulColor; + gl_Position = mv * vec4(posIn, 1.0); + gl_Position = FLIPFROMGL(gl_Position); +} + +#fragment glsl +struct VertToFrag +{ + vec4 color; + vec2 uv; +}; +SBINDING(0) in VertToFrag vtf; +TBINDING0 uniform sampler2D texY; +TBINDING1 uniform sampler2D texU; +TBINDING2 uniform sampler2D texV; +layout(location=0) out vec4 colorOut; +void main() +{ + vec3 yuv; + yuv.r = texture(texY, vtf.uv).r; + yuv.g = texture(texU, vtf.uv).r; + yuv.b = texture(texV, vtf.uv).r; + yuv.r = 1.1643*(yuv.r-0.0625); + yuv.g = yuv.g-0.5; + yuv.b = yuv.b-0.5; + colorOut = vec4(yuv.r+1.5958*yuv.b, + yuv.r-0.39173*yuv.g-0.81290*yuv.b, + yuv.r+2.017*yuv.g, 1.0) * vtf.color; +} + +#vertex hlsl +struct VertData +{ + float3 posIn : POSITION; + float2 uvIn : UV; +}; +cbuffer ViewBlock : register(b0) +{ + float4x4 mv; + float4 mulColor; +}; +struct VertToFrag +{ + float4 position : SV_Position; + float4 color : COLOR; + float2 uv : UV; +}; +VertToFrag main(in VertData v) +{ + VertToFrag vtf; + vtf.uv = v.uvIn; + vtf.color = mulColor; + vtf.position = mul(mv, float4(v.posIn, 1.0)); + return vtf; +} + +#fragment hlsl +struct VertToFrag +{ + float4 position : SV_Position; + float4 color : COLOR; + float2 uv : UV; +}; +Texture2D texs[3] : register(t0); +SamplerState samp : register(s0); +float4 main(in VertToFrag vtf) : SV_Target0 +{ + float3 yuv; + yuv.r = texs[0].Sample(samp, vtf.uv).r; + yuv.g = texs[1].Sample(samp, vtf.uv).r; + yuv.b = texs[2].Sample(samp, vtf.uv).r; + yuv.r = 1.1643*(yuv.r-0.0625); + yuv.g = yuv.g-0.5; + yuv.b = yuv.b-0.5; + return float4(yuv.r+1.5958*yuv.b, + yuv.r-0.39173*yuv.g-0.81290*yuv.b, + yuv.r+2.017*yuv.g, 1.0) * vtf.color; +} + +#vertex metal +struct VertData +{ + float3 posIn [[ attribute(0) ]]; + float2 uvIn [[ attribute(1) ]]; +}; +struct ViewBlock +{ + float4x4 mv; + float4 mulColor; +}; +struct VertToFrag +{ + float4 position [[ position ]]; + float4 color; + float2 uv; +}; +vertex VertToFrag vmain(VertData v [[ stage_in ]], constant ViewBlock& view [[ buffer(2) ]]) +{ + VertToFrag vtf; + vtf.uv = v.uvIn; + vtf.color = view.mulColor; + vtf.position = view.mv * float4(v.posIn, 1.0); + return vtf; +} + +#fragment metal +struct VertToFrag +{ + float4 position [[ position ]]; + float4 color; + float2 uv; +}; +fragment float4 fmain(VertToFrag vtf [[ stage_in ]], + sampler samp [[ sampler(0) ]], + texture2d tex0 [[ texture(0) ]], + texture2d tex1 [[ texture(1) ]], + texture2d tex2 [[ texture(2) ]]) +{ + float3 yuv; + yuv.r = tex0.sample(samp, vtf.uv).r; + yuv.g = tex1.sample(samp, vtf.uv).r; + yuv.b = tex2.sample(samp, vtf.uv).r; + yuv.r = 1.1643*(yuv.r-0.0625); + yuv.g = yuv.g-0.5; + yuv.b = yuv.b-0.5; + return float4(yuv.r+1.5958*yuv.b, + yuv.r-0.39173*yuv.g-0.81290*yuv.b, + yuv.r+2.017*yuv.g, 1.0) * vtf.color; +} diff --git a/Shaders/CNESShader.shader b/Shaders/CNESShader.shader new file mode 100644 index 000000000..5ed5bbc16 --- /dev/null +++ b/Shaders/CNESShader.shader @@ -0,0 +1,138 @@ +#shader CNESShader +#attribute position4 +#attribute uv4 +#srcfac srcalpha +#dstfac invsrcalpha +#primitive tristrips +#depthtest none +#depthwrite false +#culling none + +#vertex glsl +layout(location=0) in vec4 posIn; +layout(location=1) in vec4 uvIn; + +UBINDING0 uniform TexuredQuadUniform +{ + mat4 mtx; + vec4 color; +}; + +struct VertToFrag +{ + vec4 color; + vec2 uv; +}; + +SBINDING(0) out VertToFrag vtf; +void main() +{ + vtf.color = color; + vtf.uv = uvIn.xy; + gl_Position = mtx * vec4(posIn.xyz, 1.0); + gl_Position = FLIPFROMGL(gl_Position); +} + +#fragment glsl +struct VertToFrag +{ + vec4 color; + vec2 uv; +}; + +SBINDING(0) in VertToFrag vtf; +layout(location=0) out vec4 colorOut; +TBINDING0 uniform sampler2D tex; +void main() +{ + colorOut = vtf.color * texture(tex, vtf.uv); +} + +#vertex hlsl +struct VertData +{ + float4 posIn : POSITION; + float4 uvIn : UV; +}; + +cbuffer TexuredQuadUniform : register(b0) +{ + float4x4 mat; + float4 color; +}; + +struct VertToFrag +{ + float4 position : SV_Position; + float4 color : COLOR; + float2 uv : UV; +}; + +VertToFrag main(in VertData v) +{ + VertToFrag vtf; + vtf.color = color; + vtf.uv = v.uvIn.xy; + vtf.position = mul(mat, float4(v.posIn.xyz, 1.0)); + return vtf; +} + +#fragment hlsl +struct VertToFrag +{ + float4 position : SV_Position; + float4 color : COLOR; + float2 uv : UV; +}; + +Texture2D tex : register(t0); +SamplerState samp : register(s4); + +float4 main(in VertToFrag vtf) : SV_Target0 +{ + return vtf.color * tex.Sample(samp, vtf.uv); +} + +#vertex metal +struct VertData +{ + float4 posIn [[ attribute(0) ]]; + float4 uvIn [[ attribute(1) ]]; +}; + +struct TexuredQuadUniform +{ + float4x4 mat; + float4 color; +}; + +struct VertToFrag +{ + float4 position [[ position ]]; + float4 color; + float2 uv; +}; + +vertex VertToFrag vmain(VertData v [[ stage_in ]], constant TexuredQuadUniform& tqu [[ buffer(2) ]]) +{ + VertToFrag vtf; + vtf.color = tqu.color; + vtf.uv = v.uvIn.xy; + vtf.position = tqu.mat * float4(v.posIn.xyz, 1.0); + return vtf; +} + +#fragment metal +struct VertToFrag +{ + float4 position [[ position ]]; + float4 color; + float2 uv; +}; + +fragment float4 fmain(VertToFrag vtf [[ stage_in ]], + sampler clampSamp [[ sampler(4) ]], + texture2d tex [[ texture(0) ]]) +{ + return vtf.color * tex.sample(clampSamp, vtf.uv); +} diff --git a/Shaders/CParticleSwooshShaders.shader b/Shaders/CParticleSwooshShaders.shader new file mode 100644 index 000000000..0fe09fd12 --- /dev/null +++ b/Shaders/CParticleSwooshShaders.shader @@ -0,0 +1,216 @@ +#shader CParticleSwooshShaderTexZWrite +#attribute position4 +#attribute uv4 +#attribute color +#srcfac srcalpha +#dstfac invsrcalpha +#primitive tristrips +#depthtest lequal +#depthwrite true +#culling none + +#vertex glsl +layout(location=0) in vec4 posIn; +layout(location=1) in vec4 uvIn; +layout(location=2) in vec4 colorIn; + +UBINDING0 uniform SwooshUniform +{ + mat4 mvp; +}; + +struct VertToFrag +{ + vec4 color; + vec2 uv; +}; + +SBINDING(0) out VertToFrag vtf; +void main() +{ + vtf.color = colorIn; + vtf.uv = uvIn.xy; + gl_Position = mvp * vec4(posIn.xyz, 1.0); +} + +#fragment glsl +struct VertToFrag +{ + vec4 color; + vec2 uv; +}; + +SBINDING(0) in VertToFrag vtf; +layout(location=0) out vec4 colorOut; +TBINDING0 uniform sampler2D tex; +void main() +{ + colorOut = vtf.color * texture(tex, vtf.uv); +} + +#vertex hlsl +struct VertData +{ + float4 posIn : POSITION; + float4 uvIn : UV; + float4 colorIn : COLOR; +}; + +cbuffer SwooshUniform : register(b0) +{ + float4x4 mvp; +}; + +struct VertToFrag +{ + float4 pos : SV_Position; + float4 color : COLOR; + float2 uv : UV; +}; + +VertToFrag main(in VertData v) +{ + VertToFrag vtf; + vtf.color = v.colorIn; + vtf.uv = v.uvIn.xy; + vtf.pos = mul(mvp, float4(v.posIn.xyz, 1.0)); + return vtf; +} + +#fragment hlsl +struct VertToFrag +{ + float4 pos : SV_Position; + float4 color : COLOR; + float2 uv : UV; +}; + +SamplerState samp : register(s0); +Texture2D tex : register(t0); +float4 main(in VertToFrag vtf) : SV_Target0 +{ + return vtf.color * tex.Sample(samp, vtf.uv); +} + +#vertex metal +struct VertData +{ + float4 posIn [[ attribute(0) ]]; + float4 uvIn [[ attribute(1) ]]; + float4 colorIn [[ attribute(2) ]]; +}; + +struct SwooshUniform +{ + float4x4 mvp; +}; + +struct VertToFrag +{ + float4 pos [[ position ]]; + float4 color; + float2 uv; +}; + +vertex VertToFrag vmain(VertData v [[ stage_in ]], constant SwooshUniform& su [[ buffer(2) ]]) +{ + VertToFrag vtf; + vtf.color = v.colorIn; + vtf.uv = v.uvIn.xy; + vtf.pos = su.mvp * float4(v.posIn.xyz, 1.0); + return vtf; +} + +#fragment metal +struct VertToFrag +{ + float4 pos [[ position ]]; + float4 color; + float2 uv; +}; + +fragment float4 fmain(VertToFrag vtf [[ stage_in ]], + sampler samp [[ sampler(0) ]], + texture2d tex [[ texture(0) ]]) +{ + return vtf.color * tex.sample(samp, vtf.uv); +} + + +#shader CParticleSwooshShaderTexNoZWrite : CParticleSwooshShaderTexZWrite +#srcfac srcalpha +#dstfac invsrcalpha +#depthwrite false + +#shader CParticleSwooshShaderTexAdditiveZWrite : CParticleSwooshShaderTexZWrite +#srcfac srcalpha +#dstfac one +#depthwrite true + +#shader CParticleSwooshShaderTexAdditiveNoZWrite : CParticleSwooshShaderTexZWrite +#srcfac srcalpha +#dstfac one +#depthwrite false + +#shader CParticleSwooshShaderNoTexZWrite : CParticleSwooshShaderTexZWrite +#srcfac srcalpha +#dstfac invsrcalpha +#depthtest lequal +#depthwrite true + +#fragment glsl +struct VertToFrag +{ + vec4 color; + vec2 uv; +}; + +SBINDING(0) in VertToFrag vtf; +layout(location=0) out vec4 colorOut; +void main() +{ + colorOut = vtf.color; +} + +#fragment hlsl +struct VertToFrag +{ + float4 pos : SV_Position; + float4 color : COLOR; + float2 uv : UV; +}; + +float4 main(in VertToFrag vtf) : SV_Target0 +{ + return vtf.color; +} + +#fragment metal +struct VertToFrag +{ + float4 pos [[ position ]]; + float4 color; + float2 uv; +}; + +fragment float4 fmain(VertToFrag vtf [[ stage_in ]]) +{ + return vtf.color; +} + + +#shader CParticleSwooshShaderNoTexNoZWrite : CParticleSwooshShaderNoTexZWrite +#srcfac srcalpha +#dstfac invsrcalpha +#depthwrite false + +#shader CParticleSwooshShaderNoTexAdditiveZWrite : CParticleSwooshShaderNoTexZWrite +#srcfac srcalpha +#dstfac one +#depthwrite true + +#shader CParticleSwooshShaderNoTexAdditiveNoZWrite : CParticleSwooshShaderNoTexZWrite +#srcfac srcalpha +#dstfac one +#depthwrite false + diff --git a/Shaders/CPhazonSuitFilter.shader b/Shaders/CPhazonSuitFilter.shader new file mode 100644 index 000000000..83369aa54 --- /dev/null +++ b/Shaders/CPhazonSuitFilter.shader @@ -0,0 +1,478 @@ +#shader CPhazonSuitFilterInd +#attribute position4 +#attribute uv4 0 +#attribute uv4 1 +#attribute uv4 2 +#srcfac srcalpha +#dstfac one +#primitive tristrips +#depthtest none +#depthwrite false +#culling none + +#vertex glsl +layout(location=0) in vec4 posIn; +layout(location=1) in vec4 screenUvIn; +layout(location=2) in vec4 indUvIn; +layout(location=3) in vec4 maskUvIn; + +UBINDING0 uniform PhazonSuitUniform +{ + vec4 color; + vec4 indScaleOff; +}; + +struct VertToFrag +{ + vec4 color; + vec4 indScaleOff; + vec2 screenUv; + vec2 indUv; + vec2 maskUv; +}; + +SBINDING(0) out VertToFrag vtf; +void main() +{ + vtf.color = color; + vtf.indScaleOff = indScaleOff; + vtf.screenUv = screenUvIn.xy; + vtf.indUv = indUvIn.xy; + vtf.maskUv = maskUvIn.xy; + gl_Position = vec4(posIn.xyz, 1.0); +} + +#fragment glsl +struct VertToFrag +{ + vec4 color; + vec4 indScaleOff; + vec2 screenUv; + vec2 indUv; + vec2 maskUv; +}; + +SBINDING(0) in VertToFrag vtf; +layout(location=0) out vec4 colorOut; +TBINDING0 uniform sampler2D screenTex; +TBINDING1 uniform sampler2D indTex; +TBINDING2 uniform sampler2D maskTex; +TBINDING3 uniform sampler2D maskTexBlur; +void main() +{ + vec2 indUv = (texture(indTex, vtf.indUv).ra - vec2(0.5, 0.5)) * + vtf.indScaleOff.xy + vtf.indScaleOff.zw; + float maskBlurAlpha = clamp(0.0, (texture(maskTexBlur, vtf.maskUv).a - texture(maskTex, vtf.maskUv).a) * 2.0, 1.0); + colorOut = vtf.color * texture(screenTex, indUv + vtf.screenUv) * maskBlurAlpha; + colorOut.a = vtf.color.a; +} + +#vertex hlsl +struct VertData { + float4 posIn : POSITION; + float4 screenUvIn : UV0; + float4 indUvIn : UV1; + float4 maskUvIn : UV2; +}; + +cbuffer PhazonSuitUniform : register(b0) +{ + float4 color; + float4 indScaleOff; +}; + +struct VertToFrag +{ + float4 position : SV_Position; + float4 color : COLOR; + float4 indScaleOff : SCALEOFF; + float2 screenUv : UV0; + float2 indUv : UV1; + float2 maskUv : UV2; +}; + +VertToFrag main(in VertData v) +{ + VertToFrag vtf; + vtf.color = color; + vtf.indScaleOff = indScaleOff; + vtf.screenUv = v.screenUvIn.xy; + vtf.screenUv.y = 1.0 - vtf.screenUv.y; + vtf.indUv = v.indUvIn.xy; + vtf.maskUv = v.maskUvIn.xy; + vtf.maskUv.y = 1.0 - vtf.maskUv.y; + vtf.position = float4(v.posIn.xyz, 1.0); + return vtf; +} + +#fragment hlsl +struct VertToFrag +{ + float4 position : SV_Position; + float4 color : COLOR; + float4 indScaleOff : SCALEOFF; + float2 screenUv : UV0; + float2 indUv : UV1; + float2 maskUv : UV2; +}; + +SamplerState samp : register(s0); +Texture2D screenTex : register(t0); +Texture2D indTex : register(t1); +Texture2D maskTex : register(t2); +Texture2D maskTexBlur : register(t3); +float4 main(in VertToFrag vtf) : SV_Target0 +{ + float2 indUv = (indTex.Sample(samp, vtf.indUv).ra - float2(0.5, 0.5)) * + vtf.indScaleOff.xy + vtf.indScaleOff.zw; + float maskBlurAlpha = saturate((maskTexBlur.Sample(samp, vtf.maskUv).a - maskTex.Sample(samp, vtf.maskUv).a) * 2.0); + return float4((vtf.color * screenTex.Sample(samp, indUv + vtf.screenUv) * maskBlurAlpha).rgb, vtf.color.a); +} + +#vertex metal +struct VertData +{ + float4 posIn [[ attribute(0) ]]; + float4 screenUvIn [[ attribute(1) ]]; + float4 indUvIn [[ attribute(2) ]]; + float4 maskUvIn [[ attribute(3) ]]; +}; + +struct PhazonSuitUniform +{ + float4 color; + float4 indScaleOff; +}; + +struct VertToFrag +{ + float4 position [[ position ]]; + float4 color; + float4 indScaleOff; + float2 screenUv; + float2 indUv; + float2 maskUv; +}; + +vertex VertToFrag vmain(VertData v [[ stage_in ]], constant PhazonSuitUniform& psu [[ buffer(2) ]]) +{ + VertToFrag vtf; + vtf.color = psu.color; + vtf.indScaleOff = psu.indScaleOff; + vtf.screenUv = v.screenUvIn.xy; + vtf.screenUv.y = 1.0 - vtf.screenUv.y; + vtf.indUv = v.indUvIn.xy; + vtf.maskUv = v.maskUvIn.xy; + vtf.maskUv.y = 1.0 - vtf.maskUv.y; + vtf.position = float4(v.posIn.xyz, 1.0); + return vtf; +} + +#fragment metal +struct VertToFrag +{ + float4 position [[ position ]]; + float4 color; + float4 indScaleOff; + float2 screenUv; + float2 indUv; + float2 maskUv; +}; + +fragment float4 fmain(VertToFrag vtf [[ stage_in ]], + sampler samp [[ sampler(0) ]], + texture2d screenTex [[ texture(0) ]], + texture2d indTex [[ texture(1) ]], + texture2d maskTex [[ texture(2) ]], + texture2d maskTexBlur [[ texture(3) ]]) +{ + float2 indUv = (indTex.sample(samp, vtf.indUv).ra - float2(0.5, 0.5)) * + vtf.indScaleOff.xy + vtf.indScaleOff.zw; + float maskBlurAlpha = saturate((maskTexBlur.sample(samp, vtf.maskUv).a - maskTex.sample(samp, vtf.maskUv).a) * 2.0); + return float4((vtf.color * screenTex.sample(samp, indUv + vtf.screenUv) * maskBlurAlpha).rgb, vtf.color.a); +} + + +#shader CPhazonSuitFilterNoInd : CPhazonSuitFilterInd + +#fragment glsl +struct VertToFrag +{ + vec4 color; + vec4 indScaleOff; + vec2 screenUv; + vec2 indUv; + vec2 maskUv; +}; + +SBINDING(0) in VertToFrag vtf; +layout(location=0) out vec4 colorOut; +TBINDING0 uniform sampler2D screenTex; +TBINDING1 uniform sampler2D maskTex; +TBINDING2 uniform sampler2D maskTexBlur; +void main() +{ + float maskBlurAlpha = clamp(0.0, (texture(maskTexBlur, vtf.maskUv).a - texture(maskTex, vtf.maskUv).a) * 2.0, 1.0); + colorOut = vtf.color * texture(screenTex, vtf.screenUv) * maskBlurAlpha; + colorOut.a = vtf.color.a; +} + +#fragment hlsl +struct VertToFrag +{ + float4 position : SV_Position; + float4 color : COLOR; + float4 indScaleOff : SCALEOFF; + float2 screenUv : UV0; + float2 indUv : UV1; + float2 maskUv : UV2; +}; + +SamplerState samp : register(s3); +Texture2D screenTex : register(t0); +Texture2D maskTex : register(t1); +Texture2D maskTexBlur : register(t2); +float4 main(in VertToFrag vtf) : SV_Target0 +{ + float maskBlurAlpha = saturate((maskTexBlur.Sample(samp, vtf.maskUv).a - maskTex.Sample(samp, vtf.maskUv).a) * 2.0); + return float4((vtf.color * screenTex.Sample(samp, vtf.screenUv) * maskBlurAlpha).rgb, vtf.color.a); +} + +#fragment metal +struct VertToFrag +{ + float4 color; + float4 indScaleOff; + float2 screenUv; + float2 indUv; + float2 maskUv; +}; + +fragment float4 fmain(VertToFrag vtf [[ stage_in ]], + sampler clampSamp [[ sampler(3) ]], + texture2d screenTex [[ texture(0) ]], + texture2d maskTex [[ texture(1) ]], + texture2d maskTexBlur [[ texture(2) ]]) +{ + float maskBlurAlpha = saturate((maskTexBlur.sample(clampSamp, vtf.maskUv).a - maskTex.sample(clampSamp, vtf.maskUv).a) * 2.0); + return float4((vtf.color * screenTex.sample(clampSamp, vtf.screenUv) * maskBlurAlpha).rgb, vtf.color.a); +} + + +#shader CPhazonSuitFilterBlur +#attribute position4 +#attribute uv4 +#srcfac one +#dstfac zero + +#vertex glsl +layout(location=0) in vec4 posIn; +layout(location=1) in vec4 uvIn; + +UBINDING0 uniform PhazonSuitBlurUniform +{ + vec4 blurDir; +}; + +struct VertToFrag +{ + vec2 uv; + vec2 blurDir; +}; + +SBINDING(0) out VertToFrag vtf; +void main() +{ + vtf.uv = uvIn.xy; + vtf.blurDir = blurDir.xy; + gl_Position = vec4(posIn.xyz, 1.0); +} + +#fragment glsl +struct VertToFrag +{ + vec2 uv; + vec2 blurDir; +}; + +SBINDING(0) in VertToFrag vtf; +layout(location=0) out vec4 colorOut; +TBINDING0 uniform sampler2D maskTex; +void main() +{ + //this will be our alpha sum + float sum = 0.0; + + //apply blurring, using a 23-tap filter with predefined gaussian weights + sum += texture(maskTex, vtf.uv + -11.0 * vtf.blurDir).a * 0.007249; + sum += texture(maskTex, vtf.uv + -10.0 * vtf.blurDir).a * 0.011032; + sum += texture(maskTex, vtf.uv + -9.0 * vtf.blurDir).a * 0.016133; + sum += texture(maskTex, vtf.uv + -8.0 * vtf.blurDir).a * 0.022665; + sum += texture(maskTex, vtf.uv + -7.0 * vtf.blurDir).a * 0.030595; + sum += texture(maskTex, vtf.uv + -6.0 * vtf.blurDir).a * 0.039680; + sum += texture(maskTex, vtf.uv + -5.0 * vtf.blurDir).a * 0.049444; + sum += texture(maskTex, vtf.uv + -4.0 * vtf.blurDir).a * 0.059195; + sum += texture(maskTex, vtf.uv + -3.0 * vtf.blurDir).a * 0.068091; + sum += texture(maskTex, vtf.uv + -2.0 * vtf.blurDir).a * 0.075252; + sum += texture(maskTex, vtf.uv + -1.0 * vtf.blurDir).a * 0.079905; + sum += texture(maskTex, vtf.uv + 0.0 * vtf.blurDir).a * 0.081519; + sum += texture(maskTex, vtf.uv + 1.0 * vtf.blurDir).a * 0.079905; + sum += texture(maskTex, vtf.uv + 2.0 * vtf.blurDir).a * 0.075252; + sum += texture(maskTex, vtf.uv + 3.0 * vtf.blurDir).a * 0.068091; + sum += texture(maskTex, vtf.uv + 4.0 * vtf.blurDir).a * 0.059195; + sum += texture(maskTex, vtf.uv + 5.0 * vtf.blurDir).a * 0.049444; + sum += texture(maskTex, vtf.uv + 6.0 * vtf.blurDir).a * 0.039680; + sum += texture(maskTex, vtf.uv + 7.0 * vtf.blurDir).a * 0.030595; + sum += texture(maskTex, vtf.uv + 8.0 * vtf.blurDir).a * 0.022665; + sum += texture(maskTex, vtf.uv + 9.0 * vtf.blurDir).a * 0.016133; + sum += texture(maskTex, vtf.uv + 10.0 * vtf.blurDir).a * 0.011032; + sum += texture(maskTex, vtf.uv + 11.0 * vtf.blurDir).a * 0.007249; + + colorOut = vec4(1.0, 1.0, 1.0, sum); +} + +#vertex hlsl +struct VertData { + float4 posIn : POSITION; + float4 uvIn : UV; +}; + +cbuffer PhazonSuitBlurUniform : register(b0) +{ + float4 blurDir; +}; + +struct VertToFrag +{ + float4 position : SV_Position; + float2 uv : UV; + float2 blurDir : BLURDIR; +}; + +VertToFrag main(in VertData v) +{ + VertToFrag vtf; + vtf.uv = v.uvIn.xy; + vtf.uv.y = 1.0 - vtf.uv.y; + vtf.blurDir = blurDir.xy; + vtf.position = float4(v.posIn.xyz, 1.0); + return vtf; +} + +#fragment hlsl +struct VertToFrag +{ + float4 position : SV_Position; + float2 uv : UV; + float2 blurDir : BLURDIR; +}; + +SamplerState samp : register(s3); +Texture2D maskTex : register(t0); +float4 main(in VertToFrag vtf) : SV_Target0 +{ + //this will be our alpha sum + float sum = 0.0; + + //apply blurring, using a 23-tap filter with predefined gaussian weights + sum += maskTex.Sample(samp, vtf.uv + -11.0 * vtf.blurDir).a * 0.007249; + sum += maskTex.Sample(samp, vtf.uv + -10.0 * vtf.blurDir).a * 0.011032; + sum += maskTex.Sample(samp, vtf.uv + -9.0 * vtf.blurDir).a * 0.016133; + sum += maskTex.Sample(samp, vtf.uv + -8.0 * vtf.blurDir).a * 0.022665; + sum += maskTex.Sample(samp, vtf.uv + -7.0 * vtf.blurDir).a * 0.030595; + sum += maskTex.Sample(samp, vtf.uv + -6.0 * vtf.blurDir).a * 0.039680; + sum += maskTex.Sample(samp, vtf.uv + -5.0 * vtf.blurDir).a * 0.049444; + sum += maskTex.Sample(samp, vtf.uv + -4.0 * vtf.blurDir).a * 0.059195; + sum += maskTex.Sample(samp, vtf.uv + -3.0 * vtf.blurDir).a * 0.068091; + sum += maskTex.Sample(samp, vtf.uv + -2.0 * vtf.blurDir).a * 0.075252; + sum += maskTex.Sample(samp, vtf.uv + -1.0 * vtf.blurDir).a * 0.079905; + sum += maskTex.Sample(samp, vtf.uv + 0.0 * vtf.blurDir).a * 0.081519; + sum += maskTex.Sample(samp, vtf.uv + 1.0 * vtf.blurDir).a * 0.079905; + sum += maskTex.Sample(samp, vtf.uv + 2.0 * vtf.blurDir).a * 0.075252; + sum += maskTex.Sample(samp, vtf.uv + 3.0 * vtf.blurDir).a * 0.068091; + sum += maskTex.Sample(samp, vtf.uv + 4.0 * vtf.blurDir).a * 0.059195; + sum += maskTex.Sample(samp, vtf.uv + 5.0 * vtf.blurDir).a * 0.049444; + sum += maskTex.Sample(samp, vtf.uv + 6.0 * vtf.blurDir).a * 0.039680; + sum += maskTex.Sample(samp, vtf.uv + 7.0 * vtf.blurDir).a * 0.030595; + sum += maskTex.Sample(samp, vtf.uv + 8.0 * vtf.blurDir).a * 0.022665; + sum += maskTex.Sample(samp, vtf.uv + 9.0 * vtf.blurDir).a * 0.016133; + sum += maskTex.Sample(samp, vtf.uv + 10.0 * vtf.blurDir).a * 0.011032; + sum += maskTex.Sample(samp, vtf.uv + 11.0 * vtf.blurDir).a * 0.007249; + + return float4(1.0, 1.0, 1.0, sum); +} + +#vertex metal +struct VertData +{ + float4 posIn [[ attribute(0) ]]; + float4 uvIn [[ attribute(1) ]]; +}; + +struct PhazonSuitBlurUniform +{ + float4 blurDir; +}; + +struct VertToFrag +{ + float4 position [[ position ]]; + float2 uv; + float2 blurDir; +}; + +vertex VertToFrag vmain(VertData v [[ stage_in ]], constant PhazonSuitBlurUniform& psu [[ buffer(2) ]]) +{ + VertToFrag vtf; + vtf.uv = v.uvIn.xy; + vtf.uv.y = 1.0 - vtf.uv.y; + vtf.blurDir = psu.blurDir.xy; + vtf.position = float4(v.posIn.xyz, 1.0); + return vtf; +} + +#fragment metal +struct VertToFrag +{ + float4 position [[ position ]]; + float2 uv; + float2 blurDir; +}; + +fragment float4 fmain(VertToFrag vtf [[ stage_in ]], + sampler clampSamp [[ sampler(3) ]], + texture2d maskTex [[ texture(0) ]]) +{ + //this will be our alpha sum + float sum = 0.0; + + //apply blurring, using a 23-tap filter with predefined gaussian weights + sum += maskTex.sample(clampSamp, vtf.uv + -11.0 * vtf.blurDir).a * 0.007249; + sum += maskTex.sample(clampSamp, vtf.uv + -10.0 * vtf.blurDir).a * 0.011032; + sum += maskTex.sample(clampSamp, vtf.uv + -9.0 * vtf.blurDir).a * 0.016133; + sum += maskTex.sample(clampSamp, vtf.uv + -8.0 * vtf.blurDir).a * 0.022665; + sum += maskTex.sample(clampSamp, vtf.uv + -7.0 * vtf.blurDir).a * 0.030595; + sum += maskTex.sample(clampSamp, vtf.uv + -6.0 * vtf.blurDir).a * 0.039680; + sum += maskTex.sample(clampSamp, vtf.uv + -5.0 * vtf.blurDir).a * 0.049444; + sum += maskTex.sample(clampSamp, vtf.uv + -4.0 * vtf.blurDir).a * 0.059195; + sum += maskTex.sample(clampSamp, vtf.uv + -3.0 * vtf.blurDir).a * 0.068091; + sum += maskTex.sample(clampSamp, vtf.uv + -2.0 * vtf.blurDir).a * 0.075252; + sum += maskTex.sample(clampSamp, vtf.uv + -1.0 * vtf.blurDir).a * 0.079905; + sum += maskTex.sample(clampSamp, vtf.uv).a * 0.081519; + sum += maskTex.sample(clampSamp, vtf.uv + 1.0 * vtf.blurDir).a * 0.079905; + sum += maskTex.sample(clampSamp, vtf.uv + 2.0 * vtf.blurDir).a * 0.075252; + sum += maskTex.sample(clampSamp, vtf.uv + 3.0 * vtf.blurDir).a * 0.068091; + sum += maskTex.sample(clampSamp, vtf.uv + 4.0 * vtf.blurDir).a * 0.059195; + sum += maskTex.sample(clampSamp, vtf.uv + 5.0 * vtf.blurDir).a * 0.049444; + sum += maskTex.sample(clampSamp, vtf.uv + 6.0 * vtf.blurDir).a * 0.039680; + sum += maskTex.sample(clampSamp, vtf.uv + 7.0 * vtf.blurDir).a * 0.030595; + sum += maskTex.sample(clampSamp, vtf.uv + 8.0 * vtf.blurDir).a * 0.022665; + sum += maskTex.sample(clampSamp, vtf.uv + 9.0 * vtf.blurDir).a * 0.016133; + sum += maskTex.sample(clampSamp, vtf.uv + 10.0 * vtf.blurDir).a * 0.011032; + sum += maskTex.sample(clampSamp, vtf.uv + 11.0 * vtf.blurDir).a * 0.007249; + + return float4(1.0, 1.0, 1.0, sum); +} + + + diff --git a/Shaders/CRadarPaintShader.shader b/Shaders/CRadarPaintShader.shader new file mode 100644 index 000000000..2edc1970d --- /dev/null +++ b/Shaders/CRadarPaintShader.shader @@ -0,0 +1,148 @@ +#shader CRadarPaintShader +#attribute position4 0 +#attribute position4 1 +#attribute position4 2 +#attribute position4 3 +#attribute uv4 0 +#attribute uv4 1 +#attribute uv4 2 +#attribute uv4 3 +#attribute color +#srcfac srcalpha +#dstfac one +#primitive tristrips +#depthtest none +#depthwrite false +#culling none + +#vertex glsl +layout(location=0) in vec4 posIn[4]; +layout(location=4) in vec4 uvIn[4]; +layout(location=8) in vec4 colorIn; + +UBINDING0 uniform RadarPaintUniform +{ + mat4 xf; +}; + +struct VertToFrag +{ + vec4 color; + vec2 uv; +}; + +SBINDING(0) out VertToFrag vtf; +void main() +{ + vec3 pos = posIn[gl_VertexID].xyz; + vtf.uv = uvIn[gl_VertexID].xy; + vtf.color = colorIn; + gl_Position = xf * vec4(pos, 1.0); +} + +#fragment glsl +struct VertToFrag +{ + vec4 color; + vec2 uv; +}; + +SBINDING(0) in VertToFrag vtf; +layout(location=0) out vec4 colorOut; +TBINDING0 uniform sampler2D tex; +void main() +{ + colorOut = vtf.color * texture(tex, vtf.uv); +} + +#vertex hlsl +struct VertData +{ + float4 posIn[4] : POSITION; + float4 uvIn[4] : UV; + float4 colorIn : COLOR; +}; + +cbuffer RadarPaintUniform : register(b0) +{ + float4x4 xf; +}; + +struct VertToFrag +{ + float4 position : SV_Position; + float4 color : COLOR; + float2 uv : UV; +}; + +VertToFrag main(in VertData v, in uint vertId : SV_VertexID) +{ + VertToFrag vtf; + vtf.color = v.colorIn; + vtf.uv = v.uvIn[vertId].xy; + vtf.position = mul(xf, float4(v.posIn[vertId].xyz, 1.0)); + return vtf; +} + +#fragment hlsl +struct VertToFrag +{ + float4 position : SV_Position; + float4 color : COLOR; + float2 uv : UV; +}; + +SamplerState samp : register(s0); +Texture2D tex : register(t0); +float4 main(in VertToFrag vtf) : SV_Target0 +{ + return vtf.color * tex.Sample(samp, vtf.uv); +} + +#vertex metal +struct VertData +{ + float4 posIn[4]; + float4 uvIn[4]; + float4 colorIn; +}; + +struct RadarPaintUniform +{ + float4x4 xf; +}; + +struct VertToFrag +{ + float4 position [[ position ]]; + float4 color; + float2 uv; +}; + +vertex VertToFrag vmain(constant VertData* va [[ buffer(1) ]], + uint vertId [[ vertex_id ]], uint instId [[ instance_id ]], + constant RadarPaintUniform& rpu [[ buffer(2) ]]) +{ + VertToFrag vtf; + constant VertData& v = va[instId]; + vtf.color = v.colorIn; + vtf.uv = v.uvIn[vertId].xy; + vtf.position = rpu.xf * float4(v.posIn[vertId].xyz, 1.0); + return vtf; +} + +#fragment metal +struct VertToFrag +{ + float4 position [[ position ]]; + float4 color; + float2 uv; +}; + +fragment float4 fmain(VertToFrag vtf [[ stage_in ]], + sampler samp [[ sampler(0) ]], + texture2d tex [[ texture(0) ]]) +{ + return vtf.color * tex.sample(samp, vtf.uv); +} + diff --git a/Shaders/CRandomStaticFilter.shader b/Shaders/CRandomStaticFilter.shader new file mode 100644 index 000000000..6fee875e9 --- /dev/null +++ b/Shaders/CRandomStaticFilter.shader @@ -0,0 +1,310 @@ +#shader CRandomStaticFilterAlpha +#attribute position4 +#attribute uv4 +#srcfac srcalpha +#dstfac invsrcalpha +#primitive tristrips +#depthtest none +#depthwrite false +#culling none + +#vertex glsl +layout(location=0) in vec4 posIn; +layout(location=1) in vec4 uvIn; + +UBINDING0 uniform RandomStaticUniform +{ + vec4 color; + float randOff; + float discardThres; +}; + +struct VertToFrag +{ + vec4 color; + vec2 uv; + float randOff; + float discardThres; +}; + +SBINDING(0) out VertToFrag vtf; +void main() +{ + vtf.color = color; + vtf.uv = uvIn.xy; + vtf.randOff = randOff; + vtf.discardThres = discardThres; + gl_Position = vec4(posIn.xyz, 1.0); +} + +#fragment glsl +struct VertToFrag +{ + vec4 color; + vec2 uv; + float randOff; + float discardThres; +}; + +ivec2 Lookup8BPP(in vec2 uv, in float randOff) +{ + float bx; + float rx = modf(uv.x / 8.0, bx) * 8.0; + float by; + float ry = modf(uv.y / 4.0, by) * 4.0; + float bidx = by * 80.0 + bx; + float addr = bidx * 32.0 + ry * 8.0 + rx + randOff; + float y; + float x = modf(addr / 1024.0, y) * 1024.0; + return ivec2(x, y); +} + +SBINDING(0) in VertToFrag vtf; +layout(location=0) out vec4 colorOut; +TBINDING0 uniform sampler2D tex; +void main() +{ + colorOut = texelFetch(tex, Lookup8BPP(vtf.uv, vtf.randOff), 0) * vtf.color; + colorOut.a = vtf.color.a; +} + +#vertex hlsl +struct VertData +{ + float4 posIn : POSITION; + float2 uvIn : UV; +}; + +cbuffer RandomStaticUniform : register(b0) +{ + float4 color; + float randOff; + float discardThres; +}; + +struct VertToFrag +{ + float4 pos : SV_Position; + float4 color : COLOR; + float2 uv : UV; + float randOff : RANDOFF; + float discardThres : DISCARDTHRES; +}; + +VertToFrag main(in VertData v) +{ + VertToFrag vtf; + vtf.color = color; + vtf.uv = v.uvIn.xy; + vtf.randOff = randOff; + vtf.discardThres = discardThres; + vtf.pos = float4(v.posIn.xyz, 1.0); + return vtf; +} + +#fragment hlsl +struct VertToFrag +{ + float4 pos : SV_Position; + float4 color : COLOR; + float2 uv : UV; + float randOff : RANDOFF; + float discardThres : DISCARDTHRES; +}; + +static int3 Lookup8BPP(float2 uv, float randOff) +{ + float bx; + float rx = modf(uv.x / 8.0, bx) * 8.0; + float by; + float ry = modf(uv.y / 4.0, by) * 4.0; + float bidx = by * 80.0 + bx; + float addr = bidx * 32.0 + ry * 8.0 + rx + randOff; + float y; + float x = modf(addr / 1024.0, y) * 1024.0; + return int3(x, y, 0); +} + +Texture2D tex : register(t0); +float4 main(in VertToFrag vtf) : SV_Target0 +{ + float4 colorOut = tex.Load(Lookup8BPP(vtf.uv, vtf.randOff)) * vtf.color; + colorOut.a = vtf.color.a; + return colorOut; +} + +#vertex metal +struct VertData +{ + float4 posIn [[ attribute(0) ]]; + float2 uvIn [[ attribute(1) ]]; +}; + +struct RandomStaticUniform +{ + float4 color; + float randOff; + float discardThres; +}; + +struct VertToFrag +{ + float4 pos [[ position ]]; + float4 color; + float2 uv; + float randOff; + float discardThres; +}; + +vertex VertToFrag vmain(VertData v [[ stage_in ]], + constant RandomStaticUniform& su [[ buffer(2) ]]) +{ + VertToFrag vtf; + vtf.color = su.color; + vtf.uv = v.uvIn.xy; + vtf.randOff = su.randOff; + vtf.discardThres = su.discardThres; + vtf.pos = float4(v.posIn.xyz, 1.0); + return vtf; +} + +#fragment metal +struct VertToFrag +{ + float4 pos [[ position ]]; + float4 color; + float2 uv; + float randOff; + float discardThres; +}; + +static uint2 Lookup8BPP(float2 uv, float randOff) +{ + float bx; + float rx = modf(uv.x / 8.0, bx) * 8.0; + float by; + float ry = modf(uv.y / 4.0, by) * 4.0; + float bidx = by * 80.0 + bx; + float addr = bidx * 32.0 + ry * 8.0 + rx + randOff; + float y; + float x = modf(addr / 1024.0, y) * 1024.0; + return uint2(x, y); +} + +fragment float4 fmain(VertToFrag vtf [[ stage_in ]], + texture2d tex [[ texture(0) ]]) +{ + float4 colorOut = tex.read(Lookup8BPP(vtf.uv, vtf.randOff)) * vtf.color; + colorOut.a = vtf.color.a; + return colorOut; +} + +#shader CRandomStaticFilterAdd : CRandomStaticFilterAlpha +#srcfac srcalpha +#dstfac one + +#shader CRandomStaticFilterMult : CRandomStaticFilterAlpha +#srcfac srccolor +#dstfac dstcolor + +#shader CRandomStaticFilterCookieCutter : CRandomStaticFilterAlpha +#srcfac srccolor +#dstfac dstcolor +#depthwrite true +#depthtest lequal + +#fragment glsl +struct VertToFrag +{ + vec4 color; + vec2 uv; + float randOff; + float discardThres; +}; + +ivec2 Lookup8BPP(in vec2 uv, in float randOff) +{ + float bx; + float rx = modf(uv.x / 8.0, bx) * 8.0; + float by; + float ry = modf(uv.y / 4.0, by) * 4.0; + float bidx = by * 80.0 + bx; + float addr = bidx * 32.0 + ry * 8.0 + rx + randOff; + float y; + float x = modf(addr / 1024.0, y) * 1024.0; + return ivec2(x, y); +} + +SBINDING(0) in VertToFrag vtf; +layout(location=0) out vec4 colorOut; +TBINDING0 uniform sampler2D tex; +void main() +{ + colorOut = texelFetch(tex, Lookup8BPP(vtf.uv, vtf.randOff), 0) * vtf.color; + if (colorOut.a < vtf.discardThres) + discard; +} + +#fragment hlsl +struct VertToFrag +{ + float4 pos : SV_Position; + float4 color : COLOR; + float2 uv : UV; + float randOff : RANDOFF; + float discardThres : DISCARDTHRES; +}; + +static int3 Lookup8BPP(float2 uv, float randOff) +{ + float bx; + float rx = modf(uv.x / 8.0, bx) * 8.0; + float by; + float ry = modf(uv.y / 4.0, by) * 4.0; + float bidx = by * 80.0 + bx; + float addr = bidx * 32.0 + ry * 8.0 + rx + randOff; + float y; + float x = modf(addr / 1024.0, y) * 1024.0; + return int3(x, y, 0); +} + +Texture2D tex : register(t0); +float4 main(in VertToFrag vtf) : SV_Target0 +{ + float4 colorOut = tex.Load(Lookup8BPP(vtf.uv, vtf.randOff)) * vtf.color; + if (colorOut.a < vtf.discardThres) + discard; + return colorOut; +} + +#fragment metal +struct VertToFrag +{ + float4 pos [[ position ]]; + float4 color; + float2 uv; + float randOff; + float discardThres; +}; + +static uint2 Lookup8BPP(float2 uv, float randOff) +{ + float bx; + float rx = modf(uv.x / 8.0, bx) * 8.0; + float by; + float ry = modf(uv.y / 4.0, by) * 4.0; + float bidx = by * 80.0 + bx; + float addr = bidx * 32.0 + ry * 8.0 + rx + randOff; + float y; + float x = modf(addr / 1024.0, y) * 1024.0; + return uint2(x, y); +} + +fragment float4 fmain(VertToFrag vtf [[ stage_in ]], + texture2d tex [[ texture(0) ]]) +{ + float4 colorOut = tex.read(Lookup8BPP(vtf.uv, vtf.randOff)) * vtf.color; + if (colorOut.a < vtf.discardThres) + discard_fragment(); + return colorOut; +} diff --git a/Shaders/CScanLinesFilter.shader b/Shaders/CScanLinesFilter.shader new file mode 100644 index 000000000..ef1879592 --- /dev/null +++ b/Shaders/CScanLinesFilter.shader @@ -0,0 +1,123 @@ +#shader CScanLinesFilterAlpha +#attribute position4 +#srcfac srcalpha +#dstfac invsrcalpha +#primitive tristrips +#depthtest none +#depthwrite false +#culling none + +#vertex glsl +layout(location=0) in vec4 posIn; + +UBINDING0 uniform ScanLinesUniform +{ + vec4 color; +}; + +struct VertToFrag +{ + vec4 color; +}; + +SBINDING(0) out VertToFrag vtf; +void main() +{ + vtf.color = color; + gl_Position = vec4(posIn.xyz, 1.0); +} + +#fragment glsl +struct VertToFrag +{ + vec4 color; +}; + +SBINDING(0) in VertToFrag vtf; +layout(location=0) out vec4 colorOut; +void main() +{ + colorOut = vtf.color; +} + +#vertex hlsl +struct VertData +{ + float4 posIn : POSITION; +}; + +cbuffer ScanLinesUniform : register(b0) +{ + float4 color; +}; + +struct VertToFrag +{ + float4 position : SV_Position; + float4 color : COLOR; +}; + +VertToFrag main(in VertData v) +{ + VertToFrag vtf; + vtf.color = color; + vtf.position = float4(v.posIn.xyz, 1.0); + return vtf; +} + +#fragment hlsl +struct VertToFrag +{ + float4 position : SV_Position; + float4 color : COLOR; +}; + +float4 main(in VertToFrag vtf) : SV_Target0 +{ + return vtf.color; +} + +#vertex metal +struct VertData +{ + float4 posIn [[ attribute(0) ]]; +}; + +struct ScanLinesUniform +{ + float4 color; +}; + +struct VertToFrag +{ + float4 position [[ position ]]; + float4 color; +}; + +vertex VertToFrag vmain(VertData v [[ stage_in ]], constant ScanLinesUniform& cqu [[ buffer(2) ]]) +{ + VertToFrag vtf; + vtf.color = cqu.color; + vtf.position = float4(v.posIn.xyz, 1.0); + return vtf; +} + +#fragment metal +struct VertToFrag +{ + float4 position [[ position ]]; + float4 color; +}; + +fragment float4 fmain(VertToFrag vtf [[ stage_in ]]) +{ + return vtf.color; +} + +#shader CScanLinesFilterAdd : CScanLinesFilterAlpha +#srcfac srcalpha +#dstfac one + +#shader CScanLinesFilterMult : CScanLinesFilterAlpha +#srcfac zero +#dstfac srccolor diff --git a/Shaders/CSpaceWarpFilter.shader b/Shaders/CSpaceWarpFilter.shader new file mode 100644 index 000000000..1cbc9bd60 --- /dev/null +++ b/Shaders/CSpaceWarpFilter.shader @@ -0,0 +1,156 @@ +#shader CSpaceWarpFilter +#attribute position4 +#attribute uv4 +#srcfac one +#dstfac zero +#primitive tristrips +#depthtest none +#depthwrite false +#culling none + +#vertex glsl +layout(location=0) in vec4 posIn; +layout(location=1) in vec4 uvIn; + +UBINDING0 uniform SpaceWarpUniform +{ + mat4 mainMtx; + mat4 indMtx; + vec4 strength; +}; + +struct VertToFrag +{ + vec2 sceneUv; + vec2 indUv; + vec2 strength; +}; + +SBINDING(0) out VertToFrag vtf; +void main() +{ + gl_Position = mainMtx * vec4(posIn.xy, 0.0, 1.0); + vtf.sceneUv = gl_Position.xy * vec2(0.5) + vec2(0.5); + vtf.indUv = (mat3(indMtx) * vec3(uvIn.xy, 1.0)).xy; + vtf.strength = strength.xy; +} + +#fragment glsl +struct VertToFrag +{ + vec2 sceneUv; + vec2 indUv; + vec2 strength; +}; + +SBINDING(0) in VertToFrag vtf; +layout(location=0) out vec4 colorOut; +TBINDING0 uniform sampler2D sceneTex; +TBINDING1 uniform sampler2D indTex; +void main() +{ + vec2 indUv = texture(indTex, vtf.indUv).xy * vec2(2.0) - vec2(1.0 - 1.0 / 256.0); + colorOut = vec4(texture(sceneTex, vtf.sceneUv + indUv * vtf.strength.xy).rgb, 1.0); +} + +#vertex hlsl +struct VertData +{ + float4 posIn : POSITION; + float4 uvIn : UV; +}; +cbuffer SpaceWarpUniform : register(b0) +{ + float4x4 mainMtx; + float4x4 indMtx; + float4 strength; +}; + +struct VertToFrag +{ + float4 position : SV_Position; + float2 sceneUv : SCENEUV; + float2 indUv : INDV; + float2 strength : STRENGTH; +}; + +VertToFrag main(in VertData v) +{ + VertToFrag vtf; + vtf.position = mul(mainMtx, float4(v.posIn.xy, 0.0, 1.0)); + vtf.sceneUv = vtf.position.xy * float2(0.5, 0.5) + float2(0.5, 0.5); + vtf.sceneUv.y = 1.0 - vtf.sceneUv.y; + vtf.indUv = mul(float3x3(indMtx[0].xyz, indMtx[1].xyz, indMtx[2].xyz), float3(v.uvIn.xy, 1.0)).xy; + vtf.indUv.y = 1.0 - vtf.indUv.y; + vtf.strength = strength.xy; + return vtf; +} + +#fragment hlsl +Texture2D sceneTex : register(t0); +Texture2D indTex : register(t1); +SamplerState samp : register(s0); +struct VertToFrag +{ + float4 position : SV_Position; + float2 sceneUv : SCENEUV; + float2 indUv : INDV; + float2 strength : STRENGTH; +}; + +float4 main(in VertToFrag vtf) : SV_Target0 +{ + float2 indUv = indTex.Sample(samp, vtf.indUv).xy * float2(2.0, 2.0) - float2(1.0 - 1.0 / 256.0, 1.0 - 1.0 / 256.0); + return float4(sceneTex.Sample(samp, vtf.sceneUv + indUv * vtf.strength.xy).rgb, 1.0); +} + +#vertex metal +struct VertData +{ + float4 posIn [[ attribute(0) ]]; + float4 uvIn [[ attribute(1) ]]; +}; +struct SpaceWarpUniform +{ + float4x4 mainMtx; + float4x4 indMtx; + float4 strength; +}; + +struct VertToFrag +{ + float4 position [[ position ]]; + float2 sceneUv; + float2 indUv; + float2 strength; +}; + +vertex VertToFrag vmain(VertData v [[ stage_in ]], constant SpaceWarpUniform& swu [[ buffer(2) ]]) +{ + VertToFrag vtf; + vtf.position = swu.mainMtx * float4(v.posIn.xy, 0.0, 1.0); + vtf.sceneUv = vtf.position.xy * float2(0.5) + float2(0.5); + vtf.sceneUv.y = 1.0 - vtf.sceneUv.y; + vtf.indUv = (float3x3(swu.indMtx[0].xyz, swu.indMtx[1].xyz, swu.indMtx[2].xyz) * float3(v.uvIn.xy, 1.0)).xy; + vtf.indUv.y = 1.0 - vtf.indUv.y; + vtf.strength = swu.strength.xy; + return vtf; +} + +#fragment metal +struct VertToFrag +{ + float4 position [[ position ]]; + float2 sceneUv; + float2 indUv; + float2 strength; +}; + +fragment float4 fmain(VertToFrag vtf [[ stage_in ]], + sampler samp [[ sampler(0) ]], + texture2d sceneTex [[ texture(0) ]], + texture2d indTex [[ texture(1) ]]) +{ + float2 indUv = indTex.sample(samp, vtf.indUv).xy * float2(2.0) - float2(1.0 - 1.0 / 256.0); + return float4(sceneTex.sample(samp, vtf.sceneUv + indUv * vtf.strength.xy).rgb, 1.0); +} diff --git a/Shaders/CTextSupportShader.shader b/Shaders/CTextSupportShader.shader new file mode 100644 index 000000000..b96a52fde --- /dev/null +++ b/Shaders/CTextSupportShader.shader @@ -0,0 +1,351 @@ +#shader CTextSupportShaderAlpha +#instattribute position4 0 +#instattribute position4 1 +#instattribute position4 2 +#instattribute position4 3 +#instattribute uv4 0 +#instattribute uv4 1 +#instattribute uv4 2 +#instattribute uv4 3 +#instattribute color 0 +#instattribute color 1 +#instattribute color 2 +#srcfac srcalpha +#dstfac invsrcalpha +#primitive tristrips +#depthtest lequal +#depthwrite false +#culling none + +#vertex glsl +layout(location=0) in vec4 posIn[4]; +layout(location=4) in vec4 uvIn[4]; +layout(location=8) in vec4 fontColorIn; +layout(location=9) in vec4 outlineColorIn; +layout(location=10) in vec4 mulColorIn; + +UBINDING0 uniform TextSupportUniform +{ + mat4 mtx; + vec4 color; +}; + +struct VertToFrag +{ + vec4 fontColor; + vec4 outlineColor; + vec4 mulColor; + vec3 uv; +}; + +SBINDING(0) out VertToFrag vtf; +void main() +{ + vec3 pos = posIn[gl_VertexID].xyz; + vtf.uv = uvIn[gl_VertexID].xyz; + vtf.fontColor = color * fontColorIn; + vtf.outlineColor = color * outlineColorIn; + vtf.mulColor = mulColorIn; + gl_Position = mtx * vec4(pos, 1.0); +} + +#fragment glsl +struct VertToFrag +{ + vec4 fontColor; + vec4 outlineColor; + vec4 mulColor; + vec3 uv; +}; + +SBINDING(0) in VertToFrag vtf; +layout(location=0) out vec4 colorOut; +TBINDING0 uniform sampler2DArray tex; +void main() +{ + vec4 texel = texture(tex, vtf.uv); + colorOut = (vtf.fontColor * texel.r + vtf.outlineColor * texel.g) * vtf.mulColor; +} + +#vertex hlsl +struct InstData +{ + float4 posIn[4] : POSITION; + float4 uvIn[4] : UV; + float4 fontColorIn : COLOR0; + float4 outlineColorIn : COLOR1; + float4 mulColorIn : COLOR2; +}; + +cbuffer TextSupportUniform : register(b0) +{ + float4x4 mtx; + float4 color; +}; + +struct VertToFrag +{ + float4 pos : SV_Position; + float4 fontColor : COLOR0; + float4 outlineColor : COLOR1; + float4 mulColor : COLOR2; + float3 uv : UV; +}; + +VertToFrag main(in InstData inst, in uint vertId : SV_VertexID) +{ + VertToFrag vtf; + vtf.fontColor = color * inst.fontColorIn; + vtf.outlineColor = color * inst.outlineColorIn; + vtf.mulColor = inst.mulColorIn; + vtf.uv = inst.uvIn[vertId].xyz; + vtf.pos = mul(mtx, float4(inst.posIn[vertId].xyz, 1.0)); + return vtf; +} + +#fragment hlsl +struct VertToFrag +{ + float4 pos : SV_Position; + float4 fontColor : COLOR0; + float4 outlineColor : COLOR1; + float4 mulColor : COLOR2; + float3 uv : UV; +}; + +Texture2DArray tex : register(t0); +SamplerState samp : register(s3); + +float4 main(in VertToFrag vtf) : SV_Target0 +{ + float4 texel = tex.Sample(samp, vtf.uv.xyz); + return (vtf.fontColor * texel.r + vtf.outlineColor * texel.g) * vtf.mulColor; +} + +#vertex metal +struct InstData +{ + float4 posIn[4]; + float4 uvIn[4]; + float4 fontColorIn; + float4 outlineColorIn; + float4 mulColorIn; +}; + +struct TextSupportUniform +{ + float4x4 mtx; + float4 color; +}; + +struct VertToFrag +{ + float4 pos [[ position ]]; + float4 fontColor; + float4 outlineColor; + float4 mulColor; + float3 uv; +}; + +vertex VertToFrag vmain(constant InstData* instArr [[ buffer(1) ]], + uint vertId [[ vertex_id ]], uint instId [[ instance_id ]], + constant TextSupportUniform& uData [[ buffer(2) ]]) +{ + VertToFrag vtf; + constant InstData& inst = instArr[instId]; + vtf.fontColor = inst.fontColorIn * uData.color; + vtf.outlineColor = inst.outlineColorIn * uData.color; + vtf.mulColor = inst.mulColorIn; + vtf.uv = inst.uvIn[vertId].xyz; + vtf.pos = uData.mtx * float4(inst.posIn[vertId].xyz, 1.0); + return vtf; +} + +#fragment metal +struct VertToFrag +{ + float4 pos [[ position ]]; + float4 fontColor; + float4 outlineColor; + float4 mulColor; + float3 uv; +}; + +fragment float4 fmain(VertToFrag vtf [[ stage_in ]], + sampler clampSamp [[ sampler(3) ]], + texture2d_array tex [[ texture(0) ]]) +{ + float4 texel = tex.sample(clampSamp, vtf.uv.xy, vtf.uv.z); + return (vtf.fontColor * texel.r + vtf.outlineColor * texel.g) * vtf.mulColor; +} + +#shader CTextSupportShaderAdd : CTextSupportShaderAlpha +#srcfac srcalpha +#dstfac one + +#shader CTextSupportShaderAddOverdraw : CTextSupportShaderAlpha +#srcfac one +#dstfac one + +#shader CTextSupportShaderImageAlpha +#instattribute position4 0 +#instattribute position4 1 +#instattribute position4 2 +#instattribute position4 3 +#instattribute uv4 0 +#instattribute uv4 1 +#instattribute uv4 2 +#instattribute uv4 3 +#instattribute color 0 +#srcfac srcalpha +#dstfac invsrcalpha +#primitive tristrips +#depthtest lequal +#depthwrite false +#culling none + +#vertex glsl +layout(location=0) in vec3 posIn[4]; +layout(location=4) in vec2 uvIn[4]; +layout(location=8) in vec4 colorIn; + +UBINDING0 uniform TextSupportUniform +{ + mat4 mtx; + vec4 color; +}; + +struct VertToFrag +{ + vec4 color; + vec2 uv; +}; + +SBINDING(0) out VertToFrag vtf; +void main() +{ + vec3 pos = posIn[gl_VertexID].xyz; + vtf.uv = uvIn[gl_VertexID]; + vtf.color = color * colorIn; + gl_Position = mtx * vec4(pos, 1.0); +} + +#fragment glsl +struct VertToFrag +{ + vec4 color; + vec2 uv; +}; + +SBINDING(0) in VertToFrag vtf; +layout(location=0) out vec4 colorOut; +TBINDING0 uniform sampler2D tex; +void main() +{ + vec4 texel = texture(tex, vtf.uv); + colorOut = vtf.color * texel; +} + +#vertex hlsl +struct InstData +{ + float4 posIn[4] : POSITION; + float4 uvIn[4] : UV; + float4 colorIn : COLOR; +}; + +cbuffer TextSupportUniform : register(b0) +{ + float4x4 mtx; + float4 color; +}; + +struct VertToFrag +{ + float4 pos : SV_Position; + float4 color : COLOR; + float2 uv : UV; +}; + +VertToFrag main(in InstData inst, in uint vertId : SV_VertexID) +{ + VertToFrag vtf; + vtf.color = color * inst.colorIn; + vtf.uv = inst.uvIn[vertId].xy; + vtf.pos = mul(mtx, float4(inst.posIn[vertId].xyz, 1.0)); + return vtf; +} + +#fragment hlsl +struct VertToFrag +{ + float4 pos : SV_Position; + float4 color : COLOR; + float2 uv : UV; +}; + +Texture2D tex : register(t0); +SamplerState samp : register(s3); + +float4 main(in VertToFrag vtf) : SV_Target0 +{ + float4 texel = tex.Sample(samp, vtf.uv); + return vtf.color * texel; +} + +#vertex metal +struct InstData +{ + float4 posIn[4]; + float4 uvIn[4]; + float4 colorIn; +}; + +struct TextSupportUniform +{ + float4x4 mtx; + float4 color; +}; + +struct VertToFrag +{ + float4 pos [[ position ]]; + float4 color; + float2 uv; +}; + +vertex VertToFrag vmain(constant InstData* instArr [[ buffer(1) ]], + uint vertId [[ vertex_id ]], uint instId [[ instance_id ]], + constant TextSupportUniform& uData [[ buffer(2) ]]) +{ + VertToFrag vtf; + constant InstData& inst = instArr[instId]; + vtf.color = uData.color * inst.colorIn; + vtf.uv = inst.uvIn[vertId].xy; + vtf.pos = uData.mtx * float4(inst.posIn[vertId].xyz, 1.0); + return vtf; +} + +#fragment metal +struct VertToFrag +{ + float4 pos [[ position ]]; + float4 color; + float2 uv; +}; + +fragment float4 fmain(VertToFrag vtf [[ stage_in ]], + sampler clampSamp [[ sampler(3) ]], + texture2d tex [[ texture(0) ]]) +{ + float4 texel = tex.sample(clampSamp, vtf.uv); + return vtf.color * texel; +} + +#shader CTextSupportShaderImageAdd : CTextSupportShaderImageAlpha +#srcfac srcalpha +#dstfac one + +#shader CTextSupportShaderImageAddOverdraw : CTextSupportShaderImageAlpha +#srcfac one +#dstfac one diff --git a/Shaders/CTexturedQuadFilter.shader b/Shaders/CTexturedQuadFilter.shader new file mode 100644 index 000000000..72f4f6566 --- /dev/null +++ b/Shaders/CTexturedQuadFilter.shader @@ -0,0 +1,273 @@ +#shader CTexturedQuadFilterAlpha +#attribute position4 +#attribute uv4 +#srcfac srcalpha +#dstfac invsrcalpha +#primitive tristrips +#depthtest none +#depthwrite false +#culling none + +#vertex glsl +layout(location=0) in vec4 posIn; +layout(location=1) in vec4 uvIn; + +UBINDING0 uniform TexuredQuadUniform +{ + mat4 mtx; + vec4 color; + float lod; +}; + +struct VertToFrag +{ + vec4 color; + vec2 uv; + float lod; +}; + +SBINDING(0) out VertToFrag vtf; +void main() +{ + vtf.color = color; + vtf.uv = uvIn.xy; + vtf.lod = lod; + gl_Position = mtx * vec4(posIn.xyz, 1.0); + gl_Position = FLIPFROMGL(gl_Position); +} + +#fragment glsl +struct VertToFrag +{ + vec4 color; + vec2 uv; + float lod; +}; + +SBINDING(0) in VertToFrag vtf; +layout(location=0) out vec4 colorOut; +TBINDING0 uniform sampler2D tex; +void main() +{ + colorOut = vtf.color * vec4(texture(tex, vtf.uv, vtf.lod).rgb, 1.0); +} + +#vertex hlsl +struct VertData +{ + float4 posIn : POSITION; + float4 uvIn : UV; +}; + +cbuffer TexuredQuadUniform : register(b0) +{ + float4x4 mat; + float4 color; + float lod; +}; + +struct VertToFrag +{ + float4 position : SV_Position; + float4 color : COLOR; + float2 uv : UV; + float lod : LOD; +}; + +VertToFrag main(in VertData v) +{ + VertToFrag vtf; + vtf.color = color; + vtf.uv = v.uvIn.xy; + vtf.lod = lod; + vtf.position = mul(mat, float4(v.posIn.xyz, 1.0)); + return vtf; +} + +#fragment hlsl +struct VertToFrag +{ + float4 position : SV_Position; + float4 color : COLOR; + float2 uv : UV; + float lod : LOD; +}; + +Texture2D tex : register(t0); +SamplerState samp : register(s3); + +float4 main(in VertToFrag vtf) : SV_Target0 +{ + return vtf.color * float4(tex.SampleBias(samp, vtf.uv, vtf.lod).rgb, 1.0); +} + +#vertex metal +struct VertData +{ + float4 posIn [[ attribute(0) ]]; + float4 uvIn [[ attribute(1) ]]; +}; + +struct TexuredQuadUniform +{ + float4x4 mat; + float4 color; + float lod; +}; + +struct VertToFrag +{ + float4 position [[ position ]]; + float4 color; + float2 uv; + float lod; +}; + +vertex VertToFrag vmain(VertData v [[ stage_in ]], constant TexuredQuadUniform& tqu [[ buffer(2) ]]) +{ + VertToFrag vtf; + vtf.color = tqu.color; + vtf.uv = v.uvIn.xy; + vtf.lod = tqu.lod; + vtf.position = tqu.mat * float4(v.posIn.xyz, 1.0); + return vtf; +} + +#fragment metal +struct VertToFrag +{ + float4 position [[ position ]]; + float4 color; + float2 uv; + float lod; +}; + +fragment float4 fmain(VertToFrag vtf [[ stage_in ]], + sampler clampSamp [[ sampler(3) ]], + texture2d tex [[ texture(0) ]]) +{ + return vtf.color * float4(tex.sample(clampSamp, vtf.uv, bias(vtf.lod)).rgb, 1.0); +} + +#shader CTexturedQuadFilterAlphaGEqual : CTexturedQuadFilterAlpha +#depthtest gequal + +#shader CTexturedQuadFilterAlphaLEqual : CTexturedQuadFilterAlpha +#depthtest lequal + +#shader CTexturedQuadFilterAdd : CTexturedQuadFilterAlpha +#srcfac srcalpha +#dstfac one +#depthtest none + +#shader CTexturedQuadFilterAddGEqual : CTexturedQuadFilterAdd +#depthtest gequal + +#shader CTexturedQuadFilterAddLEqual : CTexturedQuadFilterAdd +#depthtest lequal + +#shader CTexturedQuadFilterSubtract : CTexturedQuadFilterAlpha +#srcfac srcalpha +#dstfac subtract +#depthtest none + +#shader CTexturedQuadFilterSubtractGEqual : CTexturedQuadFilterSubtract +#depthtest gequal + +#shader CTexturedQuadFilterSubtractLEqual : CTexturedQuadFilterSubtract +#depthtest lequal + +#shader CTexturedQuadFilterMult : CTexturedQuadFilterAlpha +#srcfac zero +#dstfac srccolor +#depthtest none + +#shader CTexturedQuadFilterMultGEqual : CTexturedQuadFilterMult +#depthtest gequal + +#shader CTexturedQuadFilterMultLEqual : CTexturedQuadFilterMult +#depthtest lequal + +#shader CTexturedQuadFilterInvDstMult : CTexturedQuadFilterAlpha +#srcfac zero +#dstfac invsrccolor +#depthtest none + +#shader CTexturedQuadFilterInvDstMultGEqual : CTexturedQuadFilterInvDstMult +#depthtest gequal + +#shader CTexturedQuadFilterInvDstMultLEqual : CTexturedQuadFilterInvDstMult +#depthtest lequal + +#shader CTexturedQuadFilterAlphaTexAlpha : CTexturedQuadFilterAlpha +#attribute position4 +#attribute uv4 +#srcfac srcalpha +#dstfac invsrcalpha +#depthtest none + +#fragment glsl +struct VertToFrag +{ + vec4 color; + vec2 uv; + float lod; +}; + +SBINDING(0) in VertToFrag vtf; +layout(location=0) out vec4 colorOut; +TBINDING0 uniform sampler2D tex; +void main() +{ + colorOut = vtf.color * texture(tex, vtf.uv, vtf.lod); +} + +#fragment hlsl +struct VertToFrag +{ + float4 position : SV_Position; + float4 color : COLOR; + float2 uv : UV; + float lod : LOD; +}; + +Texture2D tex : register(t0); +SamplerState samp : register(s3); + +float4 main(in VertToFrag vtf) : SV_Target0 +{ + return vtf.color * tex.SampleBias(samp, vtf.uv, vtf.lod); +} + +#fragment metal +struct VertToFrag +{ + float4 position [[ position ]]; + float4 color; + float2 uv; + float lod; +}; + +fragment float4 fmain(VertToFrag vtf [[ stage_in ]], + sampler clampSamp [[ sampler(3) ]], + texture2d tex [[ texture(0) ]]) +{ + return vtf.color * tex.sample(clampSamp, vtf.uv, bias(vtf.lod)); +} + +#shader CTexturedQuadFilterAlphaTexAdd : CTexturedQuadFilterAlphaTexAlpha +#srcfac srcalpha +#dstfac one + +#shader CTexturedQuadFilterAlphaTexSubtract : CTexturedQuadFilterAlphaTexAlpha +#srcfac srcalpha +#dstfac subtract + +#shader CTexturedQuadFilterAlphaTexMult : CTexturedQuadFilterAlphaTexAlpha +#srcfac zero +#dstfac srccolor + +#shader CTexturedQuadFilterAlphaTexInvDstMult : CTexturedQuadFilterAlphaTexAlpha +#srcfac zero +#dstfac invsrccolor + diff --git a/Shaders/CThermalColdFilter.shader b/Shaders/CThermalColdFilter.shader new file mode 100644 index 000000000..df4d6adfe --- /dev/null +++ b/Shaders/CThermalColdFilter.shader @@ -0,0 +1,225 @@ +#shader CThermalColdFilter +#attribute position4 +#attribute uv4 +#srcfac one +#dstfac zero +#primitive tristrips +#depthtest none +#depthwrite false +#culling none + +#vertex glsl +layout(location=0) in vec4 posIn; +layout(location=1) in vec4 uvIn; + +UBINDING0 uniform ThermalColdUniform +{ + mat4 shiftMtx; + mat4 indMtx; + vec4 shiftScale; + vec4 colorReg0; + vec4 colorReg1; + vec4 colorReg2; +}; + +struct VertToFrag +{ + mat3 indMtx; + vec4 colorReg0; + vec4 colorReg1; + vec4 colorReg2; + vec2 sceneUv; + vec2 shiftUv; + vec2 shiftScale; +}; + +SBINDING(0) out VertToFrag vtf; +void main() +{ + vtf.indMtx = mat3(indMtx); + vtf.colorReg0 = colorReg0; + vtf.colorReg1 = colorReg1; + vtf.colorReg2 = colorReg2; + vtf.sceneUv = uvIn.xy; + vtf.shiftUv = (mat3(shiftMtx) * uvIn.xyz).xy; + vtf.shiftScale = shiftScale.xy; + gl_Position = vec4(posIn.xyz, 1.0); +} + +#fragment glsl +struct VertToFrag +{ + mat3 indMtx; + vec4 colorReg0; + vec4 colorReg1; + vec4 colorReg2; + vec2 sceneUv; + vec2 shiftUv; + vec2 shiftScale; +}; + +SBINDING(0) in VertToFrag vtf; +layout(location=0) out vec4 colorOut; +TBINDING0 uniform sampler2D sceneTex; +TBINDING1 uniform sampler2D shiftTex; +const vec4 kRGBToYPrime = vec4(0.299, 0.587, 0.114, 0.0); +void main() +{ + vec2 shiftCoordTexel = texture(shiftTex, vtf.shiftUv).xy; + vec2 shiftCoord = vtf.sceneUv + shiftCoordTexel * vtf.shiftScale; + float shiftScene0 = dot(texture(sceneTex, shiftCoord), kRGBToYPrime); + float shiftScene1 = dot(texture(sceneTex, shiftCoord + vec2(vtf.shiftScale.x / 8.0, 0.0)), kRGBToYPrime); + vec2 indCoord = (vtf.indMtx * vec3(shiftScene0 - 0.5, shiftScene1 - 0.5, 1.0)).xy; + float indScene = dot(texture(sceneTex, vtf.sceneUv + indCoord), kRGBToYPrime); + colorOut = vtf.colorReg0 * indScene + vtf.colorReg1 * shiftScene0 + vtf.colorReg2; +} + +#vertex hlsl +struct VertData +{ + float4 posIn : POSITION; + float4 uvIn : UV; +}; + +cbuffer ThermalColdUniform : register(b0) +{ + float4x4 shiftMtx; + float4x4 indMtx; + float4 shiftScale; + float4 colorReg0; + float4 colorReg1; + float4 colorReg2; +}; + +struct VertToFrag +{ + float4 position : SV_Position; + float3x3 indMtx : INDMTX; + float4 colorReg0 : COLORREG0; + float4 colorReg1 : COLORREG1; + float4 colorReg2 : COLORREG2; + float2 sceneUv : SCENEUV; + float2 shiftUv : SHIFTUV; + float2 shiftScale : SHIFTSCALE; +}; + +VertToFrag main(in VertData v) +{ + VertToFrag vtf; + vtf.indMtx = float3x3(indMtx[0].xyz, indMtx[1].xyz, indMtx[2].xyz); + vtf.colorReg0 = colorReg0; + vtf.colorReg1 = colorReg1; + vtf.colorReg2 = colorReg2; + vtf.sceneUv = v.uvIn.xy; + vtf.sceneUv.y = 1.0 - vtf.sceneUv.y; + vtf.shiftUv = (mul(float3x3(shiftMtx[0].xyz, shiftMtx[1].xyz, shiftMtx[2].xyz), v.uvIn.xyz)).xy; + vtf.shiftScale = shiftScale.xy; + vtf.position = float4(v.posIn.xyz, 1.0); + return vtf; +} + +#fragment hlsl +Texture2D sceneTex : register(t0); +Texture2D shiftTex : register(t1); +SamplerState samp : register(s3); +struct VertToFrag +{ + float4 position : SV_Position; + float3x3 indMtx : INDMTX; + float4 colorReg0 : COLORREG0; + float4 colorReg1 : COLORREG1; + float4 colorReg2 : COLORREG2; + float2 sceneUv : SCENEUV; + float2 shiftUv : SHIFTUV; + float2 shiftScale : SHIFTSCALE; +}; + +static const float4 kRGBToYPrime = {0.299, 0.587, 0.114, 0.0}; +float4 main(in VertToFrag vtf) : SV_Target0 +{ + float2 shiftCoordTexel = shiftTex.Sample(samp, vtf.shiftUv).xy; + float2 shiftCoord = vtf.sceneUv + shiftCoordTexel * vtf.shiftScale; + float shiftScene0 = dot(sceneTex.Sample(samp, shiftCoord), kRGBToYPrime); + float shiftScene1 = dot(sceneTex.Sample(samp, shiftCoord + float2(vtf.shiftScale.x / 8.0, 0.0)), kRGBToYPrime); + float2 indCoord = (mul(vtf.indMtx, float3(shiftScene0 - 0.5, shiftScene1 - 0.5, 1.0))).xy; + float indScene = dot(sceneTex.Sample(samp, vtf.sceneUv + indCoord), kRGBToYPrime); + return vtf.colorReg0 * indScene + vtf.colorReg1 * shiftScene0 + vtf.colorReg2; +} + +#vertex metal +struct VertData +{ + float4 posIn [[ attribute(0) ]]; + float4 uvIn [[ attribute(1) ]]; +}; + +struct ThermalColdUniform +{ + float4x4 shiftMtx; + float4x4 indMtx; + float4 shiftScale; + float4 colorReg0; + float4 colorReg1; + float4 colorReg2; +}; + +struct VertToFrag +{ + float4 position [[ position ]]; + float3 indMtx0; + float3 indMtx1; + float3 indMtx2; + float4 colorReg0; + float4 colorReg1; + float4 colorReg2; + float2 sceneUv; + float2 shiftUv; + float2 shiftScale; +}; + +vertex VertToFrag vmain(VertData v [[ stage_in ]], constant ThermalColdUniform& tcu [[ buffer(2) ]]) +{ + VertToFrag vtf; + vtf.indMtx0 = tcu.indMtx[0].xyz; + vtf.indMtx1 = tcu.indMtx[1].xyz; + vtf.indMtx2 = tcu.indMtx[2].xyz; + vtf.colorReg0 = tcu.colorReg0; + vtf.colorReg1 = tcu.colorReg1; + vtf.colorReg2 = tcu.colorReg2; + vtf.sceneUv = v.uvIn.xy; + vtf.sceneUv.y = 1.0 - vtf.sceneUv.y; + vtf.shiftUv = (float3x3(tcu.shiftMtx[0].xyz, tcu.shiftMtx[1].xyz, tcu.shiftMtx[2].xyz) * v.uvIn.xyz).xy; + vtf.shiftScale = tcu.shiftScale.xy; + vtf.position = float4(v.posIn.xyz, 1.0); + return vtf; +} + +#fragment metal +struct VertToFrag +{ + float4 position [[ position ]]; + float3 indMtx0; + float3 indMtx1; + float3 indMtx2; + float4 colorReg0; + float4 colorReg1; + float4 colorReg2; + float2 sceneUv; + float2 shiftUv; + float2 shiftScale; +}; + +constant float4 kRGBToYPrime = {0.299, 0.587, 0.114, 0.0}; +fragment float4 fmain(VertToFrag vtf [[ stage_in ]], + sampler samp [[ sampler(3) ]], + texture2d sceneTex [[ texture(0) ]], + texture2d shiftTex [[ texture(1) ]]) +{ + float2 shiftCoordTexel = shiftTex.sample(samp, vtf.shiftUv).xy; + float2 shiftCoord = vtf.sceneUv + shiftCoordTexel * vtf.shiftScale; + float shiftScene0 = dot(sceneTex.sample(samp, shiftCoord), kRGBToYPrime); + float shiftScene1 = dot(sceneTex.sample(samp, shiftCoord + float2(vtf.shiftScale.x / 8.0, 0.0)), kRGBToYPrime); + float2 indCoord = (float3x3(vtf.indMtx0, vtf.indMtx1, vtf.indMtx2) * float3(shiftScene0 - 0.5, shiftScene1 - 0.5, 1.0)).xy; + float indScene = dot(sceneTex.sample(samp, vtf.sceneUv + indCoord), kRGBToYPrime); + return vtf.colorReg0 * indScene + vtf.colorReg1 * shiftScene0 + vtf.colorReg2; +} diff --git a/Shaders/CThermalHotFilter.shader b/Shaders/CThermalHotFilter.shader new file mode 100644 index 000000000..34d170a4c --- /dev/null +++ b/Shaders/CThermalHotFilter.shader @@ -0,0 +1,144 @@ +#shader CThermalHotFilter +#attribute position4 +#attribute uv4 +#srcfac dstalpha +#dstfac invdstalpha +#primitive tristrips +#depthtest none +#depthwrite false +#culling none + +#vertex glsl +layout(location=0) in vec4 posIn; +layout(location=1) in vec4 uvIn; + +UBINDING0 uniform ThermalHotUniform +{ + vec4 colorReg0; + vec4 colorReg1; + vec4 colorReg2; +}; + +struct VertToFrag +{ + vec2 sceneUv; +}; + +SBINDING(0) out VertToFrag vtf; +void main() +{ + vtf.sceneUv = uvIn.xy; + gl_Position = vec4(posIn.xyz, 1.0); +} + +#fragment glsl +struct VertToFrag +{ + vec2 sceneUv; +}; + +SBINDING(0) in VertToFrag vtf; +layout(location=0) out vec4 colorOut; +TBINDING0 uniform sampler2D sceneTex; +TBINDING1 uniform sampler2D paletteTex; +const vec4 kRGBToYPrime = vec4(0.299, 0.587, 0.114, 0.0); +void main() +{ + float sceneSample = dot(texture(sceneTex, vtf.sceneUv), kRGBToYPrime); + vec4 colorSample = texture(paletteTex, vec2(sceneSample / 17.0, 0.5)); + colorOut = vec4((colorSample * sceneSample).rgb, 0.0); +} + +#vertex hlsl +struct VertData +{ + float4 posIn : POSITION; + float4 uvIn : UV; +}; + +cbuffer ThermalHotUniform : register(b0) +{ + float4 colorReg0; + float4 colorReg1; + float4 colorReg2; +}; + +struct VertToFrag +{ + float4 position : SV_Position; + float2 sceneUv : UV; +}; + +VertToFrag main(in VertData v) +{ + VertToFrag vtf; + vtf.sceneUv = v.uvIn.xy; + vtf.sceneUv.y = 1.0 - vtf.sceneUv.y; + vtf.position = float4(v.posIn.xyz, 1.0); + return vtf; +} + +#fragment hlsl +Texture2D sceneTex : register(t0); +Texture2D paletteTex : register(t1); +SamplerState samp : register(s0); +struct VertToFrag +{ + float4 position : SV_Position; + float2 sceneUv : UV; +}; + +static const float4 kRGBToYPrime = float4(0.299, 0.587, 0.114, 0.0); +float4 main(in VertToFrag vtf) : SV_Target0 +{ + float sceneSample = dot(sceneTex.Sample(samp, vtf.sceneUv), kRGBToYPrime); + float4 colorSample = paletteTex.Sample(samp, float2(sceneSample / 17.0, 0.5)); + return float4((colorSample * sceneSample).rgb, 0.0); +} + +#vertex metal +struct VertData +{ + float4 posIn [[ attribute(0) ]]; + float4 uvIn [[ attribute(1) ]]; +}; + +struct ThermalHotUniform +{ + float4 colorReg0; + float4 colorReg1; + float4 colorReg2; +}; + +struct VertToFrag +{ + float4 position [[ position ]]; + float2 sceneUv; +}; + +vertex VertToFrag vmain(VertData v [[ stage_in ]], constant ThermalHotUniform& thu [[ buffer(2) ]]) +{ + VertToFrag vtf; + vtf.sceneUv = v.uvIn.xy; + vtf.sceneUv.y = 1.0 - vtf.sceneUv.y; + vtf.position = float4(v.posIn.xyz, 1.0); + return vtf; +} + +#fragment metal +struct VertToFrag +{ + float4 position [[ position ]]; + float2 sceneUv; +}; + +constant float4 kRGBToYPrime = float4(0.299, 0.587, 0.114, 0.0); +fragment float4 fmain(VertToFrag vtf [[ stage_in ]], + sampler samp [[ sampler(0) ]], + texture2d sceneTex [[ texture(0) ]], + texture2d paletteTex [[ texture(1) ]]) +{ + float sceneSample = dot(sceneTex.sample(samp, vtf.sceneUv), kRGBToYPrime); + float4 colorSample = paletteTex.sample(samp, float2(sceneSample / 17.0, 0.5)); + return float4((colorSample * sceneSample).rgb, 0.0); +} diff --git a/Shaders/CWorldShadowShader.shader b/Shaders/CWorldShadowShader.shader new file mode 100644 index 000000000..6ac76c129 --- /dev/null +++ b/Shaders/CWorldShadowShader.shader @@ -0,0 +1,122 @@ +#shader CWorldShadowShader +#attribute position4 +#srcfac srcalpha +#dstfac invsrcalpha +#primitive tristrips +#depthtest none +#depthwrite false +#culling none + +#vertex glsl +layout(location=0) in vec4 posIn; + +UBINDING0 uniform ColoredQuadUniform +{ + mat4 xf; + vec4 color; +}; + +struct VertToFrag +{ + vec4 color; +}; + +SBINDING(0) out VertToFrag vtf; +void main() +{ + vtf.color = color; + gl_Position = xf * vec4(posIn.xyz, 1.0); +} + +#fragment glsl +struct VertToFrag +{ + vec4 color; +}; + +SBINDING(0) in VertToFrag vtf; +layout(location=0) out vec4 colorOut; +void main() +{ + colorOut = vtf.color; +} + +#vertex hlsl +struct VertData +{ + float4 posIn : POSITION; +}; + +cbuffer ColoredQuadUniform : register(b0) +{ + float4x4 xf; + float4 color; +}; + +struct VertToFrag +{ + float4 position : SV_Position; + float4 color : COLOR; +}; + +VertToFrag main(in VertData v) +{ + VertToFrag vtf; + vtf.color = color; + vtf.position = mul(xf, float4(v.posIn.xyz, 1.0)); + return vtf; +} + +#fragment hlsl +struct VertToFrag +{ + float4 position : SV_Position; + float4 color : COLOR; +}; + +float4 main(in VertToFrag vtf) : SV_Target0 +{ + return vtf.color; +} + +#vertex metal +struct VertData +{ + float4 posIn [[ attribute(0) ]]; +}; + +struct ColoredQuadUniform +{ + float4x4 xf; + float4 color; +}; + +struct VertToFrag +{ + float4 position [[ position ]]; + float4 color; +}; + +vertex VertToFrag vmain(VertData v [[ stage_in ]], constant ColoredQuadUniform& cqu [[ buffer(2) ]]) +{ + VertToFrag vtf; + vtf.color = cqu.color; + vtf.position = cqu.xf * float4(v.posIn.xyz, 1.0); + return vtf; +} + +#fragment metal +struct VertToFrag +{ + float4 position [[ position ]]; + float4 color; +}; + +fragment float4 fmain(VertToFrag vtf [[ stage_in ]]) +{ + return vtf.color; +} + +#shader CWorldShadowShaderZ : CWorldShadowShader +#depthtest lequal +#depthwrite true diff --git a/Shaders/CXRayBlurFilter.shader b/Shaders/CXRayBlurFilter.shader new file mode 100644 index 000000000..01e067eae --- /dev/null +++ b/Shaders/CXRayBlurFilter.shader @@ -0,0 +1,254 @@ +#shader CXRayBlurFilter +#attribute position4 +#attribute uv4 +#srcfac one +#dstfac zero +#primitive tristrips +#depthtest none +#depthwrite false +#culling none + +#vertex glsl +layout(location=0) in vec4 posIn; +layout(location=1) in vec4 uvIn; + +UBINDING0 uniform XRayBlurUniform +{ + mat4 uv0; + mat4 uv1; + mat4 uv2; + mat4 uv3; + mat4 uv4; + mat4 uv5; + mat4 uv6; + mat4 uv7; +}; + +struct VertToFrag +{ + vec2 uv0; + vec2 uv1; + vec2 uv2; + vec2 uv3; + vec2 uv4; + vec2 uv5; + vec2 uv6; + vec2 uv7; +}; + +SBINDING(0) out VertToFrag vtf; +void main() +{ + vtf.uv0 = (uv0 * vec4(uvIn.xy, 0.0, 1.0)).xy; + vtf.uv1 = (uv1 * vec4(uvIn.xy, 0.0, 1.0)).xy; + vtf.uv2 = (uv2 * vec4(uvIn.xy, 0.0, 1.0)).xy; + vtf.uv3 = (uv3 * vec4(uvIn.xy, 0.0, 1.0)).xy; + vtf.uv4 = (uv4 * vec4(uvIn.xy, 0.0, 1.0)).xy; + vtf.uv5 = (uv5 * vec4(uvIn.xy, 0.0, 1.0)).xy; + vtf.uv6 = (uv6 * vec4(uvIn.xy, 0.0, 1.0)).xy; + vtf.uv7 = (uv7 * vec4(uvIn.xy, 0.0, 1.0)).xy; + gl_Position = vec4(posIn.xyz, 1.0); +} + +#fragment glsl +struct VertToFrag +{ + vec2 uv0; + vec2 uv1; + vec2 uv2; + vec2 uv3; + vec2 uv4; + vec2 uv5; + vec2 uv6; + vec2 uv7; +}; + +SBINDING(0) in VertToFrag vtf; +layout(location=0) out vec4 colorOut; +TBINDING0 uniform sampler2D sceneTex; +TBINDING1 uniform sampler2D paletteTex; +const vec4 kRGBToYPrime = vec4(0.299, 0.587, 0.114, 0.0); +void main() +{ + vec4 colorSample = texture(paletteTex, vec2(dot(texture(sceneTex, vtf.uv0), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125; + colorSample += texture(paletteTex, vec2(dot(texture(sceneTex, vtf.uv1), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125; + colorSample += texture(paletteTex, vec2(dot(texture(sceneTex, vtf.uv2), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125; + colorSample += texture(paletteTex, vec2(dot(texture(sceneTex, vtf.uv3), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125; + colorSample += texture(paletteTex, vec2(dot(texture(sceneTex, vtf.uv4), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125; + colorSample += texture(paletteTex, vec2(dot(texture(sceneTex, vtf.uv5), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125; + colorSample += texture(paletteTex, vec2(dot(texture(sceneTex, vtf.uv6), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125; + colorSample += texture(paletteTex, vec2(dot(texture(sceneTex, vtf.uv7), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125; + colorOut = colorSample; +} + +#vertex hlsl +struct VertData +{ + float4 posIn : POSITION; + float4 uvIn : UV; +}; + +cbuffer XRayBlurUniform : register(b0) +{ + float4x4 uv0; + float4x4 uv1; + float4x4 uv2; + float4x4 uv3; + float4x4 uv4; + float4x4 uv5; + float4x4 uv6; + float4x4 uv7; +}; + +struct VertToFrag +{ + float4 position : SV_Position; + float2 uv0 : UV0; + float2 uv1 : UV1; + float2 uv2 : UV2; + float2 uv3 : UV3; + float2 uv4 : UV4; + float2 uv5 : UV5; + float2 uv6 : UV6; + float2 uv7 : UV7; +}; + +VertToFrag main(in VertData v) +{ + VertToFrag vtf; + vtf.uv0 = mul(uv0, float4(v.uvIn.xy, 0.0, 1.0)).xy; + vtf.uv0.y = 1.0 - vtf.uv0.y; + vtf.uv1 = mul(uv1, float4(v.uvIn.xy, 0.0, 1.0)).xy; + vtf.uv1.y = 1.0 - vtf.uv1.y; + vtf.uv2 = mul(uv2, float4(v.uvIn.xy, 0.0, 1.0)).xy; + vtf.uv2.y = 1.0 - vtf.uv2.y; + vtf.uv3 = mul(uv3, float4(v.uvIn.xy, 0.0, 1.0)).xy; + vtf.uv3.y = 1.0 - vtf.uv3.y; + vtf.uv4 = mul(uv4, float4(v.uvIn.xy, 0.0, 1.0)).xy; + vtf.uv4.y = 1.0 - vtf.uv4.y; + vtf.uv5 = mul(uv5, float4(v.uvIn.xy, 0.0, 1.0)).xy; + vtf.uv5.y = 1.0 - vtf.uv5.y; + vtf.uv6 = mul(uv6, float4(v.uvIn.xy, 0.0, 1.0)).xy; + vtf.uv6.y = 1.0 - vtf.uv6.y; + vtf.uv7 = mul(uv7, float4(v.uvIn.xy, 0.0, 1.0)).xy; + vtf.uv7.y = 1.0 - vtf.uv7.y; + vtf.position = float4(v.posIn.xyz, 1.0); + return vtf; +} + +#fragment hlsl +Texture2D sceneTex : register(t0); +Texture2D paletteTex : register(t1); +SamplerState samp : register(s3); +struct VertToFrag +{ + float4 position : SV_Position; + float2 uv0 : UV0; + float2 uv1 : UV1; + float2 uv2 : UV2; + float2 uv3 : UV3; + float2 uv4 : UV4; + float2 uv5 : UV5; + float2 uv6 : UV6; + float2 uv7 : UV7; +}; + +static const float4 kRGBToYPrime = float4(0.299, 0.587, 0.114, 0.0); +float4 main(in VertToFrag vtf) : SV_Target0 +{ + float4 colorSample = paletteTex.Sample(samp, float2(dot(sceneTex.Sample(samp, vtf.uv0), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125; + colorSample += paletteTex.Sample(samp, float2(dot(sceneTex.Sample(samp, vtf.uv1), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125; + colorSample += paletteTex.Sample(samp, float2(dot(sceneTex.Sample(samp, vtf.uv2), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125; + colorSample += paletteTex.Sample(samp, float2(dot(sceneTex.Sample(samp, vtf.uv3), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125; + colorSample += paletteTex.Sample(samp, float2(dot(sceneTex.Sample(samp, vtf.uv4), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125; + colorSample += paletteTex.Sample(samp, float2(dot(sceneTex.Sample(samp, vtf.uv5), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125; + colorSample += paletteTex.Sample(samp, float2(dot(sceneTex.Sample(samp, vtf.uv6), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125; + colorSample += paletteTex.Sample(samp, float2(dot(sceneTex.Sample(samp, vtf.uv7), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125; + return colorSample; +} + +#vertex metal +struct VertData +{ + float4 posIn [[ attribute(0) ]]; + float4 uvIn [[ attribute(1) ]]; +}; + +struct XRayBlurUniform +{ + float4x4 uv0; + float4x4 uv1; + float4x4 uv2; + float4x4 uv3; + float4x4 uv4; + float4x4 uv5; + float4x4 uv6; + float4x4 uv7; +}; + +struct VertToFrag +{ + float4 position [[ position ]]; + float2 uv0; + float2 uv1; + float2 uv2; + float2 uv3; + float2 uv4; + float2 uv5; + float2 uv6; + float2 uv7; +}; + +vertex VertToFrag vmain(VertData v [[ stage_in ]], constant XRayBlurUniform& xbu [[ buffer(2) ]]) +{ + VertToFrag vtf; + vtf.uv0 = (xbu.uv0 * float4(v.uvIn.xy, 0.0, 1.0)).xy; + vtf.uv0.y = 1.0 - vtf.uv0.y; + vtf.uv1 = (xbu.uv1 * float4(v.uvIn.xy, 0.0, 1.0)).xy; + vtf.uv1.y = 1.0 - vtf.uv1.y; + vtf.uv2 = (xbu.uv2 * float4(v.uvIn.xy, 0.0, 1.0)).xy; + vtf.uv2.y = 1.0 - vtf.uv2.y; + vtf.uv3 = (xbu.uv3 * float4(v.uvIn.xy, 0.0, 1.0)).xy; + vtf.uv3.y = 1.0 - vtf.uv3.y; + vtf.uv4 = (xbu.uv4 * float4(v.uvIn.xy, 0.0, 1.0)).xy; + vtf.uv4.y = 1.0 - vtf.uv4.y; + vtf.uv5 = (xbu.uv5 * float4(v.uvIn.xy, 0.0, 1.0)).xy; + vtf.uv5.y = 1.0 - vtf.uv5.y; + vtf.uv6 = (xbu.uv6 * float4(v.uvIn.xy, 0.0, 1.0)).xy; + vtf.uv6.y = 1.0 - vtf.uv6.y; + vtf.uv7 = (xbu.uv7 * float4(v.uvIn.xy, 0.0, 1.0)).xy; + vtf.uv7.y = 1.0 - vtf.uv7.y; + vtf.position = float4(v.posIn.xyz, 1.0); + return vtf; +} + +#fragment metal +struct VertToFrag +{ + float4 position [[ position ]]; + float2 uv0; + float2 uv1; + float2 uv2; + float2 uv3; + float2 uv4; + float2 uv5; + float2 uv6; + float2 uv7; +}; + +constant float4 kRGBToYPrime = float4(0.299, 0.587, 0.114, 0.0); +fragment float4 fmain(VertToFrag vtf [[ stage_in ]], + sampler samp [[ sampler(3) ]], + texture2d sceneTex [[ texture(0) ]], + texture2d paletteTex [[ texture(1) ]]) +{ + float4 colorSample = paletteTex.sample(samp, float2(dot(sceneTex.sample(samp, vtf.uv0), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125; + colorSample += paletteTex.sample(samp, float2(dot(sceneTex.sample(samp, vtf.uv1), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125; + colorSample += paletteTex.sample(samp, float2(dot(sceneTex.sample(samp, vtf.uv2), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125; + colorSample += paletteTex.sample(samp, float2(dot(sceneTex.sample(samp, vtf.uv3), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125; + colorSample += paletteTex.sample(samp, float2(dot(sceneTex.sample(samp, vtf.uv4), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125; + colorSample += paletteTex.sample(samp, float2(dot(sceneTex.sample(samp, vtf.uv5), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125; + colorSample += paletteTex.sample(samp, float2(dot(sceneTex.sample(samp, vtf.uv6), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125; + colorSample += paletteTex.sample(samp, float2(dot(sceneTex.sample(samp, vtf.uv7), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.125; + return colorSample; +} diff --git a/Shaders/shader_CFluidPlaneShader.cpp b/Shaders/shader_CFluidPlaneShader.cpp new file mode 100644 index 000000000..f2ca8187d --- /dev/null +++ b/Shaders/shader_CFluidPlaneShader.cpp @@ -0,0 +1,17 @@ +#include "shader_CFluidPlaneShader.hpp" + +const boo::VertexElementDescriptor Shader_CFluidPlaneShader::VtxFmtElems[5] = +{ + {boo::VertexSemantic::Position4}, + {boo::VertexSemantic::Normal4, 0}, + {boo::VertexSemantic::Normal4, 1}, + {boo::VertexSemantic::Normal4, 2}, + {boo::VertexSemantic::Color} +}; + +const boo::VertexElementDescriptor Shader_CFluidPlaneShader::TessVtxFmtElems[3] = +{ + {boo::VertexSemantic::Position4}, + {boo::VertexSemantic::UV4, 0}, + {boo::VertexSemantic::UV4, 1} +}; diff --git a/Shaders/shader_CFluidPlaneShader.hpp b/Shaders/shader_CFluidPlaneShader.hpp new file mode 100644 index 000000000..707a553a6 --- /dev/null +++ b/Shaders/shader_CFluidPlaneShader.hpp @@ -0,0 +1,131 @@ +#pragma once +#include "hecl/PipelineBase.hpp" +#include "athena/Global.hpp" +#include "hecl/hecl.hpp" + +#ifndef URDE_MAX_LIGHTS +#define URDE_MAX_LIGHTS 8 +#endif + +enum class EFluidType +{ + NormalWater, + PoisonWater, + Lava, + PhazonFluid, + Four, + ThickLava +}; + +struct SFluidPlaneShaderInfo +{ + EFluidType m_type; + bool m_hasPatternTex1; + bool m_hasPatternTex2; + bool m_hasColorTex; + bool m_hasBumpMap; + bool m_hasEnvMap; + bool m_hasEnvBumpMap; + bool m_hasLightmap; + bool m_tessellation; + bool m_doubleLightmapBlend; + bool m_additive; + + SFluidPlaneShaderInfo(EFluidType type, bool hasPatternTex1, bool hasPatternTex2, bool hasColorTex, + bool hasBumpMap, bool hasEnvMap, bool hasEnvBumpMap, bool hasLightmap, + bool tessellation, bool doubleLightmapBlend, bool additive) + : m_type(type), m_hasPatternTex1(hasPatternTex1), m_hasPatternTex2(hasPatternTex2), m_hasColorTex(hasColorTex), + m_hasBumpMap(hasBumpMap), m_hasEnvMap(hasEnvMap), m_hasEnvBumpMap(hasEnvBumpMap), m_hasLightmap(hasLightmap), + m_tessellation(tessellation), m_doubleLightmapBlend(doubleLightmapBlend), m_additive(additive) + {} +}; + +struct SFluidPlaneDoorShaderInfo +{ + bool m_hasPatternTex1; + bool m_hasPatternTex2; + bool m_hasColorTex; + + SFluidPlaneDoorShaderInfo(bool hasPatternTex1, bool hasPatternTex2, bool hasColorTex) + : m_hasPatternTex1(hasPatternTex1), m_hasPatternTex2(hasPatternTex2), m_hasColorTex(hasColorTex) + {} +}; + +class Shader_CFluidPlaneShader : public hecl::TessellationShader +{ + friend class Shader_CFluidPlaneDoorShader; + static const boo::VertexElementDescriptor VtxFmtElems[5]; + static const boo::VertexElementDescriptor TessVtxFmtElems[3]; + const SFluidPlaneShaderInfo& m_info; +public: + Shader_CFluidPlaneShader(const SFluidPlaneShaderInfo& in, bool tessellation) + : m_info(in), VtxFmt(tessellation ? TessVtxFmtElems : VtxFmtElems), + PipelineInfo({in.m_additive ? boo::BlendFactor::One : boo::BlendFactor::SrcAlpha, + in.m_additive ? boo::BlendFactor::One : boo::BlendFactor::InvSrcAlpha, + boo::Primitive::TriStrips, boo::ZTest::LEqual, false, true, false, + boo::CullMode::None, tessellation ? 1 : 0}), + HasTessellation(tessellation) {} + + const boo::VertexFormatInfo VtxFmt; + const boo::AdditionalPipelineInfo PipelineInfo; + bool HasTessellation; + static constexpr bool HasHash = false; + static constexpr uint64_t Hash() { return 0; } + const SFluidPlaneShaderInfo& info() const { return m_info; } +}; + +template +class StageObject_CFluidPlaneShader : public hecl::StageBinary +{ + static std::string BuildShader(const SFluidPlaneShaderInfo& in, bool tessellation); +public: + StageObject_CFluidPlaneShader(hecl::StageConverter& conv, hecl::FactoryCtx& ctx, + const Shader_CFluidPlaneShader& in) + : hecl::StageBinary(conv, ctx, hecl::StageSourceText(BuildShader(in.info(), in.HasTessellation))) {} +}; + +class Shader_CFluidPlaneDoorShader : public hecl::GeneralShader +{ + const SFluidPlaneDoorShaderInfo& m_info; +public: + explicit Shader_CFluidPlaneDoorShader(const SFluidPlaneDoorShaderInfo& in) + : m_info(in), VtxFmt(Shader_CFluidPlaneShader::VtxFmtElems), + PipelineInfo({boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, + boo::Primitive::TriStrips, boo::ZTest::LEqual, false, true, false, + boo::CullMode::None}) {} + + const boo::VertexFormatInfo VtxFmt; + const boo::AdditionalPipelineInfo PipelineInfo; + static constexpr bool HasHash = false; + static constexpr uint64_t Hash() { return 0; } + const SFluidPlaneDoorShaderInfo& info() const { return m_info; } +}; + +template +class StageObject_CFluidPlaneDoorShader : public hecl::StageBinary +{ + static std::string BuildShader(const SFluidPlaneDoorShaderInfo& in); +public: + StageObject_CFluidPlaneDoorShader(hecl::StageConverter& conv, hecl::FactoryCtx& ctx, + const Shader_CFluidPlaneDoorShader& in) + : hecl::StageBinary(conv, ctx, hecl::StageSourceText(BuildShader(in.info()))) {} +}; + +#define UNIVERSAL_PIPELINES_shader_CFluidPlaneShader \ +::Shader_CFluidPlaneShader \ +::Shader_CFluidPlaneDoorShader +#define OPENGL_STAGES_shader_CFluidPlaneShader \ +STAGE_SPECIALIZATIONS(::StageObject_CFluidPlaneShader, hecl::PlatformType::OpenGL) \ +STAGE_SPECIALIZATIONS(::StageObject_CFluidPlaneDoorShader, hecl::PlatformType::OpenGL) +#define VULKAN_STAGES_shader_CFluidPlaneShader \ +STAGE_SPECIALIZATIONS(::StageObject_CFluidPlaneShader, hecl::PlatformType::Vulkan) \ +STAGE_SPECIALIZATIONS(::StageObject_CFluidPlaneDoorShader, hecl::PlatformType::Vulkan) +#define D3D11_STAGES_shader_CFluidPlaneShader \ +STAGE_SPECIALIZATIONS(::StageObject_CFluidPlaneShader, hecl::PlatformType::D3D11) \ +STAGE_SPECIALIZATIONS(::StageObject_CFluidPlaneDoorShader, hecl::PlatformType::D3D11) +#define METAL_STAGES_shader_CFluidPlaneShader \ +STAGE_SPECIALIZATIONS(::StageObject_CFluidPlaneShader, hecl::PlatformType::Metal) \ +STAGE_SPECIALIZATIONS(::StageObject_CFluidPlaneDoorShader, hecl::PlatformType::Metal) +#define NX_STAGES_shader_CFluidPlaneShader \ +STAGE_SPECIALIZATIONS(::StageObject_CFluidPlaneShader, hecl::PlatformType::NX) \ +STAGE_SPECIALIZATIONS(::StageObject_CFluidPlaneDoorShader, hecl::PlatformType::NX) diff --git a/Shaders/shader_CFluidPlaneShaderGLSL.cpp b/Shaders/shader_CFluidPlaneShaderGLSL.cpp new file mode 100644 index 000000000..1628dac80 --- /dev/null +++ b/Shaders/shader_CFluidPlaneShaderGLSL.cpp @@ -0,0 +1,832 @@ +#include "shader_CFluidPlaneShader.hpp" + +static const char* VS = +"layout(location=0) in vec4 posIn;\n" +"layout(location=1) in vec4 normalIn;\n" +"layout(location=2) in vec4 binormalIn;\n" +"layout(location=3) in vec4 tangentIn;\n" +"layout(location=4) in vec4 colorIn;\n" +"\n" +"UBINDING0 uniform FluidPlaneUniform\n" +"{\n" +" mat4 mv;\n" +" mat4 mvNorm;\n" +" mat4 proj;\n" +" mat4 texMtxs[6];\n" +"};\n" +"\n" +"struct VertToFrag\n" +"{\n" +" vec4 mvPos;\n" +" vec4 mvNorm;\n" +" vec4 mvBinorm;\n" +" vec4 mvTangent;\n" +" vec4 color;\n" +" vec2 uvs[7];\n" +"};\n" +"\n" +"SBINDING(0) out VertToFrag vtf;\n" +"void main()\n" +"{\n" +" vec4 pos = vec4(posIn.xyz, 1.0);\n" +" vtf.mvPos = mv * pos;\n" +" gl_Position = proj * vtf.mvPos;\n" +" vtf.mvNorm = mvNorm * normalIn;\n" +" vtf.mvBinorm = mvNorm * binormalIn;\n" +" vtf.mvTangent = mvNorm * tangentIn;\n" +" vtf.color = vec4(colorIn.xyz, 1.0);\n" +" vtf.uvs[0] = (texMtxs[0] * pos).xy;\n" +" vtf.uvs[1] = (texMtxs[1] * pos).xy;\n" +" vtf.uvs[2] = (texMtxs[2] * pos).xy;\n" +"%s" // Additional TCGs here +"}\n"; + +static const char* TessVS = +"layout(location=0) in vec4 posIn;\n" +"layout(location=1) in vec4 outerLevelsIn;\n" +"layout(location=2) in vec2 innerLevelsIn;\n" +"\n" +"struct VertToControl\n" +"{\n" +" vec4 minMaxPos;\n" +" vec4 outerLevels;\n" +" vec2 innerLevels;\n" +"};\n" +"\n" +"SBINDING(0) out VertToControl vtc;\n" +"\n" +"void main()\n" +"{\n" +" vtc.minMaxPos = posIn;\n" +" vtc.outerLevels = outerLevelsIn;\n" +" vtc.innerLevels = innerLevelsIn;\n" +"}\n"; + +static const char* TessCS = +"#extension GL_ARB_tessellation_shader: enable\n" +"layout(vertices = 1) out;\n" +"\n" +"struct VertToControl\n" +"{\n" +" vec4 minMaxPos;\n" +" vec4 outerLevels;\n" +" vec2 innerLevels;\n" +"};\n" +"\n" +"SBINDING(0) in VertToControl vtc[];\n" +"SBINDING(0) patch out vec4 minMaxPos;\n" +"\n" +"void main()\n" +"{\n" +" minMaxPos = vtc[gl_InvocationID].minMaxPos;\n" +" for (int i=0 ; i<4 ; ++i)\n" +" gl_TessLevelOuter[i] = vtc[gl_InvocationID].outerLevels[i];\n" +" for (int i=0 ; i<2 ; ++i)\n" +" gl_TessLevelInner[i] = vtc[gl_InvocationID].innerLevels[i];\n" +"}"; + +static const char* TessES = +"#extension GL_ARB_tessellation_shader: enable\n" +"layout(quads, equal_spacing) in;\n" +"\n" +"struct Ripple\n" +"{\n" +" vec4 center; // time, distFalloff\n" +" vec4 params; // amplitude, lookupPhase, lookupTime\n" +"};\n" +"\n" +"UBINDING0 uniform FluidPlaneUniform\n" +"{\n" +" mat4 mv;\n" +" mat4 mvNorm;\n" +" mat4 proj;\n" +" mat4 texMtxs[6];\n" +" Ripple ripples[20];\n" +" vec4 colorMul;\n" +" float rippleNormResolution;\n" +"};\n" +"\n" +"struct VertToFrag\n" +"{\n" +" vec4 mvPos;\n" +" vec4 mvNorm;\n" +" vec4 mvBinorm;\n" +" vec4 mvTangent;\n" +" vec4 color;\n" +" vec2 uvs[7];\n" +"};\n" +"\n" +"SBINDING(0) patch in vec4 minMaxPos;\n" +"SBINDING(0) out VertToFrag vtf;\n" +"\n" +"TBINDING%d uniform sampler2D RippleMap;\n" +"\n" +"const float PI_X2 = 6.283185307179586;\n" +"\n" +"void ApplyRipple(in Ripple ripple, in vec2 pos, inout float height)\n" +"{\n" +" float dist = length(ripple.center.xy - pos);\n" +" float rippleV = textureLod(RippleMap, vec2(dist * ripple.center.w, ripple.center.z), 0.0).r;\n" +" height += rippleV * ripple.params.x * sin((dist * ripple.params.y + ripple.params.z) * PI_X2);\n" +"}\n" +"\n" +"void main()\n" +"{\n" +" vec2 posIn = vec2(mix(minMaxPos.x, minMaxPos.z, gl_TessCoord.x),\n" +" mix(minMaxPos.y, minMaxPos.w, gl_TessCoord.y));\n" +" float height = 0.0;\n" +" float upHeight = 0.0;\n" +" float downHeight = 0.0;\n" +" float rightHeight = 0.0;\n" +" float leftHeight = 0.0;\n" +" for (int i=0 ; i<20 ; ++i)\n" +" {\n" +" ApplyRipple(ripples[i], posIn, height);\n" +" ApplyRipple(ripples[i], posIn + vec2(0.0, rippleNormResolution), upHeight);\n" +" ApplyRipple(ripples[i], posIn - vec2(0.0, rippleNormResolution), downHeight);\n" +" ApplyRipple(ripples[i], posIn + vec2(rippleNormResolution, 0.0), rightHeight);\n" +" ApplyRipple(ripples[i], posIn - vec2(rippleNormResolution, 0.0), leftHeight);\n" +" }\n" +" vec4 normalIn = vec4(normalize(vec3((leftHeight - rightHeight),\n" +" (downHeight - upHeight),\n" +" rippleNormResolution)), 1.0);\n" +" vec4 binormalIn = vec4(normalIn.x, normalIn.z, -normalIn.y, 1.0);\n" +" vec4 tangentIn = vec4(normalIn.z, normalIn.y, -normalIn.x, 1.0);\n" +" vec4 pos = vec4(posIn, height, 1.0);\n" +" vtf.mvPos = mv * pos;\n" +" gl_Position = proj * vtf.mvPos;\n" +" vtf.mvNorm = mvNorm * normalIn;\n" +" vtf.mvBinorm = mvNorm * binormalIn;\n" +" vtf.mvTangent = mvNorm * tangentIn;\n" +" vtf.color = max(height, 0.0) * colorMul;\n" +" vtf.color.a = 1.0;\n" +" vtf.uvs[0] = (texMtxs[0] * pos).xy;\n" +" vtf.uvs[1] = (texMtxs[1] * pos).xy;\n" +" vtf.uvs[2] = (texMtxs[2] * pos).xy;\n" +"%s\n" // Additional TCGs here +"}\n"; + +static const char* FS = +"struct Light\n" +"{\n" +" vec4 pos;\n" +" vec4 dir;\n" +" vec4 color;\n" +" vec4 linAtt;\n" +" vec4 angAtt;\n" +"};\n" +"struct Fog\n" // Reappropriated for indirect texture scaling +"{\n" +" int mode;\n" +" vec4 color;\n" +" float indScale;\n" +" float start;\n" +"};\n" +"\n" +"UBINDING2 uniform LightingUniform\n" +"{\n" +" Light lights[" _XSTR(URDE_MAX_LIGHTS) "];\n" +" vec4 ambient;\n" +" vec4 kColor0;\n" +" vec4 kColor1;\n" +" vec4 kColor2;\n" +" vec4 kColor3;\n" +" Fog fog;\n" +"};\n" +"\n" +"vec4 LightingFunc(vec3 mvPosIn, vec3 mvNormIn)\n" +"{\n" +" vec4 ret = ambient;\n" +" \n" +" for (int i=0 ; i<" _XSTR(URDE_MAX_LIGHTS) " ; ++i)\n" +" {\n" +" vec3 delta = mvPosIn - lights[i].pos.xyz;\n" +" float dist = length(delta);\n" +" float angDot = clamp(dot(normalize(delta), lights[i].dir.xyz), 0.0, 1.0);\n" +" float att = 1.0 / (lights[i].linAtt[2] * dist * dist +\n" +" lights[i].linAtt[1] * dist +\n" +" lights[i].linAtt[0]);\n" +" float angAtt = lights[i].angAtt[2] * angDot * angDot +\n" +" lights[i].angAtt[1] * angDot +\n" +" lights[i].angAtt[0];\n" +" ret += lights[i].color * clamp(angAtt, 0.0, 1.0) * att * clamp(dot(normalize(-delta), mvNormIn), 0.0, 1.0);\n" +" }\n" +" \n" +" return ret;\n" +"}\n" +"\n" +"struct VertToFrag\n" +"{\n" +" vec4 mvPos;\n" +" vec4 mvNorm;\n" +" vec4 mvBinorm;\n" +" vec4 mvTangent;\n" +" vec4 color;\n" +" vec2 uvs[7];\n" +"};\n" +"\n" +"SBINDING(0) in VertToFrag vtf;\n" +"layout(location=0) out vec4 colorOut;\n" +"%s" // Textures here +"void main()\n" +"{\n" +" vec4 lighting = LightingFunc(vtf.mvPos.xyz, normalize(vtf.mvNorm.xyz));\n" +"%s" // Combiner expression here +"}\n"; + +static const char* FSDoor = +"\n" +"struct Light\n" +"{\n" +" vec4 pos;\n" +" vec4 dir;\n" +" vec4 color;\n" +" vec4 linAtt;\n" +" vec4 angAtt;\n" +"};\n" +"struct Fog\n" // Reappropriated for indirect texture scaling +"{\n" +" int mode;\n" +" vec4 color;\n" +" float indScale;\n" +" float start;\n" +"};\n" +"\n" +"UBINDING2 uniform LightingUniform\n" +"{\n" +" Light lights[" _XSTR(URDE_MAX_LIGHTS) "];\n" +" vec4 ambient;\n" +" vec4 kColor0;\n" +" vec4 kColor1;\n" +" vec4 kColor2;\n" +" vec4 kColor3;\n" +" Fog fog;\n" +"};\n" +"\n" +"struct VertToFrag\n" +"{\n" +" vec4 mvPos;\n" +" vec4 mvNorm;\n" +" vec4 mvBinorm;\n" +" vec4 mvTangent;\n" +" vec4 color;\n" +" vec2 uvs[7];\n" +"};\n" +"\n" +"SBINDING(0) in VertToFrag vtf;\n" +"layout(location=0) out vec4 colorOut;\n" +"%s" // Textures here +"void main()\n" +"{\n" +"%s" // Combiner expression here +"}\n"; + +static std::string _BuildFS(const SFluidPlaneShaderInfo& info) +{ + std::string textures; + std::string combiner; + int nextTex = 0; + int nextTCG = 3; + int bumpMapUv, envBumpMapUv, envMapUv, lightmapUv; + + if (info.m_hasPatternTex1) + { + textures += hecl::Format("TBINDING%d uniform sampler2D patternTex1;\n", nextTex++); + } + if (info.m_hasPatternTex2) + { + textures += hecl::Format("TBINDING%d uniform sampler2D patternTex2;\n", nextTex++); + } + if (info.m_hasColorTex) + { + textures += hecl::Format("TBINDING%d uniform sampler2D colorTex;\n", nextTex++); + } + if (info.m_hasBumpMap) + { + textures += hecl::Format("TBINDING%d uniform sampler2D bumpMap;\n", nextTex++); + } + if (info.m_hasEnvMap) + { + textures += hecl::Format("TBINDING%d uniform sampler2D envMap;\n", nextTex++); + } + if (info.m_hasEnvBumpMap) + { + textures += hecl::Format("TBINDING%d uniform sampler2D envBumpMap;\n", nextTex++); + } + if (info.m_hasLightmap) + { + textures += hecl::Format("TBINDING%d uniform sampler2D lightMap;\n", nextTex++); + } + + if (info.m_hasBumpMap) + { + bumpMapUv = nextTCG++; + } + if (info.m_hasEnvBumpMap) + { + envBumpMapUv = nextTCG++; + } + if (info.m_hasEnvMap) + { + envMapUv = nextTCG++; + } + if (info.m_hasLightmap) + { + lightmapUv = nextTCG; + } + + switch (info.m_type) + { + case EFluidType::NormalWater: + case EFluidType::PhazonFluid: + case EFluidType::Four: + if (info.m_hasLightmap) + { + combiner += hecl::Format(" vec4 lightMapTexel = texture(lightMap, vtf.uvs[%d]);\n", lightmapUv); + // 0: Tex4TCG, Tex4, doubleLightmapBlend ? NULL : GX_COLOR1A1 + // ZERO, TEX, KONST, doubleLightmapBlend ? ZERO : RAS + // Output reg 2 + // KColor 2 + if (info.m_doubleLightmapBlend) + { + // 1: Tex4TCG2, Tex4, GX_COLOR1A1 + // C2, TEX, KONST, RAS + // Output reg 2 + // KColor 3 + // Tex * K2 + Lighting + combiner += " lighting += mix(lightMapTexel * kColor2, lightMapTexel, kColor3);\n"; + } + else + { + // mix(Tex * K2, Tex, K3) + Lighting + combiner += " lighting += lightMapTexel * kColor2;\n"; + } + } + + // Next: Tex0TCG, Tex0, GX_COLOR1A1 + // ZERO, TEX, KONST, RAS + // Output reg prev + // KColor 0 + + // Next: Tex1TCG, Tex1, GX_COLOR0A0 + // ZERO, TEX, PREV, RAS + // Output reg prev + + // Next: Tex2TCG, Tex2, GX_COLOR1A1 + // ZERO, TEX, hasTex4 ? C2 : RAS, PREV + // Output reg prev + + // (Tex0 * kColor0 + Lighting) * Tex1 + VertColor + Tex2 * Lighting + if (info.m_hasPatternTex2) + { + if (info.m_hasPatternTex1) + combiner += " colorOut = (texture(patternTex1, vtf.uvs[0]) * kColor0 + lighting) *\n" + " texture(patternTex2, vtf.uvs[1]) + vtf.color;\n"; + else + combiner += " colorOut = lighting * texture(patternTex2, vtf.uvs[1]) + vtf.color;\n"; + } + else + { + combiner += " colorOut = vtf.color;\n"; + } + + + if (info.m_hasColorTex && !info.m_hasEnvMap && info.m_hasEnvBumpMap) + { + // Make previous stage indirect, mtx0 + combiner += hecl::Format(" vec2 indUvs = (texture(envBumpMap, vtf.uvs[%d]).ra - vec2(0.5, 0.5)) *\n" + " vec2(fog.indScale, -fog.indScale);\n", envBumpMapUv); + combiner += " colorOut += texture(colorTex, indUvs + vtf.uvs[2]) * lighting;\n"; + } + else if (info.m_hasEnvMap) + { + // Next: envTCG, envTex, NULL + // PREV, TEX, KONST, ZERO + // Output reg prev + // KColor 1 + + // Make previous stage indirect, mtx0 + if (info.m_hasColorTex) + combiner += " colorOut += texture(colorTex, vtf.uvs[2]) * lighting;\n"; + combiner += hecl::Format(" vec2 indUvs = (texture(envBumpMap, vtf.uvs[%d]).ra - vec2(0.5, 0.5)) *\n" + " vec2(fog.indScale, -fog.indScale);\n", envBumpMapUv); + combiner += hecl::Format(" colorOut = mix(colorOut, texture(envMap, indUvs + vtf.uvs[%d]), kColor1);\n", + envMapUv); + } + else if (info.m_hasColorTex) + { + combiner += " colorOut += texture(colorTex, vtf.uvs[2]) * lighting;\n"; + } + + break; + + case EFluidType::PoisonWater: + if (info.m_hasLightmap) + { + combiner += hecl::Format(" vec4 lightMapTexel = texture(lightMap, vtf.uvs[%d]);\n", lightmapUv); + // 0: Tex4TCG, Tex4, doubleLightmapBlend ? NULL : GX_COLOR1A1 + // ZERO, TEX, KONST, doubleLightmapBlend ? ZERO : RAS + // Output reg 2 + // KColor 2 + if (info.m_doubleLightmapBlend) + { + // 1: Tex4TCG2, Tex4, GX_COLOR1A1 + // C2, TEX, KONST, RAS + // Output reg 2 + // KColor 3 + // Tex * K2 + Lighting + combiner += " lighting += mix(lightMapTexel * kColor2, lightMapTexel, kColor3);\n"; + } + else + { + // mix(Tex * K2, Tex, K3) + Lighting + combiner += " lighting += lightMapTexel * kColor2;\n"; + } + } + + // Next: Tex0TCG, Tex0, GX_COLOR1A1 + // ZERO, TEX, KONST, RAS + // Output reg prev + // KColor 0 + + // Next: Tex1TCG, Tex1, GX_COLOR0A0 + // ZERO, TEX, PREV, RAS + // Output reg prev + + // Next: Tex2TCG, Tex2, GX_COLOR1A1 + // ZERO, TEX, hasTex4 ? C2 : RAS, PREV + // Output reg prev + + // (Tex0 * kColor0 + Lighting) * Tex1 + VertColor + Tex2 * Lighting + if (info.m_hasPatternTex2) + { + if (info.m_hasPatternTex1) + combiner += " colorOut = (texture(patternTex1, vtf.uvs[0]) * kColor0 + lighting) *\n" + " texture(patternTex2, vtf.uvs[1]) + vtf.color;\n"; + else + combiner += " colorOut = lighting * texture(patternTex2, vtf.uvs[1]) + vtf.color;\n"; + } + else + { + combiner += " colorOut = vtf.color;\n"; + } + + if (info.m_hasColorTex) + { + if (info.m_hasEnvBumpMap) + { + // Make previous stage indirect, mtx0 + combiner += hecl::Format(" vec2 indUvs = (texture(envBumpMap, vtf.uvs[%d]).ra - vec2(0.5, 0.5)) *\n" + " vec2(fog.indScale, -fog.indScale);\n", envBumpMapUv); + combiner += " colorOut += texture(colorTex, indUvs + vtf.uvs[2]) * lighting;\n"; + } + else + { + combiner += " colorOut += texture(colorTex, vtf.uvs[2]) * lighting;\n"; + } + } + + break; + + case EFluidType::Lava: + // 0: Tex0TCG, Tex0, GX_COLOR0A0 + // ZERO, TEX, KONST, RAS + // Output reg prev + // KColor 0 + + // 1: Tex1TCG, Tex1, GX_COLOR0A0 + // ZERO, TEX, PREV, RAS + // Output reg prev + + // 2: Tex2TCG, Tex2, NULL + // ZERO, TEX, ONE, PREV + // Output reg prev + + // (Tex0 * kColor0 + VertColor) * Tex1 + VertColor + Tex2 + if (info.m_hasPatternTex2) + { + if (info.m_hasPatternTex1) + combiner += " colorOut = (texture(patternTex1, vtf.uvs[0]) * kColor0 + vtf.color) *\n" + " texture(patternTex2, vtf.uvs[1]) + vtf.color;\n"; + else + combiner += " colorOut = vtf.color * texture(patternTex2, vtf.uvs[1]) + vtf.color;\n"; + } + else + { + combiner += " colorOut = vtf.color;\n"; + } + + if (info.m_hasColorTex) + combiner += " colorOut += texture(colorTex, vtf.uvs[2]);\n"; + + if (info.m_hasBumpMap) + { + // 3: bumpMapTCG, bumpMap, NULL + // ZERO, TEX, ONE, HALF + // Output reg 0, no clamp, no bias + + // 4: bumpMapTCG2, bumpMap, NULL + // ZERO, TEX, ONE, C0 + // Output reg 0, subtract, clamp, no bias + + combiner += " vec3 lightVec = lights[3].pos.xyz - vtf.mvPos.xyz;\n" + " float lx = dot(vtf.mvTangent, lightVec);\n" + " float ly = dot(vtf.mvBinorm, lightVec);\n"; + combiner += hecl::Format(" vec4 emboss1 = texture(bumpMap, vtf.uvs[%d]) + vec4(0.5);\n" + " vec4 emboss2 = texture(bumpMap, vtf.uvs[%d] + vec2(lx, ly));\n", + bumpMapUv, bumpMapUv); + + // 5: NULL, NULL, NULL + // ZERO, PREV, C0, ZERO + // Output reg prev, scale 2, clamp + + // colorOut * clamp(emboss1 + 0.5 - emboss2, 0.0, 1.0) * 2.0 + combiner += "colorOut *= clamp((emboss1 + vec4(0.5) - emboss2) * vec4(2.0), vec4(0.0), vec4(1.0));\n"; + } + + break; + + case EFluidType::ThickLava: + // 0: Tex0TCG, Tex0, GX_COLOR0A0 + // ZERO, TEX, KONST, RAS + // Output reg prev + // KColor 0 + + // 1: Tex1TCG, Tex1, GX_COLOR0A0 + // ZERO, TEX, PREV, RAS + // Output reg prev + + // 2: Tex2TCG, Tex2, NULL + // ZERO, TEX, ONE, PREV + // Output reg prev + + // (Tex0 * kColor0 + VertColor) * Tex1 + VertColor + Tex2 + if (info.m_hasPatternTex2) + { + if (info.m_hasPatternTex1) + combiner += " colorOut = (texture(patternTex1, vtf.uvs[0]) * kColor0 + vtf.color) *\n" + " texture(patternTex2, vtf.uvs[1]) + vtf.color;\n"; + else + combiner += " colorOut = vtf.color * texture(patternTex2, vtf.uvs[1]) + vtf.color;\n"; + } + else + { + combiner += " colorOut = vtf.color;\n"; + } + + if (info.m_hasColorTex) + combiner += " colorOut += texture(colorTex, vtf.uvs[2]);\n"; + + if (info.m_hasBumpMap) + { + // 3: bumpMapTCG, bumpMap, NULL + // ZERO, TEX, PREV, ZERO + // Output reg prev, scale 2 + combiner += hecl::Format(" vec4 emboss1 = texture(bumpMap, vtf.uvs[%d]) + vec4(0.5);\n", bumpMapUv); + combiner += "colorOut *= emboss1 * vec4(2.0);\n"; + } + + break; + } + + combiner += " colorOut.a = kColor0.a;\n"; + + char *finalFSs; + asprintf(&finalFSs, FS, textures.c_str(), combiner.c_str()); + std::string ret(finalFSs); + free(finalFSs); + return ret; +} + +static std::string _BuildAdditionalTCGs(const SFluidPlaneShaderInfo& info) +{ + std::string additionalTCGs; + int nextTCG = 3; + int nextMtx = 4; + + if (info.m_hasBumpMap) + { + additionalTCGs += hecl::Format(" vtf.uvs[%d] = (texMtxs[0] * pos).xy;\n", nextTCG++); + } + if (info.m_hasEnvBumpMap) + { + additionalTCGs += hecl::Format(" vtf.uvs[%d] = (texMtxs[3] * vec4(normalIn.xyz, 1.0)).xy;\n", nextTCG++); + } + if (info.m_hasEnvMap) + { + additionalTCGs += hecl::Format(" vtf.uvs[%d] = (texMtxs[%d] * pos).xy;\n", nextTCG++, nextMtx++); + } + if (info.m_hasLightmap) + { + additionalTCGs += hecl::Format(" vtf.uvs[%d] = (texMtxs[%d] * pos).xy;\n", nextTCG, nextMtx); + } + + return additionalTCGs; +} + +static std::string _BuildVS(const SFluidPlaneShaderInfo& info, bool tessellation) +{ + if (tessellation) + return TessVS; + + std::string additionalTCGs = _BuildAdditionalTCGs(info); + + char *finalVSs; + asprintf(&finalVSs, VS, additionalTCGs.c_str()); + std::string ret(finalVSs); + free(finalVSs); + return ret; +} +template <> +std::string StageObject_CFluidPlaneShader::BuildShader + (const SFluidPlaneShaderInfo& in, bool tessellation) +{ + return _BuildVS(in, tessellation); +} +template <> +std::string StageObject_CFluidPlaneShader::BuildShader + (const SFluidPlaneShaderInfo& in, bool tessellation) +{ + return _BuildVS(in, tessellation); +} +template <> +std::string StageObject_CFluidPlaneShader::BuildShader + (const SFluidPlaneShaderInfo& in, bool tessellation) +{ + return _BuildVS(in, tessellation); +} + +template <> +std::string StageObject_CFluidPlaneShader::BuildShader + (const SFluidPlaneShaderInfo& in, bool tessellation) +{ + return _BuildFS(in); +} +template <> +std::string StageObject_CFluidPlaneShader::BuildShader + (const SFluidPlaneShaderInfo& in, bool tessellation) +{ + return _BuildFS(in); +} +template <> +std::string StageObject_CFluidPlaneShader::BuildShader + (const SFluidPlaneShaderInfo& in, bool tessellation) +{ + return _BuildFS(in); +} + +template <> +std::string StageObject_CFluidPlaneShader::BuildShader + (const SFluidPlaneShaderInfo& in, bool tessellation) +{ + return TessCS; +} +template <> +std::string StageObject_CFluidPlaneShader::BuildShader + (const SFluidPlaneShaderInfo& in, bool tessellation) +{ + return TessCS; +} +template <> +std::string StageObject_CFluidPlaneShader::BuildShader + (const SFluidPlaneShaderInfo& in, bool tessellation) +{ + return TessCS; +} + +static std::string BuildES(const SFluidPlaneShaderInfo& info) +{ + int nextTex = 0; + if (info.m_hasPatternTex1) + nextTex++; + if (info.m_hasPatternTex2) + nextTex++; + if (info.m_hasColorTex) + nextTex++; + if (info.m_hasBumpMap) + nextTex++; + if (info.m_hasEnvMap) + nextTex++; + if (info.m_hasEnvBumpMap) + nextTex++; + if (info.m_hasLightmap) + nextTex++; + + std::string additionalTCGs = _BuildAdditionalTCGs(info); + + char *finalESs; + asprintf(&finalESs, TessES, nextTex, additionalTCGs.c_str()); + std::string ret(finalESs); + free(finalESs); + + return ret; +} +template <> +std::string StageObject_CFluidPlaneShader::BuildShader + (const SFluidPlaneShaderInfo& in, bool tessellation) +{ + return BuildES(in); +} +template <> +std::string StageObject_CFluidPlaneShader::BuildShader + (const SFluidPlaneShaderInfo& in, bool tessellation) +{ + return BuildES(in); +} +template <> +std::string StageObject_CFluidPlaneShader::BuildShader + (const SFluidPlaneShaderInfo& in, bool tessellation) +{ + return BuildES(in); +} + +static std::string _BuildVS(const SFluidPlaneDoorShaderInfo& info) +{ + char *finalVSs; + asprintf(&finalVSs, VS, ""); + std::string ret(finalVSs); + free(finalVSs); + return ret; +} + +static std::string _BuildFS(const SFluidPlaneDoorShaderInfo& info) +{ + int nextTex = 0; + std::string textures; + std::string combiner; + + if (info.m_hasPatternTex1) + { + textures += hecl::Format("TBINDING%d uniform sampler2D patternTex1;\n", nextTex++); + } + if (info.m_hasPatternTex2) + { + textures += hecl::Format("TBINDING%d uniform sampler2D patternTex2;\n", nextTex++); + } + if (info.m_hasColorTex) + { + textures += hecl::Format("TBINDING%d uniform sampler2D colorTex;\n", nextTex++); + } + + // Tex0 * kColor0 * Tex1 + Tex2 + if (info.m_hasPatternTex1 && info.m_hasPatternTex2) + { + combiner += " colorOut = texture(patternTex1, vtf.uvs[0]) * kColor0 *\n" + " texture(patternTex2, vtf.uvs[1]);\n"; + } + else + { + combiner += " colorOut = vec4(0.0);\n"; + } + + if (info.m_hasColorTex) + { + combiner += " colorOut += texture(colorTex, vtf.uvs[2]);\n"; + } + + combiner += " colorOut.a = kColor0.a;\n"; + + char *finalFSs; + asprintf(&finalFSs, FSDoor, textures.c_str(), combiner.c_str()); + std::string ret(finalFSs); + free(finalFSs); + return ret; +} + +template <> +std::string StageObject_CFluidPlaneDoorShader::BuildShader + (const SFluidPlaneDoorShaderInfo& in) +{ + return _BuildVS(in); +} +template <> +std::string StageObject_CFluidPlaneDoorShader::BuildShader + (const SFluidPlaneDoorShaderInfo& in) +{ + return _BuildVS(in); +} +template <> +std::string StageObject_CFluidPlaneDoorShader::BuildShader + (const SFluidPlaneDoorShaderInfo& in) +{ + return _BuildVS(in); +} + +template <> +std::string StageObject_CFluidPlaneDoorShader::BuildShader + (const SFluidPlaneDoorShaderInfo& in) +{ + return _BuildFS(in); +} +template <> +std::string StageObject_CFluidPlaneDoorShader::BuildShader + (const SFluidPlaneDoorShaderInfo& in) +{ + return _BuildFS(in); +} +template <> +std::string StageObject_CFluidPlaneDoorShader::BuildShader + (const SFluidPlaneDoorShaderInfo& in) +{ + return _BuildFS(in); +} diff --git a/Shaders/shader_CFluidPlaneShaderHLSL.cpp b/Shaders/shader_CFluidPlaneShaderHLSL.cpp new file mode 100644 index 000000000..49f391ee2 --- /dev/null +++ b/Shaders/shader_CFluidPlaneShaderHLSL.cpp @@ -0,0 +1,771 @@ +#include "shader_CFluidPlaneShader.hpp" + +static const char* VS = +"struct VertData\n" +"{\n" +" float4 posIn : POSITION;\n" +" float4 normalIn : NORMAL0;\n" +" float4 binormalIn : NORMAL1;\n" +" float4 tangentIn : NORMAL2;\n" +" float4 colorIn : COLOR;\n" +"};\n" +"\n" +"cbuffer FluidPlaneUniform : register(b0)\n" +"{\n" +" float4x4 mv;\n" +" float4x4 mvNorm;\n" +" float4x4 proj;\n" +" float4x4 texMtxs[6];\n" +"};\n" +"\n" +"struct VertToFrag\n" +"{\n" +" float4 pos : SV_Position;\n" +" float4 mvPos : POSITION;\n" +" float4 mvNorm : NORMAL;\n" +" float4 mvBinorm : BINORMAL;\n" +" float4 mvTangent : TANGENT;\n" +" float4 color : COLOR;\n" +" float2 uvs[7] : UV;\n" +"};\n" +"\n" +"VertToFrag main(in VertData v)\n" +"{\n" +" VertToFrag vtf;\n" +" float4 pos = float4(v.posIn.xyz, 1.0);\n" +" float4 normalIn = v.normalIn;\n" +" vtf.mvPos = mul(mv, pos);\n" +" vtf.pos = mul(proj, vtf.mvPos);\n" +" vtf.mvNorm = mul(mvNorm, v.normalIn);\n" +" vtf.mvBinorm = mul(mvNorm, v.binormalIn);\n" +" vtf.mvTangent = mul(mvNorm, v.tangentIn);\n" +" vtf.color = float4(v.colorIn.xyz, 1.0);\n" +" vtf.uvs[0] = mul(texMtxs[0], pos).xy;\n" +" vtf.uvs[1] = mul(texMtxs[1], pos).xy;\n" +" vtf.uvs[2] = mul(texMtxs[2], pos).xy;\n" +"%s" // Additional TCGs here +" return vtf;\n" +"}\n"; + +static const char* TessVS = +"struct VertData\n" +"{\n" +" float4 posIn : POSITION;\n" +" float4 outerLevelsIn : UV0;\n" +" float2 innerLevelsIn : UV1;\n" +"};\n" +"\n" +"struct VertToControl\n" +"{\n" +" float4 minMaxPos : POSITION;\n" +" float4 outerLevels : OUTERLEVELS;\n" +" float2 innerLevels : INNERLEVELS;\n" +"};\n" +"\n" +"VertToControl main(in VertData v)\n" +"{\n" +" VertToControl vtc;\n" +" vtc.minMaxPos = v.posIn;\n" +" vtc.outerLevels = v.outerLevelsIn;\n" +" vtc.innerLevels = v.innerLevelsIn;\n" +" return vtc;\n" +"}\n"; + +static const char* TessCS = +"struct VertToControl\n" +"{\n" +" float4 minMaxPos : POSITION;\n" +" float4 outerLevels : OUTERLEVELS;\n" +" float2 innerLevels : INNERLEVELS;\n" +"};\n" +"\n" +"struct ControlToEvaluation\n" +"{\n" +" float4 minMaxPos : POSITION;\n" +" float outerLevels[4] : SV_TessFactor;\n" +" float innerLevels[2] : SV_InsideTessFactor;\n" +"};\n" +"\n" +"struct ControlPoint\n" +"{};\n" +"\n" +"ControlToEvaluation patchmain(InputPatch vtc, uint id : SV_PrimitiveID)\n" +"{\n" +" ControlToEvaluation cte;\n" +" cte.minMaxPos = vtc[id].minMaxPos;\n" +" for (int i=0 ; i<4 ; ++i)\n" +" cte.outerLevels[i] = vtc[id].outerLevels[i];\n" +" for (int i=0 ; i<2 ; ++i)\n" +" cte.innerLevels[i] = vtc[id].innerLevels[i];\n" +" return cte;\n" +"}\n" +"\n" +"[domain(\"quad\")]\n" +"[partitioning(\"integer\")]\n" +"[outputtopology(\"triangle_cw\")]\n" +"[outputcontrolpoints(1)]\n" +"[patchconstantfunc(\"patchmain\")]\n" +"ControlPoint main(InputPatch vtc, uint i : SV_OutputControlPointID, uint id : SV_PrimitiveID)\n" +"{\n" +" ControlPoint pt;\n" +" return pt;\n" +"}\n"; + +static const char* TessES = +"struct Ripple\n" +"{\n" +" float4 center; // time, distFalloff\n" +" float4 params; // amplitude, lookupPhase, lookupTime\n" +"};\n" +"\n" +"cbuffer FluidPlaneUniform : register(b0)\n" +"{\n" +" float4x4 mv;\n" +" float4x4 mvNorm;\n" +" float4x4 proj;\n" +" float4x4 texMtxs[6];\n" +" Ripple ripples[20];\n" +" float4 colorMul;\n" +" float rippleNormResolution;\n" +"};\n" +"\n" +"struct VertToFrag\n" +"{\n" +" float4 pos : SV_Position;\n" +" float4 mvPos : POSITION;\n" +" float4 mvNorm : NORMAL;\n" +" float4 mvBinorm : BINORMAL;\n" +" float4 mvTangent : TANGENT;\n" +" float4 color : COLOR;\n" +" float2 uvs[7] : UV;\n" +"};\n" +"\n" +"struct ControlToEvaluation\n" +"{\n" +" float4 minMaxPos : POSITION;\n" +" float outerLevels[4] : SV_TessFactor;\n" +" float innerLevels[2] : SV_InsideTessFactor;\n" +"};\n" +"\n" +"struct ControlPoint\n" +"{};\n" +"\n" +"Texture2D RippleMap : register(t%d);\n" +"SamplerState samp : register(s2);\n" +"\n" +"static const float PI_X2 = 6.283185307179586;\n" +"\n" +"static void ApplyRipple(in Ripple ripple, in float2 pos, inout float height)\n" +"{\n" +" float dist = length(ripple.center.xy - pos);\n" +" float rippleV = RippleMap.SampleLevel(samp, float2(dist * ripple.center.w, ripple.center.z), 0.0).r;\n" +" height += rippleV * ripple.params.x * sin((dist * ripple.params.y + ripple.params.z) * PI_X2);\n" +"}\n" +"\n" +"[domain(\"quad\")]\n" +"VertToFrag main(in ControlToEvaluation cte, in float2 TessCoord : SV_DomainLocation,\n" +" const OutputPatch bezpatch)\n" +"{\n" +" float2 posIn = float2(lerp(cte.minMaxPos.x, cte.minMaxPos.z, TessCoord.x),\n" +" lerp(cte.minMaxPos.y, cte.minMaxPos.w, TessCoord.y));\n" +" float height = 0.0;\n" +" float upHeight = 0.0;\n" +" float downHeight = 0.0;\n" +" float rightHeight = 0.0;\n" +" float leftHeight = 0.0;\n" +" for (int i=0 ; i<20 ; ++i)\n" +" {\n" +" ApplyRipple(ripples[i], posIn, height);\n" +" ApplyRipple(ripples[i], posIn + float2(0.0, rippleNormResolution), upHeight);\n" +" ApplyRipple(ripples[i], posIn - float2(0.0, rippleNormResolution), downHeight);\n" +" ApplyRipple(ripples[i], posIn + float2(rippleNormResolution, 0.0), rightHeight);\n" +" ApplyRipple(ripples[i], posIn - float2(rippleNormResolution, 0.0), leftHeight);\n" +" }\n" +" float4 normalIn = float4(normalize(float3((leftHeight - rightHeight),\n" +" (downHeight - upHeight),\n" +" rippleNormResolution)), 1.0);\n" +" float4 binormalIn = float4(normalIn.x, normalIn.z, -normalIn.y, 1.0);\n" +" float4 tangentIn = float4(normalIn.z, normalIn.y, -normalIn.x, 1.0);\n" +" float4 pos = float4(posIn, height, 1.0);\n" +" VertToFrag vtf;\n" +" vtf.mvPos = mul(mv, pos);\n" +" vtf.pos = mul(proj, vtf.mvPos);\n" +" vtf.mvNorm = mul(mvNorm, normalIn);\n" +" vtf.mvBinorm = mul(mvNorm, binormalIn);\n" +" vtf.mvTangent = mul(mvNorm, tangentIn);\n" +" vtf.color = max(height, 0.0) * colorMul;\n" +" vtf.color.a = 1.0;\n" +" vtf.uvs[0] = mul(texMtxs[0], pos).xy;\n" +" vtf.uvs[1] = mul(texMtxs[1], pos).xy;\n" +" vtf.uvs[2] = mul(texMtxs[2], pos).xy;\n" +"%s\n" // Additional TCGs here +" return vtf;\n" +"}\n"; + +static const char* FS = +"struct Light\n" +"{\n" +" float4 pos;\n" +" float4 dir;\n" +" float4 color;\n" +" float4 linAtt;\n" +" float4 angAtt;\n" +"};\n" +"struct Fog\n" // Reappropriated for indirect texture scaling +"{\n" +" int mode;\n" +" float4 color;\n" +" float indScale;\n" +" float start;\n" +"};\n" +"\n" +"cbuffer LightingUniform : register(b2)\n" +"{\n" +" Light lights[" _XSTR(URDE_MAX_LIGHTS) "];\n" +" float4 ambient;\n" +" float4 kColor0;\n" +" float4 kColor1;\n" +" float4 kColor2;\n" +" float4 kColor3;\n" +" Fog fog;\n" +"};\n" +"\n" +"static float4 LightingFunc(float3 mvPosIn, float3 mvNormIn)\n" +"{\n" +" float4 ret = ambient;\n" +" \n" +" for (int i=0 ; i<" _XSTR(URDE_MAX_LIGHTS) " ; ++i)\n" +" {\n" +" float3 delta = mvPosIn - lights[i].pos.xyz;\n" +" float dist = length(delta);\n" +" float angDot = clamp(dot(normalize(delta), lights[i].dir.xyz), 0.0, 1.0);\n" +" float att = 1.0 / (lights[i].linAtt[2] * dist * dist +\n" +" lights[i].linAtt[1] * dist +\n" +" lights[i].linAtt[0]);\n" +" float angAtt = lights[i].angAtt[2] * angDot * angDot +\n" +" lights[i].angAtt[1] * angDot +\n" +" lights[i].angAtt[0];\n" +" ret += lights[i].color * clamp(angAtt, 0.0, 1.0) * att * clamp(dot(normalize(-delta), mvNormIn), 0.0, 1.0);\n" +" }\n" +" \n" +" return ret;\n" +"}\n" +"\n" +"struct VertToFrag\n" +"{\n" +" float4 pos : SV_Position;\n" +" float4 mvPos : POSITION;\n" +" float4 mvNorm : NORMAL;\n" +" float4 mvBinorm : BINORMAL;\n" +" float4 mvTangent : TANGENT;\n" +" float4 color : COLOR;\n" +" float2 uvs[7] : UV;\n" +"};\n" +"\n" +"SamplerState samp : register(s0);\n" +"%s" // Textures here +"float4 main(in VertToFrag vtf) : SV_Target0\n" +"{\n" +" float4 lighting = LightingFunc(vtf.mvPos.xyz, normalize(vtf.mvNorm.xyz));\n" +" float4 colorOut;\n" +"%s" // Combiner expression here +" return colorOut;\n" +"}\n"; + +static const char* FSDoor = +"struct Light\n" +"{\n" +" float4 pos;\n" +" float4 dir;\n" +" float4 color;\n" +" float4 linAtt;\n" +" float4 angAtt;\n" +"};\n" +"struct Fog\n" // Reappropriated for indirect texture scaling +"{\n" +" int mode;\n" +" float4 color;\n" +" float indScale;\n" +" float start;\n" +"};\n" +"\n" +"cbuffer LightingUniform : register(b2)\n" +"{\n" +" Light lights[" _XSTR(URDE_MAX_LIGHTS) "];\n" +" float4 ambient;\n" +" float4 kColor0;\n" +" float4 kColor1;\n" +" float4 kColor2;\n" +" float4 kColor3;\n" +" Fog fog;\n" +"};\n" +"struct VertToFrag\n" +"{\n" +" float4 pos : SV_Position;\n" +" float4 mvPos : POSITION;\n" +" float4 mvNorm : NORMAL;\n" +" float4 mvBinorm : BINORMAL;\n" +" float4 mvTangent : TANGENT;\n" +" float4 color : COLOR;\n" +" float2 uvs[7] : UV;\n" +"};\n" +"\n" +"SamplerState samp : register(s0);\n" +"%s" // Textures here +"float4 main(in VertToFrag vtf) : SV_Target0\n" +"{\n" +" float4 colorOut;\n" +"%s" // Combiner expression here +" return colorOut;\n" +"}\n"; + +static std::string _BuildFS(const SFluidPlaneShaderInfo& info) +{ + std::string additionalTCGs; + std::string textures; + std::string combiner; + int nextTex = 0; + int nextTCG = 3; + int nextMtx = 4; + int bumpMapUv, envBumpMapUv, envMapUv, lightmapUv; + + if (info.m_hasPatternTex1) + textures += hecl::Format("Texture2D patternTex1 : register(t%d);\n", nextTex++); + if (info.m_hasPatternTex2) + textures += hecl::Format("Texture2D patternTex2 : register(t%d);\n", nextTex++); + if (info.m_hasColorTex) + textures += hecl::Format("Texture2D colorTex : register(t%d);\n", nextTex++); + if (info.m_hasBumpMap) + textures += hecl::Format("Texture2D bumpMap : register(t%d);\n", nextTex++); + if (info.m_hasEnvMap) + textures += hecl::Format("Texture2D envMap : register(t%d);\n", nextTex++); + if (info.m_hasEnvBumpMap) + textures += hecl::Format("Texture2D envBumpMap : register(t%d);\n", nextTex++); + if (info.m_hasLightmap) + textures += hecl::Format("Texture2D lightMap : register(t%d);\n", nextTex++); + + if (info.m_hasBumpMap) + { + bumpMapUv = nextTCG; + additionalTCGs += hecl::Format(" vtf.uvs[%d] = mul(texMtxs[0], pos).xy;\n", nextTCG++); + } + if (info.m_hasEnvBumpMap) + { + envBumpMapUv = nextTCG; + additionalTCGs += hecl::Format(" vtf.uvs[%d] = mul(texMtxs[3], float4(normalIn.xyz, 1.0)).xy;\n", nextTCG++); + } + if (info.m_hasEnvMap) + { + envMapUv = nextTCG; + additionalTCGs += hecl::Format(" vtf.uvs[%d] = mul(texMtxs[%d], pos).xy;\n", nextTCG++, nextMtx++); + } + if (info.m_hasLightmap) + { + lightmapUv = nextTCG; + additionalTCGs += hecl::Format(" vtf.uvs[%d] = mul(texMtxs[%d], pos).xy;\n", nextTCG++, nextMtx++); + } + + switch (info.m_type) + { + case EFluidType::NormalWater: + case EFluidType::PhazonFluid: + case EFluidType::Four: + if (info.m_hasLightmap) + { + combiner += hecl::Format(" float4 lightMapTexel = lightMap.Sample(samp, vtf.uvs[%d]);\n", lightmapUv); + // 0: Tex4TCG, Tex4, doubleLightmapBlend ? NULL : GX_COLOR1A1 + // ZERO, TEX, KONST, doubleLightmapBlend ? ZERO : RAS + // Output reg 2 + // KColor 2 + if (info.m_doubleLightmapBlend) + { + // 1: Tex4TCG2, Tex4, GX_COLOR1A1 + // C2, TEX, KONST, RAS + // Output reg 2 + // KColor 3 + // Tex * K2 + Lighting + combiner += " lighting += lerp(lightMapTexel * kColor2, lightMapTexel, kColor3);\n"; + } + else + { + // mix(Tex * K2, Tex, K3) + Lighting + combiner += " lighting += lightMapTexel * kColor2;\n"; + } + } + + // Next: Tex0TCG, Tex0, GX_COLOR1A1 + // ZERO, TEX, KONST, RAS + // Output reg prev + // KColor 0 + + // Next: Tex1TCG, Tex1, GX_COLOR0A0 + // ZERO, TEX, PREV, RAS + // Output reg prev + + // Next: Tex2TCG, Tex2, GX_COLOR1A1 + // ZERO, TEX, hasTex4 ? C2 : RAS, PREV + // Output reg prev + + // (Tex0 * kColor0 + Lighting) * Tex1 + VertColor + Tex2 * Lighting + if (info.m_hasPatternTex2) + { + if (info.m_hasPatternTex1) + combiner += " colorOut = (patternTex1.Sample(samp, vtf.uvs[0]) * kColor0 + lighting) *\n" + " patternTex2.Sample(samp, vtf.uvs[1]) + vtf.color;\n"; + else + combiner += " colorOut = lighting * patternTex2.Sample(samp, vtf.uvs[1]) + vtf.color;\n"; + } + else + { + combiner += " colorOut = vtf.color;\n"; + } + + + if (info.m_hasColorTex && !info.m_hasEnvMap && info.m_hasEnvBumpMap) + { + // Make previous stage indirect, mtx0 + combiner += hecl::Format(" float2 indUvs = (envBumpMap.Sample(samp, vtf.uvs[%d]).ra - float2(0.5, 0.5)) *\n" + " float2(fog.indScale, -fog.indScale);\n", envBumpMapUv); + combiner += " colorOut += colorTex.Sample(samp, indUvs + vtf.uvs[2]) * lighting;\n"; + } + else if (info.m_hasEnvMap) + { + // Next: envTCG, envTex, NULL + // PREV, TEX, KONST, ZERO + // Output reg prev + // KColor 1 + + // Make previous stage indirect, mtx0 + if (info.m_hasColorTex) + combiner += " colorOut += colorTex.Sample(samp, vtf.uvs[2]) * lighting;\n"; + combiner += hecl::Format(" float2 indUvs = (envBumpMap.Sample(samp, vtf.uvs[%d]).ra - float2(0.5, 0.5)) *\n" + " float2(fog.indScale, -fog.indScale);\n", envBumpMapUv); + combiner += hecl::Format(" colorOut = lerp(colorOut, envMap.Sample(samp, indUvs + vtf.uvs[%d]), kColor1);\n", + envMapUv); + } + else if (info.m_hasColorTex) + { + combiner += " colorOut += colorTex.Sample(samp, vtf.uvs[2]) * lighting;\n"; + } + + break; + + case EFluidType::PoisonWater: + if (info.m_hasLightmap) + { + combiner += hecl::Format(" float4 lightMapTexel = lightMap.Sample(samp, vtf.uvs[%d]);\n", lightmapUv); + // 0: Tex4TCG, Tex4, doubleLightmapBlend ? NULL : GX_COLOR1A1 + // ZERO, TEX, KONST, doubleLightmapBlend ? ZERO : RAS + // Output reg 2 + // KColor 2 + if (info.m_doubleLightmapBlend) + { + // 1: Tex4TCG2, Tex4, GX_COLOR1A1 + // C2, TEX, KONST, RAS + // Output reg 2 + // KColor 3 + // Tex * K2 + Lighting + combiner += " lighting += lerp(lightMapTexel * kColor2, lightMapTexel, kColor3);\n"; + } + else + { + // mix(Tex * K2, Tex, K3) + Lighting + combiner += " lighting += lightMapTexel * kColor2;\n"; + } + } + + // Next: Tex0TCG, Tex0, GX_COLOR1A1 + // ZERO, TEX, KONST, RAS + // Output reg prev + // KColor 0 + + // Next: Tex1TCG, Tex1, GX_COLOR0A0 + // ZERO, TEX, PREV, RAS + // Output reg prev + + // Next: Tex2TCG, Tex2, GX_COLOR1A1 + // ZERO, TEX, hasTex4 ? C2 : RAS, PREV + // Output reg prev + + // (Tex0 * kColor0 + Lighting) * Tex1 + VertColor + Tex2 * Lighting + if (info.m_hasPatternTex2) + { + if (info.m_hasPatternTex1) + combiner += " colorOut = (patternTex1.Sample(samp, vtf.uvs[0]) * kColor0 + lighting) *\n" + " patternTex2.Sample(samp, vtf.uvs[1]) + vtf.color;\n"; + else + combiner += " colorOut = lighting * patternTex2.Sample(samp, vtf.uvs[1]) + vtf.color;\n"; + } + else + { + combiner += " colorOut = vtf.color;\n"; + } + + if (info.m_hasColorTex) + { + if (info.m_hasEnvBumpMap) + { + // Make previous stage indirect, mtx0 + combiner += hecl::Format(" float2 indUvs = (envBumpMap.Sample(samp, vtf.uvs[%d]).ra - float2(0.5, 0.5)) *\n" + " float2(fog.indScale, -fog.indScale);\n", envBumpMapUv); + combiner += " colorOut += colorTex.Sample(samp, indUvs + vtf.uvs[2]) * lighting;\n"; + } + else + { + combiner += " colorOut += colorTex.Sample(samp, vtf.uvs[2]) * lighting;\n"; + } + } + + break; + + case EFluidType::Lava: + // 0: Tex0TCG, Tex0, GX_COLOR0A0 + // ZERO, TEX, KONST, RAS + // Output reg prev + // KColor 0 + + // 1: Tex1TCG, Tex1, GX_COLOR0A0 + // ZERO, TEX, PREV, RAS + // Output reg prev + + // 2: Tex2TCG, Tex2, NULL + // ZERO, TEX, ONE, PREV + // Output reg prev + + // (Tex0 * kColor0 + VertColor) * Tex1 + VertColor + Tex2 + if (info.m_hasPatternTex2) + { + if (info.m_hasPatternTex1) + combiner += " colorOut = (patternTex1.Sample(samp, vtf.uvs[0]) * kColor0 + vtf.color) *\n" + " patternTex2.Sample(samp, vtf.uvs[1]) + vtf.color;\n"; + else + combiner += " colorOut = vtf.color * patternTex2.Sample(samp, vtf.uvs[1]) + vtf.color;\n"; + } + else + { + combiner += " colorOut = vtf.color;\n"; + } + + if (info.m_hasColorTex) + combiner += " colorOut += colorTex.Sample(samp, vtf.uvs[2]);\n"; + + if (info.m_hasBumpMap) + { + // 3: bumpMapTCG, bumpMap, NULL + // ZERO, TEX, ONE, HALF + // Output reg 0, no clamp, no bias + + // 4: bumpMapTCG2, bumpMap, NULL + // ZERO, TEX, ONE, C0 + // Output reg 0, subtract, clamp, no bias + + combiner += " float3 lightVec = lights[3].pos.xyz - vtf.mvPos.xyz;\n" + " float lx = dot(vtf.mvTangent.xyz, lightVec);\n" + " float ly = dot(vtf.mvBinorm.xyz, lightVec);\n"; + combiner += hecl::Format(" float4 emboss1 = bumpMap.Sample(samp, vtf.uvs[%d]) + float4(0.5);\n" + " float4 emboss2 = bumpMap.Sample(samp, vtf.uvs[%d] + float2(lx, ly));\n", + bumpMapUv, bumpMapUv); + + // 5: NULL, NULL, NULL + // ZERO, PREV, C0, ZERO + // Output reg prev, scale 2, clamp + + // colorOut * clamp(emboss1 + 0.5 - emboss2, 0.0, 1.0) * 2.0 + combiner += "colorOut *= clamp((emboss1 + float4(0.5) - emboss2) * float4(2.0), float4(0.0), float4(1.0));\n"; + } + + break; + + case EFluidType::ThickLava: + // 0: Tex0TCG, Tex0, GX_COLOR0A0 + // ZERO, TEX, KONST, RAS + // Output reg prev + // KColor 0 + + // 1: Tex1TCG, Tex1, GX_COLOR0A0 + // ZERO, TEX, PREV, RAS + // Output reg prev + + // 2: Tex2TCG, Tex2, NULL + // ZERO, TEX, ONE, PREV + // Output reg prev + + // (Tex0 * kColor0 + VertColor) * Tex1 + VertColor + Tex2 + if (info.m_hasPatternTex2) + { + if (info.m_hasPatternTex1) + combiner += " colorOut = (patternTex1.Sample(samp, vtf.uvs[0]) * kColor0 + vtf.color) *\n" + " patternTex2.Sample(samp, vtf.uvs[1]) + vtf.color;\n"; + else + combiner += " colorOut = vtf.color * patternTex2.Sample(samp, vtf.uvs[1]) + vtf.color;\n"; + } + else + { + combiner += " colorOut = vtf.color;\n"; + } + + if (info.m_hasColorTex) + combiner += " colorOut += colorTex.Sample(samp, vtf.uvs[2]);\n"; + + if (info.m_hasBumpMap) + { + // 3: bumpMapTCG, bumpMap, NULL + // ZERO, TEX, PREV, ZERO + // Output reg prev, scale 2 + combiner += hecl::Format(" float4 emboss1 = bumpMap.Sample(samp, vtf.uvs[%d]) + float4(0.5);\n", bumpMapUv); + combiner += "colorOut *= emboss1 * float4(2.0);\n"; + } + + break; + } + + combiner += " colorOut.a = kColor0.a;\n"; + + char *finalFS; + asprintf(&finalFS, FS, textures.c_str(), combiner.c_str()); + std::string ret(finalFS); + free(finalFS); + return ret; +} + +static std::string _BuildAdditionalTCGs(const SFluidPlaneShaderInfo& info) +{ + std::string additionalTCGs; + int nextTCG = 3; + int nextMtx = 4; + + if (info.m_hasBumpMap) + { + additionalTCGs += hecl::Format(" vtf.uvs[%d] = (texMtxs[0] * pos).xy;\n", nextTCG++); + } + if (info.m_hasEnvBumpMap) + { + additionalTCGs += hecl::Format(" vtf.uvs[%d] = (texMtxs[3] * vec4(normalIn.xyz, 1.0)).xy;\n", nextTCG++); + } + if (info.m_hasEnvMap) + { + additionalTCGs += hecl::Format(" vtf.uvs[%d] = (texMtxs[%d] * pos).xy;\n", nextTCG++, nextMtx++); + } + if (info.m_hasLightmap) + { + additionalTCGs += hecl::Format(" vtf.uvs[%d] = (texMtxs[%d] * pos).xy;\n", nextTCG, nextMtx); + } + + return additionalTCGs; +} + +static std::string _BuildVS(const SFluidPlaneShaderInfo& info, bool tessellation) +{ + if (tessellation) + return TessVS; + + std::string additionalTCGs = _BuildAdditionalTCGs(info); + + char *finalVSs; + asprintf(&finalVSs, VS, additionalTCGs.c_str()); + std::string ret(finalVSs); + free(finalVSs); + return ret; +} +template <> +std::string StageObject_CFluidPlaneShader::BuildShader + (const SFluidPlaneShaderInfo& in, bool tessellation) +{ + return _BuildVS(in, tessellation); +} +template <> +std::string StageObject_CFluidPlaneShader::BuildShader + (const SFluidPlaneShaderInfo& in, bool tessellation) +{ + return _BuildVS(in, tessellation); +} +template <> +std::string StageObject_CFluidPlaneShader::BuildShader + (const SFluidPlaneShaderInfo& in, bool tessellation) +{ + return _BuildVS(in, tessellation); +} + +template <> +std::string StageObject_CFluidPlaneShader::BuildShader + (const SFluidPlaneShaderInfo& in, bool tessellation) +{ + return _BuildFS(in); +} +template <> +std::string StageObject_CFluidPlaneShader::BuildShader + (const SFluidPlaneShaderInfo& in, bool tessellation) +{ + return _BuildFS(in); +} +template <> +std::string StageObject_CFluidPlaneShader::BuildShader + (const SFluidPlaneShaderInfo& in, bool tessellation) +{ + return _BuildFS(in); +} + +template <> +std::string StageObject_CFluidPlaneShader::BuildShader + (const SFluidPlaneShaderInfo& in, bool tessellation) +{ + return TessCS; +} +template <> +std::string StageObject_CFluidPlaneShader::BuildShader + (const SFluidPlaneShaderInfo& in, bool tessellation) +{ + return TessCS; +} +template <> +std::string StageObject_CFluidPlaneShader::BuildShader + (const SFluidPlaneShaderInfo& in, bool tessellation) +{ + return TessCS; +} + +static std::string BuildES(const SFluidPlaneShaderInfo& info) +{ + int nextTex = 0; + if (info.m_hasPatternTex1) + nextTex++; + if (info.m_hasPatternTex2) + nextTex++; + if (info.m_hasColorTex) + nextTex++; + if (info.m_hasBumpMap) + nextTex++; + if (info.m_hasEnvMap) + nextTex++; + if (info.m_hasEnvBumpMap) + nextTex++; + if (info.m_hasLightmap) + nextTex++; + + std::string additionalTCGs = _BuildAdditionalTCGs(info); + + char *finalESs; + asprintf(&finalESs, TessES, nextTex, additionalTCGs.c_str()); + std::string ret(finalESs); + free(finalESs); + + return ret; +} +template <> +std::string StageObject_CFluidPlaneShader::BuildShader + (const SFluidPlaneShaderInfo& in, bool tessellation) +{ + return BuildES(in); +} +template <> +std::string StageObject_CFluidPlaneShader::BuildShader + (const SFluidPlaneShaderInfo& in, bool tessellation) +{ + return BuildES(in); +} +template <> +std::string StageObject_CFluidPlaneShader::BuildShader + (const SFluidPlaneShaderInfo& in, bool tessellation) +{ + return BuildES(in); +} diff --git a/Shaders/shader_CFluidPlaneShaderMetal.cpp b/Shaders/shader_CFluidPlaneShaderMetal.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/amuse b/amuse index 81f0a9156..4c7971f53 160000 --- a/amuse +++ b/amuse @@ -1 +1 @@ -Subproject commit 81f0a91569ba8218abaa154a5aa2cb9d8b61e528 +Subproject commit 4c7971f53a0f5c8fe471536d7e5ebc2fe2f0c601 diff --git a/gmm/gmm_def.h b/gmm/gmm_def.h index 603c57b69..47041138e 100644 --- a/gmm/gmm_def.h +++ b/gmm/gmm_def.h @@ -966,7 +966,7 @@ namespace gmm { tol = numeric_limits::epsilon(); else { int i=int(sizeof(T)/4); while(i-- > 0) tol*=T(1E-8); - GMM_WARNING1("The numeric type " << typeid(T).name() + GMM_WARNING1("The numeric type " /*<< typeid(T).name()*/ << " has no numeric_limits defined !!\n" << "Taking " << tol << " as default tolerance"); } @@ -984,7 +984,7 @@ namespace gmm { mi = std::numeric_limits::min(); else { mi = T(0); - GMM_WARNING1("The numeric type " << typeid(T).name() + GMM_WARNING1("The numeric type " /*<< typeid(T).name()*/ << " has no numeric_limits defined !!\n" << "Taking 0 as default minimum"); } @@ -1002,7 +1002,7 @@ namespace gmm { mi = std::numeric_limits::max(); else { mi = T(1); - GMM_WARNING1("The numeric type " << typeid(T).name() + GMM_WARNING1("The numeric type " /*<< typeid(T).name()*/ << " has no numeric_limits defined !!\n" << "Taking 1 as default maximum !"); } diff --git a/hecl b/hecl index dea2a40c2..0ca2a8fa8 160000 --- a/hecl +++ b/hecl @@ -1 +1 @@ -Subproject commit dea2a40c245c167af73ac8f716cb9a541252765b +Subproject commit 0ca2a8fa8c25a0d3c5e763f474feadf470371280 diff --git a/nod b/nod index 1ad101897..eb6aa3056 160000 --- a/nod +++ b/nod @@ -1 +1 @@ -Subproject commit 1ad101897c865524a9129c2afa665fa0ab2db3cc +Subproject commit eb6aa30563e262167f173c6450b67e39062157ca diff --git a/specter b/specter index 550955b07..fafcfaa50 160000 --- a/specter +++ b/specter @@ -1 +1 @@ -Subproject commit 550955b07c86724ba27000ed230713f8e4f2f711 +Subproject commit fafcfaa50aef8ac2231bf79335cd8a2871561dea