From a6477c635da76225c91f0f78f97715b2750ef3cc Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Thu, 21 Jul 2016 16:32:23 -1000 Subject: [PATCH] Lots of initial CThermalColdFilter implementation --- DataSpec/DNACommon/TXTR.cpp | 2 +- Runtime/Graphics/CBooRenderer.cpp | 5 + Runtime/Graphics/CBooRenderer.hpp | 26 +++- Runtime/Graphics/CLineRenderer.cpp | 76 ---------- Runtime/Graphics/CMakeLists.txt | 12 +- Runtime/Graphics/CModelBoo.cpp | 64 ++------ Runtime/Graphics/CTextureBoo.cpp | 2 +- Runtime/Graphics/IRenderer.hpp | 1 + Runtime/Graphics/IWeaponRenderer.cpp | 12 ++ Runtime/Graphics/IWeaponRenderer.hpp | 23 +++ .../Graphics/Shaders/CLineRendererShaders.cpp | 82 +++++++++++ Runtime/Graphics/Shaders/CModelShaders.cpp | 40 +++++ Runtime/Graphics/Shaders/CModelShaders.hpp | 2 + .../Graphics/Shaders/CThermalColdFilter.cpp | 66 +++++++++ .../Graphics/Shaders/CThermalColdFilter.hpp | 50 +++++++ .../Shaders/CThermalColdFilterGLSL.cpp | 138 ++++++++++++++++++ .../Shaders/CThermalColdFilterHLSL.cpp | 13 ++ .../Shaders/CThermalColdFilterMetal.cpp | 13 ++ .../Graphics/Shaders/CThermalHotFilter.cpp | 0 .../Graphics/Shaders/CXrayOutlineFilter.cpp | 0 Runtime/Graphics/Shaders/TFilterDecl.hpp | 17 +++ Runtime/Graphics/Shaders/TFilterShader.hpp | 99 +++++++++++++ 22 files changed, 607 insertions(+), 136 deletions(-) create mode 100644 Runtime/Graphics/IWeaponRenderer.cpp create mode 100644 Runtime/Graphics/IWeaponRenderer.hpp create mode 100644 Runtime/Graphics/Shaders/CLineRendererShaders.cpp create mode 100644 Runtime/Graphics/Shaders/CModelShaders.cpp create mode 100644 Runtime/Graphics/Shaders/CThermalColdFilter.cpp create mode 100644 Runtime/Graphics/Shaders/CThermalHotFilter.cpp create mode 100644 Runtime/Graphics/Shaders/CXrayOutlineFilter.cpp create mode 100644 Runtime/Graphics/Shaders/TFilterDecl.hpp create mode 100644 Runtime/Graphics/Shaders/TFilterShader.hpp diff --git a/DataSpec/DNACommon/TXTR.cpp b/DataSpec/DNACommon/TXTR.cpp index 0c1c238a0..70ab2347b 100644 --- a/DataSpec/DNACommon/TXTR.cpp +++ b/DataSpec/DNACommon/TXTR.cpp @@ -63,7 +63,7 @@ static size_t ComputeMippedTexelCount(unsigned inWidth, unsigned inHeight) return ret; } -/* GX uses this upsampling technique with downsampled texture formats */ +/* GX uses this upsampling technique to extract full 8-bit range */ static inline uint8_t Convert3To8(uint8_t v) { /* Swizzle bits: 00000123 -> 12312312 */ diff --git a/Runtime/Graphics/CBooRenderer.cpp b/Runtime/Graphics/CBooRenderer.cpp index f1da3ee36..1b056b5fd 100644 --- a/Runtime/Graphics/CBooRenderer.cpp +++ b/Runtime/Graphics/CBooRenderer.cpp @@ -3,6 +3,11 @@ namespace urde { +CBooRenderer::CBooRenderer(IObjectStore& store, IFactory& resFac) +: x8_factory(resFac), xc_store(store) +{ +} + void CBooRenderer::AddStaticGeometry(const std::vector&, const CAreaOctTree*, int) { } diff --git a/Runtime/Graphics/CBooRenderer.hpp b/Runtime/Graphics/CBooRenderer.hpp index c9e1da1e4..fe91d60c6 100644 --- a/Runtime/Graphics/CBooRenderer.hpp +++ b/Runtime/Graphics/CBooRenderer.hpp @@ -2,6 +2,7 @@ #define __URDE_CBOORENDERER_HPP__ #include "IRenderer.hpp" +#include "CDrawable.hpp" namespace urde { @@ -9,12 +10,29 @@ class IObjectStore; class CMemorySys; class IFactory; -class CBooRenderer : public IRenderer +class Buckets { public: - CBooRenderer(IObjectStore&, IFactory&) - { - } + static void Clear(); + static void Sort(); + static void InsertPlaneObject(float, float, const zeus::CAABox&, bool, const zeus::CPlane&, + bool, EDrawableType, const void*); + static void Insert(const zeus::CVector3f&, const zeus::CAABox&, EDrawableType, const void*, + const zeus::CPlane&, unsigned short); + static void Shutdown(); + static void Init(); +}; + +class CBooRenderer : public IRenderer +{ + IFactory& x8_factory; + IObjectStore& xc_store; + // CFont x10_fnt; + u32 x18_ = 0; + std::list x1c_; + zeus::CFrustum x44_frustumPlanes; +public: + CBooRenderer(IObjectStore& store, IFactory& resFac); void AddStaticGeometry(const std::vector&, const CAreaOctTree*, int); void RemoveStaticGeometry(const std::vector&); diff --git a/Runtime/Graphics/CLineRenderer.cpp b/Runtime/Graphics/CLineRenderer.cpp index e7f1b67c1..5a958418d 100644 --- a/Runtime/Graphics/CLineRenderer.cpp +++ b/Runtime/Graphics/CLineRenderer.cpp @@ -5,63 +5,11 @@ namespace urde { logvisor::Module LineRendererLog("urde::CLineRenderer"); -boo::IShaderPipeline* CLineRendererShaders::m_texAlpha = nullptr; -boo::IShaderPipeline* CLineRendererShaders::m_texAdditive = nullptr; - -boo::IShaderPipeline* CLineRendererShaders::m_noTexAlpha = nullptr; -boo::IShaderPipeline* CLineRendererShaders::m_noTexAdditive = nullptr; - -boo::IVertexFormat* CLineRendererShaders::m_texVtxFmt = nullptr; -boo::IVertexFormat* CLineRendererShaders::m_noTexVtxFmt = nullptr; - -std::unique_ptr CLineRendererShaders::m_bindFactory; -boo::GraphicsDataToken CLineRendererShaders::m_gfxToken; - -void CLineRendererShaders::Initialize() -{ - if (!CGraphics::g_BooFactory) - return; - - m_gfxToken = CGraphics::CommitResources( - [&](boo::IGraphicsDataFactory::Context& ctx) -> bool - { - switch (ctx.platform()) - { - case boo::IGraphicsDataFactory::Platform::OGL: - m_bindFactory.reset(Initialize(static_cast(ctx))); - break; -#if _WIN32 - case boo::IGraphicsDataFactory::Platform::D3D11: - case boo::IGraphicsDataFactory::Platform::D3D12: - 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; - } - return true; - }); -} - void CLineRenderer::Initialize() { CLineRendererShaders::Initialize(); } -void CLineRendererShaders::Shutdown() -{ - m_gfxToken.doDestroy(); -} - void CLineRenderer::Shutdown() { CLineRendererShaders::Shutdown(); @@ -85,30 +33,6 @@ struct SDrawUniform zeus::CColor moduColor; }; -void CLineRendererShaders::BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, - CLineRenderer& renderer, - boo::ITexture* texture, - bool additive) -{ - boo::IShaderPipeline* pipeline = nullptr; - if (texture) - { - if (additive) - pipeline = m_texAdditive; - else - pipeline = m_texAlpha; - } - else - { - if (additive) - pipeline = m_noTexAdditive; - else - pipeline = m_noTexAlpha; - } - - m_bindFactory->BuildShaderDataBinding(ctx, renderer, pipeline, texture); -} - CLineRenderer::CLineRenderer(EPrimitiveMode mode, u32 maxVerts, boo::ITexture* texture, bool additive) : m_mode(mode), m_maxVerts(maxVerts) { diff --git a/Runtime/Graphics/CMakeLists.txt b/Runtime/Graphics/CMakeLists.txt index e25c88a0c..34d5e4286 100644 --- a/Runtime/Graphics/CMakeLists.txt +++ b/Runtime/Graphics/CMakeLists.txt @@ -6,6 +6,7 @@ endif() set(GRAPHICS_SOURCES IRenderer.hpp + IWeaponRenderer.hpp IWeaponRenderer.cpp CBooRenderer.hpp CBooRenderer.cpp CDrawable.hpp CDrawable.cpp CDrawablePlaneObject.hpp CDrawablePlaneObject.cpp @@ -20,11 +21,12 @@ set(GRAPHICS_SOURCES CFrustumPlanes.hpp CFrustumPlanes.cpp CGraphicsPalette.hpp CGraphicsPalette.cpp CGraphics.hpp CGraphics.cpp - Shaders/CLineRendererShaders.hpp Shaders/CLineRendererShadersGLSL.cpp - Shaders/CModelShaders.hpp Shaders/CModelShadersGLSL.cpp - Shaders/CXrayOutlineFilter.hpp Shaders/CXrayOutlineFilterGLSL.cpp - Shaders/CThermalColdFilter.hpp Shaders/CThermalColdFilterGLSL.cpp - Shaders/CThermalHotFilter.hpp Shaders/CThermalHotFilterGLSL.cpp + Shaders/TFilterShader.hpp Shaders/TFilterDecl.hpp + Shaders/CLineRendererShaders.hpp Shaders/CLineRendererShaders.cpp Shaders/CLineRendererShadersGLSL.cpp + Shaders/CModelShaders.hpp Shaders/CModelShaders.cpp Shaders/CModelShadersGLSL.cpp + Shaders/CXrayOutlineFilter.hpp Shaders/CXrayOutlineFilter.cpp Shaders/CXrayOutlineFilterGLSL.cpp + Shaders/CThermalColdFilter.hpp Shaders/CThermalColdFilter.cpp Shaders/CThermalColdFilterGLSL.cpp + Shaders/CThermalHotFilter.hpp Shaders/CThermalHotFilter.cpp Shaders/CThermalHotFilterGLSL.cpp ${PLAT_SRCS}) runtime_add_list(Graphics GRAPHICS_SOURCES) diff --git a/Runtime/Graphics/CModelBoo.cpp b/Runtime/Graphics/CModelBoo.cpp index 45786e588..53ef1e28a 100644 --- a/Runtime/Graphics/CModelBoo.cpp +++ b/Runtime/Graphics/CModelBoo.cpp @@ -12,8 +12,6 @@ namespace urde static logvisor::Module Log("urde::CModelBoo"); bool CBooModel::g_DrawingOccluders = false; -static rstl::optional_object g_ModelShaders; - CBooModel::CBooModel(std::vector* surfaces, SShader& shader, boo::IVertexFormat* vtxFmt, boo::IGraphicsBufferS* vbo, boo::IGraphicsBufferS* ibo, size_t weightVecCount, size_t skinBankCount, const zeus::CAABox& aabb) @@ -572,25 +570,25 @@ CModel::CModel(std::unique_ptr&& in, u32 /* dataLen */, IObjectStore* stor m_gfxToken = CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) -> bool { - m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, vboData, hmdlMeta.vertStride, hmdlMeta.vertCount); - m_ibo = ctx.newStaticBuffer(boo::BufferUse::Index, iboData, 4, hmdlMeta.indexCount); - m_vtxFmt = hecl::Runtime::HMDLData::NewVertexFormat(ctx, hmdlMeta, m_vbo, m_ibo); + m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, vboData, hmdlMeta.vertStride, hmdlMeta.vertCount); + m_ibo = ctx.newStaticBuffer(boo::BufferUse::Index, iboData, 4, hmdlMeta.indexCount); + m_vtxFmt = hecl::Runtime::HMDLData::NewVertexFormat(ctx, hmdlMeta, m_vbo, m_ibo); - for (CBooModel::SShader& matSet : x18_matSets) - { + for (CBooModel::SShader& matSet : x18_matSets) + { matSet.m_shaders.reserve(matSet.m_matSet.materials.size()); for (const MaterialSet::Material& mat : matSet.m_matSet.materials) - { - hecl::Runtime::ShaderTag tag(mat.heclIr, - hmdlMeta.colorCount, hmdlMeta.uvCount, hmdlMeta.weightCount, - 0, mat.uvAnims.size(), boo::Primitive(hmdlMeta.topology), - true, true, true); - matSet.m_shaders.push_back(g_ModelShaders->buildExtendedShader(tag, mat.heclIr, "CMDL", ctx)); -} -} + { + hecl::Runtime::ShaderTag tag(mat.heclIr, + hmdlMeta.colorCount, hmdlMeta.uvCount, hmdlMeta.weightCount, + 0, mat.uvAnims.size(), boo::Primitive(hmdlMeta.topology), + true, true, true); + matSet.m_shaders.push_back(CModelShaders::g_ModelShaders->buildExtendedShader(tag, mat.heclIr, "CMDL", ctx)); + } + } - return true; -}); + return true; + }); u32 surfCount = hecl::SBig(*reinterpret_cast(surfInfo)); x8_surfaces.reserve(surfCount); @@ -665,38 +663,6 @@ bool CModel::IsLoaded(int shaderIdx) const return loaded; } -hecl::Runtime::ShaderCacheExtensions -CModelShaders::GetShaderExtensions(boo::IGraphicsDataFactory::Platform plat) -{ - switch (plat) - { - case boo::IGraphicsDataFactory::Platform::OGL: - case boo::IGraphicsDataFactory::Platform::Vulkan: - return GetShaderExtensionsGLSL(plat); -#if _WIN32 - case boo::IGraphicsDataFactory::Platform::D3D11: - case boo::IGraphicsDataFactory::Platform::D3D12: - return GetShaderExtensionsHLSL(plat); -#endif -#if BOO_HAS_METAL - case boo::IGraphicsDataFactory::Platform::Metal: - return GetShaderExtensionsMetal(plat); -#endif - default: - return {boo::IGraphicsDataFactory::Platform::Null}; - } -} - -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) -{ - g_ModelShaders.emplace(storeMgr, gfxFactory); -} - CFactoryFnReturn FModelFactory(const urde::SObjectTag& tag, std::unique_ptr&& in, u32 len, const urde::CVParamTransfer& vparms) diff --git a/Runtime/Graphics/CTextureBoo.cpp b/Runtime/Graphics/CTextureBoo.cpp index ef6203831..e700b62ad 100644 --- a/Runtime/Graphics/CTextureBoo.cpp +++ b/Runtime/Graphics/CTextureBoo.cpp @@ -7,7 +7,7 @@ namespace urde { static logvisor::Module Log("urde::CTextureBoo"); -/* GX uses this upsampling technique to prevent banding on downsampled texture formats */ +/* GX uses this upsampling technique to extract full 8-bit range */ static inline uint8_t Convert3To8(uint8_t v) { /* Swizzle bits: 00000123 -> 12312312 */ diff --git a/Runtime/Graphics/IRenderer.hpp b/Runtime/Graphics/IRenderer.hpp index 88d9d4e7d..99ac403c5 100644 --- a/Runtime/Graphics/IRenderer.hpp +++ b/Runtime/Graphics/IRenderer.hpp @@ -37,6 +37,7 @@ public: { }; + virtual ~IRenderer() = default; virtual void AddStaticGeometry(const std::vector&, const CAreaOctTree*, int)=0; virtual void RemoveStaticGeometry(const std::vector&)=0; virtual void DrawUnsortedGeometry(const std::vector&, int, unsigned int, unsigned int)=0; diff --git a/Runtime/Graphics/IWeaponRenderer.cpp b/Runtime/Graphics/IWeaponRenderer.cpp new file mode 100644 index 000000000..763e484c3 --- /dev/null +++ b/Runtime/Graphics/IWeaponRenderer.cpp @@ -0,0 +1,12 @@ +#include "IWeaponRenderer.hpp" +#include "Particle/CParticleGen.hpp" + +namespace urde +{ + +void CDefaultWeaponRenderer::AddParticleGen(const CParticleGen& gen) +{ + ((CParticleGen&)gen).Render(); +} + +} diff --git a/Runtime/Graphics/IWeaponRenderer.hpp b/Runtime/Graphics/IWeaponRenderer.hpp new file mode 100644 index 000000000..3f414ef4a --- /dev/null +++ b/Runtime/Graphics/IWeaponRenderer.hpp @@ -0,0 +1,23 @@ +#ifndef __URDE_IWEAPONRENDERER_HPP__ +#define __URDE_IWEAPONRENDERER_HPP__ + +namespace urde +{ +class CParticleGen; + +class IWeaponRenderer +{ +public: + virtual ~IWeaponRenderer() = default; + virtual void AddParticleGen(const CParticleGen&); +}; + +class CDefaultWeaponRenderer : public IWeaponRenderer +{ +public: + void AddParticleGen(const CParticleGen&); +}; + +} + +#endif // __URDE_IWEAPONRENDERER_HPP__ diff --git a/Runtime/Graphics/Shaders/CLineRendererShaders.cpp b/Runtime/Graphics/Shaders/CLineRendererShaders.cpp new file mode 100644 index 000000000..756d74b2b --- /dev/null +++ b/Runtime/Graphics/Shaders/CLineRendererShaders.cpp @@ -0,0 +1,82 @@ +#include "CLineRendererShaders.hpp" + +namespace urde +{ + +boo::IShaderPipeline* CLineRendererShaders::m_texAlpha = nullptr; +boo::IShaderPipeline* CLineRendererShaders::m_texAdditive = nullptr; + +boo::IShaderPipeline* CLineRendererShaders::m_noTexAlpha = nullptr; +boo::IShaderPipeline* CLineRendererShaders::m_noTexAdditive = nullptr; + +boo::IVertexFormat* CLineRendererShaders::m_texVtxFmt = nullptr; +boo::IVertexFormat* CLineRendererShaders::m_noTexVtxFmt = nullptr; + +std::unique_ptr CLineRendererShaders::m_bindFactory; +boo::GraphicsDataToken CLineRendererShaders::m_gfxToken; + +void CLineRendererShaders::Initialize() +{ + if (!CGraphics::g_BooFactory) + return; + + m_gfxToken = CGraphics::CommitResources( + [&](boo::IGraphicsDataFactory::Context& ctx) -> bool + { + switch (ctx.platform()) + { + case boo::IGraphicsDataFactory::Platform::OGL: + m_bindFactory.reset(Initialize(static_cast(ctx))); + break; +#if _WIN32 + case boo::IGraphicsDataFactory::Platform::D3D11: + case boo::IGraphicsDataFactory::Platform::D3D12: + 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; + } + return true; + }); +} + +void CLineRendererShaders::Shutdown() +{ + m_gfxToken.doDestroy(); +} + +void CLineRendererShaders::BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, + CLineRenderer& renderer, + boo::ITexture* texture, + bool additive) +{ + boo::IShaderPipeline* pipeline = nullptr; + if (texture) + { + if (additive) + pipeline = m_texAdditive; + else + pipeline = m_texAlpha; + } + else + { + if (additive) + pipeline = m_noTexAdditive; + else + pipeline = m_noTexAlpha; + } + + m_bindFactory->BuildShaderDataBinding(ctx, renderer, pipeline, texture); +} + +} diff --git a/Runtime/Graphics/Shaders/CModelShaders.cpp b/Runtime/Graphics/Shaders/CModelShaders.cpp new file mode 100644 index 000000000..f3387fd53 --- /dev/null +++ b/Runtime/Graphics/Shaders/CModelShaders.cpp @@ -0,0 +1,40 @@ +#include "CModelShaders.hpp" + +namespace urde +{ + +std::experimental::optional CModelShaders::g_ModelShaders; + +hecl::Runtime::ShaderCacheExtensions +CModelShaders::GetShaderExtensions(boo::IGraphicsDataFactory::Platform plat) +{ + switch (plat) + { + case boo::IGraphicsDataFactory::Platform::OGL: + case boo::IGraphicsDataFactory::Platform::Vulkan: + return GetShaderExtensionsGLSL(plat); +#if _WIN32 + case boo::IGraphicsDataFactory::Platform::D3D11: + case boo::IGraphicsDataFactory::Platform::D3D12: + return GetShaderExtensionsHLSL(plat); +#endif +#if BOO_HAS_METAL + case boo::IGraphicsDataFactory::Platform::Metal: + return GetShaderExtensionsMetal(plat); +#endif + default: + return {boo::IGraphicsDataFactory::Platform::Null}; + } +} + +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) +{ + g_ModelShaders.emplace(storeMgr, gfxFactory); +} + +} diff --git a/Runtime/Graphics/Shaders/CModelShaders.hpp b/Runtime/Graphics/Shaders/CModelShaders.hpp index d3aad3977..35bf082c7 100644 --- a/Runtime/Graphics/Shaders/CModelShaders.hpp +++ b/Runtime/Graphics/Shaders/CModelShaders.hpp @@ -13,7 +13,9 @@ namespace urde class CModelShaders { + friend class CModel; hecl::Runtime::ShaderCacheManager m_shaderCache; + static std::experimental::optional g_ModelShaders; 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); diff --git a/Runtime/Graphics/Shaders/CThermalColdFilter.cpp b/Runtime/Graphics/Shaders/CThermalColdFilter.cpp new file mode 100644 index 000000000..1c3d7a34d --- /dev/null +++ b/Runtime/Graphics/Shaders/CThermalColdFilter.cpp @@ -0,0 +1,66 @@ +#include "CThermalColdFilter.hpp" +#include "Graphics/CGraphics.hpp" + +namespace urde +{ + +CThermalColdFilter::CThermalColdFilter() +{ + m_token = CGraphics::g_BooFactory->commitTransaction([&](boo::IGraphicsDataFactory::Context& ctx) -> bool + { + m_shiftTex = ctx.newDynamicTexture(8, 8, boo::TextureFormat::RGBA8); + m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, 32, 1); + m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); + m_dataBind = TFilterShader::BuildShaderDataBinding(ctx, *this); + return true; + }); + + struct Vert + { + zeus::CVector2f m_pos; + zeus::CVector2f m_uv; + } verts[4] = + { + {{-1.0, -1.0}, {0.0, 0.0}}, + {{-1.0, 1.0}, {0.0, 1.0}}, + {{ 1.0, 1.0}, {1.0, 1.0}}, + {{ 1.0, -1.0}, {1.0, 0.0}} + }; + m_vbo->load(verts, sizeof(verts)); + + setShift(0); +} + +void CThermalColdFilter::setShift(unsigned shift) +{ + shift = std::min(shift, 31u); + for (unsigned y=0 ; y<4 ; ++y) + { + unsigned bx = y * 8; + for (unsigned x=0 ; x<8 ; ++x) + { + unsigned px = bx + x; + unsigned spx = px + shift; + unsigned ny = spx / 8; + if (ny > 3) + ny = 3; + unsigned nx = spx % 8; + m_shiftTexture[y][x][0] = nx / 7.f; + m_shiftTexture[y][x][1] = ny / 3.f; + } + } + m_shiftTex->load(m_shiftTexture[0][0], sizeof(m_shiftTexture)); +} + +void CThermalColdFilter::draw() +{ + m_uniform.m_shiftTexMtx[0][0] = 80.f * CGraphics::g_ProjAspect; + m_uniform.m_shiftTexMtx[1][1] = 120.f; + m_uniBuf->load(&m_uniform, sizeof(m_uniform)); + CGraphics::g_BooMainCommandQueue->setShaderDataBinding(m_dataBind); + CGraphics::g_BooMainCommandQueue->draw(0, 4); +} + +URDE_SPECIALIZE_FILTER(CThermalColdFilter) + +} diff --git a/Runtime/Graphics/Shaders/CThermalColdFilter.hpp b/Runtime/Graphics/Shaders/CThermalColdFilter.hpp index e69de29bb..64ae00243 100644 --- a/Runtime/Graphics/Shaders/CThermalColdFilter.hpp +++ b/Runtime/Graphics/Shaders/CThermalColdFilter.hpp @@ -0,0 +1,50 @@ +#ifndef __URDE_CTHERMALCOLDFILTER_HPP__ +#define __URDE_CTHERMALCOLDFILTER_HPP__ + +#include "TFilterShader.hpp" +#include "zeus/CMatrix4f.hpp" +#include "zeus/CColor.hpp" + +namespace urde +{ + +class CThermalColdFilter +{ + friend struct CThermalColdFilterGLDataBindingFactory; + friend struct CThermalColdFilterVulkanDataBindingFactory; + + struct Uniform + { + zeus::CMatrix4f m_shiftTexMtx; + zeus::CMatrix4f m_indMtx; + zeus::CColor m_colorRegs[3]; + }; + u8 m_shiftTexture[4][8][4] = {}; + boo::GraphicsDataToken m_token; + boo::ITextureD* m_shiftTex = nullptr; + boo::IGraphicsBufferD* m_vbo; + boo::IGraphicsBufferD* m_uniBuf; + boo::IShaderDataBinding* m_dataBind = nullptr; + Uniform m_uniform; + +public: + CThermalColdFilter(); + void setShift(unsigned shift); + 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 setScale(float scale) + { + scale = 0.1f * (1.f - scale); + m_uniform.m_indMtx[0][0] = scale; + m_uniform.m_indMtx[1][1] = scale; + } + void draw(); + + using _CLS = CThermalColdFilter; +#include "TFilterDecl.hpp" +}; + +} + +#endif // __URDE_CTHERMALCOLDFILTER_HPP__ diff --git a/Runtime/Graphics/Shaders/CThermalColdFilterGLSL.cpp b/Runtime/Graphics/Shaders/CThermalColdFilterGLSL.cpp index e69de29bb..d5ac4abe8 100644 --- a/Runtime/Graphics/Shaders/CThermalColdFilterGLSL.cpp +++ b/Runtime/Graphics/Shaders/CThermalColdFilterGLSL.cpp @@ -0,0 +1,138 @@ +#include "CThermalColdFilter.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 uvIn;\n" +"\n" +"UBINDING0 uniform ThermalColdUniform\n" +"{\n" +" mat4 shiftMtx;\n" +" mat4 indMtx;\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" +"};\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 = shiftMtx * uvIn;\n" +" gl_Position = FLIPFROMGL(posIn);\n" +"}\n"; + +static const char* FS_GLSL_TEX = +"#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 shiftDelta;\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 shiftCoord = vtf.sceneUv + texture(shiftTex, vtf.shiftUv).xy;\n" +" float shiftScene0 = dot(texture(sceneTex, shiftCoord - vec2(0.5)), kRGBToYPrime);\n" +" float shiftScene1 = dot(texture(sceneTex, shiftCoord - vec2(0.5, 0.4984375)), kRGBToYPrime);\n" +" vec2 indCoord = (indMtx * vec3(shiftScene0, shiftScene1, 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_FILTER(CThermalColdFilter) + +struct CThermalColdFilterGLDataBindingFactory : TFilterShader::IDataBindingFactory +{ + boo::IShaderDataBinding* BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, CThermalColdFilter& filter) + { + boo::GLDataFactory::Context& cctx = static_cast(ctx); + + const boo::VertexElementDescriptor VtxVmt[] = + { + {filter.m_vbo, nullptr, boo::VertexSemantic::Position4}, + {filter.m_vbo, nullptr, boo::VertexSemantic::UV4} + }; + boo::IGraphicsBuffer* bufs[] = {filter.m_uniBuf}; + boo::PipelineStage stages[] = {boo::PipelineStage::Vertex}; + boo::ITexture* texs[] = {CGraphics::g_SpareTexture, filter.m_shiftTex}; + return cctx.newShaderDataBinding(TFilterShader::m_pipeline, + ctx.newVertexFormat(3, VtxVmt), filter.m_vbo, nullptr, nullptr, + 1, bufs, stages, nullptr, nullptr, 2, texs); + } +}; + +#if BOO_HAS_VULKAN +struct CThermalColdFilterVulkanDataBindingFactory : TFilterShader::IDataBindingFactory +{ + boo::IShaderDataBinding* BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, CThermalColdFilter& filter) + { + boo::VulkanDataFactory::Context& cctx = static_cast(ctx); + + boo::IGraphicsBuffer* bufs[] = {filter.m_uniBuf}; + boo::ITexture* texs[] = {CGraphics::g_SpareTexture, filter.m_shiftTex}; + return cctx.newShaderDataBinding(TFilterShader::m_pipeline, + TFilterShader::m_vtxFmt, + filter.m_vbo, nullptr, nullptr, 1, bufs, + nullptr, nullptr, nullptr, 2, texs); + } +}; +#endif + +TFilterShader::IDataBindingFactory* CThermalColdFilter::Initialize(boo::GLDataFactory::Context& ctx, + boo::IShaderPipeline*& pipeOut) +{ + const char* texNames[] = {"sceneTex", "shiftTex"}; + const char* uniNames[] = {"ThermalColdUniform"}; + pipeOut = ctx.newShaderPipeline(VS_GLSL_TEX, FS_GLSL_TEX, 2, texNames, 1, uniNames, boo::BlendFactor::One, + boo::BlendFactor::Zero, boo::Primitive::TriStrips, false, false, false); + return new CThermalColdFilterGLDataBindingFactory; +} + +#if BOO_HAS_VULKAN +TFilterShader::IDataBindingFactory* CThermalColdFilter::Initialize(boo::VulkanDataFactory::Context& ctx, + boo::IShaderPipeline*& pipeOut, + boo::IVertexFormat*& vtxFmtOut) +{ + const boo::VertexElementDescriptor VtxVmt[] = + { + {nullptr, nullptr, boo::VertexSemantic::Position4}, + {nullptr, nullptr, boo::VertexSemantic::UV4} + }; + vtxFmtOut = ctx.newVertexFormat(2, VtxVmt); + pipeOut = ctx.newShaderPipeline(VS_GLSL_TEX, FS_GLSL_TEX, vtxFmtOut, boo::BlendFactor::One, + boo::BlendFactor::Zero, boo::Primitive::TriStrips, false, false, false); + return new CThermalColdFilterVulkanDataBindingFactory; +} +#endif + +} diff --git a/Runtime/Graphics/Shaders/CThermalColdFilterHLSL.cpp b/Runtime/Graphics/Shaders/CThermalColdFilterHLSL.cpp index e69de29bb..1bcccdf6b 100644 --- a/Runtime/Graphics/Shaders/CThermalColdFilterHLSL.cpp +++ b/Runtime/Graphics/Shaders/CThermalColdFilterHLSL.cpp @@ -0,0 +1,13 @@ +#include "CThermalColdFilter.hpp" + +namespace urde +{ + +TFilterShader::IDataBindingFactory* CThermalColdFilter::Initialize(boo::ID3DDataFactory::Context& ctx, + boo::IShaderPipeline*& pipeOut, + boo::IVertexFormat*& vtxFmtOut) +{ + return nullptr; +} + +} diff --git a/Runtime/Graphics/Shaders/CThermalColdFilterMetal.cpp b/Runtime/Graphics/Shaders/CThermalColdFilterMetal.cpp index e69de29bb..f27bc2ad7 100644 --- a/Runtime/Graphics/Shaders/CThermalColdFilterMetal.cpp +++ b/Runtime/Graphics/Shaders/CThermalColdFilterMetal.cpp @@ -0,0 +1,13 @@ +#include "CThermalColdFilter.hpp" + +namespace urde +{ + +TFilterShader::IDataBindingFactory* CThermalColdFilter::Initialize(boo::MetalDataFactory::Context& ctx, + boo::IShaderPipeline*& pipeOut, + boo::IVertexFormat*& vtxFmtOut) +{ + return nullptr; +} + +} diff --git a/Runtime/Graphics/Shaders/CThermalHotFilter.cpp b/Runtime/Graphics/Shaders/CThermalHotFilter.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/Runtime/Graphics/Shaders/CXrayOutlineFilter.cpp b/Runtime/Graphics/Shaders/CXrayOutlineFilter.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/Runtime/Graphics/Shaders/TFilterDecl.hpp b/Runtime/Graphics/Shaders/TFilterDecl.hpp new file mode 100644 index 000000000..eec4c3042 --- /dev/null +++ b/Runtime/Graphics/Shaders/TFilterDecl.hpp @@ -0,0 +1,17 @@ + static TFilterShader<_CLS>::IDataBindingFactory* Initialize(boo::GLDataFactory::Context& ctx, + boo::IShaderPipeline*& pipeOut); +#if _WIN32 + static TFilterShader<_CLS>::IDataBindingFactory* Initialize(boo::ID3DDataFactory::Context& ctx, + boo::IShaderPipeline*& pipeOut, + boo::IVertexFormat*& vtxFmtOut); +#endif +#if BOO_HAS_METAL + static TFilterShader<_CLS>::IDataBindingFactory* Initialize(boo::MetalDataFactory::Context& ctx, + boo::IShaderPipeline*& pipeOut, + boo::IVertexFormat*& vtxFmtOut); +#endif +#if BOO_HAS_VULKAN + static TFilterShader<_CLS>::IDataBindingFactory* Initialize(boo::VulkanDataFactory::Context& ctx, + boo::IShaderPipeline*& pipeOut, + boo::IVertexFormat*& vtxFmtOut); +#endif diff --git a/Runtime/Graphics/Shaders/TFilterShader.hpp b/Runtime/Graphics/Shaders/TFilterShader.hpp new file mode 100644 index 000000000..e735d9cba --- /dev/null +++ b/Runtime/Graphics/Shaders/TFilterShader.hpp @@ -0,0 +1,99 @@ +#ifndef __URDE_TFILTERSHADER_HPP__ +#define __URDE_TFILTERSHADER_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 TFilterShader +{ +public: + struct IDataBindingFactory + { + virtual boo::IShaderDataBinding* BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, FilterImp& filter)=0; + }; + + static boo::IShaderPipeline* m_pipeline; + static boo::IVertexFormat* m_vtxFmt; /* No OpenGL */ + + static std::unique_ptr m_bindFactory; + static boo::GraphicsDataToken m_gfxToken; + + static void Initialize() + { + if (!CGraphics::g_BooFactory) + return; + + m_gfxToken = CGraphics::CommitResources( + [&](boo::IGraphicsDataFactory::Context& ctx) -> bool + { + switch (ctx.platform()) + { + case boo::IGraphicsDataFactory::Platform::OGL: + m_bindFactory.reset(FilterImp::Initialize(static_cast(ctx), + m_pipeline)); + break; +#if _WIN32 + case boo::IGraphicsDataFactory::Platform::D3D11: + case boo::IGraphicsDataFactory::Platform::D3D12: + m_bindFactory.reset(FilterImp::Initialize(static_cast(ctx), + m_pipeline, m_vtxFmt)); + break; +#endif +#if BOO_HAS_METAL + case boo::IGraphicsDataFactory::Platform::Metal: + m_bindFactory.reset(FilterImp::Initialize(static_cast(ctx), + m_pipeline, m_vtxFmt)); + break; +#endif +#if BOO_HAS_VULKAN + case boo::IGraphicsDataFactory::Platform::Vulkan: + m_bindFactory.reset(FilterImp::Initialize(static_cast(ctx), + m_pipeline, m_vtxFmt)); + break; +#endif + default: break; + } + return true; + }); + } + + static void Shutdown() + { + m_gfxToken.doDestroy(); + } + + static boo::IShaderDataBinding* BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, FilterImp& filter) + { + return m_bindFactory->BuildShaderDataBinding(ctx, filter); + } +}; + +#define URDE_DECL_SPECIALIZE_FILTER(cls) \ +template <> boo::IShaderPipeline* \ +TFilterShader::m_pipeline; \ +template <> boo::IVertexFormat* \ +TFilterShader::m_vtxFmt; + +#define URDE_SPECIALIZE_FILTER(cls) \ +template <> boo::IShaderPipeline* \ +TFilterShader::m_pipeline = nullptr; \ +template <> boo::IVertexFormat* \ +TFilterShader::m_vtxFmt = nullptr; \ +\ +template <> std::unique_ptr::IDataBindingFactory> \ +TFilterShader::m_bindFactory; \ +template <> boo::GraphicsDataToken \ +TFilterShader::m_gfxToken; \ +\ +template class TFilterShader; + +} + +#endif // __URDE_TFILTERSHADER_HPP__