diff --git a/DataSpec/DNACommon/CMakeLists.txt b/DataSpec/DNACommon/CMakeLists.txt index 47c5b2a4b..1de07b43e 100644 --- a/DataSpec/DNACommon/CMakeLists.txt +++ b/DataSpec/DNACommon/CMakeLists.txt @@ -37,4 +37,5 @@ add_library(DNACommon Tweaks/ITweakPlayerControl.hpp Tweaks/ITweakPlayerGun.hpp Tweaks/ITweakGunRes.hpp - Tweaks/ITweakPlayerRes.hpp) + Tweaks/ITweakPlayerRes.hpp + Tweaks/ITweakGui.hpp) diff --git a/DataSpec/DNACommon/Tweaks/ITweakGui.hpp b/DataSpec/DNACommon/Tweaks/ITweakGui.hpp new file mode 100644 index 000000000..d11ad5a27 --- /dev/null +++ b/DataSpec/DNACommon/Tweaks/ITweakGui.hpp @@ -0,0 +1,19 @@ +#ifndef __DNACOMMON_ITWEAKGUI_HPP__ +#define __DNACOMMON_ITWEAKGUI_HPP__ + +#include "../DNACommon.hpp" +#include "zeus/CVector2f.hpp" + +namespace DataSpec +{ + +struct ITweakGui : BigYAML +{ + virtual float GetScanSpeed(int idx) const=0; + virtual float GetXrayBlurScaleLinear() const=0; + virtual float GetXrayBlurScaleQuadratic() const=0; +}; + +} + +#endif // __DNACOMMON_ITWEAKGUI_HPP__ diff --git a/DataSpec/DNAMP1/CMakeLists.txt b/DataSpec/DNAMP1/CMakeLists.txt index da87902b3..f4b24193a 100644 --- a/DataSpec/DNAMP1/CMakeLists.txt +++ b/DataSpec/DNAMP1/CMakeLists.txt @@ -22,7 +22,8 @@ make_dnalist(liblist Tweaks/CTweakPlayerControl Tweaks/CTweakPlayerGun Tweaks/CTweakGunRes - Tweaks/CTweakPlayerRes) + Tweaks/CTweakPlayerRes + Tweaks/CTweakGui) add_library(DNAMP1 DNAMP1.hpp DNAMP1.cpp diff --git a/DataSpec/DNAMP1/Tweaks/CTweakGui.hpp b/DataSpec/DNAMP1/Tweaks/CTweakGui.hpp new file mode 100644 index 000000000..1eb96aa24 --- /dev/null +++ b/DataSpec/DNAMP1/Tweaks/CTweakGui.hpp @@ -0,0 +1,235 @@ +#ifndef _DNAMP1_CTWEAKGAME_HPP_ +#define _DNAMP1_CTWEAKGAME_HPP_ + +#include "../../DNACommon/Tweaks/ITweakGui.hpp" + +namespace DataSpec +{ +namespace DNAMP1 +{ + +struct CTweakGui : ITweakGui +{ + DECL_YAML + Value x4_; + Value x8_; + Value xc_; + Value x10_; + Value x14_; + Value x18_; + Value x1c_; + Value x20_; + Value x24_; + Value x28_; + Value x2c_ = 0; + Value x30_; + Value x34_; + Value x38_; + Value x3c_; + Value x40_; + Value x44_; + Value x48_; + Value x4c_; + Value x50_; + Value x54_; + Value x58_; + Value x5c_; + Value x60_; + Value x64_; + Value x70_; + Value x7c_; + Value x80_; + Value x84_; + Value x88_; + Value x8c_; + Value x90_; + Value x94_; + Value x98_; + Value x9c_; + Value xa0_; + Value xa4_; + Value xa8_; + Value xac_; + Value xb0_; + Value xb4_; + Value xb8_; + Value xbc_; + Value xc0_; + Value xc4_; + Value xc8_; + Value xcc_; + Value xd0_; + Value xd4_; + Value xd8_; + Value xdc_; + Value xe0_; + Value xe4_; + Value xe8_; + Value xec_; + Value xf0_; + Value xf4_; + Value xf8_; + Value xfc_; + Value x100_; + Value x104_; + Value x108_; + Value x10c_; + Value x110_; + Value x114_; + Value x118_; + Value x11c_; + Value x120_; + Value x124_; + Value x128_; + Value x12c_; + Value x130_; + Value x134_; + Value x138_; + Value x13c_; + Value x140_; + Value x144_; + Value x148_; + Value x14c_; + String<-1> x150_; + String<-1> x160_; + String<-1> x170_; + String<-1> x180_; + String<-1> x190_; + Value x1a0_; + Value x1a4_; + Value x1a8_; + Value x1ac_; + Value x1b0_; + Value x1b4_; + Value x1b8_; + Value x1bc_; + Value x1c0_; + Value x1c4_; + Value x1c8_; + Value x1cc_; + Value x1cd_; + Value x1d0_; + Value x1d4_; + Value x1d8_; + Value x1dc_; + Value x1e0_; + Value x1e4_; + Value x1e8_; + Value x1ec_; + Value x1f0_; + Value x1f4_; + Value x1f8_; + Value x1fc_; + atVec4f x200_; + float x204_xrayBlurScaleLinear = 0.0014f; + float x208_xrayBlurScaleQuadratic = 0.0000525f; + Value x20c_; + Value x210_; + Value x214_; + Value x218_; + Value x21c_; + Value x220_; + Value x224_; + float x228_; + Value x22c_; + Value x230_; + Value x234_; + Value x238_; + Value x23c_; + Value x240_; + Value x244_; + Value x248_; + Value x24c_; + Value x250_; + Value x254_; + Value x258_; + Value x25c_; + Value x260_; + Value x264_; + Value x268_; + Value x26c_; + Value x270_; + Value x274_; + Value x275_ = true; + Value x278_; + Value x27c_; + Value x280_; + Value x284_; + Value x288_; + Value x28c_; + Value x290_; + Value x294_; + Value x298_; + Value x29c_; + Value x2a0_; + Value x2a4_; + Value x2a8_; + Value x2ac_; + Value x2b0_; + Value x2b4_; + Value x2b8_; + Value x2bc_; + Value x2c0_; + Value m_scanSpeedsCount; + Vector x2c4_scanSpeeds; + String<-1> x2d0_; + String<-1> x2e0_; + String<-1> x2f0_; + Value x300_; + Value x304_; + Value x308_; + Value x30c_; + Value x310_; + String<-1> x314_; + String<-1> x324_; + String<-1> x334_; + Value x344_; + Value x348_; + Value x34c_; + Value x350_; + Value x354_; + Value x358_; + Value x35c_; + Value x360_; + Value x364_; + + float GetXrayBlurScaleLinear() const { return x204_xrayBlurScaleLinear; } + float GetXrayBlurScaleQuadratic() const { return x208_xrayBlurScaleQuadratic; } + + float GetScanSpeed(int idx) const + { + if (idx < 0 || idx >= x2c4_scanSpeeds.size()) + return 0.f; + return x2c4_scanSpeeds[idx]; + } + + void FixupValues() + { + xd8_ = zeus::degToRad(xd8_); + xdc_ = zeus::degToRad(xdc_); + + x200_.vec[0] = x1f4_ * 0.25f; + x200_.vec[1] = x1f8_ * 0.25f; + x200_.vec[2] = x1fc_ * 0.25f; + x200_.vec[3] = 1.f; + + x210_ = zeus::degToRad(x210_); + x228_ = x220_ + x224_; + + if (x27c_ == 1) + x27c_ = 2; + else if (x27c_ == 2) + x27c_ = 4; + else if (x27c_ == 3) + x27c_ = 5; + else + x27c_ = 0; + + x84_ *= 2.0f; + } +}; + +} +} + +#endif diff --git a/Editor/ViewManager.cpp b/Editor/ViewManager.cpp index 135c88cb8..f498072ce 100644 --- a/Editor/ViewManager.cpp +++ b/Editor/ViewManager.cpp @@ -24,12 +24,6 @@ using YAMLNode = athena::io::YAMLNode; namespace urde { -URDE_DECL_SPECIALIZE_SHADER(CThermalColdFilter) -URDE_DECL_SPECIALIZE_SHADER(CThermalHotFilter) -URDE_DECL_SPECIALIZE_SHADER(CSpaceWarpFilter) -URDE_DECL_SPECIALIZE_MULTI_BLEND_SHADER(CColoredQuadFilter) -URDE_DECL_SPECIALIZE_MULTI_BLEND_SHADER(CTexturedQuadFilter) - void ViewManager::BuildTestPART(urde::IObjectStore& objStore) { #if 0 @@ -49,18 +43,17 @@ void ViewManager::BuildTestPART(urde::IObjectStore& objStore) //m_modelTest = objStore.GetObj("gun_cmdl"); m_modelTest = objStore.GetObj("MP1/Shared/CMDL_B2B41738.blend"); //m_modelTest = objStore.GetObj("CMDL_GameCube"); - m_modelTest.Lock(); //m_partGenDesc = objStore.GetObj({hecl::FOURCC('PART'), 0x972A5CD2}); //m_partGenDesc = objStore.GetObj("PowerCharge"); - //m_partGenDesc.Lock(); //m_partGen.reset(new urde::CElementGen(m_partGenDesc, // urde::CElementGen::EModelOrientationType::Normal, // urde::CElementGen::EOptionalSystemFlags::None)); //m_partGen->SetGlobalScale({5.f, 5.f, 5.f}); m_lineRenderer.reset(new urde::CLineRenderer(urde::CLineRenderer::EPrimitiveMode::LineStrip, 4, nullptr, true)); - m_particleView.reset(new ParticleView(*this, m_viewResources, *m_rootView)); + TLockedToken xrayPalette = objStore.GetObj("TXTR_XRayPalette"); + m_particleView.reset(new ParticleView(*this, m_viewResources, *m_rootView, xrayPalette)); //m_moviePlayer.reset(new CMoviePlayer("Video/SpecialEnding.thp", 1.f, false, true)); //m_moviePlayer->SetFrame({-1.0f, 1.0f, 0.f}, {-1.0f, -1.0f, 0.f}, {1.0f, -1.0f, 0.f}, {1.0f, 1.0f, 0.f}); @@ -115,7 +108,7 @@ void ViewManager::ParticleView::draw(boo::IGraphicsCommandQueue *gfxQ) float aspect = windowRect.size[0] / float(windowRect.size[1]); CGraphics::SetPerspective(55.0, aspect, 0.1f, 1000.f); - CGraphics::SetFog(ERglFogMode::PerspExp, 7.f, 15.f, zeus::CColor::skRed); + //CGraphics::SetFog(ERglFogMode::PerspExp, 7.f, 15.f, zeus::CColor::skRed); //CGraphics::SetFog(ERglFogMode::PerspExp, 10.f + std::sin(m_theta) * 5.f, 15.f + std::sin(m_theta) * 5.f, zeus::CColor::skRed); zeus::CFrustum frustum; frustum.updatePlanes(CGraphics::g_GXModelView, zeus::SProjPersp(55.0, aspect, 0.1f, 1000.f)); @@ -131,7 +124,9 @@ void ViewManager::ParticleView::draw(boo::IGraphicsCommandQueue *gfxQ) //g_Renderer->DoThermalBlendCold(); //flags.m_extendedShaderIdx = 2; flags.m_extendedShaderIdx = 1; + m_widescreen.draw(zeus::CColor::skBlack, std::sin(m_theta * 3.f) / 2.f + 0.5f); m_vm.m_modelTest->Draw(flags); + m_xrayBlur.draw(25.f); //g_Renderer->DoThermalBlendHot(); //m_spaceWarpFilter.setStrength(std::sin(m_theta * 5.f) * 0.5f + 0.5f); //m_spaceWarpFilter.draw(zeus::CVector2f{0.f, 0.f}); @@ -404,11 +399,6 @@ void ViewManager::stop() { m_videoVoice.reset(); m_projManager.shutdown(); - TShader::Shutdown(); - TShader::Shutdown(); - TShader::Shutdown(); - TMultiBlendShader::Shutdown(); - TMultiBlendShader::Shutdown(); CElementGen::Shutdown(); CMoviePlayer::Shutdown(); CLineRenderer::Shutdown(); diff --git a/Editor/ViewManager.hpp b/Editor/ViewManager.hpp index dd9fba429..83afffe4f 100644 --- a/Editor/ViewManager.hpp +++ b/Editor/ViewManager.hpp @@ -12,6 +12,8 @@ #include "Runtime/Graphics/CModel.hpp" #include "Runtime/Particle/CGenDescription.hpp" #include "Runtime/Character/CAssetFactory.hpp" +#include "Runtime/Graphics/Shaders/CColoredQuadFilter.hpp" +#include "Runtime/Graphics/Shaders/CXRayBlurFilter.hpp" namespace urde { @@ -48,17 +50,20 @@ class ViewManager : public specter::IViewManager { ViewManager& m_vm; CSpaceWarpFilter m_spaceWarpFilter; + CWideScreenFilter m_widescreen = { CCameraFilterPass::EFilterType::Blend }; + CXRayBlurFilter m_xrayBlur; CRandom16 m_random; float m_theta = 0.f; public: - ParticleView(ViewManager& vm, specter::ViewResources& res, specter::View& parent) - : View(res, parent), m_vm(vm), m_random(20) {} + ParticleView(ViewManager& vm, specter::ViewResources& res, specter::View& parent, + TLockedToken& xrayPalette) + : View(res, parent), m_vm(vm), m_xrayBlur(xrayPalette), m_random(20) {} void resized(const boo::SWindowRect& root, const boo::SWindowRect& sub); void draw(boo::IGraphicsCommandQueue* gfxQ); }; std::unique_ptr m_particleView; - urde::TCachedToken m_modelTest; - urde::TCachedToken m_partGenDesc; + urde::TLockedToken m_modelTest; + urde::TLockedToken m_partGenDesc; std::unique_ptr m_partGen; std::unique_ptr m_lineRenderer; std::unique_ptr m_moviePlayer; diff --git a/Runtime/CToken.hpp b/Runtime/CToken.hpp index 4fc3f51f7..2983dc7a5 100644 --- a/Runtime/CToken.hpp +++ b/Runtime/CToken.hpp @@ -308,8 +308,11 @@ class TLockedToken : public TCachedToken { public: TLockedToken() = default; - TLockedToken(const CToken& other) : TCachedToken(other) {CToken::Lock();} - TLockedToken(CToken&& other) : TCachedToken(std::move(other)) {CToken::Lock();} + TLockedToken(const TLockedToken& other) : TCachedToken(other) { CToken::Lock(); } + TLockedToken& operator=(const TLockedToken& other) { CToken::operator=(other); CToken::Lock(); return *this; } + TLockedToken(const CToken& other) : TCachedToken(other) { CToken::Lock(); } + TLockedToken& operator=(const CToken& other) { CToken::operator=(other); CToken::Lock(); return *this; } + TLockedToken(CToken&& other) : TCachedToken(std::move(other)) { CToken::Lock(); } }; } diff --git a/Runtime/Camera/CCameraFilter.cpp b/Runtime/Camera/CCameraFilter.cpp index 2b6263091..f0d171965 100644 --- a/Runtime/Camera/CCameraFilter.cpp +++ b/Runtime/Camera/CCameraFilter.cpp @@ -2,6 +2,7 @@ #include "CCameraFilter.hpp" #include "GameGlobalObjects.hpp" #include "Graphics/CBooRenderer.hpp" +#include "CSimplePool.hpp" namespace urde { @@ -11,15 +12,15 @@ void CCameraFilterPass::DrawFilter(EFilterType type, EFilterShape shape, const z { switch (type) { - case EFilterType::ColorMultiply: - case EFilterType::InvertDst: - case EFilterType::AdditiveAlpha: - case EFilterType::Subtractive: - case EFilterType::AlphaBlended: - case EFilterType::AdditiveDestColor: - case EFilterType::NoColorWrite: - case EFilterType::None: - case EFilterType::None2: + case EFilterType::Multiply: + case EFilterType::Invert: + case EFilterType::Add: + case EFilterType::Subtract: + case EFilterType::Blend: + case EFilterType::SceneAdd: + case EFilterType::NoColor: + case EFilterType::Passthru: + case EFilterType::Widescreen: default: return; } DrawFilterShape(shape, color, tex, uvScale); @@ -30,4 +31,88 @@ void CCameraFilterPass::DrawFilterShape(EFilterShape shape, const zeus::CColor& { } +void CCameraBlurPass::Draw() +{ + if (x10_curType == EBlurType::NoBlur) + return; + + SClipScreenRect rect = {}; + rect.xc_width = CGraphics::g_ViewportResolution.x; + rect.x10_height = CGraphics::g_ViewportResolution.y; + CGraphics::ResolveSpareTexture(rect); + + if (x10_curType == EBlurType::Xray) + { + float blurX = x1c_curValue * g_tweakGui->GetXrayBlurScaleLinear() * 0.25f; + float blurY = x1c_curValue * g_tweakGui->GetXrayBlurScaleQuadratic() * 0.25f; + + for (int i=0 ; i<4 ; ++i) + { + float iflt = i; + float uvScale = (1.f - (blurX * iflt + blurY * iflt * iflt)); + float uvOffset = uvScale * -0.5f + 0.5f; + } + } +} + +void CCameraBlurPass::Update(float dt) +{ + if (x28_remainingTime > 0.f) + { + x28_remainingTime = std::max(x28_remainingTime - dt, 0.f); + x1c_curValue = x18_endValue + (x20_startValue - x18_endValue) * x28_remainingTime / x24_totalTime; + + if (x28_remainingTime != 0.f) + return; + + x10_curType = x14_endType; + } +} + +void CCameraBlurPass::SetBlur(EBlurType type, float amount, float duration) +{ + if (duration == 0.f) + { + x24_totalTime = 0.f; + x28_remainingTime = 0.f; + x18_endValue = amount; + x1c_curValue = amount; + x20_startValue = amount; + + if (x10_curType == EBlurType::NoBlur) + { + if (type == EBlurType::Xray) + x0_paletteTex = g_SimplePool->GetObj("TXTR_XRayPalette"); + } + + x14_endType = type; + x10_curType = type; + //x2c_usePersistent = b1; + } + else + { + //x2c_usePersistent = b1; + x24_totalTime = duration; + x28_remainingTime = duration; + x18_endValue = x1c_curValue; + x20_startValue = amount; + + if (type != x14_endType) + { + if (x10_curType == EBlurType::NoBlur) + { + if (type == EBlurType::Xray) + x0_paletteTex = g_SimplePool->GetObj("TXTR_XRayPalette"); + x10_curType = type; + } + x14_endType = type; + } + } +} + +void CCameraBlurPass::DisableBlur(float duration) +{ + SetBlur(EBlurType::NoBlur, 0.f, duration); +} + } diff --git a/Runtime/Camera/CCameraFilter.hpp b/Runtime/Camera/CCameraFilter.hpp index ea8c1be59..0db3c672c 100644 --- a/Runtime/Camera/CCameraFilter.hpp +++ b/Runtime/Camera/CCameraFilter.hpp @@ -3,6 +3,7 @@ #include "zeus/CColor.hpp" #include "RetroTypes.hpp" +#include "CToken.hpp" namespace urde { @@ -13,40 +14,66 @@ class CCameraFilterPass public: enum class EFilterType { - None, - ColorMultiply, - InvertDst, - AdditiveAlpha, - Subtractive, - AlphaBlended, - None2, - AdditiveDestColor, - NoColorWrite + Passthru, + Multiply, + Invert, + Add, + Subtract, + Blend, + Widescreen, + SceneAdd, + NoColor }; enum class EFilterShape { - QuadA, - QuadB, - QuadC, - QuadQuarters, - WideScreen, - ScanLinesA, - ScanLinesB, - RandomStaticA, - RandomStaticB + Fullscreen, + FullscreenHalvesLeftRight, + FullscreenHalvesTopBottom, + FullscreenQuarters, + CinemaBars, + ScanLinesEven, + ScanLinesOdd, + RandomStatic, + CookieCutterDepthRandomStatic }; private: -public: - void SetFilter(EFilterType type, EFilterShape shape, float, const zeus::CColor& color, u32) {} - void DisableFilter(float) {} static void DrawFilter(EFilterType type, EFilterShape shape, const zeus::CColor& color, const CTexture* tex, float uvScale); static void DrawFilterShape(EFilterShape shape, const zeus::CColor& color, const CTexture* tex, float uvScale); +public: + void SetFilter(EFilterType type, EFilterShape shape, float, const zeus::CColor& color, u32) {} + void DisableFilter(float) {} + }; class CCameraBlurPass { +public: + enum class EBlurType + { + NoBlur, + LoBlur, + HiBlur, + Xray + }; +private: + TLockedToken x0_paletteTex; + EBlurType x10_curType = EBlurType::NoBlur; + EBlurType x14_endType = EBlurType::NoBlur; + float x18_endValue = 0.f; + float x1c_curValue = 0.f; + float x20_startValue = 0.f; + float x24_totalTime = 0.f; + float x28_remainingTime = 0.f; + //bool x2c_usePersistent = false; + //bool x2d_noPersistentCopy = false; + //u32 x30_persistentBuf = 0; + + void Draw(); + void Update(float dt); + void SetBlur(EBlurType type, float amount, float duration); + void DisableBlur(float duration); }; } diff --git a/Runtime/Camera/CCameraManager.cpp b/Runtime/Camera/CCameraManager.cpp index a8d1c749f..e0d75452e 100644 --- a/Runtime/Camera/CCameraManager.cpp +++ b/Runtime/Camera/CCameraManager.cpp @@ -109,8 +109,8 @@ void CCameraManager::Update(float dt, CStateManager& stateMgr) zeus::CColor tmpColor; // Get from water zeus::CVector2f tmpVector; // Get from camera x3c_fog.SetFogExplicit(ERglFogMode::PerspExp, tmpColor, tmpVector); - stateMgr.GetCameraFilterPass(4).SetFilter(CCameraFilterPass::EFilterType::ColorMultiply, - CCameraFilterPass::EFilterShape::QuadA, + stateMgr.GetCameraFilterPass(4).SetFilter(CCameraFilterPass::EFilterType::Multiply, + CCameraFilterPass::EFilterShape::Fullscreen, 0.f, tmpColor, -1); } x86_26_inWater = true; diff --git a/Runtime/GameGlobalObjects.cpp b/Runtime/GameGlobalObjects.cpp index 5263eff46..2a39b602b 100644 --- a/Runtime/GameGlobalObjects.cpp +++ b/Runtime/GameGlobalObjects.cpp @@ -22,5 +22,6 @@ DataSpec::ITweakPlayerControl* g_tweakPlayerControl = nullptr; DataSpec::ITweakPlayerGun* g_tweakPlayerGun = nullptr; DataSpec::ITweakGunRes* g_tweakGunRes = nullptr; DataSpec::ITweakPlayerRes* g_tweakPlayerRes = nullptr; +DataSpec::ITweakGui* g_tweakGui = nullptr; } diff --git a/Runtime/GameGlobalObjects.hpp b/Runtime/GameGlobalObjects.hpp index 3c8284b9a..69da70ec2 100644 --- a/Runtime/GameGlobalObjects.hpp +++ b/Runtime/GameGlobalObjects.hpp @@ -6,6 +6,7 @@ #include "../DataSpec/DNACommon/Tweaks/ITweakPlayerGun.hpp" #include "../DataSpec/DNACommon/Tweaks/ITweakGunRes.hpp" #include "../DataSpec/DNACommon/Tweaks/ITweakPlayerRes.hpp" +#include "../DataSpec/DNACommon/Tweaks/ITweakGui.hpp" #include "AutoMapper/ITweakAutoMapper.hpp" #include "GuiSys/ITweakGui.hpp" @@ -32,7 +33,7 @@ extern DataSpec::ITweakPlayerGun* g_tweakPlayerGun; extern DataSpec::ITweakGunRes* g_tweakGunRes; extern DataSpec::ITweakPlayerRes* g_tweakPlayerRes; extern ITweakAutoMapper* g_tweakAutoMapper; -extern ITweakGui* g_tweakGui; +extern DataSpec::ITweakGui* g_tweakGui; } diff --git a/Runtime/Graphics/CBooRenderer.hpp b/Runtime/Graphics/CBooRenderer.hpp index c4dc30999..a6da7fb1b 100644 --- a/Runtime/Graphics/CBooRenderer.hpp +++ b/Runtime/Graphics/CBooRenderer.hpp @@ -48,6 +48,7 @@ public: class CBooRenderer : public IRenderer { friend class CBooModel; + friend class CWorldTransManager; struct CAreaListItem { diff --git a/Runtime/Graphics/CMakeLists.txt b/Runtime/Graphics/CMakeLists.txt index b9c90b918..16ea05024 100644 --- a/Runtime/Graphics/CMakeLists.txt +++ b/Runtime/Graphics/CMakeLists.txt @@ -6,7 +6,9 @@ if(WIN32) Shaders/CModelShadersHLSL.cpp Shaders/CThermalColdFilterHLSL.cpp Shaders/CThermalHotFilterHLSL.cpp - Shaders/CSpaceWarpFilterHLSL.cpp) + Shaders/CSpaceWarpFilterHLSL.cpp + Shaders/CCameraBlurFilterHLSL.cpp + Shaders/CXRayBlurFilterHLSL.cpp) elseif(APPLE) set(PLAT_SRCS Shaders/CLineRendererShadersMetal.cpp @@ -15,7 +17,9 @@ elseif(APPLE) Shaders/CModelShadersMetal.cpp Shaders/CThermalColdFilterMetal.cpp Shaders/CThermalHotFilterMetal.cpp - Shaders/CSpaceWarpFilterMetal.cpp) + Shaders/CSpaceWarpFilterMetal.cpp + Shaders/CCameraBlurFilterMetal.cpp + Shaders/CXRayBlurFilterMetal.cpp) endif() set(GRAPHICS_SOURCES @@ -48,6 +52,8 @@ set(GRAPHICS_SOURCES Shaders/CThermalColdFilter.hpp Shaders/CThermalColdFilter.cpp Shaders/CThermalColdFilterGLSL.cpp Shaders/CThermalHotFilter.hpp Shaders/CThermalHotFilter.cpp Shaders/CThermalHotFilterGLSL.cpp Shaders/CSpaceWarpFilter.hpp Shaders/CSpaceWarpFilter.cpp Shaders/CSpaceWarpFilterGLSL.cpp + Shaders/CCameraBlurFilter.hpp Shaders/CCameraBlurFilter.cpp Shaders/CCameraBlurFilterGLSL.cpp + Shaders/CXRayBlurFilter.hpp Shaders/CXRayBlurFilter.cpp Shaders/CXRayBlurFilterGLSL.cpp ${PLAT_SRCS}) runtime_add_list(Graphics GRAPHICS_SOURCES) diff --git a/Runtime/Graphics/CTexture.hpp b/Runtime/Graphics/CTexture.hpp index be38e2cdc..402a66612 100644 --- a/Runtime/Graphics/CTexture.hpp +++ b/Runtime/Graphics/CTexture.hpp @@ -39,6 +39,10 @@ class CTexture void BuildC8(const void* data); public: + ~CTexture() + { + printf(""); + } CTexture(std::unique_ptr&& in, u32 length); enum class EClampMode { diff --git a/Runtime/Graphics/Shaders/CCameraBlurFilter.cpp b/Runtime/Graphics/Shaders/CCameraBlurFilter.cpp new file mode 100644 index 000000000..74e1d0c80 --- /dev/null +++ b/Runtime/Graphics/Shaders/CCameraBlurFilter.cpp @@ -0,0 +1,44 @@ +#include "CCameraBlurFilter.hpp" +#include "Graphics/CGraphics.hpp" + +namespace urde +{ + +CCameraBlurFilter::CCameraBlurFilter() +{ + m_token = CGraphics::g_BooFactory->commitTransaction([&](boo::IGraphicsDataFactory::Context& ctx) -> bool + { + 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, 0.0}}, + {{ 1.0, 1.0}, {1.0, 1.0}}, + }; + 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); + return true; + }); +} + +void CCameraBlurFilter::draw() +{ + SClipScreenRect clipRect = {}; + clipRect.xc_width = CGraphics::g_ViewportResolution.x; + clipRect.x10_height = CGraphics::g_ViewportResolution.y; + CGraphics::ResolveSpareTexture(clipRect); + + //m_uniBuf->load(&m_uniform, sizeof(m_uniform)); + + CGraphics::g_BooMainCommandQueue->setShaderDataBinding(m_dataBind); + CGraphics::g_BooMainCommandQueue->draw(0, 4); +} + +URDE_SPECIALIZE_SHADER(CCameraBlurFilter) + +} diff --git a/Runtime/Graphics/Shaders/CCameraBlurFilter.hpp b/Runtime/Graphics/Shaders/CCameraBlurFilter.hpp new file mode 100644 index 000000000..c4447f01e --- /dev/null +++ b/Runtime/Graphics/Shaders/CCameraBlurFilter.hpp @@ -0,0 +1,37 @@ +#ifndef __URDE_CCAMERABLURFILTER_HPP__ +#define __URDE_CCAMERABLURFILTER_HPP__ + +#include "TShader.hpp" +#include "zeus/CMatrix4f.hpp" +#include "zeus/CColor.hpp" + +namespace urde +{ + +class CCameraBlurFilter +{ + friend struct CCameraBlurFilterGLDataBindingFactory; + friend struct CCameraBlurFilterVulkanDataBindingFactory; + friend struct CCameraBlurFilterMetalDataBindingFactory; + friend struct CCameraBlurFilterD3DDataBindingFactory; + + struct Uniform + { + }; + boo::GraphicsDataToken m_token; + boo::IGraphicsBufferS* m_vbo; + boo::IGraphicsBufferD* m_uniBuf; + boo::IShaderDataBinding* m_dataBind = nullptr; + Uniform m_uniform; + +public: + CCameraBlurFilter(); + void draw(); + + using _CLS = CCameraBlurFilter; +#include "TShaderDecl.hpp" +}; + +} + +#endif // __URDE_CCAMERABLURFILTER_HPP__ diff --git a/Runtime/Graphics/Shaders/CCameraBlurFilterGLSL.cpp b/Runtime/Graphics/Shaders/CCameraBlurFilterGLSL.cpp new file mode 100644 index 000000000..57b0d3d43 --- /dev/null +++ b/Runtime/Graphics/Shaders/CCameraBlurFilterGLSL.cpp @@ -0,0 +1,124 @@ +#include "CCameraBlurFilter.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 = colorSample * sceneSample;\n" +"}\n"; + +URDE_DECL_SPECIALIZE_SHADER(CCameraBlurFilter) + +struct CCameraBlurFilterGLDataBindingFactory : TShader::IDataBindingFactory +{ + boo::IShaderDataBinding* BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, + boo::IShaderPipeline* pipeline, + boo::IVertexFormat*, + CCameraBlurFilter& 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, g_Renderer->GetThermoPalette()}; + return cctx.newShaderDataBinding(pipeline, + ctx.newVertexFormat(2, VtxVmt), filter.m_vbo, nullptr, nullptr, + 1, bufs, stages, nullptr, nullptr, 2, texs); + } +}; + +#if BOO_HAS_VULKAN +struct CCameraBlurFilterVulkanDataBindingFactory : TShader::IDataBindingFactory +{ + boo::IShaderDataBinding* BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, + boo::IShaderPipeline* pipeline, + boo::IVertexFormat* vtxFmt, + CCameraBlurFilter& filter) + { + boo::VulkanDataFactory::Context& cctx = static_cast(ctx); + + boo::IGraphicsBuffer* bufs[] = {filter.m_uniBuf}; + boo::ITexture* texs[] = {CGraphics::g_SpareTexture, g_Renderer->GetThermoPalette()}; + return cctx.newShaderDataBinding(pipeline, vtxFmt, + filter.m_vbo, nullptr, nullptr, 1, bufs, + nullptr, nullptr, nullptr, 2, texs); + } +}; +#endif + +TShader::IDataBindingFactory* CCameraBlurFilter::Initialize(boo::GLDataFactory::Context& ctx, + boo::IShaderPipeline*& pipeOut) +{ + const char* texNames[] = {"sceneTex", "paletteTex"}; + const char* uniNames[] = {"ThermalHotUniform"}; + pipeOut = ctx.newShaderPipeline(VS, FS, 2, texNames, 1, uniNames, boo::BlendFactor::DstAlpha, + boo::BlendFactor::InvDstAlpha, boo::Primitive::TriStrips, false, false, false); + return new CCameraBlurFilterGLDataBindingFactory; +} + +#if BOO_HAS_VULKAN +TShader::IDataBindingFactory* CCameraBlurFilter::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, FS, vtxFmtOut, boo::BlendFactor::DstAlpha, + boo::BlendFactor::InvDstAlpha, boo::Primitive::TriStrips, false, false, false); + return new CCameraBlurFilterVulkanDataBindingFactory; +} +#endif + +} diff --git a/Runtime/Graphics/Shaders/CColoredQuadFilter.cpp b/Runtime/Graphics/Shaders/CColoredQuadFilter.cpp index a1b27e73c..188467500 100644 --- a/Runtime/Graphics/Shaders/CColoredQuadFilter.cpp +++ b/Runtime/Graphics/Shaders/CColoredQuadFilter.cpp @@ -12,10 +12,10 @@ CColoredQuadFilter::CColoredQuadFilter(CCameraFilterPass::EFilterType type) zeus::CVector2f m_pos; } verts[4] = { - {{-1.0, -1.0}}, - {{-1.0, 1.0}}, - {{ 1.0, -1.0}}, - {{ 1.0, 1.0}}, + {{0.0, 0.0}}, + {{0.0, 1.0}}, + {{1.0, 0.0}}, + {{1.0, 1.0}}, }; m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts, 16, 4); m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); @@ -24,8 +24,12 @@ CColoredQuadFilter::CColoredQuadFilter(CCameraFilterPass::EFilterType type) }); } -void CColoredQuadFilter::draw(const zeus::CColor& color) +void CColoredQuadFilter::draw(const zeus::CColor& color, const zeus::CRectangle& rect) { + m_uniform.m_matrix[0][0] = rect.size.x * 2.f; + m_uniform.m_matrix[1][1] = rect.size.y * 2.f; + m_uniform.m_matrix[3][0] = rect.position.x * 2.f - 1.f; + m_uniform.m_matrix[3][1] = rect.position.y * 2.f - 1.f; m_uniform.m_color = color; m_uniBuf->load(&m_uniform, sizeof(m_uniform)); @@ -33,6 +37,23 @@ void CColoredQuadFilter::draw(const zeus::CColor& color) CGraphics::g_BooMainCommandQueue->draw(0, 4); } +void CWideScreenFilter::draw(const zeus::CColor& color, float t) +{ + float aspect = CGraphics::g_ViewportResolution.x / float(CGraphics::g_ViewportResolution.y); + if (aspect < 1.7777f) + { + float targetHeight = CGraphics::g_ViewportResolution.x / 1.7777f; + float delta = (CGraphics::g_ViewportResolution.y - targetHeight) * t / 2.f; + delta /= float(CGraphics::g_ViewportResolution.y); + zeus::CRectangle rect(0.f, 0.f, 1.f, delta); + m_bottom.draw(color, rect); + rect.position.y = 1.f - delta; + m_top.draw(color, rect); + } +} + +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 e547e8046..34627eaeb 100644 --- a/Runtime/Graphics/Shaders/CColoredQuadFilter.hpp +++ b/Runtime/Graphics/Shaders/CColoredQuadFilter.hpp @@ -4,6 +4,7 @@ #include "TMultiBlendShader.hpp" #include "zeus/CMatrix4f.hpp" #include "zeus/CColor.hpp" +#include "zeus/CRectangle.hpp" #include "Camera/CCameraFilter.hpp" namespace urde @@ -18,6 +19,7 @@ class CColoredQuadFilter struct Uniform { + zeus::CMatrix4f m_matrix; zeus::CColor m_color; }; boo::GraphicsDataToken m_token; @@ -27,13 +29,24 @@ class CColoredQuadFilter Uniform m_uniform; public: + static const zeus::CRectangle DefaultRect; CColoredQuadFilter(CCameraFilterPass::EFilterType type); - void draw(const zeus::CColor& color); + void draw(const zeus::CColor& color, const zeus::CRectangle& rect=DefaultRect); using _CLS = CColoredQuadFilter; #include "TMultiBlendShaderDecl.hpp" }; +class CWideScreenFilter +{ + CColoredQuadFilter m_top; + CColoredQuadFilter m_bottom; +public: + CWideScreenFilter(CCameraFilterPass::EFilterType type) + : m_top(type), m_bottom(type) {} + void draw(const zeus::CColor& color, float t); +}; + } #endif // __URDE_CCOLOREDQUADFILTER_HPP__ diff --git a/Runtime/Graphics/Shaders/CColoredQuadFilterGLSL.cpp b/Runtime/Graphics/Shaders/CColoredQuadFilterGLSL.cpp index 0240653f2..f6b49ab77 100644 --- a/Runtime/Graphics/Shaders/CColoredQuadFilterGLSL.cpp +++ b/Runtime/Graphics/Shaders/CColoredQuadFilterGLSL.cpp @@ -12,6 +12,7 @@ BOO_GLSL_BINDING_HEAD "\n" "UBINDING0 uniform ColoredQuadUniform\n" "{\n" +" mat4 xf;\n" " vec4 color;\n" "};\n" "\n" @@ -24,7 +25,7 @@ BOO_GLSL_BINDING_HEAD "void main()\n" "{\n" " vtf.color = color;\n" -" gl_Position = vec4(posIn.xyz, 1.0);\n" +" gl_Position = xf * vec4(posIn.xyz, 1.0);\n" "}\n"; static const char* FS = diff --git a/Runtime/Graphics/Shaders/CModelShadersHLSL.cpp b/Runtime/Graphics/Shaders/CModelShadersHLSL.cpp index 0ea27fc49..2cb8f4ba1 100644 --- a/Runtime/Graphics/Shaders/CModelShadersHLSL.cpp +++ b/Runtime/Graphics/Shaders/CModelShadersHLSL.cpp @@ -51,7 +51,7 @@ static const char* LightingHLSL = "}\n"; static const char* MainPostHLSL = -"float4 MainPostFunc(in VertToFrag vtf, float4 colorIn)\n" +"static float4 MainPostFunc(in VertToFrag vtf, float4 colorIn)\n" "{\n" " float fogZ = (-vtf.mvPos.z - fog.start) * fog.rangeScale;\n" " return lerp(fog.color, colorIn, saturate(exp2(-8.0 * fogZ)));\n" @@ -64,7 +64,7 @@ static const char* ThermalPostHLSL = " float4 mulColor;\n" " float4 addColor;\n" "};\n" -"float4 ThermalPostFunc(in VertToFrag vtf, float4 colorIn)\n" +"static float4 ThermalPostFunc(in VertToFrag vtf, float4 colorIn)\n" "{\n" " return float4(extTex7.Sample(samp, vtf.extTcgs[0]).rrr * mulColor.rgb + addColor.rgb, 1.0);\n" "}\n" diff --git a/Runtime/Graphics/Shaders/CTexturedQuadFilter.cpp b/Runtime/Graphics/Shaders/CTexturedQuadFilter.cpp index c6504a83c..b1a20cc58 100644 --- a/Runtime/Graphics/Shaders/CTexturedQuadFilter.cpp +++ b/Runtime/Graphics/Shaders/CTexturedQuadFilter.cpp @@ -1,10 +1,11 @@ #include "CTexturedQuadFilter.hpp" +#include "Graphics/CTexture.hpp" namespace urde { -CTexturedQuadFilter::CTexturedQuadFilter(CCameraFilterPass::EFilterType type, const TToken& tex) -: m_tex(tex) +CTexturedQuadFilter::CTexturedQuadFilter(CCameraFilterPass::EFilterType type, boo::ITexture* tex) +: m_booTex(tex) { m_token = CGraphics::g_BooFactory->commitTransaction([&](boo::IGraphicsDataFactory::Context& ctx) -> bool { @@ -26,6 +27,13 @@ CTexturedQuadFilter::CTexturedQuadFilter(CCameraFilterPass::EFilterType type, co }); } +CTexturedQuadFilter::CTexturedQuadFilter(CCameraFilterPass::EFilterType type, + TLockedToken& tex) +: CTexturedQuadFilter(type, tex->GetBooTexture()) +{ + m_tex = tex; +} + void CTexturedQuadFilter::draw(const zeus::CColor& color, float uvScale) { m_uniform.m_color = color; diff --git a/Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp b/Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp index 62576c820..b160223b8 100644 --- a/Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp +++ b/Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp @@ -23,6 +23,7 @@ class CTexturedQuadFilter float m_uvScale; }; TLockedToken m_tex; + boo::ITexture* m_booTex; boo::GraphicsDataToken m_token; boo::IGraphicsBufferS* m_vbo; boo::IGraphicsBufferD* m_uniBuf; @@ -30,7 +31,8 @@ class CTexturedQuadFilter Uniform m_uniform; public: - CTexturedQuadFilter(CCameraFilterPass::EFilterType type, const TToken& tex); + CTexturedQuadFilter(CCameraFilterPass::EFilterType type, TLockedToken& tex); + CTexturedQuadFilter(CCameraFilterPass::EFilterType type, boo::ITexture* tex); void draw(const zeus::CColor& color, float uvScale); using _CLS = CTexturedQuadFilter; diff --git a/Runtime/Graphics/Shaders/CTexturedQuadFilterGLSL.cpp b/Runtime/Graphics/Shaders/CTexturedQuadFilterGLSL.cpp index 5168ec6cb..8f70b4405 100644 --- a/Runtime/Graphics/Shaders/CTexturedQuadFilterGLSL.cpp +++ b/Runtime/Graphics/Shaders/CTexturedQuadFilterGLSL.cpp @@ -14,6 +14,7 @@ BOO_GLSL_BINDING_HEAD "UBINDING0 uniform TexuredQuadUniform\n" "{\n" " vec4 color;\n" +" float uvScale;\n" "};\n" "\n" "struct VertToFrag\n" @@ -26,7 +27,7 @@ BOO_GLSL_BINDING_HEAD "void main()\n" "{\n" " vtf.color = color;\n" -" vtf.uv = uvIn.xy;\n" +" vtf.uv = uvIn.xy * uvScale;\n" " gl_Position = vec4(posIn.xyz, 1.0);\n" "}\n"; @@ -65,7 +66,7 @@ struct CTexturedQuadFilterGLDataBindingFactory : TMultiBlendShaderGetBooTexture()}; + boo::ITexture* texs[] = {filter.m_booTex}; return cctx.newShaderDataBinding(pipeline, ctx.newVertexFormat(2, VtxVmt), filter.m_vbo, nullptr, nullptr, 1, bufs, stages, nullptr, nullptr, 1, texs); @@ -83,7 +84,7 @@ struct CTexturedQuadFilterVulkanDataBindingFactory : TMultiBlendShader(ctx); boo::IGraphicsBuffer* bufs[] = {filter.m_uniBuf}; - boo::ITexture* texs[] = {filter.m_tex->GetBooTexture()}; + boo::ITexture* texs[] = {filter.m_booTex}; return cctx.newShaderDataBinding(pipeline, vtxFmt, filter.m_vbo, nullptr, nullptr, 1, bufs, nullptr, nullptr, nullptr, 1, texs); diff --git a/Runtime/Graphics/Shaders/CTexturedQuadFilterHLSL.cpp b/Runtime/Graphics/Shaders/CTexturedQuadFilterHLSL.cpp index 008f2aab8..54b8d4085 100644 --- a/Runtime/Graphics/Shaders/CTexturedQuadFilterHLSL.cpp +++ b/Runtime/Graphics/Shaders/CTexturedQuadFilterHLSL.cpp @@ -61,7 +61,7 @@ struct CTexturedQuadFilterD3DDataBindingFactory : TMultiBlendShader(ctx); boo::IGraphicsBuffer* bufs[] = {filter.m_uniBuf}; - boo::ITexture* texs[] = {filter.m_tex->GetBooTexture()}; + boo::ITexture* texs[] = {filter.m_booTex}; return cctx.newShaderDataBinding(pipeline, vtxFmt, filter.m_vbo, nullptr, nullptr, 1, bufs, nullptr, nullptr, nullptr, 1, texs); diff --git a/Runtime/Graphics/Shaders/CTexturedQuadFilterMetal.cpp b/Runtime/Graphics/Shaders/CTexturedQuadFilterMetal.cpp index c0e11fa08..988585deb 100644 --- a/Runtime/Graphics/Shaders/CTexturedQuadFilterMetal.cpp +++ b/Runtime/Graphics/Shaders/CTexturedQuadFilterMetal.cpp @@ -63,7 +63,7 @@ struct CTexturedQuadFilterMetalDataBindingFactory : TMultiBlendShader(ctx); boo::IGraphicsBuffer* bufs[] = {filter.m_uniBuf}; - boo::ITexture* texs[] = {filter.m_tex->GetBooTexture()}; + boo::ITexture* texs[] = {filter.m_booTex}; return cctx.newShaderDataBinding(pipeline, vtxFmt, filter.m_vbo, nullptr, nullptr, 1, bufs, nullptr, nullptr, nullptr, 1, texs); diff --git a/Runtime/Graphics/Shaders/CXRayBlurFilter.cpp b/Runtime/Graphics/Shaders/CXRayBlurFilter.cpp new file mode 100644 index 000000000..fdb85ac87 --- /dev/null +++ b/Runtime/Graphics/Shaders/CXRayBlurFilter.cpp @@ -0,0 +1,62 @@ +#include "CXRayBlurFilter.hpp" +#include "Graphics/CGraphics.hpp" +#include "Graphics/CTexture.hpp" +#include "GameGlobalObjects.hpp" + +namespace urde +{ + +CXRayBlurFilter::CXRayBlurFilter(TLockedToken& tex) +: m_paletteTex(tex), m_booTex(tex->GetPaletteTexture()) +{ + m_token = CGraphics::g_BooFactory->commitTransaction([&](boo::IGraphicsDataFactory::Context& ctx) -> bool + { + 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, 0.0}}, + {{ 1.0, 1.0}, {1.0, 1.0}}, + }; + 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); + return true; + }); +} + +void CXRayBlurFilter::draw(float amount) +{ + SClipScreenRect clipRect = {}; + clipRect.xc_width = CGraphics::g_ViewportResolution.x; + clipRect.x10_height = CGraphics::g_ViewportResolution.y; + CGraphics::ResolveSpareTexture(clipRect); + + float blurL = amount * 0.0014f * 0.25f; + float blurQ = amount * 0.0000525f * 0.25f; + //float blurL = amount * g_tweakGui->GetXrayBlurScaleLinear() * 0.25f; + //float blurQ = amount * g_tweakGui->GetXrayBlurScaleQuadratic() * 0.25f; + + for (int i=0 ; i<4 ; ++i) + { + float iflt = i; + float uvScale = (1.f - (blurL * iflt + blurQ * iflt * iflt)); + float uvOffset = uvScale * -0.5f + 0.5f; + m_uniform.m_uv[i][0][0] = uvScale; + m_uniform.m_uv[i][1][1] = uvScale; + m_uniform.m_uv[i][3][0] = uvOffset; + m_uniform.m_uv[i][3][1] = uvOffset; + } + m_uniBuf->load(&m_uniform, sizeof(m_uniform)); + + CGraphics::g_BooMainCommandQueue->setShaderDataBinding(m_dataBind); + CGraphics::g_BooMainCommandQueue->draw(0, 4); +} + +URDE_SPECIALIZE_SHADER(CXRayBlurFilter) + +} diff --git a/Runtime/Graphics/Shaders/CXRayBlurFilter.hpp b/Runtime/Graphics/Shaders/CXRayBlurFilter.hpp new file mode 100644 index 000000000..d51f86a3e --- /dev/null +++ b/Runtime/Graphics/Shaders/CXRayBlurFilter.hpp @@ -0,0 +1,42 @@ +#ifndef __URDE_CCAMERABLURFILTER_HPP__ +#define __URDE_CCAMERABLURFILTER_HPP__ + +#include "TShader.hpp" +#include "zeus/CMatrix4f.hpp" +#include "zeus/CColor.hpp" +#include "CToken.hpp" + +namespace urde +{ +class CTexture; + +class CXRayBlurFilter +{ + friend struct CXRayBlurFilterGLDataBindingFactory; + friend struct CXRayBlurFilterVulkanDataBindingFactory; + friend struct CXRayBlurFilterMetalDataBindingFactory; + friend struct CXRayBlurFilterD3DDataBindingFactory; + + struct Uniform + { + zeus::CMatrix4f m_uv[4]; + }; + TLockedToken m_paletteTex; + boo::ITexture* m_booTex = nullptr; + boo::GraphicsDataToken m_token; + boo::IGraphicsBufferS* m_vbo; + boo::IGraphicsBufferD* m_uniBuf; + boo::IShaderDataBinding* m_dataBind = nullptr; + Uniform m_uniform; + +public: + CXRayBlurFilter(TLockedToken& tex); + void draw(float amount); + + using _CLS = CXRayBlurFilter; +#include "TShaderDecl.hpp" +}; + +} + +#endif // __URDE_CCAMERABLURFILTER_HPP__ diff --git a/Runtime/Graphics/Shaders/CXRayBlurFilterGLSL.cpp b/Runtime/Graphics/Shaders/CXRayBlurFilterGLSL.cpp new file mode 100644 index 000000000..76789db5c --- /dev/null +++ b/Runtime/Graphics/Shaders/CXRayBlurFilterGLSL.cpp @@ -0,0 +1,136 @@ +#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" +"};\n" +"\n" +"struct VertToFrag\n" +"{\n" +" vec2 uv0;\n" +" vec2 uv1;\n" +" vec2 uv2;\n" +" vec2 uv3;\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" +" 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" +"};\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.25;\n" +" colorSample += texture(paletteTex, vec2(dot(texture(sceneTex, vtf.uv1), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.25;\n" +" colorSample += texture(paletteTex, vec2(dot(texture(sceneTex, vtf.uv2), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.25;\n" +" colorSample += texture(paletteTex, vec2(dot(texture(sceneTex, vtf.uv3), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.25;\n" +" colorOut = colorSample;\n" +"}\n"; + +URDE_DECL_SPECIALIZE_SHADER(CXRayBlurFilter) + +struct CXRayBlurFilterGLDataBindingFactory : TShader::IDataBindingFactory +{ + boo::IShaderDataBinding* BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, + boo::IShaderPipeline* pipeline, + boo::IVertexFormat*, + CXRayBlurFilter& 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_booTex}; + return cctx.newShaderDataBinding(pipeline, + ctx.newVertexFormat(2, VtxVmt), filter.m_vbo, nullptr, nullptr, + 1, bufs, stages, nullptr, nullptr, 2, texs); + } +}; + +#if BOO_HAS_VULKAN +struct CXRayBlurFilterVulkanDataBindingFactory : TShader::IDataBindingFactory +{ + boo::IShaderDataBinding* BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, + boo::IShaderPipeline* pipeline, + boo::IVertexFormat* vtxFmt, + CXRayBlurFilter& filter) + { + boo::VulkanDataFactory::Context& cctx = static_cast(ctx); + + boo::IGraphicsBuffer* bufs[] = {filter.m_uniBuf}; + boo::ITexture* texs[] = {CGraphics::g_SpareTexture, filter.m_booTex}; + return cctx.newShaderDataBinding(pipeline, vtxFmt, + filter.m_vbo, nullptr, nullptr, 1, bufs, + nullptr, nullptr, nullptr, 2, texs); + } +}; +#endif + +TShader::IDataBindingFactory* CXRayBlurFilter::Initialize(boo::GLDataFactory::Context& ctx, + boo::IShaderPipeline*& pipeOut) +{ + const char* texNames[] = {"sceneTex", "paletteTex"}; + const char* uniNames[] = {"XRayBlurUniform"}; + pipeOut = ctx.newShaderPipeline(VS, FS, 2, texNames, 1, uniNames, boo::BlendFactor::One, + boo::BlendFactor::Zero, boo::Primitive::TriStrips, false, false, false); + return new CXRayBlurFilterGLDataBindingFactory; +} + +#if BOO_HAS_VULKAN +TShader::IDataBindingFactory* CXRayBlurFilter::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, FS, vtxFmtOut, boo::BlendFactor::One, + boo::BlendFactor::Zero, boo::Primitive::TriStrips, false, false, false); + return new CXRayBlurFilterVulkanDataBindingFactory; +} +#endif + +} diff --git a/Runtime/Graphics/Shaders/CXRayBlurFilterHLSL.cpp b/Runtime/Graphics/Shaders/CXRayBlurFilterHLSL.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/Runtime/Graphics/Shaders/CXRayBlurFilterMetal.cpp b/Runtime/Graphics/Shaders/CXRayBlurFilterMetal.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/Runtime/Graphics/Shaders/TMultiBlendShader.hpp b/Runtime/Graphics/Shaders/TMultiBlendShader.hpp index 38d17195d..74e46e91e 100644 --- a/Runtime/Graphics/Shaders/TMultiBlendShader.hpp +++ b/Runtime/Graphics/Shaders/TMultiBlendShader.hpp @@ -82,9 +82,9 @@ public: CCameraFilterPass::EFilterType type, FilterImp& filter) { - if (type == CCameraFilterPass::EFilterType::AdditiveAlpha) + if (type == CCameraFilterPass::EFilterType::Add) return m_bindFactory->BuildShaderDataBinding(ctx, m_additiveAlphaPipeline, m_vtxFmt, filter); - else if (type == CCameraFilterPass::EFilterType::ColorMultiply) + else if (type == CCameraFilterPass::EFilterType::Multiply) return m_bindFactory->BuildShaderDataBinding(ctx, m_colorMultiplyPipeline, m_vtxFmt, filter); else return m_bindFactory->BuildShaderDataBinding(ctx, m_alphaBlendPipeline, m_vtxFmt, filter); diff --git a/Runtime/MP1/MP1.cpp b/Runtime/MP1/MP1.cpp index 26b78ef54..207bb2dcb 100644 --- a/Runtime/MP1/MP1.cpp +++ b/Runtime/MP1/MP1.cpp @@ -5,12 +5,14 @@ #include "Graphics/Shaders/CSpaceWarpFilter.hpp" #include "Graphics/Shaders/CColoredQuadFilter.hpp" #include "Graphics/Shaders/CTexturedQuadFilter.hpp" +#include "Graphics/Shaders/CXRayBlurFilter.hpp" namespace urde { URDE_DECL_SPECIALIZE_SHADER(CThermalColdFilter) URDE_DECL_SPECIALIZE_SHADER(CThermalHotFilter) URDE_DECL_SPECIALIZE_SHADER(CSpaceWarpFilter) +URDE_DECL_SPECIALIZE_SHADER(CXRayBlurFilter) URDE_DECL_SPECIALIZE_MULTI_BLEND_SHADER(CColoredQuadFilter) URDE_DECL_SPECIALIZE_MULTI_BLEND_SHADER(CTexturedQuadFilter) @@ -35,6 +37,7 @@ CMain::BooSetter::BooSetter(boo::IGraphicsDataFactory* factory, TShader::Initialize(); TShader::Initialize(); TShader::Initialize(); + TShader::Initialize(); TMultiBlendShader::Initialize(); TMultiBlendShader::Initialize(); } @@ -82,6 +85,12 @@ bool CMain::Proc() void CMain::Shutdown() { + TShader::Shutdown(); + TShader::Shutdown(); + TShader::Shutdown(); + TShader::Shutdown(); + TMultiBlendShader::Shutdown(); + TMultiBlendShader::Shutdown(); } #if MP1_USE_BOO diff --git a/Runtime/World/CWorldTransManager.cpp b/Runtime/World/CWorldTransManager.cpp index 7ad93d3a6..2c082ab2a 100644 --- a/Runtime/World/CWorldTransManager.cpp +++ b/Runtime/World/CWorldTransManager.cpp @@ -9,11 +9,13 @@ #include "Character/IAnimReader.hpp" #include "Character/CSkinRules.hpp" #include "Graphics/CModel.hpp" +#include "Graphics/CBooRenderer.hpp" +#include "Camera/CCameraManager.hpp" namespace urde { -int CWorldTransManager::GetSuitCharSet() +int CWorldTransManager::GetSuitCharIdx() { CPlayerState& state = *g_GameState->GetPlayerState(); if (state.GetFusion()) @@ -77,7 +79,7 @@ void CWorldTransManager::UpdateDisabled(float) { if (x0_curTime <= 2.f) return; - x44_24_dissolveComplete = true; + x44_24_transFinished = true; } void CWorldTransManager::UpdateEnabled(float dt) @@ -88,12 +90,12 @@ void CWorldTransManager::UpdateEnabled(float dt) { x4_modelData->x1dc_dissolveStarted = true; x4_modelData->x1d0_dissolveStartTime = x0_curTime; - x4_modelData->x1d4_relativeDissolveStartTime = 4.f + x0_curTime - 2.f; - x4_modelData->x1d8_relativeDissolveEndTime = 5.f + x0_curTime - 2.f; + x4_modelData->x1d4_dissolveEndTime = 4.f + x0_curTime - 2.f; + x4_modelData->x1d8_transCompleteTime = 5.f + x0_curTime - 2.f; } - if (x0_curTime > x4_modelData->x1d8_relativeDissolveEndTime && x4_modelData->x1dc_dissolveStarted) - x44_24_dissolveComplete = true; + if (x0_curTime > x4_modelData->x1d8_transCompleteTime && x4_modelData->x1dc_dissolveStarted) + x44_24_transFinished = true; x4_modelData->x1c_samusModelData.AdvanceAnimationIgnoreParticles(dt, x20_random, true); x4_modelData->x170_gunXf = x4_modelData->x1c_samusModelData.GetScaledLocatorTransform("GUN_LCTR"); @@ -146,8 +148,63 @@ void CWorldTransManager::Update(float dt) } } +void CWorldTransManager::DrawAllModels() +{ +} + +void CWorldTransManager::DrawFirstPass() +{ + zeus::CTransform translateXf = + zeus::CTransform::Translate(x4_modelData->x1b4_shakeResult.x, + -3.5f * (1.f - zeus::clamp(0.f, x0_curTime / 10.f, 1.f)) - 3.5f, + x4_modelData->x1b4_shakeResult.y + 2.f); + zeus::CTransform rotateXf = + zeus::CTransform::RotateZ(zeus::degToRad(zeus::clamp(0.f, x0_curTime / 25.f, 100.f) * + 360.f + 180.f - 90.f)); + CGraphics::SetViewPointMatrix(rotateXf * translateXf); + DrawAllModels(); +} + +void CWorldTransManager::DrawSecondPass() +{ +} + void CWorldTransManager::DrawEnabled() { + g_Renderer->SetPerspective(CCameraManager::DefaultFirstPersonFOV(), + CGraphics::g_ViewportResolution.x / + float(CGraphics::g_ViewportResolution.y), + CCameraManager::DefaultNearPlane(), + CCameraManager::DefaultFarPlane()); + g_Renderer->x318_26_ = true; + + if (x0_curTime <= x4_modelData->x1d0_dissolveStartTime) + DrawFirstPass(); + else if (x0_curTime >= x4_modelData->x1d4_dissolveEndTime) + DrawSecondPass(); + else + { + float t = zeus::clamp(0.f, (x0_curTime - x4_modelData->x1d0_dissolveStartTime) / 2.f, 1.f); + DrawFirstPass(); + SClipScreenRect rect = {}; + rect.xc_width = CGraphics::g_ViewportResolution.x; + rect.x10_height = CGraphics::g_ViewportResolution.y; + CGraphics::ResolveSpareTexture(rect); + DrawSecondPass(); + m_dissolve.draw(zeus::CColor{1.f, 1.f, 1.f, t}, 1.f); + } + + m_widescreen.draw(zeus::CColor::skBlack, 1.f); + + float ftbT = 0.f; + if (x0_curTime < 0.25f) + ftbT = 1.f - x0_curTime / 0.25f; + else if (x0_curTime > x4_modelData->x1d8_transCompleteTime) + ftbT = 1.f; + else if (x0_curTime > x4_modelData->x1d8_transCompleteTime - 0.25f) + ftbT = 1.f - (x4_modelData->x1d8_transCompleteTime - x0_curTime) / 0.25f; + if (ftbT > 0.f) + m_fadeToBlack.draw(zeus::CColor{0.f, 0.f, 0.f, ftbT}); } void CWorldTransManager::DrawDisabled() @@ -187,7 +244,7 @@ void CWorldTransManager::TouchModels() x4_modelData->x164_suitSkin.IsLoaded() && x4_modelData->x164_suitSkin.GetObj()) { - CAnimRes animRes(x4_modelData->x0_samusRes.GetId(), GetSuitCharSet(), + CAnimRes animRes(x4_modelData->x0_samusRes.GetId(), GetSuitCharIdx(), x4_modelData->x0_samusRes.GetScale(), x4_modelData->x0_samusRes.GetDefaultAnim(), true); x4_modelData->x1c_samusModelData = animRes; @@ -232,7 +289,7 @@ void CWorldTransManager::EnableTransition(const CAnimRes& samusRes, x4_modelData->x14c_beamModel = g_SimplePool->GetObj(modelName.c_str()); TToken fac = g_CharFactoryBuilder->GetFactory(samusRes); - const CCharacterInfo& info = fac.GetObj()->GetCharInfo(GetSuitCharSet()); + const CCharacterInfo& info = fac.GetObj()->GetCharInfo(GetSuitCharIdx()); x4_modelData->x158_suitModel = g_SimplePool->GetObj(SObjectTag{FOURCC('CMDL'), info.GetModelId()}); x4_modelData->x164_suitSkin = g_SimplePool->GetObj(SObjectTag{FOURCC('CSKR'), info.GetSkinRulesId()}); @@ -290,7 +347,7 @@ void CWorldTransManager::StartTransition() { x0_curTime = 0.f; x18_bgOffset = 0.f; - x44_24_dissolveComplete = false; + x44_24_transFinished = false; x44_28_ = true; } diff --git a/Runtime/World/CWorldTransManager.hpp b/Runtime/World/CWorldTransManager.hpp index b0a632185..cbb7b6df1 100644 --- a/Runtime/World/CWorldTransManager.hpp +++ b/Runtime/World/CWorldTransManager.hpp @@ -7,6 +7,7 @@ #include "GuiSys/CGuiTextSupport.hpp" #include "Graphics/CLight.hpp" #include "Graphics/Shaders/CColoredQuadFilter.hpp" +#include "Graphics/Shaders/CTexturedQuadFilter.hpp" namespace urde { @@ -42,8 +43,8 @@ public: float x1c8_blurResult = 0.f; float x1cc_blurDelta = 0.f; float x1d0_dissolveStartTime = 99999.f; - float x1d4_relativeDissolveStartTime = 99999.f; - float x1d8_relativeDissolveEndTime = 99999.f; + float x1d4_dissolveEndTime = 99999.f; + float x1d8_transCompleteTime = 99999.f; bool x1dc_dissolveStarted = false; SModelDatas(const CAnimRes& samusRes); @@ -69,7 +70,7 @@ private: { struct { - bool x44_24_dissolveComplete : 1; + bool x44_24_transFinished : 1; bool x44_25_stopSoon : 1; bool x44_26_goingUp : 1; bool x44_27_ : 1; @@ -78,24 +79,28 @@ private: u8 dummy = 0; }; - CColoredQuadFilter m_fadeToBlack = { CCameraFilterPass::EFilterType::AlphaBlended }; + CColoredQuadFilter m_fadeToBlack = { CCameraFilterPass::EFilterType::Blend }; + CTexturedQuadFilter m_dissolve = { CCameraFilterPass::EFilterType::Blend, + CGraphics::g_SpareTexture }; + CWideScreenFilter m_widescreen = { CCameraFilterPass::EFilterType::Blend }; - static int GetSuitCharSet(); - -public: - CWorldTransManager() : x44_24_dissolveComplete(true) {} - - void DrawFirstPass() const {} - void DrawSecondPass() const {} - void DrawAllModels() const {} + static int GetSuitCharIdx(); + void DrawFirstPass(); + void DrawSecondPass(); + void DrawAllModels(); void UpdateLights(float dt); void UpdateEnabled(float); void UpdateDisabled(float); void UpdateText(float); - void Update(float); void DrawEnabled(); void DrawDisabled(); void DrawText(); + +public: + CWorldTransManager() : x44_24_transFinished(true) {} + + + void Update(float); void Draw(); void EnableTransition(const CAnimRes& samusRes, @@ -106,6 +111,7 @@ public: void StartTransition(); void EndTransition(); + bool IsTransitionFinished() const { return x44_24_transFinished; } void PleaseStopSoon() { x44_25_stopSoon = true; } bool IsTransitionEnabled() const { return x30_type != ETransType::Disabled; } void DisableTransition(); diff --git a/specter b/specter index 4efe7e484..d8186d24b 160000 --- a/specter +++ b/specter @@ -1 +1 @@ -Subproject commit 4efe7e48480f99f74da4fc8f546a09c7cb529485 +Subproject commit d8186d24b70a8ca885b4bd3e19e1f5402c076191