From 5c21e4892034d76d2076068245c818c1339dcd4d Mon Sep 17 00:00:00 2001 From: Luke Street Date: Mon, 14 Apr 2025 17:26:25 -0600 Subject: [PATCH] Migrate to DolphinCGraphics impl & cleanup old code aurora now uses the original model buffers, but byteswapped. Migrates over to the updated impl. --- CMakeLists.txt | 2 +- Runtime/AutoMapper/CAutoMapper.cpp | 18 +- Runtime/AutoMapper/CMapArea.cpp | 224 +-- Runtime/AutoMapper/CMapArea.hpp | 46 +- Runtime/AutoMapper/CMapUniverse.cpp | 3 +- Runtime/AutoMapper/CMapWorld.cpp | 106 +- Runtime/AutoMapper/CMappableObject.cpp | 309 ++-- Runtime/AutoMapper/CMappableObject.hpp | 21 +- Runtime/CMain.cpp | 4 +- Runtime/CMakeLists.txt | 2 +- Runtime/CStateManager.cpp | 51 +- Runtime/CStateManager.hpp | 6 +- Runtime/CTimeProvider.hpp | 1 + Runtime/Camera/CCameraFilter.cpp | 6 +- Runtime/Camera/CCameraFilter.hpp | 6 - Runtime/Camera/CGameCamera.cpp | 4 +- Runtime/Character/CAnimData.cpp | 10 +- Runtime/Character/CModelData.cpp | 22 +- Runtime/Character/CSkinRules.cpp | 16 +- Runtime/Character/CSkinRules.hpp | 4 +- Runtime/Collision/CCollisionActor.cpp | 23 +- Runtime/Collision/CCollisionActor.hpp | 3 - Runtime/Graphics/CBooRender.hpp.old | 303 ---- Runtime/Graphics/CBooRenderer.cpp | 1410 ---------------- Runtime/Graphics/CCubeMaterial.cpp | 164 +- Runtime/Graphics/CCubeModel.cpp | 64 +- Runtime/Graphics/CCubeModel.hpp | 66 +- Runtime/Graphics/CCubeRenderer.cpp | 116 +- Runtime/Graphics/CCubeRenderer.hpp | 2 +- Runtime/Graphics/CFont.cpp | 18 +- Runtime/Graphics/CGX.cpp | 8 + Runtime/Graphics/CGX.hpp | 61 +- Runtime/Graphics/CGraphics.cpp | 1418 ++++++++++------- Runtime/Graphics/CGraphics.hpp | 308 ++-- Runtime/Graphics/CLineRenderer.cpp | 360 ----- Runtime/Graphics/CLineRenderer.hpp | 73 - Runtime/Graphics/CMakeLists.txt | 26 +- Runtime/Graphics/CMetroidModelInstance.cpp | 53 +- Runtime/Graphics/CMetroidModelInstance.hpp | 34 +- Runtime/Graphics/CModel.cpp | 42 +- Runtime/Graphics/CModel.hpp | 11 +- Runtime/Graphics/CModel.hpp.old | 312 ---- Runtime/Graphics/CModelBoo.cpp | 1323 --------------- Runtime/Graphics/CMoviePlayer.cpp | 12 +- Runtime/Graphics/CRainSplashGenerator.cpp | 18 +- Runtime/Graphics/CRainSplashGenerator.hpp | 3 +- Runtime/Graphics/CSimpleShadow.cpp | 2 +- Runtime/Graphics/CSkinnedModel.cpp | 24 +- Runtime/Graphics/CSkinnedModel.hpp | 8 +- Runtime/Graphics/CTexture.hpp.old | 116 -- Runtime/Graphics/CTextureBoo.cpp | 939 ----------- Runtime/Graphics/CVertexMorphEffect.cpp | 14 +- Runtime/Graphics/IRenderer.hpp | 2 +- Runtime/Graphics/Shaders/CAABoxShader.cpp | 79 - Runtime/Graphics/Shaders/CAABoxShader.hpp | 32 - .../Graphics/Shaders/CCameraBlurFilter.cpp | 88 - .../Graphics/Shaders/CCameraBlurFilter.hpp | 27 - .../Graphics/Shaders/CColoredQuadFilter.cpp | 117 -- .../Graphics/Shaders/CColoredQuadFilter.hpp | 52 - .../Graphics/Shaders/CColoredStripShader.cpp | 84 - .../Graphics/Shaders/CColoredStripShader.hpp | 39 - Runtime/Graphics/Shaders/CDecalShaders.cpp | 72 - Runtime/Graphics/Shaders/CDecalShaders.hpp | 23 - .../Graphics/Shaders/CElementGenShaders.cpp | 298 ---- .../Graphics/Shaders/CElementGenShaders.hpp | 50 - Runtime/Graphics/Shaders/CEnergyBarShader.cpp | 95 -- Runtime/Graphics/Shaders/CEnergyBarShader.hpp | 44 - Runtime/Graphics/Shaders/CEnvFxShaders.cpp | 57 - Runtime/Graphics/Shaders/CEnvFxShaders.hpp | 41 - .../Graphics/Shaders/CFluidPlaneShader.cpp | 292 ---- .../Graphics/Shaders/CFluidPlaneShader.hpp | 178 --- Runtime/Graphics/Shaders/CFogVolumeFilter.cpp | 77 - Runtime/Graphics/Shaders/CFogVolumeFilter.hpp | 23 - .../Shaders/CFogVolumePlaneShader.cpp | 65 - .../Shaders/CFogVolumePlaneShader.hpp | 35 - .../Graphics/Shaders/CLineRendererShaders.cpp | 116 -- .../Graphics/Shaders/CLineRendererShaders.hpp | 33 - .../Graphics/Shaders/CMapSurfaceShader.cpp | 40 - .../Graphics/Shaders/CMapSurfaceShader.hpp | 30 - Runtime/Graphics/Shaders/CModelShaders.cpp | 235 --- Runtime/Graphics/Shaders/CModelShaders.hpp | 113 -- .../Shaders/CParticleSwooshShaders.cpp | 112 -- .../Shaders/CParticleSwooshShaders.hpp | 42 - .../Graphics/Shaders/CPhazonSuitFilter.cpp | 154 -- .../Graphics/Shaders/CPhazonSuitFilter.hpp | 30 - .../Graphics/Shaders/CRadarPaintShader.cpp | 57 - .../Graphics/Shaders/CRadarPaintShader.hpp | 36 - .../Graphics/Shaders/CRandomStaticFilter.cpp | 83 - .../Graphics/Shaders/CRandomStaticFilter.hpp | 42 - Runtime/Graphics/Shaders/CScanLinesFilter.cpp | 67 - Runtime/Graphics/Shaders/CScanLinesFilter.hpp | 43 - Runtime/Graphics/Shaders/CSpaceWarpFilter.cpp | 171 -- Runtime/Graphics/Shaders/CSpaceWarpFilter.hpp | 38 - .../Graphics/Shaders/CTextSupportShader.cpp | 81 - .../Graphics/Shaders/CTextSupportShader.hpp | 100 -- .../Graphics/Shaders/CTexturedQuadFilter.cpp | 346 ---- .../Graphics/Shaders/CTexturedQuadFilter.hpp | 70 - .../Graphics/Shaders/CThermalColdFilter.cpp | 62 - .../Graphics/Shaders/CThermalColdFilter.hpp | 39 - .../Graphics/Shaders/CThermalHotFilter.cpp | 60 - .../Graphics/Shaders/CThermalHotFilter.hpp | 30 - .../Graphics/Shaders/CWorldShadowShader.cpp | 90 -- .../Graphics/Shaders/CWorldShadowShader.hpp | 45 - Runtime/Graphics/Shaders/CXRayBlurFilter.cpp | 72 - Runtime/Graphics/Shaders/CXRayBlurFilter.hpp | 31 - Runtime/GuiSys/CAuiEnergyBarT01.cpp | 2 +- Runtime/GuiSys/CAuiEnergyBarT01.hpp | 1 - Runtime/GuiSys/CAuiImagePane.cpp | 4 +- Runtime/GuiSys/CCompoundTargetReticle.cpp | 59 +- Runtime/GuiSys/CCompoundTargetReticle.hpp | 8 - Runtime/GuiSys/CGuiFrame.cpp | 2 +- Runtime/GuiSys/CGuiPane.cpp | 2 +- Runtime/GuiSys/CGuiTextSupport.cpp | 2 +- Runtime/GuiSys/CHudRadarInterface.cpp | 2 +- Runtime/GuiSys/COrbitPointMarker.cpp | 2 +- Runtime/GuiSys/CScanDisplay.cpp | 2 +- Runtime/GuiSys/CSplashScreen.cpp | 2 +- Runtime/GuiSys/CTextRenderBuffer.cpp | 1 - Runtime/GuiSys/CTextRenderBuffer.hpp | 1 - Runtime/MP1/CInGameGuiManager.hpp | 1 - Runtime/MP1/CPlayerVisor.cpp | 4 +- Runtime/MP1/CSamusHud.hpp | 1 - Runtime/MP1/MP1.cpp | 1 - Runtime/MP1/Tweaks/CTweakAutoMapper.cpp | 4 +- Runtime/MP1/Tweaks/CTweakAutoMapper.hpp | 6 +- Runtime/MP1/World/CIceAttackProjectile.cpp | 2 +- Runtime/MP1/World/COmegaPirate.cpp | 10 +- Runtime/MP1/World/CThardus.cpp | 8 +- Runtime/Particle/CDecal.cpp | 1 - Runtime/Particle/CDecalManager.cpp | 5 - Runtime/Particle/CElementGen.cpp | 172 +- Runtime/Particle/CElementGen.hpp | 17 - Runtime/Particle/CParticleElectric.cpp | 2 +- Runtime/Particle/CParticleElectric.hpp | 4 - Runtime/Particle/CParticleSwoosh.cpp | 136 +- Runtime/Particle/CParticleSwoosh.hpp | 8 - Runtime/Tweaks/ITweakAutoMapper.hpp | 1 - Runtime/Weapon/CBomb.cpp | 2 +- Runtime/Weapon/CGrappleArm.cpp | 4 +- Runtime/Weapon/CGunWeapon.cpp | 2 +- Runtime/Weapon/CNewFlameThrower.cpp | 2 +- Runtime/Weapon/CPhazonBeam.cpp | 10 +- Runtime/Weapon/CPhazonBeam.hpp | 4 +- Runtime/Weapon/CPlasmaProjectile.cpp | 90 +- Runtime/Weapon/CPlasmaProjectile.hpp | 3 +- Runtime/Weapon/CPlayerGun.cpp | 24 +- Runtime/Weapon/CPowerBeam.cpp | 2 +- Runtime/Weapon/CWaveBuster.cpp | 26 +- Runtime/Weapon/CWaveBuster.hpp | 2 - Runtime/World/CActor.cpp | 44 +- Runtime/World/CActor.hpp | 3 - Runtime/World/CActorModelParticles.cpp | 33 +- Runtime/World/CEnvFxManager.cpp | 100 +- Runtime/World/CEnvFxManager.hpp | 4 +- Runtime/World/CFishCloud.cpp | 6 +- Runtime/World/CFluidPlane.cpp | 784 ++++----- Runtime/World/CFluidPlane.hpp | 23 +- Runtime/World/CFluidPlaneCPU.cpp | 320 ++-- Runtime/World/CFluidPlaneCPU.hpp | 6 +- Runtime/World/CFluidPlaneDoor.cpp | 88 +- Runtime/World/CFluidPlaneDoor.hpp | 5 +- Runtime/World/CFluidPlaneGPU.cpp | 120 +- Runtime/World/CFluidPlaneGPU.hpp | 6 +- Runtime/World/CGameArea.cpp | 26 +- Runtime/World/CGameArea.hpp | 2 +- Runtime/World/CMorphBallShadow.cpp | 13 +- Runtime/World/CPathFindSearch.cpp | 8 +- Runtime/World/CPathFindSearch.hpp | 3 - Runtime/World/CScriptMazeNode.cpp | 8 +- Runtime/World/CScriptMazeNode.hpp | 2 - Runtime/World/CScriptPlatform.cpp | 12 +- Runtime/World/CScriptPlatform.hpp | 3 - Runtime/World/CScriptTrigger.cpp | 4 +- Runtime/World/CScriptTrigger.hpp | 3 - Runtime/World/CSnakeWeedSwarm.cpp | 4 +- Runtime/World/CVisorFlare.cpp | 8 +- Runtime/World/CWallCrawlerSwarm.cpp | 10 +- Runtime/World/CWorldShadow.cpp | 11 +- Runtime/World/CWorldTransManager.cpp | 2 +- Shaders/CAABoxShader.shader | 125 -- Shaders/CCameraBlurFilter.shader | 242 --- Shaders/CColoredQuadFilter.shader | 131 -- Shaders/CColoredStripShader.shader | 155 -- Shaders/CDecalShaders.shader | 350 ---- Shaders/CElementGenShaders.shader | 787 --------- Shaders/CEnergyBarShader.shader | 138 -- Shaders/CEnvFxShaders.shader | 302 ---- Shaders/CFogVolumeFilter.shader | 237 --- Shaders/CFogVolumePlaneShader.shader | 91 -- Shaders/CLineRendererShaders.shader | 916 ----------- Shaders/CMakeLists.txt | 65 - Shaders/CMapSurfaceShader.shader | 118 -- Shaders/CModelShaders.common.glsl | 16 - Shaders/CModelShaders.common.hlsl | 15 - Shaders/CModelShaders.common.metal | 21 - Shaders/CModelShaders.frag.glsl | 372 ----- Shaders/CModelShaders.frag.hlsl | 373 ----- Shaders/CModelShaders.frag.metal | 389 ----- Shaders/CModelShaders.vert.glsl | 58 - Shaders/CModelShaders.vert.hlsl | 72 - Shaders/CModelShaders.vert.metal | 60 - Shaders/CMoviePlayerShader.shader | 155 -- Shaders/CNESShader.shader | 137 -- Shaders/CParticleSwooshShaders.shader | 245 --- Shaders/CPhazonSuitFilter.shader | 485 ------ Shaders/CRadarPaintShader.shader | 148 -- Shaders/CRandomStaticFilter.shader | 301 ---- Shaders/CScanLinesFilter.shader | 124 -- Shaders/CSpaceWarpFilter.shader | 156 -- Shaders/CTextSupportShader.shader | 351 ---- Shaders/CTexturedQuadFilter.shader | 292 ---- Shaders/CThermalColdFilter.shader | 257 --- Shaders/CThermalHotFilter.shader | 144 -- Shaders/CWorldShadowShader.shader | 122 -- Shaders/CXRayBlurFilter.shader | 254 --- Shaders/shader_CFluidPlaneShader.cpp | 10 - Shaders/shader_CFluidPlaneShader.hpp | 112 -- Shaders/shader_CFluidPlaneShaderGLSL.cpp | 785 --------- Shaders/shader_CFluidPlaneShaderHLSL.cpp | 771 --------- Shaders/shader_CFluidPlaneShaderMetal.cpp | 762 --------- Shaders/shader_CModelShaders.hpp | 68 - Shaders/shader_CModelShadersGLSL.cpp | 286 ---- Shaders/shader_CModelShadersHLSL.cpp | 197 --- Shaders/shader_CModelShadersMetal.cpp | 218 --- extern/CMakeLists.txt | 1 - extern/aurora | 2 +- extern/musyx | 2 +- extern/zeus | 2 +- imgui/ImGuiEngine.cpp | 10 +- 229 files changed, 3029 insertions(+), 23239 deletions(-) delete mode 100644 Runtime/Graphics/CBooRender.hpp.old delete mode 100644 Runtime/Graphics/CBooRenderer.cpp delete mode 100644 Runtime/Graphics/CLineRenderer.cpp delete mode 100644 Runtime/Graphics/CLineRenderer.hpp delete mode 100644 Runtime/Graphics/CModel.hpp.old delete mode 100644 Runtime/Graphics/CModelBoo.cpp delete mode 100644 Runtime/Graphics/CTexture.hpp.old delete mode 100644 Runtime/Graphics/CTextureBoo.cpp delete mode 100644 Runtime/Graphics/Shaders/CAABoxShader.cpp delete mode 100644 Runtime/Graphics/Shaders/CAABoxShader.hpp delete mode 100644 Runtime/Graphics/Shaders/CCameraBlurFilter.cpp delete mode 100644 Runtime/Graphics/Shaders/CCameraBlurFilter.hpp delete mode 100644 Runtime/Graphics/Shaders/CColoredQuadFilter.cpp delete mode 100644 Runtime/Graphics/Shaders/CColoredQuadFilter.hpp delete mode 100644 Runtime/Graphics/Shaders/CColoredStripShader.cpp delete mode 100644 Runtime/Graphics/Shaders/CColoredStripShader.hpp delete mode 100644 Runtime/Graphics/Shaders/CDecalShaders.cpp delete mode 100644 Runtime/Graphics/Shaders/CDecalShaders.hpp delete mode 100644 Runtime/Graphics/Shaders/CElementGenShaders.cpp delete mode 100644 Runtime/Graphics/Shaders/CElementGenShaders.hpp delete mode 100644 Runtime/Graphics/Shaders/CEnergyBarShader.cpp delete mode 100644 Runtime/Graphics/Shaders/CEnergyBarShader.hpp delete mode 100644 Runtime/Graphics/Shaders/CEnvFxShaders.cpp delete mode 100644 Runtime/Graphics/Shaders/CEnvFxShaders.hpp delete mode 100644 Runtime/Graphics/Shaders/CFluidPlaneShader.cpp delete mode 100644 Runtime/Graphics/Shaders/CFluidPlaneShader.hpp delete mode 100644 Runtime/Graphics/Shaders/CFogVolumeFilter.cpp delete mode 100644 Runtime/Graphics/Shaders/CFogVolumeFilter.hpp delete mode 100644 Runtime/Graphics/Shaders/CFogVolumePlaneShader.cpp delete mode 100644 Runtime/Graphics/Shaders/CFogVolumePlaneShader.hpp delete mode 100644 Runtime/Graphics/Shaders/CLineRendererShaders.cpp delete mode 100644 Runtime/Graphics/Shaders/CLineRendererShaders.hpp delete mode 100644 Runtime/Graphics/Shaders/CMapSurfaceShader.cpp delete mode 100644 Runtime/Graphics/Shaders/CMapSurfaceShader.hpp delete mode 100644 Runtime/Graphics/Shaders/CModelShaders.cpp delete mode 100644 Runtime/Graphics/Shaders/CModelShaders.hpp delete mode 100644 Runtime/Graphics/Shaders/CParticleSwooshShaders.cpp delete mode 100644 Runtime/Graphics/Shaders/CParticleSwooshShaders.hpp delete mode 100644 Runtime/Graphics/Shaders/CPhazonSuitFilter.cpp delete mode 100644 Runtime/Graphics/Shaders/CPhazonSuitFilter.hpp delete mode 100644 Runtime/Graphics/Shaders/CRadarPaintShader.cpp delete mode 100644 Runtime/Graphics/Shaders/CRadarPaintShader.hpp delete mode 100644 Runtime/Graphics/Shaders/CRandomStaticFilter.cpp delete mode 100644 Runtime/Graphics/Shaders/CRandomStaticFilter.hpp delete mode 100644 Runtime/Graphics/Shaders/CScanLinesFilter.cpp delete mode 100644 Runtime/Graphics/Shaders/CScanLinesFilter.hpp delete mode 100644 Runtime/Graphics/Shaders/CSpaceWarpFilter.cpp delete mode 100644 Runtime/Graphics/Shaders/CSpaceWarpFilter.hpp delete mode 100644 Runtime/Graphics/Shaders/CTextSupportShader.cpp delete mode 100644 Runtime/Graphics/Shaders/CTextSupportShader.hpp delete mode 100644 Runtime/Graphics/Shaders/CTexturedQuadFilter.cpp delete mode 100644 Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp delete mode 100644 Runtime/Graphics/Shaders/CThermalColdFilter.cpp delete mode 100644 Runtime/Graphics/Shaders/CThermalColdFilter.hpp delete mode 100644 Runtime/Graphics/Shaders/CThermalHotFilter.cpp delete mode 100644 Runtime/Graphics/Shaders/CThermalHotFilter.hpp delete mode 100644 Runtime/Graphics/Shaders/CWorldShadowShader.cpp delete mode 100644 Runtime/Graphics/Shaders/CWorldShadowShader.hpp delete mode 100644 Runtime/Graphics/Shaders/CXRayBlurFilter.cpp delete mode 100644 Runtime/Graphics/Shaders/CXRayBlurFilter.hpp delete mode 100644 Shaders/CAABoxShader.shader delete mode 100644 Shaders/CCameraBlurFilter.shader delete mode 100644 Shaders/CColoredQuadFilter.shader delete mode 100644 Shaders/CColoredStripShader.shader delete mode 100644 Shaders/CDecalShaders.shader delete mode 100644 Shaders/CElementGenShaders.shader delete mode 100644 Shaders/CEnergyBarShader.shader delete mode 100644 Shaders/CEnvFxShaders.shader delete mode 100644 Shaders/CFogVolumeFilter.shader delete mode 100644 Shaders/CFogVolumePlaneShader.shader delete mode 100644 Shaders/CLineRendererShaders.shader delete mode 100644 Shaders/CMakeLists.txt delete mode 100644 Shaders/CMapSurfaceShader.shader delete mode 100644 Shaders/CModelShaders.common.glsl delete mode 100644 Shaders/CModelShaders.common.hlsl delete mode 100644 Shaders/CModelShaders.common.metal delete mode 100644 Shaders/CModelShaders.frag.glsl delete mode 100644 Shaders/CModelShaders.frag.hlsl delete mode 100644 Shaders/CModelShaders.frag.metal delete mode 100644 Shaders/CModelShaders.vert.glsl delete mode 100644 Shaders/CModelShaders.vert.hlsl delete mode 100644 Shaders/CModelShaders.vert.metal delete mode 100644 Shaders/CMoviePlayerShader.shader delete mode 100644 Shaders/CNESShader.shader delete mode 100644 Shaders/CParticleSwooshShaders.shader delete mode 100644 Shaders/CPhazonSuitFilter.shader delete mode 100644 Shaders/CRadarPaintShader.shader delete mode 100644 Shaders/CRandomStaticFilter.shader delete mode 100644 Shaders/CScanLinesFilter.shader delete mode 100644 Shaders/CSpaceWarpFilter.shader delete mode 100644 Shaders/CTextSupportShader.shader delete mode 100644 Shaders/CTexturedQuadFilter.shader delete mode 100644 Shaders/CThermalColdFilter.shader delete mode 100644 Shaders/CThermalHotFilter.shader delete mode 100644 Shaders/CWorldShadowShader.shader delete mode 100644 Shaders/CXRayBlurFilter.shader delete mode 100644 Shaders/shader_CFluidPlaneShader.cpp delete mode 100644 Shaders/shader_CFluidPlaneShader.hpp delete mode 100644 Shaders/shader_CFluidPlaneShaderGLSL.cpp delete mode 100644 Shaders/shader_CFluidPlaneShaderHLSL.cpp delete mode 100644 Shaders/shader_CFluidPlaneShaderMetal.cpp delete mode 100644 Shaders/shader_CModelShaders.hpp delete mode 100644 Shaders/shader_CModelShadersGLSL.cpp delete mode 100644 Shaders/shader_CModelShadersHLSL.cpp delete mode 100644 Shaders/shader_CModelShadersMetal.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c52b280d..0a8c56614 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -328,7 +328,7 @@ set(ZLIB_LIBRARIES ZLIB::ZLIB CACHE STRING "zlib libraries" FORCE) include(ExternalProject) ExternalProject_Add(bintoc SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/bintoc" - CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH= + CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH= -DCMAKE_TOOLCHAIN_FILE:PATH=${CMAKE_TOOLCHAIN_FILE} -DVCPKG_TARGET_TRIPLET:STRING=${VCPKG_TARGET_TRIPLET} INSTALL_COMMAND ${CMAKE_COMMAND} --build . --config Release --target install) include(${CMAKE_CURRENT_LIST_DIR}/bintoc/bintocHelpers.cmake) diff --git a/Runtime/AutoMapper/CAutoMapper.cpp b/Runtime/AutoMapper/CAutoMapper.cpp index 28e090aad..9f6a4d853 100644 --- a/Runtime/AutoMapper/CAutoMapper.cpp +++ b/Runtime/AutoMapper/CAutoMapper.cpp @@ -1049,8 +1049,7 @@ void CAutoMapper::ProcessControllerInput(const CFinalInput& input, CStateManager x308_textpane_instructions2->TextSupport().SetText(u""); } else { x2fc_textpane_hint->TextSupport().SetText(u""); - std::u16string str = - fmt::format(u"&image=SI,0.6,1.0,{};", g_tweakPlayerRes->x24_lStick[x2e4_lStickPos]); + std::u16string str = fmt::format(u"&image=SI,0.6,1.0,{};", g_tweakPlayerRes->x24_lStick[x2e4_lStickPos]); str += g_MainStringTable->GetString(46 + (!g_Main->IsUSA() || g_Main->IsTrilogy())); // Rotate x300_textpane_instructions->TextSupport().SetText(str); str = fmt::format(u"&image=SI,0.6,1.0,{};", g_tweakPlayerRes->x4c_cStick[x2e8_rStickPos]); @@ -1083,8 +1082,7 @@ void CAutoMapper::ProcessControllerInput(const CFinalInput& input, CStateManager } } - if (input.PZ() || input.PSpecialKey(ESpecialKey::Tab) || input.PB() || - input.PSpecialKey(ESpecialKey::Esc)) { + if (input.PZ() || input.PSpecialKey(ESpecialKey::Tab) || input.PB() || input.PSpecialKey(ESpecialKey::Esc)) { if (x328_ == 0) { if (CanLeaveMapScreenInternal(mgr)) { LeaveMapScreen(mgr); @@ -1295,8 +1293,9 @@ void CAutoMapper::Update(float dt, CStateManager& mgr) { void CAutoMapper::Draw(const CStateManager& mgr, const zeus::CTransform& xf, float alpha) { SCOPED_GRAPHICS_DEBUG_GROUP("CAutoMapper::Draw", zeus::skPurple); alpha *= g_GameState->GameOptions().GetHUDAlpha() / 255.f; - // Blend mode alpha - // Backface cull + g_Renderer->SetBlendMode_AlphaBlended(); + CGraphics::SetCullMode(ERglCullMode::Front); + float alphaInterp; if (x1bc_state != EAutoMapperState::MiniMap && x1c0_nextState != EAutoMapperState::MiniMap) { alphaInterp = 1.f; @@ -1496,9 +1495,10 @@ void CAutoMapper::Draw(const CStateManager& mgr, const zeus::CTransform& xf, flo } } - // No zread, no zwrite - // Ambient color white - // Disable all lights + g_Renderer->SetDepthReadWrite(false, false); + g_Renderer->SetAmbientColor(zeus::skWhite); + CGraphics::DisableAllLights(); + if (m_frmeInitialized) { float frmeAlpha = 0.f; if (x1bc_state != EAutoMapperState::MiniMap && x1c0_nextState != EAutoMapperState::MiniMap) { diff --git a/Runtime/AutoMapper/CMapArea.cpp b/Runtime/AutoMapper/CMapArea.cpp index 7fd5283b2..ee88cf2af 100644 --- a/Runtime/AutoMapper/CMapArea.cpp +++ b/Runtime/AutoMapper/CMapArea.cpp @@ -8,6 +8,7 @@ #include "Runtime/GameGlobalObjects.hpp" #include "Runtime/World/CWorld.hpp" #include "Runtime/CBasics.hpp" +#include "Runtime/Graphics/CGX.hpp" namespace metaforce { constexpr std::array MinesPostTransforms{{ @@ -101,49 +102,10 @@ void CMapArea::PostConstruct() { tmp += 12; } - std::vector index; m_surfaces.reserve(x30_surfaceCount); for (u32 i = 0, j = 0; i < x30_surfaceCount; ++i, j += 32) { - m_surfaces.emplace_back(x40_surfaceStart + j).PostConstruct(x44_buf.get(), index); + m_surfaces.emplace_back(x40_surfaceStart + j).PostConstruct(x44_buf.get()); } - -// CGraphics::CommitResources([this, &index](boo::IGraphicsDataFactory::Context& ctx) { -// m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, m_verts.data(), 16, m_verts.size()); -// m_ibo = ctx.newStaticBuffer(boo::BufferUse::Index, index.data(), 4, index.size()); -// -// /* Only the map universe specifies Always; it draws a maximum of 1016 instances */ -// size_t instCount = (xc_visibilityMode == EVisMode::Always) ? 1024 : 1; -// -// for (u32 i = 0; i < x30_surfaceCount; ++i) { -// CMapAreaSurface& surf = m_surfaces[i]; -// surf.m_instances.reserve(instCount); -// for (u32 inst = 0; inst < instCount; ++inst) { -// CMapAreaSurface::Instance& instance = surf.m_instances.emplace_back(ctx, m_vbo, m_ibo); -// -// athena::io::MemoryReader r(surf.x1c_outlineOffset, INT_MAX); -// u32 outlineCount = r.ReadLong(); -// -// std::vector& linePrims = instance.m_linePrims; -// linePrims.reserve(outlineCount * 2); -// for (u32 j = 0; j < 2; ++j) { -// r.seek(4, athena::SeekOrigin::Begin); -// for (u32 k = 0; k < outlineCount; ++k) { -// const u32 count = r.ReadLong(); -// r.seek(count); -// r.seekAlign4(); -// linePrims.emplace_back(ctx, CLineRenderer::EPrimitiveMode::LineStrip, count, nullptr, false, false, true); -// } -// } -// } -// } -// -// for (u32 i = 0; i < x28_mappableObjCount; ++i) { -// CMappableObject& mapObj = m_mappableObjects[i]; -// if (CMappableObject::IsDoorType(mapObj.GetType())) -// mapObj.CreateDoorSurface(ctx); -// } -// return true; -// } BooTrace); } bool CMapArea::GetIsVisibleToAutoMapper(bool worldVis, bool areaVis) const { @@ -183,129 +145,87 @@ CMapArea::CMapAreaSurface::CMapAreaSurface(const void* surfBuf) { CMemoryInStream r(surfBuf, 32, CMemoryInStream::EOwnerShip::NotOwned); x0_normal = r.Get(); xc_centroid = r.Get(); - x18_surfOffset = reinterpret_cast(uintptr_t(r.ReadLong())); - x1c_outlineOffset = reinterpret_cast(uintptr_t(r.ReadLong())); + x18_surfOffset = reinterpret_cast(static_cast(r.ReadLong())); + x1c_outlineOffset = reinterpret_cast(static_cast(r.ReadLong())); } -void CMapArea::CMapAreaSurface::PostConstruct(const u8* buf, std::vector& index) { - x18_surfOffset = buf + reinterpret_cast(x18_surfOffset); - x1c_outlineOffset = buf + reinterpret_cast(x1c_outlineOffset); +void CMapArea::CMapAreaSurface::PostConstruct(const void* buf) { + x18_surfOffset = + reinterpret_cast(static_cast(buf) + reinterpret_cast(x18_surfOffset)); + x1c_outlineOffset = + reinterpret_cast(static_cast(buf) + reinterpret_cast(x1c_outlineOffset)); +} - m_primStart = index.size(); - bool start = true; - { - CMemoryInStream r(x18_surfOffset, INT_MAX, CMemoryInStream::EOwnerShip::NotOwned); - u32 primCount = r.ReadLong(); - for (u32 i = 0; i < primCount; ++i) { - GXPrimitive prim = GXPrimitive(r.ReadLong()); - u32 count = r.ReadLong(); - switch (prim) { - case GX_TRIANGLES: { - for (u32 v = 0; v < count; v += 3) { - if (!start) { - index.push_back(index.back()); - index.push_back(r.ReadUint8()); - index.push_back(index.back()); - } else { - index.push_back(r.ReadUint8()); - start = false; - } - index.push_back(r.ReadUint8()); - index.push_back(r.ReadUint8()); - index.push_back(index.back()); - } - break; +void CMapArea::CMapAreaSurface::Draw(TConstVectorRef verts, const CColor& surfColor, const CColor& lineColor, + float lineWidth) const { + bool hasSurfAlpha = surfColor.a() > 0.0f; + bool hasLineAlpha = lineColor.a() > 0.0f; + u32 numSurfaces = CBasics::SwapBytes(*x18_surfOffset); + u32 numOutlines = CBasics::SwapBytes(*x1c_outlineOffset); + if (!verts.empty()) { + CGX::SetArray(GX_VA_POS, verts); + } + if (hasSurfAlpha) { + CGX::SetTevKColor(GX_KCOLOR0, surfColor); + const u32* surface = &x18_surfOffset[1]; + for (u32 i = 0; i < numSurfaces; ++i) { + GXPrimitive primType = static_cast(CBasics::SwapBytes(*surface++)); + u32 numVertices = CBasics::SwapBytes(*surface++); + const u8* data = reinterpret_cast(surface); + surface += ((numVertices + 3) & ~3) / 4; + + CGX::Begin(primType, GX_VTXFMT0, numVertices); + for (u32 v = 0; v < numVertices; ++v) { + GXPosition1x8(data[v]); } - case GX_TRIANGLESTRIP: { - if (!start) { - index.push_back(index.back()); - index.push_back(r.ReadUint8()); - index.push_back(index.back()); - } else { - index.push_back(r.ReadUint8()); - start = false; - } - for (u32 v = 1; v < count; ++v) - index.push_back(r.ReadUint8()); - if (count & 1) - index.push_back(index.back()); - break; + CGX::End(); + } + } + if (hasLineAlpha) { + bool thickLine = lineWidth > 1.f; + for (u32 j = 0; j < (thickLine ? 1 : 0) + 1; ++j) { + const u32* outline = &x1c_outlineOffset[1]; + + if (thickLine) { + CGraphics::SetLineWidth(lineWidth - j, ERglTexOffset::One); } - case GX_TRIANGLEFAN: { - u8 firstVert = r.ReadUint8(); - if (!start) { - index.push_back(index.back()); - index.push_back(r.ReadUint8()); - } else { - index.push_back(r.ReadUint8()); - index.push_back(index.back()); - start = false; - } - for (u32 v = 1; v < count; ++v) { - index.push_back(firstVert); - index.push_back(r.ReadUint8()); - } - break; + CColor clr = lineColor; + if (thickLine) { + clr.a() *= 0.5f; } - default: - break; - } - u32 pos = r.GetReadPosition(); - while (r.GetReadPosition() != ROUND_UP_4(pos)) { - r.ReadUint8(); + CGX::SetTevKColor(GX_KCOLOR0, clr); + + for (u32 i = 0; i < numOutlines; ++i) { + u32 numVertices = CBasics::SwapBytes(*outline++); + const u8* data = reinterpret_cast(outline); + outline += ((numVertices + 3) & ~3) / 4; + + CGX::Begin(GX_LINESTRIP, GX_VTXFMT0, numVertices); + for (u32 v = 0; v < numVertices; ++v) { + GXPosition1x8(data[v]); + } + CGX::End(); } } } - m_primCount = index.size() - m_primStart; } -void CMapArea::CMapAreaSurface::Draw(const zeus::CVector3f* verts, const zeus::CColor& surfColor, - const zeus::CColor& lineColor, float lineWidth, size_t instIdx) { - if (instIdx >= m_instances.size()) { - return; - } - - Instance& instance = m_instances[instIdx]; - - if (surfColor.a()) { - instance.m_surfacePrims.draw(surfColor, m_primStart, m_primCount); - } - - if (lineColor.a()) { - bool draw2 = lineWidth > 1.f; - u32 outlineCount = *reinterpret_cast(x1c_outlineOffset); -#if METAFORCE_TARGET_BYTE_ORDER == __ORDER_LITTLE_ENDIAN__ - outlineCount = CBasics::SwapBytes(outlineCount); -#endif - - std::vector& linePrims = instance.m_linePrims; - zeus::CColor color = lineColor; - if (draw2) - color.a() *= 0.5f; - float width = lineWidth; - - auto primIt = linePrims.begin(); - for (u32 j = 0; j <= u32(draw2); ++j) { - CMemoryInStream r(x1c_outlineOffset, INT_MAX, CMemoryInStream::EOwnerShip::NotOwned); - r.ReadLong(); - for (u32 i = 0; i < outlineCount; ++i) { - CLineRenderer& prim = *primIt++; - prim.Reset(); - u32 count = r.ReadLong(); - for (u32 v = 0; v < count; ++v) { - u8 idx = r.ReadUint8(); - prim.AddVertex(verts[idx], color, width); - } - - u32 pos = r.GetReadPosition(); - while (r.GetReadPosition() != ROUND_UP_4(pos)) { - r.ReadUint8(); - } - prim.Render(); - } - width -= 1.f; - } - } +void CMapArea::CMapAreaSurface::SetupGXMaterial() { + const GXVtxDescList list[2] = { + {GX_VA_POS, GX_INDEX8}, + {GX_VA_NULL, GX_NONE}, + }; + CGX::SetVtxDescv(list); + CGX::SetNumChans(1); + CGX::SetNumTexGens(0); + CGX::SetNumTevStages(1); + CGX::SetChanCtrl(CGX::EChannelId::Channel0, false, GX_SRC_REG, GX_SRC_VTX, GX_LIGHT_NULL, GX_DF_NONE, GX_AF_NONE); + CGX::SetTevColorIn(GX_TEVSTAGE0, GX_CC_ZERO, GX_CC_ZERO, GX_CC_ZERO, GX_CC_KONST); + CGX::SetTevAlphaIn(GX_TEVSTAGE0, GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO, GX_CA_KONST); + CGX::SetTevColorOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, true, GX_TEVPREV); + CGX::SetTevAlphaOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, true, GX_TEVPREV); + CGX::SetTevKColorSel(GX_TEVSTAGE0, GX_TEV_KCSEL_K0); + CGX::SetTevKAlphaSel(GX_TEVSTAGE0, GX_TEV_KASEL_K0_A); } CFactoryFnReturn FMapAreaFactory(const SObjectTag& objTag, CInputStream& in, const CVParamTransfer&, diff --git a/Runtime/AutoMapper/CMapArea.hpp b/Runtime/AutoMapper/CMapArea.hpp index 642ad0b97..f7bd81daf 100644 --- a/Runtime/AutoMapper/CMapArea.hpp +++ b/Runtime/AutoMapper/CMapArea.hpp @@ -3,46 +3,38 @@ #include #include +#include "Runtime/Graphics/CCubeModel.hpp" #include "Runtime/AutoMapper/CMappableObject.hpp" #include "Runtime/CResFactory.hpp" -#include "Runtime/Graphics/CLineRenderer.hpp" -#include "Runtime/Graphics/Shaders/CMapSurfaceShader.hpp" #include "Runtime/RetroTypes.hpp" #include #include namespace metaforce { +using CColor = zeus::CColor; +using CVector3f = zeus::CVector3f; + class IWorld; class CMapArea { public: class CMapAreaSurface { friend class CMapArea; - zeus::CVector3f x0_normal; - zeus::CVector3f xc_centroid; - const u8* x18_surfOffset; - const u8* x1c_outlineOffset; - u32 m_primStart; - u32 m_primCount; - struct Instance { - CMapSurfaceShader m_surfacePrims; - std::vector m_linePrims; - Instance(std::vector vbo, - std::vector ibo) - : m_surfacePrims(vbo, ibo) {} - Instance(Instance&&) = default; - Instance& operator=(Instance&&) = default; - }; - std::vector m_instances; + CVector3f x0_normal; + CVector3f xc_centroid; + const u32* x18_surfOffset; + const u32* x1c_outlineOffset; public: explicit CMapAreaSurface(const void* surfBuf); - CMapAreaSurface(CMapAreaSurface&&) = default; - void PostConstruct(const u8* buf, std::vector& index); - void Draw(const zeus::CVector3f* verts, const zeus::CColor& surfColor, const zeus::CColor& lineColor, - float lineWidth, size_t instIdx = 0); - const zeus::CVector3f& GetNormal() const { return x0_normal; } - const zeus::CVector3f& GetCenterPosition() const { return xc_centroid; } + + void PostConstruct(const void* buf); + void Draw(TConstVectorRef verts, const CColor& surfColor, const CColor& lineColor, float lineWidth) const; + + static void SetupGXMaterial(); + + const CVector3f& GetNormal() const { return x0_normal; } + const CVector3f& GetCenterPosition() const { return xc_centroid; } }; enum class EVisMode { Always, MapStationOrVisit, Visit, Never }; @@ -59,12 +51,10 @@ private: u8* x38_moStart; std::vector m_mappableObjects; u8* x3c_vertexStart; - std::vector m_verts; + std::vector> m_verts; u8* x40_surfaceStart; std::vector m_surfaces; std::unique_ptr x44_buf; -// boo::ObjToken m_vbo; -// boo::ObjToken m_ibo; public: explicit CMapArea(CInputStream& in, u32 size); @@ -80,7 +70,7 @@ public: u32 GetNumSurfaces() const { return m_surfaces.size(); } zeus::CTransform GetAreaPostTransform(const IWorld& world, TAreaId aid) const; static const zeus::CVector3f& GetAreaPostTranslate(const IWorld& world, TAreaId aid); - const zeus::CVector3f* GetVertices() const { return m_verts.data(); } + TConstVectorRef GetVertices() const { return m_verts; } }; CFactoryFnReturn FMapAreaFactory(const SObjectTag& objTag, CInputStream& in, const CVParamTransfer&, CObjectReference*); diff --git a/Runtime/AutoMapper/CMapUniverse.cpp b/Runtime/AutoMapper/CMapUniverse.cpp index 329738b06..bf7efd7e3 100644 --- a/Runtime/AutoMapper/CMapUniverse.cpp +++ b/Runtime/AutoMapper/CMapUniverse.cpp @@ -85,7 +85,6 @@ void CMapUniverse::Draw(const CMapUniverseDrawParms& parms, const zeus::CVector3 int lastWldIdx = -1; int lastHexIdx = -1; - size_t instIdx = 0; for (const CMapObjectSortInfo& info : sortInfos) { const CMapWorldData& mwData = x10_worldDatas[info.GetWorldIndex()]; zeus::CColor surfColor = info.GetSurfaceColor(); @@ -110,7 +109,7 @@ void CMapUniverse::Draw(const CMapUniverseDrawParms& parms, const zeus::CVector3 if (info.GetAreaIndex() != lastHexIdx || info.GetWorldIndex() != lastWldIdx) CGraphics::SetModelMatrix(parms.GetPaneProjectionTransform() * mwData.GetMapAreaData(info.GetAreaIndex())); - surf.Draw(x4_hexagonToken->GetVertices(), surfColor, outlineColor, 2.f, instIdx++); + surf.Draw(x4_hexagonToken->GetVertices(), surfColor, outlineColor, 2.f); } } diff --git a/Runtime/AutoMapper/CMapWorld.cpp b/Runtime/AutoMapper/CMapWorld.cpp index 612e15fd0..632a0ac26 100644 --- a/Runtime/AutoMapper/CMapWorld.cpp +++ b/Runtime/AutoMapper/CMapWorld.cpp @@ -8,6 +8,7 @@ #include "Runtime/GameGlobalObjects.hpp" #include "Runtime/AutoMapper/CMapWorldInfo.hpp" #include "Runtime/World/CWorld.hpp" +#include "Runtime/Graphics/CCubeRenderer.hpp" namespace metaforce { namespace { @@ -460,8 +461,8 @@ bool CMapWorld::IsMapAreaValid(const IWorld& wld, int areaIdx, bool checkLoad) c void CMapWorld::DrawAreas(const CMapWorldDrawParms& parms, int selArea, const std::vector& bfsInfos, bool inMapScreen) { - // Alpha blend - // Line width 1 + g_Renderer->SetBlendMode_AlphaBlended(); + CGraphics::SetLineWidth(1.f, ERglTexOffset::One); int surfCount = 0; int objCount = 0; @@ -556,7 +557,7 @@ void CMapWorld::DrawAreas(const CMapWorldDrawParms& parms, int selArea, const st u32 si = 0; for (; i < mapa->GetNumMappableObjects(); ++i, si += 6) { const CMappableObject& obj = mapa->GetMappableObject(i); - if (!obj.IsVisibleToAutoMapper(mwInfo.IsWorldVisible(thisArea), mwInfo)) + if (!obj.GetIsVisibleToAutoMapper(mwInfo.IsWorldVisible(thisArea), mwInfo)) continue; bool doorType = CMappableObject::IsDoorType(obj.GetType()); @@ -582,58 +583,61 @@ void CMapWorld::DrawAreas(const CMapWorldDrawParms& parms, int selArea, const st } } - std::sort(sortInfos.begin(), sortInfos.end(), [](const CMapObjectSortInfo& a, const CMapObjectSortInfo& b) { - return a.GetZDistance() > b.GetZDistance(); - }); + if (!sortInfos.empty()) { + std::sort(sortInfos.begin(), sortInfos.end(), [](const CMapObjectSortInfo& a, const CMapObjectSortInfo& b) { + return a.GetZDistance() > b.GetZDistance(); + }); + CMapArea::CMapAreaSurface::SetupGXMaterial(); - u32 lastAreaIdx = UINT32_MAX; - CMapObjectSortInfo::EObjectCode lastType = CMapObjectSortInfo::EObjectCode::Invalid; - for (const CMapObjectSortInfo& info : sortInfos) { - CMapArea* mapa = GetMapArea(info.GetAreaIndex()); - zeus::CTransform areaPostXf = mapa->GetAreaPostTransform(parms.GetWorld(), info.GetAreaIndex()); - if (info.GetObjectCode() == CMapObjectSortInfo::EObjectCode::Surface) { - CMapArea::CMapAreaSurface& surf = mapa->GetSurface(info.GetLocalObjectIndex()); - zeus::CColor color( - std::max(0.f, (-parms.GetCameraTransform().basis[1]).dot(areaPostXf.rotate(surf.GetNormal()))) * - g_tweakAutoMapper->GetMapSurfaceNormColorLinear() + - g_tweakAutoMapper->GetMapSurfaceNormColorConstant()); - color *= info.GetSurfaceColor(); - if (lastAreaIdx != info.GetAreaIndex() || lastType != CMapObjectSortInfo::EObjectCode::Surface) { - CGraphics::SetModelMatrix(parms.GetPlaneProjectionTransform() * areaPostXf); + u32 lastAreaIdx = UINT32_MAX; + CMapObjectSortInfo::EObjectCode lastType = CMapObjectSortInfo::EObjectCode::Invalid; + for (const CMapObjectSortInfo& info : sortInfos) { + CMapArea* mapa = GetMapArea(info.GetAreaIndex()); + zeus::CTransform areaPostXf = mapa->GetAreaPostTransform(parms.GetWorld(), info.GetAreaIndex()); + if (info.GetObjectCode() == CMapObjectSortInfo::EObjectCode::Surface) { + CMapArea::CMapAreaSurface& surf = mapa->GetSurface(info.GetLocalObjectIndex()); + zeus::CColor color( + std::max(0.f, (-parms.GetCameraTransform().basis[1]).dot(areaPostXf.rotate(surf.GetNormal()))) * + g_tweakAutoMapper->GetMapSurfaceNormColorLinear() + + g_tweakAutoMapper->GetMapSurfaceNormColorConstant()); + color *= info.GetSurfaceColor(); + if (lastAreaIdx != info.GetAreaIndex() || lastType != CMapObjectSortInfo::EObjectCode::Surface) { + CGraphics::SetModelMatrix(parms.GetPlaneProjectionTransform() * areaPostXf); + } + surf.Draw(mapa->GetVertices(), color, info.GetOutlineColor(), parms.GetOutlineWidthScale()); + + lastAreaIdx = info.GetAreaIndex(); + lastType = info.GetObjectCode(); } - surf.Draw(mapa->GetVertices(), color, info.GetOutlineColor(), parms.GetOutlineWidthScale()); - - lastAreaIdx = info.GetAreaIndex(); - lastType = info.GetObjectCode(); } - } - for (const CMapObjectSortInfo& info : sortInfos) { - CMapArea* mapa = GetMapArea(info.GetAreaIndex()); - if (info.GetObjectCode() == CMapObjectSortInfo::EObjectCode::Door || - info.GetObjectCode() == CMapObjectSortInfo::EObjectCode::Object) { - CMappableObject& mapObj = mapa->GetMappableObject(info.GetLocalObjectIndex()); - const zeus::CTransform objXf = - zeus::CTransform::Translate(CMapArea::GetAreaPostTranslate(parms.GetWorld(), info.GetAreaIndex())) * - mapObj.GetTransform(); - if (info.GetObjectCode() == CMapObjectSortInfo::EObjectCode::Door) { - CGraphics::SetModelMatrix(parms.GetPlaneProjectionTransform() * objXf); - } else { - CGraphics::SetModelMatrix( - parms.GetPlaneProjectionTransform() * objXf * - zeus::CTransform(parms.GetCameraTransform().buildMatrix3f() * zeus::CMatrix3f(parms.GetObjectScale()))); + for (const CMapObjectSortInfo& info : sortInfos) { + CMapArea* mapa = GetMapArea(info.GetAreaIndex()); + if (info.GetObjectCode() == CMapObjectSortInfo::EObjectCode::Door || + info.GetObjectCode() == CMapObjectSortInfo::EObjectCode::Object) { + CMappableObject& mapObj = mapa->GetMappableObject(info.GetLocalObjectIndex()); + const zeus::CTransform objXf = + zeus::CTransform::Translate(CMapArea::GetAreaPostTranslate(parms.GetWorld(), info.GetAreaIndex())) * + mapObj.GetTransform(); + if (info.GetObjectCode() == CMapObjectSortInfo::EObjectCode::Door) { + CGraphics::SetModelMatrix(parms.GetPlaneProjectionTransform() * objXf); + } else { + CGraphics::SetModelMatrix( + parms.GetPlaneProjectionTransform() * objXf * + zeus::CTransform(parms.GetCameraTransform().buildMatrix3f() * zeus::CMatrix3f(parms.GetObjectScale()))); + } + mapObj.Draw(selArea, mwInfo, parms.GetAlpha(), lastType != info.GetObjectCode()); + lastType = info.GetObjectCode(); + } else if (info.GetObjectCode() == CMapObjectSortInfo::EObjectCode::DoorSurface) { + CMappableObject& mapObj = mapa->GetMappableObject(info.GetLocalObjectIndex() / 6); + const zeus::CTransform objXf = + parms.GetPlaneProjectionTransform() * + zeus::CTransform::Translate(CMapArea::GetAreaPostTranslate(parms.GetWorld(), info.GetAreaIndex())) * + mapObj.GetTransform(); + CGraphics::SetModelMatrix(objXf); + mapObj.DrawDoorSurface(selArea, mwInfo, parms.GetAlpha(), info.GetLocalObjectIndex() % 6, + lastType != info.GetObjectCode()); + lastType = info.GetObjectCode(); } - mapObj.Draw(selArea, mwInfo, parms.GetAlpha(), lastType != info.GetObjectCode()); - lastType = info.GetObjectCode(); - } else if (info.GetObjectCode() == CMapObjectSortInfo::EObjectCode::DoorSurface) { - CMappableObject& mapObj = mapa->GetMappableObject(info.GetLocalObjectIndex() / 6); - const zeus::CTransform objXf = - parms.GetPlaneProjectionTransform() * - zeus::CTransform::Translate(CMapArea::GetAreaPostTranslate(parms.GetWorld(), info.GetAreaIndex())) * - mapObj.GetTransform(); - CGraphics::SetModelMatrix(objXf); - mapObj.DrawDoorSurface(selArea, mwInfo, parms.GetAlpha(), info.GetLocalObjectIndex() % 6, - lastType != info.GetObjectCode()); - lastType = info.GetObjectCode(); } } } diff --git a/Runtime/AutoMapper/CMappableObject.cpp b/Runtime/AutoMapper/CMappableObject.cpp index 509dd14f7..8187829de 100644 --- a/Runtime/AutoMapper/CMappableObject.cpp +++ b/Runtime/AutoMapper/CMappableObject.cpp @@ -1,19 +1,41 @@ #include "Runtime/AutoMapper/CMappableObject.hpp" #include "Runtime/AutoMapper/CMapWorldInfo.hpp" +#include "Runtime/AutoMapper/CMapArea.hpp" #include "Runtime/CSimplePool.hpp" #include "Runtime/CToken.hpp" -#include "Runtime/Camera/CCameraFilter.hpp" #include "Runtime/GameGlobalObjects.hpp" +#include "Runtime/Graphics/CGX.hpp" #include "Runtime/Graphics/CTexture.hpp" namespace metaforce { -std::array CMappableObject::skDoorVerts{}; +using zeus::CColor; +using zeus::CVector3f; +using uchar = unsigned char; -std::array CMappableObject::skDoorIndices{ - 6, 4, 2, 0, 3, 1, 7, 5, 1, 0, 5, 4, 7, 6, 3, 2, 3, 2, 1, 0, 5, 4, 7, 6, +struct SDrawData { + float x0_x; + float x4_y; + float x8_z; + uchar xc_idxA; + uchar xd_idxB; + uchar xe_idxC; + uchar xf_idxD; }; +static const SDrawData sDrawData[6] = { + // clang-format off + { 0.f, 0.f, -1.f, 6, 4, 2, 0}, + { 0.f, 0.f, 1.f, 3, 1, 7, 5}, + { 0.f, -1.f, 1.f, 1, 0, 5, 4}, + { 0.f, 1.f, 1.f, 7, 6, 3, 2}, + {-1.f, 0.f, 0.f, 3, 2, 1, 0}, + { 1.f, 0.f, 0.f, 5, 4, 7, 6}, + // clang-format on +}; + +static std::array, 8> skDoorVerts{}; + CMappableObject::CMappableObject(const void* buf) { CMemoryInStream r(buf, 64); x0_type = EMappableObjectType(r.ReadLong()); @@ -24,11 +46,11 @@ CMappableObject::CMappableObject(const void* buf) { } zeus::CTransform CMappableObject::AdjustTransformForType() const { - const float doorCenterX = g_tweakAutoMapper->GetDoorCenter().x(); - const float doorCenterZ = g_tweakAutoMapper->GetDoorCenter().z(); + const float doorCenterX = g_tweakAutoMapper->xa4_doorCenterA; + const float doorCenterZ = g_tweakAutoMapper->xac_doorCenterC; if (x0_type == EMappableObjectType::BigDoor1) { zeus::CTransform orientation; - orientation.origin = {-1.4f * doorCenterX, 0.0f, 0.0f}; + orientation.origin = {0.0f, 0.0f, -1.4f * doorCenterX}; orientation.rotateLocalZ(zeus::degToRad(90.0f)); return (x10_transform * orientation) * zeus::CTransform::Scale(zeus::CVector3f{1.5f}); } else if (x0_type == EMappableObjectType::BigDoor2) { @@ -54,15 +76,15 @@ zeus::CTransform CMappableObject::AdjustTransformForType() const { orientation.origin = {-0.49f * doorCenterX, 0.f, -1.f * doorCenterZ}; orientation.rotateLocalY(zeus::degToRad(90.f)); return x10_transform * orientation; - } else if (x0_type >= EMappableObjectType::BlueDoor && x0_type <= EMappableObjectType::PlasmaDoorFloor2) { + } else if (IsDoorType(x0_type)) { return x10_transform; } return zeus::CTransform::Translate(x10_transform.origin); } -std::pair CMappableObject::GetDoorColors(int curAreaId, const CMapWorldInfo& mwInfo, - float alpha) const { - zeus::CColor color = {1.f, 0.f, 1.f, 1.f}; +std::pair CMappableObject::GetDoorColors(int curAreaId, const CMapWorldInfo& mwInfo, + float alpha) const { + CColor color; if (x8_objId.AreaNum() == curAreaId) { if (mwInfo.IsDoorVisited(x8_objId) && x0_type == EMappableObjectType::ShieldDoor) { color = g_tweakAutoMapper->GetDoorColor(0); @@ -102,124 +124,147 @@ std::pair CMappableObject::GetDoorColors(int curArea } color.a() *= alpha; - return {color, zeus::CColor(std::min(1.4f * color.r(), 1.f), std::min(1.4f * color.g(), 1.f), - std::min(1.4f * color.b(), 1.f), std::min(1.4f * color.a(), 1.f))}; + return {color, CColor(std::min(1.4f * color.r(), 1.f), std::min(1.4f * color.g(), 1.f), + std::min(1.4f * color.b(), 1.f), std::min(1.4f * color.a(), 1.f))}; } void CMappableObject::PostConstruct(const void*) { x10_transform = AdjustTransformForType(); } void CMappableObject::Draw(int curArea, const CMapWorldInfo& mwInfo, float alpha, bool needsVtxLoad) { SCOPED_GRAPHICS_DEBUG_GROUP("CMappableObject::Draw", zeus::skCyan); - if (IsDoorType(x0_type)) { - std::pair colors = GetDoorColors(curArea, mwInfo, alpha); - // TODO -// for (int s = 0; s < 6; ++s) { -// DoorSurface& ds = *m_doorSurface; -// ds.m_surface.draw(colors.first, s * 4, 4); -// CLineRenderer& line = ds.m_outline; -// const u16* baseIdx = &skDoorIndices[s * 4]; -// line.Reset(); -// line.AddVertex(skDoorVerts[baseIdx[0]], colors.second, 1.f); -// line.AddVertex(skDoorVerts[baseIdx[1]], colors.second, 1.f); -// line.AddVertex(skDoorVerts[baseIdx[3]], colors.second, 1.f); -// line.AddVertex(skDoorVerts[baseIdx[2]], colors.second, 1.f); -// line.Render(); -// } - } else { - CAssetId iconRes; - zeus::CColor iconColor = zeus::skWhite; - switch (x0_type) { - case EMappableObjectType::DownArrowYellow: - iconRes = g_tweakPlayerRes->x10_minesBreakFirstTopIcon; - iconColor = zeus::CColor{1.f, 1.f, 0.588f, 1.f}; - break; - case EMappableObjectType::UpArrowYellow: - iconRes = g_tweakPlayerRes->x14_minesBreakFirstBottomIcon; - iconColor = zeus::CColor{1.f, 1.f, 0.588f, 1.f}; - break; - case EMappableObjectType::DownArrowGreen: - iconRes = g_tweakPlayerRes->x10_minesBreakFirstTopIcon; - iconColor = zeus::CColor{0.392f, 1.f, 0.588f, 1.f}; - break; - case EMappableObjectType::UpArrowGreen: - iconRes = g_tweakPlayerRes->x14_minesBreakFirstBottomIcon; - iconColor = zeus::CColor{0.392f, 1.f, 0.588f, 1.f}; - break; - case EMappableObjectType::DownArrowRed: - iconRes = g_tweakPlayerRes->x10_minesBreakFirstTopIcon; - iconColor = zeus::CColor{1.f, 0.392f, 0.588f, 1.f}; - break; - case EMappableObjectType::UpArrowRed: - iconRes = g_tweakPlayerRes->x14_minesBreakFirstBottomIcon; - iconColor = zeus::CColor{1.f, 0.392f, 0.588f, 1.f}; - break; - case EMappableObjectType::SaveStation: - iconRes = g_tweakPlayerRes->x4_saveStationIcon; - break; - case EMappableObjectType::MissileStation: - iconRes = g_tweakPlayerRes->x8_missileStationIcon; - break; - default: - iconRes = g_tweakPlayerRes->xc_elevatorIcon; - break; + if (IsDoorType(x0_type) == true) { + std::pair colors = GetDoorColors(curArea, mwInfo, alpha); + for (int i = 0; i < 6; ++i) { + if (needsVtxLoad) { + CGX::SetArray(GX_VA_POS, skDoorVerts); + } + CGX::SetTevKColor(GX_KCOLOR0, colors.first); + CGX::Begin(GX_TRIANGLESTRIP, GX_VTXFMT0, 4); + GXPosition1x8(sDrawData[i].xc_idxA); + GXPosition1x8(sDrawData[i].xd_idxB); + GXPosition1x8(sDrawData[i].xe_idxC); + GXPosition1x8(sDrawData[i].xf_idxD); + CGX::End(); + + CGX::SetTevKColor(GX_KCOLOR0, colors.second); + CGX::Begin(GX_LINESTRIP, GX_VTXFMT0, 5); + GXPosition1x8(sDrawData[i].xc_idxA); + GXPosition1x8(sDrawData[i].xd_idxB); + GXPosition1x8(sDrawData[i].xf_idxD); + GXPosition1x8(sDrawData[i].xe_idxC); + GXPosition1x8(sDrawData[i].xc_idxA); + CGX::End(); } - - iconColor.a() *= alpha; - - TLockedToken tex = g_SimplePool->GetObj(SObjectTag{FOURCC('TXTR'), iconRes}); -// if (!m_texQuadFilter || m_texQuadFilter->GetTex().GetObj() != tex.GetObj()) { - //m_texQuadFilter.emplace(EFilterType::Add, tex, CTexturedQuadFilter::ZTest::GEqual); -// } - -// constexpr std::array verts{{ -// {{-2.6f, 0.f, 2.6f}, {0.f, 1.f}}, -// {{-2.6f, 0.f, -2.6f}, {0.f, 0.f}}, -// {{2.6f, 0.f, 2.6f}, {1.f, 1.f}}, -// {{2.6f, 0.f, -2.6f}, {1.f, 0.f}}, -// }}; - //m_texQuadFilter->drawVerts(iconColor, verts); + return; } + + CAssetId iconRes; + CColor iconColor = CColor(0xffffffffu); + switch (x0_type) { + case EMappableObjectType::DownArrowYellow: + iconColor = CColor(0xffff96ffu); + iconRes = g_tweakPlayerRes->x10_minesBreakFirstTopIcon; + break; + case EMappableObjectType::UpArrowYellow: + iconColor = CColor(0xffff96ffu); + iconRes = g_tweakPlayerRes->x14_minesBreakFirstBottomIcon; + break; + case EMappableObjectType::DownArrowGreen: + iconColor = CColor(0x64ff96ffu); + iconRes = g_tweakPlayerRes->x10_minesBreakFirstTopIcon; + break; + case EMappableObjectType::UpArrowGreen: + iconColor = CColor(0x64ff96ffu); + iconRes = g_tweakPlayerRes->x14_minesBreakFirstBottomIcon; + break; + case EMappableObjectType::DownArrowRed: + iconColor = CColor(0xff6496ffu); + iconRes = g_tweakPlayerRes->x10_minesBreakFirstTopIcon; + break; + case EMappableObjectType::UpArrowRed: + iconColor = CColor(0xff6496ffu); + iconRes = g_tweakPlayerRes->x14_minesBreakFirstBottomIcon; + break; + case EMappableObjectType::SaveStation: + iconRes = g_tweakPlayerRes->x4_saveStationIcon; + break; + case EMappableObjectType::MissileStation: + iconRes = g_tweakPlayerRes->x8_missileStationIcon; + break; + default: + iconRes = g_tweakPlayerRes->xc_elevatorIcon; + break; + } + + TLockedToken tex = g_SimplePool->GetObj(SObjectTag('TXTR', iconRes)); + tex->Load(GX_TEXMAP0, EClampMode::Repeat); + CGraphics::SetTevOp(ERglTevStage::Stage0, CTevCombiners::kEnvModulate); + CGraphics::StreamBegin(ERglPrimitive::TriangleStrip); + iconColor.a() = alpha; + CGraphics::StreamColor(iconColor); + CGraphics::StreamTexcoord(0.0f, 1.0f); + CGraphics::StreamVertex(-2.6f, 0.0f, 2.6f); + CGraphics::StreamTexcoord(0.0f, 0.0f); + CGraphics::StreamVertex(-2.6f, 0.0f, -2.6f); + CGraphics::StreamTexcoord(1.0f, 1.0f); + CGraphics::StreamVertex(2.6f, 0.0f, 2.6f); + CGraphics::StreamTexcoord(1.0f, 0.0f); + CGraphics::StreamVertex(2.6f, 0.0f, -2.6f); + CGraphics::StreamEnd(); + + // Metaforce addition: restore GX state + CMapArea::CMapAreaSurface::SetupGXMaterial(); } void CMappableObject::DrawDoorSurface(int curArea, const CMapWorldInfo& mwInfo, float alpha, int surfIdx, bool needsVtxLoad) { - std::pair colors = GetDoorColors(curArea, mwInfo, alpha); -// DoorSurface& ds = *m_doorSurface; -// ds.m_surface.draw(colors.first, surfIdx * 4, 4); -// CLineRenderer& line = ds.m_outline; -// const u16* baseIdx = &skDoorIndices[surfIdx * 4]; -// line.Reset(); -// line.AddVertex(skDoorVerts[baseIdx[0]], colors.second, 1.f); -// line.AddVertex(skDoorVerts[baseIdx[1]], colors.second, 1.f); -// line.AddVertex(skDoorVerts[baseIdx[3]], colors.second, 1.f); -// line.AddVertex(skDoorVerts[baseIdx[2]], colors.second, 1.f); -// line.Render(); -} - -zeus::CVector3f CMappableObject::BuildSurfaceCenterPoint(int surfIdx) const { - const zeus::CVector3f& doorCenter = g_tweakAutoMapper->GetDoorCenter(); - - switch (surfIdx) { - case 0: - return x10_transform * zeus::skZero3f; - case 1: - return x10_transform * zeus::CVector3f{0.f, 0.f, 2.f * doorCenter.x()}; - case 2: - return x10_transform * zeus::CVector3f{0.f, -doorCenter.y(), 0.f}; - case 3: - return x10_transform * zeus::CVector3f{0.f, doorCenter.y(), 0.f}; - case 4: - return x10_transform * zeus::CVector3f{-doorCenter.x(), 0.f, 0.f}; - case 5: - return x10_transform * zeus::CVector3f{doorCenter.x(), 0.f, 0.f}; - default: - break; + std::pair colors = GetDoorColors(curArea, mwInfo, alpha); + const SDrawData& drawData = sDrawData[surfIdx]; + if (needsVtxLoad) { + CGX::SetArray(GX_VA_POS, skDoorVerts); } - return {}; + CGX::SetTevKColor(GX_KCOLOR0, colors.first); + CGX::Begin(GX_TRIANGLESTRIP, GX_VTXFMT0, 4); + GXPosition1x8(drawData.xc_idxA); + GXPosition1x8(drawData.xd_idxB); + GXPosition1x8(drawData.xe_idxC); + GXPosition1x8(drawData.xf_idxD); + CGX::End(); + + CGX::SetTevKColor(GX_KCOLOR0, colors.second); + CGX::Begin(GX_LINESTRIP, GX_VTXFMT0, 5); + GXPosition1x8(drawData.xc_idxA); + GXPosition1x8(drawData.xd_idxB); + GXPosition1x8(drawData.xf_idxD); + GXPosition1x8(drawData.xe_idxC); + GXPosition1x8(drawData.xc_idxA); + CGX::End(); } -bool CMappableObject::IsVisibleToAutoMapper(bool worldVis, const CMapWorldInfo& mwInfo) const { +CVector3f CMappableObject::BuildSurfaceCenterPoint(int surfaceIdx) const { + const float x = g_tweakAutoMapper->xac_doorCenterC; + const float y = g_tweakAutoMapper->xa8_doorCenterB; + const float z = g_tweakAutoMapper->xa4_doorCenterA; + switch (surfaceIdx) { + case 0: + return x10_transform * CVector3f{}; + case 1: + return x10_transform * CVector3f(0.f, 0.f, 2.f * z); + case 2: + return x10_transform * CVector3f(0.f, -y, 0.f); + case 3: + return x10_transform * CVector3f(0.f, y, 0.f); + case 4: + return x10_transform * CVector3f(-x, 0.f, 0.f); + case 5: + return x10_transform * CVector3f(x, 0.f, 0.f); + default: + return CVector3f{}; + } +} + +bool CMappableObject::GetIsVisibleToAutoMapper(bool worldVis, const CMapWorldInfo& mwInfo) const { bool areaVis = mwInfo.IsAreaVisible(x8_objId.AreaNum()); switch (x4_visibilityMode) { case EVisMode::Always: @@ -229,8 +274,9 @@ bool CMappableObject::IsVisibleToAutoMapper(bool worldVis, const CMapWorldInfo& case EVisMode::MapStationOrVisit2: return worldVis || areaVis; case EVisMode::Visit: - if (IsDoorType(x0_type)) + if (IsDoorType(x0_type)) { return mwInfo.IsDoorVisited(x8_objId); + } return areaVis; case EVisMode::Never: return false; @@ -238,29 +284,16 @@ bool CMappableObject::IsVisibleToAutoMapper(bool worldVis, const CMapWorldInfo& } void CMappableObject::ReadAutoMapperTweaks(const ITweakAutoMapper& tweaks) { - const zeus::CVector3f& center = tweaks.GetDoorCenter(); - const zeus::simd_floats centerF(center.mSimd); - - // Wrap door verts around -Z to build surface - auto& doorVerts = skDoorVerts; - doorVerts[0].assign(-centerF[2], -centerF[1], 0.f); - doorVerts[1].assign(-centerF[2], -centerF[1], 2.f * centerF[0]); - doorVerts[2].assign(-centerF[2], centerF[1], 0.f); - doorVerts[3].assign(-centerF[2], centerF[1], 2.f * centerF[0]); - doorVerts[4].assign(.2f * -centerF[2], -centerF[1], 0.f); - doorVerts[5].assign(.2f * -centerF[2], -centerF[1], 2.f * centerF[0]); - doorVerts[6].assign(.2f * -centerF[2], centerF[1], 0.f); - doorVerts[7].assign(.2f * -centerF[2], centerF[1], 2.f * centerF[0]); - -// CGraphics::CommitResources([](boo::IGraphicsDataFactory::Context& ctx) { -// g_doorVbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, skDoorVerts.data(), 16, skDoorVerts.size()); -// g_doorIbo = ctx.newStaticBuffer(boo::BufferUse::Index, DoorIndices.data(), 4, DoorIndices.size()); -// return true; -// } BooTrace); -} - -void CMappableObject::Shutdown() { -// g_doorVbo.reset(); -// g_doorIbo.reset(); + const float x = tweaks.xac_doorCenterC; + const float y = tweaks.xa8_doorCenterB; + const float z = tweaks.xa4_doorCenterA; + skDoorVerts[0] = aurora::Vec3(-x, -y, 0.f); + skDoorVerts[1] = aurora::Vec3(-x, -y, z * 2.f); + skDoorVerts[2] = aurora::Vec3(-x, y, 0.f); + skDoorVerts[3] = aurora::Vec3(-x, y, z * 2.f); + skDoorVerts[4] = aurora::Vec3(-x * .2f, -y, 0.f); + skDoorVerts[5] = aurora::Vec3(-x * .2f, -y, z * 2.f); + skDoorVerts[6] = aurora::Vec3(-x * .2f, y, 0.f); + skDoorVerts[7] = aurora::Vec3(-x * .2f, y, z * 2.f); } } // namespace metaforce diff --git a/Runtime/AutoMapper/CMappableObject.hpp b/Runtime/AutoMapper/CMappableObject.hpp index 675e440a5..a42ac768b 100644 --- a/Runtime/AutoMapper/CMappableObject.hpp +++ b/Runtime/AutoMapper/CMappableObject.hpp @@ -1,15 +1,10 @@ #pragma once -#include -#include #include #include "Runtime/GameGlobalObjects.hpp" -#include "Runtime/Graphics/CLineRenderer.hpp" -#include "Runtime/Graphics/Shaders/CMapSurfaceShader.hpp" #include "Runtime/RetroTypes.hpp" -#include #include namespace metaforce { @@ -49,24 +44,12 @@ public: enum class EVisMode { Always, MapStationOrVisit, Visit, Never, MapStationOrVisit2 }; private: - static std::array skDoorVerts; - static std::array skDoorIndices; - EMappableObjectType x0_type; EVisMode x4_visibilityMode; TEditorId x8_objId; u32 xc_; zeus::CTransform x10_transform; -// struct DoorSurface { -// CMapSurfaceShader m_surface; -// CLineRenderer m_outline; -// explicit DoorSurface() -// : m_surface(skDoorVerts, skDoorIndices) -// , m_outline(CLineRenderer::EPrimitiveMode::LineLoop, 5, {}, false, false, true) {} -// }; -// std::optional m_doorSurface; - zeus::CTransform AdjustTransformForType() const; std::pair GetDoorColors(int idx, const CMapWorldInfo& mwInfo, float alpha) const; @@ -81,15 +64,13 @@ public: zeus::CVector3f BuildSurfaceCenterPoint(int surfIdx) const; bool IsDoorConnectedToArea(int idx, const CStateManager&) const; bool IsDoorConnectedToVisitedArea(const CStateManager&) const; - bool IsVisibleToAutoMapper(bool worldVis, const CMapWorldInfo& mwInfo) const; + bool GetIsVisibleToAutoMapper(bool worldVis, const CMapWorldInfo& mwInfo) const; bool GetIsSeen() const; -// void CreateDoorSurface() { m_doorSurface.emplace(); } static void ReadAutoMapperTweaks(const ITweakAutoMapper&); static bool GetTweakIsMapVisibilityCheat(); static bool IsDoorType(EMappableObjectType type) { return type >= EMappableObjectType::BlueDoor && type <= EMappableObjectType::PlasmaDoorFloor2; } - static void Shutdown(); }; } // namespace metaforce diff --git a/Runtime/CMain.cpp b/Runtime/CMain.cpp index e2acea5f4..55849ab30 100644 --- a/Runtime/CMain.cpp +++ b/Runtime/CMain.cpp @@ -470,11 +470,13 @@ static void aurora_log_callback(AuroraLogLevel level, const char* module, const break; } const std::string_view view(message, len); + spdlog::log(severity, "[{}] {}", module, view); if (level == LOG_FATAL) { + spdlog::default_logger()->flush(); auto msg = fmt::format("Metaforce encountered an internal error:\n\n{}", view); SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Metaforce", msg.c_str(), metaforce::g_window); + std::abort(); } - spdlog::log(severity, "[{}] {}", module, view); } static void aurora_imgui_init_callback(const AuroraWindowSize* size) { g_app->onImGuiInit(size->scale); } diff --git a/Runtime/CMakeLists.txt b/Runtime/CMakeLists.txt index d01244df0..265359fe5 100644 --- a/Runtime/CMakeLists.txt +++ b/Runtime/CMakeLists.txt @@ -150,7 +150,7 @@ endfunction() set(RUNTIME_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}) set(RUNTIME_LIBRARIES zeus nod NESEmulator libjpeg-turbo jbus kabufuda OptickCore - imgui_support aurora::core aurora::gx aurora::vi spdlog::spdlog $<$:nowide::nowide> + imgui_support aurora::core aurora::gx aurora::vi aurora::mtx spdlog::spdlog $<$:nowide::nowide> ${ZLIB_LIBRARIES} ) diff --git a/Runtime/CStateManager.cpp b/Runtime/CStateManager.cpp index 7b86c8d2d..aef2135f5 100644 --- a/Runtime/CStateManager.cpp +++ b/Runtime/CStateManager.cpp @@ -500,7 +500,7 @@ void CStateManager::DrawReflection(const zeus::CVector3f& reflectPoint) { const zeus::CVector3f viewPos = playerPos - surfToPlayer.normalized() * 3.5f; const zeus::CTransform look = zeus::lookAt(viewPos, playerPos, {0.f, 0.f, -1.f}); - const zeus::CTransform backupView = CGraphics::g_ViewMatrix; + const zeus::CTransform backupView = CGraphics::mViewMatrix; CGraphics::SetViewPointMatrix(look); const CGraphics::CProjectionState backupProj = CGraphics::GetProjectionState(); const CGameCamera* cam = x870_cameraManager->GetCurrentCamera(*this); @@ -649,38 +649,38 @@ void CStateManager::DrawAdditionalFilters() { CCameraFilterPass::DrawFilter(EFilterType::Add, EFilterShape::Fullscreen, color, nullptr, 1.f); } -zeus::CFrustum CStateManager::SetupDrawFrustum(const SViewport& vp) const { +zeus::CFrustum CStateManager::SetupDrawFrustum(const CViewport& vp) const { zeus::CFrustum ret; const CGameCamera* cam = x870_cameraManager->GetCurrentCamera(*this); const zeus::CTransform camXf = x870_cameraManager->GetCurrentCameraTransform(*this); - const int vpWidth = static_cast(xf2c_viewportScale.x() * vp.x8_width); - const int vpHeight = static_cast(xf2c_viewportScale.y() * vp.xc_height); - const int vpLeft = static_cast((vp.x8_width - vpWidth) / 2 + vp.x0_left); - const int vpTop = static_cast((vp.xc_height - vpHeight) / 2 + vp.x4_top); + const int vpWidth = static_cast(xf2c_viewportScale.x() * vp.mWidth); + const int vpHeight = static_cast(xf2c_viewportScale.y() * vp.mHeight); + const int vpLeft = (vp.mWidth - vpWidth) / 2 + vp.mLeft; + const int vpTop = (vp.mHeight - vpHeight) / 2 + vp.mTop; g_Renderer->SetViewport(vpLeft, vpTop, vpWidth, vpHeight); const float fov = std::atan(std::tan(zeus::degToRad(cam->GetFov()) * 0.5f) * xf2c_viewportScale.y()) * 2.f; - const float width = xf2c_viewportScale.x() * vp.x8_width; - const float height = xf2c_viewportScale.y() * vp.xc_height; + const float width = xf2c_viewportScale.x() * vp.mWidth; + const float height = xf2c_viewportScale.y() * vp.mHeight; zeus::CProjection proj; proj.setPersp(zeus::SProjPersp{fov, width / height, cam->GetNearClipDistance(), cam->GetFarClipDistance()}); ret.updatePlanes(camXf, proj); return ret; } -zeus::CFrustum CStateManager::SetupViewForDraw(const SViewport& vp) const { +zeus::CFrustum CStateManager::SetupViewForDraw(const CViewport& vp) const { const CGameCamera* cam = x870_cameraManager->GetCurrentCamera(*this); const zeus::CTransform camXf = x870_cameraManager->GetCurrentCameraTransform(*this); g_Renderer->SetWorldViewpoint(camXf); CCubeModel::SetNewPlayerPositionAndTime(x84c_player->GetTranslation(), CStopwatch::GetGlobalTimerObj()); - const int vpWidth = static_cast(xf2c_viewportScale.x() * vp.x8_width); - const int vpHeight = static_cast(xf2c_viewportScale.y() * vp.xc_height); - const int vpLeft = static_cast((vp.x8_width - vpWidth) / 2 + vp.x0_left); - const int vpTop = static_cast((vp.xc_height - vpHeight) / 2 + vp.x4_top); + const int vpWidth = static_cast(xf2c_viewportScale.x() * vp.mWidth); + const int vpHeight = static_cast(xf2c_viewportScale.y() * vp.mHeight); + const int vpLeft = (vp.mWidth - vpWidth) / 2 + vp.mLeft; + const int vpTop = (vp.mHeight - vpHeight) / 2 + vp.mTop; g_Renderer->SetViewport(vpLeft, vpTop, vpWidth, vpHeight); CGraphics::SetDepthRange(DEPTH_WORLD, DEPTH_FAR); const float fov = std::atan(std::tan(zeus::degToRad(cam->GetFov()) * 0.5f) * xf2c_viewportScale.y()) * 2.f; - const float width = xf2c_viewportScale.x() * vp.x8_width; - const float height = xf2c_viewportScale.y() * vp.xc_height; + const float width = xf2c_viewportScale.x() * vp.mWidth; + const float height = xf2c_viewportScale.y() * vp.mHeight; g_Renderer->SetPerspective(zeus::radToDeg(fov), width, height, cam->GetNearClipDistance(), cam->GetFarClipDistance()); zeus::CFrustum frustum; zeus::CProjection proj; @@ -690,14 +690,13 @@ zeus::CFrustum CStateManager::SetupViewForDraw(const SViewport& vp) const { g_Renderer->PrimColor(zeus::skWhite); CGraphics::SetModelMatrix(zeus::CTransform()); x87c_fluidPlaneManager->StartFrame(false); - g_Renderer->SetDebugOption(IRenderer::EDebugOption::PVSState, int(EPVSVisSetState::NodeFound)); + g_Renderer->SetDebugOption(IRenderer::EDebugOption::PVSState, static_cast(EPVSVisSetState::NodeFound)); return frustum; } -void CStateManager::ResetViewAfterDraw(const SViewport& backupViewport, +void CStateManager::ResetViewAfterDraw(const CViewport& backupViewport, const zeus::CTransform& backupViewMatrix) const { - g_Renderer->SetViewport(backupViewport.x0_left, backupViewport.x4_top, backupViewport.x8_width, - backupViewport.xc_height); + g_Renderer->SetViewport(backupViewport.mLeft, backupViewport.mTop, backupViewport.mWidth, backupViewport.mHeight); const CGameCamera* cam = x870_cameraManager->GetCurrentCamera(*this); zeus::CFrustum frustum; @@ -712,15 +711,15 @@ void CStateManager::ResetViewAfterDraw(const SViewport& backupViewport, void CStateManager::DrawWorld() { SCOPED_GRAPHICS_DEBUG_GROUP("CStateManager::DrawWorld", zeus::skBlue); const CTimeProvider timeProvider(xf14_curTimeMod900); - const SViewport backupViewport = CGraphics::g_Viewport; + const CViewport backupViewport = CGraphics::mViewport; /* Area camera is in (not necessarily player) */ const TAreaId visAreaId = GetVisAreaId(); x850_world->TouchSky(); - const zeus::CFrustum frustum = SetupViewForDraw(CGraphics::g_Viewport); - const zeus::CTransform backupViewMatrix = CGraphics::g_ViewMatrix; + const zeus::CFrustum frustum = SetupViewForDraw(CGraphics::mViewport); + const zeus::CTransform backupViewMatrix = CGraphics::mViewMatrix; int areaCount = 0; std::array areaArr; @@ -747,7 +746,7 @@ void CStateManager::DrawWorld() { if (visAreaId == b->x4_selfIdx) { return true; } - return CGraphics::g_ViewPoint.dot(a->GetAABB().center()) > CGraphics::g_ViewPoint.dot(b->GetAABB().center()); + return CGraphics::mViewPoint.dot(a->GetAABB().center()) > CGraphics::mViewPoint.dot(b->GetAABB().center()); }); int pvsCount = 0; @@ -789,7 +788,7 @@ void CStateManager::DrawWorld() { g_Renderer->SetWorldFog(ERglFogMode::None, 0.f, 1.f, zeus::skBlack); } - x850_world->DrawSky(zeus::CTransform::Translate(CGraphics::g_ViewPoint)); + x850_world->DrawSky(zeus::CTransform::Translate(CGraphics::mViewPoint)); if (areaCount != 0) { SetupFogForArea(*areaArr[areaCount - 1]); @@ -1074,7 +1073,7 @@ void CStateManager::PreRender() { } SCOPED_GRAPHICS_DEBUG_GROUP("CStateManager::PreRender", zeus::skBlue); - const zeus::CFrustum frustum = SetupDrawFrustum(CGraphics::g_Viewport); + const zeus::CFrustum frustum = SetupDrawFrustum(CGraphics::mViewport); x86c_stateManagerContainer->xf370_.clear(); x86c_stateManagerContainer->xf39c_renderLast.clear(); xf7c_projectedShadow = nullptr; @@ -1143,7 +1142,7 @@ bool CStateManager::GetVisSetForArea(TAreaId a, TAreaId b, CPVSVisSet& setOut) c return false; } - const zeus::CVector3f viewPoint = CGraphics::g_ViewMatrix.origin; + const zeus::CVector3f viewPoint = CGraphics::mViewMatrix.origin; zeus::CVector3f closestDockPoint = viewPoint; bool hasClosestDock = false; if (a != b) { diff --git a/Runtime/CStateManager.hpp b/Runtime/CStateManager.hpp index 26b7c15f8..3357947cf 100644 --- a/Runtime/CStateManager.hpp +++ b/Runtime/CStateManager.hpp @@ -250,9 +250,9 @@ public: void RenderCamerasAndAreaLights(); void DrawE3DeathEffect(); void DrawAdditionalFilters(); - zeus::CFrustum SetupDrawFrustum(const SViewport& vp) const; - zeus::CFrustum SetupViewForDraw(const SViewport& vp) const; - void ResetViewAfterDraw(const SViewport& backupViewport, const zeus::CTransform& backupViewMatrix) const; + zeus::CFrustum SetupDrawFrustum(const CViewport& vp) const; + zeus::CFrustum SetupViewForDraw(const CViewport& vp) const; + void ResetViewAfterDraw(const CViewport& backupViewport, const zeus::CTransform& backupViewMatrix) const; void DrawWorld(); void SetupFogForArea3XRange(TAreaId area) const; void SetupFogForArea(TAreaId area) const; diff --git a/Runtime/CTimeProvider.hpp b/Runtime/CTimeProvider.hpp index e8fbe2cd8..d3978ba98 100644 --- a/Runtime/CTimeProvider.hpp +++ b/Runtime/CTimeProvider.hpp @@ -8,5 +8,6 @@ public: CTimeProvider(const float& time); ~CTimeProvider(); + float GetSecondsMod900() const { return x0_currentTime; } }; } // namespace metaforce diff --git a/Runtime/Camera/CCameraFilter.cpp b/Runtime/Camera/CCameraFilter.cpp index d5e4052c9..a6a92a18b 100644 --- a/Runtime/Camera/CCameraFilter.cpp +++ b/Runtime/Camera/CCameraFilter.cpp @@ -191,7 +191,7 @@ void CCameraFilterPass::DrawFullScreenTexturedQuadQuarters(const zeus::CColor& c CGraphics::SetCullMode(ERglCullMode::None); for (int i = 0; i < 4; ++i) { g_Renderer->SetModelMatrix(zeus::CTransform::Scale((i & 1) != 0 ? 1.f : -1.f, 0.f, (i & 2) != 0 ? 1.f : -1.f)); - CGraphics::StreamBegin(GX_TRIANGLESTRIP); + CGraphics::StreamBegin(ERglPrimitive::TriangleStrip); CGraphics::StreamColor(color); CGraphics::StreamTexcoord(lod, lod); CGraphics::StreamVertex(lt.x(), 0.f, rb.y()); @@ -217,7 +217,7 @@ void CCameraFilterPass::DrawFullScreenTexturedQuad(const zeus::CColor& color, CT } CGraphics::SetTevOp(ERglTevStage::Stage0, CTevCombiners::kEnvModulate); CGraphics::SetTevOp(ERglTevStage::Stage1, CTevCombiners::kEnvPassthru); - CGraphics::StreamBegin(GX_TRIANGLESTRIP); + CGraphics::StreamBegin(ERglPrimitive::TriangleStrip); CGraphics::StreamColor(color); CGraphics::StreamTexcoord(u, v); CGraphics::StreamVertex(lt.x() - 1.f, 0.f, 1.f + rb.y()); @@ -255,7 +255,7 @@ void CCameraFilterPass::DrawRandomStatic(const zeus::CColor& color, float alpha, m_randomStatic.UnLock(); m_randomStatic.Load(GX_TEXMAP0, EClampMode::Clamp); - CGraphics::StreamBegin(GX_TRIANGLESTRIP); + CGraphics::StreamBegin(ERglPrimitive::TriangleStrip); CGraphics::StreamColor(color); CGraphics::StreamTexcoord(0.f, 1.f); CGraphics::StreamVertex(lb.x() - 1.f, 0.01f, rt.y() + 1.f); diff --git a/Runtime/Camera/CCameraFilter.hpp b/Runtime/Camera/CCameraFilter.hpp index 06a4226ae..0fac0d453 100644 --- a/Runtime/Camera/CCameraFilter.hpp +++ b/Runtime/Camera/CCameraFilter.hpp @@ -1,12 +1,7 @@ #pragma once -#include -#include - #include "Runtime/CToken.hpp" #include "Runtime/Graphics/CTexture.hpp" -#include "Runtime/Graphics/Shaders/CCameraBlurFilter.hpp" -#include "Runtime/Graphics/Shaders/CXRayBlurFilter.hpp" #include "Runtime/RetroTypes.hpp" #include @@ -38,7 +33,6 @@ enum class EFilterShape { }; class CCameraFilterPass { -private: EFilterType x0_curType = EFilterType::Passthru; EFilterType x4_nextType = EFilterType::Passthru; EFilterShape x8_shape = EFilterShape::Fullscreen; diff --git a/Runtime/Camera/CGameCamera.cpp b/Runtime/Camera/CGameCamera.cpp index 41aa31591..8157ccfcc 100644 --- a/Runtime/Camera/CGameCamera.cpp +++ b/Runtime/Camera/CGameCamera.cpp @@ -57,9 +57,7 @@ zeus::CVector3f CGameCamera::ConvertToScreenSpace(const zeus::CVector3f& v) cons if (rVec.isZero()) return {-1.f, -1.f, 1.f}; - rVec = zeus::CVector3f(rVec.x(), rVec.z(), -rVec.y()); - zeus::CMatrix4f mtx = GetPerspectiveMatrix(); - return mtx.multiplyOneOverW(rVec); + return GetPerspectiveMatrix().multiplyOneOverW(rVec); } zeus::CTransform CGameCamera::ValidateCameraTransform(const zeus::CTransform& newXf, diff --git a/Runtime/Character/CAnimData.cpp b/Runtime/Character/CAnimData.cpp index eee469b3e..01eaac9c1 100644 --- a/Runtime/Character/CAnimData.cpp +++ b/Runtime/Character/CAnimData.cpp @@ -67,8 +67,8 @@ CAnimData::CAnimData(CAssetId id, const CCharacterInfo& character, int defaultAn g_TransientInt32POINodes.resize(16); xd8_modelData->CalculateDefault(); - for (const auto& item : *xd8_modelData->GetModel()->GetPositions()) { - x108_aabb.accumulateBounds(item); + for (const auto& item : xd8_modelData->GetModel()->GetPositions()) { + x108_aabb.accumulateBounds({item.x, item.y, item.z}); } x120_particleDB.CacheParticleDesc(xc_charInfo.GetParticleResData()); @@ -560,7 +560,7 @@ void CAnimData::SetupRender(CSkinnedModel& model, CVertexMorphEffect* morphEffec } void CAnimData::DrawSkinnedModel(CSkinnedModel& model, const CModelFlags& flags) { - CGX::SetChanCtrl(CGX::EChannelId::Channel0, CGraphics::g_LightActive); + CGX::SetChanCtrl(CGX::EChannelId::Channel0, CGraphics::mLightActive); model.Draw(flags); } @@ -888,8 +888,8 @@ zeus::CAABox CAnimData::GetBoundingBox() const { void CAnimData::SubstituteModelData(const TCachedToken& model) { xd8_modelData = model; x108_aabb = {}; - for (const auto& item : *xd8_modelData->GetModel()->GetPositions()) { - x108_aabb.accumulateBounds(item); + for (const auto& item : xd8_modelData->GetModel()->GetPositions()) { + x108_aabb.accumulateBounds({item.x, item.y, item.z}); } } diff --git a/Runtime/Character/CModelData.cpp b/Runtime/Character/CModelData.cpp index 0aab38f45..33e57eb2b 100644 --- a/Runtime/Character/CModelData.cpp +++ b/Runtime/Character/CModelData.cpp @@ -286,7 +286,7 @@ void CModelData::RenderThermal(const zeus::CTransform& xf, const zeus::CColor& m if (x10_animData) { CSkinnedModel& model = PickAnimatedModel(EWhichModel::ThermalHot); - x10_animData->SetupRender(model, nullptr, nullptr); + x10_animData->SetupRender(model, nullptr, {}); ThermalDraw(model, mulColor, addColor, flags); } else { auto& model = PickStaticModel(EWhichModel::ThermalHot); @@ -335,7 +335,7 @@ void CModelData::Render(EWhichModel which, const zeus::CTransform& xf, const CAc } if (x10_animData) { - x10_animData->Render(PickAnimatedModel(which), drawFlags, nullptr, nullptr); + x10_animData->Render(PickAnimatedModel(which), drawFlags, nullptr, {}); } else { // TODO supposed to be optional_object? if (x1c_normalModel) { @@ -357,10 +357,10 @@ void CModelData::FlatDraw(EWhichModel which, const zeus::CTransform& xf, bool un g_Renderer->SetModelMatrix(xf * zeus::CTransform::Scale(x0_scale)); CGraphics::DisableAllLights(); if (!x10_animData) { - g_Renderer->DrawModelFlat(*PickStaticModel(which), flags, unsortedOnly, nullptr, nullptr); + g_Renderer->DrawModelFlat(*PickStaticModel(which), flags, unsortedOnly, {}, {}); } else { auto model = PickAnimatedModel(which); - x10_animData->SetupRender(model, nullptr, nullptr); + x10_animData->SetupRender(model, nullptr, {}); model.DoDrawCallback([=](TConstVectorRef positions, TConstVectorRef normals) { auto m = model.GetModel(); g_Renderer->DrawModelFlat(*m, flags, unsortedOnly, positions, normals); @@ -371,12 +371,12 @@ void CModelData::FlatDraw(EWhichModel which, const zeus::CTransform& xf, bool un void CModelData::MultiLightingDraw(EWhichModel which, const zeus::CTransform& xf, const CActorLights* lights, const zeus::CColor& alphaColor, const zeus::CColor& additiveColor) { CModel* model = nullptr; - const auto callback = [&](auto positions, auto normals) { + const auto callback = [&](TConstVectorRef positions, TConstVectorRef normals) { CGraphics::DisableAllLights(); constexpr CModelFlags flags1{5, 0, 3, zeus::CColor{1.f, 0.f}}; const CModelFlags flags2{5, 0, 1, alphaColor}; const CModelFlags flags3{7, 0, 1, additiveColor}; - if (positions == nullptr) { + if (positions.empty()) { model->Draw(flags1); if (lights != nullptr) { lights->ActivateLights(); @@ -395,12 +395,12 @@ void CModelData::MultiLightingDraw(EWhichModel which, const zeus::CTransform& xf CGraphics::SetModelMatrix(xf * zeus::CTransform::Scale(x0_scale)); if (x10_animData) { auto& skinnedModel = PickAnimatedModel(which); - x10_animData->SetupRender(skinnedModel, nullptr, nullptr); + x10_animData->SetupRender(skinnedModel, nullptr, {}); model = skinnedModel.GetModel().GetObj(); skinnedModel.DoDrawCallback(callback); } else { model = PickStaticModel(which).GetObj(); - callback(nullptr, nullptr); + callback({}, {}); } } @@ -415,7 +415,7 @@ void CModelData::MultiPassDraw(EWhichModel which, const zeus::CTransform& xf, co } if (x10_animData) { auto& skinnedModel = PickAnimatedModel(which); - x10_animData->SetupRender(skinnedModel, nullptr, nullptr); + x10_animData->SetupRender(skinnedModel, nullptr, {}); auto& model = *skinnedModel.GetModel(); skinnedModel.DoDrawCallback([&](auto positions, auto normals) { for (int i = 0; i < count; ++i) { @@ -443,12 +443,12 @@ void CModelData::DisintegrateDraw(EWhichModel which, const zeus::CTransform& xf, const auto aabb = GetBounds(scaledXf); if (x10_animData) { auto& model = PickAnimatedModel(which); - x10_animData->SetupRender(model, nullptr, nullptr); + x10_animData->SetupRender(model, nullptr, {}); model.DoDrawCallback([&](auto positions, auto normals) { g_Renderer->DrawModelDisintegrate(*model.GetModel(), tex, addColor, positions, normals, t); }); } else { - g_Renderer->DrawModelDisintegrate(*PickStaticModel(which), tex, addColor, nullptr, nullptr, t); + g_Renderer->DrawModelDisintegrate(*PickStaticModel(which), tex, addColor, {}, {}, t); } } diff --git a/Runtime/Character/CSkinRules.cpp b/Runtime/Character/CSkinRules.cpp index 41022a0d4..5a13ca5a1 100644 --- a/Runtime/Character/CSkinRules.cpp +++ b/Runtime/Character/CSkinRules.cpp @@ -52,7 +52,7 @@ void CSkinRules::BuildPoints(TConstVectorRef positions, TVectorRef out) { size_t offset = 0; for (auto& bone : x0_bones) { u32 vertexCount = bone.GetVertexCount(); - bone.BuildPoints(positions->data() + offset, out, vertexCount); + bone.BuildPoints(positions.data() + offset, out, vertexCount); offset += vertexCount; } } @@ -61,7 +61,7 @@ void CSkinRules::BuildNormals(TConstVectorRef normals, TVectorRef out) { size_t offset = 0; for (auto& bone : x0_bones) { u32 vertexCount = bone.GetVertexCount(); - bone.BuildNormals(normals->data() + offset, out, vertexCount); + bone.BuildNormals(normals.data() + offset, out, vertexCount); offset += vertexCount; } } @@ -85,15 +85,19 @@ static inline auto StreamInSkinWeighting(CInputStream& in) { CVirtualBone::CVirtualBone(CInputStream& in) : x0_weights(StreamInSkinWeighting(in)), x1c_vertexCount(in.ReadLong()) {} -void CVirtualBone::BuildPoints(const zeus::CVector3f* in, TVectorRef out, u32 count) const { +void CVirtualBone::BuildPoints(const aurora::Vec3* in, TVectorRef out, u32 count) const { for (u32 i = 0; i < count; ++i) { - out->emplace_back(x20_xf * in[i]); + const auto& vec = in[i]; + zeus::CVector3f zout = x20_xf * zeus::CVector3f{vec.x, vec.y, vec.z}; + out->emplace_back(zout.x(), zout.y(), zout.z()); } } -void CVirtualBone::BuildNormals(const zeus::CVector3f* in, TVectorRef out, u32 count) const { +void CVirtualBone::BuildNormals(const aurora::Vec3* in, TVectorRef out, u32 count) const { for (u32 i = 0; i < count; ++i) { - out->emplace_back(x50_rotation * in[i]); + const auto& vec = in[i]; + zeus::CVector3f zout = x50_rotation * zeus::CVector3f{vec.x, vec.y, vec.z}; + out->emplace_back(zout.x(), zout.y(), zout.z()); } } diff --git a/Runtime/Character/CSkinRules.hpp b/Runtime/Character/CSkinRules.hpp index 8c728f645..51269ae72 100644 --- a/Runtime/Character/CSkinRules.hpp +++ b/Runtime/Character/CSkinRules.hpp @@ -31,8 +31,8 @@ class CVirtualBone { public: explicit CVirtualBone(CInputStream& in); - void BuildPoints(const zeus::CVector3f* in, TVectorRef out, u32 count) const; - void BuildNormals(const zeus::CVector3f* in, TVectorRef out, u32 count) const; + void BuildPoints(const aurora::Vec3* in, TVectorRef out, u32 count) const; + void BuildNormals(const aurora::Vec3* in, TVectorRef out, u32 count) const; void BuildAccumulatedTransform(const CPoseAsTransforms& pose, const zeus::CVector3f* points); [[nodiscard]] const auto& GetWeights() const { return x0_weights; } diff --git a/Runtime/Collision/CCollisionActor.cpp b/Runtime/Collision/CCollisionActor.cpp index 952365848..147e04ab9 100644 --- a/Runtime/Collision/CCollisionActor.cpp +++ b/Runtime/Collision/CCollisionActor.cpp @@ -185,17 +185,18 @@ void CCollisionActor::SetSphereRadius(float radius) { x288_sphereRadius = radius; x284_spherePrimitive->SetSphereRadius(radius); } + void CCollisionActor::DebugDraw() { - zeus::CAABox aabox; - if (x258_primitiveType == EPrimitiveType::OBBTreeGroup) - aabox = x27c_obbTreeGroupPrimitive->CalculateAABox(x34_transform); - else if (x258_primitiveType == EPrimitiveType::AABox) - aabox = x280_aaboxPrimitive->CalculateAABox(x34_transform); - else if (x258_primitiveType == EPrimitiveType::Sphere) - aabox = x284_spherePrimitive->CalculateAABox(x34_transform); - m_aabox.setAABB(aabox); - zeus::CColor col = !GetActive() ? zeus::skRed : zeus::skGreen; - col.a() = 0.5f; - m_aabox.draw(col); + // zeus::CAABox aabox; + // if (x258_primitiveType == EPrimitiveType::OBBTreeGroup) + // aabox = x27c_obbTreeGroupPrimitive->CalculateAABox(x34_transform); + // else if (x258_primitiveType == EPrimitiveType::AABox) + // aabox = x280_aaboxPrimitive->CalculateAABox(x34_transform); + // else if (x258_primitiveType == EPrimitiveType::Sphere) + // aabox = x284_spherePrimitive->CalculateAABox(x34_transform); + // m_aabox.setAABB(aabox); + // zeus::CColor col = !GetActive() ? zeus::skRed : zeus::skGreen; + // col.a() = 0.5f; + // m_aabox.draw(col); } } // namespace metaforce diff --git a/Runtime/Collision/CCollisionActor.hpp b/Runtime/Collision/CCollisionActor.hpp index 3c4f2d28f..a400b2ae7 100644 --- a/Runtime/Collision/CCollisionActor.hpp +++ b/Runtime/Collision/CCollisionActor.hpp @@ -3,7 +3,6 @@ #include #include -#include "Runtime/Graphics/Shaders/CAABoxShader.hpp" #include "Runtime/World/CDamageVulnerability.hpp" #include "Runtime/World/CHealthInfo.hpp" #include "Runtime/World/CPhysicsActor.hpp" @@ -33,8 +32,6 @@ class CCollisionActor : public CPhysicsActor { EWeaponCollisionResponseTypes x300_responseType = EWeaponCollisionResponseTypes::EnemyNormal; zeus::CVector3f x304_extendedTouchBounds = zeus::skZero3f; - CAABoxShader m_aabox; - public: DEFINE_ENTITY CCollisionActor(TUniqueId uid, TAreaId areaId, TUniqueId owner, const zeus::CVector3f& extent, diff --git a/Runtime/Graphics/CBooRender.hpp.old b/Runtime/Graphics/CBooRender.hpp.old deleted file mode 100644 index 89c73ef0e..000000000 --- a/Runtime/Graphics/CBooRender.hpp.old +++ /dev/null @@ -1,303 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include - -#include "Runtime/CRandom16.hpp" -#include "Runtime/rstl.hpp" -#include "Runtime/Graphics/CDrawable.hpp" -#include "Runtime/Graphics/CDrawablePlaneObject.hpp" -#include "Runtime/Graphics/CPVSVisSet.hpp" -#include "Runtime/Graphics/CTexture.hpp" -#include "Runtime/Graphics/IRenderer.hpp" -#include "Runtime/Graphics/Shaders/CFogVolumeFilter.hpp" -#include "Runtime/Graphics/Shaders/CFogVolumePlaneShader.hpp" -#include "Runtime/Graphics/Shaders/CPhazonSuitFilter.hpp" -#include "Runtime/Graphics/Shaders/CSpaceWarpFilter.hpp" -#include "Runtime/Graphics/Shaders/CThermalColdFilter.hpp" -#include "Runtime/Graphics/Shaders/CThermalHotFilter.hpp" -#include "Runtime/World/CGameArea.hpp" -#include "CMetroidModelInstance.hpp" - -#include -#include -#include -#include -#include -#include -#include - -namespace metaforce { -class CBooModel; -class CMemorySys; -class CParticleGen; -class CTexture; -class IFactory; -class IObjectStore; - -class Buckets; - -enum class EWorldShadowMode { None, WorldOnActorShadow, BallOnWorldShadow, BallOnWorldIds, MAX }; - -class CBooRenderer final : public IRenderer { - friend class CBooModel; - friend class CGameArea; - friend class CModel; - friend class CMorphBallShadow; - friend class CWorldTransManager; - - struct CAreaListItem { - const std::vector* x0_geometry; - const CAreaRenderOctTree* x4_octTree; - /* originally auto_ptrs of vectors */ - std::unordered_map> x8_textures; - std::vector x10_models; - int x18_areaIdx; - /* Per-area octree-word major, light bits minor */ - std::vector x1c_lightOctreeWords; - const SShader* m_shaderSet; - - CAreaListItem(const std::vector* geom, const CAreaRenderOctTree* octTree, - std::unordered_map>&& textures, std::vector&& models, - int areaIdx, const SShader* shaderSet); - ~CAreaListItem(); - }; - - struct CFogVolumeListItem { - zeus::CTransform x0_transform; - zeus::CColor x30_color; - zeus::CAABox x34_aabb; - TLockedToken x4c_model; - // bool x58_b; Optional for model token - const CSkinnedModel* x5c_skinnedModel = nullptr; - CFogVolumeListItem(const zeus::CTransform& xf, const zeus::CColor& color, const zeus::CAABox& aabb, - const TLockedToken* model, const CSkinnedModel* sModel) - : x0_transform(xf), x30_color(color), x34_aabb(aabb), x5c_skinnedModel(sModel) { - if (model) - x4c_model = *model; - } - }; - - IFactory& x8_factory; - IObjectStore& xc_store; - TLockedToken m_staticEntropy; - // CFont x10_fnt; - u32 x18_ = 0; - std::list x1c_areaListItems; - zeus::CFrustum x44_frustumPlanes; - - TDrawableCallback xa8_drawableCallback; - void* xac_callbackContext; - - zeus::CPlane xb0_viewPlane = {0.f, 1.f, 0.f, 0.f}; - - enum class EPVSMode { Mask, PVS, PVSAndMask } xc4_pvsMode = EPVSMode::Mask; - std::optional xc8_pvs; - u32 xe0_pvsAreaIdx = 0; - - // boo::ITextureS* xe4_blackTex = nullptr; - bool xee_24_ : 1 = true; - - aurora::gfx::TextureHandle m_clearTexture; - aurora::gfx::TextureHandle m_blackTexture; - aurora::gfx::TextureHandle m_whiteTexture; - std::unordered_map m_colorTextures; - - aurora::gfx::TextureHandle x14c_reflectionTex; - // boo::ITextureS* x150_mirrorRamp = nullptr; -// aurora::gfx::TextureHandle x1b8_fogVolumeRamp; - aurora::gfx::TextureHandle x220_sphereRamp; -// TLockedToken m_thermoPaletteTex; -// aurora::gfx::TextureHandle x288_thermoPalette; -// TLockedToken m_ballFadeTex; - aurora::gfx::TextureHandle m_ballFade; - aurora::gfx::TextureHandle m_ballShadowId; -// boo::ObjToken m_scanLinesEvenVBO; -// boo::ObjToken m_scanLinesOddVBO; - int m_ballShadowIdW = 64; - int m_ballShadowIdH = 64; - - CRandom16 x2a8_thermalRand; - std::list x2ac_fogVolumes; -// std::list m_fogVolumePlaneShaders; -// std::list::iterator m_nextFogVolumePlaneShader; -// std::list m_fogVolumeFilters; -// std::list::iterator m_nextFogVolumeFilter; - std::list> x2c4_spaceWarps; - u32 x2dc_reflectionAge = 2; - zeus::CColor x2e0_ = zeus::skWhite; - zeus::CVector3f x2e4_ = {0.f, 1.f, 0.f}; - - CSpaceWarpFilter m_spaceWarpFilter; - - float x2f0_thermalVisorLevel; - zeus::CColor x2f4_thermColor; - float x2f8_thermColdScale = 0.f; - zeus::CColor x2fc_tevReg1Color = {1.f, 0.f, 1.f, 1.f}; - std::optional m_thermColdFilter; - std::optional m_thermHotFilter; - - std::vector x300_dynamicLights; - - u32 x310_phazonSuitMaskCountdown = 0; - // std::unique_ptr x314_phazonSuitMask; - CPhazonSuitFilter m_phazonSuitFilter; - - bool x318_24_refectionDirty : 1 = false; - bool x318_25_drawWireframe : 1 = false; - bool x318_26_requestRGBA6 : 1 = false; - bool x318_27_currentRGBA6 : 1 = false; - bool x318_28_disableFog : 1 = false; - bool x318_29_thermalVisor : 1 = false; - bool x318_30_inAreaDraw : 1 = false; - bool x318_31_persistRGBA6 : 1 = false; - bool m_thermalHotPass : 1 = false; - -// void GenerateFogVolumeRampTex(); -// void GenerateSphereRampTex(); -// void GenerateScanLinesVBO(); -// void LoadThermoPalette(); -// void LoadBallFade(); - - void ActivateLightsForModel(CAreaListItem* item, CBooModel& model); - void RenderBucketItems(CAreaListItem* item); - void HandleUnsortedModel(CAreaListItem* item, CBooModel& model, const CModelFlags& flags); - static void CalcDrawFogFan(const zeus::CPlane* planes, size_t numPlanes, const zeus::CVector3f* verts, - size_t numVerts, size_t iteration, size_t level, CFogVolumePlaneShader& fogVol); - static void DrawFogSlices(const zeus::CPlane* planes, size_t numPlanes, size_t iteration, - const zeus::CVector3f& center, float delta, CFogVolumePlaneShader& fogVol); - static void RenderFogVolumeModel(const zeus::CAABox& aabb, const CModel* model, const zeus::CTransform& modelMtx, - const zeus::CTransform& viewMtx, const CSkinnedModel* sModel, int pass); - void SetupRendererStates() const; - - void ReallyDrawPhazonSuitIndirectEffect(const zeus::CColor& vertColor, /*const CTexture& maskTex,*/ - const CTexture& indTex, const zeus::CColor& modColor, float scale, float offX, - float offY); - void ReallyDrawPhazonSuitEffect(const zeus::CColor& modColor /*, const CTexture& maskTex*/); - void DoPhazonSuitIndirectAlphaBlur(float blurRadius /*, float f2*/, const TLockedToken& indTex); - -public: - CBooRenderer(IObjectStore& store, IFactory& resFac); - ~CBooRenderer() override; - - void AddWorldSurfaces(CBooModel& model); - - std::list::iterator FindStaticGeometry(const std::vector*); - void AddStaticGeometry(const std::vector* geometry, const CAreaRenderOctTree* octTree, - int areaIdx, const SShader* shaderSet) override; - void EnablePVS(const CPVSVisSet& set, u32 areaIdx) override; - void DisablePVS() override; - void UpdateAreaUniforms(int areaIdx, EWorldShadowMode shadowMode = EWorldShadowMode::None, bool activateLights = true, - int cubeFace = -1, const CModelFlags* ballShadowFlags = nullptr); - void RemoveStaticGeometry(const std::vector*) override; - void DrawAreaGeometry(int areaIdx, int mask, int targetMask) override; - void DrawUnsortedGeometry(int areaIdx, int mask, int targetMask, bool shadowRender = false) override; - void DrawSortedGeometry(int areaIdx, int mask, int targetMask) override; - void DrawStaticGeometry(int areaIdx, int mask, int targetMask) override; - void DrawModelFlat(const CModel& model, const CModelFlags& flags, bool unsortedOnly) override; - void PostRenderFogs() override; - void SetModelMatrix(const zeus::CTransform& xf) override; - void AddParticleGen(CParticleGen& gen) override; - void AddParticleGen(CParticleGen& gen, const zeus::CVector3f& pos, const zeus::CAABox& bounds) override; - void AddPlaneObject(void* obj, const zeus::CAABox& aabb, const zeus::CPlane& plane, int type) override; - void AddDrawable(void* obj, const zeus::CVector3f& pos, const zeus::CAABox& aabb, int mode, - EDrawableSorting sorting) override; - void SetDrawableCallback(TDrawableCallback cb, void* ctx) override; - void SetWorldViewpoint(const zeus::CTransform& xf) override; - void SetPerspective(float fovy, float width, float height, float znear, float zfar) override; - void SetPerspective(float fovy, float aspect, float znear, float zfar) override; - std::pair SetViewportOrtho(bool centered, float znear, float zfar) override; - void SetClippingPlanes(const zeus::CFrustum& frustum) override; - void SetViewport(int left, int bottom, int width, int height) override; - // void SetDepthReadWrite(bool, bool); - // void SetBlendMode_AdditiveAlpha(); - // void SetBlendMode_AlphaBlended(); - // void SetBlendMode_NoColorWrite(); - // void SetBlendMode_ColorMultiply(); - // void SetBlendMode_InvertDst(); - // void SetBlendMode_InvertSrc(); - // void SetBlendMode_Replace(); - // void SetBlendMode_AdditiveDestColor(); - void SetDebugOption(EDebugOption, int) override; - void BeginScene() override; - void EndScene() override; - // void BeginPrimitive(EPrimitiveType, int); - // void BeginLines(int); - // void BeginLineStrip(int); - // void BeginTriangles(int); - // void BeginTriangleStrip(int); - // void BeginTriangleFan(int); - // void PrimVertex(const zeus::CVector3f&); - // void PrimNormal(const zeus::CVector3f&); - // void PrimColor(float, float, float, float); - // void PrimColor(const zeus::CColor&); - // void EndPrimitive(); - void SetAmbientColor(const zeus::CColor& color) override; - void DrawString(const char* string, int, int) override; - u32 GetFPS() override; - void CacheReflection(TReflectionCallback cb, void* ctx, bool clearAfter) override; - void DrawSpaceWarp(const zeus::CVector3f& pt, float strength) override; - void DrawThermalModel(const CModel& model, const zeus::CColor& multCol, const zeus::CColor& addCol) override; - void DrawXRayOutline(const zeus::CAABox&) override; - void SetWireframeFlags(int flags) override; - void SetWorldFog(ERglFogMode mode, float startz, float endz, const zeus::CColor& color) override; - void RenderFogVolume(const zeus::CColor& color, const zeus::CAABox& aabb, const TLockedToken* model, - const CSkinnedModel* sModel) override; - void SetThermal(bool thermal, float level, const zeus::CColor& color) override; - void SetThermalColdScale(float scale) override; - void DoThermalBlendCold() override; - void DoThermalBlendHot() override; - u32 GetStaticWorldDataSize() override; - void PrepareDynamicLights(const std::vector& lights) override; - void SetGXRegister1Color(const zeus::CColor& color) override; - void SetWorldLightFadeLevel(float level) override; - void SetWorldLightMultiplyColor(const zeus::CColor& col) override; - void DrawPhazonSuitIndirectEffect(const zeus::CColor& nonIndirectMod, const TLockedToken& indTex, - const zeus::CColor& indirectMod, float blurRadius, float indScale, float indOffX, - float indOffY); - void AllocatePhazonSuitMaskTexture(); - - void ReallyRenderFogVolume(const zeus::CColor& color, const zeus::CAABox& aabb, const CModel* model, - const CSkinnedModel* sModel); - -// const boo::ObjToken& GetThermoPalette() const { return x288_thermoPalette; } -// const boo::ObjToken& GetFogRampTex() const { return x1b8_fogVolumeRamp; } -// const boo::ObjToken& GetRandomStaticEntropyTex() const { return m_staticEntropy->GetBooTexture(); } -// const boo::ObjToken& GetScanLinesEvenVBO() const { return m_scanLinesEvenVBO; } -// const boo::ObjToken& GetScanLinesOddVBO() const { return m_scanLinesOddVBO; } - - const aurora::gfx::TextureHandle& GetClearTexture() const { return m_clearTexture; } - const aurora::gfx::TextureHandle& GetBlackTexture() const { return m_blackTexture; } - const aurora::gfx::TextureHandle& GetWhiteTexture() const { return m_whiteTexture; } - - aurora::gfx::TextureHandle GetColorTexture(const zeus::CColor& color); - - static void BindMainDrawTarget() { -// CGraphics::g_BooMainCommandQueue->setRenderTarget(CGraphics::g_SpareTexture); - } - void BindReflectionDrawTarget() { -// CGraphics::g_BooMainCommandQueue->setRenderTarget(x14c_reflectionTex); - } - void BindBallShadowIdTarget() { -// CGraphics::g_BooMainCommandQueue->setRenderTarget(m_ballShadowId); - SetViewport(0, 0, m_ballShadowIdW, m_ballShadowIdH); - } - void ResolveBallShadowIdTarget() { -// CGraphics::g_BooMainCommandQueue->resolveBindTexture( -// m_ballShadowId, boo::SWindowRect(0, 0, m_ballShadowIdW, m_ballShadowIdH), false, 0, true, false); - } - - void FindOverlappingWorldModels(std::vector& modelBits, const zeus::CAABox& aabb) const; - int DrawOverlappingWorldModelIDs(int alphaVal, const std::vector& modelBits, const zeus::CAABox& aabb); - void DrawOverlappingWorldModelShadows(int alphaVal, const std::vector& modelBits, const zeus::CAABox& aabb, - float alpha); - - bool IsThermalVisorActive() const { return x318_29_thermalVisor; } - bool IsThermalVisorHotPass() const { return m_thermalHotPass; } -}; - -} // namespace metaforce diff --git a/Runtime/Graphics/CBooRenderer.cpp b/Runtime/Graphics/CBooRenderer.cpp deleted file mode 100644 index c00eba34f..000000000 --- a/Runtime/Graphics/CBooRenderer.cpp +++ /dev/null @@ -1,1410 +0,0 @@ -#include "Runtime/Graphics/CBooRenderer.hpp" - -#include "Runtime/GameGlobalObjects.hpp" -#include "Runtime/rstl.hpp" -#include "Runtime/Collision/CAreaOctTree.hpp" -#include "Runtime/Graphics/CMetroidModelInstance.hpp" -#include "Runtime/Graphics/CModel.hpp" -#include "Runtime/Graphics/CSkinnedModel.hpp" -#include "Runtime/Particle/CDecal.hpp" -#include "Runtime/Particle/CElementGen.hpp" -#include "Runtime/Particle/CGenDescription.hpp" -#include "Runtime/Particle/CParticleGen.hpp" -#include "Runtime/World/CActor.hpp" - -#include -#include - -#include -#include -#include -#include -#include - -#define FOGVOL_RAMP_RES 256 -#define FOGVOL_FAR 750.0 -#define FOGVOL_NEAR 0.2 -#define SPHERE_RAMP_RES 32 - -namespace metaforce { -namespace { -struct FogVolumeControl { - std::array, 12> xfc_{ - {{0, 1}, {1, 3}, {3, 2}, {2, 0}, {4, 5}, {5, 7}, {7, 6}, {6, 4}, {0, 4}, {1, 5}, {3, 7}, {2, 6}}, - }; - std::array x15c_{}; - // GXVtxDescList x17c_; {{POS, DIRECT}, {TEX0, DIRECT}} -}; - -logvisor::Module Log("CBooRenderer"); - -rstl::reserved_vector sDataHolder; -rstl::reserved_vector, 50> sBucketsHolder; -rstl::reserved_vector sPlaneObjectDataHolder; -rstl::reserved_vector sPlaneObjectBucketHolder; - -constexpr FogVolumeControl s_FogVolumeCtrl{}; - -constexpr std::array, 3> OrthogonalAxis{ - {{1, 2}, {0, 2}, {0, 1}}, -}; - -constexpr bool TestBit(const u32* words, size_t bit) { return (words[bit / 32] & (1U << (bit & 0x1f))) != 0; } - -float GetPlaneInterpolant(const zeus::CPlane& plane, const zeus::CVector3f& vert1, const zeus::CVector3f& vert2) { - return zeus::clamp(0.f, -plane.pointToPlaneDist(vert1) / (vert2 - vert1).dot(plane.normal()), 1.f); -} -} // Anonymous namespace - -class Buckets { - friend class CBooRenderer; - - static inline rstl::reserved_vector sBucketIndex; - static inline rstl::reserved_vector* sData = nullptr; - static inline rstl::reserved_vector, 50>* sBuckets = nullptr; - static inline rstl::reserved_vector* sPlaneObjectData = nullptr; - static inline rstl::reserved_vector* sPlaneObjectBucket = nullptr; - static constexpr std::array skWorstMinMaxDistance{99999.0f, -99999.0f}; - static inline std::array sMinMaxDistance{0.0f, 0.0f}; - -public: - static void Clear(); - static void Sort(); - static void InsertPlaneObject(float closeDist, float farDist, const zeus::CAABox& aabb, bool invertTest, - const zeus::CPlane& plane, bool zOnly, EDrawableType dtype, void* data); - static void Insert(const zeus::CVector3f& pos, const zeus::CAABox& aabb, EDrawableType dtype, void* data, - const zeus::CPlane& plane, u16 extraSort); - static void Shutdown(); - static void Init(); -}; - -void Buckets::Clear() { - sData->clear(); - sBucketIndex.clear(); - sPlaneObjectData->clear(); - sPlaneObjectBucket->clear(); - for (rstl::reserved_vector& bucket : *sBuckets) { - bucket.clear(); - } - sMinMaxDistance = skWorstMinMaxDistance; -} - -void Buckets::Sort() { - float delta = std::max(1.f, sMinMaxDistance[1] - sMinMaxDistance[0]); - float pitch = 49.f / delta; - for (auto it = sPlaneObjectData->begin(); it != sPlaneObjectData->end(); ++it) - if (sPlaneObjectBucket->size() != sPlaneObjectBucket->capacity()) - sPlaneObjectBucket->push_back(s16(it - sPlaneObjectData->begin())); - - u32 precision = 50; - if (sPlaneObjectBucket->size()) { - std::sort(sPlaneObjectBucket->begin(), sPlaneObjectBucket->end(), - [](u16 a, u16 b) { return (*sPlaneObjectData)[a].GetDistance() < (*sPlaneObjectData)[b].GetDistance(); }); - precision = 50 / u32(sPlaneObjectBucket->size() + 1); - pitch = 1.f / (delta / float(precision - 2)); - - int accum = 0; - for (u16 idx : *sPlaneObjectBucket) { - ++accum; - CDrawablePlaneObject& planeObj = (*sPlaneObjectData)[idx]; - planeObj.x24_targetBucket = u16(precision * accum); - } - } - - for (CDrawable& drawable : *sData) { - int slot; - float relDist = drawable.GetDistance() - sMinMaxDistance[0]; - if (sPlaneObjectBucket->empty()) { - slot = zeus::clamp(1, int(relDist * pitch), 49); - } else { - slot = zeus::clamp(0, int(relDist * pitch), int(precision) - 2); - for (u16 idx : *sPlaneObjectBucket) { - CDrawablePlaneObject& planeObj = (*sPlaneObjectData)[idx]; - bool partial, full; - if (planeObj.x3c_25_zOnly) { - partial = drawable.GetBounds().max.z() > planeObj.GetPlane().d(); - full = drawable.GetBounds().min.z() > planeObj.GetPlane().d(); - } else { - partial = planeObj.GetPlane().pointToPlaneDist( - drawable.GetBounds().closestPointAlongVector(planeObj.GetPlane().normal())) > 0.f; - full = planeObj.GetPlane().pointToPlaneDist( - drawable.GetBounds().furthestPointAlongVector(planeObj.GetPlane().normal())) > 0.f; - } - bool cont; - if (drawable.GetType() == EDrawableType::Particle) - cont = planeObj.x3c_24_invertTest ? !partial : full; - else - cont = planeObj.x3c_24_invertTest ? (!partial || !full) : (partial || full); - if (!cont) - break; - slot += precision; - } - } - - if (slot == -1) - slot = 49; - rstl::reserved_vector& bucket = (*sBuckets)[slot]; - if (bucket.size() < bucket.capacity()) - bucket.push_back(&drawable); - // else - // spdlog::fatal("Full bucket!!!"); - } - - u16 bucketIdx = u16(sBuckets->size()); - for (auto it = sBuckets->rbegin(); it != sBuckets->rend(); ++it) { - --bucketIdx; - sBucketIndex.push_back(bucketIdx); - rstl::reserved_vector& bucket = *it; - if (bucket.size()) { - std::sort(bucket.begin(), bucket.end(), [](CDrawable* a, CDrawable* b) { - if (a->GetDistance() == b->GetDistance()) - return a->GetExtraSort() > b->GetExtraSort(); - return a->GetDistance() > b->GetDistance(); - }); - } - } - - for (auto it = sPlaneObjectBucket->rbegin(); it != sPlaneObjectBucket->rend(); ++it) { - CDrawablePlaneObject& planeObj = (*sPlaneObjectData)[*it]; - rstl::reserved_vector& bucket = (*sBuckets)[planeObj.x24_targetBucket]; - bucket.push_back(&planeObj); - } -} - -void Buckets::InsertPlaneObject(float closeDist, float farDist, const zeus::CAABox& aabb, bool invertTest, - const zeus::CPlane& plane, bool zOnly, EDrawableType dtype, void* data) { - if (sPlaneObjectData->size() == sPlaneObjectData->capacity()) { - return; - } - sPlaneObjectData->emplace_back(dtype, closeDist, farDist, aabb, invertTest, plane, zOnly, data); -} - -void Buckets::Insert(const zeus::CVector3f& pos, const zeus::CAABox& aabb, EDrawableType dtype, void* data, - const zeus::CPlane& plane, u16 extraSort) { - if (sData->size() == sData->capacity()) { - spdlog::fatal("Rendering buckets filled to capacity"); - return; - } - - const float dist = plane.pointToPlaneDist(pos); - sData->emplace_back(dtype, extraSort, dist, aabb, data); - sMinMaxDistance[0] = std::min(sMinMaxDistance[0], dist); - sMinMaxDistance[1] = std::max(sMinMaxDistance[1], dist); -} - -void Buckets::Shutdown() { - sData = nullptr; - sBuckets = nullptr; - sPlaneObjectData = nullptr; - sPlaneObjectBucket = nullptr; -} - -void Buckets::Init() { - sData = &sDataHolder; - sBuckets = &sBucketsHolder; - sBuckets->resize(50); - sPlaneObjectData = &sPlaneObjectDataHolder; - sPlaneObjectBucket = &sPlaneObjectBucketHolder; - sMinMaxDistance = skWorstMinMaxDistance; -} - -CBooRenderer::CAreaListItem::CAreaListItem(const std::vector* geom, - const CAreaRenderOctTree* octTree, - std::unordered_map>&& textures, - std::vector&& models, int areaIdx, const SShader* shaderSet) -: x0_geometry(geom) -, x4_octTree(octTree) -, x8_textures(std::move(textures)) -, x10_models(std::move(models)) -, x18_areaIdx(areaIdx) -, m_shaderSet(shaderSet) {} - -CBooRenderer::CAreaListItem::~CAreaListItem() = default; - -void CBooRenderer::ActivateLightsForModel(CAreaListItem* item, CBooModel& model) { - OPTICK_EVENT(); - constexpr size_t lightCount = 4; - std::vector thisLights; - thisLights.reserve(lightCount); - - if (!x300_dynamicLights.empty()) { - u32 lightOctreeWordCount = 0; - const u32* lightOctreeWords = nullptr; - if (item != nullptr && model.x44_areaInstanceIdx != UINT32_MAX) { - lightOctreeWordCount = item->x4_octTree->x14_bitmapWordCount; - lightOctreeWords = item->x1c_lightOctreeWords.data(); - } - - std::array lightRads{-1.f, -1.f, -1.f, -1.f}; - std::array lightRefs{}; - auto it = x300_dynamicLights.begin(); - for (size_t i = 0; i < lightCount && it != x300_dynamicLights.end(); - ++it, lightOctreeWords += lightOctreeWordCount) { - CLight& refLight = *it; - if (lightOctreeWords != nullptr && !TestBit(lightOctreeWords, model.x44_areaInstanceIdx)) { - continue; - } - - const float radius = - model.x20_aabb.intersectionRadius(zeus::CSphere(refLight.GetPosition(), refLight.GetRadius())); - - bool foundLight = false; - for (size_t j = 0; j < i; ++j) { - if (lightRefs[j] == &refLight) { - continue; - } - if (radius < 0.f) { - break; - } - if (lightRads[j] <= radius) { - break; - } - lightRads[j] = radius; - thisLights.push_back(refLight); - foundLight = true; - break; - } - - if (foundLight) { - continue; - } - - lightRads[i] = radius; - if (radius < 0.f) { - continue; - } - lightRefs[i] = &refLight; - thisLights.push_back(refLight); - ++i; - } - } - - model.ActivateLights(thisLights); -} - -void CBooRenderer::RenderBucketItems(CAreaListItem* item) { - CModelFlags flags; - flags.m_noZWrite = true; - flags.m_extendedShader = EExtendedShader::Lighting; - - for (u16 idx : Buckets::sBucketIndex) { - rstl::reserved_vector& bucket = (*Buckets::sBuckets)[idx]; - for (CDrawable* drawable : bucket) { - switch (drawable->GetType()) { - case EDrawableType::Particle: { - static_cast(drawable->GetData())->Render(); - break; - } - case EDrawableType::WorldSurface: { - // SetupRendererStates(); - auto* surf = static_cast(drawable->GetData()); - CBooModel* model = surf->m_parent; - if (model) { - ActivateLightsForModel(item, *model); - model->DrawSurface(*surf, flags); - } - break; - } - default: { - if (xa8_drawableCallback) { - xa8_drawableCallback(drawable->GetData(), xac_callbackContext, int(drawable->GetType()) - 2); - } - break; - } - } - } - } -} - -void CBooRenderer::HandleUnsortedModel(CAreaListItem* item, CBooModel& model, const CModelFlags& flags) { - // ActivateLightsForModel(item, model); - CBooSurface* surf = model.x38_firstUnsortedSurface; - while (surf) { - model.DrawSurface(*surf, flags); - surf = surf->m_next; - } -} - -void CBooRenderer::CalcDrawFogFan(const zeus::CPlane* planes, size_t numPlanes, const zeus::CVector3f* verts, - size_t numVerts, size_t iteration, size_t level, CFogVolumePlaneShader& fogVol) { - if (level == iteration) { - CalcDrawFogFan(planes, numPlanes, verts, numVerts, iteration, level + 1, fogVol); - return; - } - - if (level == numPlanes) { - fogVol.addFan(verts, numVerts); - return; - } - - const zeus::CPlane& plane = planes[level]; - size_t insidePlaneCount = 0; - std::array outsidePlane; - for (size_t i = 0; i < numVerts; ++i) { - outsidePlane[insidePlaneCount++] = plane.normal().dot(verts[i]) < plane.d(); - } - - size_t numUseVerts = 0; - std::array useVerts; - for (size_t i = 0; i < numVerts; ++i) { - const size_t nextIdx = (i + 1) % numVerts; - const int insidePair = int(outsidePlane[i]) | (int(outsidePlane[nextIdx]) << 1); - if ((insidePair & 0x1) == 0) { - useVerts[numUseVerts++] = verts[i]; - } - if (insidePair == 1 || insidePair == 2) { - /* Inside/outside transition; clip verts to other plane boundary */ - const zeus::CVector3f vert1 = verts[i]; - const zeus::CVector3f vert2 = verts[nextIdx]; - const float interp = GetPlaneInterpolant(plane, vert1, vert2); - if (interp > 0.f || interp < 1.f) { - useVerts[numUseVerts++] = (vert1 * (1.f - interp)) + (vert2 * interp); - } - } - } - - if (numUseVerts < 3) { - return; - } - - CalcDrawFogFan(planes, numPlanes, useVerts.data(), numUseVerts, iteration, level + 1, fogVol); -} - -void CBooRenderer::DrawFogSlices(const zeus::CPlane* planes, size_t numPlanes, size_t iteration, - const zeus::CVector3f& center, float longestAxis, CFogVolumePlaneShader& fogVol) { - u32 vertCount = 0; - std::array verts; - u32 vert2Count = 0; - std::array verts2; - const zeus::CPlane& plane = planes[iteration]; - int longestNormAxis = std::fabs(plane[1]) > std::fabs(plane[0]); - if (std::fabs(plane[2]) > std::fabs(plane[longestNormAxis])) { - longestNormAxis = 2; - } - - const zeus::CVector3d pointOnPlane = center - (plane.pointToPlaneDist(center) * plane.normal()); - - float deltaSign = plane[longestNormAxis] >= 0.f ? -1.f : 1.f; - if (longestNormAxis == 1) { - deltaSign = -deltaSign; - } - - zeus::CVector3d vec1; - zeus::CVector3d vec2; - - vec1[OrthogonalAxis[longestNormAxis][0]] = longestAxis; - vec2[OrthogonalAxis[longestNormAxis][1]] = deltaSign * longestAxis; - - verts[vertCount++] = pointOnPlane - vec1 - vec2; - verts[vertCount++] = pointOnPlane + vec1 - vec2; - verts[vertCount++] = pointOnPlane + vec1 + vec2; - verts[vertCount++] = pointOnPlane - vec1 + vec2; - - const zeus::CVector3d planeNormal = plane.normal(); - for (const zeus::CVector3d& vert : verts) { - verts2[vert2Count++] = vert - (planeNormal * zeus::CVector3f(planeNormal.dot(vert) - plane.d())); - } - - CalcDrawFogFan(planes, numPlanes, verts2.data(), vert2Count, iteration, 0, fogVol); -} - -void CBooRenderer::RenderFogVolumeModel(const zeus::CAABox& aabb, const CModel* model, const zeus::CTransform& modelMtx, - const zeus::CTransform& viewMtx, const CSkinnedModel* sModel, int pass) { - if (!model && !sModel) { - if (pass == 0) { - zeus::CAABox xfAABB = aabb.getTransformedAABox(modelMtx); - zeus::CUnitVector3f viewNormal(viewMtx.basis[1]); - const std::array planes{{ - {zeus::skRight, xfAABB.min.x()}, - {zeus::skLeft, -xfAABB.max.x()}, - {zeus::skForward, xfAABB.min.y()}, - {zeus::skBack, -xfAABB.max.y()}, - {zeus::skUp, xfAABB.min.z()}, - {zeus::skDown, -xfAABB.max.z()}, - {viewNormal, viewNormal.dot(viewMtx.origin) + 0.2f + 0.1f}, - }}; - - CGraphics::SetModelMatrix(zeus::CTransform()); - - const float longestAxis = std::max(std::max(xfAABB.max.x() - xfAABB.min.x(), xfAABB.max.y() - xfAABB.min.y()), - xfAABB.max.z() - xfAABB.min.z()) * - 2.f; - - CFogVolumePlaneShader fvs; - fvs.reset(7 * 6); - for (size_t i = 0; i < planes.size(); ++i) { - DrawFogSlices(planes.data(), planes.size(), i, xfAABB.center(), longestAxis, fvs); - } - aurora::gfx::queue_fog_volume_plane(fvs.m_verts, 0); - } else { - aurora::gfx::queue_fog_volume_plane({}, pass); - } - } else { - CModelFlags flags; - switch (pass) { - case 0: - default: - flags.m_extendedShader = EExtendedShader::SolidColorFrontfaceCullLEqualAlphaOnly; - flags.x4_color = zeus::CColor(1.f, 1.f, 1.f, 1.f); - break; - case 1: - flags.m_extendedShader = EExtendedShader::SolidColorFrontfaceCullAlwaysAlphaOnly; - flags.x4_color = zeus::CColor(1.f, 1.f, 1.f, 1.f); - break; - case 2: - flags.m_extendedShader = EExtendedShader::SolidColorBackfaceCullLEqualAlphaOnly; - flags.x4_color = zeus::CColor(1.f, 1.f, 1.f, 0.f); - break; - case 3: - flags.m_extendedShader = EExtendedShader::SolidColorBackfaceCullGreaterAlphaOnly; - flags.x4_color = zeus::CColor(1.f, 1.f, 1.f, 0.f); - break; - } - - if (sModel) { - sModel->Draw(flags); - } else { - model->UpdateLastFrame(); - model->Draw(flags); - } - } -} - -void CBooRenderer::SetupRendererStates() const { - CGraphics::SetModelMatrix(zeus::CTransform()); - CGraphics::g_ColorRegs[1] = x2fc_tevReg1Color; -} - -void CBooRenderer::ReallyRenderFogVolume(const zeus::CColor& color, const zeus::CAABox& aabb, const CModel* model, - const CSkinnedModel* sModel) { - SCOPED_GRAPHICS_DEBUG_GROUP("CBooRenderer::ReallyRenderFogVolume", zeus::skPurple); - zeus::CMatrix4f proj = CGraphics::GetPerspectiveProjectionMatrix(false); - std::array points; - - for (size_t i = 0; i < points.size(); ++i) { - const zeus::CVector3f xfPt = CGraphics::g_GXModelView * aabb.getPoint(i); - points[i] = proj * zeus::CVector4f(xfPt); - } - - zeus::CVector2i vpMax(0, 0); - zeus::CVector2i vpMin(g_Viewport.x8_width, g_Viewport.xc_height); - - for (size_t i = 0; i < 20; ++i) { - zeus::CVector3f overW; - if (i < points.size()) { - overW = points[i].toVec3f() * (1.f / points[i].w()); - } else { - const zeus::CVector4f& pt1 = points[s_FogVolumeCtrl.xfc_[i - 8][0]]; - const zeus::CVector4f& pt2 = points[s_FogVolumeCtrl.xfc_[i - 8][1]]; - - const bool eq1 = (pt1.z() / pt1.w()) == 1.f; - const bool eq2 = (pt2.z() / pt2.w()) == 1.f; - if (eq1 == eq2) { - continue; - } - - const float interp = -(pt1.w() - 1.f) / (pt2.w() - pt1.w()); - if (interp <= 0.f || interp >= 1.f) { - continue; - } - - const float wRecip = 1.f / (interp * (pt2.w() - pt1.w()) + pt1.w()); - const zeus::CVector3f pt1_3 = pt1.toVec3f(); - const zeus::CVector3f pt2_3 = pt2.toVec3f(); - overW = (pt1_3 + interp * (pt2_3 - pt1_3)) * wRecip; - } - - // if (overW.z > 1.001f) - // continue; - - const int vpX = zeus::clamp(0, int(g_Viewport.x8_width * overW.x() * 0.5f + (g_Viewport.x8_width / 2)), - int(g_Viewport.x8_width)); - const int vpY = zeus::clamp(0, int(g_Viewport.xc_height * overW.y() * 0.5f + (g_Viewport.xc_height / 2)), - int(g_Viewport.xc_height)); - vpMax.x = std::max(vpMax.x, vpX); - vpMin.x = std::min(vpMin.x, vpX); - vpMax.y = std::max(vpMax.y, vpY); - vpMin.y = std::min(vpMin.y, vpY); - } - - zeus::CVector2i vpSize = {vpMax.x - vpMin.x, vpMax.y - vpMin.y}; - if (vpSize.x <= 0 || vpSize.y <= 0) - return; - - SClipScreenRect rect = {}; - rect.x4_left = vpMin.x; - rect.x8_top = vpMin.y; - rect.xc_width = vpSize.x; - rect.x10_height = vpSize.y; - - rect.x4_left = 0; - rect.x8_top = 0; - rect.xc_width = g_Viewport.x8_width; - rect.x10_height = g_Viewport.xc_height; - - // CGraphics::SetScissor(vpMin.x, vpMin.y, vpSize.x, vpSize.y); - zeus::CAABox marginAABB((CGraphics::g_GXModelView * aabb.min) - 1.f, (CGraphics::g_GXModelView * aabb.max) + 1.f); - bool camInModel = marginAABB.pointInside(CGraphics::g_ViewMatrix.origin) && (model || sModel); - -// CFogVolumePlaneShader* fvs; -// if (!model && !sModel) { -// fvs = &*((m_nextFogVolumePlaneShader == m_fogVolumePlaneShaders.end()) -// ? m_fogVolumePlaneShaders.insert(m_fogVolumePlaneShaders.end(), CFogVolumePlaneShader()) -// : m_nextFogVolumePlaneShader++); -// } else { -// fvs = nullptr; -// } - - RenderFogVolumeModel(aabb, model, CGraphics::g_GXModelMatrix, CGraphics::g_ViewMatrix, sModel, 0); - if (camInModel) - RenderFogVolumeModel(aabb, model, CGraphics::g_GXModelMatrix, CGraphics::g_ViewMatrix, sModel, 1); - - CGraphics::ResolveSpareDepth(rect, 0); - - RenderFogVolumeModel(aabb, model, CGraphics::g_GXModelMatrix, CGraphics::g_ViewMatrix, sModel, 2); - if (camInModel) - RenderFogVolumeModel(aabb, model, CGraphics::g_GXModelMatrix, CGraphics::g_ViewMatrix, sModel, 3); - - CGraphics::ResolveSpareDepth(rect, 1); - - aurora::gfx::queue_fog_volume_filter(color, true); - if (camInModel) - aurora::gfx::queue_fog_volume_filter(color, false); - - // CGraphics::SetScissor(g_Viewport.x0_left, g_Viewport.x4_top, g_Viewport.x8_width, g_Viewport.xc_height); -} - -//void CBooRenderer::GenerateFogVolumeRampTex() { -// std::array, FOGVOL_RAMP_RES> data{}; -// for (size_t y = 0; y < data.size(); ++y) { -// for (size_t x = 0; x < data[y].size(); ++x) { -// const int tmp = int(y << 16 | x << 8 | 0x7f); -// const double a = -// zeus::clamp(0.0, -// (-150.0 / (tmp / double(0xffffff) * (FOGVOL_FAR - FOGVOL_NEAR) - FOGVOL_FAR) - FOGVOL_NEAR) * -// 3.0 / (FOGVOL_FAR - FOGVOL_NEAR), -// 1.0); -// data[y][x] = (a * a + a) / 2.0; -// } -// } -// x1b8_fogVolumeRamp = -// aurora::new_static_texture_2d(FOGVOL_RAMP_RES, FOGVOL_RAMP_RES, 1, aurora::gfx::TextureFormat::R32Float, -// {data[0].data(), FOGVOL_RAMP_RES * FOGVOL_RAMP_RES * 2}); -//} -// -//void CBooRenderer::GenerateSphereRampTex() { -// std::array, SPHERE_RAMP_RES> data{}; -// constexpr float halfRes = SPHERE_RAMP_RES / 2.f; -// for (size_t y = 0; y < data.size(); ++y) { -// for (size_t x = 0; x < data[y].size(); ++x) { -// const zeus::CVector2f vec((float(x) - halfRes) / halfRes, (float(y) - halfRes) / halfRes); -// data[y][x] = 255 - zeus::clamp(0.f, vec.canBeNormalized() ? vec.magnitude() : 0.f, 1.f) * 255; -// } -// } -// x220_sphereRamp = -// aurora::new_static_texture_2d(SPHERE_RAMP_RES, SPHERE_RAMP_RES, 1, aurora::gfx::TextureFormat::R8, -// {data[0].data(), SPHERE_RAMP_RES * SPHERE_RAMP_RES}); -//} -// -//void CBooRenderer::GenerateScanLinesVBO() { -// std::vector verts; -// verts.reserve(670); -// -// for (int i = 0; i < 112; ++i) { -// verts.emplace_back(-1.f, (float(i) * (4.f / 448.f) + (1.f / 448.f)) * 2.f - 1.f, 0.f); -// if (i != 0) { -// verts.emplace_back(verts.back()); -// } -// verts.emplace_back(-1.f, (float(i) * (4.f / 448.f) - (1.f / 448.f)) * 2.f - 1.f, 0.f); -// verts.emplace_back(1.f, (float(i) * (4.f / 448.f) + (1.f / 448.f)) * 2.f - 1.f, 0.f); -// verts.emplace_back(1.f, (float(i) * (4.f / 448.f) - (1.f / 448.f)) * 2.f - 1.f, 0.f); -// if (i != 111) { -// verts.emplace_back(verts.back()); -// } -// } -// -// m_scanLinesEvenVBO = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), sizeof(zeus::CVector3f), verts.size()); -// -// verts.clear(); -// -// for (int i = 0; i < 112; ++i) { -// verts.emplace_back(-1.f, (float(i) * (4.f / 448.f) + (3.f / 448.f)) * 2.f - 1.f, 0.f); -// if (i != 0) { -// verts.emplace_back(verts.back()); -// } -// verts.emplace_back(-1.f, (float(i) * (4.f / 448.f) + (1.f / 448.f)) * 2.f - 1.f, 0.f); -// verts.emplace_back(1.f, (float(i) * (4.f / 448.f) + (3.f / 448.f)) * 2.f - 1.f, 0.f); -// verts.emplace_back(1.f, (float(i) * (4.f / 448.f) + (1.f / 448.f)) * 2.f - 1.f, 0.f); -// if (i != 111) { -// verts.emplace_back(verts.back()); -// } -// } -// -// m_scanLinesOddVBO = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), sizeof(zeus::CVector3f), verts.size()); -//} - -aurora::gfx::TextureHandle CBooRenderer::GetColorTexture(const zeus::CColor& color) { - const auto search = m_colorTextures.find(color); - if (search != m_colorTextures.end()) { - return search->second; - } - - std::array pixel{}; - color.toRGBA8(pixel[0], pixel[1], pixel[2], pixel[3]); - auto tex = aurora::gfx::new_static_texture_2d(1, 1, 1, aurora::gfx::TextureFormat::RGBA8, pixel, "Color Texture"); - m_colorTextures.emplace(color, tex); - return tex; -} - -//void CBooRenderer::LoadThermoPalette() { -// m_thermoPaletteTex = xc_store.GetObj("TXTR_ThermoPalette"); -// CTexture* thermoTexObj = m_thermoPaletteTex.GetObj(); -// if (thermoTexObj) -// x288_thermoPalette = thermoTexObj->GetPaletteTexture(); -//} -// -//void CBooRenderer::LoadBallFade() { -// m_ballFadeTex = xc_store.GetObj("TXTR_BallFade"); -// CTexture* ballFadeTexObj = m_ballFadeTex.GetObj(); -// if (ballFadeTexObj) { -// m_ballFade = ballFadeTexObj->GetBooTexture(); -// m_ballFade->setClampMode(boo::TextureClampMode::ClampToEdge); -// } -//} - -CBooRenderer::CBooRenderer(IObjectStore& store, IFactory& resFac) -: x8_factory(resFac), xc_store(store), x2a8_thermalRand(20) { - g_Renderer = this; - - m_staticEntropy = store.GetObj("RandomStaticEntropy"); - - constexpr std::array clearPixel{0, 0, 0, 0}; - m_clearTexture = - aurora::gfx::new_static_texture_2d(1, 1, 1, aurora::gfx::TextureFormat::RGBA8, clearPixel, "Clear Texture"); - constexpr std::array blackPixel{0, 0, 0, 255}; - m_blackTexture = - aurora::gfx::new_static_texture_2d(1, 1, 1, aurora::gfx::TextureFormat::RGBA8, blackPixel, "Black Texture"); - constexpr std::array whitePixel{255, 255, 255, 255}; - m_whiteTexture = - aurora::gfx::new_static_texture_2d(1, 1, 1, aurora::gfx::TextureFormat::RGBA8, whitePixel, "White Texture"); - - // GenerateFogVolumeRampTex(); -// GenerateSphereRampTex(); - m_ballShadowId = aurora::gfx::new_render_texture(m_ballShadowIdW, m_ballShadowIdH, 1, 0, "Ball Shadow"); -// m_ballShadowId = ctx.newRenderTexture(m_ballShadowIdW, m_ballShadowIdH, boo::TextureClampMode::Repeat, 1, 0); - x14c_reflectionTex = aurora::gfx::new_render_texture(256, 256, 1, 0, "Reflection"); -// x14c_reflectionTex = ctx.newRenderTexture(256, 256, boo::TextureClampMode::ClampToBlack, 1, 0); -// GenerateScanLinesVBO(); -// LoadThermoPalette(); -// LoadBallFade(); - m_thermColdFilter.emplace(); - m_thermHotFilter.emplace(); - - Buckets::Init(); - -// m_nextFogVolumePlaneShader = m_fogVolumePlaneShaders.end(); -// m_nextFogVolumeFilter = m_fogVolumeFilters.end(); -} - -CBooRenderer::~CBooRenderer() { g_Renderer = nullptr; } - -void CBooRenderer::AddWorldSurfaces(CBooModel& model) { - CBooSurface* surf = model.x3c_firstSortedSurface; - while (surf) { -// const MaterialSet::Material& mat = model.GetMaterialByIndex(surf->m_data.matIdx); - zeus::CAABox aabb = surf->GetBounds(); - zeus::CVector3f pt = aabb.closestPointAlongVector(xb0_viewPlane.normal()); - Buckets::Insert(pt, aabb, EDrawableType::WorldSurface, surf, xb0_viewPlane, - /*mat.blendMode == MaterialSet::Material::BlendMaterial::BlendMode::Alpha*/ false); - surf = surf->m_next; - } -} - -std::list::iterator -CBooRenderer::FindStaticGeometry(const std::vector* geometry) { - return std::find_if(x1c_areaListItems.begin(), x1c_areaListItems.end(), - [&](const CAreaListItem& item) { return item.x0_geometry == geometry; }); -} - -void CBooRenderer::AddStaticGeometry(const std::vector* geometry, - const CAreaRenderOctTree* octTree, int areaIdx, const SShader* shaderSet) { - auto search = FindStaticGeometry(geometry); - if (search == x1c_areaListItems.end()) { - std::unordered_map> textures; - std::vector models; - if (geometry->size()) { - (*geometry)[0].m_instance->MakeTexturesFromMats(textures, xc_store); - models.reserve(geometry->size()); - int instIdx = 0; - for (const CMetroidModelInstance& inst : *geometry) { - models.push_back(inst.m_instance.get()); - models.back()->x44_areaInstanceIdx = instIdx++; - } - } - x1c_areaListItems.emplace_back(geometry, octTree, std::move(textures), std::move(models), areaIdx, shaderSet); - } -} - -void CBooRenderer::EnablePVS(const CPVSVisSet& set, u32 areaIdx) { - xc8_pvs.emplace(set); - xe0_pvsAreaIdx = areaIdx; -} - -void CBooRenderer::DisablePVS() { xc8_pvs = std::nullopt; } - -void CBooRenderer::UpdateAreaUniforms(int areaIdx, EWorldShadowMode shadowMode, bool activateLights, int cubeFace, - const CModelFlags* ballShadowFlags) { - OPTICK_EVENT(); - SetupRendererStates(); - - CModelFlags flags; - int bufIdx; - if (shadowMode == EWorldShadowMode::WorldOnActorShadow) { - flags.m_extendedShader = EExtendedShader::SolidColor; - flags.x4_color = zeus::skBlack; - bufIdx = 1; - } else if (shadowMode == EWorldShadowMode::BallOnWorldShadow) { - flags = *ballShadowFlags; - bufIdx = 2; - } else if (shadowMode == EWorldShadowMode::BallOnWorldIds) { - flags.m_extendedShader = EExtendedShader::SolidColor; - bufIdx = 3; - } else { - flags.m_extendedShader = EExtendedShader::Lighting; - bufIdx = cubeFace == -1 ? 0 : 4 + cubeFace; - } - - for (CAreaListItem& item : x1c_areaListItems) { - if (areaIdx != -1 && item.x18_areaIdx != areaIdx) - continue; - -// item.m_shaderSet->m_geomLayout->Update(flags, nullptr, nullptr, &item.m_shaderSet->m_matSet, -// item.m_shaderSet->m_geomLayout->GetSharedBuffer(bufIdx), nullptr); - - if (shadowMode == EWorldShadowMode::BallOnWorldShadow || shadowMode == EWorldShadowMode::BallOnWorldIds) - continue; - - for (auto it = item.x10_models.begin(); it != item.x10_models.end(); ++it) { - CBooModel* model = *it; - if (model->TryLockTextures()) { - if (activateLights) - ActivateLightsForModel(&item, *model); -// model->UpdateUniformData(flags, nullptr, nullptr, bufIdx); - } - } - } -} - -void CBooRenderer::RemoveStaticGeometry(const std::vector* geometry) { - auto search = FindStaticGeometry(geometry); - if (search != x1c_areaListItems.end()) - x1c_areaListItems.erase(search); -} - -void CBooRenderer::DrawAreaGeometry(int areaIdx, int mask, int targetMask) { - SCOPED_GRAPHICS_DEBUG_GROUP("CBooRenderer::DrawAreaGeometry", zeus::skPurple); - x318_30_inAreaDraw = true; - // SetupRendererStates(); - CModelFlags flags; - - for (CAreaListItem& item : x1c_areaListItems) { - if (areaIdx != -1 || item.x18_areaIdx == areaIdx) { - CPVSVisSet* pvs = xc8_pvs ? &*xc8_pvs : nullptr; - if (xe0_pvsAreaIdx != item.x18_areaIdx) - pvs = nullptr; - int modelIdx = 0; - for (auto it = item.x10_models.begin(); it != item.x10_models.end(); ++it, ++modelIdx) { - CBooModel* model = *it; - if (pvs) { - bool visible = pvs->GetVisible(modelIdx) != EPVSVisSetState::EndOfTree; - if ((xc4_pvsMode == EPVSMode::PVS && !visible) || (xc4_pvsMode == EPVSMode::PVSAndMask && visible)) - continue; - } - if ((model->x41_mask & mask) != targetMask) - continue; - if (!x44_frustumPlanes.aabbFrustumTest(model->x20_aabb)) - continue; - - for (const CBooSurface* surf = model->x38_firstUnsortedSurface; surf; surf = surf->m_next) - model->DrawSurface(*surf, flags); - for (const CBooSurface* surf = model->x3c_firstSortedSurface; surf; surf = surf->m_next) - model->DrawSurface(*surf, flags); - } - } - } - - x318_30_inAreaDraw = false; -} - -void CBooRenderer::DrawUnsortedGeometry(int areaIdx, int mask, int targetMask, bool shadowRender) { - SCOPED_GRAPHICS_DEBUG_GROUP("CBooRenderer::DrawUnsortedGeometry", zeus::skPurple); - // SetupRendererStates(); - CModelFlags flags; - flags.m_extendedShader = shadowRender ? EExtendedShader::SolidColor : EExtendedShader::Lighting; - - CAreaListItem* lastOctreeItem = nullptr; - - for (CAreaListItem& item : x1c_areaListItems) { - if (areaIdx != -1 && item.x18_areaIdx != areaIdx) - continue; - - if (item.x4_octTree) - lastOctreeItem = &item; - - CPVSVisSet* pvs = nullptr; - if (xc8_pvs) - pvs = &*xc8_pvs; - if (xe0_pvsAreaIdx != item.x18_areaIdx) - pvs = nullptr; - - u32 idx = 0; - for (auto it = item.x10_models.begin(); it != item.x10_models.end(); ++it, ++idx) { - CBooModel* model = *it; - if (pvs) { - bool vis = pvs->GetVisible(idx) != EPVSVisSetState::EndOfTree; - switch (xc4_pvsMode) { - case EPVSMode::PVS: { - if (!vis) { - model->x40_25_modelVisible = false; - continue; - } - break; - } - case EPVSMode::PVSAndMask: { - if (!vis && (model->x41_mask & mask) != targetMask) { - model->x40_25_modelVisible = false; - continue; - } - break; - } - default: - break; - } - } - - if ((model->x41_mask & mask) != targetMask) { - model->x40_25_modelVisible = false; - continue; - } - - if (!x44_frustumPlanes.aabbFrustumTest(model->x20_aabb)) { - model->x40_25_modelVisible = false; - continue; - } - - if (x318_25_drawWireframe) { - model->x40_25_modelVisible = false; - // HandleUnsortedModelWireframe(); - continue; - } - - model->x40_25_modelVisible = true; - HandleUnsortedModel(lastOctreeItem, *model, flags); - } - } - - // SetupCGraphicsStates(); -} - -void CBooRenderer::DrawSortedGeometry(int areaIdx, int mask, int targetMask) { - SCOPED_GRAPHICS_DEBUG_GROUP("CBooRenderer::DrawSortedGeometry", zeus::skPurple); - // SetupRendererStates(); - - CAreaListItem* lastOctreeItem = nullptr; - - for (CAreaListItem& item : x1c_areaListItems) { - if (areaIdx != -1 && item.x18_areaIdx != areaIdx) - continue; - - if (item.x4_octTree) - lastOctreeItem = &item; - - for (auto it = item.x10_models.begin(); it != item.x10_models.end(); ++it) { - CBooModel* model = *it; - if (model->x40_25_modelVisible) - AddWorldSurfaces(*model); - } - } - - Buckets::Sort(); - RenderBucketItems(lastOctreeItem); - - // SetupCGraphicsStates(); - // DrawRenderBucketsDebug(); - Buckets::Clear(); -} - -void CBooRenderer::DrawStaticGeometry(int modelCount, int mask, int targetMask) { - DrawUnsortedGeometry(modelCount, mask, targetMask); - DrawSortedGeometry(modelCount, mask, targetMask); -} - -void CBooRenderer::DrawModelFlat(const CModel& model, const CModelFlags& flags, bool unsortedOnly) { - model.GetInstance().DrawFlat(unsortedOnly ? CBooModel::ESurfaceSelection::UnsortedOnly - : CBooModel::ESurfaceSelection::All, - flags.m_extendedShader); -} - -void CBooRenderer::PostRenderFogs() { - for (const auto& warp : x2c4_spaceWarps) - DrawSpaceWarp(warp.first, warp.second); - x2c4_spaceWarps.clear(); - - x2ac_fogVolumes.sort([](const CFogVolumeListItem& a, const CFogVolumeListItem& b) { - zeus::CAABox aabbA = a.x34_aabb.getTransformedAABox(a.x0_transform); - bool insideA = - aabbA.pointInside(zeus::CVector3f(CGraphics::g_ViewPoint.x(), CGraphics::g_ViewPoint.y(), aabbA.min.z())); - - zeus::CAABox aabbB = b.x34_aabb.getTransformedAABox(b.x0_transform); - bool insideB = - aabbB.pointInside(zeus::CVector3f(CGraphics::g_ViewPoint.x(), CGraphics::g_ViewPoint.y(), aabbB.min.z())); - - if (insideA != insideB) - return insideA; - - float dotA = aabbA.furthestPointAlongVector(CGraphics::g_ViewMatrix.basis[1]).dot(CGraphics::g_ViewMatrix.basis[1]); - float dotB = aabbB.furthestPointAlongVector(CGraphics::g_ViewMatrix.basis[1]).dot(CGraphics::g_ViewMatrix.basis[1]); - return dotA < dotB; - }); - for (const CFogVolumeListItem& fog : x2ac_fogVolumes) { - CGraphics::SetModelMatrix(fog.x0_transform); - ReallyRenderFogVolume(fog.x30_color, fog.x34_aabb, fog.x4c_model.GetObj(), fog.x5c_skinnedModel); - } - x2ac_fogVolumes.clear(); -} - -void CBooRenderer::SetModelMatrix(const zeus::CTransform& xf) { CGraphics::SetModelMatrix(xf); } -void CBooRenderer::AddParticleGen(CParticleGen& gen) { - if (auto bounds = gen.GetBounds()) { - zeus::CVector3f pt = bounds.value().closestPointAlongVector(xb0_viewPlane.normal()); - Buckets::Insert(pt, bounds.value(), EDrawableType::Particle, &gen, xb0_viewPlane, 0); - } -} - -void CBooRenderer::AddParticleGen(CParticleGen& gen, const zeus::CVector3f& pos, const zeus::CAABox& bounds) { - Buckets::Insert(pos, bounds, EDrawableType::Particle, &gen, xb0_viewPlane, 0); -} - -void CBooRenderer::AddPlaneObject(void* obj, const zeus::CAABox& aabb, const zeus::CPlane& plane, int type) { - zeus::CVector3f closePoint = aabb.closestPointAlongVector(xb0_viewPlane.normal()); - zeus::CVector3f farPoint = aabb.furthestPointAlongVector(xb0_viewPlane.normal()); - float closeDist = xb0_viewPlane.pointToPlaneDist(closePoint); - float farDist = xb0_viewPlane.pointToPlaneDist(farPoint); - if (closeDist >= 0.f || farDist >= 0.f) { - bool zOnly = plane.normal() == zeus::skUp; - bool invert; - if (zOnly) - invert = CGraphics::g_ViewMatrix.origin.z() >= plane.d(); - else - invert = plane.pointToPlaneDist(CGraphics::g_ViewMatrix.origin) >= 0.f; - Buckets::InsertPlaneObject(closeDist, farDist, aabb, invert, plane, zOnly, EDrawableType(type + 2), obj); - } -} - -void CBooRenderer::AddDrawable(void* obj, const zeus::CVector3f& pos, const zeus::CAABox& aabb, int mode, - EDrawableSorting sorting) { - if (sorting == EDrawableSorting::UnsortedCallback) - xa8_drawableCallback(obj, xac_callbackContext, mode); - else - Buckets::Insert(pos, aabb, EDrawableType(mode + 2), obj, xb0_viewPlane, 0); -} - -void CBooRenderer::SetDrawableCallback(TDrawableCallback cb, void* ctx) { - xa8_drawableCallback = cb; - xac_callbackContext = ctx; -} - -void CBooRenderer::SetWorldViewpoint(const zeus::CTransform& xf) { - CGraphics::SetViewPointMatrix(xf); - xb0_viewPlane = zeus::CPlane(xf.basis[1], xf.basis[1].dot(xf.origin)); -} - -void CBooRenderer::SetPerspective(float fovy, float width, float height, float znear, float zfar) { - CGraphics::SetPerspective(fovy, width / height, znear, zfar); -} - -void CBooRenderer::SetPerspective(float fovy, float aspect, float znear, float zfar) { - CGraphics::SetPerspective(fovy, aspect, znear, zfar); -} - -std::pair CBooRenderer::SetViewportOrtho(bool centered, float znear, float zfar) { - float left = centered ? g_Viewport.x0_left - g_Viewport.x10_halfWidth : 0.f; - float bottom = centered ? g_Viewport.x4_top - g_Viewport.x14_halfHeight : 0.f; - float top = centered ? g_Viewport.x0_left + g_Viewport.x14_halfHeight : g_Viewport.xc_height; - float right = centered ? g_Viewport.x4_top + g_Viewport.x10_halfWidth : g_Viewport.x8_width; - - CGraphics::SetOrtho(left, right, top, bottom, znear, zfar); - CGraphics::SetViewPointMatrix(zeus::CTransform()); - CGraphics::SetModelMatrix(zeus::CTransform()); - - return {{left, bottom}, {right, top}}; -} - -void CBooRenderer::SetClippingPlanes(const zeus::CFrustum& frustum) { x44_frustumPlanes = frustum; } - -void CBooRenderer::SetViewport(int left, int bottom, int width, int height) { - CGraphics::SetViewport(left, bottom, width, height); - CGraphics::SetScissor(left, bottom, width, height); -} - -void CBooRenderer::SetDebugOption(EDebugOption, int) {} - -void CBooRenderer::BeginScene() { - OPTICK_EVENT(); - CGraphics::SetViewport(0, 0, g_Viewport.x8_width, g_Viewport.xc_height); - CGraphics::SetPerspective(75.f, CGraphics::g_ProjAspect, 1.f, 4096.f); - CGraphics::SetModelMatrix(zeus::CTransform()); -#if 0 - if (x310_phazonSuitMaskCountdown != 0) - { - --x310_phazonSuitMaskCountdown; - if (x310_phazonSuitMaskCountdown == 0) - x314_phazonSuitMask.reset(); - } -#endif - x318_27_currentRGBA6 = x318_26_requestRGBA6; - if (!x318_31_persistRGBA6) - x318_26_requestRGBA6 = false; - // GXSetPixelFmt(x318_27_currentRGBA6); - CGraphics::BeginScene(); -// m_nextFogVolumePlaneShader = m_fogVolumePlaneShaders.begin(); -// m_nextFogVolumeFilter = m_fogVolumeFilters.begin(); -} - -void CBooRenderer::EndScene() { - OPTICK_EVENT(); - CGraphics::EndScene(); - if (x2dc_reflectionAge >= 2) { - // Delete reflection tex x14c_ - } else { - ++x2dc_reflectionAge; - } -} - -void CBooRenderer::SetAmbientColor(const zeus::CColor& color) { CGraphics::SetAmbientColor(color); } - -void CBooRenderer::DrawString(const char*, int, int) {} - -u32 CBooRenderer::GetFPS() { return 0; } - -void CBooRenderer::CacheReflection(TReflectionCallback cb, void* ctx, bool clearAfter) { - SCOPED_GRAPHICS_DEBUG_GROUP("CBooRenderer::CacheReflection", zeus::skPurple); - if (!x318_24_refectionDirty) - return; - x318_24_refectionDirty = false; - x2dc_reflectionAge = 0; - - // TODO - // BindReflectionDrawTarget(); - // SViewport backupVp = g_Viewport; - // SetViewport(0, 0, 256, 256); - // CGraphics::g_BooMainCommandQueue->clearTarget(); - // cb(ctx, CBooModel::g_ReflectViewPos); - // boo::SWindowRect rect(0, 0, 256, 256); - // CGraphics::g_BooMainCommandQueue->resolveBindTexture(x14c_reflectionTex, rect, false, 0, true, false); - // BindMainDrawTarget(); - // SetViewport(backupVp.x0_left, backupVp.x4_top, backupVp.x8_width, backupVp.xc_height); -} - -void CBooRenderer::DrawSpaceWarp(const zeus::CVector3f& pt, float strength) { - SCOPED_GRAPHICS_DEBUG_GROUP("CBooRenderer::DrawSpaceWarp", zeus::skPurple); - m_spaceWarpFilter.setStrength(strength); - m_spaceWarpFilter.draw(pt); -} - -void CBooRenderer::DrawThermalModel(const CModel& model, const zeus::CColor& mulCol, const zeus::CColor& addCol) { - SCOPED_GRAPHICS_DEBUG_GROUP("CBooRenderer::DrawThermalModel", zeus::skPurple); - CModelFlags flags; - flags.m_extendedShader = EExtendedShader::ThermalModel; - flags.x4_color = mulCol; - flags.addColor = addCol; - model.UpdateLastFrame(); - model.Draw(flags); -} - -void CBooRenderer::DrawXRayOutline(const zeus::CAABox& aabb) { - SCOPED_GRAPHICS_DEBUG_GROUP("CBooRenderer::DrawXRayOutline", zeus::skPurple); - CModelFlags flags; - flags.m_extendedShader = EExtendedShader::ForcedAlpha; - - for (CAreaListItem& item : x1c_areaListItems) { - if (item.x4_octTree) { - std::vector bitmap; - item.x4_octTree->FindOverlappingModels(bitmap, aabb); - - for (u32 c = 0; c < item.x4_octTree->x14_bitmapWordCount; ++c) { - for (u32 b = 0; b < 32; ++b) { - if ((bitmap[c] & (1U << b)) != 0) { - CBooModel* model = item.x10_models[c * 32 + b]; -// model->UpdateUniformData(flags, nullptr, nullptr); - const CBooSurface* surf = model->x38_firstUnsortedSurface; - while (surf) { - if (surf->GetBounds().intersects(aabb)) - model->DrawSurface(*surf, flags); - surf = surf->m_next; - } - } - } - } - } - } -} - -void CBooRenderer::SetWireframeFlags(int) {} - -void CBooRenderer::SetWorldFog(ERglFogMode mode, float startz, float endz, const zeus::CColor& color) { - if (x318_28_disableFog) - mode = ERglFogMode::None; - CGraphics::SetFog(mode, startz, endz, color); -} - -void CBooRenderer::RenderFogVolume(const zeus::CColor& color, const zeus::CAABox& aabb, - const TLockedToken* model, const CSkinnedModel* sModel) { - if (!x318_28_disableFog) - x2ac_fogVolumes.emplace_back(CGraphics::g_GXModelMatrix, color, aabb, model, sModel); -} - -void CBooRenderer::SetThermal(bool thermal, float level, const zeus::CColor& color) { - x318_29_thermalVisor = thermal; - x2f0_thermalVisorLevel = level; - x2f4_thermColor = color; - CDecal::SetMoveRedToAlphaBuffer(false); - CElementGen::SetMoveRedToAlphaBuffer(false); - m_thermalHotPass = false; -} - -void CBooRenderer::SetThermalColdScale(float scale) { x2f8_thermColdScale = zeus::clamp(0.f, scale, 1.f); } - -void CBooRenderer::DoThermalBlendCold() { - SCOPED_GRAPHICS_DEBUG_GROUP("CBooRenderer::DoThermalBlendCold", zeus::skMagenta); - zeus::CColor a = zeus::CColor::lerp(x2f4_thermColor, zeus::skWhite, x2f8_thermColdScale); - m_thermColdFilter->setColorA(a); - float bAlpha = 1.f; - if (x2f8_thermColdScale < 0.5f) - bAlpha = x2f8_thermColdScale * 2.f; - float bFac = (1.f - bAlpha) / 8.f; - m_thermColdFilter->setColorB(zeus::CColor(bFac, bAlpha)); - float cFac; - if (x2f8_thermColdScale < 0.25f) - cFac = 0.f; - else if (x2f8_thermColdScale >= 1.f) - cFac = 1.f; - else - cFac = (x2f8_thermColdScale - 0.25f) * 4.f / 3.f; - m_thermColdFilter->setColorC(zeus::CColor(cFac, cFac)); - - m_thermColdFilter->setScale(x2f8_thermColdScale); - - m_thermColdFilter->setNoiseOffset(x2a8_thermalRand.Next() % 32); - m_thermColdFilter->draw(); - CElementGen::SetMoveRedToAlphaBuffer(true); - CDecal::SetMoveRedToAlphaBuffer(true); - m_thermalHotPass = true; -} - -void CBooRenderer::DoThermalBlendHot() { - SCOPED_GRAPHICS_DEBUG_GROUP("CBooRenderer::DoThermalBlendHot", zeus::skMagenta); - m_thermHotFilter->draw(); - m_thermalHotPass = false; -} - -u32 CBooRenderer::GetStaticWorldDataSize() { return 0; } - -void CBooRenderer::PrepareDynamicLights(const std::vector& lights) { - x300_dynamicLights = lights; - for (CAreaListItem& area : x1c_areaListItems) { - if (const CAreaRenderOctTree* arot = area.x4_octTree) { - area.x1c_lightOctreeWords.clear(); - area.x1c_lightOctreeWords.resize(arot->x14_bitmapWordCount * lights.size()); - u32* wordPtr = area.x1c_lightOctreeWords.data(); - for (const CLight& light : lights) { - float radius = light.GetRadius(); - zeus::CVector3f vMin = light.GetPosition() - radius; - zeus::CVector3f vMax = light.GetPosition() + radius; - zeus::CAABox aabb(vMin, vMax); - arot->FindOverlappingModels(wordPtr, aabb); - wordPtr += arot->x14_bitmapWordCount; - } - } - } -} - -void CBooRenderer::SetGXRegister1Color(const zeus::CColor& color) { CGraphics::g_ColorRegs[1] = color; } - -void CBooRenderer::SetWorldLightFadeLevel(float level) { x2fc_tevReg1Color = zeus::CColor(level, level, level, 1.f); } -void CBooRenderer::SetWorldLightMultiplyColor(const zeus::CColor& color) { CGraphics::g_ColorRegs[2] = color; } - -void CBooRenderer::ReallyDrawPhazonSuitIndirectEffect(const zeus::CColor& vertColor, /*const CTexture& maskTex,*/ - const CTexture& indTex, const zeus::CColor& modColor, float scale, - float offX, float offY) { - SCOPED_GRAPHICS_DEBUG_GROUP("CBooRenderer::ReallyDrawPhazonSuitIndirectEffect", zeus::skMagenta); - float qScale = scale / 8.f; // Adjustment for URDE - m_phazonSuitFilter.draw(modColor, scale, offX * qScale, offY * qScale); -} - -void CBooRenderer::ReallyDrawPhazonSuitEffect(const zeus::CColor& modColor /*, const CTexture& maskTex*/) { - SCOPED_GRAPHICS_DEBUG_GROUP("CBooRenderer::ReallyDrawPhazonSuitEffect", zeus::skMagenta); - m_phazonSuitFilter.draw(modColor, 0.f, 0.f, 0.f); -} - -void CBooRenderer::DoPhazonSuitIndirectAlphaBlur(float blurRadius /*, float f2*/, - const TLockedToken& indTex) { - SCOPED_GRAPHICS_DEBUG_GROUP("CBooRenderer::DoPhazonSuitIndirectAlphaBlur", zeus::skMagenta); - m_phazonSuitFilter.drawBlurPasses(blurRadius, indTex.IsLoaded() ? indTex.GetObj() : nullptr); -} - -void CBooRenderer::DrawPhazonSuitIndirectEffect(const zeus::CColor& nonIndirectMod, - const TLockedToken& indTex, const zeus::CColor& indirectMod, - float blurRadius, float scale, float offX, float offY) { - SCOPED_GRAPHICS_DEBUG_GROUP("CBooRenderer::DrawPhazonSuitIndirectEffect", zeus::skPurple); - /* Indirect background already in binding 0 */ - - /* Resolve alpha channel of just-drawn phazon suit into binding 1 */ - SClipScreenRect rect(g_Viewport); - CGraphics::ResolveSpareTexture(rect, 1); - - /* Perform blur filter and resolve into binding 2 */ - DoPhazonSuitIndirectAlphaBlur(blurRadius, indTex); - - /* Draw effect; subtracting binding 1 from binding 2 for the filter 'cutout' */ - if (indTex && indTex.IsLoaded()) - ReallyDrawPhazonSuitIndirectEffect(zeus::skWhite, *indTex, indirectMod, scale, offX, offY); - else - ReallyDrawPhazonSuitEffect(nonIndirectMod); -} - -void CBooRenderer::AllocatePhazonSuitMaskTexture() { - x318_26_requestRGBA6 = true; - x310_phazonSuitMaskCountdown = 2; -} - -void CBooRenderer::FindOverlappingWorldModels(std::vector& modelBits, const zeus::CAABox& aabb) const { - u32 bitmapWords = 0; - for (const CAreaListItem& item : x1c_areaListItems) - if (item.x4_octTree) - bitmapWords += item.x4_octTree->x14_bitmapWordCount; - - if (!bitmapWords) { - modelBits.clear(); - return; - } - - modelBits.clear(); - modelBits.resize(bitmapWords); - - u32 curWord = 0; - for (const CAreaListItem& item : x1c_areaListItems) { - if (!item.x4_octTree) - continue; - - item.x4_octTree->FindOverlappingModels(modelBits.data() + curWord, aabb); - - u32 wordModel = 0; - for (u32 i = 0; i < item.x4_octTree->x14_bitmapWordCount; ++i, wordModel += 32) { - u32& word = modelBits[curWord + i]; - if (word == 0) { - continue; - } - for (u32 j = 0; j < 32; ++j) { - if (((1U << j) & word) != 0) { - const zeus::CAABox& modelAABB = item.x10_models[wordModel + j]->x20_aabb; - if (!modelAABB.intersects(aabb)) - word &= ~(1U << j); - } - } - } - - curWord += item.x4_octTree->x14_bitmapWordCount; - } -} - -int CBooRenderer::DrawOverlappingWorldModelIDs(int alphaVal, const std::vector& modelBits, - const zeus::CAABox& aabb) { - SCOPED_GRAPHICS_DEBUG_GROUP("CBooRenderer::DrawOverlappingWorldModelIDs", zeus::skGrey); - SetupRendererStates(); - UpdateAreaUniforms(-1, EWorldShadowMode::BallOnWorldIds, false); - - CModelFlags flags; - flags.m_extendedShader = EExtendedShader::SolidColor; // Do solid color draw - - u32 curWord = 0; - for (const CAreaListItem& item : x1c_areaListItems) { - if (!item.x4_octTree) - continue; - - u32 wordModel = 0; - for (u32 i = 0; i < item.x4_octTree->x14_bitmapWordCount; ++i, wordModel += 32) { - const u32& word = modelBits[curWord + i]; - if (word == 0) { - continue; - } - for (u32 j = 0; j < 32; ++j) { - if (((1U << j) & word) != 0) { - if (alphaVal > 255) { - return alphaVal; - } - - flags.x4_color.a() = static_cast(alphaVal) / 255.f; - CBooModel& model = *item.x10_models[wordModel + j]; -// model.UpdateUniformData(flags, nullptr, nullptr, 3); - model.VerifyCurrentShader(0); - for (const CBooSurface* surf = model.x38_firstUnsortedSurface; surf; surf = surf->m_next) { - if (surf->GetBounds().intersects(aabb)) { - model.DrawSurface(*surf, flags); - } - } - alphaVal += 4; - } - } - } - - curWord += item.x4_octTree->x14_bitmapWordCount; - } - - return alphaVal; -} - -void CBooRenderer::DrawOverlappingWorldModelShadows(int alphaVal, const std::vector& modelBits, - const zeus::CAABox& aabb, float alpha) { - SCOPED_GRAPHICS_DEBUG_GROUP("CBooRenderer::DrawOverlappingWorldModelShadows", zeus::skGrey); - CModelFlags flags; - flags.x4_color.a() = alpha; - flags.m_extendedShader = EExtendedShader::MorphBallShadow; // Do shadow draw - flags.mbShadowBox = aabb; - - UpdateAreaUniforms(-1, EWorldShadowMode::BallOnWorldShadow, false, -1, &flags); - - u32 curWord = 0; - for (const CAreaListItem& item : x1c_areaListItems) { - if (!item.x4_octTree) - continue; - - u32 wordModel = 0; - for (u32 i = 0; i < item.x4_octTree->x14_bitmapWordCount; ++i, wordModel += 32) { - const u32& word = modelBits[curWord + i]; - if (word == 0) { - continue; - } - for (u32 j = 0; j < 32; ++j) { - if (((1U << j) & word) != 0) { - if (alphaVal > 255) { - return; - } - - flags.x4_color.r() = static_cast(alphaVal) / 255.f; - CBooModel& model = *item.x10_models[wordModel + j]; -// model.UpdateUniformData(flags, nullptr, nullptr, 2); - model.VerifyCurrentShader(0); - for (const CBooSurface* surf = model.x38_firstUnsortedSurface; surf; surf = surf->m_next) - if (surf->GetBounds().intersects(aabb)) - model.DrawSurface(*surf, flags); - alphaVal += 4; - } - } - } - - curWord += item.x4_octTree->x14_bitmapWordCount; - } -} - -} // namespace metaforce diff --git a/Runtime/Graphics/CCubeMaterial.cpp b/Runtime/Graphics/CCubeMaterial.cpp index f7c23dedd..f4c98956c 100644 --- a/Runtime/Graphics/CCubeMaterial.cpp +++ b/Runtime/Graphics/CCubeMaterial.cpp @@ -312,7 +312,7 @@ u32 CCubeMaterial::HandleColorChannels(u32 chanCount, u32 firstChan) { CGX::SetChanAmbColor(CGX::EChannelId::Channel1, GX_BLACK); CGX::SetChanMatColor(CGX::EChannelId::Channel1, GX_WHITE); - auto chan0Lights = CGraphics::g_LightActive & ~CCubeModel::sChannel0DisableLightMask; + auto chan0Lights = CGraphics::mLightActive & ~CCubeModel::sChannel0DisableLightMask; CGX::SetChanCtrl(CGX::EChannelId::Channel0, firstChan, chan0Lights); CGX::SetChanCtrl(CGX::EChannelId::Channel1, CCubeModel::sChannel1EnableLightMask); if (chan0Lights.any()) { @@ -334,8 +334,8 @@ u32 CCubeMaterial::HandleColorChannels(u32 chanCount, u32 firstChan) { if (chanCount == 0) { CGX::SetChanCtrl(CGX::EChannelId::Channel0, {}); } else { - CGX::SetChanCtrl(CGX::EChannelId::Channel0, firstChan, CGraphics::g_LightActive); - if (CGraphics::g_LightActive.any()) { + CGX::SetChanCtrl(CGX::EChannelId::Channel0, firstChan, CGraphics::mLightActive); + if (CGraphics::mLightActive.any()) { CGX::SetChanMatColor(CGX::EChannelId::Channel0, GX_WHITE); } else { CGX::SetChanMatColor(CGX::EChannelId::Channel0, CGX::GetChanAmbColor(CGX::EChannelId::Channel0)); @@ -363,26 +363,35 @@ void CCubeMaterial::HandleTev(u32 tevCur, const u32* materialDataCur, const u32* CGX::SetTevKAlphaSel(stage, static_cast(matFlags >> 0x10 & 0xFF)); } -constexpr zeus::CTransform MvPostXf{ - {zeus::CVector3f{0.5f, 0.f, 0.f}, {0.f, 0.f, 0.f}, {0.f, 0.5f, 0.f}}, - {0.5f, 0.5f, 1.f}, -}; - -u32 CCubeMaterial::HandleAnimatedUV(const u32* uvAnim, GXTexMtx texMtx, GXPTTexMtx pttTexMtx) { +u32 CCubeMaterial::HandleAnimatedUV(const u32* uvAnim, GXTexMtx texMtx, GXPTTexMtx ptTexMtx) { + static const Mtx postMtx = { + {0.5f, 0.0f, 0.0f, 0.5f}, + {0.0f, 0.0f, 0.5f, 0.5f}, + {0.0f, 0.0f, 0.0f, 1.0f}, + }; + static Mtx translateMtx = { + {1.0f, 0.0f, 0.0f, 0.0f}, + {0.0f, 1.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 1.0f, 0.0f}, + }; u32 type = SBig(*uvAnim); const float* params = reinterpret_cast(uvAnim + 1); switch (type) { case 0: { - auto xf = CGraphics::g_ViewMatrix.inverse().multiplyIgnoreTranslation(CGraphics::g_GXModelMatrix); + auto xf = CGraphics::GetViewMatrix().quickInverse().multiplyIgnoreTranslation(CGraphics::GetModelMatrix()); xf.origin.zeroOut(); - GXLoadTexMtxImm(&xf, texMtx, GX_MTX3x4); - GXLoadTexMtxImm(&MvPostXf, pttTexMtx, GX_MTX3x4); + Mtx mtx; + xf.toCStyleMatrix(mtx); + GXLoadTexMtxImm(mtx, texMtx, GX_MTX3x4); + GXLoadTexMtxImm(postMtx, ptTexMtx, GX_MTX3x4); return 1; } case 1: { - auto xf = CGraphics::g_ViewMatrix.inverse() * CGraphics::g_GXModelMatrix; - GXLoadTexMtxImm(&xf, texMtx, GX_MTX3x4); - GXLoadTexMtxImm(&MvPostXf, pttTexMtx, GX_MTX3x4); + auto xf = CGraphics::GetViewMatrix().quickInverse() * CGraphics::GetModelMatrix(); + Mtx mtx; + xf.toCStyleMatrix(mtx); + GXLoadTexMtxImm(mtx, texMtx, GX_MTX3x4); + GXLoadTexMtxImm(postMtx, ptTexMtx, GX_MTX3x4); return 1; } case 2: { @@ -391,74 +400,101 @@ u32 CCubeMaterial::HandleAnimatedUV(const u32* uvAnim, GXTexMtx texMtx, GXPTTexM const float f3 = SBig(params[2]); const float f4 = SBig(params[3]); const float seconds = CGraphics::GetSecondsMod900(); - const auto xf = zeus::CTransform::Translate(seconds * f3 + f1, seconds * f4 + f2, 0.f); - GXLoadTexMtxImm(&xf, texMtx, GX_MTX3x4); + translateMtx[0][3] = f1 + seconds * f3; + translateMtx[1][3] = f2 + seconds * f4; + GXLoadTexMtxImm(translateMtx, texMtx, GX_MTX3x4); return 5; } case 3: { - const float angle = CGraphics::GetSecondsMod900() * SBig(params[1]) + SBig(params[0]); - const float acos = std::cos(angle); + const float f1 = SBig(params[0]); + const float f2 = SBig(params[1]); + const float seconds = CGraphics::GetSecondsMod900(); + const float angle = f1 + seconds * f2; const float asin = std::sin(angle); - zeus::CTransform xf; - xf.basis[0][0] = acos; - xf.basis[0][1] = asin; - xf.basis[1][0] = -asin; - xf.basis[1][1] = acos; - xf.origin[0] = (1.f - (acos - asin)) * 0.5f; - xf.origin[1] = (1.f - (asin + acos)) * 0.5f; - GXLoadTexMtxImm(&xf, texMtx, GX_MTX3x4); + const float acos = std::cos(angle); + Mtx mtx = { + {acos, -asin, 0.f, (1.f - (acos - asin)) * 0.5f}, + {asin, acos, 0.f, (1.f - (asin + acos)) * 0.5f}, + {0.f, 0.f, 1.f, 0.f}, + }; + GXLoadTexMtxImm(mtx, texMtx, GX_MTX3x4); return 3; } case 4: case 5: { - zeus::CTransform xf; - const float value = SBig(params[0]) * SBig(params[2]) * (SBig(params[3]) + CGraphics::GetSecondsMod900()); + const float f1 = SBig(params[0]); + const float f2 = SBig(params[1]); + const float f3 = SBig(params[2]); + const float f4 = SBig(params[3]); + const float value = (f4 + CGraphics::GetSecondsMod900()) * f1 * f3; + const float fmod = std::fmod(value, 1.f); + const float fs = std::trunc(fmod * f2); + const float v2 = fs * f3; if (type == 4) { - xf.origin.x() = std::trunc(SBig(params[1]) * std::fmod(value, 1.f)) * SBig(params[2]); - xf.origin.y() = 0.f; + translateMtx[0][3] = v2; + translateMtx[1][3] = 0.f; } else { - xf.origin.x() = 0.f; - xf.origin.y() = std::trunc(SBig(params[1]) * std::fmod(value, 1.f)) * SBig(params[2]); + translateMtx[0][3] = 0.f; + translateMtx[1][3] = v2; } - GXLoadTexMtxImm(&xf, texMtx, GX_MTX3x4); + GXLoadTexMtxImm(translateMtx, texMtx, GX_MTX3x4); return 5; } case 6: { - const zeus::CTransform mtx{CGraphics::g_GXModelMatrix.basis}; - const zeus::CTransform postMtx{ - { - zeus::CVector3f{0.5f, 0.f, 0.f}, - zeus::CVector3f{0.f, 0.f, 0.f}, - zeus::CVector3f{0.f, 0.5f, 0.f}, - }, - zeus::CVector3f{ - CGraphics::g_GXModelMatrix.origin.x() * 0.05f, - CGraphics::g_GXModelMatrix.origin.y() * 0.05f, - 1.f, - }, + static const Mtx sTexMtx = { + {0.f, 0.f, 0.f, 0.f}, + {0.f, 0.f, 0.f, 0.f}, + {0.f, 0.f, 0.f, 0.f}, }; - GXLoadTexMtxImm(&mtx, texMtx, GX_MTX3x4); - GXLoadTexMtxImm(&postMtx, pttTexMtx, GX_MTX3x4); + static const Mtx sPtMtx = { + {0.5f, 0.f, 0.f, 0.f}, + {0.f, 0.f, 0.5f, 0.f}, + {0.f, 0.f, 0.f, 1.f}, + }; + const zeus::CTransform& mm = CGraphics::GetModelMatrix(); + Mtx tmpTexMtx; + Mtx tmpPtMtx; + memcpy(&tmpTexMtx, &sTexMtx, sizeof(Mtx)); + tmpTexMtx[0][0] = mm.basis[0][0]; + tmpTexMtx[0][1] = mm.basis[1][0]; + tmpTexMtx[0][2] = mm.basis[2][0]; + tmpTexMtx[1][0] = mm.basis[0][1]; + tmpTexMtx[1][1] = mm.basis[1][1]; + tmpTexMtx[1][2] = mm.basis[2][1]; + tmpTexMtx[2][0] = mm.basis[0][2]; + tmpTexMtx[2][1] = mm.basis[1][2]; + tmpTexMtx[2][2] = mm.basis[2][2]; + memcpy(&tmpPtMtx, &sPtMtx, sizeof(Mtx)); + tmpPtMtx[0][3] = mm.origin.x() * 0.05f; + tmpPtMtx[1][3] = mm.origin.y() * 0.05f; + GXLoadTexMtxImm(tmpTexMtx, texMtx, GX_MTX3x4); + GXLoadTexMtxImm(tmpPtMtx, ptTexMtx, GX_MTX3x4); return 1; } case 7: { - zeus::CTransform mtx = CGraphics::g_ViewMatrix.inverse().multiplyIgnoreTranslation(CGraphics::g_GXModelMatrix); - mtx.origin.zeroOut(); - float xy = SBig(params[1]) * (CGraphics::g_ViewMatrix.origin.x() + CGraphics::g_ViewMatrix.origin.y()) * 0.025f; - xy = (xy - static_cast(xy)); - float z = SBig(params[1]) * CGraphics::g_ViewMatrix.origin.z() * 0.05f; - z = (z - static_cast(z)); - float halfA = SBig(params[0]) * 0.5f; - zeus::CTransform postMtx{ - { - zeus::CVector3f{halfA, 0.f, 0.f}, - zeus::CVector3f{0.f, 0.f, 0.f}, - zeus::CVector3f{0.f, halfA, 0.f}, - }, - zeus::CVector3f{xy, z, 1.f}, + static const Mtx sPtMtx = { + {0.f, 0.f, 0.f, 0.f}, + {0.f, 0.f, 0.f, 0.f}, + {0.f, 0.f, 0.f, 1.f}, }; - GXLoadTexMtxImm(&mtx, texMtx, GX_MTX3x4); - GXLoadTexMtxImm(&postMtx, pttTexMtx, GX_MTX3x4); + const zeus::CTransform& vm = CGraphics::GetViewMatrix(); + zeus::CTransform xf = vm.quickInverse().multiplyIgnoreTranslation(CGraphics::GetModelMatrix()); + float v = SBig(params[0]) / 2.f; + float v03 = 0.025f * (vm.origin.x() + vm.origin.y()) * SBig(params[1]); + float v13 = 0.05f * vm.origin.z() * SBig(params[1]); + float v03f = std::fmod(v03, 1.f); + float v13f = std::fmod(v13, 1.f); + xf.origin.zeroOut(); + Mtx mtx; + xf.toCStyleMatrix(mtx); + Mtx tmpPtMtx; + memcpy(&tmpPtMtx, &sPtMtx, sizeof(Mtx)); + tmpPtMtx[0][0] = v; + tmpPtMtx[0][3] = v03f; + tmpPtMtx[1][2] = v; + tmpPtMtx[1][3] = v13f; + GXLoadTexMtxImm(mtx, texMtx, GX_MTX3x4); + GXLoadTexMtxImm(tmpPtMtx, ptTexMtx, GX_MTX3x4); return 3; } default: diff --git a/Runtime/Graphics/CCubeModel.cpp b/Runtime/Graphics/CCubeModel.cpp index c4b619b8c..ed6e8262c 100644 --- a/Runtime/Graphics/CCubeModel.cpp +++ b/Runtime/Graphics/CCubeModel.cpp @@ -22,10 +22,9 @@ static bool sDrawingWireframe = false; static zeus::CVector3f sPlayerPosition; CCubeModel::CCubeModel(std::vector* surfaces, std::vector>* textures, - u8* materialData, std::vector* positions, std::vector* colors, - std::vector* normals, std::vector>* texCoords, - std::vector>* packedTexCoords, const zeus::CAABox& aabb, u8 flags, bool b1, - u32 idx) + u8* materialData, std::span positions, std::span colors, + std::span normals, std::span texCoords, std::span packedTexCoords, + const zeus::CAABox& aabb, u8 flags, bool b1, u32 idx) : x0_modelInstance(surfaces, materialData, positions, colors, normals, texCoords, packedTexCoords) , x1c_textures(textures) , x20_worldAABB(aabb) @@ -148,7 +147,7 @@ void CCubeModel::DrawAlphaSurfaces(const CModelFlags& flags) { } void CCubeModel::DrawFlat(TConstVectorRef positions, TConstVectorRef normals, ESurfaceSelection surfaces) { - if (positions == nullptr) { + if (positions.empty()) { SetArraysCurrent(); } else { SetSkinningArraysCurrent(positions, normals); @@ -259,8 +258,8 @@ void CCubeModel::EnableShadowMaps(const CTexture& shadowTex, const zeus::CTransf void CCubeModel::DisableShadowMaps() { sRenderModelShadow = false; } void CCubeModel::SetArraysCurrent() { - CGX::SetArray(GX_VA_POS, x0_modelInstance.GetVertexPointer(), true); - CGX::SetArray(GX_VA_NRM, x0_modelInstance.GetNormalPointer(), true); + CGX::SetArray(GX_VA_POS, x0_modelInstance.GetVertexPointer(), 12); + CGX::SetArray(GX_VA_NRM, x0_modelInstance.GetNormalPointer(), (x41_visorFlags & 1) != 0 ? 6 : 12); SetStaticArraysCurrent(); } @@ -280,26 +279,26 @@ void CCubeModel::SetRenderModelBlack(bool v) { } void CCubeModel::SetSkinningArraysCurrent(TConstVectorRef positions, TConstVectorRef normals) { - CGX::SetArray(GX_VA_POS, positions, false); - CGX::SetArray(GX_VA_NRM, normals, false); + CGX::SetArray(GX_VA_POS, positions); + CGX::SetArray(GX_VA_NRM, normals); // colors unused SetStaticArraysCurrent(); } void CCubeModel::SetStaticArraysCurrent() { - // colors unused - const auto* packedTexCoords = x0_modelInstance.GetPackedTCPointer(); - const auto* texCoords = x0_modelInstance.GetTCPointer(); - if (packedTexCoords == nullptr) { - sUsingPackedLightmaps = false; + if (!x0_modelInstance.GetColorPointer().empty()) { + CGX::SetArray(GX_VA_CLR0, x0_modelInstance.GetColorPointer(), 4); } + const auto packedTexCoords = x0_modelInstance.GetPackedTCPointer(); + const auto texCoords = x0_modelInstance.GetTCPointer(); + sUsingPackedLightmaps = !packedTexCoords.empty(); if (sUsingPackedLightmaps) { - CGX::SetArray(GX_VA_TEX0, packedTexCoords, true); + CGX::SetArray(GX_VA_TEX0, packedTexCoords, 4); } else { - CGX::SetArray(GX_VA_TEX0, texCoords, true); + CGX::SetArray(GX_VA_TEX0, texCoords, 8); } for (int i = GX_VA_TEX1; i <= GX_VA_TEX7; ++i) { - CGX::SetArray(static_cast(i), texCoords, true); + CGX::SetArray(static_cast(i), texCoords, 8); } CCubeMaterial::KillCachedViewDepState(); } @@ -307,16 +306,39 @@ void CCubeModel::SetStaticArraysCurrent() { void CCubeModel::SetUsingPackedLightmaps(bool v) { sUsingPackedLightmaps = v; if (v) { - CGX::SetArray(GX_VA_TEX0, x0_modelInstance.GetPackedTCPointer(), true); + CGX::SetArray(GX_VA_TEX0, x0_modelInstance.GetPackedTCPointer(), 4); } else { - CGX::SetArray(GX_VA_TEX0, x0_modelInstance.GetTCPointer(), true); + CGX::SetArray(GX_VA_TEX0, x0_modelInstance.GetTCPointer(), 8); } } template <> aurora::Vec2 cinput_stream_helper(CInputStream& in) { - float x = in.ReadFloat(); - float y = in.ReadFloat(); + const auto x = in.ReadFloat(); + const auto y = in.ReadFloat(); return {x, y}; } + +template <> +aurora::Vec3 cinput_stream_helper(CInputStream& in) { + const auto x = in.ReadFloat(); + const auto y = in.ReadFloat(); + const auto z = in.ReadFloat(); + return {x, y, z}; +} + +template <> +aurora::Vec2 cinput_stream_helper(CInputStream& in) { + const auto x = in.ReadUint16(); + const auto y = in.ReadUint16(); + return {x, y}; +} + +template <> +aurora::Vec3 cinput_stream_helper(CInputStream& in) { + const auto x = in.ReadInt16(); + const auto y = in.ReadInt16(); + const auto z = in.ReadInt16(); + return {x, y, z}; +} } // namespace metaforce diff --git a/Runtime/Graphics/CCubeModel.hpp b/Runtime/Graphics/CCubeModel.hpp index 4a91697cf..2dd4ef1c9 100644 --- a/Runtime/Graphics/CCubeModel.hpp +++ b/Runtime/Graphics/CCubeModel.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include "CStopwatch.hpp" @@ -22,8 +23,13 @@ enum class ESurfaceSelection { }; // These parameters were originally float* -using TVectorRef = std::vector*; -using TConstVectorRef = const std::vector*; +using TVectorRef = std::vector>*; +using TConstVectorRef = std::span>; + +template +std::span byte_span(const std::vector& vec) { + return std::span(reinterpret_cast(vec.data()), vec.size() * sizeof(T)); +} class CCubeModel { friend class CModel; @@ -31,18 +37,18 @@ class CCubeModel { private: class ModelInstance { - std::vector* x0_surfacePtrs; // was rstl::vector* - u8* x4_materialData; // - std::vector* x8_positions; // was void* - std::vector* xc_normals; // was void* - std::vector* x10_colors; // was void* - std::vector>* x14_texCoords; // was void* - std::vector>* x18_packedTexCoords; // was void* + std::vector* x0_surfacePtrs; // was rstl::vector* + u8* x4_materialData; // + std::span x8_positions; // was void* + std::span xc_normals; // was void* + std::span x10_colors; // was void* + std::span x14_texCoords; // was void* + std::span x18_packedTexCoords; // was void* public: - ModelInstance(std::vector* surfaces, u8* material, std::vector* positions, - std::vector* colors, std::vector* normals, - std::vector>* texCoords, std::vector>* packedTexCoords) + ModelInstance(std::vector* surfaces, u8* material, std::span positions, + std::span colors, std::span normals, std::span texCoords, + std::span packedTexCoords) : x0_surfacePtrs(surfaces) , x4_materialData(material) , x8_positions(positions) @@ -58,13 +64,11 @@ private: [[nodiscard]] std::vector* Surfaces() const { return x0_surfacePtrs; } [[nodiscard]] u8* GetMaterialPointer() const { return x4_materialData; } void SetMaterialPointer(u8* mat) { x4_materialData = mat; } - [[nodiscard]] TVectorRef GetVertexPointer() { return x8_positions; } - [[nodiscard]] TConstVectorRef GetVertexPointer() const { return x8_positions; } - [[nodiscard]] TVectorRef GetNormalPointer() { return xc_normals; } - [[nodiscard]] TConstVectorRef GetNormalPointer() const { return xc_normals; } - [[nodiscard]] std::vector* GetColorPointer() const { return x10_colors; } - [[nodiscard]] std::vector>* GetTCPointer() const { return x14_texCoords; } - [[nodiscard]] std::vector>* GetPackedTCPointer() const { return x18_packedTexCoords; } + [[nodiscard]] std::span GetVertexPointer() const { return x8_positions; } + [[nodiscard]] std::span GetNormalPointer() const { return xc_normals; } + [[nodiscard]] std::span GetColorPointer() const { return x10_colors; } + [[nodiscard]] std::span GetTCPointer() const { return x14_texCoords; } + [[nodiscard]] std::span GetPackedTCPointer() const { return x18_packedTexCoords; } }; ModelInstance x0_modelInstance; @@ -79,9 +83,9 @@ private: public: CCubeModel(std::vector* surfaces, std::vector>* textures, u8* materialData, - std::vector* positions, std::vector* colors, - std::vector* normals, std::vector>* texCoords, - std::vector>* packedTexCoords, const zeus::CAABox& aabb, u8 flags, bool b1, u32 idx); + std::span positions, std::span colors, std::span normals, + std::span texCoords, std::span packedTexCoords, const zeus::CAABox& aabb, u8 flags, + bool b1, u32 idx); CCubeMaterial GetMaterialByIndex(u32 idx); bool TryLockTextures(); @@ -107,10 +111,14 @@ public: [[nodiscard]] CCubeSurface* GetFirstSortedSurface() { return x3c_firstSortedSurf; } [[nodiscard]] const CCubeSurface* GetFirstSortedSurface() const { return x3c_firstSortedSurf; } - [[nodiscard]] TVectorRef GetPositions() { return x0_modelInstance.GetVertexPointer(); } - [[nodiscard]] TConstVectorRef GetPositions() const { return x0_modelInstance.GetVertexPointer(); } - [[nodiscard]] TVectorRef GetNormals() { return x0_modelInstance.GetNormalPointer(); } - [[nodiscard]] TConstVectorRef GetNormals() const { return x0_modelInstance.GetNormalPointer(); } + [[nodiscard]] TConstVectorRef GetPositions() const { + const auto sp = x0_modelInstance.GetVertexPointer(); + return {reinterpret_cast*>(sp.data()), sp.size() / sizeof(aurora::Vec3)}; + } + [[nodiscard]] TConstVectorRef GetNormals() const { + const auto sp = x0_modelInstance.GetNormalPointer(); + return {reinterpret_cast*>(sp.data()), sp.size() / sizeof(aurora::Vec3)}; + } [[nodiscard]] TCachedToken& GetTexture(u32 idx) const { return x1c_textures->at(idx); } static void EnableShadowMaps(const CTexture& shadowTex, const zeus::CTransform& textureProjXf, @@ -142,4 +150,10 @@ private: template <> aurora::Vec2 cinput_stream_helper(CInputStream& in); +template <> +aurora::Vec3 cinput_stream_helper(CInputStream& in); +template <> +aurora::Vec2 cinput_stream_helper(CInputStream& in); +template <> +aurora::Vec3 cinput_stream_helper(CInputStream& in); } // namespace metaforce diff --git a/Runtime/Graphics/CCubeRenderer.cpp b/Runtime/Graphics/CCubeRenderer.cpp index c2684f6f9..17297a77e 100644 --- a/Runtime/Graphics/CCubeRenderer.cpp +++ b/Runtime/Graphics/CCubeRenderer.cpp @@ -297,15 +297,11 @@ void CCubeRenderer::AddStaticGeometry(const std::vector* models->reserve(geometry->size()); s32 instIdx = 0; for (const CMetroidModelInstance& inst : *geometry) { - models->emplace_back( - std::make_unique(const_cast*>(inst.GetSurfaces()), textures.get(), - const_cast(inst.GetMaterialPointer()), - const_cast*>(inst.GetVertexPointer()), - const_cast*>(inst.GetColorPointer()), - const_cast*>(inst.GetNormalPointer()), - const_cast>*>(inst.GetTCPointer()), - const_cast>*>(inst.GetPackedTCPointer()), - inst.GetBoundingBox(), inst.GetFlags(), false, instIdx)); + models->emplace_back(std::make_unique( + const_cast*>(inst.GetSurfaces()), textures.get(), + const_cast(inst.GetMaterialPointer()), inst.GetVertexPointer(), inst.GetColorPointer(), + inst.GetNormalPointer(), inst.GetTCPointer(), inst.GetPackedTCPointer(), inst.GetBoundingBox(), + inst.GetFlags(), false, instIdx)); ++instIdx; } } @@ -329,8 +325,7 @@ void CCubeRenderer::RemoveStaticGeometry(const std::vectorx18_areaIdx).c_str(), zeus::skBlue); + SCOPED_GRAPHICS_DEBUG_GROUP(fmt::format("CCubeRenderer::RenderBucketItems areaIdx={}", item->x18_areaIdx).c_str(), + zeus::skBlue); CCubeModel* lastModel = nullptr; EDrawableType lastDrawableType = EDrawableType::Invalid; @@ -544,19 +537,19 @@ void CCubeRenderer::PostRenderFogs() { x2ac_fogVolumes.sort([](const CFogVolumeListItem& a, const CFogVolumeListItem& b) { zeus::CAABox aabbA = a.x34_aabb.getTransformedAABox(a.x0_transform); - bool insideA = - aabbA.pointInside(zeus::CVector3f(CGraphics::g_ViewPoint.x(), CGraphics::g_ViewPoint.y(), aabbA.min.z())); + bool insideA = aabbA.pointInside( + zeus::CVector3f(CGraphics::mViewMatrix.origin.x(), CGraphics::mViewMatrix.origin.y(), aabbA.min.z())); zeus::CAABox aabbB = b.x34_aabb.getTransformedAABox(b.x0_transform); - bool insideB = - aabbB.pointInside(zeus::CVector3f(CGraphics::g_ViewPoint.x(), CGraphics::g_ViewPoint.y(), aabbB.min.z())); + bool insideB = aabbB.pointInside( + zeus::CVector3f(CGraphics::mViewMatrix.origin.x(), CGraphics::mViewMatrix.origin.y(), aabbB.min.z())); if (insideA != insideB) { return insideA; } - float dotA = aabbA.furthestPointAlongVector(CGraphics::g_ViewMatrix.basis[1]).dot(CGraphics::g_ViewMatrix.basis[1]); - float dotB = aabbB.furthestPointAlongVector(CGraphics::g_ViewMatrix.basis[1]).dot(CGraphics::g_ViewMatrix.basis[1]); + float dotA = aabbA.furthestPointAlongVector(CGraphics::mViewMatrix.basis[1]).dot(CGraphics::mViewMatrix.basis[1]); + float dotB = aabbB.furthestPointAlongVector(CGraphics::mViewMatrix.basis[1]).dot(CGraphics::mViewMatrix.basis[1]); return dotA < dotB; }); for (const CFogVolumeListItem& fog : x2ac_fogVolumes) { @@ -677,8 +670,8 @@ void CCubeRenderer::AddPlaneObject(void* obj, const zeus::CAABox& aabb, const ze if (closestDist >= 0.f || furthestDist >= 0.f) { const bool zOnly = plane.normal() == zeus::skUp; - const bool invertTest = zOnly ? CGraphics::g_GXModelView.origin.z() >= plane.d() - : plane.pointToPlaneDist(CGraphics::g_GXModelView.origin) >= 0.f; + const bool invertTest = zOnly ? CGraphics::mViewMatrix.origin.z() >= plane.d() + : plane.pointToPlaneDist(CGraphics::mViewMatrix.origin) >= 0.f; Buckets::InsertPlaneObject(closestDist, furthestDist, aabb, invertTest, plane, zOnly, EDrawableType(type + 2), obj); } } @@ -735,14 +728,14 @@ void CCubeRenderer::SetViewport(s32 left, s32 bottom, s32 width, s32 height) { void CCubeRenderer::BeginScene() { CGraphics::SetUseVideoFilter(true); - CGraphics::SetViewport(0, 0, CGraphics::g_Viewport.x8_width, CGraphics::g_Viewport.xc_height); + CGraphics::SetViewport(0, 0, CGraphics::mRenderModeObj.fbWidth, CGraphics::mRenderModeObj.xfbHeight); CGraphics::SetClearColor(zeus::skClear); CGraphics::SetCullMode(ERglCullMode::Front); CGraphics::SetDepthWriteMode(true, ERglEnum::LEqual, true); CGraphics::SetBlendMode(ERglBlendMode::Blend, ERglBlendFactor::SrcAlpha, ERglBlendFactor::InvSrcAlpha, ERglLogicOp::Clear); - CGraphics::SetPerspective(75.f, CGraphics::g_Viewport.x8_width / CGraphics::g_Viewport.xc_height, 1.f, 4096.f); + CGraphics::SetPerspective(75.f, CGraphics::mViewport.mWidth / CGraphics::mViewport.mHeight, 1.f, 4096.f); CGraphics::SetModelMatrix(zeus::CTransform()); if (x310_phazonSuitMaskCountdown != 0) { --x310_phazonSuitMaskCountdown; @@ -756,14 +749,14 @@ void CCubeRenderer::BeginScene() { x318_26_requestRGBA6 = false; } - // GXSetPixelFmt(x318_27_currentRGBA6, GX_ZC_LINEAR); + GXSetPixelFmt(x318_27_currentRGBA6 ? GX_PF_RGBA6_Z24 : GX_PF_RGB8_Z24, GX_ZC_LINEAR); GXSetAlphaUpdate(true); GXSetDstAlpha(true, 0.f); CGraphics::BeginScene(); } void CCubeRenderer::EndScene() { - x318_31_persistRGBA6 = !CGraphics::g_IsBeginSceneClearFb; + x318_31_persistRGBA6 = !CGraphics::mIsBeginSceneClearFb; CGraphics::EndScene(); if (x2dc_reflectionAge < 2) { @@ -802,7 +795,7 @@ void CCubeRenderer::BeginPrimitive(IRenderer::EPrimitiveType type, s32 nverts) { CGX::SetStandardTevColorAlphaOp(GX_TEVSTAGE0); x18_primVertCount = nverts; CGX::SetVtxDescv(vtxDescList.data()); - CGX::Begin(GXPrimitive(type), GX_VTXFMT0, nverts); + CGX::Begin(static_cast(type), GX_VTXFMT0, nverts); } void CCubeRenderer::BeginLines(s32 nverts) { BeginPrimitive(EPrimitiveType::Lines, nverts); } @@ -839,7 +832,7 @@ void CCubeRenderer::SetAmbientColor(const zeus::CColor& color) { CGraphics::SetA void CCubeRenderer::DrawString(const char* string, s32 x, s32 y) { x10_font.DrawString(string, x, y, zeus::skWhite); } -u32 CCubeRenderer::GetFPS() { return CGraphics::GetFPS(); } +float CCubeRenderer::GetFPS() { return CGraphics::GetFPS(); } void CCubeRenderer::CacheReflection(IRenderer::TReflectionCallback cb, void* ctx, bool clearAfter) { // TODO @@ -880,25 +873,23 @@ void CCubeRenderer::DrawModelDisintegrate(CModel& model, CTexture& tex, const ze const auto transformedBounds = bounds.getTransformedAABox(rotation); const auto xf = zeus::CTransform::Scale(5.f / (transformedBounds.max - transformedBounds.min)) * zeus::CTransform::Translate(-transformedBounds.min) * rotation; - const zeus::CTransform ptTex1{ - zeus::CMatrix3f{ - 1.f, 1.f, 0.f, - 0.f, 0.f, 1.f, - 0.f, 0.f, 0.f, - }, - zeus::CVector3f{t * -0.85f - 0.15f, -(1.f - t) * 6.f + 1.f, 1.f}, + Mtx mtx; + xf.toCStyleMatrix(mtx); + float f1 = -(1.f - t) * 6.f + 1.f; + float f2 = t * -0.85f - 0.15f; + const Mtx ptTex0 = { + {1.0f, 1.0f, 0.0f, t}, + {0.0f, 0.0f, 1.0f, f1}, + {0.0f, 0.0f, 0.0f, 1.0f}, }; - const zeus::CTransform ptTex0{ - zeus::CMatrix3f{ - 1.f, 1.f, 0.f, - 0.f, 0.f, 1.f, - 0.f, 0.f, 0.f, - }, - zeus::CVector3f{t, ptTex1.origin.y(), 1.f}, + const Mtx ptTex1 = { + {1.0f, 1.0f, 0.0f, f2}, + {0.0f, 0.0f, 1.0f, f1}, + {0.0f, 0.0f, 0.0f, 1.0f}, }; - GXLoadTexMtxImm(&xf, GX_TEXMTX0, GX_MTX3x4); - GXLoadTexMtxImm(&ptTex0, GX_PTTEXMTX0, GX_MTX3x4); - GXLoadTexMtxImm(&ptTex1, GX_PTTEXMTX1, GX_MTX3x4); + GXLoadTexMtxImm(mtx, GX_TEXMTX0, GX_MTX3x4); + GXLoadTexMtxImm(ptTex0, GX_PTTEXMTX0, GX_MTX3x4); + GXLoadTexMtxImm(ptTex1, GX_PTTEXMTX1, GX_MTX3x4); CGX::SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX3x4, GX_TG_POS, GX_TEXMTX0, false, GX_PTTEXMTX0); CGX::SetTexCoordGen(GX_TEXCOORD1, GX_TG_MTX3x4, GX_TG_POS, GX_TEXMTX0, false, GX_PTTEXMTX1); CGX::SetAlphaCompare(GX_GREATER, 0, GX_AOP_AND, GX_ALWAYS, 0); @@ -949,7 +940,7 @@ void CCubeRenderer::SetWorldFog(ERglFogMode mode, float startz, float endz, cons void CCubeRenderer::RenderFogVolume(const zeus::CColor& color, const zeus::CAABox& aabb, const TLockedToken* model, const CSkinnedModel* sModel) { if (!x318_28_disableFog) { - x2ac_fogVolumes.emplace_back(CGraphics::g_GXModelMatrix, color, aabb, model, sModel); + x2ac_fogVolumes.emplace_back(CGraphics::mModelMatrix, color, aabb, model, sModel); } } @@ -977,7 +968,7 @@ void CCubeRenderer::DoThermalBlendCold() { CGX::SetZMode(true, GX_LEQUAL, false); GXSetTexCopySrc(left, top, width, height); GXSetTexCopyDst(width, height, GX_TF_I4, false); - GXCopyTex(CGraphics::sSpareTextureData, true); + GXCopyTex(CGraphics::mpSpareBuffer, true); CGraphics::LoadDolphinSpareTexture(width, height, GX_TF_I4, nullptr, GX_TEXMAP7); // Upload random static texture (game reads from .text) @@ -1050,7 +1041,7 @@ void CCubeRenderer::DoThermalBlendCold() { CGX::SetBlendMode(GX_BM_NONE, GX_BL_ONE, GX_BL_ZERO, GX_LO_CLEAR); // Backup & set viewport/projection - const auto backupViewMatrix = CGraphics::g_ViewMatrix; + const auto backupViewMatrix = CGraphics::mViewMatrix; const auto backupProjectionState = CGraphics::GetProjectionState(); CGraphics::SetOrtho(0.f, static_cast(width), 0.f, static_cast(height), -4096.f, 4096.f); CGraphics::SetViewPointMatrix({}); @@ -1093,7 +1084,7 @@ void CCubeRenderer::DoThermalBlendHot() { CGX::SetZMode(true, GX_LEQUAL, true); GXSetTexCopySrc(left, top, width, height); GXSetTexCopyDst(width, height, GX_TF_I4, false); - GXCopyTex(CGraphics::sSpareTextureData, false); + GXCopyTex(CGraphics::mpSpareBuffer, false); x288_thermoPalette.Load(); CGraphics::LoadDolphinSpareTexture(width, height, GX_TF_C4, GX_TLUT0, nullptr, GX_TEXMAP7); CGX::SetTevColorIn(GX_TEVSTAGE0, GX_CC_ZERO, GX_CC_TEXA, GX_CC_TEXC, GX_CC_ZERO); @@ -1115,7 +1106,7 @@ void CCubeRenderer::DoThermalBlendHot() { CGX::SetBlendMode(GX_BM_BLEND, GX_BL_DSTALPHA, GX_BL_INVDSTALPHA, GX_LO_CLEAR); // Backup & set viewport/projection - const auto backupViewMatrix = CGraphics::g_ViewMatrix; + const auto backupViewMatrix = CGraphics::mViewMatrix; const auto backupProjectionState = CGraphics::GetProjectionState(); CGraphics::SetOrtho(0.f, static_cast(width), 0.f, static_cast(height), -4096.f, 4096.f); CGraphics::SetViewPointMatrix({}); @@ -1186,7 +1177,7 @@ void CCubeRenderer::DrawPhazonSuitIndirectEffect(const zeus::CColor& nonIndirect const TLockedToken& indTex, const zeus::CColor& indirectMod, float blurRadius, float scale, float offX, float offY) { if (x318_27_currentRGBA6 && x310_phazonSuitMaskCountdown != 0) { - const auto backupViewMatrix = CGraphics::g_ViewMatrix; + const auto backupViewMatrix = CGraphics::mViewMatrix; const auto backupProjectionState = CGraphics::GetProjectionState(); if (!x314_phazonSuitMask || x314_phazonSuitMask->GetWidth() != CGraphics::GetViewportWidth() / 4 || x314_phazonSuitMask->GetHeight() != CGraphics::GetViewportHeight() / 4) { @@ -1370,9 +1361,10 @@ void CCubeRenderer::SetupRendererStates(bool depthWrite) { GXSetTevColor(GX_TEVREG1, to_gx_color(x2fc_tevReg1Color)); } -constexpr zeus::CTransform MvPostXf{ - {zeus::CVector3f{0.5f, 0.f, 0.f}, {0.f, 0.f, 0.f}, {0.f, 0.5f, 0.f}}, - {0.5f, 0.5f, 1.f}, +constexpr Mtx MvPostXf = { + {0.5f, 0.0f, 0.0f, 0.5f}, + {0.0f, 0.5f, 0.5f, 0.5f}, + {0.0f, 0.0f, 0.0f, 1.0f}, }; void CCubeRenderer::DoThermalModelDraw(CCubeModel& model, const zeus::CColor& multCol, const zeus::CColor& addCol, @@ -1382,10 +1374,12 @@ void CCubeRenderer::DoThermalModelDraw(CCubeModel& model, const zeus::CColor& mu CGX::SetNumTexGens(1); CGX::SetNumChans(0); x220_sphereRamp.Load(GX_TEXMAP0, EClampMode::Clamp); - zeus::CTransform xf = CGraphics::g_ViewMatrix.inverse().multiplyIgnoreTranslation(CGraphics::g_GXModelMatrix); + zeus::CTransform xf = CGraphics::mViewMatrix.quickInverse().multiplyIgnoreTranslation(CGraphics::mModelMatrix); xf.origin.zeroOut(); - GXLoadTexMtxImm(&xf, GX_TEXMTX0, GX_MTX3x4); - GXLoadTexMtxImm(&MvPostXf, GX_PTTEXMTX0, GX_MTX3x4); + Mtx mtx; + xf.toCStyleMatrix(mtx); + GXLoadTexMtxImm(mtx, GX_TEXMTX0, GX_MTX3x4); + GXLoadTexMtxImm(MvPostXf, GX_PTTEXMTX0, GX_MTX3x4); CGX::SetStandardTevColorAlphaOp(GX_TEVSTAGE0); CGX::SetTevColorIn(GX_TEVSTAGE0, GX_CC_ZERO, GX_CC_C0, GX_CC_TEXC, GX_CC_KONST); CGX::SetTevAlphaIn(GX_TEVSTAGE0, GX_CA_ZERO, GX_CA_TEXA, GX_CA_A0, GX_CA_KONST); @@ -1451,7 +1445,7 @@ void CCubeRenderer::ReallyDrawSpaceWarp(const zeus::CVector3f& pt, float strengt CGX::SetFog(GX_FOG_NONE, fogStartZ, fogEndZ, fogNearZ, fogFarZ, fogColor); GXSetTexCopySrc(v2right.x, v2right.y, v2sub.x, v2sub.y); GXSetTexCopyDst(v2sub.x, v2sub.y, GX_TF_RGBA8, false); - GXCopyTex(CGraphics::sSpareTextureData, false); + GXCopyTex(CGraphics::mpSpareBuffer, false); GXPixModeSync(); CGraphics::LoadDolphinSpareTexture(v2sub.x, v2sub.y, GX_TF_RGBA8, nullptr, GX_TEXMAP7); x150_reflectionTex.Load(GX_TEXMAP1, EClampMode::Clamp); diff --git a/Runtime/Graphics/CCubeRenderer.hpp b/Runtime/Graphics/CCubeRenderer.hpp index 75b64fa5f..a9e9b8e4a 100644 --- a/Runtime/Graphics/CCubeRenderer.hpp +++ b/Runtime/Graphics/CCubeRenderer.hpp @@ -180,7 +180,7 @@ public: void EndPrimitive() override; void SetAmbientColor(const zeus::CColor& color) override; void DrawString(const char* string, s32, s32) override; - u32 GetFPS() override; + float GetFPS() override; void CacheReflection(TReflectionCallback cb, void* ctx, bool clearAfter) override; void DrawSpaceWarp(const zeus::CVector3f& pt, float strength) override; void DrawThermalModel(CModel& model, const zeus::CColor& multCol, const zeus::CColor& addCol, diff --git a/Runtime/Graphics/CFont.cpp b/Runtime/Graphics/CFont.cpp index 16d771e11..7bd22ba40 100644 --- a/Runtime/Graphics/CFont.cpp +++ b/Runtime/Graphics/CFont.cpp @@ -57,15 +57,15 @@ void CFont::LinearToTile8(u8* dest, const u8* src) { } void CFont::DrawString(const char* str, int x, int y, const zeus::CColor& col) { - bool bVar2 = CGraphics::BeginRender2D(*mpTexture.get()); - char chr = *str; - while (chr != 0) { - u32 cellSize = static_cast(16.f * x4_scale); - ++str; - CGraphics::DoRender2D(*mpTexture, x, y, (chr & 0xf) * 16, 0xf0, 0x10, cellSize, cellSize, col); - chr = *str; - } - CGraphics::EndRender2D(bVar2); + // bool bVar2 = CGraphics::BeginRender2D(*mpTexture.get()); + // char chr = *str; + // while (chr != 0) { + // u32 cellSize = static_cast(16.f * x4_scale); + // ++str; + // CGraphics::DoRender2D(*mpTexture, x, y, (chr & 0xf) * 16, 0xf0, 0x10, cellSize, cellSize, col); + // chr = *str; + // } + // CGraphics::EndRender2D(bVar2); } u32 CFont::StringWidth(const char* str) const { diff --git a/Runtime/Graphics/CGX.cpp b/Runtime/Graphics/CGX.cpp index ce3c618dc..79374a8fd 100644 --- a/Runtime/Graphics/CGX.cpp +++ b/Runtime/Graphics/CGX.cpp @@ -6,6 +6,14 @@ namespace metaforce::CGX { SGXState sGXState{}; std::array sVtxDescList{}; +void SetLineWidth(u8 width, GXTexOffset offset) noexcept { + u16 flags = width | offset << 8; + if (flags != sGXState.x54_lineWidthAndOffset) { + sGXState.x54_lineWidthAndOffset = flags; + GXSetLineWidth(width, offset); + } +} + void ResetGXStates() noexcept { sGXState.x48_descList = 0; GXClearVtxDesc(); diff --git a/Runtime/Graphics/CGX.hpp b/Runtime/Graphics/CGX.hpp index efa17c9ba..23685bca4 100644 --- a/Runtime/Graphics/CGX.hpp +++ b/Runtime/Graphics/CGX.hpp @@ -3,6 +3,7 @@ #include "Graphics/GX.hpp" #include "RetroTypes.hpp" +#include #include namespace metaforce::CGX { @@ -118,10 +119,29 @@ static inline void SetAlphaCompare(GXCompare comp0, u8 ref0, GXAlphaOp op, GXCom } } +static inline void SetArray(GXAttr attr, std::span data, u8 stride) noexcept { + const auto* ptr = static_cast(data.data()); + if (ptr != nullptr && sGXState.x0_arrayPtrs[attr - GX_VA_POS] != ptr) { + // sGXState.x0_arrayPtrs[attr - GX_VA_POS] = const_cast(ptr); + GXSetArray(attr, data.data(), data.size(), stride); + } +} + template -static inline void SetArray(GXAttr attr, const std::vector* data, bool isStatic) noexcept { - if (data != nullptr && sGXState.x0_arrayPtrs[attr - GX_VA_POS] != data) { - GXSetArray(attr, data->data(), data->size() * sizeof(T), sizeof(T)); +static inline void SetArray(GXAttr attr, std::span data) noexcept { + const auto* ptr = static_cast(data.data()); + if (ptr != nullptr && sGXState.x0_arrayPtrs[attr - GX_VA_POS] != ptr) { + // sGXState.x0_arrayPtrs[attr - GX_VA_POS] = const_cast(ptr); + GXSetArray(attr, data.data(), data.size_bytes(), sizeof(T)); + } +} + +template +static inline void SetArray(GXAttr attr, const std::array& data) noexcept { + const auto* ptr = static_cast(data.data()); + if (ptr != nullptr && sGXState.x0_arrayPtrs[attr - GX_VA_POS] != ptr) { + // sGXState.x0_arrayPtrs[attr - GX_VA_POS] = const_cast(ptr); + GXSetArray(attr, ptr, data.size() * sizeof(T), sizeof(T)); } } @@ -403,25 +423,24 @@ static inline void SetTexCoordGen(GXTexCoordID dstCoord, u32 flags) noexcept { } } -static inline void SetVtxDescv_Compressed(u32 descList) noexcept { - u32 currentDescList = sGXState.x48_descList; - if (descList != currentDescList) { - size_t remain = sVtxDescList.size() - 1; - u32 shift = 0; - u32 attrIdx = 0; - do { - sVtxDescList[attrIdx] = { - GXAttr(GX_VA_POS + attrIdx), - GXAttrType(descList >> shift & 3), - }; - shift += 2; - ++attrIdx; - --remain; - } while (remain != 0); - sVtxDescList[attrIdx] = {GX_VA_NULL, GX_NONE}; - GXSetVtxDescv(sVtxDescList.data()); - sGXState.x48_descList = descList; +static inline void SetVtxDescv_Compressed(u32 flags) noexcept { + if (flags == sGXState.x48_descList) { + return; } + GXVtxDescList* list = sVtxDescList.data(); + for (u32 idx = 0; idx < sVtxDescList.size() - 1; ++idx) { + u32 shift = idx * 2; + if ((flags & 3 << shift) == (sGXState.x48_descList & 3 << shift)) { + continue; + } + list->attr = static_cast(GX_VA_POS + idx); + list->type = static_cast(flags >> shift & 3); + ++list; + } + list->attr = GX_VA_NULL; + list->type = GX_NONE; + GXSetVtxDescv(sVtxDescList.data()); + sGXState.x48_descList = flags; } static inline void SetVtxDescv(const GXVtxDescList* descList) noexcept { diff --git a/Runtime/Graphics/CGraphics.cpp b/Runtime/Graphics/CGraphics.cpp index a83dd90c8..c24c7dbc0 100644 --- a/Runtime/Graphics/CGraphics.cpp +++ b/Runtime/Graphics/CGraphics.cpp @@ -1,141 +1,201 @@ #include "Runtime/Graphics/CGraphics.hpp" #include "Runtime/CTimeProvider.hpp" -#include "Runtime/Graphics/CLineRenderer.hpp" #include "Runtime/Graphics/CTexture.hpp" -#include "Runtime/Graphics/Shaders/CTextSupportShader.hpp" #include "Runtime/GuiSys/CGuiSys.hpp" #include "Runtime/Graphics/CGX.hpp" +#include "Runtime/Logging.hpp" -#include #include +#include +#include namespace metaforce { -CGraphics::CProjectionState CGraphics::g_Proj; -// CFogState CGraphics::g_Fog; -float CGraphics::g_ProjAspect = 1.f; -u32 CGraphics::g_NumBreakpointsWaiting = 0; -u32 CGraphics::g_FlippingState; -bool CGraphics::g_LastFrameUsedAbove = false; -bool CGraphics::g_InterruptLastFrameUsedAbove = false; -GX::LightMask CGraphics::g_LightActive{}; -std::array CGraphics::g_LightObjs; -std::array CGraphics::g_LightTypes; -zeus::CTransform CGraphics::g_GXModelView; -zeus::CTransform CGraphics::g_GXModelViewInvXpose; -zeus::CTransform CGraphics::g_GXModelMatrix = zeus::CTransform(); -zeus::CTransform CGraphics::g_ViewMatrix; -zeus::CVector3f CGraphics::g_ViewPoint; -zeus::CTransform CGraphics::g_GXViewPointMatrix; -zeus::CTransform CGraphics::g_CameraMatrix; -SClipScreenRect CGraphics::g_CroppedViewport; -bool CGraphics::g_IsGXModelMatrixIdentity = true; -zeus::CColor CGraphics::g_ClearColor = zeus::skClear; -float CGraphics::g_ClearDepthValue = 1.f; -bool CGraphics::g_IsBeginSceneClearFb = true; +using CVector3f = zeus::CVector3f; +using CVector2i = zeus::CVector2i; +using CTransform4f = zeus::CTransform; +using CColor = zeus::CColor; +using uchar = unsigned char; +using uint = unsigned int; +using ushort = unsigned short; -SViewport CGraphics::g_Viewport = { - 0, 0, 640, 480, 640 / 2.f, 480 / 2.f, 0.0f, +CGraphics::CRenderState CGraphics::sRenderState; +VecPtr CGraphics::vtxBuffer; +VecPtr CGraphics::nrmBuffer; +Vec2Ptr CGraphics::txtBuffer0; +Vec2Ptr CGraphics::txtBuffer1; +uint* CGraphics::clrBuffer; +bool CGraphics::mJustReset; +ERglCullMode CGraphics::mCullMode; +int CGraphics::mNumLightsActive; +float CGraphics::mDepthNear; +VecPtr CGraphics::mpVtxBuffer; +VecPtr CGraphics::mpNrmBuffer; +Vec2Ptr CGraphics::mpTxtBuffer0; +Vec2Ptr CGraphics::mpTxtBuffer1; +uint* CGraphics::mpClrBuffer; + +struct { + Vec vtx; + Vec nrm; + Vec2 uv0; + Vec2 uv1; + u32 color; + u16 textureUsed; + u8 streamFlags; +} vtxDescr; + +CVector3f CGraphics::kDefaultPositionVector(0.f, 0.f, 0.f); +CVector3f CGraphics::kDefaultDirectionVector(0.f, 1.f, 0.f); +CGraphics::CProjectionState CGraphics::mProj(true, -1.f, 1.f, 1.f, -1.f, 1.f, 100.f); +CTransform4f CGraphics::mViewMatrix = CTransform4f(); +CTransform4f CGraphics::mModelMatrix = CTransform4f(); +CColor CGraphics::mClearColor = zeus::skBlack; +CVector3f CGraphics::mViewPoint(0.f, 0.f, 0.f); +GXLightObj CGraphics::mLightObj[8]; +// GXTexRegion CGraphics::mTexRegions[GX_MAX_TEXMAP]; +// GXTexRegion CGraphics::mTexRegionsCI[GX_MAX_TEXMAP / 2]; +GXRenderModeObj CGraphics::mRenderModeObj; +Mtx CGraphics::mGXViewPointMatrix; +Mtx CGraphics::mGXModelMatrix; +Mtx CGraphics::mGxModelView; +Mtx CGraphics::mCameraMtx; + +int CGraphics::mNumPrimitives; +int CGraphics::mFrameCounter; +float CGraphics::mFramesPerSecond; +float CGraphics::mLastFramesPerSecond; +int CGraphics::mNumBreakpointsWaiting; +int CGraphics::mFlippingState; +bool CGraphics::mLastFrameUsedAbove; +bool CGraphics::mInterruptLastFrameUsedAbove; +GX::LightMask CGraphics::mLightActive; +GX::LightMask CGraphics::mLightsWereOn; +void* CGraphics::mpFrameBuf1; +void* CGraphics::mpFrameBuf2; +void* CGraphics::mpCurrenFrameBuf; +int CGraphics::mSpareBufferSize; +void* CGraphics::mpSpareBuffer; +int CGraphics::mSpareBufferTexCacheSize; +// GXTexRegionCallback CGraphics::mGXDefaultTexRegionCallback; +void* CGraphics::mpFifo; +GXFifoObj* CGraphics::mpFifoObj; +uint CGraphics::mRenderTimings; +float CGraphics::mSecondsMod900; +CTimeProvider* CGraphics::mpExternalTimeProvider; +int CGraphics::mScreenStretch; +int CGraphics::mScreenPositionX; +int CGraphics::mScreenPositionY; + +CViewport CGraphics::mViewport = {0, 0, 640, 480, 320.f, 240.f}; +ELightType CGraphics::mLightTypes[8] = { + ELightType::Directional, ELightType::Directional, ELightType::Directional, ELightType::Directional, + ELightType::Directional, ELightType::Directional, ELightType::Directional, ELightType::Directional, }; -u32 CGraphics::g_FrameCounter = 0; -u32 CGraphics::g_Framerate = 0; -u32 CGraphics::g_FramesPast = 0; -frame_clock::time_point CGraphics::g_FrameStartTime = frame_clock::now(); -ERglEnum CGraphics::g_depthFunc = ERglEnum::Never; -ERglCullMode CGraphics::g_cullMode = ERglCullMode::None; -const std::array CGraphics::skCubeBasisMats{{ - /* Right */ - {0.f, 1.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.f, -1.f}, - /* Left */ - {0.f, -1.f, 0.f, -1.f, 0.f, 0.f, 0.f, 0.f, -1.f}, - /* Up */ - {1.f, 0.f, 0.f, 0.f, 0.f, -1.f, 0.f, 1.f, 0.f}, - /* Down */ - {1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, -1.f, 0.f}, - /* Back */ - {1.f, 0.f, 0.f, 0.f, -1.f, 0.f, 0.f, 0.f, -1.f}, - /* Forward */ - {-1.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, -1.f}, -}}; +// const CTevCombiners::CTevPass& CGraphics::kEnvPassthru = CTevCombiners::kEnvPassthru; +bool CGraphics::mIsBeginSceneClearFb = true; +ERglEnum CGraphics::mDepthFunc = ERglEnum::LEqual; +ERglPrimitive CGraphics::mCurrentPrimitive = ERglPrimitive::Points; +float CGraphics::mDepthFar = 1.f; +u32 CGraphics::mClearDepthValue = GX_MAX_Z24; +bool CGraphics::mIsGXModelMatrixIdentity = true; +bool CGraphics::mFirstFrame = true; +GXBool CGraphics::mUseVideoFilter = GX_ENABLE; +float CGraphics::mBrightness = 1.f; + +const GXTexMapID CGraphics::kSpareBufferTexMapID = GX_TEXMAP7; + // We don't actually store anything here -u8 CGraphics::sSpareTextureData[] = {0}; - -// Stream API -static u32 sStreamFlags; -static GXPrimitive sStreamPrimitive; -static u32 sVerticesCount; -static zeus::CColor sQueuedColor; -// Originally writes directly to GX FIFO -struct StreamVertex { - zeus::CColor color; - zeus::CVector2f texCoord; - zeus::CVector3f normal; - zeus::CVector3f vertex; - constexpr StreamVertex(const zeus::CColor& color) : color(color) {} - constexpr StreamVertex(const StreamVertex&) = default; -}; -static std::vector sQueuedVertices; +static std::array sSpareFrameBuffer; void CGraphics::DisableAllLights() { - g_LightActive.reset(); - CGX::SetChanCtrl(CGX::EChannelId::Channel0, {}); + mNumLightsActive = 0; + mLightActive.reset(); + CGX::SetChanCtrl(CGX::EChannelId::Channel0, false, GX_SRC_REG, GX_SRC_REG, GX_LIGHT_NULL, GX_DF_NONE, GX_AF_NONE); +} + +static inline GXLightID get_hw_light_index(ERglLight light) { + return static_cast((1 << light) & (GX_MAX_LIGHT - 1)); } void CGraphics::LoadLight(ERglLight light, const CLight& info) { - const auto lightId = static_cast(1 << light); + GXLightID lightId = get_hw_light_index(light); + ELightType type = info.GetType(); + CVector3f pos = info.GetPosition(); + CVector3f dir = info.GetDirection(); - auto& obj = g_LightObjs[light]; - zeus::CVector3f pos = info.GetPosition(); - zeus::CVector3f dir = info.GetDirection(); - const auto type = info.GetType(); - if (type == ELightType::Directional) { - dir = -(g_CameraMatrix.buildMatrix3f() * dir); - GXInitLightPos(&obj, dir.x() * 1048576.f, dir.y() * 1048576.f, dir.z() * 1048576.f); - GXInitLightAttn(&obj, 1.f, 0.f, 0.f, 1.f, 0.f, 0.f); - } else if (type == ELightType::Spot) { - pos = g_CameraMatrix * pos; - GXInitLightPos(&obj, pos.x(), pos.y(), pos.z()); - dir = g_CameraMatrix.buildMatrix3f() * dir; - GXInitLightDir(&obj, dir.x(), dir.y(), dir.z()); - GXInitLightAttn(&obj, 1.f, 0.f, 0.f, info.GetAttenuationConstant(), info.GetAttenuationLinear(), + switch (type) { + case ELightType::Spot: { + MTXMultVec(mCameraMtx, reinterpret_cast(&pos), reinterpret_cast(&pos)); + GXLightObj* obj = &mLightObj[light]; + GXInitLightPos(obj, pos.x(), pos.y(), pos.z()); + MTXMultVecSR(mCameraMtx, reinterpret_cast(&dir), reinterpret_cast(&dir)); + GXInitLightDir(obj, dir.x(), dir.y(), dir.z()); + GXInitLightAttn(obj, 1.f, 0.f, 0.f, info.GetAttenuationConstant(), info.GetAttenuationLinear(), info.GetAttenuationQuadratic()); - GXInitLightSpot(&obj, info.GetSpotCutoff(), GX_SP_COS2); - } else if (type == ELightType::Custom) { - pos = g_CameraMatrix * pos; - GXInitLightPos(&obj, pos.x(), pos.y(), pos.z()); - dir = g_CameraMatrix.buildMatrix3f() * dir; - GXInitLightDir(&obj, dir.x(), dir.y(), dir.z()); - GXInitLightAttn(&obj, info.GetAngleAttenuationConstant(), info.GetAngleAttenuationLinear(), + GXInitLightSpot(obj, info.GetSpotCutoff(), GX_SP_COS2); + break; + } + case ELightType::Point: + case ELightType::LocalAmbient: { + MTXMultVec(mCameraMtx, reinterpret_cast(&pos), reinterpret_cast(&pos)); + GXInitLightPos(&mLightObj[light], pos.x(), pos.y(), pos.z()); + GXInitLightAttn(&mLightObj[light], 1.f, 0.f, 0.f, info.GetAttenuationConstant(), info.GetAttenuationLinear(), + info.GetAttenuationQuadratic()); + break; + } + case ELightType::Directional: { + MTXMultVecSR(mCameraMtx, reinterpret_cast(&dir), reinterpret_cast(&dir)); + dir = -dir; + GXInitLightPos(&mLightObj[light], dir.x() * 1048576.f, dir.y() * 1048576.f, dir.z() * 1048576.f); + GXInitLightAttn(&mLightObj[light], 1.f, 0.f, 0.f, 1.f, 0.f, 0.f); + break; + } + case ELightType::Custom: { + MTXMultVec(mCameraMtx, reinterpret_cast(&pos), reinterpret_cast(&pos)); + GXLightObj* obj = &mLightObj[light]; + GXInitLightPos(obj, pos.x(), pos.y(), pos.z()); + MTXMultVecSR(mCameraMtx, reinterpret_cast(&dir), reinterpret_cast(&dir)); + GXInitLightDir(obj, dir.x(), dir.y(), dir.z()); + GXInitLightAttn(obj, info.GetAngleAttenuationConstant(), info.GetAngleAttenuationLinear(), info.GetAngleAttenuationQuadratic(), info.GetAttenuationConstant(), info.GetAttenuationLinear(), info.GetAttenuationQuadratic()); - } else if (type == ELightType::LocalAmbient || type == ELightType::Point) { - pos = g_CameraMatrix * pos; - GXInitLightPos(&obj, pos.x(), pos.y(), pos.z()); - GXInitLightAttn(&obj, 1.f, 0.f, 0.f, info.GetAttenuationConstant(), info.GetAttenuationLinear(), - info.GetAttenuationQuadratic()); + break; + } + default: + break; } - g_LightTypes[light] = type; - zeus::CColor col(info.GetColor().r(), info.GetColor().g(), info.GetColor().b()); - GXInitLightColor(&obj, to_gx_color(col)); - GXLoadLightObjImm(&obj, lightId); + GXInitLightColor(&mLightObj[light], to_gx_color(info.GetColor())); + GXLoadLightObjImm(&mLightObj[light], lightId); + mLightTypes[light] = info.GetType(); } void CGraphics::EnableLight(ERglLight light) { CGX::SetNumChans(1); - if (!g_LightActive.test(light)) { - g_LightActive.set(light); - CGX::SetChanCtrl(CGX::EChannelId::Channel0, g_LightActive); + GX::LightMask lightsWereOn = mLightActive; + if (!lightsWereOn.test(light)) { + mLightActive.set(light); + CGX::SetChanCtrl(CGX::EChannelId::Channel0, true, GX_SRC_REG, GX_SRC_REG, mLightActive, GX_DF_CLAMP, GX_AF_SPOT); + ++mNumLightsActive; } + mLightsWereOn = mLightActive; } -void CGraphics::SetLightState(GX::LightMask lightState) { - g_LightActive = lightState; - const bool hasLights = lightState.any(); - CGX::SetChanCtrl(CGX::EChannelId::Channel0, hasLights, GX_SRC_REG, - sStreamFlags & 2 /* fHasColor */ ? GX_SRC_VTX : GX_SRC_REG, lightState, - hasLights ? GX_DF_CLAMP : GX_DF_NONE, hasLights ? GX_AF_SPOT : GX_AF_NONE); +void CGraphics::SetLightState(GX::LightMask lights) { + GXAttnFn attnFn = GX_AF_NONE; + if (lights.any()) { + attnFn = GX_AF_SPOT; + } + GXDiffuseFn diffFn = GX_DF_NONE; + if (lights.any()) { + diffFn = GX_DF_CLAMP; + } + CGX::SetChanCtrl(CGX::EChannelId::Channel0, lights.any() ? GX_ENABLE : GX_DISABLE, GX_SRC_REG, + (vtxDescr.streamFlags & 2) != 0 ? GX_SRC_VTX : GX_SRC_REG, lights, diffFn, attnFn); + mLightActive = lights; + mNumLightsActive = lights.count(); } void CGraphics::SetAmbientColor(const zeus::CColor& col) { @@ -144,522 +204,712 @@ void CGraphics::SetAmbientColor(const zeus::CColor& col) { } void CGraphics::SetFog(ERglFogMode mode, float startz, float endz, const zeus::CColor& color) { - CGX::SetFog(GXFogType(mode), startz, endz, g_Proj.x14_near, g_Proj.x18_far, to_gx_color(color)); + CGX::SetFog(static_cast(mode), startz, endz, mProj.GetNear(), mProj.GetFar(), to_gx_color(color)); } -void CGraphics::SetDepthWriteMode(bool compare_enable, ERglEnum comp, bool update_enable) { - g_depthFunc = comp; - CGX::SetZMode(compare_enable, GXCompare(comp), update_enable); +void CGraphics::SetDepthWriteMode(const bool test, ERglEnum comp, const bool write) { + mDepthFunc = comp; + CGX::SetZMode(test, static_cast(comp), write); } void CGraphics::SetBlendMode(ERglBlendMode mode, ERglBlendFactor src, ERglBlendFactor dst, ERglLogicOp op) { - CGX::SetBlendMode(GXBlendMode(mode), GXBlendFactor(src), GXBlendFactor(dst), GXLogicOp(op)); + CGX::SetBlendMode(static_cast(mode), static_cast(src), static_cast(dst), + static_cast(op)); } -void CGraphics::SetCullMode(ERglCullMode mode) { - g_cullMode = mode; - GXSetCullMode(GXCullMode(mode)); +void CGraphics::SetCullMode(ERglCullMode cullMode) { + mCullMode = cullMode; + GXSetCullMode(static_cast(cullMode)); } -void CGraphics::BeginScene() { - // ClearBackAndDepthBuffers(); +void CGraphics::ClearBackAndDepthBuffers() { + GXInvalidateTexAll(); + GXSetViewport(0.f, 0.f, mRenderModeObj.fbWidth, mRenderModeObj.xfbHeight, 0.f, 1.f); + GXInvalidateVtxCache(); } +void CGraphics::BeginScene() { ClearBackAndDepthBuffers(); } + void CGraphics::EndScene() { CGX::SetZMode(true, GX_LEQUAL, true); - - /* Spinwait until g_NumBreakpointsWaiting is 0 */ - /* ++g_NumBreakpointsWaiting; */ - /* GXCopyDisp to g_CurrenFrameBuf with clear enabled */ - /* Register next breakpoint with GP FIFO */ - - /* Yup, GX effectively had fences long before D3D12 and Vulkan - * (same functionality implemented in boo's execute method) */ - - /* This usually comes from VI register during interrupt; - * we don't care in the era of progressive-scan dominance, - * so simulate field-flipping with XOR instead */ - g_InterruptLastFrameUsedAbove ^= 1; - g_LastFrameUsedAbove = g_InterruptLastFrameUsedAbove; - - ++g_FrameCounter; - - UpdateFPSCounter(); + // volatile int& numBreakPt = const_cast< volatile int& >(mNumBreakpointsWaiting); + // while (numBreakPt > 0) { + // OSYieldThread(); + // } + ++mNumBreakpointsWaiting; + void*& frameBuf = mpCurrenFrameBuf; + float brightness = std::clamp(mBrightness, 0.f, 2.f); + static const u8 copyFilter[7] = {0x00, 0x00, 0x15, 0x16, 0x15, 0x00, 0x00}; + const u8* inFilter = mUseVideoFilter ? mRenderModeObj.vfilter : copyFilter; + u8 vfilter[7]; + for (int i = 0; i < 7; i++) { + vfilter[i] = static_cast(static_cast(inFilter[i]) * brightness); + } + GXSetCopyFilter(mRenderModeObj.aa, mRenderModeObj.sample_pattern, true, vfilter); + GXCopyDisp(frameBuf, mIsBeginSceneClearFb ? GX_TRUE : GX_FALSE); + GXSetCopyFilter(mRenderModeObj.aa, mRenderModeObj.sample_pattern, mUseVideoFilter ? GX_ENABLE : GX_DISABLE, + mRenderModeObj.vfilter); + // GXSetBreakPtCallback(SwapBuffers); + // VISetPreRetraceCallback(VideoPreCallback); + // VISetPostRetraceCallback(VideoPostCallback); + GXFlush(); + GXFifoObj* fifo = GXGetGPFifo(); + void* readPtr; + void* writePtr; + GXGetFifoPtrs(fifo, &readPtr, &writePtr); + // GXEnableBreakPt(writePtr); + mLastFrameUsedAbove = mInterruptLastFrameUsedAbove; + ++mFrameCounter; + // CFrameDelayedKiller::fn_8036CB90(); } +static constexpr GXVtxDescList skPosColorTexDirect[] = { + {GX_VA_POS, GX_DIRECT}, + {GX_VA_CLR0, GX_DIRECT}, + {GX_VA_TEX0, GX_DIRECT}, + {GX_VA_NULL, GX_DIRECT}, +}; + void CGraphics::Render2D(CTexture& tex, u32 x, u32 y, u32 w, u32 h, const zeus::CColor& col) { - const auto oldProj = g_Proj; - const auto oldCull = g_cullMode; - const auto oldLights = g_LightActive; - SetOrtho(-g_Viewport.x8_width / 2, g_Viewport.x8_width / 2, g_Viewport.xc_height / 2, -g_Viewport.xc_height / 2, -1.f, + Mtx44 proj; + MTXOrtho(proj, mViewport.mHeight / 2, -mViewport.mHeight / 2, -mViewport.mWidth / 2, mViewport.mWidth / 2, -1.f, -10.f); - GXLoadPosMtxImm(&zeus::skIdentityMatrix4f, GX_PNMTX0); - GXVtxDescList desc[] = { - {GX_VA_POS, GX_DIRECT}, - {GX_VA_CLR0, GX_DIRECT}, - {GX_VA_TEX0, GX_DIRECT}, - {GX_VA_NULL, GX_NONE}, - }; - CGX::SetVtxDescv(desc); + GXSetProjection(proj, GX_ORTHOGRAPHIC); + uint c = col.toRGBA(); + + Mtx mtx; + MTXIdentity(mtx); + GXLoadPosMtxImm(mtx, GX_PNMTX0); + + float x2, y2, x1, y1; + x1 = x - mViewport.mWidth / 2; + y1 = y - mViewport.mHeight / 2; + x2 = x1 + w; + y2 = y1 + h; + + // Save state + setup + CGX::SetVtxDescv(skPosColorTexDirect); SetTevStates(6); - if (g_LightActive.any()) { + mLightsWereOn = mLightActive; + if (mLightActive.any()) { DisableAllLights(); } + ERglCullMode cullMode = mCullMode; SetCullMode(ERglCullMode::None); - // float hPad, vPad; - // if (CGraphics::GetViewportAspect() >= 1.78f) { - // hPad = 1.78f / CGraphics::GetViewportAspect(); - // vPad = 1.78f / 1.33f; - // } else { - // hPad = 1.f; - // vPad = CGraphics::GetViewportAspect() / 1.33f; - // } - // TODO make this right - float scaledX = static_cast(x) / 640.f * static_cast(g_Viewport.x8_width); - float scaledY = static_cast(y) / 448.f * static_cast(g_Viewport.xc_height); - float scaledW = static_cast(w) / 640.f * static_cast(g_Viewport.x8_width); - float scaledH = static_cast(h) / 448.f * static_cast(g_Viewport.xc_height); - - float x1 = scaledX - (g_Viewport.x8_width / 2); - float y1 = scaledY - (g_Viewport.xc_height / 2); - float x2 = x1 + scaledW; - float y2 = y1 + scaledH; - - tex.Load(GX_TEXMAP0, EClampMode::Repeat); + // Draw CGX::Begin(GX_TRIANGLESTRIP, GX_VTXFMT0, 4); - { - GXPosition3f32(x1, y1, 1.f); - GXColor4f32(col.r(), col.g(), col.b(), col.a()); - GXTexCoord2f32(0.f, 0.f); - GXPosition3f32(x2, y1, 1.f); - GXColor4f32(col.r(), col.g(), col.b(), col.a()); - GXTexCoord2f32(1.f, 0.f); - GXPosition3f32(x1, y2, 1.f); - GXColor4f32(col.r(), col.g(), col.b(), col.a()); - GXTexCoord2f32(0.f, 1.f); - GXPosition3f32(x2, y2, 1.f); - GXColor4f32(col.r(), col.g(), col.b(), col.a()); - GXTexCoord2f32(1.f, 1.f); - } + GXPosition3f32(x1, y1, 1.f); + GXColor1u32(c); + GXTexCoord2f32(0.f, 0.f); + GXPosition3f32(x2, y1, 1.f); + GXColor1u32(c); + GXTexCoord2f32(1.f, 0.f); + GXPosition3f32(x1, y2, 1.f); + GXColor1u32(c); + GXTexCoord2f32(0.f, 1.f); + GXPosition3f32(x2, y2, 1.f); + GXColor1u32(c); + GXTexCoord2f32(1.f, 1.f); CGX::End(); - if (oldLights.any()) { - SetLightState(oldLights); + // Restore state + if (mLightsWereOn.any()) { + SetLightState(mLightsWereOn); } - g_Proj = oldProj; FlushProjection(); - SetModelMatrix({}); - SetCullMode(oldCull); + mIsGXModelMatrixIdentity = false; + SetModelMatrix(mModelMatrix); + SetCullMode(cullMode); } -bool CGraphics::BeginRender2D(const CTexture& tex) { return false; } - -void CGraphics::DoRender2D(const CTexture& tex, s32 x, s32 y, s32 w1, s32 w2, s32 w3, s32 w4, s32 w5, - const zeus::CColor& col) {} - -void CGraphics::EndRender2D(bool v) {} - -void CGraphics::SetAlphaCompare(ERglAlphaFunc comp0, u8 ref0, ERglAlphaOp op, ERglAlphaFunc comp1, u8 ref1) { +void CGraphics::SetAlphaCompare(ERglAlphaFunc comp0, uchar ref0, ERglAlphaOp op, ERglAlphaFunc comp1, uchar ref1) { CGX::SetAlphaCompare(static_cast(comp0), ref0, static_cast(op), static_cast(comp1), ref1); } void CGraphics::SetViewPointMatrix(const zeus::CTransform& xf) { - g_ViewMatrix = xf; - g_ViewPoint = xf.origin; - zeus::CMatrix3f tmp(xf.basis[0], xf.basis[2], -xf.basis[1]); - g_GXViewPointMatrix = zeus::CTransform(tmp.transposed()); + mViewMatrix = xf; + mGXViewPointMatrix[0][0] = xf.basis[0][0]; + mGXViewPointMatrix[0][1] = xf.basis[0][1]; + mGXViewPointMatrix[0][2] = xf.basis[0][2]; + mGXViewPointMatrix[0][3] = 0.f; + mGXViewPointMatrix[1][0] = xf.basis[2][0]; + mGXViewPointMatrix[1][1] = xf.basis[2][1]; + mGXViewPointMatrix[1][2] = xf.basis[2][2]; + mGXViewPointMatrix[1][3] = 0.f; + mGXViewPointMatrix[2][0] = -xf.basis[1][0]; + mGXViewPointMatrix[2][1] = -xf.basis[1][1]; + mGXViewPointMatrix[2][2] = -xf.basis[1][2]; + mGXViewPointMatrix[2][3] = 0.f; + mViewPoint = xf.origin; + SetViewMatrix(); +} + +void CGraphics::SetIdentityViewPointMatrix() { + mViewMatrix = CTransform4f(); + MTXIdentity(mGXViewPointMatrix); + mGXViewPointMatrix[2][2] = 0.f; + mGXViewPointMatrix[1][1] = 0.f; + mGXViewPointMatrix[1][2] = 1.f; + mGXViewPointMatrix[2][1] = -1.f; + mViewPoint = CVector3f(); SetViewMatrix(); } void CGraphics::SetViewMatrix() { - g_CameraMatrix = g_GXViewPointMatrix * zeus::CTransform::Translate(-g_ViewPoint); - if (g_IsGXModelMatrixIdentity) - g_GXModelView = g_CameraMatrix; - else - g_GXModelView = g_CameraMatrix * g_GXModelMatrix; - /* Load position matrix */ - GXLoadPosMtxImm(&g_GXModelView, GX_PNMTX0); - /* Inverse-transpose */ - g_GXModelViewInvXpose = g_GXModelView.inverse(); - g_GXModelViewInvXpose.basis.transpose(); - /* Load normal matrix */ - GXLoadNrmMtxImm(&g_GXModelViewInvXpose, GX_PNMTX0); + Mtx mtx; + MTXTrans(mtx, -mViewPoint.x(), -mViewPoint.y(), -mViewPoint.z()); + MTXConcat(mGXViewPointMatrix, mtx, mCameraMtx); + if (mIsGXModelMatrixIdentity) { + MTXCopy(mCameraMtx, mGxModelView); + } else { + MTXConcat(mCameraMtx, mGXModelMatrix, mGxModelView); + } + GXLoadPosMtxImm(mGxModelView, GX_PNMTX0); + + Mtx nrmMtx; + MTXInvXpose(mGxModelView, nrmMtx); + GXLoadNrmMtxImm(nrmMtx, GX_PNMTX0); } void CGraphics::SetModelMatrix(const zeus::CTransform& xf) { - g_IsGXModelMatrixIdentity = false; - g_GXModelMatrix = xf; + if (xf == zeus::CTransform()) { + if (!mIsGXModelMatrixIdentity) { + mModelMatrix = xf; + mIsGXModelMatrixIdentity = true; + SetViewMatrix(); + } + return; + } + + mModelMatrix = xf; + mIsGXModelMatrixIdentity = false; + mGXModelMatrix[0][0] = xf.basis[0][0]; + mGXModelMatrix[0][1] = xf.basis[1][0]; + mGXModelMatrix[0][2] = xf.basis[2][0]; + mGXModelMatrix[0][3] = xf.origin.x(); + mGXModelMatrix[1][0] = xf.basis[0][1]; + mGXModelMatrix[1][1] = xf.basis[1][1]; + mGXModelMatrix[1][2] = xf.basis[2][1]; + mGXModelMatrix[1][3] = xf.origin.y(); + mGXModelMatrix[2][0] = xf.basis[0][2]; + mGXModelMatrix[2][1] = xf.basis[1][2]; + mGXModelMatrix[2][2] = xf.basis[2][2]; + mGXModelMatrix[2][3] = xf.origin.z(); SetViewMatrix(); } -zeus::CMatrix4f CGraphics::CalculatePerspectiveMatrix(float fovy, float aspect, float znear, float zfar) { - CProjectionState st; - float tfov = std::tan(zeus::degToRad(fovy * 0.5f)); - st.x14_near = znear; - st.x18_far = zfar; - st.xc_top = znear * tfov; - st.x10_bottom = -st.xc_top; - st.x8_right = aspect * znear * tfov; - st.x4_left = -st.x8_right; - - float rml = st.x8_right - st.x4_left; - float rpl = st.x8_right + st.x4_left; - float tmb = st.xc_top - st.x10_bottom; - float tpb = st.xc_top + st.x10_bottom; - float fpn = st.x18_far + st.x14_near; - float fmn = st.x18_far - st.x14_near; - // clang-format off - return { - 2.f * st.x14_near / rml, 0.f, rpl / rml, 0.f, - 0.f, 2.f * st.x14_near / tmb, tpb / tmb, 0.f, - 0.f, 0.f, -fpn / fmn, -2.f * st.x18_far * st.x14_near / fmn, - 0.f, 0.f, -1.f, 0.f, - }; - // clang-format on -} - -zeus::CMatrix4f CGraphics::GetPerspectiveProjectionMatrix() { - if (g_Proj.x0_persp) { - float rml = g_Proj.x8_right - g_Proj.x4_left; - float rpl = g_Proj.x8_right + g_Proj.x4_left; - float tmb = g_Proj.xc_top - g_Proj.x10_bottom; - float tpb = g_Proj.xc_top + g_Proj.x10_bottom; - float fpn = g_Proj.x18_far + g_Proj.x14_near; - float fmn = g_Proj.x18_far - g_Proj.x14_near; - // clang-format off - return { - 2.f * g_Proj.x14_near / rml, 0.f, rpl / rml, 0.f, 0.f, - 2.f * g_Proj.x14_near / tmb, tpb / tmb, 0.f, - 0.f, 0.f, -g_Proj.x14_near / fmn, -(g_Proj.x18_far * g_Proj.x14_near) / fmn, - 0.f, 0.f, -1.f, 0.f, - }; - // clang-format on - } else { - float rml = g_Proj.x8_right - g_Proj.x4_left; - float rpl = g_Proj.x8_right + g_Proj.x4_left; - float tmb = g_Proj.xc_top - g_Proj.x10_bottom; - float tpb = g_Proj.xc_top + g_Proj.x10_bottom; - float fmn = g_Proj.x18_far - g_Proj.x14_near; - // clang-format off - return { - 2.f / rml, 0.f, 0.f, -rpl / rml, - 0.f, 2.f / tmb, 0.f, -tpb / tmb, - 0.f, 0.f, -1.f / fmn, -g_Proj.x18_far / fmn, - 0.f, 0.f, 0.f, 1.f - }; - // clang-format on +void CGraphics::SetIdentityModelMatrix() { + if (!mIsGXModelMatrixIdentity) { + mModelMatrix = CTransform4f(); + mIsGXModelMatrixIdentity = true; + SetViewMatrix(); } } -const CGraphics::CProjectionState& CGraphics::GetProjectionState() { return g_Proj; } +zeus::CMatrix4f CGraphics::CalculatePerspectiveMatrix(float fovy, float aspect, float znear, float zfar) { + float t = std::tan(zeus::degToRad(fovy) / 2.f); + float right = aspect * 2.f * znear * t * 0.5f; + float left = -right; + float top = znear * 2.f * t * 0.5f; + float bottom = -top; + return zeus::CMatrix4f{ + // clang-format off + (2.f * znear) / (right - left), + -(right + left) / (right - left), + 0.f, + 0.f, + 0.f, + -(top + bottom) / (top - bottom), + (2.f * znear) / (top - bottom), + 0.f, + 0.f, + (zfar + znear) / (zfar - znear), + 0.f, + -(2.f * zfar * znear) / (zfar - znear), + 0.f, + 1.f, + 0.f, + 0.f, + // clang-format on + }; +} -void CGraphics::SetProjectionState(const CGraphics::CProjectionState& proj) { - g_Proj = proj; +zeus::CMatrix4f CGraphics::GetPerspectiveProjectionMatrix() { + return zeus::CMatrix4f{ + // clang-format off + (mProj.GetNear() * 2.f) / (mProj.GetRight() - mProj.GetLeft()), + -(mProj.GetRight() + mProj.GetLeft()) / (mProj.GetRight() - mProj.GetLeft()), + 0.f, + 0.f, + 0.f, + -(mProj.GetTop() + mProj.GetBottom()) / (mProj.GetTop() - mProj.GetBottom()), + (mProj.GetNear() * 2.f) / (mProj.GetTop() - mProj.GetBottom()), + 0.f, + 0.f, + (mProj.GetFar() + mProj.GetNear()) / (mProj.GetFar() - mProj.GetNear()), + 0.f, + -(mProj.GetFar() * 2.f * mProj.GetNear()) / (mProj.GetFar() - mProj.GetNear()), + 0.f, + 1.f, + 0.f, + 0.f + // clang-format on + }; +} + +const CGraphics::CProjectionState& CGraphics::GetProjectionState() { return mProj; } + +void CGraphics::SetProjectionState(const CProjectionState& proj) { + mProj = proj; FlushProjection(); } void CGraphics::SetPerspective(float fovy, float aspect, float znear, float zfar) { - g_ProjAspect = aspect; - - float tfov = std::tan(zeus::degToRad(fovy * 0.5f)); - g_Proj.x0_persp = true; - g_Proj.x14_near = znear; - g_Proj.x18_far = zfar; - g_Proj.xc_top = znear * tfov; - g_Proj.x10_bottom = -g_Proj.xc_top; - g_Proj.x8_right = aspect * znear * tfov; - g_Proj.x4_left = -g_Proj.x8_right; - + float t = tan(zeus::degToRad(fovy) / 2.f); + mProj = CProjectionState(true, // Is Projection + -(aspect * 2.f * znear * t * 0.5f), // Left + (aspect * 2.f * znear * t * 0.5f), // Right + (znear * 2.f * t * 0.5f), // Top + -(znear * 2.f * t * 0.5f), // Bottom + znear, zfar); FlushProjection(); } void CGraphics::SetOrtho(float left, float right, float top, float bottom, float znear, float zfar) { - g_Proj.x0_persp = false; - g_Proj.x4_left = left; - g_Proj.x8_right = right; - g_Proj.xc_top = top; - g_Proj.x10_bottom = bottom; - g_Proj.x14_near = znear; - g_Proj.x18_far = zfar; - + mProj = CProjectionState(false, left, right, top, bottom, znear, zfar); FlushProjection(); } void CGraphics::FlushProjection() { - const auto mtx = GetPerspectiveProjectionMatrix(); - if (g_Proj.x0_persp) { - // Convert and load persp - GXSetProjection(&mtx, GX_PERSPECTIVE); + float right = mProj.GetRight(); + float left = mProj.GetLeft(); + float top = mProj.GetTop(); + float bottom = mProj.GetBottom(); + float near = mProj.GetNear(); + float far = mProj.GetFar(); + if (mProj.IsPerspective()) { + Mtx44 mtx; + MTXFrustum(mtx, top, bottom, left, right, near, far); + GXSetProjection(mtx, GX_PERSPECTIVE); } else { - // Convert and load ortho - GXSetProjection(&mtx, GX_ORTHOGRAPHIC); + Mtx44 mtx; + MTXOrtho(mtx, top, bottom, left, right, near, far); + GXSetProjection(mtx, GX_ORTHOGRAPHIC); } } zeus::CVector2i CGraphics::ProjectPoint(const zeus::CVector3f& point) { - zeus::CVector3f projPt = GetPerspectiveProjectionMatrix().multiplyOneOverW(point); - return {int(projPt.x() * g_Viewport.x10_halfWidth) + int(g_Viewport.x10_halfWidth), - int(g_Viewport.xc_height) - (int(projPt.y() * g_Viewport.x14_halfHeight) + int(g_Viewport.x14_halfHeight))}; + zeus::CVector3f vec = GetPerspectiveProjectionMatrix().multiplyOneOverW(point); + vec.x() = vec.x() * mViewport.mHalfWidth + mViewport.mHalfWidth; + vec.y() = -vec.y() * mViewport.mHalfHeight + mViewport.mHalfHeight; + return CVector2i(vec.x(), vec.y()); } -SClipScreenRect CGraphics::ClipScreenRectFromMS(const zeus::CVector3f& p1, const zeus::CVector3f& p2) { - zeus::CVector3f xf1 = g_GXModelView * p1; - zeus::CVector3f xf2 = g_GXModelView * p2; - return ClipScreenRectFromVS(xf1, xf2); +static CVector3f TransposeMultiply(const CTransform4f& self, const CVector3f& in) { + return self.transposeRotate({in.x() - self.origin.x(), in.y() - self.origin.y(), in.z() - self.origin.z()}); } -SClipScreenRect CGraphics::ClipScreenRectFromVS(const zeus::CVector3f& p1, const zeus::CVector3f& p2) { - if (p1.x() == 0.f && p1.y() == 0.f && p1.z() == 0.f) - return {}; - if (p2.x() == 0.f && p2.y() == 0.f && p2.z() == 0.f) - return {}; +CGraphics::CClippedScreenRect CGraphics::ClipScreenRectFromMS(const CVector3f& p1, const CVector3f& p2, + ETexelFormat fmt) { + return ClipScreenRectFromVS(TransposeMultiply(mViewMatrix, mModelMatrix * p1), + TransposeMultiply(mViewMatrix, mModelMatrix * p2), fmt); +} - if (-p1.z() < GetProjectionState().x14_near || -p2.z() < GetProjectionState().x14_near) - return {}; - if (-p1.z() > GetProjectionState().x18_far || -p2.z() > GetProjectionState().x18_far) - return {}; +CGraphics::CClippedScreenRect CGraphics::ClipScreenRectFromVS(const CVector3f& p1, const CVector3f& p2, + ETexelFormat fmt) { + if (p1.isZero() || p2.isZero()) { + return CClippedScreenRect(); + } + if (p1.y() < GetProjectionState().GetNear() || p2.y() < GetProjectionState().GetNear()) { + return CClippedScreenRect(); + } + if (p1.y() > GetProjectionState().GetFar() || p2.y() > GetProjectionState().GetFar()) { + return CClippedScreenRect(); + } - zeus::CVector2i sp1 = ProjectPoint(p1); - zeus::CVector2i sp2 = ProjectPoint(p2); - int minX = std::min(sp2.x, sp1.x); - int minX2 = minX & 0xfffffffe; - int minY = std::min(sp2.y, sp1.y); - int minY2 = minY & 0xfffffffe; + CVector2i p1p = ProjectPoint(p1); + CVector2i p2p = ProjectPoint(p2); - if (minX2 >= g_Viewport.x8_width) - return {}; + int minX = std::min(p1p.x, p2p.x); + int minY = std::min(p1p.y, p2p.y); - int maxX = abs(sp1.x - sp2.x) + minX; - int maxX2 = (maxX + 2) & 0xfffffffe; - if (maxX2 <= 0 /* ViewportX origin */) - return {}; + int maxX = abs(p1p.x - p2p.x); + int maxY = abs(p1p.y - p2p.y); - // int finalMinX = std::max(minX, 0 /* ViewportX origin */); - // int finalMaxX = std::min(maxX, int(g_Viewport.x8_width)); + int left = minX & ~1; + if (left >= mViewport.mLeft + mViewport.mWidth) { + return CClippedScreenRect(); + } - if (minY2 >= g_Viewport.xc_height) - return {}; + int right = minX + maxX + 2 & ~1; + if (right <= mViewport.mLeft) { + return CClippedScreenRect(); + } + left = std::max(left, mViewport.mLeft) & ~1; + right = std::min(right, mViewport.mLeft + mViewport.mWidth) + 1 & ~1; - int maxY = abs(sp1.y - sp2.y) + minY; - int maxY2 = (maxY + 2) & 0xfffffffe; - if (maxY2 <= 0 /* ViewportY origin */) - return {}; + int top = minY & ~1; + if (top >= mViewport.mTop + mViewport.mHeight) { + return CClippedScreenRect(); + } - // int finalMinY = std::max(minY, 0 /* ViewportY origin */); - // int finalMaxY = std::min(maxY, int(g_Viewport.xc_height)); + int bottom = minY + maxY + 2 & ~1; + if (bottom <= mViewport.mTop) { + return CClippedScreenRect(); + } + top = std::max(top, mViewport.mTop) & ~1; + bottom = std::min(bottom, mViewport.mTop + mViewport.mHeight) + 1 & ~1; - int width = maxX2 - minX2; - int height = maxY2 - minY2; - return {true, - minX2, - minY2, - width, - height, - width, - minX2 / float(g_Viewport.x8_width), - maxX2 / float(g_Viewport.x8_width), - 1.f - maxY2 / float(g_Viewport.xc_height), - 1.f - minY2 / float(g_Viewport.xc_height)}; + float minV = static_cast(minY - top) / static_cast(bottom - top); + float maxV = static_cast(maxY + (minY - top) + 1) / static_cast(bottom - top); + + int texAlign = 4; + switch (fmt) { + case ETexelFormat::I8: + texAlign = 8; + break; + case ETexelFormat::IA8: + case ETexelFormat::RGB565: + case ETexelFormat::RGB5A3: + texAlign = 4; + break; + case ETexelFormat::RGBA8: + texAlign = 2; + break; + } + + int texWidth = texAlign + (right - left) - 1 & ~(texAlign - 1); + float minU = static_cast(minX - left) / static_cast(texWidth); + float maxU = static_cast(maxX + (minX - left) + 1) / static_cast(texWidth); + return CClippedScreenRect(left, top, right - left, bottom - top, texWidth, minU, maxU, minV, maxV); } void CGraphics::SetViewportResolution(const zeus::CVector2i& res) { - g_Viewport.x8_width = res.x; - g_Viewport.xc_height = res.y; - g_CroppedViewport = SClipScreenRect(); - g_CroppedViewport.xc_width = res.x; - g_CroppedViewport.x10_height = res.y; - g_Viewport.x10_halfWidth = res.x / 2.f; - g_Viewport.x14_halfHeight = res.y / 2.f; - g_Viewport.aspect = res.x / float(res.y); + mRenderModeObj.fbWidth = res.x; + mRenderModeObj.efbHeight = res.y; + mRenderModeObj.xfbHeight = res.y; + SetViewport(0, 0, res.x, res.y); if (g_GuiSys) g_GuiSys->OnViewportResize(); } -static zeus::CRectangle CachedVP; -zeus::CVector2f CGraphics::g_CachedDepthRange = {0.f, 1.f}; - -void CGraphics::SetViewport(int leftOff, int bottomOff, int width, int height) { - CachedVP.position[0] = leftOff; - CachedVP.position[1] = bottomOff; - CachedVP.size[0] = width; - CachedVP.size[1] = height; - GXSetViewport(CachedVP.position[0], CachedVP.position[1], CachedVP.size[0], CachedVP.size[1], g_CachedDepthRange[0], - g_CachedDepthRange[1]); +void CGraphics::SetViewport(int left, int bottom, int width, int height) { + mViewport.mLeft = left; + mViewport.mTop = mRenderModeObj.efbHeight - (bottom + height); + mViewport.mWidth = width; + mViewport.mHeight = height; + mViewport.mHalfWidth = static_cast(width / 2); + mViewport.mHalfHeight = static_cast(height / 2); + GXSetViewport(static_cast(mViewport.mLeft), static_cast(mViewport.mTop), + static_cast(mViewport.mWidth), static_cast(mViewport.mHeight), mDepthNear, mDepthFar); } -void CGraphics::SetScissor(int leftOff, int bottomOff, int width, int height) { - GXSetScissor(leftOff, bottomOff, width, height); +void CGraphics::SetScissor(int left, int bottom, int width, int height) { + GXSetScissor(left, mRenderModeObj.efbHeight - (bottom + height), width, height); } -void CGraphics::SetDepthRange(float znear, float zfar) { - g_CachedDepthRange[0] = znear; - g_CachedDepthRange[1] = zfar; - GXSetViewport(CachedVP.position[0], CachedVP.position[1], CachedVP.size[0], CachedVP.size[1], g_CachedDepthRange[0], - g_CachedDepthRange[1]); +void CGraphics::SetDepthRange(float near, float far) { + mDepthNear = near; + mDepthFar = far; + GXSetViewport(static_cast(mViewport.mLeft), static_cast(mViewport.mTop), + static_cast(mViewport.mWidth), static_cast(mViewport.mHeight), mDepthNear, mDepthFar); } -CTimeProvider* CGraphics::g_ExternalTimeProvider = nullptr; -float CGraphics::g_DefaultSeconds = 0.f; -u32 CGraphics::g_RenderTimings = 0; - float CGraphics::GetSecondsMod900() { - if (!g_ExternalTimeProvider) - return g_DefaultSeconds; - return g_ExternalTimeProvider->x0_currentTime; + if (mpExternalTimeProvider != nullptr) { + return mpExternalTimeProvider->GetSecondsMod900(); + } + return mSecondsMod900; } void CGraphics::TickRenderTimings() { OPTICK_EVENT(); - g_RenderTimings = (g_RenderTimings + 1) % u32(900 * 60); - g_DefaultSeconds = g_RenderTimings / 60.f; + mRenderTimings = (mRenderTimings + 1) % (900 * 60); + mSecondsMod900 = static_cast(mRenderTimings) / 60.f; } -static constexpr u64 FPS_REFRESH_RATE = 1000; -void CGraphics::UpdateFPSCounter() { - ++g_FramesPast; - - std::chrono::duration timeElapsed = frame_clock::now() - g_FrameStartTime; - if (timeElapsed.count() > FPS_REFRESH_RATE) { - g_Framerate = g_FramesPast; - g_FrameStartTime = frame_clock::now(); - g_FramesPast = 0; - } +void CGraphics::SetUseVideoFilter(bool b) { + mUseVideoFilter = b; + GXSetCopyFilter(mRenderModeObj.aa, mRenderModeObj.sample_pattern, b ? GX_ENABLE : GX_DISABLE, mRenderModeObj.vfilter); } -static bool g_UseVideoFilter = false; -void CGraphics::SetUseVideoFilter(bool filter) { - g_UseVideoFilter = filter; - // GXSetCopyFilter(CGraphics::mRenderModeObj.aa, CGraphics::mRenderModeObj.sample_pattern, filter, - // CGraphics::mRenderModeObj.vfilter); +void CGraphics::SetClearColor(const CColor& color) { + mClearColor = color; + GXSetCopyClear(to_gx_color(color), mClearDepthValue); } -void CGraphics::SetClearColor(const zeus::CColor& color) { - g_ClearColor = color; - GXSetCopyClear(to_gx_color(color), g_ClearDepthValue); +void CGraphics::SetCopyClear(const CColor& color, float depth) { + mClearColor = color; + mClearDepthValue = static_cast(depth * GX_MAX_Z24); + GXSetCopyClear(to_gx_color(color), mClearDepthValue); } -void CGraphics::SetCopyClear(const zeus::CColor& color, float depth) { - g_ClearColor = color; - g_ClearDepthValue = depth; // 1.6777215E7 * depth; Metroid Prime needed this to convert float [0,1] depth into 24 bit - // range, we no longer have this requirement - GXSetCopyClear(to_gx_color(g_ClearColor), g_ClearDepthValue); -} - -void CGraphics::SetIsBeginSceneClearFb(bool clear) { g_IsBeginSceneClearFb = clear; } +void CGraphics::SetIsBeginSceneClearFb(bool b) { mIsBeginSceneClearFb = b; } void CGraphics::SetTevOp(ERglTevStage stage, const CTevCombiners::CTevPass& pass) { CTevCombiners::SetupPass(stage, pass); } -void CGraphics::StreamBegin(GXPrimitive primitive) { - // Originally ResetVertexDataStream(true); - sQueuedVertices.clear(); - sQueuedVertices.emplace_back(sQueuedColor); - sVerticesCount = 0; - // End - sStreamFlags = 2; - sStreamPrimitive = primitive; +#define STREAM_PRIM_BUFFER_SIZE 240 + +static std::array sVtxBuffer; +static std::array sNrmBuffer; +static std::array sTxt0Buffer; +static std::array sTxt1Buffer; +static std::array sClrBuffer; + +static const uchar kHasNormals = 1; +static const uchar kHasColor = 2; +static const uchar kHasTexture = 4; + +void CGraphics::StreamBegin(ERglPrimitive primitive) { + vtxBuffer = sVtxBuffer.data(); + nrmBuffer = sNrmBuffer.data(); + txtBuffer0 = sTxt0Buffer.data(); + txtBuffer1 = sTxt1Buffer.data(); + clrBuffer = sClrBuffer.data(); + ResetVertexDataStream(true); + mCurrentPrimitive = primitive; + vtxDescr.streamFlags = kHasColor; } void CGraphics::StreamNormal(const zeus::CVector3f& nrm) { - sQueuedVertices.back().normal = nrm; - sStreamFlags |= 1; + vtxDescr.nrm.x = nrm.x(); + vtxDescr.nrm.y = nrm.y(); + vtxDescr.nrm.z = nrm.z(); + vtxDescr.streamFlags |= kHasNormals; } void CGraphics::StreamColor(const zeus::CColor& color) { - if (sStreamFlags) { - sQueuedVertices.back().color = color; - } else { - sQueuedColor = color; - } - sStreamFlags |= 2; + vtxDescr.color = color.toRGBA(); + vtxDescr.streamFlags |= kHasColor; } void CGraphics::StreamTexcoord(const zeus::CVector2f& uv) { - sQueuedVertices.back().texCoord = uv; - sStreamFlags |= 4; + vtxDescr.uv0.x = uv.x(); + vtxDescr.uv0.y = uv.y(); + vtxDescr.streamFlags |= kHasTexture; + vtxDescr.textureUsed |= 1; } void CGraphics::StreamVertex(const zeus::CVector3f& pos) { - sQueuedVertices.back().vertex = pos; + vtxDescr.vtx.x = pos.x(); + vtxDescr.vtx.y = pos.y(); + vtxDescr.vtx.z = pos.z(); UpdateVertexDataStream(); } void CGraphics::StreamEnd() { - if (sVerticesCount != 0) { + if (mNumPrimitives != 0) { FlushStream(); } - sStreamFlags = {}; + vtxBuffer = nullptr; + vtxDescr.streamFlags = 0; + vtxDescr.textureUsed = 0; + nrmBuffer = nullptr; + txtBuffer0 = nullptr; + txtBuffer1 = nullptr; + clrBuffer = nullptr; +} + +void CGraphics::SetLineWidth(float w, ERglTexOffset offs) { + CGX::SetLineWidth(static_cast(w * 6.f), static_cast(offs)); } void CGraphics::UpdateVertexDataStream() { - ++sVerticesCount; - if (sVerticesCount == 240) { + ++mNumPrimitives; + mpVtxBuffer->x = vtxDescr.vtx.x; + mpVtxBuffer->y = vtxDescr.vtx.y; + mpVtxBuffer->z = vtxDescr.vtx.z; + ++mpVtxBuffer; + if ((vtxDescr.streamFlags & kHasNormals) != 0) { + mpNrmBuffer->x = vtxDescr.nrm.x; + mpNrmBuffer->y = vtxDescr.nrm.y; + mpNrmBuffer->z = vtxDescr.nrm.z; + ++mpNrmBuffer; + } + if ((vtxDescr.streamFlags & kHasTexture) != 0) { + mpTxtBuffer0->x = vtxDescr.uv0.x; + mpTxtBuffer0->y = vtxDescr.uv0.y; + ++mpTxtBuffer0; + + mpTxtBuffer1->x = vtxDescr.uv1.x; + mpTxtBuffer1->y = vtxDescr.uv1.y; + ++mpTxtBuffer1; + } + if ((vtxDescr.streamFlags & kHasColor) != 0) { + *mpClrBuffer = vtxDescr.color; + ++mpClrBuffer; + } + mJustReset = 0; + if (mNumPrimitives == STREAM_PRIM_BUFFER_SIZE) { FlushStream(); ResetVertexDataStream(false); - } else { - sQueuedVertices.emplace_back(sQueuedVertices.back()); } } void CGraphics::FlushStream() { - std::array vtxDescList{}; - size_t idx = 0; - vtxDescList[idx++] = {GX_VA_POS, GX_DIRECT}; - if (sStreamFlags & 1) { - vtxDescList[idx++] = {GX_VA_NRM, GX_DIRECT}; + GXVtxDescList vtxDesc[10]; + + GXVtxDescList* curDesc = vtxDesc; + const GXVtxDescList vtxDescPos = {GX_VA_POS, GX_DIRECT}; + *curDesc++ = vtxDescPos; + + if ((vtxDescr.streamFlags & kHasNormals) != 0) { + const GXVtxDescList vtxDescNrm = {GX_VA_NRM, GX_DIRECT}; + *curDesc++ = vtxDescNrm; } - if (sStreamFlags & 2) { - vtxDescList[idx++] = {GX_VA_CLR0, GX_DIRECT}; + + if ((vtxDescr.streamFlags & kHasColor) != 0) { + const GXVtxDescList vtxDescClr0 = {GX_VA_CLR0, GX_DIRECT}; + *curDesc++ = vtxDescClr0; } - if (sStreamFlags & 4) { - vtxDescList[idx++] = {GX_VA_TEX0, GX_DIRECT}; + + if ((vtxDescr.streamFlags & kHasTexture) != 0) { + const GXVtxDescList vtxDescTex0 = {GX_VA_TEX0, GX_DIRECT}; + *curDesc++ = vtxDescTex0; } - vtxDescList[idx] = {GX_VA_NULL, GX_NONE}; - CGX::SetVtxDescv(vtxDescList.data()); - SetTevStates(sStreamFlags); + + const GXVtxDescList vtxDescNull = {GX_VA_NULL, GX_NONE}; + *curDesc = vtxDescNull; + + CGX::SetVtxDescv(vtxDesc); + SetTevStates(vtxDescr.streamFlags); FullRender(); } void CGraphics::FullRender() { - CGX::Begin(sStreamPrimitive, GX_VTXFMT0, sVerticesCount); - for (size_t i = 0; i < sVerticesCount; ++i) { - const auto& item = sQueuedVertices[i]; - GXPosition3f32(item.vertex); - if (sStreamFlags & 1) { - GXNormal3f32(item.normal); + CGX::Begin(static_cast(mCurrentPrimitive), GX_VTXFMT0, mNumPrimitives); + switch (vtxDescr.streamFlags) { + case 0: + for (int i = 0; i < mNumPrimitives; i++) { + const Vec& vtx = vtxBuffer[i]; + GXPosition3f32(vtx.x, vtx.y, vtx.z); } - if (sStreamFlags & 2) { - GXColor4f32(item.color); + break; + case kHasNormals: + for (int i = 0; i < mNumPrimitives; i++) { + const Vec& vtx = vtxBuffer[i]; + GXPosition3f32(vtx.x, vtx.y, vtx.z); + const Vec& nrm = nrmBuffer[i]; + GXNormal3f32(nrm.x, nrm.y, nrm.z); } - if (sStreamFlags & 4) { - GXTexCoord2f32(item.texCoord); + break; + case kHasColor: + for (int i = 0; i < mNumPrimitives; i++) { + const Vec& vtx = vtxBuffer[i]; + GXPosition3f32(vtx.x, vtx.y, vtx.z); + GXColor1u32(clrBuffer[i]); } + break; + case kHasTexture: + for (int i = 0; i < mNumPrimitives; i++) { + const Vec& vtx = vtxBuffer[i]; + GXPosition3f32(vtx.x, vtx.y, vtx.z); + const Vec2& uv = txtBuffer0[i]; + GXTexCoord2f32(uv.x, uv.y); + } + break; + case kHasNormals | kHasTexture: + for (int i = 0; i < mNumPrimitives; i++) { + const Vec& vtx = vtxBuffer[i]; + GXPosition3f32(vtx.x, vtx.y, vtx.z); + const Vec& nrm = nrmBuffer[i]; + GXNormal3f32(nrm.x, nrm.y, nrm.z); + const Vec2& uv = txtBuffer0[i]; + GXTexCoord2f32(uv.x, uv.y); + } + break; + case kHasNormals | kHasColor: + for (int i = 0; i < mNumPrimitives; i++) { + const Vec& vtx = vtxBuffer[i]; + GXPosition3f32(vtx.x, vtx.y, vtx.z); + const Vec& nrm = nrmBuffer[i]; + GXNormal3f32(nrm.x, nrm.y, nrm.z); + GXColor1u32(clrBuffer[i]); + } + break; + case kHasColor | kHasTexture: + for (int i = 0; i < mNumPrimitives; i++) { + const Vec& vtx = vtxBuffer[i]; + GXPosition3f32(vtx.x, vtx.y, vtx.z); + GXColor1u32(clrBuffer[i]); + const Vec2& uv = txtBuffer0[i]; + GXTexCoord2f32(uv.x, uv.y); + } + break; + case kHasNormals | kHasColor | kHasTexture: + for (int i = 0; i < mNumPrimitives; i++) { + const Vec& vtx = vtxBuffer[i]; + GXPosition3f32(vtx.x, vtx.y, vtx.z); + const Vec& nrm = nrmBuffer[i]; + GXNormal3f32(nrm.x, nrm.y, nrm.z); + GXColor1u32(clrBuffer[i]); + const Vec2& uv = txtBuffer0[i]; + GXTexCoord2f32(uv.x, uv.y); + } + break; } CGX::End(); } -void CGraphics::ResetVertexDataStream(bool end) { - if (end) { - sQueuedVertices.clear(); - } else { - const auto lastVertex = sQueuedVertices.back(); - sQueuedVertices.clear(); - sQueuedVertices.emplace_back(lastVertex); +void CGraphics::ResetVertexDataStream(bool initial) { + mpVtxBuffer = vtxBuffer; + mpNrmBuffer = nrmBuffer; + mpTxtBuffer0 = txtBuffer0; + mpTxtBuffer1 = txtBuffer1; + mpClrBuffer = clrBuffer; + mNumPrimitives = 0; + + if (initial) { + return; } - sVerticesCount = 0; - if (!end) { - // TODO something with triangle fans + + switch (mCurrentPrimitive) { + case ERglPrimitive::TriangleFan: + mpVtxBuffer = vtxBuffer + 1; + memcpy(mpVtxBuffer, &vtxDescr.vtx, sizeof(Vec)); + ++mpVtxBuffer; + + if ((vtxDescr.streamFlags & kHasNormals) != 0) { + ++mpNrmBuffer; + memcpy(mpNrmBuffer, &vtxDescr.nrm, sizeof(Vec)); + ++mpNrmBuffer; + } + + if ((vtxDescr.streamFlags & kHasTexture) != 0) { + ++mpTxtBuffer0; + memcpy(mpTxtBuffer0, &vtxDescr.uv0, sizeof(Vec2)); + ++mpTxtBuffer0; + + ++mpTxtBuffer1; + memcpy(mpTxtBuffer1, &vtxDescr.uv1, sizeof(Vec2)); + ++mpTxtBuffer1; + } + + if ((vtxDescr.streamFlags & kHasColor) != 0) { + ++mpClrBuffer; + *mpClrBuffer = vtxDescr.color; + ++mpClrBuffer; + } + + mNumPrimitives += 2; + break; + + default: + break; } + + mJustReset = 1; } -void CGraphics::DrawPrimitive(GXPrimitive primitive, const zeus::CVector3f* pos, const zeus::CVector3f& normal, +void CGraphics::DrawPrimitive(ERglPrimitive primitive, const zeus::CVector3f* pos, const zeus::CVector3f& normal, const zeus::CColor& col, s32 numVerts) { StreamBegin(primitive); - StreamColor(col); StreamNormal(normal); + StreamColor(col); for (u32 i = 0; i < numVerts; ++i) { StreamVertex(pos[i]); } @@ -667,71 +917,145 @@ void CGraphics::DrawPrimitive(GXPrimitive primitive, const zeus::CVector3f* pos, } void CGraphics::SetTevStates(u32 flags) noexcept { - if (flags & 4 /* fHasTexture */) { - CGX::SetNumTexGens(1); // sTextureUsed & 3? - CGX::SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0); - CGX::SetTevOrder(GX_TEVSTAGE1, GX_TEXCOORD1, GX_TEXMAP1, GX_COLOR0A0); - } else { + switch (flags) { + case 0: + case kHasNormals: + case kHasColor: + case kHasNormals | kHasColor: + CGX::SetNumChans(1); CGX::SetNumTexGens(0); CGX::SetNumTevStages(1); CGX::SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR0A0); CGX::SetTevOrder(GX_TEVSTAGE1, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR0A0); + break; + case kHasTexture: + case kHasNormals | kHasTexture: + case kHasColor | kHasTexture: + case kHasNormals | kHasColor | kHasTexture: + CGX::SetNumChans(1); + if ((vtxDescr.textureUsed & 3) != 0) { + CGX::SetNumTexGens(2); + } else { + CGX::SetNumTexGens(1); + } + CGX::SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0); + CGX::SetTevOrder(GX_TEVSTAGE1, GX_TEXCOORD1, GX_TEXMAP1, GX_COLOR0A0); + break; } - CGX::SetNumChans(1); CGX::SetNumIndStages(0); CGX::SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY, false, GX_PTIDENTITY); CGX::SetTexCoordGen(GX_TEXCOORD1, GX_TG_MTX2x4, GX_TG_TEX1, GX_IDENTITY, false, GX_PTIDENTITY); - const bool hasLights = g_LightActive.any(); - CGX::SetChanCtrl(CGX::EChannelId::Channel0, hasLights, GX_SRC_REG, - flags & 2 /* fHasColor */ ? GX_SRC_VTX : GX_SRC_REG, g_LightActive, - hasLights ? GX_DF_CLAMP : GX_DF_NONE, hasLights ? GX_AF_SPOT : GX_AF_NONE); - CGX::FlushState(); // normally would be handled in FullRender TODO + + GX::LightMask light = mLightActive; + GXAttnFn attnFn = GX_AF_NONE; + if (light.any()) { + attnFn = GX_AF_SPOT; + } + GXDiffuseFn diffFn = GX_DF_NONE; + if (light.any()) { + diffFn = GX_DF_CLAMP; + } + CGX::SetChanCtrl(CGX::EChannelId::Channel0, light.any() ? GX_ENABLE : GX_DISABLE, GX_SRC_REG, + (flags & kHasColor) ? GX_SRC_VTX : GX_SRC_REG, light, diffFn, attnFn); } -void CGraphics::Startup() { - // Setup GXFifo +bool CGraphics::Startup() { + // mpFifo = fifoBase; + // mpFifoObj = GXInit(fifoBase, fifoSize); + mpFifoObj = GXInit(nullptr, 0); + // GXFifoObj fifoObj; + // GXInitFifoBase(&fifoObj, mpFifo, fifoSize); + // GXSetCPUFifo(&fifoObj); + // GXSetGPFifo(&fifoObj); + // GXInitFifoLimits(mpFifoObj, fifoSize - 0x4000, fifoSize - 0x10000); + // GXSetCPUFifo(mpFifoObj); + // GXSetGPFifo(mpFifoObj); + // GXSetMisc(GX_MT_XF_FLUSH, 8); + GXSetDither(GX_FALSE); CGX::ResetGXStates(); InitGraphicsVariables(); - // ConfigureFrameBuffer(...); - InitGraphicsDefaults(); - // GXInitTexCacheRegion - // GXSetTexRegionCallback + ConfigureFrameBuffer(/*osContext*/); + // for (int i = 0; i < ARRAY_SIZE(mTexRegions); i++) { + // GXInitTexCacheRegion(&mTexRegions[i], false, 0x8000 * i, GX_TEXCACHE_32K, 0x80000 + (0x8000 * i), + // GX_TEXCACHE_32K); + // } + // for (int i = 0; i < ARRAY_SIZE(mTexRegionsCI); i++) { + // GXInitTexCacheRegion(&mTexRegionsCI[i], false, (8 + (2 * i)) << 0xF, GX_TEXCACHE_32K, (9 + (2 * i)) << 0xF, + // GX_TEXCACHE_32K); + // } + // mGXDefaultTexRegionCallback = GXSetTexRegionCallback(TexRegionCallback); + mSpareBufferSize = sSpareFrameBuffer.size(); + mpSpareBuffer = sSpareFrameBuffer.data(); + mSpareBufferTexCacheSize = 0x10000; + return true; } +#define ARRAY_SIZE(arr) static_cast(sizeof(arr) / sizeof(arr[0])) + void CGraphics::InitGraphicsVariables() { - g_LightTypes.fill(ELightType::Directional); - g_LightActive = {}; - SetDepthWriteMode(false, g_depthFunc, false); + for (int i = 0; i < ARRAY_SIZE(mLightTypes); ++i) { + mLightTypes[i] = ELightType::Directional; + } + mLightActive = 0; + SetDepthWriteMode(false, mDepthFunc, false); SetCullMode(ERglCullMode::None); - SetAmbientColor(zeus::CColor{0.2f, 1.f}); - g_IsGXModelMatrixIdentity = false; - // SetIdentityViewPointMatrix(); - // SetIdentityModelMatrix(); - SetViewport(0, 0, g_Viewport.x8_width, g_Viewport.xc_height); - SetPerspective(60.f, g_Viewport.x8_width / g_Viewport.xc_height, g_Proj.x14_near, g_Proj.x18_far); - SetCopyClear(g_ClearColor, 1.f); - CGX::SetChanMatColor(CGX::EChannelId::Channel0, zeus::skWhite); - // g_RenderState.ResetFlushAll(); + SetAmbientColor(CColor(0.2f, 0.2f, 0.2f, 1.f)); + mIsGXModelMatrixIdentity = false; + SetIdentityViewPointMatrix(); + SetIdentityModelMatrix(); + SetViewport(0, 0, mViewport.mWidth, mViewport.mHeight); + SetPerspective(60.f, static_cast(mViewport.mWidth) / static_cast(mViewport.mHeight), mProj.GetNear(), + mProj.GetFar()); + SetCopyClear(mClearColor, 1.f); + constexpr GXColor white = {0xFF, 0xFF, 0xFF, 0xFF}; + CGX::SetChanMatColor(CGX::EChannelId::Channel0, white); + sRenderState.ResetFlushAll(); } void CGraphics::InitGraphicsDefaults() { SetDepthRange(0.f, 1.f); - g_IsGXModelMatrixIdentity = false; - SetModelMatrix(g_GXModelMatrix); - SetViewPointMatrix(g_GXModelView); - SetDepthWriteMode(false, g_depthFunc, false); - SetCullMode(g_cullMode); - SetViewport(g_Viewport.x0_left, g_Viewport.x4_top, g_Viewport.x8_width, g_Viewport.xc_height); + mIsGXModelMatrixIdentity = false; + SetModelMatrix(mModelMatrix); + SetViewPointMatrix(mViewMatrix); + SetDepthWriteMode(false, mDepthFunc, false); + SetCullMode(mCullMode); + SetViewport(mViewport.mLeft, mViewport.mTop, mViewport.mWidth, mViewport.mHeight); FlushProjection(); CTevCombiners::Init(); DisableAllLights(); SetDefaultVtxAttrFmt(); } -void CGraphics::SetDefaultVtxAttrFmt() { - // Unneeded, all attributes are expected to be full floats - // Left here for reference +void CGraphics::ConfigureFrameBuffer(/*const COsContext& osContext*/) { + // mRenderModeObj = osContext.GetRenderModeObj(); + // mpFrameBuf1 = osContext.GetFramebuf1(); + // mpFrameBuf2 = osContext.GetFramebuf2(); + // VIConfigure(&mRenderModeObj); + // VISetNextFrameBuffer(mpFrameBuf1); + mpCurrenFrameBuf = mpFrameBuf2; + GXSetViewport(0.f, 0.f, static_cast(mRenderModeObj.fbWidth), static_cast(mRenderModeObj.efbHeight), 0.f, + 1.f); + GXSetScissor(0, 0, mRenderModeObj.fbWidth, mRenderModeObj.efbHeight); + GXSetDispCopySrc(0, 0, mRenderModeObj.fbWidth, mRenderModeObj.efbHeight); + GXSetDispCopyDst(mRenderModeObj.fbWidth, mRenderModeObj.efbHeight); + GXSetDispCopyYScale(static_cast(mRenderModeObj.xfbHeight) / static_cast(mRenderModeObj.efbHeight)); + GXSetCopyFilter(mRenderModeObj.aa, mRenderModeObj.sample_pattern, GX_ENABLE, mRenderModeObj.vfilter); + if (mRenderModeObj.aa) { + GXSetPixelFmt(GX_PF_RGB565_Z16, GX_ZC_LINEAR); + } else { + GXSetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR); + } + GXSetDispCopyGamma(GX_GM_1_0); + GXCopyDisp(mpCurrenFrameBuf, true); + VIFlush(); + // VIWaitForRetrace(); + // VIWaitForRetrace(); + mViewport.mWidth = mRenderModeObj.fbWidth; + mViewport.mHeight = mRenderModeObj.efbHeight; + InitGraphicsDefaults(); +} +void CGraphics::SetDefaultVtxAttrFmt() { GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0); GXSetVtxAttrFmt(GX_VTXFMT1, GX_VA_POS, GX_POS_XYZ, GX_F32, 0); GXSetVtxAttrFmt(GX_VTXFMT2, GX_VA_POS, GX_POS_XYZ, GX_F32, 0); @@ -744,51 +1068,73 @@ void CGraphics::SetDefaultVtxAttrFmt() { GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0); GXSetVtxAttrFmt(GX_VTXFMT1, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0); GXSetVtxAttrFmt(GX_VTXFMT2, GX_VA_TEX0, GX_TEX_ST, GX_U16, 15); - for (GXAttr attr = GX_VA_TEX1; attr <= GX_VA_TEX7; attr = GXAttr(attr + 1)) { + for (int i = 1; i <= 7; ++i) { + GXAttr attr = static_cast(GX_VA_TEX0 + i); GXSetVtxAttrFmt(GX_VTXFMT0, attr, GX_TEX_ST, GX_F32, 0); GXSetVtxAttrFmt(GX_VTXFMT1, attr, GX_TEX_ST, GX_F32, 0); GXSetVtxAttrFmt(GX_VTXFMT2, attr, GX_TEX_ST, GX_F32, 0); } } -void CGraphics::ResetGfxStates() noexcept { - // sRenderState.x0_ = 0; -} +void CGraphics::ResetGfxStates() noexcept { sRenderState.Set(0); } -void CGraphics::LoadDolphinSpareTexture(int width, int height, GXTexFmt format, void* data, GXTexMapID id) { - void* ptr = static_cast(sSpareTextureData); - if (data != nullptr) { - ptr = data; - } - GXTexObj obj; - GXInitTexObj(&obj, ptr, width, height, format, GX_CLAMP, GX_CLAMP, false); - GXInitTexObjLOD(&obj, GX_NEAR, GX_NEAR, 0.0, 0.0, 0.0, false, false, GX_ANISO_1); - GXLoadTexObj(&obj, id); - // CTexture::InvalidateTexmap(id); - if (id == GX_TEXMAP7) { - // GXInvalidateTexRegion(...); - } +void CGraphics::LoadDolphinSpareTexture(int width, int height, GXTexFmt fmt, void* data, GXTexMapID texId) { + GXTexObj texObj; + GXInitTexObj(&texObj, data != nullptr ? data : mpSpareBuffer, width, height, fmt, GX_CLAMP, GX_CLAMP, GX_DISABLE); + GXInitTexObjLOD(&texObj, GX_NEAR, GX_NEAR, 0.f, 0.f, 0.f, GX_DISABLE, GX_DISABLE, GX_ANISO_1); + GXLoadTexObj(&texObj, texId); + // CTexture::InvalidateTexmap(texId); + // if (texId == GX_TEXMAP7) { + // GXInvalidateTexRegion(&mTexRegions[0]); + // } #ifdef AURORA - GXDestroyTexObj(&obj); + GXDestroyTexObj(&texObj); #endif } -void CGraphics::LoadDolphinSpareTexture(int width, int height, GXCITexFmt format, GXTlut tlut, void* data, - GXTexMapID id) { - void* ptr = static_cast(sSpareTextureData); - if (data != nullptr) { - ptr = data; - } - GXTexObj obj; - GXInitTexObjCI(&obj, ptr, width, height, format, GX_CLAMP, GX_CLAMP, false, tlut); - GXInitTexObjLOD(&obj, GX_NEAR, GX_NEAR, 0.0, 0.0, 0.0, false, false, GX_ANISO_1); - GXLoadTexObj(&obj, id); - // CTexture::InvalidateTexmap(id); - if (id == GX_TEXMAP7) { - // GXInvalidateTexRegion(...); - } +void CGraphics::LoadDolphinSpareTexture(int width, int height, GXCITexFmt fmt, GXTlut tlut, void* data, + GXTexMapID texId) { + GXTexObj texObj; + GXInitTexObjCI(&texObj, data != nullptr ? data : mpSpareBuffer, width, height, fmt, GX_CLAMP, GX_CLAMP, GX_DISABLE, + tlut); + GXInitTexObjLOD(&texObj, GX_NEAR, GX_NEAR, 0.f, 0.f, 0.f, GX_DISABLE, GX_DISABLE, GX_ANISO_1); + GXLoadTexObj(&texObj, texId); + // CTexture::InvalidateTexmap(texId); + // if (texId == GX_TEXMAP7) { + // GXInvalidateTexRegion(&mTexRegions[0]); + // } #ifdef AURORA - GXDestroyTexObj(&obj); + GXDestroyTexObj(&texObj); #endif } + +CGraphics::CRenderState::CRenderState() { + x0_ = 0; + x4_ = 0; +} + +void CGraphics::CRenderState::Flush() {} + +int CGraphics::CRenderState::SetVtxState(const float* pos, const float* nrm, const uint* clr) { + // CGX::SetArray(GX_VA_POS, pos, 12); + // CGX::SetArray(GX_VA_NRM, nrm, 12); + // CGX::SetArray(GX_VA_CLR0, clr, 4); + int result = 1; + if (nrm != nullptr) { + result |= 2; + } + if (clr != nullptr) { + result |= 16; + } + return result; +} + +void CGraphics::CRenderState::ResetFlushAll() { + x0_ = 0; + SetVtxState(nullptr, nullptr, nullptr); + for (int i = 0; i < 8; i++) { + CGX::SetArray(static_cast(GX_VA_TEX0 + i), std::span{}); + } + Flush(); +} } // namespace metaforce diff --git a/Runtime/Graphics/CGraphics.hpp b/Runtime/Graphics/CGraphics.hpp index 433a1f1ef..179ec7b11 100644 --- a/Runtime/Graphics/CGraphics.hpp +++ b/Runtime/Graphics/CGraphics.hpp @@ -2,12 +2,11 @@ #include "Runtime/ConsoleVariables/CVar.hpp" #include "Runtime/Graphics/CLight.hpp" +#include "Runtime/Graphics/CTexture.hpp" #include "Runtime/Graphics/CTevCombiners.hpp" #include "Runtime/Graphics/GX.hpp" #include "Runtime/RetroTypes.hpp" -#include -#include #include #include @@ -17,8 +16,7 @@ #include #include - -using frame_clock = std::chrono::high_resolution_clock; +#include namespace metaforce { class CTexture; @@ -102,6 +100,16 @@ enum class ERglEnum : std::underlying_type_t { Always = GX_ALWAYS, }; +enum class ERglPrimitive : std::underlying_type_t { + Quads = GX_QUADS, + Triangles = GX_TRIANGLES, + TriangleStrip = GX_TRIANGLESTRIP, + TriangleFan = GX_TRIANGLEFAN, + Lines = GX_LINES, + LineStrip = GX_LINESTRIP, + Points = GX_POINTS, +}; + using ERglLight = u8; enum class ERglTexOffset : std::underlying_type_t { @@ -129,49 +137,20 @@ enum class ERglFogMode : std::underlying_type_t { OrthoRevExp2 = GX_FOG_ORTHO_REVEXP2, }; -struct SViewport { - u32 x0_left; - u32 x4_top; - u32 x8_width; - u32 xc_height; - float x10_halfWidth; - float x14_halfHeight; - float aspect; +struct CViewport { + int mLeft; + int mTop; + int mWidth; + int mHeight; + float mHalfWidth; + float mHalfHeight; }; -struct SClipScreenRect { - bool x0_valid = false; - int x4_left = 0; - int x8_top = 0; - int xc_width = 0; - int x10_height = 0; - int x14_dstWidth = 0; - float x18_uvXMin = 0.f; - float x1c_uvXMax = 0.f; - float x20_uvYMin = 0.f; - float x24_uvYMax = 0.f; - - SClipScreenRect() = default; - SClipScreenRect(bool valid, int left, int top, int width, int height, int dstWidth, float uvXMin, float uvXMax, - float uvYMin, float uvYMax) - : x0_valid(valid) - , x4_left(left) - , x8_top(top) - , xc_width(width) - , x10_height(height) - , x14_dstWidth(dstWidth) - , x18_uvXMin(uvXMin) - , x1c_uvXMax(uvXMax) - , x20_uvYMin(uvYMin) - , x24_uvYMax(uvYMax) {} - - SClipScreenRect(const SViewport& vp) { - x4_left = vp.x0_left; - x8_top = vp.x4_top; - xc_width = vp.x8_width; - x10_height = vp.xc_height; - } -}; +// TODO +typedef struct { + float x; + float y; +} Vec2, *Vec2Ptr; #define DEPTH_FAR 1.f #define DEPTH_SKY 0.999f @@ -184,49 +163,171 @@ struct SClipScreenRect { #define CUBEMAP_RES 256 #define CUBEMAP_MIPS 6 +enum class ETexelFormat; + class CGraphics { public: - struct CProjectionState { + using CVector3f = zeus::CVector3f; + using CTransform4f = zeus::CTransform; + using CColor = zeus::CColor; + using uchar = unsigned char; + using uint = unsigned int; + + class CRenderState { + public: + CRenderState(); + + void Flush(); + void ResetFlushAll(); + int SetVtxState(const float* pos, const float* nrm, const uint* clr); + + // In map this takes two args, but x4 is unused? + void Set(int v0) { x0_ = v0; } + + private: + int x0_; + int x4_; + }; + + class CProjectionState { + public: + CProjectionState(bool persp, float left, float right, float top, float bottom, float near, float far) + : x0_persp(persp), x4_left(left), x8_right(right), xc_top(top), x10_bottom(bottom), x14_near(near), x18_far(far) {} + + bool IsPerspective() const { return x0_persp; } + float GetLeft() const { return x4_left; } + float GetRight() const { return x8_right; } + float GetTop() const { return xc_top; } + float GetBottom() const { return x10_bottom; } + float GetNear() const { return x14_near; } + float GetFar() const { return x18_far; } + + private: bool x0_persp; float x4_left; float x8_right; + // TODO: I think top/bottom are flipped float xc_top; float x10_bottom; float x14_near; float x18_far; }; - static CProjectionState g_Proj; - static zeus::CVector2f g_CachedDepthRange; - // static CFogState g_Fog; - static SViewport g_Viewport; - static float g_ProjAspect; - static u32 g_NumBreakpointsWaiting; - static u32 g_FlippingState; - static bool g_LastFrameUsedAbove; - static bool g_InterruptLastFrameUsedAbove; - static GX::LightMask g_LightActive; - static std::array g_LightObjs; - static std::array g_LightTypes; - static zeus::CTransform g_GXModelView; - static zeus::CTransform g_GXModelViewInvXpose; - static zeus::CTransform g_GXModelMatrix; - static zeus::CTransform g_ViewMatrix; - static zeus::CVector3f g_ViewPoint; - static zeus::CTransform g_GXViewPointMatrix; - static zeus::CTransform g_CameraMatrix; - static SClipScreenRect g_CroppedViewport; - static bool g_IsGXModelMatrixIdentity; - static zeus::CColor g_ClearColor; - static float g_ClearDepthValue; // Was a 24bit value, we use a float range from [0,1] - static bool g_IsBeginSceneClearFb; + class CClippedScreenRect { + public: + CClippedScreenRect() : x0_valid(false) {} + CClippedScreenRect(int x, int y, int width, int height, int texWidth, float minU, float maxU, float minV, + float maxV) + : x0_valid(true) + , x4_x(x) + , x8_y(y) + , xc_width(width) + , x10_height(height) + , x14_texWidth(texWidth) + , x18_minU(minU) + , x1c_maxU(maxU) + , x20_minV(minV) + , x24_maxV(maxV) {} - static ERglEnum g_depthFunc; - static ERglCullMode g_cullMode; + bool IsValid() const { return x0_valid; } + int GetX() const { return x4_x; } + int GetY() const { return x8_y; } + int GetWidth() const { return xc_width; } + int GetHeight() const { return x10_height; } + int GetTexWidth() const { return x14_texWidth; } + float GetMinU() const { return x18_minU; } + float GetMaxU() const { return x1c_maxU; } + float GetMinV() const { return x20_minV; } + float GetMaxV() const { return x24_maxV; } - static void Startup(); + private: + bool x0_valid; + int x4_x; + int x8_y; + int xc_width; + int x10_height; + int x14_texWidth; + float x18_minU; + float x1c_maxU; + float x20_minV; + float x24_maxV; + }; + + static CRenderState sRenderState; + static VecPtr vtxBuffer; + static VecPtr nrmBuffer; + static Vec2Ptr txtBuffer0; + static Vec2Ptr txtBuffer1; + static uint* clrBuffer; + static bool mJustReset; + static ERglCullMode mCullMode; + static int mNumLightsActive; + static float mDepthNear; + static VecPtr mpVtxBuffer; + static VecPtr mpNrmBuffer; + static Vec2Ptr mpTxtBuffer0; + static Vec2Ptr mpTxtBuffer1; + static uint* mpClrBuffer; + static int mNumPrimitives; + static int mFrameCounter; + static float mFramesPerSecond; + static float mLastFramesPerSecond; + static int mNumBreakpointsWaiting; + static int mFlippingState; + static bool mLastFrameUsedAbove; + static bool mInterruptLastFrameUsedAbove; + static GX::LightMask mLightActive; + static GX::LightMask mLightsWereOn; + static void* mpFrameBuf1; + static void* mpFrameBuf2; + static void* mpCurrenFrameBuf; + static int mSpareBufferSize; + static void* mpSpareBuffer; + static int mSpareBufferTexCacheSize; + // static GXTexRegionCallback mGXDefaultTexRegionCallback; + static void* mpFifo; + static GXFifoObj* mpFifoObj; + static uint mRenderTimings; + static float mSecondsMod900; + static CTimeProvider* mpExternalTimeProvider; + static int mScreenStretch; + static int mScreenPositionX; + static int mScreenPositionY; + + static CVector3f kDefaultPositionVector; + static CVector3f kDefaultDirectionVector; + static CProjectionState mProj; + static CTransform4f mViewMatrix; + static CTransform4f mModelMatrix; + static CColor mClearColor; + static CVector3f mViewPoint; + static CViewport mViewport; + static ELightType mLightTypes[8]; + static GXLightObj mLightObj[8]; + // static GXTexRegion mTexRegions[GX_MAX_TEXMAP]; + // static GXTexRegion mTexRegionsCI[GX_MAX_TEXMAP / 2]; + static GXRenderModeObj mRenderModeObj; + static Mtx mGXViewPointMatrix; + static Mtx mGXModelMatrix; + static Mtx mGxModelView; + static Mtx mCameraMtx; + + static bool mIsBeginSceneClearFb; + static ERglEnum mDepthFunc; + static ERglPrimitive mCurrentPrimitive; + static float mDepthFar; + static u32 mClearDepthValue; // = GX_MAX_Z24 + static bool mIsGXModelMatrixIdentity; + static bool mFirstFrame; + static GXBool mUseVideoFilter; + static float mBrightness; + + static const GXTexMapID kSpareBufferTexMapID; + + static bool Startup(); static void InitGraphicsVariables(); static void InitGraphicsDefaults(); + static void ConfigureFrameBuffer(); static void SetDefaultVtxAttrFmt(); static void DisableAllLights(); static void LoadLight(ERglLight light, const CLight& info); @@ -240,10 +341,6 @@ public: static void BeginScene(); static void EndScene(); static void Render2D(CTexture& tex, u32 x, u32 y, u32 w, u32 h, const zeus::CColor& col); - static bool BeginRender2D(const CTexture& tex); - static void DoRender2D(const CTexture& tex, s32 x, s32 y, s32 w1, s32 w2, s32 w3, s32 w4, s32 w5, - const zeus::CColor& col); - static void EndRender2D(bool v); static void SetAlphaCompare(ERglAlphaFunc comp0, u8 ref0, ERglAlphaOp op, ERglAlphaFunc comp1, u8 ref1); static void SetViewPointMatrix(const zeus::CTransform& xf); static void SetViewMatrix(); @@ -256,51 +353,38 @@ public: static void SetOrtho(float left, float right, float top, float bottom, float znear, float zfar); static void FlushProjection(); static zeus::CVector2i ProjectPoint(const zeus::CVector3f& point); - static SClipScreenRect ClipScreenRectFromMS(const zeus::CVector3f& p1, const zeus::CVector3f& p2); - static SClipScreenRect ClipScreenRectFromVS(const zeus::CVector3f& p1, const zeus::CVector3f& p2); + static CClippedScreenRect ClipScreenRectFromVS(const CVector3f& p1, const CVector3f& p2, ETexelFormat fmt); + static CClippedScreenRect ClipScreenRectFromMS(const CVector3f& p1, const CVector3f& p2, ETexelFormat fmt); static void SetViewportResolution(const zeus::CVector2i& res); static void SetViewport(int leftOff, int bottomOff, int width, int height); static void SetScissor(int leftOff, int bottomOff, int width, int height); static void SetDepthRange(float near, float far); + static void SetIdentityViewPointMatrix(); + static void SetIdentityModelMatrix(); + static void ClearBackAndDepthBuffers(); - static CTimeProvider* g_ExternalTimeProvider; - static float g_DefaultSeconds; - static u32 g_RenderTimings; - static void SetExternalTimeProvider(CTimeProvider* provider) { g_ExternalTimeProvider = provider; } + static void SetExternalTimeProvider(CTimeProvider* provider) { mpExternalTimeProvider = provider; } static float GetSecondsMod900(); static void TickRenderTimings(); - static u32 g_FrameCounter; - static u32 g_Framerate; - static u32 g_FramesPast; - static frame_clock::time_point g_FrameStartTime; - static u32 GetFrameCounter() { return g_FrameCounter; } - static u32 GetFPS() { return g_Framerate; } - static void UpdateFPSCounter(); + static int GetFrameCounter() { return mFrameCounter; } + static float GetFPS() { return mFramesPerSecond; } static void SetUseVideoFilter(bool); static void SetClearColor(const zeus::CColor& color); static void SetCopyClear(const zeus::CColor& color, float depth); static void SetIsBeginSceneClearFb(bool clear); - static u32 GetViewportLeft() { return g_Viewport.x0_left; } - static u32 GetViewportTop() { return g_Viewport.x4_top; } - static u32 GetViewportWidth() { return g_Viewport.x8_width; } - static u32 GetViewportHeight() { return g_Viewport.xc_height; } - static float GetViewportHalfWidth() { return g_Viewport.x10_halfWidth; } - static float GetViewportHalfHeight() { return g_Viewport.x14_halfHeight; } - static float GetViewportAspect() { return g_Viewport.aspect; } - static bool IsCroppedViewportValid() { return g_CroppedViewport.x0_valid; } - static int GetCroppedViewportLeft() { return g_CroppedViewport.x4_left; } - static int GetCroppedViewportTop() { return g_CroppedViewport.x8_top; } - static int GetCroppedViewportWidth() { return g_CroppedViewport.xc_width; } - static int GetCroppedViewportHeight() { return g_CroppedViewport.x10_height; } - static float GetCroppedViewportDstWidth() { return g_CroppedViewport.x14_dstWidth; } - static float GetCroppedViewportUVXMin() { return g_CroppedViewport.x18_uvXMin; } - static float GetCroppedViewportUVXMax() { return g_CroppedViewport.x1c_uvXMax; } - static float GetCroppedViewportUVYMin() { return g_CroppedViewport.x20_uvYMin; } - static float GetCroppedViewportUVYMax() { return g_CroppedViewport.x24_uvYMax; } - - static const std::array skCubeBasisMats; - static u8 sSpareTextureData[]; + static u32 GetViewportLeft() { return mViewport.mLeft; } + static u32 GetViewportTop() { return mViewport.mTop; } + static u32 GetViewportWidth() { return mViewport.mWidth; } + static u32 GetViewportHeight() { return mViewport.mHeight; } + static float GetViewportHalfWidth() { return mViewport.mHalfWidth; } + static float GetViewportHalfHeight() { return mViewport.mHalfHeight; } + static float GetViewportAspect() { + return static_cast(mViewport.mWidth) / static_cast(mViewport.mHeight); + } + static const CVector3f& GetViewPoint() { return mViewPoint; } + static const CTransform4f& GetViewMatrix() { return mViewMatrix; } + static const CTransform4f& GetModelMatrix() { return mModelMatrix; } static void LoadDolphinSpareTexture(int width, int height, GXTexFmt format, void* data, GXTexMapID id); static void LoadDolphinSpareTexture(int width, int height, GXCITexFmt format, GXTlut tlut, void* data, GXTexMapID id); @@ -308,7 +392,7 @@ public: static void ResetGfxStates() noexcept; static void SetTevStates(u32 flags) noexcept; static void SetTevOp(ERglTevStage stage, const CTevCombiners::CTevPass& pass); - static void StreamBegin(GXPrimitive primitive); + static void StreamBegin(ERglPrimitive primitive); static void StreamNormal(const zeus::CVector3f& nrm); static void StreamColor(const zeus::CColor& color); static inline void StreamColor(float r, float g, float b, float a) { StreamColor({r, g, b, a}); } @@ -322,7 +406,7 @@ public: static void ResetVertexDataStream(bool end); static void FlushStream(); static void FullRender(); - static void DrawPrimitive(GXPrimitive primitive, const zeus::CVector3f* pos, const zeus::CVector3f& normal, + static void DrawPrimitive(ERglPrimitive primitive, const zeus::CVector3f* pos, const zeus::CVector3f& normal, const zeus::CColor& col, s32 numVerts); static void SetLineWidth(float width, ERglTexOffset offs); }; diff --git a/Runtime/Graphics/CLineRenderer.cpp b/Runtime/Graphics/CLineRenderer.cpp deleted file mode 100644 index 90d4e4ef7..000000000 --- a/Runtime/Graphics/CLineRenderer.cpp +++ /dev/null @@ -1,360 +0,0 @@ -#include "Runtime/Graphics/CLineRenderer.hpp" - -#include "Runtime/Graphics/Shaders/CLineRendererShaders.hpp" -#include "Runtime/Logging.hpp" - -namespace metaforce { -void CLineRenderer::Initialize() { CLineRendererShaders::Initialize(); } - -void CLineRenderer::Shutdown() { - CLineRendererShaders::Shutdown(); -// s_vertPoolTex.doDestroy(); -// s_vertPoolNoTex.doDestroy(); -// s_uniformPool.doDestroy(); -} - -//hecl::VertexBufferPool CLineRenderer::s_vertPoolTex = {}; -//hecl::VertexBufferPool CLineRenderer::s_vertPoolNoTex = {}; -//hecl::UniformBufferPool CLineRenderer::s_uniformPool = {}; - -CLineRenderer::CLineRenderer(EPrimitiveMode mode, u32 maxVerts, u32 texture, - bool additive, bool zTest, bool zGEqual) -: m_mode(mode), m_maxVerts(maxVerts) { - OPTICK_EVENT(); - if (maxVerts < 2) { - spdlog::fatal("maxVerts < 2, maxVerts = {}", maxVerts); - return; - } - m_textured = bool(texture); - - u32 maxTriVerts = 0; - switch (mode) { - case EPrimitiveMode::Lines: - case EPrimitiveMode::LineStrip: - maxTriVerts = maxVerts * 4; - break; - case EPrimitiveMode::LineLoop: - maxTriVerts = maxVerts * 4 + 4; - break; - } - -// if (texture) { -// m_vertBufTex = s_vertPoolTex.allocateBlock(CGraphics::g_BooFactory, maxTriVerts); -// } else { -// m_vertBufNoTex = s_vertPoolNoTex.allocateBlock(CGraphics::g_BooFactory, maxTriVerts); -// } -// -// m_uniformBuf = s_uniformPool.allocateBlock(CGraphics::g_BooFactory); -// -// CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { -// CLineRendererShaders::BuildShaderDataBinding(ctx, *this, texture, additive, zTest, zGEqual); -// return true; -// } BooTrace); -} - -//rstl::reserved_vector CLineRenderer::g_StaticLineVertsTex = {}; -//rstl::reserved_vector CLineRenderer::g_StaticLineVertsNoTex = {}; - -static bool IntersectLines(const zeus::CVector2f& pa1, const zeus::CVector2f& pa2, const zeus::CVector2f& pb1, - const zeus::CVector2f& pb2, zeus::CVector3f& intersect) { - zeus::CVector2f deltaA = pa1 - pa2; - zeus::CVector2f deltaB = pb1 - pb2; - float det = deltaA.cross(deltaB); - if (std::fabs(det) < 0.000001f) - return false; - float c0 = pa1.cross(pa2); - float c1 = pb1.cross(pb2); - intersect = (c0 * (pb1 - pb2) - c1 * (pa1 - pa2)) / det; - return true; -} - -void CLineRenderer::Reset() { - m_nextVert = 0; - m_final = false; -// if (m_textured) -// g_StaticLineVertsTex.clear(); -// else -// g_StaticLineVertsNoTex.clear(); -} - -void CLineRenderer::AddVertex(const zeus::CVector3f& position, const zeus::CColor& color, float width, - const zeus::CVector2f& uv) { - if (m_final /*|| !m_shaderBind[0]*/ || m_nextVert >= m_maxVerts) - return; - - float adjWidth = width / 480.f; - float w = 0.f; - zeus::CVector3f projPt = {}; // CGraphics::ProjectModelPointToViewportSpace(position, w); - - if (m_mode == EPrimitiveMode::LineLoop) { - if (m_nextVert == 0) { - m_firstPos = projPt; - m_firstW = w; - m_secondPos = projPt; - m_firstUV = uv; - m_firstColor = color; - m_firstWidth = adjWidth; - } else if (m_nextVert == 1) { - m_secondPos = projPt; - } - } - - if (m_nextVert > 1) { - zeus::CVector2f dva = (m_lastPos - m_lastPos2).toVec2f(); - if (!dva.canBeNormalized()) - dva = {0.f, 1.f}; - dva = dva.normalized().perpendicularVector() * m_lastWidth; - dva.x() /= CGraphics::g_ProjAspect; - - zeus::CVector2f dvb = (projPt - m_lastPos).toVec2f(); - if (!dvb.canBeNormalized()) - dvb = {0.f, 1.f}; - dvb = dvb.normalized().perpendicularVector() * m_lastWidth; - dvb.x() /= CGraphics::g_ProjAspect; - - if (m_textured) { - if (m_mode == EPrimitiveMode::Lines) { - if (m_nextVert & 1) { -// g_StaticLineVertsTex.push_back(g_StaticLineVertsTex.back()); -// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dvb, m_lastW), m_lastColor, m_lastUV}); -// g_StaticLineVertsTex.push_back(g_StaticLineVertsTex.back()); -// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dvb, m_lastW), m_lastColor, m_lastUV}); - } else { -// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dva, m_lastW), m_lastColor, m_lastUV}); -// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dva, m_lastW), m_lastColor, m_lastUV}); - } - } else { - zeus::CVector3f intersect1; - bool good1 = IntersectLines(m_lastPos2.toVec2f() + dva, m_lastPos.toVec2f() + dva, m_lastPos.toVec2f() + dvb, - projPt.toVec2f() + dvb, intersect1); - if ((intersect1.toVec2f() - m_lastPos.toVec2f()).magnitude() > m_lastWidth * 2.f) - good1 = false; - - zeus::CVector3f intersect2; - bool good2 = IntersectLines(m_lastPos2.toVec2f() - dva, m_lastPos.toVec2f() - dva, m_lastPos.toVec2f() - dvb, - projPt.toVec2f() - dvb, intersect2); - if ((intersect2.toVec2f() - m_lastPos.toVec2f()).magnitude() > m_lastWidth * 2.f) - good2 = false; - - if (good1 && good2) { - intersect1.z() = float(m_lastPos.z()); - intersect2.z() = float(m_lastPos.z()); -// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(intersect1, m_lastW), m_lastColor, m_lastUV}); -// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(intersect2, m_lastW), m_lastColor, m_lastUV}); - } else { -// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dva, m_lastW), m_lastColor, m_lastUV}); -// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dva, m_lastW), m_lastColor, m_lastUV}); -// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dvb, m_lastW), m_lastColor, m_lastUV}); -// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dvb, m_lastW), m_lastColor, m_lastUV}); - } - } - } else { - if (m_mode == EPrimitiveMode::Lines) { - if (m_nextVert & 1) { -// g_StaticLineVertsNoTex.push_back(g_StaticLineVertsNoTex.back()); -// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dvb, m_lastW), m_lastColor}); -// g_StaticLineVertsNoTex.push_back(g_StaticLineVertsNoTex.back()); -// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dvb, m_lastW), m_lastColor}); - } else { -// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dva, m_lastW), m_lastColor}); -// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dva, m_lastW), m_lastColor}); - } - } else { - zeus::CVector3f intersect1; - bool good1 = IntersectLines(m_lastPos2.toVec2f() + dva, m_lastPos.toVec2f() + dva, m_lastPos.toVec2f() + dvb, - projPt.toVec2f() + dvb, intersect1); - if ((intersect1.toVec2f() - m_lastPos.toVec2f()).magnitude() > m_lastWidth * 2.f) - good1 = false; - - zeus::CVector3f intersect2; - bool good2 = IntersectLines(m_lastPos2.toVec2f() - dva, m_lastPos.toVec2f() - dva, m_lastPos.toVec2f() - dvb, - projPt.toVec2f() - dvb, intersect2); - if ((intersect2.toVec2f() - m_lastPos.toVec2f()).magnitude() > m_lastWidth * 2.f) - good2 = false; - - if (good1 && good2) { - intersect1.z() = float(m_lastPos.z()); - intersect2.z() = float(m_lastPos.z()); -// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(intersect1, m_lastW), m_lastColor}); -// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(intersect2, m_lastW), m_lastColor}); - } else { -// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dva, m_lastW), m_lastColor}); -// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dva, m_lastW), m_lastColor}); -// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dvb, m_lastW), m_lastColor}); -// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dvb, m_lastW), m_lastColor}); - } - } - } - } else if (m_nextVert == 1) { - zeus::CVector2f dv = (projPt - m_lastPos).toVec2f(); - if (!dv.canBeNormalized()) - dv = {0.f, 1.f}; - dv = dv.normalized().perpendicularVector() * m_lastWidth; - dv.x() /= CGraphics::g_ProjAspect; - if (m_textured) { -// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dv, m_lastW), m_lastColor, m_lastUV}); -// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dv, m_lastW), m_lastColor, m_lastUV}); - } else { -// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dv, m_lastW), m_lastColor}); -// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dv, m_lastW), m_lastColor}); - } - } - - m_lastPos2 = m_lastPos; - m_lastPos = projPt; - m_lastW = w; - m_lastUV = uv; - m_lastColor = color; - m_lastWidth = adjWidth; - ++m_nextVert; -} - -void CLineRenderer::Render(bool alphaWrite, const zeus::CColor& moduColor) { - SCOPED_GRAPHICS_DEBUG_GROUP("CLineRenderer::Render", zeus::skGrey); - - if (!m_final && m_nextVert > 1) { - if (m_mode == EPrimitiveMode::LineLoop) { - { - zeus::CVector2f dva = (m_lastPos - m_lastPos2).toVec2f(); - if (!dva.canBeNormalized()) - dva = {0.f, 1.f}; - dva = dva.normalized().perpendicularVector() * m_lastWidth; - dva.x() /= CGraphics::g_ProjAspect; - - zeus::CVector2f dvb = (m_firstPos - m_lastPos).toVec2f(); - if (!dvb.canBeNormalized()) - dvb = {0.f, 1.f}; - dvb = dvb.normalized().perpendicularVector() * m_lastWidth; - dvb.x() /= CGraphics::g_ProjAspect; - - zeus::CVector3f intersect1; - bool good1 = IntersectLines(m_lastPos2.toVec2f() + dva, m_lastPos.toVec2f() + dva, m_lastPos.toVec2f() + dvb, - m_firstPos.toVec2f() + dvb, intersect1); - if ((intersect1.toVec2f() - m_lastPos.toVec2f()).magnitude() > m_lastWidth * 2.f) - good1 = false; - - zeus::CVector3f intersect2; - bool good2 = IntersectLines(m_lastPos2.toVec2f() - dva, m_lastPos.toVec2f() - dva, m_lastPos.toVec2f() - dvb, - m_firstPos.toVec2f() - dvb, intersect2); - if ((intersect2.toVec2f() - m_lastPos.toVec2f()).magnitude() > m_lastWidth * 2.f) - good2 = false; - - if (m_textured) { - if (good1 && good2) { - intersect1.z() = float(m_lastPos.z()); - intersect2.z() = float(m_lastPos.z()); -// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(intersect1, m_lastW), m_lastColor, m_lastUV}); -// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(intersect2, m_lastW), m_lastColor, m_lastUV}); - } else { -// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dva, m_lastW), m_lastColor, m_lastUV}); -// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dva, m_lastW), m_lastColor, m_lastUV}); -// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dvb, m_lastW), m_lastColor, m_lastUV}); -// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dvb, m_lastW), m_lastColor, m_lastUV}); - } - } else { - if (good1 && good2) { - intersect1.z() = float(m_lastPos.z()); - intersect2.z() = float(m_lastPos.z()); -// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(intersect1, m_lastW), m_lastColor}); -// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(intersect2, m_lastW), m_lastColor}); - } else { -// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dva, m_lastW), m_lastColor}); -// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dva, m_lastW), m_lastColor}); -// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dvb, m_lastW), m_lastColor}); -// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dvb, m_lastW), m_lastColor}); - } - } - } - { - zeus::CVector2f dva = (m_firstPos - m_lastPos).toVec2f(); - if (!dva.canBeNormalized()) - dva = {0.f, 1.f}; - dva = dva.normalized().perpendicularVector() * m_firstWidth; - dva.x() /= CGraphics::g_ProjAspect; - - zeus::CVector2f dvb = (m_secondPos - m_firstPos).toVec2f(); - if (!dvb.canBeNormalized()) - dvb = {0.f, 1.f}; - dvb = dvb.normalized().perpendicularVector() * m_firstWidth; - dvb.x() /= CGraphics::g_ProjAspect; - - zeus::CVector3f intersect1; - bool good1 = IntersectLines(m_lastPos.toVec2f() + dva, m_firstPos.toVec2f() + dva, m_firstPos.toVec2f() + dvb, - m_secondPos.toVec2f() + dvb, intersect1); - if ((intersect1.toVec2f() - m_firstPos.toVec2f()).magnitude() > m_firstWidth * 2.f) - good1 = false; - - zeus::CVector3f intersect2; - bool good2 = IntersectLines(m_lastPos.toVec2f() - dva, m_firstPos.toVec2f() - dva, m_firstPos.toVec2f() - dvb, - m_secondPos.toVec2f() - dvb, intersect2); - if ((intersect2.toVec2f() - m_firstPos.toVec2f()).magnitude() > m_firstWidth * 2.f) - good2 = false; - - if (m_textured) { - if (good1 && good2) { - intersect1.z() = float(m_firstPos.z()); - intersect2.z() = float(m_firstPos.z()); -// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(intersect1, m_lastW), m_lastColor, m_lastUV}); -// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(intersect2, m_lastW), m_lastColor, m_lastUV}); - } else { -// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_firstPos + dva, m_lastW), m_lastColor, m_lastUV}); -// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_firstPos - dva, m_lastW), m_lastColor, m_lastUV}); -// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_firstPos + dvb, m_lastW), m_lastColor, m_lastUV}); -// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_firstPos - dvb, m_lastW), m_lastColor, m_lastUV}); - } - } else { - if (good1 && good2) { - intersect1.z() = float(m_firstPos.z()); - intersect2.z() = float(m_firstPos.z()); -// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(intersect1, m_lastW), m_lastColor}); -// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(intersect2, m_lastW), m_lastColor}); - } else { -// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_firstPos + dva, m_lastW), m_lastColor}); -// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_firstPos - dva, m_lastW), m_lastColor}); -// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_firstPos + dvb, m_lastW), m_lastColor}); -// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_firstPos - dvb, m_lastW), m_lastColor}); - } - } - } - } else { - zeus::CVector2f dv = (m_lastPos - m_lastPos2).toVec2f(); - if (!dv.canBeNormalized()) - dv = {0.f, 1.f}; - dv = dv.normalized().perpendicularVector() * m_lastWidth; - dv.x() /= CGraphics::g_ProjAspect; - if (m_textured) { - if (m_mode == EPrimitiveMode::Lines && (m_nextVert & 1)) { - } else { -// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dv, m_lastW), m_lastColor, m_lastUV}); -// g_StaticLineVertsTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dv, m_lastW), m_lastColor, m_lastUV}); - } - } else { - if (m_mode == EPrimitiveMode::Lines && (m_nextVert & 1)) { - } else { -// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos + dv, m_lastW), m_lastColor}); -// g_StaticLineVertsNoTex.push_back({zeus::CVector4f::ToClip(m_lastPos - dv, m_lastW), m_lastColor}); - } - } - } - - m_final = true; - } - -// m_uniformBuf.access() = SDrawUniform{moduColor, CGraphics::g_Fog}; -// if (m_textured) { -// if (!g_StaticLineVertsTex.empty()) { -// memmove(m_vertBufTex.access(), g_StaticLineVertsTex.data(), sizeof(SDrawVertTex) * g_StaticLineVertsTex.size()); -// CGraphics::SetShaderDataBinding(m_shaderBind[alphaWrite]); -// CGraphics::DrawArray(0, g_StaticLineVertsTex.size()); -// } -// } else { -// if (!g_StaticLineVertsNoTex.empty()) { -// memmove(m_vertBufNoTex.access(), g_StaticLineVertsNoTex.data(), -// sizeof(SDrawVertNoTex) * g_StaticLineVertsNoTex.size()); -// CGraphics::SetShaderDataBinding(m_shaderBind[alphaWrite]); -// CGraphics::DrawArray(0, g_StaticLineVertsNoTex.size()); -// } -// } -} - -} // namespace metaforce diff --git a/Runtime/Graphics/CLineRenderer.hpp b/Runtime/Graphics/CLineRenderer.hpp deleted file mode 100644 index 4e87675e8..000000000 --- a/Runtime/Graphics/CLineRenderer.hpp +++ /dev/null @@ -1,73 +0,0 @@ -#pragma once - -#include - -#include "Runtime/RetroTypes.hpp" -#include "Runtime/rstl.hpp" -#include "Runtime/Graphics/CGraphics.hpp" - -#include -#include -#include -#include - -namespace metaforce { - -class CLineRenderer { -public: - enum class EPrimitiveMode { Lines, LineStrip, LineLoop }; - -private: - EPrimitiveMode m_mode; - u32 m_maxVerts; - u32 m_nextVert = 0; - bool m_final = false; - bool m_textured; - - zeus::CVector3f m_firstPos; - zeus::CVector3f m_secondPos; - zeus::CVector2f m_firstUV; - zeus::CColor m_firstColor; - float m_firstWidth; - float m_firstW; - - zeus::CVector3f m_lastPos; - zeus::CVector3f m_lastPos2; - zeus::CVector2f m_lastUV; - zeus::CColor m_lastColor; - float m_lastWidth; - float m_lastW; - -// static rstl::reserved_vector g_StaticLineVertsTex; -// static rstl::reserved_vector g_StaticLineVertsNoTex; - -// static hecl::VertexBufferPool s_vertPoolTex; -// static hecl::VertexBufferPool s_vertPoolNoTex; -// static hecl::UniformBufferPool s_uniformPool; - -public: -// hecl::VertexBufferPool::Token m_vertBufTex; -// hecl::VertexBufferPool::Token m_vertBufNoTex; -// hecl::UniformBufferPool::Token m_uniformBuf; -// std::array, 2> m_shaderBind; - - CLineRenderer(EPrimitiveMode mode, u32 maxVerts, u32 texture, bool additive, - bool zTest = false, bool zGEqual = false); - CLineRenderer(CLineRenderer&&) = default; - - void Reset(); - void AddVertex(const zeus::CVector3f& position, const zeus::CColor& color, float width, - const zeus::CVector2f& uv = zeus::skZero2f); - void Render(bool alphaWrite = false, const zeus::CColor& moduColor = zeus::skWhite); - -// static void UpdateBuffers() { -// s_vertPoolTex.updateBuffers(); -// s_vertPoolNoTex.updateBuffers(); -// s_uniformPool.updateBuffers(); -// } - - static void Initialize(); - static void Shutdown(); -}; - -} // namespace metaforce diff --git a/Runtime/Graphics/CMakeLists.txt b/Runtime/Graphics/CMakeLists.txt index a176c948f..72e6e81eb 100644 --- a/Runtime/Graphics/CMakeLists.txt +++ b/Runtime/Graphics/CMakeLists.txt @@ -7,7 +7,6 @@ set(GRAPHICS_SOURCES CCubeSurface.cpp CCubeSurface.hpp CDrawable.hpp CDrawablePlaneObject.hpp - CLineRenderer.hpp CLineRenderer.cpp CMetroidModelInstance.cpp CMetroidModelInstance.hpp CLight.hpp CLight.cpp CTevCombiners.cpp CTevCombiners.hpp @@ -25,29 +24,6 @@ set(GRAPHICS_SOURCES CSimpleShadow.hpp CSimpleShadow.cpp CRainSplashGenerator.hpp CRainSplashGenerator.cpp CFont.hpp CFont.cpp - Shaders/CLineRendererShaders.hpp Shaders/CLineRendererShaders.cpp - Shaders/CColoredStripShader.hpp Shaders/CColoredStripShader.cpp - Shaders/CModelShaders.hpp Shaders/CModelShaders.cpp - Shaders/CThermalColdFilter.hpp Shaders/CThermalColdFilter.cpp - Shaders/CThermalHotFilter.hpp Shaders/CThermalHotFilter.cpp - Shaders/CSpaceWarpFilter.hpp Shaders/CSpaceWarpFilter.cpp - Shaders/CCameraBlurFilter.hpp Shaders/CCameraBlurFilter.cpp - Shaders/CXRayBlurFilter.hpp Shaders/CXRayBlurFilter.cpp - Shaders/CTextSupportShader.hpp Shaders/CTextSupportShader.cpp - Shaders/CFogVolumePlaneShader.hpp Shaders/CFogVolumePlaneShader.cpp - Shaders/CFogVolumeFilter.hpp Shaders/CFogVolumeFilter.cpp - Shaders/CEnergyBarShader.hpp Shaders/CEnergyBarShader.cpp - Shaders/CRadarPaintShader.hpp Shaders/CRadarPaintShader.cpp - Shaders/CMapSurfaceShader.hpp Shaders/CMapSurfaceShader.cpp - Shaders/CPhazonSuitFilter.hpp Shaders/CPhazonSuitFilter.cpp - Shaders/CScanLinesFilter.hpp Shaders/CScanLinesFilter.cpp - Shaders/CRandomStaticFilter.hpp Shaders/CRandomStaticFilter.cpp - Shaders/CElementGenShaders.hpp Shaders/CElementGenShaders.cpp - Shaders/CDecalShaders.hpp Shaders/CDecalShaders.cpp - Shaders/CParticleSwooshShaders.hpp Shaders/CParticleSwooshShaders.cpp - Shaders/CFluidPlaneShader.hpp Shaders/CFluidPlaneShader.cpp - Shaders/CAABoxShader.hpp Shaders/CAABoxShader.cpp - Shaders/CWorldShadowShader.hpp Shaders/CWorldShadowShader.cpp - Shaders/CEnvFxShaders.hpp Shaders/CEnvFxShaders.cpp) +) runtime_add_list(Graphics GRAPHICS_SOURCES) diff --git a/Runtime/Graphics/CMetroidModelInstance.cpp b/Runtime/Graphics/CMetroidModelInstance.cpp index db2b0e123..74168b223 100644 --- a/Runtime/Graphics/CMetroidModelInstance.cpp +++ b/Runtime/Graphics/CMetroidModelInstance.cpp @@ -3,60 +3,57 @@ #include "Graphics/CCubeSurface.hpp" #include "Streams/IOStreams.hpp" -#include - namespace metaforce { -CMetroidModelInstance::CMetroidModelInstance(std::pair modelHeader, const u8* materialData, - std::pair positions, std::pair normals, - std::pair colors, std::pair texCoords, - std::pair packedTexCoords, - std::vector&& surfaces) +CMetroidModelInstance::CMetroidModelInstance(std::span modelHeader, const u8* materialData, + std::span positions, std::span normals, + std::span colors, std::span texCoords, + std::span packedTexCoords, std::vector&& surfaces) : x4c_materialData(materialData), x50_surfaces(std::move(surfaces)) { { - CMemoryInStream stream{modelHeader.first, modelHeader.second}; + CMemoryInStream stream{modelHeader.data(), static_cast(modelHeader.size_bytes())}; x0_visorFlags = stream.ReadUint32(); x4_worldXf = stream.Get(); x34_worldAABB = stream.Get(); } { - u32 numVertices = positions.second / 12; - CMemoryInStream stream{positions.first, positions.second}; + u32 numVertices = positions.size_bytes() / 12; + x60_positions.reserve(numVertices); + CMemoryInStream stream{positions.data(), static_cast(positions.size_bytes())}; for (u32 i = 0; i < numVertices; ++i) { - x60_positions.emplace_back(stream.Get()); + x60_positions.push_back(stream.Get>()); } } { // Always short normals in MREA - u32 numNormals = normals.second / 6; - CMemoryInStream stream{normals.first, normals.second}; + u32 numNormals = normals.size_bytes() / 6; + x64_normals.reserve(numNormals); + CMemoryInStream stream{normals.data(), static_cast(normals.size_bytes())}; for (u32 i = 0; i < numNormals; ++i) { - const auto x = static_cast(stream.ReadInt16()) / 16384.f; - const auto y = static_cast(stream.ReadInt16()) / 16384.f; - const auto z = static_cast(stream.ReadInt16()) / 16384.f; - x64_normals.emplace_back(x, y, z); + x64_normals.push_back(stream.Get>()); } } { - u32 numColors = colors.second / 4; - CMemoryInStream stream{colors.first, colors.second}; + u32 numColors = colors.size_bytes() / 4; + x68_colors.reserve(numColors); + CMemoryInStream stream{colors.data(), static_cast(colors.size_bytes())}; for (u32 i = 0; i < numColors; ++i) { - x68_colors.emplace_back(stream.ReadUint32()); + x68_colors.push_back(stream.ReadUint32()); } } { - u32 numTexCoords = texCoords.second / 8; - CMemoryInStream stream{texCoords.first, texCoords.second}; + u32 numTexCoords = texCoords.size_bytes() / 8; + x6c_texCoords.reserve(numTexCoords); + CMemoryInStream stream{texCoords.data(), static_cast(texCoords.size_bytes())}; for (u32 i = 0; i < numTexCoords; ++i) { - x6c_texCoords.emplace_back(stream.Get>()); + x6c_texCoords.push_back(stream.Get>()); } } { - u32 numPackedTexCoords = packedTexCoords.second / 4; - CMemoryInStream stream{packedTexCoords.first, packedTexCoords.second}; + u32 numPackedTexCoords = packedTexCoords.size_bytes() / 4; + x70_packedTexCoords.reserve(numPackedTexCoords); + CMemoryInStream stream{packedTexCoords.data(), static_cast(packedTexCoords.size_bytes())}; for (u32 i = 0; i < numPackedTexCoords; ++i) { - const auto u = static_cast(stream.ReadInt16()) / 32768.f; - const auto v = static_cast(stream.ReadInt16()) / 32768.f; - x70_packedTexCoords.emplace_back(u, v); + x70_packedTexCoords.push_back(stream.Get>()); } } } diff --git a/Runtime/Graphics/CMetroidModelInstance.hpp b/Runtime/Graphics/CMetroidModelInstance.hpp index a698bf82e..1accec78a 100644 --- a/Runtime/Graphics/CMetroidModelInstance.hpp +++ b/Runtime/Graphics/CMetroidModelInstance.hpp @@ -1,10 +1,11 @@ #pragma once #include +#include #include #include -#include "Graphics/CCubeModel.hpp" +#include "Runtime/Graphics/CCubeModel.hpp" #include "Runtime/RetroTypes.hpp" #include @@ -19,31 +20,28 @@ class CMetroidModelInstance { zeus::CTransform x4_worldXf; zeus::CAABox x34_worldAABB; const u8* x4c_materialData = nullptr; - std::vector x50_surfaces; // was rstl::vector* - std::vector x60_positions; // was void* - std::vector x64_normals; // was void* - std::vector x68_colors; // was void* - std::vector> x6c_texCoords; // was void* - std::vector> x70_packedTexCoords; // was void* + std::vector x50_surfaces; // was rstl::vector* + std::vector> x60_positions; // was void* + std::vector> x64_normals; // was void* + std::vector x68_colors; // was void* + std::vector> x6c_texCoords; // was void* + std::vector> x70_packedTexCoords; // was void* public: CMetroidModelInstance() = default; - CMetroidModelInstance(std::pair modelHeader, const u8* materialData, - std::pair positions, std::pair normals, - std::pair colors, std::pair texCoords, - std::pair packedTexCoords, std::vector&& surfaces); + CMetroidModelInstance(std::span modelHeader, const u8* materialData, std::span positions, + std::span normals, std::span colors, std::span texCoords, + std::span packedTexCoords, std::vector&& surfaces); [[nodiscard]] u32 GetFlags() const { return x0_visorFlags; } [[nodiscard]] const zeus::CAABox& GetBoundingBox() const { return x34_worldAABB; } [[nodiscard]] std::vector* GetSurfaces() { return &x50_surfaces; } [[nodiscard]] const std::vector* GetSurfaces() const { return &x50_surfaces; } [[nodiscard]] const u8* GetMaterialPointer() const { return x4c_materialData; } - [[nodiscard]] TVectorRef GetVertexPointer() { return &x60_positions; } - [[nodiscard]] TConstVectorRef GetVertexPointer() const { return &x60_positions; } - [[nodiscard]] TVectorRef GetNormalPointer() { return &x64_normals; } - [[nodiscard]] TConstVectorRef GetNormalPointer() const { return &x64_normals; } - [[nodiscard]] const std::vector* GetColorPointer() const { return &x68_colors; } - [[nodiscard]] const std::vector>* GetTCPointer() const { return &x6c_texCoords; } - [[nodiscard]] const std::vector>* GetPackedTCPointer() const { return &x70_packedTexCoords; } + [[nodiscard]] std::span GetVertexPointer() const { return byte_span(x60_positions); } + [[nodiscard]] std::span GetNormalPointer() const { return byte_span(x64_normals); } + [[nodiscard]] std::span GetColorPointer() const { return byte_span(x68_colors); } + [[nodiscard]] std::span GetTCPointer() const { return byte_span(x6c_texCoords); } + [[nodiscard]] std::span GetPackedTCPointer() const { return byte_span(x70_packedTexCoords); } }; } // namespace metaforce diff --git a/Runtime/Graphics/CModel.cpp b/Runtime/Graphics/CModel.cpp index 91a58b65a..b9a386d9d 100644 --- a/Runtime/Graphics/CModel.cpp +++ b/Runtime/Graphics/CModel.cpp @@ -61,34 +61,38 @@ CModel::CModel(std::unique_ptr in, u32 dataLen, IObjectStore* store) x4_dataLen += shader.x0_textures.size() * sizeof(TCachedToken); } - /* Metaforce note: Due to padding in zeus types we need to convert these and store locally */ u32 numVertices = CBasics::SwapBytes(*secSizeCur) / 12; + m_positions.reserve(numVertices); auto positions = StreamFromPartData(dataCur, secSizeCur); for (u32 i = 0; i < numVertices; ++i) { - m_positions.emplace_back(positions.Get()); + m_positions.emplace_back(positions.Get>()); } u32 numNormals = CBasics::SwapBytes(*secSizeCur); numNormals /= (flags & 2) == 0 ? 12 : 6; + if ((flags & 2) == 0) { + m_normals.reserve(numNormals); + } else { + m_shortNormals.reserve(numNormals); + } auto normals = StreamFromPartData(dataCur, secSizeCur); for (u32 i = 0; i < numNormals; ++i) { if ((flags & 2) == 0) { - m_normals.emplace_back(normals.Get()); + m_normals.emplace_back(normals.Get>()); } else { - const auto x = static_cast(normals.ReadShort()) / 16384.f; - const auto y = static_cast(normals.ReadShort()) / 16384.f; - const auto z = static_cast(normals.ReadShort()) / 16384.f; - m_normals.emplace_back(x, y, z); + m_shortNormals.emplace_back(normals.Get>()); } } u32 numColors = CBasics::SwapBytes(*secSizeCur) / 4; + m_colors.reserve(numColors); auto vtxColors = StreamFromPartData(dataCur, secSizeCur); for (u32 i = 0; i < numColors; ++i) { - m_colors.emplace_back(zeus::CColor(vtxColors.ReadUint32())); + m_colors.emplace_back(vtxColors.ReadUint32()); } u32 numFloatUVs = CBasics::SwapBytes(*secSizeCur) / 8; + m_floatUVs.reserve(numFloatUVs); auto floatUVs = StreamFromPartData(dataCur, secSizeCur); for (u32 i = 0; i < numFloatUVs; ++i) { m_floatUVs.emplace_back(floatUVs.Get>()); @@ -96,11 +100,10 @@ CModel::CModel(std::unique_ptr in, u32 dataLen, IObjectStore* store) if ((flags & 4) != 0) { u32 numShortUVs = CBasics::SwapBytes(*secSizeCur) / 4; + m_shortUVs.reserve(numShortUVs); auto shortUVs = StreamFromPartData(dataCur, secSizeCur); for (u32 i = 0; i < numShortUVs; ++i) { - const auto u = static_cast(shortUVs.ReadShort()) / 32768.f; - const auto v = static_cast(shortUVs.ReadShort()) / 32768.f; - m_shortUVs.emplace_back(u, v); + m_shortUVs.emplace_back(shortUVs.Get>()); } } @@ -122,9 +125,10 @@ CModel::CModel(std::unique_ptr in, u32 dataLen, IObjectStore* store) }; /* This constructor has been changed from the original to take into account platform differences */ - x28_modelInst = - std::make_unique(&x8_surfaces, &x18_matSets[0].x0_textures, x18_matSets[0].x10_data, &m_positions, - &m_colors, &m_normals, &m_floatUVs, &m_shortUVs, aabb, flags, true, -1); + x28_modelInst = std::make_unique(&x8_surfaces, &x18_matSets[0].x0_textures, x18_matSets[0].x10_data, + byte_span(m_positions), byte_span(m_colors), + (flags & 2) == 0 ? byte_span(m_normals) : byte_span(m_shortNormals), + byte_span(m_floatUVs), byte_span(m_shortUVs), aabb, flags, true, -1); sThisFrameList = this; if (x34_next != nullptr) { @@ -203,12 +207,8 @@ void CModel::EnableTextureTimeout() { sIsTextureTimeoutEnabled = true; } void CModel::DisableTextureTimeout() { sIsTextureTimeoutEnabled = false; } -TVectorRef CModel::GetPositions() { return x28_modelInst->GetPositions(); } - TConstVectorRef CModel::GetPositions() const { return x28_modelInst->GetPositions(); } -TVectorRef CModel::GetNormals() { return x28_modelInst->GetNormals(); } - TConstVectorRef CModel::GetNormals() const { return x28_modelInst->GetNormals(); } void CModel::VerifyCurrentShader(u32 matIdx) { @@ -262,7 +262,7 @@ void CModel::Touch(u32 matIdx) { void CModel::Draw(CModelFlags flags) { if (flags.x2_flags & CModelFlagBits::DrawNormal) { - x28_modelInst->DrawNormal(nullptr, nullptr, ESurfaceSelection::All); + x28_modelInst->DrawNormal({}, {}, ESurfaceSelection::All); } CCubeMaterial::ResetCachedMaterials(); MoveToThisFrameList(); @@ -282,7 +282,7 @@ void CModel::Draw(TConstVectorRef positions, TConstVectorRef normals, const CMod void CModel::DrawSortedParts(CModelFlags flags) { if (flags.x2_flags & CModelFlagBits::DrawNormal) { - x28_modelInst->DrawNormal(nullptr, nullptr, ESurfaceSelection::Sorted); + x28_modelInst->DrawNormal({}, {}, ESurfaceSelection::Sorted); } CCubeMaterial::ResetCachedMaterials(); MoveToThisFrameList(); @@ -292,7 +292,7 @@ void CModel::DrawSortedParts(CModelFlags flags) { void CModel::DrawUnsortedParts(CModelFlags flags) { if (flags.x2_flags & CModelFlagBits::DrawNormal) { - x28_modelInst->DrawNormal(nullptr, nullptr, ESurfaceSelection::Unsorted); + x28_modelInst->DrawNormal({}, {}, ESurfaceSelection::Unsorted); } CCubeMaterial::ResetCachedMaterials(); MoveToThisFrameList(); diff --git a/Runtime/Graphics/CModel.hpp b/Runtime/Graphics/CModel.hpp index a770d0c5d..04d499134 100644 --- a/Runtime/Graphics/CModel.hpp +++ b/Runtime/Graphics/CModel.hpp @@ -85,11 +85,12 @@ private: u32 x38_lastFrame; /* Resident copies of maintained data */ - std::vector m_positions; - std::vector m_normals; - std::vector m_colors; + std::vector> m_positions; + std::vector> m_normals; + std::vector> m_shortNormals; + std::vector m_colors; std::vector> m_floatUVs; - std::vector> m_shortUVs; + std::vector> m_shortUVs; public: CModel(std::unique_ptr in, u32 dataLen, IObjectStore* store); @@ -106,9 +107,7 @@ public: void DrawUnsortedParts(CModelFlags flags); bool IsLoaded(u32 matIdx); - [[nodiscard]] TVectorRef GetPositions(); [[nodiscard]] TConstVectorRef GetPositions() const; - [[nodiscard]] TVectorRef GetNormals(); [[nodiscard]] TConstVectorRef GetNormals() const; [[nodiscard]] u32 GetNumMaterialSets() const { return x18_matSets.size(); } [[nodiscard]] bool IsOpaque() const { return x28_modelInst->x3c_firstSortedSurf == nullptr; } diff --git a/Runtime/Graphics/CModel.hpp.old b/Runtime/Graphics/CModel.hpp.old deleted file mode 100644 index 1e3255d23..000000000 --- a/Runtime/Graphics/CModel.hpp.old +++ /dev/null @@ -1,312 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -//#include "DataSpec/DNACommon/CMDL.hpp" -//#include "DataSpec/DNAMP1/CMDLMaterials.hpp" -#include "Runtime/CFactoryMgr.hpp" -#include "Runtime/CToken.hpp" -#include "Runtime/Graphics/CTexture.hpp" -#include "Runtime/Graphics/Shaders/CModelShaders.hpp" -#include "Runtime/RetroTypes.hpp" - -//#include -#include -#include - -namespace metaforce { -class CLight; -class CModel; -class CPoseAsTransforms; -class CSkinRules; -class IObjectStore; - -struct CModelFlags { - u8 x0_blendMode = 0; /* 2: add color, >6: additive, >4: blend, else opaque */ - u8 x1_matSetIdx = 0; - EExtendedShader m_extendedShader = EExtendedShader::Lighting; - bool m_noCull = false; - bool m_noZTest = false; - bool m_noZWrite = false; - bool m_depthGreater = false; - u16 x2_flags = 0; /* Flags */ - zeus::CColor x4_color; /* Set into kcolor slot specified by material */ - zeus::CColor addColor = zeus::skClear; - zeus::CAABox mbShadowBox; - - constexpr CModelFlags() = default; - constexpr CModelFlags(u8 blendMode, u8 shadIdx, u16 flags, const zeus::CColor& col) - : x0_blendMode(blendMode), x1_matSetIdx(shadIdx), x2_flags(flags), x4_color(col) { - /* Blend mode will override this if the surface's original material is opaque */ - m_noZWrite = (x2_flags & 0x2) == 0; - m_depthGreater = (x2_flags & 0x8) != 0; - } - - /* Flags - 0x1: depth lequal - 0x2: depth update - 0x4: render without texture lock - 0x8: depth greater - 0x10: depth non-inclusive - */ - - bool operator==(const CModelFlags& other) const { - return x0_blendMode == other.x0_blendMode && x1_matSetIdx == other.x1_matSetIdx && x2_flags == other.x2_flags && - x4_color == other.x4_color; - } - - bool operator!=(const CModelFlags& other) const { return !operator==(other); } -}; - -/* metaforce addition: doesn't require hacky stashing of - * pointers within loaded CMDL buffer */ -struct CBooSurface { -// DataSpec::DNACMDL::SurfaceHeader_2 m_data; - size_t selfIdx; - class CBooModel* m_parent = nullptr; - CBooSurface* m_next = nullptr; - - zeus::CAABox GetBounds() const { -// if (!m_data.aabbSz) -// return zeus::CAABox(m_data.centroid, m_data.centroid); -// else -// return zeus::CAABox(m_data.aabb[0], m_data.aabb[1]); - return {}; - } -}; - -//using MaterialSet = DataSpec::DNAMP1::HMDLMaterialSet; - -//struct GeometryUniformLayout { -// mutable std::vector> m_sharedBuffer; -// size_t m_geomBufferSize = 0; -// size_t m_skinBankCount = 0; -// size_t m_weightVecCount = 0; -// -// std::vector m_skinOffs; -// std::vector m_skinSizes; -// -// std::vector m_uvOffs; -// std::vector m_uvSizes; -// -// GeometryUniformLayout(const CModel* model, const MaterialSet* matSet); -// void Update(const CModelFlags& flags, const CSkinRules* cskr, const CPoseAsTransforms* pose, -// const MaterialSet* matSet, const boo::ObjToken& buf, -// const CBooModel* parent) const; -// -// void ReserveSharedBuffers(boo::IGraphicsDataFactory::Context& ctx, int size); -// boo::ObjToken GetSharedBuffer(int idx) const; -//}; - -struct SShader { - std::unordered_map> x0_textures; -// std::unordered_map m_shaders; -// MaterialSet m_matSet; -// std::optional m_geomLayout; - int m_matSetIdx; - explicit SShader(int idx) : m_matSetIdx(idx) { - x0_textures.clear(); -// m_shaders.clear(); - } -// void InitializeLayout(const CModel* model) { m_geomLayout.emplace(model, &m_matSet); } - void UnlockTextures(); -// CModelShaders::ShaderPipelines BuildShader(const hecl::HMDLMeta& meta, const MaterialSet::Material& mat); -// void BuildShaders(const hecl::HMDLMeta& meta, std::unordered_map& shaders); -// void BuildShaders(const hecl::HMDLMeta& meta) { BuildShaders(meta, m_shaders); } -}; - -class CBooModel { - friend class CBooRenderer; - friend class CGameArea; - friend class CMetroidModelInstance; - friend class CModel; - friend class CSkinnedModel; - friend struct GeometryUniformLayout; - -public: - enum class ESurfaceSelection { UnsortedOnly, SortedOnly, All }; - -private: - CBooModel* m_next = nullptr; - CBooModel* m_prev = nullptr; - size_t m_uniUpdateCount = 0; - TToken m_modelTok; - CModel* m_model; - std::vector* x0_surfaces; -// const MaterialSet* x4_matSet; -// const GeometryUniformLayout* m_geomLayout; - int m_matSetIdx = -1; -// const std::unordered_map* m_pipelines; - std::unordered_map> x1c_textures; - zeus::CAABox x20_aabb; - CBooSurface* x38_firstUnsortedSurface = nullptr; - CBooSurface* x3c_firstSortedSurface = nullptr; - bool x40_24_texturesLoaded : 1 = false; - bool x40_25_modelVisible : 1 = false; - u8 x41_mask; - u32 x44_areaInstanceIdx = UINT32_MAX; - -// struct UVAnimationBuffer { -// static void ProcessAnimation(u8*& bufOut, const MaterialSet::Material::PASS& anim); -// static void PadOutBuffer(u8*& bufStart, u8*& bufOut); -// static void Update(u8*& bufOut, const MaterialSet* matSet, const CModelFlags& flags, const CBooModel* parent); -// }; - - CModelShaders::LightingUniform m_lightingData; - - /* metaforce addition: boo! */ -// size_t m_uniformDataSize = 0; -// struct ModelInstance { -// boo::ObjToken m_geomUniformBuffer; -// boo::ObjToken m_uniformBuffer; -// std::vector>> m_shaderDataBindings; -// boo::ObjToken m_dynamicVbo; -// -// boo::ObjToken GetBooVBO(const CBooModel& model, boo::IGraphicsDataFactory::Context& ctx); -// }; -// std::vector m_instances; -// ModelInstance m_ballShadowInstance; - -// boo::ObjToken m_staticVbo; -// boo::ObjToken m_staticIbo; -// -// boo::ObjToken m_lastDrawnShadowMap; -// boo::ObjToken m_lastDrawnOneTexture; -// boo::ObjToken m_lastDrawnReflectionCube; - -// ModelInstance* PushNewModelInstance(int sharedLayoutBuf = -1, boo::IGraphicsDataFactory::Context* ctx = nullptr); - void DrawAlphaSurfaces(const CModelFlags& flags) const; - void DrawNormalSurfaces(const CModelFlags& flags) const; - void DrawSurfaces(const CModelFlags& flags) const; - void DrawSurface(const CBooSurface& surf, const CModelFlags& flags) const; - void WarmupDrawSurfaces() const; - void WarmupDrawSurface(const CBooSurface& surf) const; - - static inline zeus::CVector3f g_PlayerPosition; - static inline float g_ModSeconds = 0.0f; - static inline float g_TransformedTime = 0.0f; - static inline float g_TransformedTime2 = 0.0f; - static inline CBooModel* g_LastModelCached = nullptr; - - static inline bool g_DummyTextures = false; - static inline bool g_RenderModelBlack = false; - -public: - ~CBooModel(); - CBooModel(TToken& token, CModel* parent, std::vector* surfaces, SShader& shader, - // TODO -// boo::ObjToken vbo, boo::ObjToken ibo, - const zeus::CAABox& aabb, u8 renderMask); - -// static void MakeTexturesFromMats(const MaterialSet& matSet, -// std::unordered_map>& toksOut, IObjectStore& store); - void MakeTexturesFromMats(std::unordered_map>& toksOut, IObjectStore& store); - - bool IsOpaque() const { return x3c_firstSortedSurface == nullptr; } - void ActivateLights(const std::vector& lights); - void SetAmbientColor(const zeus::CColor& color) { m_lightingData.ambient = color; } - void DisableAllLights(); - void RemapMaterialData(SShader& shader); - bool TryLockTextures(); - void UnlockTextures(); - void SyncLoadTextures(); - void Touch(int shaderIdx); - void VerifyCurrentShader(int shaderIdx); -// boo::ObjToken UpdateUniformData(const CModelFlags& flags, const CSkinRules* cskr, -// const CPoseAsTransforms* pose, int sharedLayoutBuf = -1); - void DrawAlpha(const CModelFlags& flags, const CSkinRules* cskr, const CPoseAsTransforms* pose); - void DrawNormal(const CModelFlags& flags, const CSkinRules* cskr, const CPoseAsTransforms* pose); - void Draw(const CModelFlags& flags, const CSkinRules* cskr, const CPoseAsTransforms* pose); - void DrawFlat(ESurfaceSelection sel, EExtendedShader extendedIdx) const; - - void LockParent() { m_modelTok.Lock(); } - void UnlockParent() { m_modelTok.Unlock(); } - -// const MaterialSet::Material& GetMaterialByIndex(int idx) const { return x4_matSet->materials.at(idx); } - - void ClearUniformCounter() { m_uniUpdateCount = 0; } - static void ClearModelUniformCounters(); - - static inline bool g_DrawingOccluders = false; - static void SetDrawingOccluders(bool occ) { g_DrawingOccluders = occ; } - - static void SetNewPlayerPositionAndTime(const zeus::CVector3f& pos); - - static inline zeus::CVector3f g_ReflectViewPos; - static void KillCachedViewDepState(); - static void EnsureViewDepStateCached(const CBooModel& model, const CBooSurface* surf, zeus::CMatrix4f* mtxsOut, - float& alphaOut); - - static inline aurora::gfx::TextureHandle g_shadowMap; - static inline zeus::CTransform g_shadowTexXf; - static void EnableShadowMaps(const aurora::gfx::TextureHandle& map, const zeus::CTransform& texXf); - static void DisableShadowMaps(); - - static inline aurora::gfx::TextureHandle g_disintegrateTexture; - static void SetDisintegrateTexture(const aurora::gfx::TextureHandle& map) { g_disintegrateTexture = map; } - - static inline aurora::gfx::TextureHandle g_reflectionCube; - static void SetReflectionCube(const aurora::gfx::TextureHandle& map) { g_reflectionCube = map; } - - static void SetDummyTextures(bool b) { g_DummyTextures = b; } - static void SetRenderModelBlack(bool b) { g_RenderModelBlack = b; } - - static void Shutdown(); - - const zeus::CAABox& GetAABB() const { return x20_aabb; } -}; - -class CModel { - friend class CBooModel; - friend struct GeometryUniformLayout; - // std::unique_ptr x0_data; - // u32 x4_dataLen; - TToken m_selfToken; /* DO NOT LOCK! */ - zeus::CAABox m_aabb; - u32 m_flags; - std::vector x8_surfaces; - std::vector x18_matSets; - std::unique_ptr x28_modelInst; - // CModel* x30_next = nullptr; - // CModel* x34_prev = nullptr; - int x38_lastFrame; - - /* metaforce addition: boo! */ -// boo::ObjToken m_staticVbo; -// hecl::HMDLMeta m_hmdlMeta; - std::unique_ptr m_dynamicVertexData; -// boo::ObjToken m_ibo; - -public: -// using MaterialSet = DataSpec::DNAMP1::HMDLMaterialSet; - - CModel(std::unique_ptr&& in, u32 dataLen, IObjectStore* store, CObjectReference* selfRef); - void DrawSortedParts(const CModelFlags& flags) const; - void DrawUnsortedParts(const CModelFlags& flags) const; - void Draw(const CModelFlags& flags) const; - bool IsLoaded(int shaderIdx) const; - void Touch(int shaderIdx) { x28_modelInst->Touch(shaderIdx); } - - const zeus::CAABox& GetAABB() const { return m_aabb; } - CBooModel& GetInstance() { return *x28_modelInst; } - const CBooModel& GetInstance() const { return *x28_modelInst; } - std::unique_ptr MakeNewInstance(int shaderIdx, bool lockParent = true); - void UpdateLastFrame() const { const_cast(*this).x38_lastFrame = CGraphics::GetFrameCounter(); } - u32 GetNumMaterialSets() const { return x18_matSets.size(); } - - size_t GetPoolVertexOffset(size_t idx) const; - zeus::CVector3f GetPoolVertex(size_t idx) const; - size_t GetPoolNormalOffset(size_t idx) const; - zeus::CVector3f GetPoolNormal(size_t idx) const; -// void ApplyVerticesCPU(const boo::ObjToken& vertBuf, -// const std::vector>& vn) const; -// void RestoreVerticesCPU(const boo::ObjToken& vertBuf) const; -}; - -CFactoryFnReturn FPCModelFactory(const metaforce::SObjectTag& tag, std::unique_ptr&& in, u32 len, - const metaforce::CVParamTransfer& vparms, CObjectReference* selfRef); - -} // namespace metaforce diff --git a/Runtime/Graphics/CModelBoo.cpp b/Runtime/Graphics/CModelBoo.cpp deleted file mode 100644 index 6309dc031..000000000 --- a/Runtime/Graphics/CModelBoo.cpp +++ /dev/null @@ -1,1323 +0,0 @@ -#include "Runtime/Graphics/CModel.hpp" - -#include "Runtime/CBasics.hpp" -#include "Runtime/CSimplePool.hpp" -#include "Runtime/GameGlobalObjects.hpp" -#include "Runtime/Character/CSkinRules.hpp" -#include "Runtime/Graphics/CCubeRenderer.hpp" -#include "Runtime/Graphics/CGraphics.hpp" -#include "Runtime/Graphics/CLight.hpp" -#include "Runtime/Graphics/CTexture.hpp" -#include "Runtime/Graphics/Shaders/CModelShaders.hpp" - -#include - -#include "ConsoleVariables/CVarManager.hpp" -//#include -#include -#include - -namespace metaforce { -namespace { -logvisor::Module Log("metaforce::CBooModel"); -CBooModel* g_FirstModel = nullptr; - -constexpr zeus::CMatrix4f ReflectBaseMtx{ - 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 1.f, -}; - -constexpr zeus::CMatrix4f ReflectPostGL{ - 1.f, 0.f, 0.f, 0.f, 0.f, -1.f, 0.f, 1.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.f, 1.f, -}; - -constexpr zeus::CMatrix4f MBShadowPost0{ - 1.f, 0.f, 0.f, 0.f, 0.f, -1.f, 0.f, 1.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 1.f, -}; - -constexpr zeus::CMatrix4f MBShadowPost1{ - 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 1.f, -0.0625f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 1.f, -}; - -constexpr zeus::CMatrix4f DisintegratePost{ - 1.f, 1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 1.f, -}; -} // Anonymous namespace - -void CBooModel::Shutdown() { - g_shadowMap.reset(); - g_disintegrateTexture.reset(); - g_reflectionCube.reset(); - assert(g_FirstModel == nullptr && "Dangling CBooModels detected"); -} - -void CBooModel::ClearModelUniformCounters() { - OPTICK_EVENT(); - for (CBooModel* model = g_FirstModel; model; model = model->m_next) - model->ClearUniformCounter(); -} - -void CBooModel::SetNewPlayerPositionAndTime(const zeus::CVector3f& pos) { - g_PlayerPosition = pos; - KillCachedViewDepState(); - u32 modMillis = - std::chrono::duration_cast(std::chrono::steady_clock::now().time_since_epoch()) - .count() % - u64(100000.f * 4.f * M_PIF / 3.f); - g_ModSeconds = modMillis / 1000.f; - g_TransformedTime = 1.f / -(0.05f * std::sin(g_ModSeconds * 1.5f) - 1.f); - g_TransformedTime2 = 1.f / -(0.015f * std::sin(g_ModSeconds * 1.5f + 1.f) - 1.f); -} - -void CBooModel::KillCachedViewDepState() { g_LastModelCached = nullptr; } - -void CBooModel::EnsureViewDepStateCached(const CBooModel& model, const CBooSurface* surf, zeus::CMatrix4f* mtxsOut, - float& alphaOut) { - zeus::CVector3f modelToPlayer = g_PlayerPosition - CGraphics::g_GXModelMatrix.origin; - zeus::CVector3f modelToPlayerLocal = CGraphics::g_GXModelMatrix.transposeRotate(modelToPlayer); - - zeus::CVector3f surfPos; - float surfSize = 0.f; - if (surf) { -// zeus::CVector3f surfCenter(surf->m_data.centroid); -// zeus::CVector3f surfNormal(surf->m_data.reflectionNormal); -// float dotDelta = surfNormal.dot(modelToPlayerLocal) - surfCenter.dot(surfNormal); -// surfPos = modelToPlayerLocal - surfNormal * dotDelta; - } else { - surfPos = model.x20_aabb.center(); - surfSize = - (model.x20_aabb.max.x() - model.x20_aabb.min.x()) + (model.x20_aabb.max.y() - model.x20_aabb.min.y()) * 0.5f; - } - - if (g_Renderer->x318_24_refectionDirty) { - zeus::CVector3f playerToPos = g_ReflectViewPos - g_PlayerPosition; - zeus::CVector3f vecToPos = surfPos - g_PlayerPosition; - if (playerToPos.dot(playerToPos) < vecToPos.dot(vecToPos)) - g_ReflectViewPos = surfPos; - } else { - g_ReflectViewPos = surfPos; - g_Renderer->x318_24_refectionDirty = true; - } - - zeus::CVector3f playerToSurf = surfPos - modelToPlayerLocal; - float distance = std::max(-(0.5f * surfSize - playerToSurf.magnitude()), FLT_EPSILON); - if (distance >= 5.f) { - alphaOut = 0.f; - } else { - alphaOut = (5.f - distance) / 5.f; - - /* Indirect map matrix */ - mtxsOut[0] = (CGraphics::g_ViewMatrix.inverse() * CGraphics::g_GXModelMatrix).toMatrix4f(); - - /* Reflection map matrix */ - zeus::CVector3f v1 = playerToSurf * (1.f / surfSize); - zeus::CVector3f v2 = v1.cross(zeus::skUp); - if (v2.canBeNormalized()) - v2.normalize(); - else - v2 = zeus::skRight; - - float timeScale = 0.32258067f * (0.02f * distance + 1.f); - float f1 = timeScale * g_TransformedTime; - float f2 = timeScale * g_TransformedTime2; - mtxsOut[1] = ReflectBaseMtx; - mtxsOut[1][0][0] = f1 * v2.x(); - mtxsOut[1][1][0] = f1 * v2.y(); - mtxsOut[1][3][0] = -surfPos.dot(v2) * f1 + 0.5f; - mtxsOut[1][2][1] = f2; - mtxsOut[1][3][1] = -modelToPlayerLocal.z() * f2; -// switch (CGraphics::g_BooPlatform) { -// case boo::IGraphicsDataFactory::Platform::OpenGL: -// mtxsOut[1] = ReflectPostGL * mtxsOut[1]; -// break; -// default: -// break; -// } - } -} - -void CBooModel::EnableShadowMaps(const aurora::gfx::TextureHandle& map, const zeus::CTransform& texXf) { - g_shadowMap = map; - g_shadowTexXf = texXf; -} -void CBooModel::DisableShadowMaps() { g_shadowMap.reset(); } - -CBooModel::~CBooModel() { - if (m_prev) - m_prev->m_next = m_next; - if (m_next) - m_next->m_prev = m_prev; - if (this == g_FirstModel) - g_FirstModel = m_next; -} - -CBooModel::CBooModel(TToken& token, CModel* parent, std::vector* surfaces, SShader& shader, -// boo::ObjToken vbo, boo::ObjToken ibo, - const zeus::CAABox& aabb, u8 renderMask) -: 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) -, x41_mask(renderMask) -//, m_staticVbo(std::move(vbo)) -//, m_staticIbo(std::move(ibo)) -{ - if (!g_FirstModel) - g_FirstModel = this; - else { - g_FirstModel->m_prev = this; - m_next = g_FirstModel; - g_FirstModel = this; - } - - for (CBooSurface& surf : *x0_surfaces) - surf.m_parent = this; - - for (auto it = x0_surfaces->rbegin(); it != x0_surfaces->rend(); ++it) { -// u32 matId = it->m_data.matIdx; -// const MaterialSet::Material& matData = GetMaterialByIndex(matId); -// if (matData.flags.depthSorting()) { -// it->m_next = x3c_firstSortedSurface; -// x3c_firstSortedSurface = &*it; -// } else { -// it->m_next = x38_firstUnsortedSurface; -// x38_firstUnsortedSurface = &*it; -// } - } - -// m_instances.reserve(numInsts); -// for (int i = 0; i < numInsts; ++i) -// PushNewModelInstance(); -} - -//boo::ObjToken CBooModel::ModelInstance::GetBooVBO(const CBooModel& model, -// boo::IGraphicsDataFactory::Context& ctx) { -// if (model.m_staticVbo) -// return model.m_staticVbo.get(); -// if (!m_dynamicVbo && model.m_model) { -// const CModel& parent = *model.m_model; -// m_dynamicVbo = -// ctx.newDynamicBuffer(boo::BufferUse::Vertex, parent.m_hmdlMeta.vertStride, parent.m_hmdlMeta.vertCount); -// m_dynamicVbo->load(parent.m_dynamicVertexData.get(), parent.m_hmdlMeta.vertStride * parent.m_hmdlMeta.vertCount); -// } -// return m_dynamicVbo.get(); -//} - -//GeometryUniformLayout::GeometryUniformLayout(const CModel* model, const MaterialSet* matSet) { -// if (model) { -// m_skinBankCount = model->m_hmdlMeta.bankCount; -// m_weightVecCount = model->m_hmdlMeta.weightCount; -// } -// -// m_skinOffs.reserve(std::max(size_t(1), m_skinBankCount)); -// m_skinSizes.reserve(std::max(size_t(1), m_skinBankCount)); -// -// m_uvOffs.reserve(matSet->materials.size()); -// m_uvSizes.reserve(matSet->materials.size()); -// -// if (m_skinBankCount) { -// /* Skinned */ -// for (size_t i = 0; i < m_skinBankCount; ++i) { -// size_t thisSz = ROUND_UP_256(sizeof(zeus::CMatrix4f) * (2 * m_weightVecCount * 4 + 3)); -// m_skinOffs.push_back(m_geomBufferSize); -// m_skinSizes.push_back(thisSz); -// m_geomBufferSize += thisSz; -// } -// } else { -// /* Non-Skinned */ -// size_t thisSz = ROUND_UP_256(sizeof(zeus::CMatrix4f) * 3); -// m_skinOffs.push_back(m_geomBufferSize); -// m_skinSizes.push_back(thisSz); -// m_geomBufferSize += thisSz; -// } -// -// /* Animated UV transform matrices */ -// for (const MaterialSet::Material& mat : matSet->materials) { -// (void)mat; -// size_t thisSz = ROUND_UP_256(/*mat.uvAnims.size()*/ 8 * (sizeof(zeus::CMatrix4f) * 2)); -// m_uvOffs.push_back(m_geomBufferSize); -// m_uvSizes.push_back(thisSz); -// m_geomBufferSize += thisSz; -// } -//} - -//CBooModel::ModelInstance* CBooModel::PushNewModelInstance(int sharedLayoutBuf, -// boo::IGraphicsDataFactory::Context* ctx) { -// OPTICK_EVENT(); -// if (!x40_24_texturesLoaded && !g_DummyTextures) { -// return nullptr; -// } -// -// if (m_instances.size() >= 512) { -// spdlog::fatal("Model buffer overflow"); -// } -// -// ModelInstance& newInst = m_instances.emplace_back(); -// -// /* Build geometry uniform buffer if shared not available */ -// boo::ObjToken geomUniformBuf; -// if (sharedLayoutBuf >= 0) { -// geomUniformBuf = m_geomLayout->GetSharedBuffer(sharedLayoutBuf); -// } else { -// geomUniformBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, m_geomLayout->m_geomBufferSize, 1); -// newInst.m_geomUniformBuffer = geomUniformBuf; -// } -// -// /* Lighting and reflection uniforms */ -// size_t uniBufSize = 0; -// -// /* Lighting uniform */ -// size_t lightOff = 0; -// size_t lightSz = 0; -// { -// size_t thisSz = ROUND_UP_256(sizeof(CModelShaders::LightingUniform)); -// lightOff = uniBufSize; -// lightSz = thisSz; -// uniBufSize += thisSz; -// } -// -// /* Surface reflection texmatrix uniform with first identity slot */ -// size_t reflectOff = uniBufSize; -// uniBufSize += 256; -// for (const CBooSurface& surf : *x0_surfaces) { -// const MaterialSet::Material& mat = x4_matSet->materials.at(surf.m_data.matIdx); -// if (mat.flags.samusReflection() || mat.flags.samusReflectionSurfaceEye()) -// uniBufSize += 256; -// } -// -// /* Allocate resident buffer */ -// m_uniformDataSize = uniBufSize; -// newInst.m_uniformBuffer = ctx.newDynamicBuffer(boo::BufferUse::Uniform, uniBufSize, 1); -// -// const std::array, 4> bufs{ -// geomUniformBuf.get(), -// geomUniformBuf.get(), -// newInst.m_uniformBuffer.get(), -// newInst.m_uniformBuffer.get(), -// }; -// -// /* Binding for each surface */ -// newInst.m_shaderDataBindings.reserve(x0_surfaces->size()); -// -// std::array thisOffs; -// std::array thisSizes; -// -// static constexpr std::array stages{ -// boo::PipelineStage::Vertex, -// boo::PipelineStage::Vertex, -// boo::PipelineStage::Fragment, -// boo::PipelineStage::Vertex, -// }; -// -// /* Enumerate surfaces and build data bindings */ -// size_t curReflect = reflectOff + 256; -// for (const CBooSurface& surf : *x0_surfaces) { -// const MaterialSet::Material& mat = x4_matSet->materials.at(surf.m_data.matIdx); -// -// std::array, 12> texs{ -// g_Renderer->m_clearTexture.get(), g_Renderer->m_clearTexture.get(), g_Renderer->m_clearTexture.get(), -// g_Renderer->m_clearTexture.get(), g_Renderer->m_clearTexture.get(), g_Renderer->m_clearTexture.get(), -// g_Renderer->m_whiteTexture.get(), g_Renderer->m_clearTexture.get(), g_Renderer->x220_sphereRamp.get(), -// g_Renderer->x220_sphereRamp.get(), g_Renderer->x220_sphereRamp.get(), g_Renderer->x220_sphereRamp.get(), -// }; -// if (!g_DummyTextures) { -// for (const auto& ch : mat.chunks) { -// if (const auto* const pass = ch.get_if()) { -// auto search = x1c_textures.find(pass->texId.toUint32()); -// boo::ObjToken btex; -// if (search != x1c_textures.cend() && (btex = search->second.GetObj()->GetBooTexture())) { -// texs[MaterialSet::Material::TexMapIdx(pass->type)] = btex; -// } -// } else if (const auto* const pass = ch.get_if()) { -// boo::ObjToken btex = g_Renderer->GetColorTexture(zeus::CColor(pass->color)); -// texs[MaterialSet::Material::TexMapIdx(pass->type)] = btex; -// } -// } -// } -// -// if (m_geomLayout->m_skinBankCount) { -// thisOffs[0] = m_geomLayout->m_skinOffs[surf.m_data.skinMtxBankIdx]; -// thisSizes[0] = m_geomLayout->m_skinSizes[surf.m_data.skinMtxBankIdx]; -// } else { -// thisOffs[0] = 0; -// thisSizes[0] = 256; -// } -// -// thisOffs[1] = m_geomLayout->m_uvOffs[surf.m_data.matIdx]; -// thisSizes[1] = m_geomLayout->m_uvSizes[surf.m_data.matIdx]; -// -// thisOffs[2] = lightOff; -// thisSizes[2] = lightSz; -// -// bool useReflection = mat.flags.samusReflection() || mat.flags.samusReflectionSurfaceEye(); -// if (useReflection) { -// if (g_Renderer->x14c_reflectionTex) -// texs[11] = g_Renderer->x14c_reflectionTex.get(); -// thisOffs[3] = curReflect; -// curReflect += 256; -// } else { -// thisOffs[3] = reflectOff; -// } -// thisSizes[3] = 256; -// -// const CModelShaders::ShaderPipelines& pipelines = m_pipelines->at(surf.m_data.matIdx); -// -// std::vector>& extendeds = newInst.m_shaderDataBindings.emplace_back(); -// extendeds.reserve(pipelines->size()); -// -// EExtendedShader idx{}; -// for (const auto& pipeline : *pipelines) { -// if (idx == EExtendedShader::ThermalModel || idx == EExtendedShader::ThermalModelNoZTestNoZWrite || -// idx == EExtendedShader::ThermalStatic || idx == EExtendedShader::ThermalStaticNoZWrite) { -// texs[8] = g_Renderer->x220_sphereRamp.get(); -// } else if (idx == EExtendedShader::MorphBallShadow) { -// texs[8] = g_Renderer->m_ballShadowId.get(); -// texs[9] = g_Renderer->x220_sphereRamp.get(); -// texs[10] = g_Renderer->m_ballFade.get(); -// } else if (idx == EExtendedShader::WorldShadow || idx == EExtendedShader::LightingCubeReflectionWorldShadow) { -// if (g_shadowMap) -// texs[8] = g_shadowMap; -// else -// texs[8] = g_Renderer->x220_sphereRamp.get(); -// } else if (idx == EExtendedShader::Disintegrate) { -// if (g_disintegrateTexture) -// texs[8] = g_disintegrateTexture; -// else -// texs[8] = g_Renderer->x220_sphereRamp.get(); -// } else if (hecl::com_cubemaps->toBoolean() && (idx == EExtendedShader::LightingCubeReflection || -// idx == EExtendedShader::LightingCubeReflectionWorldShadow)) { -// if (m_lastDrawnReflectionCube) -// texs[11] = m_lastDrawnReflectionCube.get(); -// else -// texs[11] = g_Renderer->x220_sphereRamp.get(); -// } -// extendeds.push_back(ctx.newShaderDataBinding( -// pipeline, newInst.GetBooVBO(*this, ctx), nullptr, m_staticIbo.get(), bufs.size(), bufs.data(), -// stages.data(), thisOffs.data(), thisSizes.data(), texs.size(), texs.data(), nullptr, nullptr)); -// idx = EExtendedShader(size_t(idx) + 1); -// } -// } -// -// return &newInst; -//} - -//void CBooModel::MakeTexturesFromMats(const MaterialSet& matSet, -// std::unordered_map>& toksOut, -// IObjectStore& store) { -// for (const auto& mat : matSet.materials) { -// for (const auto& chunk : mat.chunks) { -// if (const auto* const pass = chunk.get_if()) { -// toksOut.emplace(std::make_pair(pass->texId.toUint32(), store.GetObj({SBIG('TXTR'), pass->texId.toUint32()}))); -// } -// } -// } -//} - -void CBooModel::MakeTexturesFromMats(std::unordered_map>& toksOut, - IObjectStore& store) { -// MakeTexturesFromMats(*x4_matSet, toksOut, store); -} - -void CBooModel::ActivateLights(const std::vector& lights) { m_lightingData.ActivateLights(lights); } - -void CBooModel::DisableAllLights() { - m_lightingData.ambient = zeus::skBlack; - - for (size_t curLight = 0; curLight < m_lightingData.lights.size(); ++curLight) { - CModelShaders::Light& lightOut = m_lightingData.lights[curLight]; - lightOut.color = zeus::skClear; - lightOut.linAtt[0] = 1.f; - lightOut.angAtt[0] = 1.f; - } -} - -void CBooModel::RemapMaterialData(SShader& shader) { - // TODO what is this checking? -// if (!shader.m_geomLayout) -// return; -// x4_matSet = &shader.m_matSet; - x1c_textures = shader.x0_textures; - x40_24_texturesLoaded = false; -} - -bool CBooModel::TryLockTextures() { - if (!x40_24_texturesLoaded) { - bool allLoad = true; - for (auto& tex : x1c_textures) { - tex.second.Lock(); - if (!tex.second.IsLoaded()) { - allLoad = false; - } - } - - // TODO -// if (allLoad) { -// for (const auto& pipeline : *m_pipelines) { -// for (const auto& subpipeline : *pipeline.second) { -// if (!subpipeline->isReady()) { -// allLoad = false; -// break; -// } -// } -// if (!allLoad) { -// break; -// } -// } -// } - - x40_24_texturesLoaded = allLoad; - } - - return x40_24_texturesLoaded; -} - -void CBooModel::UnlockTextures() { -// m_instances.clear(); - - for (auto& tex : x1c_textures) { - tex.second.Unlock(); - } - - x40_24_texturesLoaded = false; -} - -void CBooModel::SyncLoadTextures() { - if (x40_24_texturesLoaded) { - return; - } - - for (auto& tex : x1c_textures) { - tex.second.GetObj(); - } - - x40_24_texturesLoaded = true; -} - -void CBooModel::DrawFlat(ESurfaceSelection sel, EExtendedShader extendedIdx) const { - const CBooSurface* surf; - CModelFlags flags = {}; - flags.m_extendedShader = extendedIdx; - - if (sel != ESurfaceSelection::SortedOnly) { - surf = x38_firstUnsortedSurface; - while (surf) { - DrawSurface(*surf, flags); - surf = surf->m_next; - } - } - - if (sel != ESurfaceSelection::UnsortedOnly) { - surf = x3c_firstSortedSurface; - while (surf) { - DrawSurface(*surf, flags); - surf = surf->m_next; - } - } -} - -void CBooModel::DrawAlphaSurfaces(const CModelFlags& flags) const { - const CBooSurface* surf = x3c_firstSortedSurface; - while (surf) { - DrawSurface(*surf, flags); - surf = surf->m_next; - } -} - -void CBooModel::DrawNormalSurfaces(const CModelFlags& flags) const { - const CBooSurface* surf = x38_firstUnsortedSurface; - while (surf) { - DrawSurface(*surf, flags); - surf = surf->m_next; - } -} - -void CBooModel::DrawSurfaces(const CModelFlags& flags) const { - const CBooSurface* surf = x38_firstUnsortedSurface; - while (surf) { - DrawSurface(*surf, flags); - surf = surf->m_next; - } - - surf = x3c_firstSortedSurface; - while (surf) { - DrawSurface(*surf, flags); - surf = surf->m_next; - } -} - -//static EExtendedShader ResolveExtendedShader(const MaterialSet::Material& data, const CModelFlags& flags) { -// bool noZWrite = flags.m_noZWrite || !data.flags.depthWrite(); -// -// /* Ensure cubemap extension shaders fall back to non-cubemap equivalents if necessary */ -// EExtendedShader intermediateExtended = flags.m_extendedShader; -// if (!com_cubemaps->toBoolean() || g_Renderer->IsThermalVisorHotPass() || g_Renderer->IsThermalVisorActive()) { -// if (intermediateExtended == EExtendedShader::LightingCubeReflection) -// intermediateExtended = EExtendedShader::Lighting; -// else if (intermediateExtended == EExtendedShader::LightingCubeReflectionWorldShadow) -// intermediateExtended = EExtendedShader::WorldShadow; -// } -// -// EExtendedShader extended = EExtendedShader::Flat; -// if (intermediateExtended == EExtendedShader::Lighting) { -// /* Transform lighting into thermal if the thermal visor is active */ -// if (g_Renderer->IsThermalVisorHotPass()) -// return flags.m_noZTest ? EExtendedShader::LightingAlphaWriteNoZTestNoZWrite -// : (noZWrite ? EExtendedShader::ThermalStaticNoZWrite : EExtendedShader::ThermalStatic); -// else if (g_Renderer->IsThermalVisorActive()) -// return EExtendedShader::ThermalCold; -// if (data.blendMode == MaterialSet::Material::BlendMaterial::BlendMode::Opaque) { -// /* Override shader if originally opaque (typical for FRME models) */ -// if (flags.x0_blendMode > 6) { -// if (flags.m_depthGreater) -// extended = EExtendedShader::ForcedAdditiveNoZWriteDepthGreater; -// else -// extended = -// flags.m_noCull -// ? (noZWrite ? EExtendedShader::ForcedAdditiveNoCullNoZWrite : EExtendedShader::ForcedAdditiveNoCull) -// : (noZWrite ? EExtendedShader::ForcedAdditiveNoZWrite : EExtendedShader::ForcedAdditive); -// } else if (flags.x0_blendMode > 4) { -// extended = flags.m_noCull -// ? (noZWrite ? EExtendedShader::ForcedAlphaNoCullNoZWrite : EExtendedShader::ForcedAlphaNoCull) -// : (noZWrite ? EExtendedShader::ForcedAlphaNoZWrite : EExtendedShader::ForcedAlpha); -// } else { -// extended = flags.m_noCull -// ? (noZWrite ? EExtendedShader::ForcedAlphaNoCullNoZWrite : EExtendedShader::ForcedAlphaNoCull) -// : (noZWrite ? EExtendedShader::ForcedAlphaNoZWrite : EExtendedShader::Lighting); -// } -// } else if (flags.m_noCull && noZWrite) { -// /* Substitute no-cull,no-zwrite pipeline if available */ -// if (data.blendMode == MaterialSet::Material::BlendMaterial::BlendMode::Additive) -// extended = EExtendedShader::ForcedAdditiveNoCullNoZWrite; -// else -// extended = EExtendedShader::ForcedAlphaNoCullNoZWrite; -// } else if (flags.m_noCull) { -// /* Substitute no-cull pipeline if available */ -// if (data.blendMode == MaterialSet::Material::BlendMaterial::BlendMode::Additive) -// extended = EExtendedShader::ForcedAdditiveNoCull; -// else -// extended = EExtendedShader::ForcedAlphaNoCull; -// } else if (noZWrite) { -// /* Substitute no-zwrite pipeline if available */ -// if (data.blendMode == MaterialSet::Material::BlendMaterial::BlendMode::Additive) -// extended = EExtendedShader::ForcedAdditiveNoZWrite; -// else -// extended = EExtendedShader::ForcedAlphaNoZWrite; -// } else { -// extended = EExtendedShader::Lighting; -// } -// } else if (intermediateExtended == EExtendedShader::ThermalModel) { -// extended = flags.m_noZTest ? EExtendedShader::ThermalModelNoZTestNoZWrite : EExtendedShader::ThermalModel; -// } else if (intermediateExtended < EExtendedShader::MAX) { -// extended = intermediateExtended; -// } -// -// return extended; -//} - -void CBooModel::DrawSurface(const CBooSurface& surf, const CModelFlags& flags) const { -// if (m_uniUpdateCount == 0 || m_uniUpdateCount > m_instances.size()) -// return; -// const ModelInstance& inst = m_instances[m_uniUpdateCount - 1]; -// -// const MaterialSet::Material& data = GetMaterialByIndex(surf.m_data.matIdx); -// if (data.flags.shadowOccluderMesh() && !g_DrawingOccluders) -// return; -// -// const std::vector>& extendeds = inst.m_shaderDataBindings[surf.selfIdx]; -// EExtendedShader extended = ResolveExtendedShader(data, flags); -// -// boo::ObjToken binding = extendeds[size_t(extended)]; -// CGraphics::SetShaderDataBinding(binding); -// CGraphics::DrawArrayIndexed(surf.m_data.idxStart, surf.m_data.idxCount); -} - -void CBooModel::WarmupDrawSurfaces() const { - const CBooSurface* surf = x38_firstUnsortedSurface; - while (surf) { - WarmupDrawSurface(*surf); - surf = surf->m_next; - } - - surf = x3c_firstSortedSurface; - while (surf) { - WarmupDrawSurface(*surf); - surf = surf->m_next; - } -} - -void CBooModel::WarmupDrawSurface(const CBooSurface& surf) const { -// if (m_uniUpdateCount > m_instances.size()) -// return; -// const ModelInstance& inst = m_instances[m_uniUpdateCount - 1]; -// -// for (const auto& binding : inst.m_shaderDataBindings[surf.selfIdx]) { -// CGraphics::SetShaderDataBinding(binding); -// CGraphics::DrawArrayIndexed(surf.m_data.idxStart, std::min(u32(3), surf.m_data.idxCount)); -// } -} - -//void CBooModel::UVAnimationBuffer::ProcessAnimation(u8*& bufOut, const MaterialSet::Material::PASS& anim) { -// using UVAnimType = MaterialSet::Material::BlendMaterial::UVAnimType; -// if (anim.uvAnimType == UVAnimType::Invalid) -// return; -// zeus::CMatrix4f& texMtxOut = reinterpret_cast(*bufOut); -// zeus::CMatrix4f& postMtxOut = reinterpret_cast(*(bufOut + sizeof(zeus::CMatrix4f))); -// texMtxOut = zeus::CMatrix4f(); -// postMtxOut = zeus::CMatrix4f(); -// switch (anim.uvAnimType) { -// case UVAnimType::MvInvNoTranslation: { -// texMtxOut = CGraphics::g_GXModelViewInvXpose.toMatrix4f(); -// texMtxOut[3].w() = 1.f; -// postMtxOut[0].x() = 0.5f; -// postMtxOut[1].y() = 0.5f; -// postMtxOut[3].x() = 0.5f; -// postMtxOut[3].y() = 0.5f; -// break; -// } -// case UVAnimType::MvInv: { -// texMtxOut = CGraphics::g_GXModelViewInvXpose.toMatrix4f(); -// texMtxOut[3] = CGraphics::g_ViewMatrix.inverse() * CGraphics::g_GXModelMatrix.origin; -// texMtxOut[3].w() = 1.f; -// postMtxOut[0].x() = 0.5f; -// postMtxOut[1].y() = 0.5f; -// postMtxOut[3].x() = 0.5f; -// postMtxOut[3].y() = 0.5f; -// break; -// } -// case UVAnimType::Scroll: { -// texMtxOut[3].x() = CGraphics::GetSecondsMod900() * anim.uvAnimParms[2] + anim.uvAnimParms[0]; -// texMtxOut[3].y() = CGraphics::GetSecondsMod900() * anim.uvAnimParms[3] + anim.uvAnimParms[1]; -// break; -// } -// case UVAnimType::Rotation: { -// float angle = CGraphics::GetSecondsMod900() * anim.uvAnimParms[1] + anim.uvAnimParms[0]; -// float acos = std::cos(angle); -// float asin = std::sin(angle); -// texMtxOut[0].x() = acos; -// texMtxOut[0].y() = asin; -// texMtxOut[1].x() = -asin; -// texMtxOut[1].y() = acos; -// texMtxOut[3].x() = (1.0f - (acos - asin)) * 0.5f; -// texMtxOut[3].y() = (1.0f - (asin + acos)) * 0.5f; -// break; -// } -// case UVAnimType::HStrip: { -// float value = anim.uvAnimParms[0] * anim.uvAnimParms[2] * (anim.uvAnimParms[3] + CGraphics::GetSecondsMod900()); -// texMtxOut[3].x() = std::trunc(anim.uvAnimParms[1] * fmod(value, 1.0f)) * anim.uvAnimParms[2]; -// break; -// } -// case UVAnimType::VStrip: { -// float value = anim.uvAnimParms[0] * anim.uvAnimParms[2] * (anim.uvAnimParms[3] + CGraphics::GetSecondsMod900()); -// texMtxOut[3].y() = std::trunc(anim.uvAnimParms[1] * fmod(value, 1.0f)) * anim.uvAnimParms[2]; -// break; -// } -// case UVAnimType::Model: { -// texMtxOut = CGraphics::g_GXModelMatrix.toMatrix4f(); -// texMtxOut[3] = zeus::CVector4f(0.f, 0.f, 0.f, 1.f); -// postMtxOut[0].x() = 0.5f; -// postMtxOut[1].y() = 0.f; -// postMtxOut[2].y() = 0.5f; -// postMtxOut[3].x() = CGraphics::g_GXModelMatrix.origin.x() * 0.05f; -// postMtxOut[3].y() = CGraphics::g_GXModelMatrix.origin.y() * 0.05f; -// break; -// } -// case UVAnimType::CylinderEnvironment: { -// texMtxOut = CGraphics::g_GXModelViewInvXpose.toMatrix4f(); -// -// const zeus::CVector3f& viewOrigin = CGraphics::g_ViewMatrix.origin; -// float xy = (viewOrigin.x() + viewOrigin.y()) * 0.025f * anim.uvAnimParms[1]; -// xy = (xy - std::trunc(xy)); -// float z = (viewOrigin.z()) * 0.05f * anim.uvAnimParms[1]; -// z = (z - std::trunc(z)); -// -// float halfA = anim.uvAnimParms[0] * 0.5f; -// -// postMtxOut = -// zeus::CTransform(zeus::CMatrix3f(halfA, 0.0, 0.0, 0.0, 0.0, halfA, 0.0, 0.0, 0.0), zeus::CVector3f(xy, z, 1.0)) -// .toMatrix4f(); -// break; -// } -// default: -// break; -// } -// bufOut += sizeof(zeus::CMatrix4f) * 2; -//} -// -//void CBooModel::UVAnimationBuffer::PadOutBuffer(u8*& bufStart, u8*& bufOut) { -// bufOut = bufStart + ROUND_UP_256(bufOut - bufStart); -//} -// -//void CBooModel::UVAnimationBuffer::Update(u8*& bufOut, const MaterialSet* matSet, const CModelFlags& flags, -// const CBooModel* parent) { -// u8* start = bufOut; -// -// if (flags.m_extendedShader == EExtendedShader::MorphBallShadow) { -// /* Special matrices for MorphBall shadow rendering */ -// zeus::CMatrix4f texMtx = (zeus::CTransform::Scale(1.f / (flags.mbShadowBox.max - flags.mbShadowBox.min)) * -// zeus::CTransform::Translate(-flags.mbShadowBox.min) * CGraphics::g_GXModelMatrix) -// .toMatrix4f(); -// for (const MaterialSet::Material& mat : matSet->materials) { -// (void)mat; -// std::array* mtxs = reinterpret_cast*>(bufOut); -// mtxs[0][0] = texMtx; -// mtxs[0][1] = MBShadowPost0; -// mtxs[1][0] = texMtx; -// mtxs[1][1] = MBShadowPost1; -// bufOut += sizeof(zeus::CMatrix4f) * 2 * 8; -// PadOutBuffer(start, bufOut); -// } -// return; -// } else if (flags.m_extendedShader == EExtendedShader::Disintegrate) { -// assert(parent != nullptr && "Parent CBooModel not set"); -// zeus::CTransform xf = zeus::CTransform::RotateX(-zeus::degToRad(45.f)); -// zeus::CAABox aabb = parent->GetAABB().getTransformedAABox(xf); -// xf = zeus::CTransform::Scale(5.f / (aabb.max - aabb.min)) * zeus::CTransform::Translate(-aabb.min) * xf; -// zeus::CMatrix4f texMtx = xf.toMatrix4f(); -// zeus::CMatrix4f post0 = DisintegratePost; -// post0[3].x() = flags.addColor.a(); -// post0[3].y() = 6.f * -(1.f - flags.addColor.a()) + 1.f; -// zeus::CMatrix4f post1 = DisintegratePost; -// post1[3].x() = -0.85f * flags.addColor.a() - 0.15f; -// post1[3].y() = float(post0[3].y()); -// /* Special matrices for disintegration rendering */ -// for (const MaterialSet::Material& mat : matSet->materials) { -// (void)mat; -// std::array* mtxs = reinterpret_cast*>(bufOut); -// mtxs[0][0] = texMtx; -// mtxs[0][1] = post0; -// mtxs[1][0] = texMtx; -// mtxs[1][1] = post1; -// bufOut += sizeof(zeus::CMatrix4f) * 2 * 8; -// PadOutBuffer(start, bufOut); -// } -// return; -// } -// -// std::optional> specialMtxOut; -// if (flags.m_extendedShader == EExtendedShader::ThermalModel || -// flags.m_extendedShader == EExtendedShader::ThermalModelNoZTestNoZWrite || -// flags.m_extendedShader == EExtendedShader::ThermalStatic || -// flags.m_extendedShader == EExtendedShader::ThermalStaticNoZWrite) { -// /* Special Mode0 matrix for exclusive Thermal Visor use */ -// specialMtxOut.emplace(); -// -// zeus::CMatrix4f& texMtxOut = (*specialMtxOut)[0]; -// texMtxOut = CGraphics::g_GXModelViewInvXpose.toMatrix4f(); -// texMtxOut[3].zeroOut(); -// texMtxOut[3].w() = 1.f; -// -// zeus::CMatrix4f& postMtxOut = (*specialMtxOut)[1]; -// postMtxOut[0].x() = 0.5f; -// postMtxOut[1].y() = 0.5f; -// postMtxOut[3].x() = 0.5f; -// postMtxOut[3].y() = 0.5f; -// } else if (flags.m_extendedShader == EExtendedShader::WorldShadow || -// flags.m_extendedShader == EExtendedShader::LightingCubeReflectionWorldShadow) { -// /* Special matrix for mapping world shadow */ -// specialMtxOut.emplace(); -// -// zeus::CMatrix4f mat = g_shadowTexXf.toMatrix4f(); -// zeus::CMatrix4f& texMtxOut = (*specialMtxOut)[0]; -// texMtxOut[0][0] = float(mat[0][0]); -// texMtxOut[1][0] = float(mat[1][0]); -// texMtxOut[2][0] = float(mat[2][0]); -// texMtxOut[3][0] = float(mat[3][0]); -// texMtxOut[0][1] = float(mat[0][2]); -// texMtxOut[1][1] = float(mat[1][2]); -// texMtxOut[2][1] = float(mat[2][2]); -// texMtxOut[3][1] = float(mat[3][2]); -// } -// -// for (const MaterialSet::Material& mat : matSet->materials) { -// if (specialMtxOut) { -// std::array* mtxs = reinterpret_cast*>(bufOut); -// mtxs[7][0] = (*specialMtxOut)[0]; -// mtxs[7][1] = (*specialMtxOut)[1]; -// } -// u8* bufOrig = bufOut; -// for (const auto& chunk : mat.chunks) { -// if (const auto* const pass = chunk.get_if()) { -// ProcessAnimation(bufOut, *pass); -// } -// } -// bufOut = bufOrig + sizeof(zeus::CMatrix4f) * 2 * 8; -// PadOutBuffer(start, bufOut); -// } -//} - -//void GeometryUniformLayout::Update(const CModelFlags& flags, const CSkinRules* cskr, const CPoseAsTransforms* pose, -// const MaterialSet* matSet, const boo::ObjToken& buf, -// const CBooModel* parent) const { -// u8* dataOut = reinterpret_cast(buf->map(m_geomBufferSize)); -// u8* dataCur = dataOut; -// -// if (m_skinBankCount) { -// /* Skinned */ -// std::vector bankTransforms; -// size_t weightCount = m_weightVecCount * 4; -// bankTransforms.reserve(weightCount); -// for (size_t i = 0; i < m_skinBankCount; ++i) { -// if (cskr && pose) { -// cskr->GetBankTransforms(bankTransforms, *pose, i); -// -// for (size_t w = 0; w < weightCount; ++w) { -// zeus::CMatrix4f& obj = reinterpret_cast(*dataCur); -// if (w >= bankTransforms.size()) -// obj = zeus::CMatrix4f(); -// else -// obj = bankTransforms[w]->toMatrix4f(); -// dataCur += sizeof(zeus::CMatrix4f); -// } -// for (size_t w = 0; w < weightCount; ++w) { -// zeus::CMatrix4f& objInv = reinterpret_cast(*dataCur); -// if (w >= bankTransforms.size()) -// objInv = zeus::CMatrix4f(); -// else -// objInv = bankTransforms[w]->basis; -// dataCur += sizeof(zeus::CMatrix4f); -// } -// -// bankTransforms.clear(); -// } else { -// for (size_t w = 0; w < weightCount; ++w) { -// zeus::CMatrix4f& mv = reinterpret_cast(*dataCur); -// mv = zeus::CMatrix4f(); -// dataCur += sizeof(zeus::CMatrix4f); -// } -// for (size_t w = 0; w < weightCount; ++w) { -// zeus::CMatrix4f& mvinv = reinterpret_cast(*dataCur); -// mvinv = zeus::CMatrix4f(); -// dataCur += sizeof(zeus::CMatrix4f); -// } -// } -// zeus::CMatrix4f& mv = reinterpret_cast(*dataCur); -// mv = CGraphics::g_GXModelView.toMatrix4f(); -// dataCur += sizeof(zeus::CMatrix4f); -// -// zeus::CMatrix4f& mvinv = reinterpret_cast(*dataCur); -// mvinv = CGraphics::g_GXModelViewInvXpose.toMatrix4f(); -// dataCur += sizeof(zeus::CMatrix4f); -// -// zeus::CMatrix4f& proj = reinterpret_cast(*dataCur); -// proj = CGraphics::GetPerspectiveProjectionMatrix(true); -// dataCur += sizeof(zeus::CMatrix4f); -// -// dataCur = dataOut + ROUND_UP_256(dataCur - dataOut); -// } -// } else { -// /* Non-Skinned */ -// zeus::CMatrix4f& mv = reinterpret_cast(*dataCur); -// mv = CGraphics::g_GXModelView.toMatrix4f(); -// dataCur += sizeof(zeus::CMatrix4f); -// -// zeus::CMatrix4f& mvinv = reinterpret_cast(*dataCur); -// mvinv = CGraphics::g_GXModelViewInvXpose.toMatrix4f(); -// dataCur += sizeof(zeus::CMatrix4f); -// -// zeus::CMatrix4f& proj = reinterpret_cast(*dataCur); -// proj = CGraphics::GetPerspectiveProjectionMatrix(true); -// dataCur += sizeof(zeus::CMatrix4f); -// -// dataCur = dataOut + ROUND_UP_256(dataCur - dataOut); -// } -// -// CBooModel::UVAnimationBuffer::Update(dataCur, matSet, flags, parent); -// buf->unmap(); -//} - -//void GeometryUniformLayout::ReserveSharedBuffers(boo::IGraphicsDataFactory::Context& ctx, int size) { -// if (m_sharedBuffer.size() < size) -// m_sharedBuffer.resize(size); -// for (int i = 0; i < size; ++i) { -// auto& buf = m_sharedBuffer[i]; -// if (!buf) -// buf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, m_geomBufferSize, 1); -// } -//} -// -//boo::ObjToken GeometryUniformLayout::GetSharedBuffer(int idx) const { -// if (idx >= m_sharedBuffer.size()) -// m_sharedBuffer.resize(idx + 1); -// -// auto& buf = m_sharedBuffer[idx]; -// if (!buf) { -// CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { -// buf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, m_geomBufferSize, 1); -// return true; -// } BooTrace); -// } -// -// return buf; -//} - -//boo::ObjToken CBooModel::UpdateUniformData(const CModelFlags& flags, const CSkinRules* cskr, -// const CPoseAsTransforms* pose, int sharedLayoutBuf) { -// OPTICK_EVENT(); -//// if (!g_DummyTextures && !TryLockTextures()) -// return {}; -// -//// /* Invalidate instances if new shadow being drawn */ -//// if ((flags.m_extendedShader == EExtendedShader::WorldShadow || -//// flags.m_extendedShader == EExtendedShader::LightingCubeReflectionWorldShadow) && -//// m_lastDrawnShadowMap != g_shadowMap) { -//// m_lastDrawnShadowMap = g_shadowMap; -//// m_instances.clear(); -//// } -//// -//// /* Invalidate instances if new one-texture being drawn */ -//// if (flags.m_extendedShader == EExtendedShader::Disintegrate && m_lastDrawnOneTexture != g_disintegrateTexture) { -//// m_lastDrawnOneTexture = g_disintegrateTexture; -//// m_instances.clear(); -//// } -//// -//// /* Invalidate instances if new reflection cube being drawn */ -//// if (hecl::com_cubemaps->toBoolean() && -//// (flags.m_extendedShader == EExtendedShader::LightingCubeReflection || -//// flags.m_extendedShader == EExtendedShader::LightingCubeReflectionWorldShadow) && -//// m_lastDrawnReflectionCube != g_reflectionCube) { -//// m_lastDrawnReflectionCube = g_reflectionCube; -//// m_instances.clear(); -//// } -// -//// const ModelInstance* inst; -//// if (sharedLayoutBuf >= 0) { -//// if (m_instances.size() <= sharedLayoutBuf) { -//// do { -//// inst = PushNewModelInstance(m_instances.size(), ctx); -//// if (!inst) { -//// return {}; -//// } -//// } while (m_instances.size() <= sharedLayoutBuf); -//// } else { -//// inst = &m_instances[sharedLayoutBuf]; -//// } -//// m_uniUpdateCount = sharedLayoutBuf + 1; -//// } else { -//// if (m_instances.size() <= m_uniUpdateCount) { -//// inst = PushNewModelInstance(sharedLayoutBuf, ctx); -//// if (!inst) { -//// return {}; -//// } -//// } else { -//// inst = &m_instances[m_uniUpdateCount]; -//// } -//// ++m_uniUpdateCount; -//// } -//// -//// if (inst->m_geomUniformBuffer) { -//// m_geomLayout->Update(flags, cskr, pose, x4_matSet, inst->m_geomUniformBuffer, this); -//// } -//// -//// u8* dataOut = reinterpret_cast(inst->m_uniformBuffer->map(m_uniformDataSize)); -//// u8* dataCur = dataOut; -//// -//// if (flags.m_extendedShader == EExtendedShader::ThermalModel || -//// flags.m_extendedShader == EExtendedShader::ThermalModelNoZTestNoZWrite) /* Thermal Model (same as UV Mode 0) */ -//// { -//// CModelShaders::ThermalUniform& thermalOut = *reinterpret_cast(dataCur); -//// thermalOut.mulColor = flags.x4_color; -//// thermalOut.addColor = flags.addColor; -//// } else if (flags.m_extendedShader >= EExtendedShader::SolidColor && -//// flags.m_extendedShader <= EExtendedShader::SolidColorBackfaceCullGreaterAlphaOnly) /* Solid color render */ -//// { -//// CModelShaders::SolidUniform& solidOut = *reinterpret_cast(dataCur); -//// solidOut.solidColor = flags.x4_color; -//// } else if (flags.m_extendedShader == EExtendedShader::MorphBallShadow) /* MorphBall shadow render */ -//// { -//// CModelShaders::MBShadowUniform& shadowOut = *reinterpret_cast(dataCur); -//// shadowOut.shadowUp = CGraphics::g_GXModelView.rotate(zeus::skUp); -//// shadowOut.shadowUp.w() = flags.x4_color.a(); -//// shadowOut.shadowId = flags.x4_color.r(); -//// } else if (flags.m_extendedShader == EExtendedShader::Disintegrate) { -//// CModelShaders::OneTextureUniform& oneTexOut = *reinterpret_cast(dataCur); -//// oneTexOut.addColor = flags.addColor; -//// oneTexOut.fog = CGraphics::g_Fog; -//// } else { -//// CModelShaders::LightingUniform& lightingOut = *reinterpret_cast(dataCur); -//// lightingOut = m_lightingData; -//// lightingOut.colorRegs = CGraphics::g_ColorRegs; -//// lightingOut.mulColor = flags.x4_color; -//// lightingOut.addColor = flags.addColor; -//// lightingOut.fog = CGraphics::g_Fog; -//// } -//// -//// dataCur += sizeof(CModelShaders::LightingUniform); -//// dataCur = dataOut + ROUND_UP_256(dataCur - dataOut); -//// -//// /* Reflection texmtx uniform */ -//// zeus::CMatrix4f* identMtxs = reinterpret_cast(dataCur); -//// identMtxs[0] = zeus::CMatrix4f(); -//// identMtxs[1] = zeus::CMatrix4f(); -//// u8* curReflect = dataCur + 256; -//// for (const CBooSurface& surf : *x0_surfaces) { -//// const MaterialSet::Material& mat = x4_matSet->materials.at(surf.m_data.matIdx); -//// if (mat.flags.samusReflection() || mat.flags.samusReflectionSurfaceEye()) { -//// zeus::CMatrix4f* mtxs = reinterpret_cast(curReflect); -//// float& alpha = reinterpret_cast(mtxs[2]); -//// curReflect += 256; -//// EnsureViewDepStateCached(*this, mat.flags.samusReflectionSurfaceEye() ? &surf : nullptr, mtxs, alpha); -//// } -//// } -//// -//// inst->m_uniformBuffer->unmap(); -//// return inst->m_dynamicVbo; -//} - -void CBooModel::DrawAlpha(const CModelFlags& flags, const CSkinRules* cskr, const CPoseAsTransforms* pose) { - CModelFlags rFlags = flags; - /* Check if we're overriding with RenderModelBlack */ - if (g_RenderModelBlack) { - rFlags.m_extendedShader = EExtendedShader::SolidColor; - rFlags.x4_color = zeus::skBlack; - } - - if (TryLockTextures()) { - // TODO? -// UpdateUniformData(rFlags, cskr, pose); - DrawAlphaSurfaces(rFlags); - } -} - -void CBooModel::DrawNormal(const CModelFlags& flags, const CSkinRules* cskr, const CPoseAsTransforms* pose) { - CModelFlags rFlags = flags; - /* Check if we're overriding with RenderModelBlack */ - if (g_RenderModelBlack) { - rFlags.m_extendedShader = EExtendedShader::SolidColor; - rFlags.x4_color = zeus::skBlack; - } - if (TryLockTextures()) { - // TODO? -// UpdateUniformData(rFlags, cskr, pose); - DrawNormalSurfaces(rFlags); - } -} - -void CBooModel::Draw(const CModelFlags& flags, const CSkinRules* cskr, const CPoseAsTransforms* pose) { - CModelFlags rFlags = flags; - /* Check if we're overriding with RenderModelBlack */ - if (g_RenderModelBlack) { - rFlags.m_extendedShader = EExtendedShader::SolidColor; - rFlags.x4_color = zeus::skBlack; - } - - if (TryLockTextures()) { - // TODO? -// UpdateUniformData(rFlags, cskr, pose); - DrawSurfaces(rFlags); - } -} - -static const u8* MemoryFromPartData(const u8*& dataCur, const u32*& secSizeCur) { - const u8* ret; - if (*secSizeCur != 0) - ret = dataCur; - else - ret = nullptr; - - dataCur += CBasics::SwapBytes(*secSizeCur); - ++secSizeCur; - return ret; -} - -std::unique_ptr CModel::MakeNewInstance(int shaderIdx, bool lockParent) { - if (shaderIdx >= x18_matSets.size()) - shaderIdx = 0; - auto ret = std::make_unique(m_selfToken, this, &x8_surfaces, x18_matSets[shaderIdx], //m_staticVbo, m_ibo, - m_aabb, (m_flags & 0x2) != 0); - if (lockParent) - ret->LockParent(); - return ret; -} - -//CModelShaders::ShaderPipelines SShader::BuildShader(const hecl::HMDLMeta& meta, const MaterialSet::Material& mat) { -// OPTICK_EVENT(); -// hecl::Backend::ReflectionType reflectionType; -// if (mat.flags.samusReflectionIndirectTexture()) -// reflectionType = hecl::Backend::ReflectionType::Indirect; -// else if (mat.flags.samusReflection() || mat.flags.samusReflectionSurfaceEye()) -// reflectionType = hecl::Backend::ReflectionType::Simple; -// else -// reflectionType = hecl::Backend::ReflectionType::None; -// hecl::Backend::ShaderTag tag(mat.hash, meta.colorCount, meta.uvCount, meta.weightCount, meta.weightCount * 4, -// boo::Primitive(meta.topology), reflectionType, true, true, true, mat.flags.alphaTest()); -// return CModelShaders::BuildExtendedShader(tag, mat); -//} -// -//void SShader::BuildShaders(const hecl::HMDLMeta& meta, -// std::unordered_map& shaders) { -// shaders.reserve(m_matSet.materials.size()); -// int idx = 0; -// for (const MaterialSet::Material& mat : m_matSet.materials) -// shaders[idx++] = BuildShader(meta, mat); -//} - -CModel::CModel(std::unique_ptr&& in, u32 /* dataLen */, IObjectStore* store, CObjectReference* selfRef) -: m_selfToken(selfRef) { - x38_lastFrame = CGraphics::GetFrameCounter() - 2; - std::unique_ptr data = std::move(in); - - u32 version = CBasics::SwapBytes(*reinterpret_cast(data.get() + 0x4)); - m_flags = CBasics::SwapBytes(*reinterpret_cast(data.get() + 0x8)); - if (version != 0x10002) { - spdlog::error("invalid CMDL for loading with boo"); - return; - } - - u32 secCount = CBasics::SwapBytes(*reinterpret_cast(data.get() + 0x24)); - u32 matSetCount = CBasics::SwapBytes(*reinterpret_cast(data.get() + 0x28)); - x18_matSets.reserve(matSetCount); - const u8* dataCur = data.get() + ROUND_UP_32(0x2c + secCount * 4); - const u32* secSizeCur = reinterpret_cast(data.get() + 0x2c); - for (u32 i = 0; i < matSetCount; ++i) { - const u32 matSetSz = CBasics::SwapBytes(*secSizeCur); - const u8* sec = MemoryFromPartData(dataCur, secSizeCur); - SShader& shader = x18_matSets.emplace_back(i); -// athena::io::MemoryReader r(sec, matSetSz); -// shader.m_matSet.read(r); -// CBooModel::MakeTexturesFromMats(shader.m_matSet, shader.x0_textures, *store); - } - - { - u32 hmdlSz = CBasics::SwapBytes(*secSizeCur); - const u8* hmdlMetadata = MemoryFromPartData(dataCur, secSizeCur); -// athena::io::MemoryReader r(hmdlMetadata, hmdlSz); -// m_hmdlMeta.read(r); - } - - const u8* vboData = MemoryFromPartData(dataCur, secSizeCur); - const u8* iboData = MemoryFromPartData(dataCur, secSizeCur); - const u8* surfInfo = MemoryFromPartData(dataCur, secSizeCur); - -// for (SShader& matSet : x18_matSets) { -// matSet.InitializeLayout(this); -// matSet.BuildShaders(m_hmdlMeta); -// } - -// CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { -// /* Index buffer is always static */ -// if (m_hmdlMeta.indexCount) -// m_ibo = ctx.newStaticBuffer(boo::BufferUse::Index, iboData, 4, m_hmdlMeta.indexCount); -// -// if (!m_hmdlMeta.bankCount) { -// /* Non-skinned models use static vertex buffers shared with CBooModel instances */ -// if (m_hmdlMeta.vertCount) -// m_staticVbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, vboData, m_hmdlMeta.vertStride, m_hmdlMeta.vertCount); -// } else { -// /* Skinned models use per-instance dynamic buffers for vertex manipulation effects */ -// size_t vboSz = m_hmdlMeta.vertStride * m_hmdlMeta.vertCount; -// if (vboSz) { -// m_dynamicVertexData.reset(new uint8_t[vboSz]); -// memmove(m_dynamicVertexData.get(), vboData, vboSz); -// } -// } -// -// return true; -// } BooTrace); - - const u32 surfCount = CBasics::SwapBytes(*reinterpret_cast(surfInfo)); - x8_surfaces.reserve(surfCount); - for (u32 i = 0; i < surfCount; ++i) { - const u32 surfSz = CBasics::SwapBytes(*secSizeCur); - const u8* sec = MemoryFromPartData(dataCur, secSizeCur); - CBooSurface& surf = x8_surfaces.emplace_back(); - surf.selfIdx = i; -// athena::io::MemoryReader r(sec, surfSz); -// surf.m_data.read(r); - } - - const float* aabbPtr = reinterpret_cast(data.get() + 0xc); - m_aabb = zeus::CAABox(CBasics::SwapBytes(aabbPtr[0]), CBasics::SwapBytes(aabbPtr[1]), CBasics::SwapBytes(aabbPtr[2]), CBasics::SwapBytes(aabbPtr[3]), - CBasics::SwapBytes(aabbPtr[4]), CBasics::SwapBytes(aabbPtr[5])); - x28_modelInst = MakeNewInstance(0, false); -} - -void SShader::UnlockTextures() { - for (auto& tex : x0_textures) - tex.second.Unlock(); -} - -void CBooModel::VerifyCurrentShader(int shaderIdx) { - if (shaderIdx != m_matSetIdx && m_model) - RemapMaterialData(m_model->x18_matSets[shaderIdx]); -} - -void CBooModel::Touch(int shaderIdx) { - VerifyCurrentShader(shaderIdx); - TryLockTextures(); -} - -void CModel::DrawSortedParts(const CModelFlags& flags) const { - x28_modelInst->VerifyCurrentShader(flags.x1_matSetIdx); - x28_modelInst->DrawAlpha(flags, nullptr, nullptr); -} - -void CModel::DrawUnsortedParts(const CModelFlags& flags) const { - x28_modelInst->VerifyCurrentShader(flags.x1_matSetIdx); - x28_modelInst->DrawNormal(flags, nullptr, nullptr); -} - -void CModel::Draw(const CModelFlags& flags) const { - x28_modelInst->VerifyCurrentShader(flags.x1_matSetIdx); - x28_modelInst->Draw(flags, nullptr, nullptr); -} - -bool CModel::IsLoaded(int shaderIdx) const { - x28_modelInst->VerifyCurrentShader(shaderIdx); - return x28_modelInst->TryLockTextures(); -} - -size_t CModel::GetPoolVertexOffset(size_t idx) const { -// return m_hmdlMeta.vertStride * idx; - return 0; -} - -zeus::CVector3f CModel::GetPoolVertex(size_t idx) const { - const auto* floats = reinterpret_cast(m_dynamicVertexData.get() + GetPoolVertexOffset(idx)); - return {floats}; -} - -size_t CModel::GetPoolNormalOffset(size_t idx) const { -// return m_hmdlMeta.vertStride * idx + 12; - return 0; -} - -zeus::CVector3f CModel::GetPoolNormal(size_t idx) const { - const auto* floats = reinterpret_cast(m_dynamicVertexData.get() + GetPoolNormalOffset(idx)); - return {floats}; -} - -//void CModel::ApplyVerticesCPU(const boo::ObjToken& vertBuf, -// const std::vector>& vn) const { -// u8* data = reinterpret_cast(vertBuf->map(m_hmdlMeta.vertStride * m_hmdlMeta.vertCount)); -// for (u32 i = 0; i < std::min(u32(vn.size()), m_hmdlMeta.vertCount); ++i) { -// const std::pair& avn = vn[i]; -// float* floats = reinterpret_cast(data + GetPoolVertexOffset(i)); -// floats[0] = avn.first.x(); -// floats[1] = avn.first.y(); -// floats[2] = avn.first.z(); -// floats[3] = avn.second.x(); -// floats[4] = avn.second.y(); -// floats[5] = avn.second.z(); -// } -// vertBuf->unmap(); -//} -// -//void CModel::RestoreVerticesCPU(const boo::ObjToken& vertBuf) const { -// size_t size = m_hmdlMeta.vertStride * m_hmdlMeta.vertCount; -// u8* data = reinterpret_cast(vertBuf->map(size)); -// memcpy(data, m_dynamicVertexData.get(), size); -// vertBuf->unmap(); -//} - -CFactoryFnReturn FPCModelFactory(const metaforce::SObjectTag& tag, std::unique_ptr&& in, u32 len, - const metaforce::CVParamTransfer& vparms, CObjectReference* selfRef) { - CSimplePool* sp = vparms.GetOwnedObj(); - CFactoryFnReturn ret = TToken::GetIObjObjectFor(std::make_unique(std::move(in), len, sp, selfRef)); - return ret; -} - -} // namespace metaforce diff --git a/Runtime/Graphics/CMoviePlayer.cpp b/Runtime/Graphics/CMoviePlayer.cpp index 978888ef8..233988043 100644 --- a/Runtime/Graphics/CMoviePlayer.cpp +++ b/Runtime/Graphics/CMoviePlayer.cpp @@ -48,13 +48,9 @@ static void MyTHPGXYuv2RgbSetup(bool interlaced2ndFrame, bool fieldFlip) { if (!fieldFlip) { CGX::SetNumTexGens(3); CGX::SetTexCoordGen(GX_TEXCOORD2, GX_TG_MTX2x4, GX_TG_POS, GX_TEXMTX0, false, GX_PTIDENTITY); - aurora::Mat4x2 mtx; - mtx.m0.x = 0.125f; - mtx.m2.y = 0.25f; - if (interlaced2ndFrame) { - mtx.m3.y = 0.25f; - } - GXLoadTexMtxImm(&mtx, GX_TEXMTX0, GX_MTX2x4); + float n = interlaced2ndFrame ? 0.25f : 0.f; + float mtx[8] = {0.125f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.25f, n}; + GXLoadTexMtxImm(mtx, GX_TEXMTX0, GX_MTX2x4); GXTexObj texObj; GXInitTexObj(&texObj, InterlaceTex.data(), 8, 4, GX_TF_I8, GX_REPEAT, GX_REPEAT, false); GXInitTexObjLOD(&texObj, GX_NEAR, GX_NEAR, 0.f, 0.f, 0.f, false, false, GX_ANISO_1); @@ -567,7 +563,7 @@ void CMoviePlayer::DrawFrame(const zeus::CVector3f& v1, const zeus::CVector3f& v /* ensure second field is being displayed by VI to signal advance * (faked in metaforce with continuous xor) */ - if (xfc_fieldIndex == 0 && CGraphics::g_LastFrameUsedAbove) + if (xfc_fieldIndex == 0 && CGraphics::mLastFrameUsedAbove) xf4_26_fieldFlip = true; ++xfc_fieldIndex; diff --git a/Runtime/Graphics/CRainSplashGenerator.cpp b/Runtime/Graphics/CRainSplashGenerator.cpp index 468ee4613..77b89bcd1 100644 --- a/Runtime/Graphics/CRainSplashGenerator.cpp +++ b/Runtime/Graphics/CRainSplashGenerator.cpp @@ -22,13 +22,13 @@ void CRainSplashGenerator::SSplashLine::Draw(float alpha, float dt, const zeus:: float delta = dt * xc_speed; float vt = std::max(0.f, x0_t - delta * x15_length); auto vertCount = u32((x0_t - vt) / delta + 1.f); - m_renderer.Reset(); + // m_renderer.Reset(); for (u32 i = 0; i < vertCount; ++i) { float vertAlpha = vt * alpha; zeus::CVector3f vec(vt * x4_xEnd, vt * x8_yEnd, -4.f * vt * (vt - 1.f) * x10_zParabolaHeight); vec += pos; vt += delta; - m_renderer.AddVertex(vec, zeus::CColor(1.f, vertAlpha), 1); + // m_renderer.AddVertex(vec, zeus::CColor(1.f, vertAlpha), 1); } // m_renderer.Render(g_Renderer->IsThermalVisorHotPass()); } @@ -70,7 +70,7 @@ void CRainSplashGenerator::Draw(const zeus::CTransform& xf) { DoDraw(xf); } -CRainSplashGenerator::SSplashLine::SSplashLine() : m_renderer(CLineRenderer::EPrimitiveMode::LineStrip, 3, {}, false) {} +CRainSplashGenerator::SSplashLine::SSplashLine() {} CRainSplashGenerator::SRainSplash::SRainSplash() { for (size_t i = 0; i < x0_lines.capacity(); ++i) { @@ -146,13 +146,16 @@ void CRainSplashGenerator::Update(float dt, CStateManager& mgr) { } u32 CRainSplashGenerator::GetNextBestPt(u32 pt, const SSkinningWorkspace& workspace, CRandom16& rand, float minZ) { - const auto& refVert = workspace.m_vertexWorkspace[pt]; + const auto& refVertA = workspace.m_vertexWorkspace[pt]; + const zeus::CVector3f refVert{refVertA.x, refVertA.y, refVertA.z}; float maxDist = 0.f; u32 nextPt = pt; for (int i = 0; i < 3; ++i) { const auto idx = u32(rand.Range(0, int(workspace.m_vertexWorkspace.size() - 1))); - const auto& vert = workspace.m_vertexWorkspace[idx]; - const auto& norm = workspace.m_normalWorkspace[idx]; + const auto& vertA = workspace.m_vertexWorkspace[idx]; + const zeus::CVector3f vert{vertA.x, vertA.y, vertA.z}; + const auto& normA = workspace.m_normalWorkspace[idx]; + const zeus::CVector3f norm{normA.x, normA.y, normA.z}; const float distSq = (refVert - vert).magSquared(); if (distSq > maxDist && norm.dot(zeus::skUp) >= 0.f && (vert.z() <= 0.f || vert.z() > minZ)) { nextPt = idx; @@ -185,7 +188,8 @@ void CRainSplashGenerator::GeneratePoints(const SSkinningWorkspace& workspace) { if (x40_queueSize >= x0_rainSplashes.size()) break; x34_curPoint = GetNextBestPt(x34_curPoint, workspace, x10_random, x2c_minZ); - AddPoint(x14_scale * workspace.m_vertexWorkspace[x34_curPoint]); + const auto& vert = workspace.m_vertexWorkspace[x34_curPoint]; + AddPoint(x14_scale * zeus::CVector3f{vert.x, vert.y, vert.z}); } x20_generateTimer = 0.f; } diff --git a/Runtime/Graphics/CRainSplashGenerator.hpp b/Runtime/Graphics/CRainSplashGenerator.hpp index 41e6cffa5..ed2c915b7 100644 --- a/Runtime/Graphics/CRainSplashGenerator.hpp +++ b/Runtime/Graphics/CRainSplashGenerator.hpp @@ -6,7 +6,6 @@ #include "Runtime/CRandom16.hpp" #include "Runtime/RetroTypes.hpp" #include "Runtime/rstl.hpp" -#include "Runtime/Graphics/CLineRenderer.hpp" #include "Runtime/Graphics/CSkinnedModel.hpp" #include @@ -24,7 +23,7 @@ class CRainSplashGenerator { u8 x14_ = 3; u8 x15_length = 1; bool x16_active = true; // used to be one-bit bitfield - CLineRenderer m_renderer; + explicit SSplashLine(); void Update(float dt, CStateManager& mgr); void Draw(float alpha, float dt, const zeus::CVector3f& pos); diff --git a/Runtime/Graphics/CSimpleShadow.cpp b/Runtime/Graphics/CSimpleShadow.cpp index ceb2f37f0..9c99e8cb8 100644 --- a/Runtime/Graphics/CSimpleShadow.cpp +++ b/Runtime/Graphics/CSimpleShadow.cpp @@ -40,7 +40,7 @@ void CSimpleShadow::Render(TLockedToken& tex) { CGraphics::SetDepthWriteMode(true, ERglEnum::LEqual, false); CGraphics::SetBlendMode(ERglBlendMode::Blend, ERglBlendFactor::SrcAlpha, ERglBlendFactor::InvSrcAlpha, ERglLogicOp::Clear); - CGraphics::StreamBegin(GX_QUADS); + CGraphics::StreamBegin(ERglPrimitive::Quads); float radius = x34_radius * x30_scale; CGraphics::StreamColor(zeus::CColor{1.f, x3c_heightAlpha * x38_userAlpha}); CGraphics::StreamTexcoord(0.f, 0.f); diff --git a/Runtime/Graphics/CSkinnedModel.cpp b/Runtime/Graphics/CSkinnedModel.cpp index d78ffa6ff..2c61e2073 100644 --- a/Runtime/Graphics/CSkinnedModel.cpp +++ b/Runtime/Graphics/CSkinnedModel.cpp @@ -68,28 +68,28 @@ void CSkinnedModel::Draw(TConstVectorRef verts, TConstVectorRef norms, const CMo void CSkinnedModel::Draw(const CModelFlags& drawFlags) { if (x35_disableWorkspaces) { - const auto mtx = CGraphics::g_GXModelMatrix; + const auto mtx = CGraphics::mModelMatrix; CGraphics::SetModelMatrix(mtx * x10_skinRules->x0_bones.front().x20_xf); x4_model->Draw(drawFlags); CGraphics::SetModelMatrix(mtx); } else if (m_workspace.IsEmpty()) { x4_model->Draw(drawFlags); } else { - x4_model->Draw(&m_workspace.m_vertexWorkspace, &m_workspace.m_normalWorkspace, drawFlags); + x4_model->Draw(m_workspace.m_vertexWorkspace, m_workspace.m_normalWorkspace, drawFlags); // PostDrawFunc(); } } void CSkinnedModel::DoDrawCallback(const FCustomDraw& func) const { if (x35_disableWorkspaces) { - const auto mtx = CGraphics::g_GXModelMatrix; + const auto mtx = CGraphics::mModelMatrix; CGraphics::SetModelMatrix(mtx * x10_skinRules->x0_bones.front().x20_xf); func(x4_model->GetPositions(), x4_model->GetNormals()); CGraphics::SetModelMatrix(mtx); } else if (m_workspace.IsEmpty()) { func(x4_model->GetPositions(), x4_model->GetNormals()); } else { - func(&m_workspace.m_vertexWorkspace, &m_workspace.m_normalWorkspace); + func(m_workspace.m_vertexWorkspace, m_workspace.m_normalWorkspace); // PostDrawFunc(); } } @@ -102,33 +102,37 @@ CSkinnedModelWithAvgNormals::CSkinnedModelWithAvgNormals(IObjectStore& store, CA CAssetId layoutInfo) : CSkinnedModel(store, model, skinRules, layoutInfo) { const auto vertexCount = GetSkinRules()->GetVertexCount(); - const auto& modelPositions = *GetModel()->GetPositions(); + const auto modelPositions = GetModel()->GetPositions(); x40_averagedNormals.resize(vertexCount); std::vector>> vertMap; for (int vertIdx = 0; vertIdx < vertexCount; ++vertIdx) { - const auto curPos = modelPositions[vertIdx]; + const auto curPosV = modelPositions[vertIdx]; + const zeus::CVector3f curPos{curPosV.x, curPosV.y, curPosV.z}; if (std::find_if(vertMap.cbegin(), vertMap.cend(), [=](const auto& pair) { return pair.first.isEqu(curPos); }) == vertMap.cend()) { auto& [_, list] = vertMap.emplace_back(curPos, std::list{}); for (int idx = vertIdx; idx < vertexCount; ++idx) { // Originally uses ==, but adjusted to match above - if (modelPositions[idx].isEqu(curPos)) { + const auto& mpv = modelPositions[idx]; + const zeus::CVector3f mpz{mpv.x, mpv.y, mpv.z}; + if (mpz.isEqu(curPos)) { list.emplace_back(idx); } } } } - const auto& modelNormals = *GetModel()->GetNormals(); + const auto& modelNormals = GetModel()->GetNormals(); for (const auto& [_, idxs] : vertMap) { zeus::CVector3f averagedNormal; for (const auto idx : idxs) { - averagedNormal += modelNormals[idx]; + const auto& mnv = modelNormals[idx]; + averagedNormal += zeus::CVector3f{mnv.x, mnv.y, mnv.z}; } averagedNormal.normalize(); for (const auto idx : idxs) { - x40_averagedNormals[idx] = averagedNormal; + x40_averagedNormals[idx] = {averagedNormal.x(), averagedNormal.y(), averagedNormal.z()}; } } } diff --git a/Runtime/Graphics/CSkinnedModel.hpp b/Runtime/Graphics/CSkinnedModel.hpp index cad58db5a..6a212b054 100644 --- a/Runtime/Graphics/CSkinnedModel.hpp +++ b/Runtime/Graphics/CSkinnedModel.hpp @@ -20,8 +20,8 @@ class IObjectStore; // Originally vert + normal workspaces were allocated together, but here separated for ease of use struct SSkinningWorkspace { - std::vector m_vertexWorkspace; - std::vector m_normalWorkspace; + std::vector> m_vertexWorkspace; + std::vector> m_normalWorkspace; SSkinningWorkspace(const CSkinRules& rules) { Reset(rules); } void Reset(const CSkinRules& rules) { @@ -83,13 +83,13 @@ public: }; class CSkinnedModelWithAvgNormals : public CSkinnedModel { - std::vector x40_averagedNormals; // was rstl::auto_ptr + std::vector> x40_averagedNormals; // was rstl::auto_ptr public: CSkinnedModelWithAvgNormals(IObjectStore& store, CAssetId model, CAssetId skinRules, CAssetId layoutInfo); ~CSkinnedModelWithAvgNormals() override = default; - TConstVectorRef GetAveragedNormals() const { return &x40_averagedNormals; } + TConstVectorRef GetAveragedNormals() const { return x40_averagedNormals; } }; } // namespace metaforce diff --git a/Runtime/Graphics/CTexture.hpp.old b/Runtime/Graphics/CTexture.hpp.old deleted file mode 100644 index 1cf50baf7..000000000 --- a/Runtime/Graphics/CTexture.hpp.old +++ /dev/null @@ -1,116 +0,0 @@ -#pragma once - -#include -#include - -#include "Runtime/CFactoryMgr.hpp" -#include "Runtime/GCNTypes.hpp" -#include "Runtime/Graphics/CGraphics.hpp" -#include "Runtime/IObj.hpp" -#include "Runtime/Streams/IOStreams.hpp" -#include "Runtime/Graphics/CGraphicsPalette.hpp" - -namespace metaforce { -class CVParamTransfer; -class CTextureInfo; - -class CTexture { - class CDumpedBitmapDataReloader { - int x0_; - u32 x4_; - int x8_; - u32 xc_; - bool x10_; - int x14_; - void* x18_; - }; - -public: - enum class EClampMode { - Clamp, - Repeat, - Mirror, - }; - - enum class EFontType { - None = -1, - OneLayer = 0, /* Fill bit0 */ - OneLayerOutline = 1, /* Fill bit0, Outline bit1 */ - FourLayers = 2, - TwoLayersOutlines = 3, /* Fill bit0/2, Outline bit1/3 */ - TwoLayers = 4, /* Fill bit0/1 and copied to bit2/3 */ - TwoLayersOutlines2 = 8 /* Fill bit2/3, Outline bit0/1 */ - }; - -private: - static u32 sCurrentFrameCount; - ETexelFormat x0_fmt; - u16 x4_w; - u16 x6_h; - u8 x8_mips; - u8 x9_bitsPerPixel; - u32 xc_memoryAllocated{}; - std::unique_ptr x10_graphicsPalette; - std::unique_ptr x14_bitmapReloader; - u32 x18_gxFormat{}; - u32 x1c_gxCIFormat{}; - /* GXTexObj x20_texObj */ - EClampMode x40_clampMode = EClampMode::Repeat; - /* CARAMToken x44_aramToken */ - u32 x64_frameAllocated{}; - - aurora::gfx::TextureHandle m_tex; - aurora::gfx::TextureHandle m_paletteTex; - std::unique_ptr m_otex; - EFontType m_ftype = EFontType::None; - const CTextureInfo* m_textureInfo{}; - - size_t ComputeMippedTexelCount() const; - size_t ComputeMippedBlockCountDXT1() const; - void BuildI4FromGCN(CInputStream& in, aurora::zstring_view label); - void BuildI8FromGCN(CInputStream& in, aurora::zstring_view label); - void BuildIA4FromGCN(CInputStream& in, aurora::zstring_view label); - void BuildIA8FromGCN(CInputStream& in, aurora::zstring_view label); - void BuildC4FromGCN(CInputStream& in, aurora::zstring_view label); - void BuildC8FromGCN(CInputStream& in, aurora::zstring_view label); - void BuildC14X2FromGCN(CInputStream& in, aurora::zstring_view label); - void BuildRGB565FromGCN(CInputStream& in, aurora::zstring_view label); - void BuildRGB5A3FromGCN(CInputStream& in, aurora::zstring_view label); - void BuildRGBA8FromGCN(CInputStream& in, aurora::zstring_view label); - void BuildDXT1FromGCN(CInputStream& in, aurora::zstring_view label); - void BuildRGBA8(const void* data, size_t length, aurora::zstring_view label); - void BuildC8(const void* data, size_t length, aurora::zstring_view label); - void BuildC8Font(const void* data, EFontType ftype, aurora::zstring_view label); - void BuildDXT1(const void* data, size_t length, aurora::zstring_view label); - void BuildDXT3(const void* data, size_t length, aurora::zstring_view label); - - void InitBitmapBuffers(ETexelFormat fmt, s16 width, s16 height, s32 mips); - void InitTextureObjs(); - -public: - CTexture(ETexelFormat, s16, s16, s32); - CTexture(std::unique_ptr&& in, u32 length, bool otex, const CTextureInfo* inf, CAssetId id); - [[nodiscard]] ETexelFormat GetTexelFormat() const { return x0_fmt; } - [[nodiscard]] ETexelFormat GetMemoryCardTexelFormat() const { - return x0_fmt == ETexelFormat::C8PC ? ETexelFormat::C8 : ETexelFormat::RGB5A3; - } - [[nodiscard]] u16 GetWidth() const { return x4_w; } - [[nodiscard]] u16 GetHeight() const { return x6_h; } - [[nodiscard]] u8 GetNumMips() const { return x8_mips; } - [[nodiscard]] u8 GetBitsPerPixel() const { return x9_bitsPerPixel; } - void Load(int slot, EClampMode clamp) const; - [[nodiscard]] const aurora::gfx::TextureHandle& GetTexture() const { return m_tex; } - [[nodiscard]] const aurora::gfx::TextureHandle& GetPaletteTexture() const { return m_paletteTex; } - std::unique_ptr BuildMemoryCardTex(u32& sizeOut, ETexelFormat& fmtOut, std::unique_ptr& paletteOut) const; - const aurora::gfx::TextureHandle& GetFontTexture(EFontType tp); - - [[nodiscard]] const CTextureInfo* GetTextureInfo() const { return m_textureInfo; } - - static u32 TexelFormatBitsPerPixel(ETexelFormat fmt); - static void SetCurrentFrameCount(u32 frameCount) { sCurrentFrameCount = frameCount; } -}; - -CFactoryFnReturn FTextureFactory(const metaforce::SObjectTag& tag, std::unique_ptr&& in, u32 len, - const metaforce::CVParamTransfer& vparms, CObjectReference* selfRef); - -} // namespace metaforce diff --git a/Runtime/Graphics/CTextureBoo.cpp b/Runtime/Graphics/CTextureBoo.cpp deleted file mode 100644 index c0ef8e92d..000000000 --- a/Runtime/Graphics/CTextureBoo.cpp +++ /dev/null @@ -1,939 +0,0 @@ -#include "Runtime/Graphics/CTexture.hpp" - -#include - -#include "Runtime/CBasics.hpp" -#include "Runtime/CSimplePool.hpp" -#include "Runtime/CTextureCache.hpp" -#include "Runtime/CToken.hpp" -#include "Runtime/GameGlobalObjects.hpp" -#include "Runtime/Graphics/CGraphics.hpp" - -#include - -namespace metaforce { -namespace { -logvisor::Module Log("metaforce::CTextureBoo"); - -struct RGBA8 { - u8 r; - u8 g; - u8 b; - u8 a; -}; - -struct DXT1Block { - u16 color1; - u16 color2; - std::array lines; -}; - -/* GX uses this upsampling technique to extract full 8-bit range */ -constexpr u8 Convert3To8(u8 v) { - /* Swizzle bits: 00000123 -> 12312312 */ - return static_cast((u32{v} << 5) | (u32{v} << 2) | (u32{v} >> 1)); -} - -constexpr u8 Convert4To8(u8 v) { - /* Swizzle bits: 00001234 -> 12341234 */ - return static_cast((u32{v} << 4) | u32{v}); -} - -constexpr u8 Convert5To8(u8 v) { - /* Swizzle bits: 00012345 -> 12345123 */ - return static_cast((u32{v} << 3) | (u32{v} >> 2)); -} - -constexpr u8 Convert6To8(u8 v) { - /* Swizzle bits: 00123456 -> 12345612 */ - return static_cast((u32{v} << 2) | (u32{v} >> 4)); -} -} // Anonymous namespace - -size_t CTexture::ComputeMippedTexelCount() const { - size_t w = x4_w; - size_t h = x6_h; - size_t ret = w * h; - for (u32 i = x8_mips; i > 1; --i) { - if (w > 1) - w /= 2; - if (h > 1) - h /= 2; - ret += w * h; - } - return ret; -} - -size_t CTexture::ComputeMippedBlockCountDXT1() const { - size_t w = x4_w / 4; - size_t h = x6_h / 4; - size_t ret = w * h; - for (u32 i = x8_mips; i > 1; --i) { - if (w > 1) - w /= 2; - if (h > 1) - h /= 2; - ret += w * h; - } - return ret; -} - -void CTexture::BuildI4FromGCN(CInputStream& in, aurora::zstring_view label) { - const size_t texelCount = ComputeMippedTexelCount(); - std::unique_ptr buf(new RGBA8[texelCount]); - - int w = x4_w; - int h = x6_h; - RGBA8* targetMip = buf.get(); - for (u32 mip = 0; mip < x8_mips; ++mip) { - const int bwidth = (w + 7) / 8; - const int bheight = (h + 7) / 8; - for (int by = 0; by < bheight; ++by) { - const int baseY = by * 8; - for (int bx = 0; bx < bwidth; ++bx) { - const int baseX = bx * 8; - for (int y = 0; y < std::min(h, 8); ++y) { - RGBA8* target = targetMip + (baseY + y) * w + baseX; - std::array source; - in.Get(source.data(), std::min(size_t(w) / 4, source.size())); - for (size_t x = 0; x < std::min(w, 8); ++x) { - target[x].r = Convert4To8(source[x / 2] >> ((x & 1) ? 0 : 4) & 0xf); - target[x].g = target[x].r; - target[x].b = target[x].r; - target[x].a = target[x].r; - } - } - } - } - targetMip += w * h; - if (w > 1) { - w /= 2; - } - if (h > 1) { - h /= 2; - } - } - - m_tex = aurora::gfx::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::gfx::TextureFormat::RGBA8, - {reinterpret_cast(buf.get()), texelCount * 4}, label); -} - -void CTexture::BuildI8FromGCN(CInputStream& in, aurora::zstring_view label) { - const size_t texelCount = ComputeMippedTexelCount(); - std::unique_ptr buf(new RGBA8[texelCount]); - - int w = x4_w; - int h = x6_h; - RGBA8* targetMip = buf.get(); - for (u32 mip = 0; mip < x8_mips; ++mip) { - const int bwidth = (w + 7) / 8; - const int bheight = (h + 3) / 4; - for (int by = 0; by < bheight; ++by) { - const int baseY = by * 4; - for (int bx = 0; bx < bwidth; ++bx) { - const int baseX = bx * 8; - for (int y = 0; y < 4; ++y) { - RGBA8* target = targetMip + (baseY + y) * w + baseX; - std::array source; - in.Get(source.data(), source.size()); - for (size_t x = 0; x < source.size(); ++x) { - target[x].r = source[x]; - target[x].g = source[x]; - target[x].b = source[x]; - target[x].a = source[x]; - } - } - } - } - targetMip += w * h; - if (w > 1) { - w /= 2; - } - if (h > 1) { - h /= 2; - } - } - - m_tex = aurora::gfx::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::gfx::TextureFormat::RGBA8, - {reinterpret_cast(buf.get()), texelCount * 4}, label); -} - -void CTexture::BuildIA4FromGCN(CInputStream& in, aurora::zstring_view label) { - const size_t texelCount = ComputeMippedTexelCount(); - std::unique_ptr buf(new RGBA8[texelCount]); - - int w = x4_w; - int h = x6_h; - RGBA8* targetMip = buf.get(); - for (u32 mip = 0; mip < x8_mips; ++mip) { - const int bwidth = (w + 7) / 8; - const int bheight = (h + 3) / 4; - for (int by = 0; by < bheight; ++by) { - const int baseY = by * 4; - for (int bx = 0; bx < bwidth; ++bx) { - const int baseX = bx * 8; - for (int y = 0; y < 4; ++y) { - RGBA8* target = targetMip + (baseY + y) * w + baseX; - std::array source; - in.Get(source.data(), source.size()); - for (size_t x = 0; x < source.size(); ++x) { - const u8 intensity = Convert4To8(source[x] >> 4 & 0xf); - target[x].r = intensity; - target[x].g = intensity; - target[x].b = intensity; - target[x].a = Convert4To8(source[x] & 0xf); - } - } - } - } - targetMip += w * h; - if (w > 1) { - w /= 2; - } - if (h > 1) { - h /= 2; - } - } - - m_tex = aurora::gfx::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::gfx::TextureFormat::RGBA8, - {reinterpret_cast(buf.get()), texelCount * 4}, label); -} - -void CTexture::BuildIA8FromGCN(CInputStream& in, aurora::zstring_view label) { - const size_t texelCount = ComputeMippedTexelCount(); - std::unique_ptr buf(new RGBA8[texelCount]); - - int w = x4_w; - int h = x6_h; - RGBA8* targetMip = buf.get(); - for (u32 mip = 0; mip < x8_mips; ++mip) { - const int bwidth = (w + 3) / 4; - const int bheight = (h + 3) / 4; - for (int by = 0; by < bheight; ++by) { - const int baseY = by * 4; - for (int bx = 0; bx < bwidth; ++bx) { - const int baseX = bx * 4; - for (int y = 0; y < 4; ++y) { - RGBA8* target = targetMip + (baseY + y) * w + baseX; - std::array source; - in.Get(reinterpret_cast(source.data()), sizeof(source)); - for (size_t x = 0; x < source.size(); ++x) { - const u8 intensity = source[x] >> 8; - target[x].r = intensity; - target[x].g = intensity; - target[x].b = intensity; - target[x].a = source[x] & 0xff; - } - } - } - } - targetMip += w * h; - if (w > 1) { - w /= 2; - } - if (h > 1) { - h /= 2; - } - } - - m_tex = aurora::gfx::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::gfx::TextureFormat::RGBA8, - {reinterpret_cast(buf.get()), texelCount * 4}, label); -} - -static std::vector DecodePalette(int numEntries, CInputStream& in) { - std::vector ret; - ret.reserve(numEntries); - - enum class EPaletteType { IA8, RGB565, RGB5A3 }; - - EPaletteType format = EPaletteType(in.ReadLong()); - in.ReadLong(); - switch (format) { - case EPaletteType::IA8: { - for (int e = 0; e < numEntries; ++e) { - u8 intensity = in.ReadUint8(); - u8 alpha = in.ReadUint8(); - ret.push_back({intensity, intensity, intensity, alpha}); - } - break; - } - case EPaletteType::RGB565: { - for (int e = 0; e < numEntries; ++e) { - u16 texel = in.ReadShort(); - ret.push_back({Convert5To8(texel >> 11 & 0x1f), Convert6To8(texel >> 5 & 0x3f), Convert5To8(texel & 0x1f), 0xff}); - } - break; - } - case EPaletteType::RGB5A3: { - for (int e = 0; e < numEntries; ++e) { - u16 texel = in.ReadShort(); - if (texel & 0x8000) { - ret.push_back( - {Convert5To8(texel >> 10 & 0x1f), Convert5To8(texel >> 5 & 0x1f), Convert5To8(texel & 0x1f), 0xff}); - } else { - ret.push_back({Convert4To8(texel >> 8 & 0xf), Convert4To8(texel >> 4 & 0xf), Convert4To8(texel & 0xf), - Convert3To8(texel >> 12 & 0x7)}); - } - } - break; - } - } - return ret; -} - -void CTexture::BuildC4FromGCN(CInputStream& in, aurora::zstring_view label) { - const size_t texelCount = ComputeMippedTexelCount(); - std::unique_ptr buf(new RGBA8[texelCount]); - std::vector palette = DecodePalette(16, in); - - int w = x4_w; - int h = x6_h; - RGBA8* targetMip = buf.get(); - for (u32 mip = 0; mip < x8_mips; ++mip) { - const int bwidth = (w + 7) / 8; - const int bheight = (h + 7) / 8; - for (int by = 0; by < bheight; ++by) { - const int baseY = by * 8; - for (int bx = 0; bx < bwidth; ++bx) { - const int baseX = bx * 8; - for (int y = 0; y < 8; ++y) { - RGBA8* target = targetMip + (baseY + y) * w + baseX; - std::array source; - in.Get(source.data(), source.size()); - for (size_t x = 0; x < 8; ++x) { - target[x] = palette[source[x / 2] >> ((x & 1) ? 0 : 4) & 0xf]; - } - } - } - } - targetMip += w * h; - if (w > 1) { - w /= 2; - } - if (h > 1) { - h /= 2; - } - } - - m_tex = aurora::gfx::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::gfx::TextureFormat::RGBA8, - {reinterpret_cast(buf.get()), texelCount * 4}, label); -} - -void CTexture::BuildC8FromGCN(CInputStream& in, aurora::zstring_view label) { - const size_t texelCount = ComputeMippedTexelCount(); - std::unique_ptr buf(new RGBA8[texelCount]); - std::vector palette = DecodePalette(256, in); - - int w = x4_w; - int h = x6_h; - RGBA8* targetMip = buf.get(); - for (u32 mip = 0; mip < x8_mips; ++mip) { - const int bwidth = (w + 7) / 8; - const int bheight = (h + 3) / 4; - for (int by = 0; by < bheight; ++by) { - const int baseY = by * 4; - for (int bx = 0; bx < bwidth; ++bx) { - const int baseX = bx * 8; - for (int y = 0; y < 4; ++y) { - RGBA8* target = targetMip + (baseY + y) * w + baseX; - std::array source; - in.Get(source.data(), source.size()); - for (size_t x = 0; x < source.size(); ++x) { - target[x] = palette[source[x]]; - } - } - } - } - targetMip += w * h; - if (w > 1) { - w /= 2; - } - if (h > 1) { - h /= 2; - } - } - - m_tex = aurora::gfx::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::gfx::TextureFormat::RGBA8, - {reinterpret_cast(buf.get()), texelCount * 4}, label); -} - -void CTexture::BuildC14X2FromGCN(CInputStream& in, aurora::zstring_view label) { - spdlog::fatal("C14X2 not implemented"); -} - -void CTexture::BuildRGB565FromGCN(CInputStream& in, aurora::zstring_view label) { - const size_t texelCount = ComputeMippedTexelCount(); - std::unique_ptr buf(new RGBA8[texelCount]); - - int w = x4_w; - int h = x6_h; - RGBA8* targetMip = buf.get(); - for (u32 mip = 0; mip < x8_mips; ++mip) { - const int bwidth = (w + 3) / 4; - const int bheight = (h + 3) / 4; - for (int by = 0; by < bheight; ++by) { - const int baseY = by * 4; - for (int bx = 0; bx < bwidth; ++bx) { - const int baseX = bx * 4; - for (int y = 0; y < 4; ++y) { - RGBA8* target = targetMip + (baseY + y) * w + baseX; - for (size_t x = 0; x < 4; ++x) { - const u16 texel = in.ReadShort(); - target[x].r = Convert5To8(texel >> 11 & 0x1f); - target[x].g = Convert6To8(texel >> 5 & 0x3f); - target[x].b = Convert5To8(texel & 0x1f); - target[x].a = 0xff; - } - } - } - } - targetMip += w * h; - if (w > 1) { - w /= 2; - } - if (h > 1) { - h /= 2; - } - } - - m_tex = aurora::gfx::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::gfx::TextureFormat::RGBA8, - {reinterpret_cast(buf.get()), texelCount * 4}, label); -} - -void CTexture::BuildRGB5A3FromGCN(CInputStream& in, aurora::zstring_view label) { - size_t texelCount = ComputeMippedTexelCount(); - std::unique_ptr buf(new RGBA8[texelCount]); - - int w = x4_w; - int h = x6_h; - RGBA8* targetMip = buf.get(); - for (u32 mip = 0; mip < x8_mips; ++mip) { - const int bwidth = (w + 3) / 4; - const int bheight = (h + 3) / 4; - for (int by = 0; by < bheight; ++by) { - const int baseY = by * 4; - for (int bx = 0; bx < bwidth; ++bx) { - const int baseX = bx * 4; - for (int y = 0; y < 4; ++y) { - RGBA8* target = targetMip + (baseY + y) * w + baseX; - for (size_t x = 0; x < 4; ++x) { - const u16 texel = in.ReadShort(); - if ((texel & 0x8000) != 0) { - target[x].r = Convert5To8(texel >> 10 & 0x1f); - target[x].g = Convert5To8(texel >> 5 & 0x1f); - target[x].b = Convert5To8(texel & 0x1f); - target[x].a = 0xff; - } else { - target[x].r = Convert4To8(texel >> 8 & 0xf); - target[x].g = Convert4To8(texel >> 4 & 0xf); - target[x].b = Convert4To8(texel & 0xf); - target[x].a = Convert3To8(texel >> 12 & 0x7); - } - } - } - } - } - targetMip += w * h; - if (w > 1) { - w /= 2; - } - if (h > 1) { - h /= 2; - } - } - - m_tex = aurora::gfx::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::gfx::TextureFormat::RGBA8, - {reinterpret_cast(buf.get()), texelCount * 4}, label); -} - -void CTexture::BuildRGBA8FromGCN(CInputStream& in, aurora::zstring_view label) { - const size_t texelCount = ComputeMippedTexelCount(); - std::unique_ptr buf(new RGBA8[texelCount]); - - int w = x4_w; - int h = x6_h; - RGBA8* targetMip = buf.get(); - for (u32 mip = 0; mip < x8_mips; ++mip) { - const int bwidth = (w + 3) / 4; - const int bheight = (h + 3) / 4; - for (int by = 0; by < bheight; ++by) { - const int baseY = by * 4; - for (int bx = 0; bx < bwidth; ++bx) { - const int baseX = bx * 4; - for (int c = 0; c < 2; ++c) { - for (int y = 0; y < 4; ++y) { - RGBA8* target = targetMip + (baseY + y) * w + baseX; - std::array source; - in.Get(source.data(), source.size()); - for (size_t x = 0; x < 4; ++x) { - if (c != 0) { - target[x].g = source[x * 2]; - target[x].b = source[x * 2 + 1]; - } else { - target[x].a = source[x * 2]; - target[x].r = source[x * 2 + 1]; - } - } - } - } - } - } - targetMip += w * h; - if (w > 1) { - w /= 2; - } - if (h > 1) { - h /= 2; - } - } - - m_tex = aurora::gfx::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::gfx::TextureFormat::RGBA8, - {reinterpret_cast(buf.get()), texelCount * 4}, label); -} - -void CTexture::BuildDXT1FromGCN(CInputStream& in, aurora::zstring_view label) { - const size_t blockCount = ComputeMippedBlockCountDXT1(); - std::unique_ptr buf(new DXT1Block[blockCount]); - - int w = x4_w / 4; - int h = x6_h / 4; - DXT1Block* targetMip = buf.get(); - for (u32 mip = 0; mip < x8_mips; ++mip) { - const int bwidth = (w + 1) / 2; - const int bheight = (h + 1) / 2; - for (int by = 0; by < bheight; ++by) { - const int baseY = by * 2; - for (int bx = 0; bx < bwidth; ++bx) { - const int baseX = bx * 2; - for (int y = 0; y < 2; ++y) { - DXT1Block* target = targetMip + (baseY + y) * w + baseX; - std::array source; - in.Get(reinterpret_cast(source.data()), sizeof(source)); - for (size_t x = 0; x < source.size(); ++x) { - target[x].color1 = CBasics::SwapBytes(source[x].color1); - target[x].color2 = CBasics::SwapBytes(source[x].color2); - for (size_t i = 0; i < 4; ++i) { - std::array ind; - const u8 packed = source[x].lines[i]; - ind[3] = packed & 0x3; - ind[2] = (packed >> 2) & 0x3; - ind[1] = (packed >> 4) & 0x3; - ind[0] = (packed >> 6) & 0x3; - target[x].lines[i] = ind[0] | (ind[1] << 2) | (ind[2] << 4) | (ind[3] << 6); - } - } - } - } - } - targetMip += w * h; - - if (w > 1) { - w /= 2; - } - if (h > 1) { - h /= 2; - } - } - - m_tex = aurora::gfx::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::gfx::TextureFormat::DXT1, - {reinterpret_cast(buf.get()), blockCount * 8}, label); -} - -void CTexture::BuildRGBA8(const void* data, size_t length, aurora::zstring_view label) { - size_t texelCount = ComputeMippedTexelCount(); - size_t expectedSize = texelCount * 4; - if (expectedSize > length) - spdlog::fatal("insufficient TXTR length ({}/{})", length, expectedSize); - - m_tex = aurora::gfx::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::gfx::TextureFormat::RGBA8, - {reinterpret_cast(data), expectedSize}, label); -} - -void CTexture::BuildC8(const void* data, size_t length, aurora::zstring_view label) { - size_t texelCount = ComputeMippedTexelCount(); - if (texelCount > length) - spdlog::fatal("insufficient TXTR length ({}/{})", length, texelCount); - - uint32_t nentries = CBasics::SwapBytes(*reinterpret_cast(data)); - const u8* paletteTexels = reinterpret_cast(data) + 4; - const u8* texels = reinterpret_cast(data) + 4 + nentries * 4; - m_paletteTex = aurora::gfx::new_static_texture_2d(nentries, 1, 1, aurora::gfx::TextureFormat::RGBA8, - {paletteTexels, nentries * 4}, label); - m_tex = aurora::gfx::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::gfx::TextureFormat::R8, {texels, texelCount}, - label); -} - -void CTexture::BuildC8Font(const void* data, EFontType ftype, aurora::zstring_view label) { - size_t texelCount = ComputeMippedTexelCount(); - - size_t layerCount = 1; - switch (ftype) { - case EFontType::OneLayer: - case EFontType::OneLayerOutline: - layerCount = 1; - break; - case EFontType::FourLayers: - layerCount = 4; - break; - case EFontType::TwoLayersOutlines: - case EFontType::TwoLayers: - case EFontType::TwoLayersOutlines2: - layerCount = 2; - break; - default: - break; - } - - const uint32_t nentries = CBasics::SwapBytes(*reinterpret_cast(data)); - const u8* texels = reinterpret_cast(data) + 4 + nentries * 4; - auto buf = std::make_unique(texelCount * layerCount); - - size_t w = x4_w; - size_t h = x6_h; - RGBA8* bufCur = buf.get(); - for (size_t i = 0; i < x8_mips; ++i) { - size_t tCount = w * h; - RGBA8* l0 = bufCur; - RGBA8* l1 = bufCur + tCount; - RGBA8* l2 = bufCur + tCount * 2; - RGBA8* l3 = bufCur + tCount * 3; - for (size_t j = 0; j < tCount; ++j) { - u8 texel = texels[j]; - switch (ftype) { - case EFontType::OneLayer: - l0[j].r = (texel & 0x1) ? 0xff : 0; - l0[j].a = 0xff; - break; - case EFontType::OneLayerOutline: - l0[j].r = (texel & 0x1) ? 0xff : 0; - l0[j].g = (texel & 0x2) ? 0xff : 0; - l0[j].a = 0xff; - break; - case EFontType::FourLayers: - l0[j].r = (texel & 0x1) ? 0xff : 0; - l0[j].a = 0xff; - l1[j].r = (texel & 0x2) ? 0xff : 0; - l1[j].a = 0xff; - l2[j].r = (texel & 0x4) ? 0xff : 0; - l2[j].a = 0xff; - l3[j].r = (texel & 0x8) ? 0xff : 0; - l3[j].a = 0xff; - break; - case EFontType::TwoLayersOutlines: - l0[j].r = (texel & 0x1) ? 0xff : 0; - l0[j].g = (texel & 0x2) ? 0xff : 0; - l0[j].a = 0xff; - l1[j].r = (texel & 0x4) ? 0xff : 0; - l1[j].g = (texel & 0x8) ? 0xff : 0; - l1[j].a = 0xff; - break; - case EFontType::TwoLayers: - l0[j].r = (texel & 0x1) ? 0xff : 0; - l0[j].a = 0xff; - l1[j].r = (texel & 0x2) ? 0xff : 0; - l1[j].a = 0xff; - break; - case EFontType::TwoLayersOutlines2: - l0[j].r = (texel & 0x4) ? 0xff : 0; - l0[j].g = (texel & 0x1) ? 0xff : 0; - l0[j].a = 0xff; - l1[j].r = (texel & 0x8) ? 0xff : 0; - l1[j].g = (texel & 0x2) ? 0xff : 0; - l1[j].a = 0xff; - break; - default: - break; - } - } - texels += tCount; - bufCur += tCount * layerCount; - if (w > 1) - w /= 2; - if (h > 1) - h /= 2; - } - - // TODO array tex - // CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { - // m_booTex = ctx.newStaticArrayTexture(x4_w, x6_h, layerCount, x8_mips, boo::TextureFormat::RGBA8, - // boo::TextureClampMode::Repeat, buf.get(), texelCount * layerCount * 4) - // .get(); - // return true; - // } BooTrace); -} - -void CTexture::BuildDXT1(const void* data, size_t length, aurora::zstring_view label) { - m_tex = aurora::gfx::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::gfx::TextureFormat::DXT1, - {reinterpret_cast(data), length}, label); -} - -void CTexture::BuildDXT3(const void* data, size_t length, aurora::zstring_view label) { - m_tex = aurora::gfx::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::gfx::TextureFormat::DXT3, - {reinterpret_cast(data), length}, label); -} - -static std::string_view TextureFormatString(ETexelFormat format) { - switch (format) { - case ETexelFormat::I4: - return "I4"sv; - case ETexelFormat::I8: - return "I8"sv; - case ETexelFormat::IA4: - return "IA4"sv; - case ETexelFormat::IA8: - return "IA8"sv; - case ETexelFormat::C4: - return "C4"sv; - case ETexelFormat::C8: - return "C8"sv; - case ETexelFormat::C14X2: - return "C14X2"sv; - case ETexelFormat::RGB565: - return "RGB565"sv; - case ETexelFormat::RGB5A3: - return "RGB5A3"sv; - case ETexelFormat::RGBA8: - return "RGBA8"sv; - case ETexelFormat::CMPR: - return "CMPR"sv; - case ETexelFormat::RGBA8PC: - return "RGBA8PC"sv; - case ETexelFormat::C8PC: - return "C8PC"sv; - case ETexelFormat::CMPRPC: - return "CMPRPC"sv; - case ETexelFormat::CMPRPCA: - return "CMPRPCA"sv; - default: - return "Invalid"sv; - } -} - -u32 CTexture::TexelFormatBitsPerPixel(ETexelFormat fmt) { - switch (fmt) { - case ETexelFormat::I4: - case ETexelFormat::C4: - case ETexelFormat::CMPR: - return 4; - case ETexelFormat::I8: - case ETexelFormat::IA4: - case ETexelFormat::C8: - return 8; - case ETexelFormat::IA8: - case ETexelFormat::C14X2: - case ETexelFormat::RGB565: - case ETexelFormat::RGB5A3: - return 16; - case ETexelFormat::RGBA8: - return 32; - default: - return 0; - } -} - -u32 CTexture::sCurrentFrameCount = 0; - -void CTexture::InitBitmapBuffers(ETexelFormat fmt, s16 width, s16 height, s32 mips) {} -void CTexture::InitTextureObjs() {} - -CTexture::CTexture(ETexelFormat fmt, s16 w, s16 h, s32 mips) -: x0_fmt(fmt) -, x4_w(w) -, x6_h(h) -, x8_mips(mips) -, x9_bitsPerPixel(TexelFormatBitsPerPixel(fmt)) -, x64_frameAllocated(sCurrentFrameCount) { - - InitBitmapBuffers(fmt, w, h, mips); - InitTextureObjs(); -} - -CTexture::CTexture(std::unique_ptr&& in, u32 length, bool otex, const CTextureInfo* inf, CAssetId id) { - std::unique_ptr owned = std::move(in); - CMemoryInStream r(owned.get(), length, CMemoryInStream::EOwnerShip::NotOwned); - x0_fmt = ETexelFormat(r.ReadLong()); - x4_w = r.ReadShort(); - x6_h = r.ReadShort(); - x8_mips = r.ReadLong(); - x9_bitsPerPixel = TexelFormatBitsPerPixel(x0_fmt); - m_textureInfo = inf; - - auto label = fmt::format("TXTR {:08X} ({})", id.Value(), TextureFormatString(x0_fmt)); - switch (x0_fmt) { - case ETexelFormat::I4: - BuildI4FromGCN(r, label); - break; - case ETexelFormat::I8: - BuildI8FromGCN(r, label); - break; - case ETexelFormat::IA4: - BuildIA4FromGCN(r, label); - break; - case ETexelFormat::IA8: - BuildIA8FromGCN(r, label); - break; - case ETexelFormat::C4: - BuildC4FromGCN(r, label); - break; - case ETexelFormat::C8: - BuildC8FromGCN(r, label); - break; - case ETexelFormat::C14X2: - BuildC14X2FromGCN(r, label); - break; - case ETexelFormat::RGB565: - BuildRGB565FromGCN(r, label); - break; - case ETexelFormat::RGB5A3: - BuildRGB5A3FromGCN(r, label); - break; - case ETexelFormat::RGBA8: - BuildRGBA8FromGCN(r, label); - break; - case ETexelFormat::CMPR: - if (aurora::gfx::get_dxt_compression_supported()) { - BuildDXT1FromGCN(r, label); - } else { - spdlog::error("BC/DXT1 compression is not supported on your GPU, unable to load {}", label); - x0_fmt = ETexelFormat::RGBA8PC; - x8_mips = 1; - std::unique_ptr data = std::make_unique(x4_w * x6_h * 4); - /* Build a fake texture to use */ - for (u32 i = 0; i < (x4_w * x6_h) * 4; i += 4) { - data[i + 0] = 0xFF; - data[i + 1] = 0x00; - data[i + 2] = 0xFF; - data[i + 3] = 0xFF; - } - m_tex = aurora::gfx::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::gfx::TextureFormat::RGBA8, - {reinterpret_cast(data.get()), (x4_w * x6_h * 4ul)}, - label); - } - break; - case ETexelFormat::RGBA8PC: - BuildRGBA8(owned.get() + 12, length - 12, label); - break; - case ETexelFormat::C8PC: - BuildC8(owned.get() + 12, length - 12, label); - otex = true; - break; - case ETexelFormat::CMPRPC: - BuildDXT1(owned.get() + 12, length - 12, label); - break; - case ETexelFormat::CMPRPCA: - BuildDXT3(owned.get() + 12, length - 12, label); - break; - default: - spdlog::fatal("invalid texture type {} for boo", int(x0_fmt)); - } - - if (otex) - m_otex = std::move(owned); -} - -void CTexture::Load(int slot, EClampMode clamp) const {} - -std::unique_ptr CTexture::BuildMemoryCardTex(u32& sizeOut, ETexelFormat& fmtOut, - std::unique_ptr& paletteOut) const { - if (!m_otex) - spdlog::fatal("MemoryCard TXTR not loaded with 'otex'"); - - size_t texelCount = x4_w * x6_h; - std::unique_ptr ret; - if (x0_fmt == ETexelFormat::RGBA8PC) { - sizeOut = texelCount * 2; - fmtOut = ETexelFormat::RGB5A3; - ret.reset(new u8[sizeOut]); - u16* texel = reinterpret_cast(ret.get()); - - int w = x4_w; - int h = x6_h; - const RGBA8* sourceMip = reinterpret_cast(m_otex.get() + 12); - int bwidth = (w + 3) / 4; - int bheight = (h + 3) / 4; - for (int by = 0; by < bheight; ++by) { - int baseY = by * 4; - for (int bx = 0; bx < bwidth; ++bx) { - int baseX = bx * 4; - for (int y = 0; y < 4; ++y) { - const RGBA8* source = sourceMip + (x6_h - (baseY + y) - 1) * w + baseX; - for (int x = 0; x < 4; ++x) { - if (source[x].a == 0xff) { - *texel++ = - CBasics::SwapBytes(u16((source[x].r >> 3 << 10) | (source[x].g >> 3 << 5) | (source[x].b >> 3))); - } else { - *texel++ = CBasics::SwapBytes(u16((source[x].r >> 4 << 8) | (source[x].g >> 4 << 4) | (source[x].b >> 4) | - (source[x].a >> 5 << 12))); - } - } - } - } - } - } else if (x0_fmt == ETexelFormat::C8PC) { - sizeOut = texelCount; - fmtOut = ETexelFormat::C8; - ret.reset(new u8[sizeOut]); - paletteOut.reset(new u8[512]); - u8* texel = ret.get(); - u16* paletteColors = reinterpret_cast(paletteOut.get()); - - int w = x4_w; - int h = x6_h; - const u8* data = m_otex.get() + 12; - u32 nentries = CBasics::SwapBytes(*reinterpret_cast(data)); - const RGBA8* paletteTexels = reinterpret_cast(data + 4); - const u8* sourceMip = data + 4 + nentries * 4; - - for (u32 i = 0; i < 256; ++i) { - u16& color = paletteColors[i]; - if (i >= nentries) { - color = 0; - } else { - const RGBA8& colorIn = paletteTexels[i]; - if (colorIn.a == 0xff) { - color = CBasics::SwapBytes(u16((colorIn.r >> 3 << 10) | (colorIn.g >> 3 << 5) | (colorIn.b >> 3) | 0x8000)); - } else { - color = CBasics::SwapBytes( - u16((colorIn.r >> 4 << 8) | (colorIn.g >> 4 << 4) | (colorIn.b >> 4) | (colorIn.a >> 5 << 12))); - } - } - } - - int bwidth = (w + 7) / 8; - int bheight = (h + 3) / 4; - for (int by = 0; by < bheight; ++by) { - int baseY = by * 4; - for (int bx = 0; bx < bwidth; ++bx) { - int baseX = bx * 8; - for (int y = 0; y < 4; ++y) { - const u8* source = sourceMip + (x6_h - (baseY + y) - 1) * w + baseX; - for (int x = 0; x < 8; ++x) - *texel++ = source[x]; - } - } - } - } else - spdlog::fatal("MemoryCard texture may only use RGBA8PC or C8PC format"); - - return ret; -} - -const aurora::gfx::TextureHandle& CTexture::GetFontTexture(EFontType tp) { - if (m_ftype != tp && x0_fmt == ETexelFormat::C8PC) { - m_ftype = tp; - BuildC8Font(m_otex.get() + 12, m_ftype, "Font (TODO)"); - } - return m_tex; -} - -CFactoryFnReturn FTextureFactory(const metaforce::SObjectTag& tag, std::unique_ptr&& in, u32 len, - const metaforce::CVParamTransfer& vparms, CObjectReference* selfRef) { - u32 u32Owned = vparms.GetOwnedObj(); - const CTextureInfo* inf = nullptr; - if (g_TextureCache) - inf = g_TextureCache->GetTextureInfo(tag.id); - return TToken::GetIObjObjectFor( - std::make_unique(std::move(in), len, u32Owned == SBIG('OTEX'), inf, tag.id)); -} - -} // namespace metaforce diff --git a/Runtime/Graphics/CVertexMorphEffect.cpp b/Runtime/Graphics/CVertexMorphEffect.cpp index bf877cc29..11989f32e 100644 --- a/Runtime/Graphics/CVertexMorphEffect.cpp +++ b/Runtime/Graphics/CVertexMorphEffect.cpp @@ -13,22 +13,28 @@ void CVertexMorphEffect::MorphVertices(SSkinningWorkspace& workspace, TConstVect TLockedToken& skinRules, const CPoseAsTransforms& pose, u32 vertexCount) { if (x28_indices.empty()) { - std::vector normalsOut; + std::vector> normalsOut; normalsOut.reserve(vertexCount); skinRules->BuildNormals(averagedNormals, &normalsOut); for (int i = 0; i < vertexCount; ++i) { - float dist = normalsOut[i].dot(x0_dir); + const auto& nov = normalsOut[i]; + const zeus::CVector3f noz{nov.x, nov.y, nov.z}; + float dist = noz.dot(x0_dir); if (dist > 0.5f) { x28_indices.emplace_back(i); const auto vert = workspace.m_vertexWorkspace[i]; - const auto length = vert.x() + vert.y() + vert.z(); + const auto length = vert.x + vert.y + vert.z; x38_floats.emplace_back((length - std::trunc(length)) * (dist - 0.5f)); } } } for (int i = 0; i < x28_indices.size(); ++i) { const auto scale = x1c_elapsed / x18_duration; - workspace.m_vertexWorkspace[x28_indices[i]] += scale * x20_diagExtent * x38_floats[i] * x0_dir; + auto& out = workspace.m_vertexWorkspace[x28_indices[i]]; + const auto add = scale * x20_diagExtent * x38_floats[i] * x0_dir; + out.x += add.x(); + out.y += add.y(); + out.z += add.z(); } } diff --git a/Runtime/Graphics/IRenderer.hpp b/Runtime/Graphics/IRenderer.hpp index b1f238dfb..11c23e4bd 100644 --- a/Runtime/Graphics/IRenderer.hpp +++ b/Runtime/Graphics/IRenderer.hpp @@ -89,7 +89,7 @@ public: virtual void EndPrimitive() = 0; virtual void SetAmbientColor(const zeus::CColor& color) = 0; virtual void DrawString(const char* string, int, int) = 0; - virtual u32 GetFPS() = 0; + virtual float GetFPS() = 0; virtual void CacheReflection(TReflectionCallback cb, void* ctx, bool clearAfter) = 0; virtual void DrawSpaceWarp(const zeus::CVector3f& pt, float strength) = 0; virtual void DrawThermalModel(CModel& model, const zeus::CColor& multCol, const zeus::CColor& addCol, diff --git a/Runtime/Graphics/Shaders/CAABoxShader.cpp b/Runtime/Graphics/Shaders/CAABoxShader.cpp deleted file mode 100644 index 749280c93..000000000 --- a/Runtime/Graphics/Shaders/CAABoxShader.cpp +++ /dev/null @@ -1,79 +0,0 @@ -#include "Runtime/Graphics/Shaders/CAABoxShader.hpp" - -#include - -#include "Runtime/Graphics/CGraphics.hpp" - -//#include -#include - -namespace metaforce { - -//static boo::ObjToken s_Pipeline; -//static boo::ObjToken s_zOnlyPipeline; - -void CAABoxShader::Initialize() { -// 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); -// const std::array, 1> bufs{m_uniBuf.get()}; -// constexpr std::array stages{boo::PipelineStage::Vertex}; -// m_dataBind = -// ctx.newShaderDataBinding(zOnly ? s_zOnlyPipeline : s_Pipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), -// bufs.data(), stages.data(), nullptr, nullptr, 0, nullptr, nullptr, nullptr); -// return true; -// } BooTrace); -} - -void CAABoxShader::setAABB(const zeus::CAABox& aabb) { - const std::array vboData{{ - {aabb.max.x(), aabb.max.y(), aabb.min.z()}, {aabb.max.x(), aabb.min.y(), aabb.min.z()}, - {aabb.max.x(), aabb.max.y(), aabb.max.z()}, {aabb.max.x(), aabb.min.y(), aabb.max.z()}, - {aabb.max.x(), aabb.min.y(), aabb.max.z()}, - - {aabb.min.x(), aabb.max.y(), aabb.min.z()}, {aabb.min.x(), aabb.max.y(), aabb.min.z()}, - {aabb.max.x(), aabb.max.y(), aabb.min.z()}, {aabb.min.x(), aabb.max.y(), aabb.max.z()}, - {aabb.max.x(), aabb.max.y(), aabb.max.z()}, {aabb.max.x(), aabb.max.y(), aabb.max.z()}, - - {aabb.min.x(), aabb.max.y(), aabb.min.z()}, {aabb.min.x(), aabb.max.y(), aabb.min.z()}, - {aabb.min.x(), aabb.min.y(), aabb.min.z()}, {aabb.min.x(), aabb.max.y(), aabb.max.z()}, - {aabb.min.x(), aabb.min.y(), aabb.max.z()}, {aabb.min.x(), aabb.min.y(), aabb.max.z()}, - - {aabb.min.x(), aabb.min.y(), aabb.min.z()}, {aabb.min.x(), aabb.min.y(), aabb.min.z()}, - {aabb.max.x(), aabb.min.y(), aabb.min.z()}, {aabb.min.x(), aabb.min.y(), aabb.max.z()}, - {aabb.max.x(), aabb.min.y(), aabb.max.z()}, {aabb.max.x(), aabb.min.y(), aabb.max.z()}, - - {aabb.min.x(), aabb.min.y(), aabb.max.z()}, {aabb.min.x(), aabb.min.y(), aabb.max.z()}, - {aabb.max.x(), aabb.min.y(), aabb.max.z()}, {aabb.min.x(), aabb.max.y(), aabb.max.z()}, - {aabb.max.x(), aabb.max.y(), aabb.max.z()}, {aabb.max.x(), aabb.max.y(), aabb.max.z()}, - - {aabb.min.x(), aabb.min.y(), aabb.min.z()}, {aabb.min.x(), aabb.min.y(), aabb.min.z()}, - {aabb.max.x(), aabb.min.y(), aabb.min.z()}, {aabb.min.x(), aabb.max.y(), aabb.min.z()}, - {aabb.max.x(), aabb.max.y(), aabb.min.z()}, - }}; - -// m_vbo->load(vboData.data(), sizeof(vboData)); -} - -void CAABoxShader::draw(const zeus::CColor& color) { - SCOPED_GRAPHICS_DEBUG_GROUP("CAABoxShader::draw", zeus::skMagenta); - - m_uniform.m_xf = CGraphics::GetPerspectiveProjectionMatrix(/*true*/) * CGraphics::g_GXModelView.toMatrix4f(); - m_uniform.m_color = color; -// m_uniBuf->load(&m_uniform, sizeof(Uniform)); -// -// CGraphics::SetShaderDataBinding(m_dataBind); -// CGraphics::DrawArray(0, 34); -} - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CAABoxShader.hpp b/Runtime/Graphics/Shaders/CAABoxShader.hpp deleted file mode 100644 index ec201302c..000000000 --- a/Runtime/Graphics/Shaders/CAABoxShader.hpp +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -//#include - -#include -#include - -namespace zeus { -class CAABox; -} - -namespace metaforce { - -class CAABoxShader { - struct Uniform { - zeus::CMatrix4f m_xf; - zeus::CColor m_color; - }; -// boo::ObjToken m_vbo; -// boo::ObjToken m_uniBuf; -// boo::ObjToken m_dataBind; - Uniform m_uniform; - -public: - static void Initialize(); - static void Shutdown(); - explicit CAABoxShader(bool zOnly = false); - void setAABB(const zeus::CAABox& aabb); - void draw(const zeus::CColor& color); -}; - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CCameraBlurFilter.cpp b/Runtime/Graphics/Shaders/CCameraBlurFilter.cpp deleted file mode 100644 index 82bd316c7..000000000 --- a/Runtime/Graphics/Shaders/CCameraBlurFilter.cpp +++ /dev/null @@ -1,88 +0,0 @@ -#include "Runtime/Graphics/Shaders/CCameraBlurFilter.hpp" - -#include -#include -#include - -#include "Runtime/Graphics/CGraphics.hpp" - -//#include -#include - -namespace metaforce { -namespace { -struct Vert { - zeus::CVector2f m_pos; - zeus::CVector2f m_uv; -}; - -//boo::ObjToken s_Pipeline; -} // Anonymous namespace - -void CCameraBlurFilter::Initialize() { -// s_Pipeline = hecl::conv->convert(Shader_CCameraBlurFilter{}); -} - -void CCameraBlurFilter::Shutdown() { -// s_Pipeline.reset(); -} - -CCameraBlurFilter::CCameraBlurFilter() { -// 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); -// const std::array, 1> bufs{m_uniBuf.get()}; -// constexpr std::array stages{boo::PipelineStage::Vertex}; -// const std::array, 1> texs{CGraphics::g_SpareTexture.get()}; -// m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), -// stages.data(), nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr); -// return true; -// } BooTrace); -} - -void CCameraBlurFilter::draw(float amount, bool clearDepth) { - if (amount <= 0.f) { - return; - } - - SCOPED_GRAPHICS_DEBUG_GROUP("CCameraBlurFilter::draw", zeus::skMagenta); - - const SClipScreenRect clipRect(CGraphics::g_Viewport); -// CGraphics::ResolveSpareTexture(clipRect, 0, clearDepth); - const float aspect = float(CGraphics::g_CroppedViewport.xc_width) / float(CGraphics::g_CroppedViewport.x10_height); - - const float xFac = float(CGraphics::GetCroppedViewportWidth()) / float(CGraphics::GetViewportWidth()); - const float yFac = float(CGraphics::GetCroppedViewportHeight()) / float(CGraphics::GetViewportHeight()); - const float xBias = float(CGraphics::GetCroppedViewportLeft()) / float(CGraphics::GetViewportWidth()); - const float yBias = float(CGraphics::GetCroppedViewportTop()) / float(CGraphics::GetViewportHeight()); - - const std::array verts{{ - {{-1.0, -1.0}, {xBias, yBias}}, - {{-1.0, 1.0}, {xBias, yBias + yFac}}, - {{1.0, -1.0}, {xBias + xFac, yBias}}, - {{1.0, 1.0}, {xBias + xFac, yBias + yFac}}, - }}; -// m_vbo->load(verts.data(), sizeof(verts)); - - for (size_t i = 0; i < m_uniform.m_uv.size(); ++i) { - auto tmp = static_cast(i); - tmp *= 2.f * M_PIF; - tmp /= 6.f; - - float amtX = std::cos(tmp); - amtX *= amount / 448.f / aspect; - - float amtY = std::sin(tmp); - amtY *= amount / 448.f; - - m_uniform.m_uv[i][0] = amtX * xFac; - m_uniform.m_uv[i][1] = amtY * yFac; - } - m_uniform.m_opacity = std::min(amount / 2.f, 1.f); -// m_uniBuf->load(&m_uniform, sizeof(m_uniform)); - -// CGraphics::SetShaderDataBinding(m_dataBind); -// CGraphics::DrawArray(0, 4); -} - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CCameraBlurFilter.hpp b/Runtime/Graphics/Shaders/CCameraBlurFilter.hpp deleted file mode 100644 index 46fe2dc03..000000000 --- a/Runtime/Graphics/Shaders/CCameraBlurFilter.hpp +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include -//#include -#include - -namespace metaforce { - -class CCameraBlurFilter { - struct Uniform { - std::array m_uv; - float m_opacity = 1.f; - }; - -// boo::ObjToken m_vbo; -// boo::ObjToken m_uniBuf; -// boo::ObjToken m_dataBind; - Uniform m_uniform; - -public: - static void Initialize(); - static void Shutdown(); - CCameraBlurFilter(); - void draw(float amount, bool clearDepth = false); -}; - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CColoredQuadFilter.cpp b/Runtime/Graphics/Shaders/CColoredQuadFilter.cpp deleted file mode 100644 index 006c76aac..000000000 --- a/Runtime/Graphics/Shaders/CColoredQuadFilter.cpp +++ /dev/null @@ -1,117 +0,0 @@ -#include "Runtime/Graphics/Shaders/CColoredQuadFilter.hpp" - -#include - -#include "Runtime/Camera/CCameraFilter.hpp" -#include "Runtime/Graphics/CGraphics.hpp" - -//#include - -namespace metaforce { - -// 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 s_AlphaPipeline; -// } -// } - -CColoredQuadFilter::CColoredQuadFilter(EFilterType type) { - // CGraphics::CommitResources([this, type](boo::IGraphicsDataFactory::Context& ctx) { - // struct Vert { - // zeus::CVector2f m_pos; - // }; - // - // const std::array verts{{ - // {{0.0, 0.0}}, - // {{0.0, 1.0}}, - // {{1.0, 0.0}}, - // {{1.0, 1.0}}, - // }}; - // - // m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), 16, verts.size()); - // m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); - // - // const std::array, 1> bufs{m_uniBuf.get()}; - // constexpr std::array stages{boo::PipelineStage::Vertex}; - // m_dataBind = ctx.newShaderDataBinding(SelectPipeline(type), m_vbo.get(), nullptr, nullptr, bufs.size(), - // bufs.data(), - // stages.data(), nullptr, nullptr, 0, nullptr, nullptr, nullptr); - // return true; - // } BooTrace); -} - -void CColoredQuadFilter::draw(const zeus::CColor& color, const zeus::CRectangle& rect) { - SCOPED_GRAPHICS_DEBUG_GROUP("CColoredQuadFilter::draw", zeus::skMagenta); - - 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)); - // - // CGraphics::SetShaderDataBinding(m_dataBind); - // CGraphics::DrawArray(0, 4); -} - -void CWideScreenFilter::draw(const zeus::CColor& color, float t) { - if (CGraphics::GetViewportAspect() < 1.7777f) { - float targetHeight = CGraphics::GetViewportWidth() / 1.7777f; - float delta = (CGraphics::GetViewportHeight() - targetHeight) * t / 2.f; - delta /= float(CGraphics::GetViewportHeight()); - 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); - } -} - -float CWideScreenFilter::SetViewportToMatch(float t) { - if (CGraphics::GetViewportAspect() < 1.7777f) { - float targetHeight = CGraphics::GetViewportWidth() / 1.7777f; - float delta = (CGraphics::GetViewportHeight() - targetHeight) * t / 2.f; - // boo::SWindowRect rect = {}; - // rect.size[0] = g_Viewport.x8_width; - // rect.size[1] = g_Viewport.xc_height - delta * 2.f; - // rect.location[1] = delta; - // CGraphics::g_CroppedViewport = rect; - // CGraphics::g_BooMainCommandQueue->setViewport(rect); - return 1.7777f; - } - - SetViewportToFull(); - return CGraphics::GetViewportAspect(); -} - -void CWideScreenFilter::SetViewportToFull() { - // boo::SWindowRect rect = {}; - // rect.size[0] = g_Viewport.x8_width; - // rect.size[1] = g_Viewport.xc_height; - // CGraphics::g_CroppedViewport = rect; - // CGraphics::g_BooMainCommandQueue->setViewport(rect); -} - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CColoredQuadFilter.hpp b/Runtime/Graphics/Shaders/CColoredQuadFilter.hpp deleted file mode 100644 index 76d30f20c..000000000 --- a/Runtime/Graphics/Shaders/CColoredQuadFilter.hpp +++ /dev/null @@ -1,52 +0,0 @@ -#pragma once - -#include "Runtime/CToken.hpp" - -//#include - -#include -#include -#include - -namespace metaforce { -class CTexture; - -enum class EFilterShape; -enum class EFilterType; - -class CColoredQuadFilter { - struct Uniform { - zeus::CMatrix4f m_matrix; - zeus::CColor m_color; - }; -// boo::ObjToken m_vbo; -// boo::ObjToken m_uniBuf; -// boo::ObjToken m_dataBind; - Uniform m_uniform; - -public: - static void Initialize(); - static void Shutdown(); - static constexpr zeus::CRectangle DefaultRect{0.f, 0.f, 1.f, 1.f}; - - explicit CColoredQuadFilter(EFilterType type); - explicit 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); } -}; - -class CWideScreenFilter { - CColoredQuadFilter m_top; - CColoredQuadFilter m_bottom; - -public: - explicit CWideScreenFilter(EFilterType type) : m_top(type), m_bottom(type) {} - explicit CWideScreenFilter(EFilterType type, const TLockedToken&) : CWideScreenFilter(type) {} - void draw(const zeus::CColor& color, float t); - void DrawFilter(EFilterShape shape, const zeus::CColor& color, float t) { draw(color, t); } - - static float SetViewportToMatch(float t); - static void SetViewportToFull(); -}; - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CColoredStripShader.cpp b/Runtime/Graphics/Shaders/CColoredStripShader.cpp deleted file mode 100644 index 10c12f780..000000000 --- a/Runtime/Graphics/Shaders/CColoredStripShader.cpp +++ /dev/null @@ -1,84 +0,0 @@ -#include "Runtime/Graphics/Shaders/CColoredStripShader.hpp" - -#include - -#include "Runtime/GameGlobalObjects.hpp" -#include "Runtime/Graphics/CCubeRenderer.hpp" -#include "Runtime/Graphics/CGraphics.hpp" - -//#include - -namespace metaforce { - -//static boo::ObjToken s_Pipeline; -//static boo::ObjToken s_AdditivePipeline; -//static boo::ObjToken s_FullAdditivePipeline; -//static boo::ObjToken s_SubtractivePipeline; - -void CColoredStripShader::Initialize() { -// s_Pipeline = hecl::conv->convert(Shader_CColoredStripShader{}); -// s_AdditivePipeline = hecl::conv->convert(Shader_CColoredStripShaderAdditive{}); -// s_FullAdditivePipeline = hecl::conv->convert(Shader_CColoredStripShaderFullAdditive{}); -// s_SubtractivePipeline = hecl::conv->convert(Shader_CColoredStripShaderSubtractive{}); -} - -void CColoredStripShader::Shutdown() { -// s_Pipeline.reset(); -// s_AdditivePipeline.reset(); -// s_FullAdditivePipeline.reset(); -// s_SubtractivePipeline.reset(); -} - -//static const boo::ObjToken& SelectPipeline(CColoredStripShader::Mode mode) { -// switch (mode) { -// case CColoredStripShader::Mode::Alpha: -// default: -// return s_Pipeline; -// case CColoredStripShader::Mode::Additive: -// return s_AdditivePipeline; -// case CColoredStripShader::Mode::FullAdditive: -// return s_FullAdditivePipeline; -// case CColoredStripShader::Mode::Subtractive: -// return s_SubtractivePipeline; -// } -//} -// -//void CColoredStripShader::BuildResources(boo::IGraphicsDataFactory::Context& ctx, size_t maxVerts, Mode mode, -// boo::ObjToken tex) { -// m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(Vert), maxVerts); -// m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); -// -// const std::array, 1> bufs{m_uniBuf.get()}; -// constexpr std::array stages{boo::PipelineStage::Vertex}; -// std::array, 1> texs; -// if (tex) { -// texs[0] = tex; -// } else { -// texs[0] = g_Renderer->GetWhiteTexture(); -// } -// -// m_dataBind = ctx.newShaderDataBinding(SelectPipeline(mode), m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), -// stages.data(), nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr); -//} - -CColoredStripShader::CColoredStripShader(size_t maxVerts, Mode mode, CTexture& tex) { -// CGraphics::CommitResources([this, maxVerts, mode, tex](boo::IGraphicsDataFactory::Context& ctx) { -// BuildResources(ctx, maxVerts, mode, tex); -// return true; -// } BooTrace); -} - -void CColoredStripShader::draw(const zeus::CColor& color, size_t numVerts, const Vert* verts) { - SCOPED_GRAPHICS_DEBUG_GROUP("CColoredStripShader::draw", zeus::skMagenta); - -// m_vbo->load(verts, sizeof(Vert) * numVerts); - - m_uniform.m_matrix = CGraphics::GetPerspectiveProjectionMatrix(/*true*/) * CGraphics::g_GXModelView.toMatrix4f(); - m_uniform.m_color = color; -// m_uniBuf->load(&m_uniform, sizeof(m_uniform)); -// -// CGraphics::SetShaderDataBinding(m_dataBind); -// CGraphics::DrawArray(0, numVerts); -} - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CColoredStripShader.hpp b/Runtime/Graphics/Shaders/CColoredStripShader.hpp deleted file mode 100644 index ee0f356d5..000000000 --- a/Runtime/Graphics/Shaders/CColoredStripShader.hpp +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once - -#include "Runtime/Graphics/CGraphics.hpp" - -#include -#include - -namespace metaforce { - -class CColoredStripShader { -public: - enum class Mode { Alpha, Additive, FullAdditive, Subtractive }; - -private: - struct Uniform { - zeus::CMatrix4f m_matrix; - zeus::CColor m_color; - }; -// boo::ObjToken m_vbo; -// boo::ObjToken m_uniBuf; -// boo::ObjToken m_dataBind; - Uniform m_uniform; - -// void BuildResources(boo::IGraphicsDataFactory::Context& ctx, size_t maxVerts, Mode mode, -// boo::ObjToken tex); - -public: - struct Vert { - zeus::CVector3f m_pos; - zeus::CColor m_color; - zeus::CVector2f m_uv; - }; - static void Initialize(); - static void Shutdown(); - CColoredStripShader(size_t maxVerts, Mode mode, CTexture& tex); - void draw(const zeus::CColor& color, size_t numVerts, const Vert* verts); -}; - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CDecalShaders.cpp b/Runtime/Graphics/Shaders/CDecalShaders.cpp deleted file mode 100644 index 47c8d62a2..000000000 --- a/Runtime/Graphics/Shaders/CDecalShaders.cpp +++ /dev/null @@ -1,72 +0,0 @@ -#include "Runtime/Graphics/Shaders/CDecalShaders.hpp" - -#include - -#include "Runtime/Particle/CDecal.hpp" - -//#include - -namespace metaforce { - -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(CQuadDecal& decal) { -// boo::ObjToken regPipeline; -// boo::ObjToken redToAlphaPipeline; - -// if (decal.m_desc->x14_TEX) { -// if (decal.m_desc->x18_ADD) -// regPipeline = m_texAdditiveZTest; -// else -// regPipeline = m_texZTestNoZWrite; -// redToAlphaPipeline = m_texRedToAlphaZTest; -// } else { -// if (decal.m_desc->x18_ADD) -// regPipeline = m_noTexAdditiveZTest; -// else -// regPipeline = m_noTexZTestNoZWrite; -// } -// -// const SQuadDescr* const desc = decal.m_desc; -// const CUVElement* const texr = desc->x14_TEX.get(); -// size_t texCount = 0; -// std::array, 1> textures; -// -// if (texr != nullptr) { -// textures[0] = texr->GetValueTexture(0).GetObj()->GetBooTexture(); -// texCount = 1; -// } -// -// if (!decal.m_instBuf) { -// return; -// } -// -// std::array, 1> uniforms{decal.m_uniformBuf.get()}; -// -// if (regPipeline) { -// decal.m_normalDataBind = -// ctx.newShaderDataBinding(regPipeline, nullptr, decal.m_instBuf.get(), nullptr, uniforms.size(), uniforms.data(), -// nullptr, texCount, textures.data(), nullptr, nullptr); -// } -// if (redToAlphaPipeline) { -// decal.m_redToAlphaDataBind = -// ctx.newShaderDataBinding(redToAlphaPipeline, nullptr, decal.m_instBuf.get(), nullptr, uniforms.size(), -// uniforms.data(), nullptr, texCount, textures.data(), nullptr, nullptr); -// } -} - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CDecalShaders.hpp b/Runtime/Graphics/Shaders/CDecalShaders.hpp deleted file mode 100644 index 53cde90f4..000000000 --- a/Runtime/Graphics/Shaders/CDecalShaders.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -//#include - -namespace metaforce { -struct CQuadDecal; - -class CDecalShaders { -private: -// static inline boo::ObjToken m_texZTestNoZWrite; -// static inline boo::ObjToken m_texAdditiveZTest; -// static inline boo::ObjToken m_texRedToAlphaZTest; -// -// static inline boo::ObjToken m_noTexZTestNoZWrite; -// static inline boo::ObjToken m_noTexAdditiveZTest; - -public: - static void Initialize(); - static void Shutdown(); - static void BuildShaderDataBinding(CQuadDecal& decal); -}; - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CElementGenShaders.cpp b/Runtime/Graphics/Shaders/CElementGenShaders.cpp deleted file mode 100644 index 90f39c69e..000000000 --- a/Runtime/Graphics/Shaders/CElementGenShaders.cpp +++ /dev/null @@ -1,298 +0,0 @@ -#include "Runtime/Graphics/Shaders/CElementGenShaders.hpp" - -#include - -#include "Runtime/Particle/CElementGen.hpp" - -//#include - -namespace metaforce { - -void CElementGenShaders::Initialize() { -// m_texZTestZWrite = {hecl::conv->convert(Shader_CElementGenShaderTexZTestZWrite{}), -// hecl::conv->convert(Shader_CElementGenShaderTexZTestZWrite{})}; -// m_texNoZTestZWrite = {hecl::conv->convert(Shader_CElementGenShaderTexNoZTestZWrite{}), -// hecl::conv->convert(Shader_CElementGenShaderTexNoZTestZWriteAWrite{})}; -// m_texZTestNoZWrite = {hecl::conv->convert(Shader_CElementGenShaderTexZTestNoZWrite{}), -// hecl::conv->convert(Shader_CElementGenShaderTexZTestNoZWriteAWrite{})}; -// m_texNoZTestNoZWrite = {hecl::conv->convert(Shader_CElementGenShaderTexNoZTestNoZWrite{}), -// hecl::conv->convert(Shader_CElementGenShaderTexNoZTestNoZWriteAWrite{})}; -// m_texAdditiveZTest = {hecl::conv->convert(Shader_CElementGenShaderTexAdditiveZTest{}), -// hecl::conv->convert(Shader_CElementGenShaderTexAdditiveZTestAWrite{})}; -// m_texAdditiveNoZTest = {hecl::conv->convert(Shader_CElementGenShaderTexAdditiveNoZTest{}), -// hecl::conv->convert(Shader_CElementGenShaderTexAdditiveNoZTestAWrite{})}; -// m_texRedToAlphaZTest = {hecl::conv->convert(Shader_CElementGenShaderTexRedToAlphaZTest{}), -// hecl::conv->convert(Shader_CElementGenShaderTexRedToAlphaZTestAWrite{})}; -// m_texRedToAlphaNoZTest = {hecl::conv->convert(Shader_CElementGenShaderTexRedToAlphaNoZTest{}), -// hecl::conv->convert(Shader_CElementGenShaderTexRedToAlphaNoZTestAWrite{})}; -// m_texZTestNoZWriteSub = {hecl::conv->convert(Shader_CElementGenShaderTexZTestNoZWriteSub{}), -// hecl::conv->convert(Shader_CElementGenShaderTexZTestNoZWriteSubAWrite{})}; -// m_texNoZTestNoZWriteSub = {hecl::conv->convert(Shader_CElementGenShaderTexNoZTestNoZWriteSub{}), -// hecl::conv->convert(Shader_CElementGenShaderTexNoZTestNoZWriteSubAWrite{})}; -// m_texRedToAlphaZTestSub = {hecl::conv->convert(Shader_CElementGenShaderTexRedToAlphaZTestSub{}), -// hecl::conv->convert(Shader_CElementGenShaderTexRedToAlphaZTestSubAWrite{})}; -// m_texRedToAlphaNoZTestSub = {hecl::conv->convert(Shader_CElementGenShaderTexRedToAlphaNoZTestSub{}), -// hecl::conv->convert(Shader_CElementGenShaderTexRedToAlphaNoZTestSubAWrite{})}; -// -// m_indTexZWrite = {hecl::conv->convert(Shader_CElementGenShaderIndTexZWrite{}), -// hecl::conv->convert(Shader_CElementGenShaderIndTexZWriteAWrite{})}; -// m_indTexNoZWrite = {hecl::conv->convert(Shader_CElementGenShaderIndTexNoZWrite{}), -// hecl::conv->convert(Shader_CElementGenShaderIndTexNoZWriteAWrite{})}; -// m_indTexAdditive = {hecl::conv->convert(Shader_CElementGenShaderIndTexAdditive{}), -// hecl::conv->convert(Shader_CElementGenShaderIndTexAdditiveAWrite{})}; -// -// m_cindTexZWrite = {hecl::conv->convert(Shader_CElementGenShaderCindTexZWrite{}), -// hecl::conv->convert(Shader_CElementGenShaderCindTexZWriteAWrite{})}; -// m_cindTexNoZWrite = {hecl::conv->convert(Shader_CElementGenShaderCindTexNoZWrite{}), -// hecl::conv->convert(Shader_CElementGenShaderCindTexNoZWriteAWrite{})}; -// m_cindTexAdditive = {hecl::conv->convert(Shader_CElementGenShaderCindTexAdditive{}), -// hecl::conv->convert(Shader_CElementGenShaderCindTexAdditiveAWrite{})}; -// -// m_noTexZTestZWrite = {hecl::conv->convert(Shader_CElementGenShaderNoTexZTestZWrite{}), -// hecl::conv->convert(Shader_CElementGenShaderNoTexZTestZWriteAWrite{})}; -// m_noTexNoZTestZWrite = {hecl::conv->convert(Shader_CElementGenShaderNoTexNoZTestZWrite{}), -// hecl::conv->convert(Shader_CElementGenShaderNoTexNoZTestZWriteAWrite{})}; -// m_noTexZTestNoZWrite = {hecl::conv->convert(Shader_CElementGenShaderNoTexZTestNoZWrite{}), -// hecl::conv->convert(Shader_CElementGenShaderNoTexZTestNoZWriteAWrite{})}; -// m_noTexNoZTestNoZWrite = {hecl::conv->convert(Shader_CElementGenShaderNoTexNoZTestNoZWrite{}), -// hecl::conv->convert(Shader_CElementGenShaderNoTexNoZTestNoZWriteAWrite{})}; -// m_noTexAdditiveZTest = {hecl::conv->convert(Shader_CElementGenShaderNoTexAdditiveZTest{}), -// hecl::conv->convert(Shader_CElementGenShaderNoTexAdditiveZTestAWrite{})}; -// m_noTexAdditiveNoZTest = {hecl::conv->convert(Shader_CElementGenShaderNoTexAdditiveNoZTest{}), -// hecl::conv->convert(Shader_CElementGenShaderNoTexAdditiveNoZTestAWrite{})}; -} - -void CElementGenShaders::Shutdown() { -// for (auto& s : m_texZTestZWrite) -// s.reset(); -// for (auto& s : m_texNoZTestZWrite) -// s.reset(); -// for (auto& s : m_texZTestNoZWrite) -// s.reset(); -// for (auto& s : m_texNoZTestNoZWrite) -// s.reset(); -// for (auto& s : m_texAdditiveZTest) -// s.reset(); -// for (auto& s : m_texAdditiveNoZTest) -// s.reset(); -// for (auto& s : m_texRedToAlphaZTest) -// s.reset(); -// for (auto& s : m_texRedToAlphaNoZTest) -// s.reset(); -// for (auto& s : m_texZTestNoZWriteSub) -// s.reset(); -// for (auto& s : m_texNoZTestNoZWriteSub) -// s.reset(); -// for (auto& s : m_texRedToAlphaZTestSub) -// s.reset(); -// for (auto& s : m_texRedToAlphaNoZTestSub) -// s.reset(); -// -// for (auto& s : m_indTexZWrite) -// s.reset(); -// for (auto& s : m_indTexNoZWrite) -// s.reset(); -// for (auto& s : m_indTexAdditive) -// s.reset(); -// -// for (auto& s : m_cindTexZWrite) -// s.reset(); -// for (auto& s : m_cindTexNoZWrite) -// s.reset(); -// for (auto& s : m_cindTexAdditive) -// s.reset(); -// -// for (auto& s : m_noTexZTestZWrite) -// s.reset(); -// for (auto& s : m_noTexNoZTestZWrite) -// s.reset(); -// for (auto& s : m_noTexZTestNoZWrite) -// s.reset(); -// for (auto& s : m_noTexNoZTestNoZWrite) -// s.reset(); -// for (auto& s : m_noTexAdditiveZTest) -// s.reset(); -// for (auto& s : m_noTexAdditiveNoZTest) -// s.reset(); -} - -CElementGenShaders::EShaderClass CElementGenShaders::GetShaderClass(CElementGen& gen) { - CGenDescription* desc = gen.x1c_genDesc.GetObj(); - - if (desc->x54_x40_TEXR) { - if (desc->x58_x44_TIND) - return EShaderClass::IndTex; - else - return EShaderClass::Tex; - } else - return EShaderClass::NoTex; -} - -void CElementGenShaders::BuildShaderDataBinding(CElementGen& gen) { - CGenDescription* desc = gen.x1c_genDesc.GetObj(); -// std::array, 2>* regPipeline = nullptr; -// std::array, 2>* regPipelineSub = nullptr; -// std::array, 2>* redToAlphaPipeline = nullptr; -// std::array, 2>* redToAlphaPipelineSub = nullptr; -// std::array, 2>* regPipelinePmus = nullptr; -// std::array, 2>* redToAlphaPipelinePmus = nullptr; -// -// if (gen.x26c_28_zTest) { -// redToAlphaPipeline = &m_texRedToAlphaZTest; -// regPipelineSub = &m_texZTestNoZWriteSub; -// redToAlphaPipelineSub = &m_texRedToAlphaZTestSub; -// } else { -// redToAlphaPipeline = &m_texRedToAlphaNoZTest; -// regPipelineSub = &m_texNoZTestNoZWriteSub; -// redToAlphaPipelineSub = &m_texRedToAlphaNoZTestSub; -// } -// -// if (desc->x54_x40_TEXR) { -// if (desc->x58_x44_TIND) { -// if (desc->x45_30_x32_24_CIND) { -// if (gen.x26c_26_AAPH) -// regPipeline = &m_cindTexAdditive; -// else { -// if (gen.x26c_27_ZBUF) -// regPipeline = &m_cindTexZWrite; -// else -// regPipeline = &m_cindTexNoZWrite; -// } -// } else { -// if (gen.x26c_26_AAPH) -// regPipeline = &m_indTexAdditive; -// else { -// if (gen.x26c_27_ZBUF) -// regPipeline = &m_indTexZWrite; -// else -// regPipeline = &m_indTexNoZWrite; -// } -// } -// } else { -// if (gen.x26c_26_AAPH) { -// if (gen.x26c_28_zTest) -// regPipeline = &m_texAdditiveZTest; -// else -// regPipeline = &m_texAdditiveNoZTest; -// } else { -// if (gen.x26c_28_zTest) { -// if (gen.x26c_27_ZBUF) -// regPipeline = &m_texZTestZWrite; -// else -// regPipeline = &m_texZTestNoZWrite; -// } else { -// if (gen.x26c_27_ZBUF) -// regPipeline = &m_texNoZTestZWrite; -// else -// regPipeline = &m_texNoZTestNoZWrite; -// } -// } -// } -// } else { -// if (gen.x26c_26_AAPH) { -// if (gen.x26c_28_zTest) -// regPipeline = &m_noTexAdditiveZTest; -// else -// regPipeline = &m_noTexAdditiveNoZTest; -// } else { -// if (gen.x26c_28_zTest) { -// if (gen.x26c_27_ZBUF) -// regPipeline = &m_noTexZTestZWrite; -// else -// regPipeline = &m_noTexZTestNoZWrite; -// } else { -// if (gen.x26c_27_ZBUF) -// regPipeline = &m_noTexNoZTestZWrite; -// else -// regPipeline = &m_noTexNoZTestNoZWrite; -// } -// } -// } -// -// if (desc->x45_24_x31_26_PMUS) { -// if (desc->x54_x40_TEXR) { -// redToAlphaPipelinePmus = &m_texRedToAlphaZTest; -// if (desc->x44_31_x31_25_PMAB) -// regPipelinePmus = &m_texAdditiveZTest; -// else -// regPipelinePmus = &m_texZTestZWrite; -// } else { -// if (desc->x44_31_x31_25_PMAB) -// regPipelinePmus = &m_noTexAdditiveZTest; -// else -// regPipelinePmus = &m_noTexZTestZWrite; -// } -// } -// -// const CUVElement* const texr = desc->x54_x40_TEXR.get(); -// const CUVElement* const tind = desc->x58_x44_TIND.get(); -// int texCount = 0; -// std::array, 3> textures; -// -// 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) { -// const std::array, 1> uniforms{gen.m_uniformBuf.get()}; -// -// if (regPipeline != nullptr) { -// for (size_t i = 0; i < gen.m_normalDataBind.size(); ++i) { -// gen.m_normalDataBind[i] = -// ctx.newShaderDataBinding((*regPipeline)[i], nullptr, gen.m_instBuf.get(), nullptr, uniforms.size(), -// uniforms.data(), nullptr, texCount, textures.data(), nullptr, nullptr); -// } -// } -// if (regPipelineSub != nullptr) { -// for (size_t i = 0; i < gen.m_normalSubDataBind.size(); ++i) { -// gen.m_normalSubDataBind[i] = -// ctx.newShaderDataBinding((*regPipelineSub)[i], nullptr, gen.m_instBuf.get(), nullptr, uniforms.size(), -// uniforms.data(), nullptr, texCount, textures.data(), nullptr, nullptr); -// } -// } -// if (redToAlphaPipeline != nullptr) { -// for (size_t i = 0; i < gen.m_redToAlphaDataBind.size(); ++i) { -// gen.m_redToAlphaDataBind[i] = -// ctx.newShaderDataBinding((*redToAlphaPipeline)[i], nullptr, gen.m_instBuf.get(), nullptr, uniforms.size(), -// uniforms.data(), nullptr, texCount, textures.data(), nullptr, nullptr); -// } -// } -// if (redToAlphaPipelineSub != nullptr) { -// for (size_t i = 0; i < gen.m_redToAlphaSubDataBind.size(); ++i) { -// gen.m_redToAlphaSubDataBind[i] = ctx.newShaderDataBinding( -// (*redToAlphaPipelineSub)[i], nullptr, gen.m_instBuf.get(), nullptr, uniforms.size(), uniforms.data(), -// nullptr, texCount, textures.data(), nullptr, nullptr); -// } -// } -// } -// -// if (gen.m_instBufPmus) { -// const std::array, 1> uniforms{gen.m_uniformBufPmus.get()}; -// texCount = std::min(texCount, 1); -// -// if (regPipelinePmus != nullptr) { -// for (size_t i = 0; i < gen.m_normalDataBindPmus.size(); ++i) { -// gen.m_normalDataBindPmus[i] = -// ctx.newShaderDataBinding((*regPipelinePmus)[i], nullptr, gen.m_instBufPmus.get(), nullptr, uniforms.size(), -// uniforms.data(), nullptr, texCount, textures.data(), nullptr, nullptr); -// } -// } -// if (redToAlphaPipelinePmus != nullptr) { -// for (size_t i = 0; i < gen.m_redToAlphaDataBindPmus.size(); ++i) { -// gen.m_redToAlphaDataBindPmus[i] = ctx.newShaderDataBinding( -// (*redToAlphaPipelinePmus)[i], nullptr, gen.m_instBufPmus.get(), nullptr, uniforms.size(), uniforms.data(), -// nullptr, texCount, textures.data(), nullptr, nullptr); -// } -// } -// } -} - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CElementGenShaders.hpp b/Runtime/Graphics/Shaders/CElementGenShaders.hpp deleted file mode 100644 index c5171a6c7..000000000 --- a/Runtime/Graphics/Shaders/CElementGenShaders.hpp +++ /dev/null @@ -1,50 +0,0 @@ -#pragma once - -#include - -//#include - -namespace metaforce { -class CElementGen; - -class CElementGenShaders { -public: - enum class EShaderClass { Tex, IndTex, NoTex }; - -private: -// static inline std::array, 2> m_texZTestZWrite; -// static inline std::array, 2> m_texNoZTestZWrite; -// static inline std::array, 2> m_texZTestNoZWrite; -// static inline std::array, 2> m_texNoZTestNoZWrite; -// static inline std::array, 2> m_texAdditiveZTest; -// static inline std::array, 2> m_texAdditiveNoZTest; -// static inline std::array, 2> m_texRedToAlphaZTest; -// static inline std::array, 2> m_texRedToAlphaNoZTest; -// static inline std::array, 2> m_texZTestNoZWriteSub; -// static inline std::array, 2> m_texNoZTestNoZWriteSub; -// static inline std::array, 2> m_texRedToAlphaZTestSub; -// static inline std::array, 2> m_texRedToAlphaNoZTestSub; -// -// static inline std::array, 2> m_indTexZWrite; -// static inline std::array, 2> m_indTexNoZWrite; -// static inline std::array, 2> m_indTexAdditive; -// -// static inline std::array, 2> m_cindTexZWrite; -// static inline std::array, 2> m_cindTexNoZWrite; -// static inline std::array, 2> m_cindTexAdditive; -// -// static inline std::array, 2> m_noTexZTestZWrite; -// static inline std::array, 2> m_noTexNoZTestZWrite; -// static inline std::array, 2> m_noTexZTestNoZWrite; -// static inline std::array, 2> m_noTexNoZTestNoZWrite; -// static inline std::array, 2> m_noTexAdditiveZTest; -// static inline std::array, 2> m_noTexAdditiveNoZTest; - -public: - static void Initialize(); - static void Shutdown(); - static EShaderClass GetShaderClass(CElementGen& gen); - static void BuildShaderDataBinding(CElementGen& gen); -}; - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CEnergyBarShader.cpp b/Runtime/Graphics/Shaders/CEnergyBarShader.cpp deleted file mode 100644 index c17ed0202..000000000 --- a/Runtime/Graphics/Shaders/CEnergyBarShader.cpp +++ /dev/null @@ -1,95 +0,0 @@ -#include "Runtime/Graphics/Shaders/CEnergyBarShader.hpp" - -#include - -#include "Runtime/Graphics/CGraphics.hpp" -#include "Runtime/Graphics/CTexture.hpp" - -//#include - -namespace metaforce { - -//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(); -} - -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) { - SCOPED_GRAPHICS_DEBUG_GROUP("CEnergyBarShader::draw", zeus::skMagenta); - - size_t totalVerts = verts0.size() + verts1.size() + verts2.size(); - if (!totalVerts) - return; - - if (totalVerts > m_maxVerts) { - m_maxVerts = totalVerts; - m_tex = tex; -// CGraphics::CommitResources([this](boo::IGraphicsDataFactory::Context& ctx) { -// m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(Vertex), m_maxVerts); -// -// std::array, 1> bufs; -// constexpr std::array stages{boo::PipelineStage::Vertex}; -// const std::array, 1> texs{m_tex->GetBooTexture()}; -// -// for (size_t i = 0; i < m_uniBuf.size(); ++i) { -// m_uniBuf[i] = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); -// bufs[0] = m_uniBuf[i].get(); -// m_dataBind[i] = -// ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), stages.data(), -// nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr); -// } -// -// return true; -// } BooTrace); - } - - size_t vertIter = 0; -// Vertex* verts = reinterpret_cast(m_vbo->map(sizeof(Vertex) * totalVerts)); -// if (verts0.size()) { -// memmove(verts, verts0.data(), sizeof(Vertex) * verts0.size()); -// vertIter += verts0.size(); -// } -// if (verts1.size()) { -// memmove(verts + vertIter, verts1.data(), sizeof(Vertex) * verts1.size()); -// vertIter += verts1.size(); -// } -// if (verts2.size()) { -// memmove(verts + vertIter, verts2.data(), sizeof(Vertex) * verts2.size()); -// } -// m_vbo->unmap(); - - vertIter = 0; - if (verts0.size()) { - m_uniform.m_color = color0; -// m_uniBuf[0]->load(&m_uniform, sizeof(Uniform)); -// CGraphics::SetShaderDataBinding(m_dataBind[0]); -// CGraphics::DrawArray(0, verts0.size()); - vertIter += verts0.size(); - } - if (verts1.size()) { - m_uniform.m_color = color1; -// m_uniBuf[1]->load(&m_uniform, sizeof(Uniform)); -// CGraphics::SetShaderDataBinding(m_dataBind[1]); -// CGraphics::DrawArray(vertIter, verts1.size()); - vertIter += verts1.size(); - } - if (verts2.size()) { - m_uniform.m_color = color2; -// m_uniBuf[2]->load(&m_uniform, sizeof(Uniform)); -// CGraphics::SetShaderDataBinding(m_dataBind[2]); -// CGraphics::DrawArray(vertIter, verts2.size()); - } -} - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CEnergyBarShader.hpp b/Runtime/Graphics/Shaders/CEnergyBarShader.hpp deleted file mode 100644 index 6cb6b47a7..000000000 --- a/Runtime/Graphics/Shaders/CEnergyBarShader.hpp +++ /dev/null @@ -1,44 +0,0 @@ -#pragma once - -#include -#include - -//#include - -#include -#include -#include -#include - -namespace metaforce { -class CTexture; - -class CEnergyBarShader { -public: - struct Vertex { - zeus::CVector3f pos; - zeus::CVector2f uv; - }; - -private: - struct Uniform { - zeus::CMatrix4f m_matrix; - zeus::CColor m_color; - }; -// boo::ObjToken m_vbo; -// std::array, 3> m_uniBuf; -// std::array, 3> m_dataBind; - Uniform m_uniform; - const CTexture* m_tex = nullptr; - size_t m_maxVerts = 0; - -public: - static void Initialize(); - static void Shutdown(); - void updateModelMatrix(); - void 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); -}; - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CEnvFxShaders.cpp b/Runtime/Graphics/Shaders/CEnvFxShaders.cpp deleted file mode 100644 index 7302486ea..000000000 --- a/Runtime/Graphics/Shaders/CEnvFxShaders.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include "Runtime/Graphics/Shaders/CEnvFxShaders.hpp" - -#include "Runtime/World/CEnvFxManager.hpp" - -//#include - -namespace metaforce { -//boo::ObjToken CEnvFxShaders::m_snowPipeline; -//boo::ObjToken CEnvFxShaders::m_underwaterPipeline; - -void CEnvFxShaders::Initialize() { -// m_snowPipeline = hecl::conv->convert(Shader_CEnvFxSnowShader{}); -// m_underwaterPipeline = hecl::conv->convert(Shader_CEnvFxUnderwaterShader{}); -} - -void CEnvFxShaders::Shutdown() { -// m_snowPipeline.reset(); -// m_underwaterPipeline.reset(); -} - -void CEnvFxShaders::BuildShaderDataBinding(CEnvFxManager& fxMgr, - CEnvFxManagerGrid& grid) { -// const auto uBufInfo = grid.m_uniformBuf.getBufferInfo(); -// const auto iBufInfo = grid.m_instBuf.getBufferInfo(); - -// const std::array, 2> uniforms{{ -// uBufInfo.first.get(), -// fxMgr.m_fogUniformBuf.get(), -// }}; -// const std::array ubufOffsets{ -// size_t(uBufInfo.second), -// 0, -// }; -// constexpr std::array ubufSizes{ -// sizeof(CEnvFxShaders::Uniform), -// sizeof(CGraphics::g_Fog), -// }; -// constexpr std::array uniformStages{ -// boo::PipelineStage::Vertex, -// boo::PipelineStage::Fragment, -// }; -// std::array, 2> textures{ -// fxMgr.xb74_txtrSnowFlake->GetBooTexture(), -// fxMgr.x40_txtrEnvGradient->GetBooTexture(), -// }; -// -// grid.m_snowBinding = ctx.newShaderDataBinding( -// m_snowPipeline, nullptr, iBufInfo.first.get(), nullptr, uniforms.size(), uniforms.data(), uniformStages.data(), -// ubufOffsets.data(), ubufSizes.data(), textures.size(), textures.data(), nullptr, nullptr, 0, iBufInfo.second); -// textures[0] = fxMgr.xc48_underwaterFlake->GetBooTexture(); -// grid.m_underwaterBinding = -// ctx.newShaderDataBinding(m_underwaterPipeline, nullptr, iBufInfo.first.get(), nullptr, uniforms.size(), -// uniforms.data(), uniformStages.data(), ubufOffsets.data(), ubufSizes.data(), -// textures.size(), textures.data(), nullptr, nullptr, 0, iBufInfo.second); -} - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CEnvFxShaders.hpp b/Runtime/Graphics/Shaders/CEnvFxShaders.hpp deleted file mode 100644 index 69fbbf5f5..000000000 --- a/Runtime/Graphics/Shaders/CEnvFxShaders.hpp +++ /dev/null @@ -1,41 +0,0 @@ -#pragma once - -#include - -//#include - -#include -#include -#include -#include - -namespace metaforce { -class CEnvFxManager; -class CEnvFxManagerGrid; - -class CEnvFxShaders { -public: - struct Instance { - std::array positions; - zeus::CColor color; - std::array uvs; - }; - struct Uniform { - zeus::CMatrix4f mv; - zeus::CMatrix4f proj; - zeus::CMatrix4f envMtx; - zeus::CColor moduColor; - }; - -private: -// static boo::ObjToken m_snowPipeline; -// static boo::ObjToken m_underwaterPipeline; - -public: - static void Initialize(); - static void Shutdown(); - static void BuildShaderDataBinding(CEnvFxManager& fxMgr, - CEnvFxManagerGrid& grid); -}; - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CFluidPlaneShader.cpp b/Runtime/Graphics/Shaders/CFluidPlaneShader.cpp deleted file mode 100644 index 3dd8b1477..000000000 --- a/Runtime/Graphics/Shaders/CFluidPlaneShader.cpp +++ /dev/null @@ -1,292 +0,0 @@ -#include "Runtime/Graphics/Shaders/CFluidPlaneShader.hpp" - -#include "Runtime/World/CRipple.hpp" -#include "Runtime/World/CRippleManager.hpp" - -//#include - -namespace metaforce { - -//CFluidPlaneShader::Cache CFluidPlaneShader::_cache = {}; -// -//u16 CFluidPlaneShader::Cache::MakeCacheKey(const SFluidPlaneShaderInfo& info) { -// u16 ret = 0; -// -// switch (info.m_type) { -// case EFluidType::NormalWater: -// case EFluidType::PhazonFluid: -// case EFluidType::Four: -// if (info.m_hasLightmap) { -// ret |= 1 << 2; -// if (info.m_doubleLightmapBlend) -// ret |= 1 << 3; -// } -// -// if (!info.m_hasEnvMap && info.m_hasEnvBumpMap) -// ret |= 1 << 4; -// -// if (info.m_hasEnvMap) -// ret |= 1 << 5; -// -// break; -// -// case EFluidType::PoisonWater: -// ret |= 1; -// -// if (info.m_hasLightmap) { -// ret |= 1 << 2; -// if (info.m_doubleLightmapBlend) -// ret |= 1 << 3; -// } -// -// if (info.m_hasEnvBumpMap) -// ret |= 1 << 4; -// -// break; -// -// case EFluidType::Lava: -// ret |= 2; -// -// if (info.m_hasBumpMap) -// ret |= 1 << 2; -// -// break; -// -// case EFluidType::ThickLava: -// ret |= 3; -// -// if (info.m_hasBumpMap) -// ret |= 1 << 2; -// -// break; -// } -// -// if (info.m_hasPatternTex1) -// ret |= 1 << 6; -// if (info.m_hasPatternTex2) -// ret |= 1 << 7; -// if (info.m_hasColorTex) -// ret |= 1 << 8; -// -// if (info.m_additive) -// ret |= 1 << 9; -// -// return ret; -//} -// -//u16 CFluidPlaneShader::Cache::MakeCacheKey(const SFluidPlaneDoorShaderInfo& info) { -// u16 ret = 0; -// -// if (info.m_hasPatternTex1) -// ret |= 1 << 0; -// if (info.m_hasPatternTex2) -// ret |= 1 << 1; -// if (info.m_hasColorTex) -// ret |= 1 << 2; -// -// return ret; -//} -// -//template <> -//CFluidPlaneShader::ShaderPair -//CFluidPlaneShader::Cache::GetOrBuildShader(const SFluidPlaneShaderInfo& info) { -// OPTICK_EVENT(); -// u16 key = MakeCacheKey(info); -// auto& slot = CacheSlot(info, key); -// if (slot.m_regular) -// return slot; -// -// 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) { -// OPTICK_EVENT(); -// u16 key = MakeCacheKey(info); -// auto& slot = CacheSlot(info, key); -// if (slot.m_regular) -// return slot; -// -// slot.m_regular = hecl::conv->convert(Shader_CFluidPlaneDoorShader{info}); -// -// return slot; -//} -// -//void CFluidPlaneShader::Cache::Clear() { -// for (auto& p : m_cache) -// p.reset(); -// for (auto& p : m_doorCache) -// p.reset(); -//} - -void CFluidPlaneShader::PrepareBinding(u32 maxVertCount) { -// CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { -// m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(Vertex), maxVertCount); -// if (m_pipelines.m_tessellation) { -// m_pvbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(PatchVertex), maxVertCount); -// } -// m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); -// -// const std::array, 3> ubufs{{ -// m_uniBuf.get(), -// m_uniBuf.get(), -// m_uniBuf.get(), -// }}; -// constexpr std::array ubufStages{ -// boo::PipelineStage::Vertex, -// boo::PipelineStage::Vertex, -// boo::PipelineStage::Fragment, -// }; -// constexpr std::array ubufOffs{ -// 0, -// 0, -// 1280, -// }; -// constexpr std::array ubufSizes{ -// 1280, -// 1280, -// sizeof(CModelShaders::LightingUniform), -// }; -// -// size_t texCount = 0; -// std::array, 8> texs; -// 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(m_pipelines.m_regular, m_vbo.get(), nullptr, nullptr, ubufs.size(), -// ubufs.data(), ubufStages.data(), ubufOffs.data(), ubufSizes.data(), -// texCount, texs.data(), nullptr, nullptr); -// boo::ObjToken tessellation; -// if (m_pipelines.m_tessellation) { -// texs[texCount++] = m_rippleMap.get(); -// tessellation = ctx.newShaderDataBinding(m_pipelines.m_tessellation, m_pvbo.get(), nullptr, nullptr, ubufs.size(), -// ubufs.data(), ubufStages.data(), ubufOffs.data(), ubufSizes.data(), -// texCount, texs.data(), nullptr, nullptr); -// } -// m_dataBind = {regular, tessellation}; -// return true; -// } BooTrace); -} - -void CFluidPlaneShader::Shutdown() { -// _cache.Clear(); -} - -CFluidPlaneShader::CFluidPlaneShader(EFluidType type, const TLockedToken& patternTex1, - const TLockedToken& patternTex2, const TLockedToken& colorTex, - const TLockedToken& bumpMap, const TLockedToken& envMap, - const TLockedToken& envBumpMap, const TLockedToken& lightmap, - CTexture& rippleMap, bool doubleLightmapBlend, - bool additive, u32 maxVertCount) -: m_patternTex1(patternTex1) -, m_patternTex2(patternTex2) -, m_colorTex(colorTex) -, m_bumpMap(bumpMap) -, m_envMap(envMap) -, m_envBumpMap(envBumpMap) -, m_lightmap(lightmap) -//, m_rippleMap(rippleMap) -{ - SFluidPlaneShaderInfo shaderInfo(type, m_patternTex1.HasReference(), m_patternTex2.HasReference(), - m_colorTex.HasReference(), m_bumpMap.HasReference(), m_envMap.HasReference(), - m_envBumpMap.HasReference(), m_lightmap.HasReference(), false/*m_rippleMap.operator bool()*/, - doubleLightmapBlend, additive); -// m_pipelines = _cache.GetOrBuildShader(shaderInfo); - PrepareBinding(maxVertCount); -} - -CFluidPlaneShader::CFluidPlaneShader(const TLockedToken& patternTex1, - const TLockedToken& patternTex2, const TLockedToken& colorTex, - u32 maxVertCount) -: m_patternTex1(patternTex1), m_patternTex2(patternTex2), m_colorTex(colorTex) { - SFluidPlaneDoorShaderInfo shaderInfo(m_patternTex1.HasReference(), m_patternTex2.HasReference(), - m_colorTex.HasReference()); -// m_pipelines = _cache.GetOrBuildShader(shaderInfo); - PrepareBinding(maxVertCount); -} - -void CFluidPlaneShader::prepareDraw(const RenderSetupInfo& info) { -// Uniform& uni = *reinterpret_cast(m_uniBuf->map(sizeof(Uniform))); -// uni.m_mv = CGraphics::g_GXModelView.toMatrix4f(); -// uni.m_mvNorm = info.normMtx; -// uni.m_proj = CGraphics::GetPerspectiveProjectionMatrix(true); -// uni.m_texMtxs = info.texMtxs; -// uni.m_lighting.ActivateLights(info.lights); -// for (size_t i = 0; i < uni.m_lighting.colorRegs.size(); ++i) { -// uni.m_lighting.colorRegs[i] = info.kColors[i]; -// } -// uni.m_lighting.mulColor = info.kColors[3]; -// uni.m_lighting.fog = CGraphics::g_Fog; -// uni.m_pad2.x() = info.indScale; -// m_uniBuf->unmap(); -} - -void CFluidPlaneShader::prepareDraw(const RenderSetupInfo& info, const zeus::CVector3f& waterCenter, - const CRippleManager& rippleManager, const zeus::CColor& colorMul, - float rippleNormResolution) { -// Uniform& uni = *reinterpret_cast(m_uniBuf->map(sizeof(Uniform))); -// uni.m_mv = CGraphics::g_GXModelView.toMatrix4f(); -// uni.m_mvNorm = info.normMtx; -// uni.m_proj = CGraphics::GetPerspectiveProjectionMatrix(true); -// uni.m_texMtxs = info.texMtxs; -// -// size_t i = 0; -// for (const CRipple& ripple : rippleManager.GetRipples()) { -// assert(i < uni.m_ripple.size() && "Too many ripples"); -// Ripple& rOut = uni.m_ripple[i++]; -// if (ripple.GetTime() >= ripple.GetTimeFalloff()) { -// rOut.center.zeroOut(); -// rOut.params.zeroOut(); -// continue; -// } -// zeus::CVector3f localPos = ripple.GetCenter() - waterCenter; -// rOut.center.x() = float(localPos.x()); -// rOut.center.y() = float(localPos.y()); -// rOut.center.z() = ripple.GetTime() * ripple.GetOOTimeFalloff(); -// rOut.center.w() = ripple.GetOODistanceFalloff(); -// rOut.params.x() = ripple.GetAmplitude(); -// rOut.params.y() = ripple.GetPhase(); -// rOut.params.z() = -// (1.f - ripple.GetTime() * ripple.GetOOTimeFalloff() * ripple.GetOOTimeFalloff()) * ripple.GetFrequency(); -// } -// uni.m_colorMul = colorMul; -// uni.m_pad[0].x() = rippleNormResolution; -// uni.m_lighting.ActivateLights(info.lights); -// for (i = 0; i < uni.m_lighting.colorRegs.size(); ++i) { -// uni.m_lighting.colorRegs[i] = info.kColors[i]; -// } -// uni.m_lighting.mulColor = info.kColors[3]; -// uni.m_lighting.fog = CGraphics::g_Fog; -// uni.m_pad2.x() = info.indScale; -// m_uniBuf->unmap(); -} - -void CFluidPlaneShader::loadVerts(const std::vector& verts, const std::vector& pVerts) { -// m_vbo->load(verts.data(), verts.size() * sizeof(Vertex)); -// if (m_pvbo) -// m_pvbo->load(pVerts.data(), pVerts.size() * sizeof(PatchVertex)); -} - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CFluidPlaneShader.hpp b/Runtime/Graphics/Shaders/CFluidPlaneShader.hpp deleted file mode 100644 index b4cbf9c1b..000000000 --- a/Runtime/Graphics/Shaders/CFluidPlaneShader.hpp +++ /dev/null @@ -1,178 +0,0 @@ -#pragma once - -#include -#include - -#include "Runtime/CToken.hpp" -#include "Runtime/Graphics/CTexture.hpp" -#include "Runtime/Graphics/Shaders/CModelShaders.hpp" -#include "Runtime/World/CFluidPlaneManager.hpp" - -#include "Shaders/shader_CFluidPlaneShader.hpp" - -//#include - -#include -#include -#include -#include - -namespace metaforce { - -class CFluidPlaneShader { -public: - struct Vertex { - zeus::CVector3f m_pos; - zeus::CVector3f m_norm; - zeus::CVector3f m_binorm; - zeus::CVector3f m_tangent; - zeus::CColor m_color; - - Vertex() = default; - Vertex(const zeus::CVector3f& position) : m_pos(position) {} - Vertex(const zeus::CVector3f& position, const zeus::CColor& color) : m_pos(position), m_color(color) {} - Vertex(const zeus::CVector3f& position, const zeus::CVector3f& normal, const zeus::CColor& color) - : m_pos(position), m_norm(normal), m_color(color) {} - Vertex(const zeus::CVector3f& position, const zeus::CVector3f& normal, const zeus::CVector3f& binormal, - const zeus::CVector3f& tangent, const zeus::CColor& color) - : m_pos(position), m_norm(normal), m_binorm(binormal), m_tangent(tangent), m_color(color) {} - }; - - struct PatchVertex { - zeus::CVector4f m_pos; - std::array m_outerLevels{}; - std::array m_innerLevels{}; - }; - - struct RenderSetupInfo { - std::array texMtxs; - zeus::CMatrix4f normMtx; - float indScale = 1.f; - std::array kColors; - std::vector lights; - }; - -private: -// struct ShaderPair { -// boo::ObjToken m_regular; -// boo::ObjToken m_tessellation; -// void reset() { -// m_regular.reset(); -// m_tessellation.reset(); -// } -// }; -// -// struct BindingPair { -// boo::ObjToken m_regular; -// boo::ObjToken m_tessellation; -// }; - -// class Cache { -// std::array m_cache{}; -// std::array m_doorCache{}; -// ShaderPair& CacheSlot(const SFluidPlaneShaderInfo& info, int i) { return m_cache[i]; } -// ShaderPair& CacheSlot(const SFluidPlaneDoorShaderInfo& info, int i) { return m_doorCache[i]; } -// static u16 MakeCacheKey(const SFluidPlaneShaderInfo& info); -// static u16 MakeCacheKey(const SFluidPlaneDoorShaderInfo& info); -// -// public: -// template -// ShaderPair GetOrBuildShader(const T& info); -// void Clear(); -// }; -// static Cache _cache; - - struct Ripple { - zeus::CVector4f center; // time, distFalloff - zeus::CVector4f params; // amplitude, lookupPhase, lookupTime - }; - -// struct Uniform { -// zeus::CMatrix4f m_mv; -// zeus::CMatrix4f m_mvNorm; -// zeus::CMatrix4f m_proj; -// std::array m_texMtxs; -// std::array m_ripple; -// zeus::CVector4f m_colorMul; -// std::array m_pad; // rippleNormResolution, Pad out to 1280 bytes -// CModelShaders::LightingUniform m_lighting; -// zeus::CVector3f m_pad2; // Pad out to 768 bytes, also holds ind scale -// }; - - TLockedToken m_patternTex1; - TLockedToken m_patternTex2; - TLockedToken m_colorTex; - TLockedToken m_bumpMap; - TLockedToken m_envMap; - TLockedToken m_envBumpMap; - TLockedToken m_lightmap; -// aurora::gfx::TextureHandle m_rippleMap; -// boo::ObjToken m_vbo; -// boo::ObjToken m_pvbo; -// boo::ObjToken m_uniBuf; -// ShaderPair m_pipelines; -// BindingPair m_dataBind; - int m_lastBind = -1; - -//#if BOO_HAS_GL -// static ShaderPair BuildShader(boo::GLDataFactory::Context& ctx, const SFluidPlaneShaderInfo& info); -// static ShaderPair BuildShader(boo::GLDataFactory::Context& ctx, const SFluidPlaneDoorShaderInfo& info); -// BindingPair BuildBinding(boo::GLDataFactory::Context& ctx, const ShaderPair& pipeline); -//#endif -//#if _WIN32 -// static ShaderPair BuildShader(boo::D3D11DataFactory::Context& ctx, const SFluidPlaneShaderInfo& info); -// static ShaderPair BuildShader(boo::D3D11DataFactory::Context& ctx, const SFluidPlaneDoorShaderInfo& info); -// BindingPair BuildBinding(boo::D3D11DataFactory::Context& ctx, const ShaderPair& pipeline); -//#endif -//#if BOO_HAS_METAL -// static ShaderPair BuildShader(boo::MetalDataFactory::Context& ctx, const SFluidPlaneShaderInfo& info); -// static ShaderPair BuildShader(boo::MetalDataFactory::Context& ctx, const SFluidPlaneDoorShaderInfo& info); -// BindingPair BuildBinding(boo::MetalDataFactory::Context& ctx, const ShaderPair& pipeline); -//#endif -//#if BOO_HAS_VULKAN -// static ShaderPair BuildShader(boo::VulkanDataFactory::Context& ctx, const SFluidPlaneShaderInfo& info); -// static ShaderPair BuildShader(boo::VulkanDataFactory::Context& ctx, const SFluidPlaneDoorShaderInfo& info); -// BindingPair BuildBinding(boo::VulkanDataFactory::Context& ctx, const ShaderPair& pipeline); -//#endif - - template - static void _Shutdown(); - - void PrepareBinding(u32 maxVertCount); - -public: - CFluidPlaneShader(EFluidType type, const TLockedToken& patternTex1, - const TLockedToken& patternTex2, const TLockedToken& colorTex, - const TLockedToken& bumpMap, const TLockedToken& envMap, - const TLockedToken& envBumpMap, const TLockedToken& lightmap, - CTexture& rippleMap, bool doubleLightmapBlend, bool additive, - u32 maxVertCount); - CFluidPlaneShader(const TLockedToken& patternTex1, const TLockedToken& patternTex2, - const TLockedToken& colorTex, u32 maxVertCount); - void prepareDraw(const RenderSetupInfo& info); - void prepareDraw(const RenderSetupInfo& info, const zeus::CVector3f& waterCenter, const CRippleManager& rippleManager, - const zeus::CColor& colorMul, float rippleNormResolution); - void bindRegular() { - if (m_lastBind != 0) { -// CGraphics::SetShaderDataBinding(m_dataBind.m_regular); - m_lastBind = 0; - } - } - bool bindTessellation() { - if (m_lastBind != 1) { -// CGraphics::SetShaderDataBinding(m_dataBind.m_tessellation); - m_lastBind = 1; - } - return true; - } - void doneDrawing() { m_lastBind = -1; } - void loadVerts(const std::vector& verts, const std::vector& pVerts); - bool isReady() const { -// return m_pipelines.m_regular->isReady() && (!m_pipelines.m_tessellation || m_pipelines.m_tessellation->isReady()); - return false; - } - - static void Shutdown(); -}; - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CFogVolumeFilter.cpp b/Runtime/Graphics/Shaders/CFogVolumeFilter.cpp deleted file mode 100644 index 925f397e5..000000000 --- a/Runtime/Graphics/Shaders/CFogVolumeFilter.cpp +++ /dev/null @@ -1,77 +0,0 @@ -#include "Runtime/Graphics/Shaders/CFogVolumeFilter.hpp" - -#include - -#include "Runtime/GameGlobalObjects.hpp" -#include "Runtime/Graphics/CCubeRenderer.hpp" -#include "Runtime/Graphics/CGraphics.hpp" - -//#include -//#include -#include - -namespace metaforce { - -//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) { -// struct Vert { -// zeus::CVector2f m_pos; -// zeus::CVector2f m_uv; -// }; -// constexpr std::array verts{{ -// {{-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.data(), sizeof(Vert), verts.size()); -// m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(zeus::CColor), 1); -// const std::array, 3> texs{ -// CGraphics::g_SpareTexture.get(), -// CGraphics::g_SpareTexture.get(), -// g_Renderer->GetFogRampTex().get(), -// }; -// constexpr std::array bindIdxs{0, 1, 0}; -// constexpr std::array bindDepth{true, true, false}; -// const std::array, 1> ubufs{m_uniBuf.get()}; -// -// m_dataBind1Way = -// ctx.newShaderDataBinding(s_1WayPipeline, m_vbo.get(), nullptr, nullptr, ubufs.size(), ubufs.data(), nullptr, -// nullptr, nullptr, texs.size(), texs.data(), bindIdxs.data(), bindDepth.data()); -// m_dataBind2Way = -// ctx.newShaderDataBinding(s_2WayPipeline, m_vbo.get(), nullptr, nullptr, ubufs.size(), ubufs.data(), nullptr, -// nullptr, nullptr, texs.size(), texs.data(), bindIdxs.data(), bindDepth.data()); -// return true; -// } BooTrace); -} - -void CFogVolumeFilter::draw2WayPass(const zeus::CColor& color) { - SCOPED_GRAPHICS_DEBUG_GROUP("CFogVolumeFilter::draw2WayPass", zeus::skMagenta); - -// m_uniBuf->load(&color, sizeof(zeus::CColor)); -// CGraphics::SetShaderDataBinding(m_dataBind2Way); -// CGraphics::DrawArray(0, 4); -} - -void CFogVolumeFilter::draw1WayPass(const zeus::CColor& color) { - SCOPED_GRAPHICS_DEBUG_GROUP("CFogVolumeFilter::draw1WayPass", zeus::skMagenta); - -// m_uniBuf->load(&color, sizeof(zeus::CColor)); -// CGraphics::SetShaderDataBinding(m_dataBind1Way); -// CGraphics::DrawArray(0, 4); -} - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CFogVolumeFilter.hpp b/Runtime/Graphics/Shaders/CFogVolumeFilter.hpp deleted file mode 100644 index ced382d90..000000000 --- a/Runtime/Graphics/Shaders/CFogVolumeFilter.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -namespace zeus { -class CColor; -} // namespace zeus - -namespace metaforce { - -class CFogVolumeFilter { -// 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); -}; - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CFogVolumePlaneShader.cpp b/Runtime/Graphics/Shaders/CFogVolumePlaneShader.cpp deleted file mode 100644 index 63dde5d69..000000000 --- a/Runtime/Graphics/Shaders/CFogVolumePlaneShader.cpp +++ /dev/null @@ -1,65 +0,0 @@ -#include "Runtime/Graphics/Shaders/CFogVolumePlaneShader.hpp" - -#include "Runtime/Graphics/CGraphics.hpp" - -//#include - -namespace metaforce { - -//static std::array, 4> s_Pipelines; -// -//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); -// for (size_t i = 0; i < m_dataBinds.size(); ++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); -//} - -void CFogVolumePlaneShader::addFan(const zeus::CVector3f* verts, int numVerts) { - zeus::CMatrix4f proj = CGraphics::GetPerspectiveProjectionMatrix(/*true*/); - zeus::CVector4f vert0 = proj * zeus::CVector4f(CGraphics::g_GXModelView * verts[0]); - if (!m_verts.empty()) { - m_verts.push_back(m_verts.back()); - m_verts.push_back(vert0); - if (m_verts.size() & 1) - m_verts.push_back(vert0); - } - TriFanToStrip fanToStrip(m_verts); - fanToStrip.AddVert(vert0); - for (int i = 1; i < numVerts; ++i) - fanToStrip.AddVert(proj * zeus::CVector4f(CGraphics::g_GXModelView * verts[i])); -} - -void CFogVolumePlaneShader::draw(int pass) { - if (m_verts.empty()) - return; - SCOPED_GRAPHICS_DEBUG_GROUP("CFogVolumePlaneShader::draw", zeus::skMagenta); -// if (pass == 0) { -// if (m_vertCapacity < m_verts.size()) -// CommitResources(m_verts.size()); -// m_vbo->load(m_verts.data(), m_verts.size() * sizeof(zeus::CVector4f)); -// } -// CGraphics::SetShaderDataBinding(m_dataBinds[pass]); -// CGraphics::DrawArray(0, m_verts.size()); -} - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CFogVolumePlaneShader.hpp b/Runtime/Graphics/Shaders/CFogVolumePlaneShader.hpp deleted file mode 100644 index 25376341b..000000000 --- a/Runtime/Graphics/Shaders/CFogVolumePlaneShader.hpp +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - -#include -#include -#include - -//#include - -#include -#include - -namespace zeus { -class CVector3f; -} // namespace zeus - -namespace metaforce { - -class CFogVolumePlaneShader { -// boo::ObjToken m_vbo; -// std::array, 4> m_dataBinds; - size_t m_vertCapacity = 0; -public: - std::vector m_verts; - -public: - 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); -}; - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CLineRendererShaders.cpp b/Runtime/Graphics/Shaders/CLineRendererShaders.cpp deleted file mode 100644 index 01f699abb..000000000 --- a/Runtime/Graphics/Shaders/CLineRendererShaders.cpp +++ /dev/null @@ -1,116 +0,0 @@ -#include "Runtime/Graphics/Shaders/CLineRendererShaders.hpp" - -#include - -#include "Runtime/Graphics/CLineRenderer.hpp" - -//#include - -namespace metaforce { - -void CLineRendererShaders::Initialize() { -// CGraphics::CommitResources([](boo::IGraphicsDataFactory::Context& ctx) { -// m_texAlpha = {hecl::conv->convert(ctx, Shader_CLineRendererShaderTexAlpha{}), -// hecl::conv->convert(ctx, Shader_CLineRendererShaderTexAlphaAWrite{})}; -// m_texAdditive = {hecl::conv->convert(ctx, Shader_CLineRendererShaderTexAdditive{}), -// hecl::conv->convert(ctx, Shader_CLineRendererShaderTexAdditiveAWrite{})}; -// m_noTexAlpha = {hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAlpha{}), -// hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAlphaAWrite{})}; -// m_noTexAdditive = {hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAdditive{}), -// hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAdditiveAWrite{})}; -// m_texAlphaZ = {hecl::conv->convert(ctx, Shader_CLineRendererShaderTexAlphaZ{}), -// hecl::conv->convert(ctx, Shader_CLineRendererShaderTexAlphaZAWrite{})}; -// m_texAdditiveZ = {hecl::conv->convert(ctx, Shader_CLineRendererShaderTexAdditiveZ{}), -// hecl::conv->convert(ctx, Shader_CLineRendererShaderTexAdditiveZAWrite{})}; -// m_noTexAlphaZ = {hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAlphaZ{}), -// hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAlphaZAWrite{})}; -// m_noTexAdditiveZ = {hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAdditiveZ{}), -// hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAdditiveZAWrite{})}; -// m_noTexAlphaZGEqual = {hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAlphaZGEqual{}), -// hecl::conv->convert(ctx, Shader_CLineRendererShaderNoTexAlphaZGEqualAWrite{})}; -// return true; -// } BooTrace); -} - -void CLineRendererShaders::Shutdown() { -// for (auto& s : m_texAlpha) -// s.reset(); -// for (auto& s : m_texAdditive) -// s.reset(); -// for (auto& s : m_noTexAlpha) -// s.reset(); -// for (auto& s : m_noTexAdditive) -// s.reset(); -// for (auto& s : m_texAlphaZ) -// s.reset(); -// for (auto& s : m_texAdditiveZ) -// s.reset(); -// for (auto& s : m_noTexAlphaZ) -// s.reset(); -// for (auto& s : m_noTexAdditiveZ) -// s.reset(); -// for (auto& s : m_noTexAlphaZGEqual) -// s.reset(); -} - -void CLineRendererShaders::BuildShaderDataBinding(CLineRenderer& renderer, - CTexture& texture, bool additive, - bool zTest, bool zGEqual) { -// std::array, 2>* pipeline = nullptr; -// -// if (zGEqual) { -// pipeline = &m_noTexAlphaZGEqual; -// } else if (zTest) { -// if (texture) { -// if (additive) -// pipeline = &m_texAdditiveZ; -// else -// pipeline = &m_texAlphaZ; -// } else { -// if (additive) -// pipeline = &m_noTexAdditiveZ; -// else -// pipeline = &m_noTexAlphaZ; -// } -// } else { -// if (texture) { -// if (additive) -// pipeline = &m_texAdditive; -// else -// pipeline = &m_texAlpha; -// } else { -// if (additive) -// pipeline = &m_noTexAdditive; -// else -// pipeline = &m_noTexAlpha; -// } -// } -// -// size_t texCount = 0; -// std::array, 1> textures; -// -// 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(); -// } -// -// const std::array, 1> uniforms{ubufInfo.first.get()}; -// constexpr std::array stages{boo::PipelineStage::Fragment}; -// const std::array ubufOffs{size_t(ubufInfo.second)}; -// const std::array ubufSizes{sizeof(CLineRenderer::SDrawUniform)}; -// -// for (size_t i = 0; i < renderer.m_shaderBind.size(); ++i) { -// renderer.m_shaderBind[i] = ctx.newShaderDataBinding( -// (*pipeline)[i], vbufInfo.first.get(), nullptr, nullptr, uniforms.size(), uniforms.data(), stages.data(), -// ubufOffs.data(), ubufSizes.data(), texCount, textures.data(), nullptr, nullptr, vbufInfo.second); -// } -} - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CLineRendererShaders.hpp b/Runtime/Graphics/Shaders/CLineRendererShaders.hpp deleted file mode 100644 index 758e15e97..000000000 --- a/Runtime/Graphics/Shaders/CLineRendererShaders.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include - -#include "Runtime/Graphics/CGraphics.hpp" - -namespace metaforce { -class CLineRenderer; - -class CLineRendererShaders { -// static inline std::array, 2> m_texAlpha; -// static inline std::array, 2> m_texAdditive; -// -// static inline std::array, 2> m_noTexAlpha; -// static inline std::array, 2> m_noTexAdditive; -// -// static inline std::array, 2> m_texAlphaZ; -// static inline std::array, 2> m_texAdditiveZ; -// -// static inline std::array, 2> m_noTexAlphaZ; -// static inline std::array, 2> m_noTexAdditiveZ; -// -// static inline std::array, 2> m_noTexAlphaZGEqual; - -public: - static void Initialize(); - static void Shutdown(); - static void BuildShaderDataBinding(CLineRenderer& renderer, - CTexture& texture, bool additive, bool zTest, - bool zGEqual); -}; - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CMapSurfaceShader.cpp b/Runtime/Graphics/Shaders/CMapSurfaceShader.cpp deleted file mode 100644 index 3d43a79ca..000000000 --- a/Runtime/Graphics/Shaders/CMapSurfaceShader.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include "Runtime/Graphics/Shaders/CMapSurfaceShader.hpp" - -#include - -#include "Runtime/Graphics/CGraphics.hpp" - -//#include - -namespace metaforce { - -//static boo::ObjToken s_Pipeline; - -void CMapSurfaceShader::Initialize() { -// s_Pipeline = hecl::conv->convert(Shader_CMapSurfaceShader{}); -} - -void CMapSurfaceShader::Shutdown() { -// s_Pipeline.reset(); -} - -CMapSurfaceShader::CMapSurfaceShader(std::vector vbo, - std::vector ibo) -//: m_vbo(vbo), m_ibo(ibo) -{ -// m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); -// const std::array, 1> bufs{m_uniBuf.get()}; -// constexpr std::array stages{boo::PipelineStage::Vertex}; -// m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, m_ibo.get(), bufs.size(), bufs.data(), -// stages.data(), nullptr, nullptr, 0, nullptr, nullptr, nullptr); -} - -void CMapSurfaceShader::draw(const zeus::CColor& color, u32 start, u32 count) { - SCOPED_GRAPHICS_DEBUG_GROUP("CMapSurfaceShader::draw", zeus::skMagenta); - Uniform uniform = {CGraphics::GetPerspectiveProjectionMatrix(/*true*/) * CGraphics::g_GXModelView.toMatrix4f(), color}; -// m_uniBuf->load(&uniform, sizeof(Uniform)); -// CGraphics::SetShaderDataBinding(m_dataBind); -// CGraphics::DrawArrayIndexed(start, count); -} - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CMapSurfaceShader.hpp b/Runtime/Graphics/Shaders/CMapSurfaceShader.hpp deleted file mode 100644 index bb77cabaf..000000000 --- a/Runtime/Graphics/Shaders/CMapSurfaceShader.hpp +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once - -#include "Runtime/GCNTypes.hpp" -#include "Runtime/Graphics/CGraphics.hpp" - -#include -#include - -namespace metaforce { - -class CMapSurfaceShader { - struct Uniform { - zeus::CMatrix4f mtx; - zeus::CColor color; - }; - -// boo::ObjToken m_uniBuf; -// boo::ObjToken m_vbo; -// boo::ObjToken m_ibo; -// boo::ObjToken m_dataBind; - -public: - static void Initialize(); - static void Shutdown(); - CMapSurfaceShader(std::vector vbo, - std::vector ibo); - void draw(const zeus::CColor& color, u32 start, u32 count); -}; - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CModelShaders.cpp b/Runtime/Graphics/Shaders/CModelShaders.cpp deleted file mode 100644 index 192043249..000000000 --- a/Runtime/Graphics/Shaders/CModelShaders.cpp +++ /dev/null @@ -1,235 +0,0 @@ -#include "Runtime/Graphics/Shaders/CModelShaders.hpp" - -#include "Runtime/CStopwatch.hpp" -#include "Runtime/Graphics/CLight.hpp" - -//#include -//#include - -namespace metaforce { - -//std::unordered_map CModelShaders::g_ShaderPipelines; - -//void CModelShaders::LightingUniform::ActivateLights(const std::vector& lts) { -// ambient = zeus::skClear; -// size_t curLight = 0; -// -// for (const CLight& light : lts) { -// switch (light.GetType()) { -// case ELightType::LocalAmbient: -// ambient += light.GetColor(); -// break; -// case ELightType::Point: -// case ELightType::Spot: -// case ELightType::Custom: -// case ELightType::Directional: { -// if (curLight >= lights.size()) { -// continue; -// } -// CModelShaders::Light& lightOut = lights[curLight++]; -// lightOut.pos = CGraphics::g_CameraMatrix * light.GetPosition(); -// lightOut.dir = CGraphics::g_CameraMatrix.basis * light.GetDirection(); -// lightOut.dir.normalize(); -// lightOut.color = light.GetColor(); -// lightOut.linAtt[0] = light.GetAttenuationConstant(); -// lightOut.linAtt[1] = light.GetAttenuationLinear(); -// lightOut.linAtt[2] = light.GetAttenuationQuadratic(); -// lightOut.angAtt[0] = light.GetAngleAttenuationConstant(); -// lightOut.angAtt[1] = light.GetAngleAttenuationLinear(); -// lightOut.angAtt[2] = light.GetAngleAttenuationQuadratic(); -// -// if (light.GetType() == ELightType::Directional) -// lightOut.pos = (-lightOut.dir) * 1048576.f; -// break; -// } -// } -// } -// -// for (; curLight < lights.size(); ++curLight) { -// CModelShaders::Light& lightOut = lights[curLight]; -// lightOut.pos = zeus::skZero3f; -// lightOut.dir = zeus::skDown; -// lightOut.color = zeus::skClear; -// lightOut.linAtt[0] = 1.f; -// lightOut.linAtt[1] = 0.f; -// lightOut.linAtt[2] = 0.f; -// lightOut.angAtt[0] = 1.f; -// lightOut.angAtt[1] = 0.f; -// lightOut.angAtt[2] = 0.f; -// } -//} - -//using TexCoordSource = hecl::Backend::TexCoordSource; -// -//constexpr std::array ThermalTextures{{ -// {TexCoordSource::Normal, 7, true}, -//}}; -// -//constexpr std::array BallFadeTextures{{ -// {TexCoordSource::Position, 0, false}, // ID tex -// {TexCoordSource::Position, 0, false}, // Sphere ramp -// {TexCoordSource::Position, 1, false}, // TXTR_BallFade -//}}; -// -//constexpr std::array WorldShadowTextures{{ -// {TexCoordSource::Position, 7, false}, // Shadow tex -//}}; -// -//constexpr std::array DisintegrateTextures{{ -// {TexCoordSource::Position, 0, false}, // Ashy tex -// {TexCoordSource::Position, 1, false}, // Ashy tex -//}}; - -//static std::array g_ExtensionSlots{{ -// /* 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 model shading */ -// {1, ThermalTextures.data(), hecl::Backend::BlendFactor::One, hecl::Backend::BlendFactor::One, -// hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Backface, false, false, false, true}, -// /* Thermal model shading without Z-test or Z-write */ -// {1, ThermalTextures.data(), hecl::Backend::BlendFactor::One, hecl::Backend::BlendFactor::One, -// hecl::Backend::ZTest::None, hecl::Backend::CullMode::Backface, true, false, false, true}, -// /* Thermal static shading */ -// {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original, -// hecl::Backend::CullMode::Backface, false, false, false, true, false, false, true}, -// /* Thermal static shading without Z-write */ -// {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original, -// hecl::Backend::CullMode::Backface, true, false, false, true, false, false, false}, -// /* 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, false, 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.data(), 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.data(), 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}, -// /* Disintegration */ -// {2, DisintegrateTextures.data(), hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::InvSrcAlpha, -// hecl::Backend::ZTest::LEqual, hecl::Backend::CullMode::Original, false, false, true, false, false, true}, -// /* Forced additive shading without culling or Z-write and greater depth test */ -// {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Greater, -// hecl::Backend::CullMode::None, true, false, true}, -// /* Thermal cold shading */ -// {0, nullptr, hecl::Backend::BlendFactor::Original, hecl::Backend::BlendFactor::Original, -// hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Original, false, false, true, false, false, false, true}, -// /* Normal lit shading with alpha */ -// {0, nullptr, hecl::Backend::BlendFactor::Original, hecl::Backend::BlendFactor::Original, -// hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Backface}, -// /* Normal lit shading with alpha without Z-write or depth test */ -// {0, nullptr, hecl::Backend::BlendFactor::Original, hecl::Backend::BlendFactor::Original, hecl::Backend::ZTest::None, -// hecl::Backend::CullMode::Backface, true}, -// /* Normal lit shading with cube reflection */ -// {0, nullptr, hecl::Backend::BlendFactor::Original, hecl::Backend::BlendFactor::Original, -// hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Backface, false, false, true}, -// /* Normal lit shading with cube reflection and world shadow */ -// {1, WorldShadowTextures.data(), hecl::Backend::BlendFactor::Original, hecl::Backend::BlendFactor::Original, -// hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Backface, false, false, true}, -//}}; - -//constexpr std::array ShaderMacros{ -// "URDE_LIGHTING", -// "URDE_LIGHTING", -// "URDE_THERMAL_MODEL", -// "URDE_THERMAL_MODEL", -// "URDE_THERMAL_STATIC", -// "URDE_THERMAL_STATIC", -// "URDE_LIGHTING", -// "URDE_LIGHTING", -// "URDE_SOLID", -// "URDE_SOLID", -// "URDE_SOLID", -// "URDE_SOLID", -// "URDE_SOLID", -// "URDE_SOLID", -// "URDE_MB_SHADOW", -// "URDE_LIGHTING_SHADOW", -// "URDE_LIGHTING", -// "URDE_LIGHTING", -// "URDE_LIGHTING", -// "URDE_LIGHTING", -// "URDE_LIGHTING", -// "URDE_LIGHTING", -// "URDE_LIGHTING", -// "URDE_DISINTEGRATE", -// "URDE_LIGHTING", -// "URDE_THERMAL_COLD", -// "URDE_LIGHTING", -// "URDE_LIGHTING", -// "URDE_LIGHTING_CUBE_REFLECTION", -// "URDE_LIGHTING_CUBE_REFLECTION_SHADOW", -//}; - -void CModelShaders::Initialize() { -// for (size_t i = 0; i < g_ExtensionSlots.size(); i++) { -// g_ExtensionSlots[i].shaderMacro = ShaderMacros[i]; -// } -} - -void CModelShaders::Shutdown() { -// g_ShaderPipelines.clear(); -} - -//CModelShaders::ShaderPipelines CModelShaders::BuildExtendedShader(const hecl::Backend::ShaderTag& tag, -// const Material& material) { -// auto search = g_ShaderPipelines.find(tag.val64()); -// if (search != g_ShaderPipelines.cend()) -// return search->second; -// -// ShaderPipelines& newPipelines = g_ShaderPipelines[tag.val64()]; -// newPipelines = std::make_shared(); -// CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { -// size_t idx = 0; -// for (const auto& ext : g_ExtensionSlots) -// (*newPipelines)[idx++] = hecl::conv->convert(ctx, Shader_CModelShaders(SModelShadersInfo(material, tag, ext))); -// return true; -// } BooTrace); -// return newPipelines; -//} - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CModelShaders.hpp b/Runtime/Graphics/Shaders/CModelShaders.hpp deleted file mode 100644 index 190edfe3d..000000000 --- a/Runtime/Graphics/Shaders/CModelShaders.hpp +++ /dev/null @@ -1,113 +0,0 @@ -#pragma once - -#include -#include -#include - -//#include "DataSpec/DNAMP1/CMDLMaterials.hpp" - -#include "Runtime/Graphics/CGraphics.hpp" - -#include -#include -#include - -#define URDE_MAX_LIGHTS 8 - -namespace hecl::Backend { -class ShaderTag; -} - -namespace metaforce { -class CLight; - -enum class EExtendedShader : uint8_t { - Flat, - Lighting, - ThermalModel, - ThermalModelNoZTestNoZWrite, - ThermalStatic, - ThermalStaticNoZWrite, - ForcedAlpha, - ForcedAdditive, - SolidColor, - SolidColorAdditive, - SolidColorFrontfaceCullLEqualAlphaOnly, - SolidColorFrontfaceCullAlwaysAlphaOnly, // No Z-write or test - SolidColorBackfaceCullLEqualAlphaOnly, - SolidColorBackfaceCullGreaterAlphaOnly, // No Z-write - MorphBallShadow, - WorldShadow, - ForcedAlphaNoCull, - ForcedAdditiveNoCull, - ForcedAlphaNoZWrite, - ForcedAdditiveNoZWrite, - ForcedAlphaNoCullNoZWrite, - ForcedAdditiveNoCullNoZWrite, - DepthGEqualNoZWrite, - Disintegrate, - ForcedAdditiveNoZWriteDepthGreater, - ThermalCold, - LightingAlphaWrite, - LightingAlphaWriteNoZTestNoZWrite, - LightingCubeReflection, - LightingCubeReflectionWorldShadow, - MAX -}; - -class CModelShaders { - friend class CModel; - -public: -// struct Light { -// zeus::CVector3f pos; -// zeus::CVector3f dir; -// zeus::CColor color = zeus::skClear; -// std::array linAtt{1.f, 0.f, 0.f}; -// std::array angAtt{1.f, 0.f, 0.f}; -// }; -// -// struct LightingUniform { -// std::array lights; -// zeus::CColor ambient; -// std::array colorRegs; -// zeus::CColor mulColor; -// zeus::CColor addColor; -// CFogState fog; -// -// void ActivateLights(const std::vector& lts); -// }; -// -// struct ThermalUniform { -// zeus::CColor mulColor; -// zeus::CColor addColor; -// }; -// -// struct SolidUniform { -// zeus::CColor solidColor; -// }; -// -// struct MBShadowUniform { -// zeus::CVector4f shadowUp; -// float shadowId; -// }; -// -// struct OneTextureUniform { -// zeus::CColor addColor; -// CFogState fog; -// }; - - static void Initialize(); - static void Shutdown(); - -// using ShaderPipelinesData = std::array, size_t(EExtendedShader::MAX)>; -// using ShaderPipelines = std::shared_ptr; - -// using Material = DataSpec::DNAMP1::HMDLMaterialSet::Material; -// static ShaderPipelines BuildExtendedShader(const hecl::Backend::ShaderTag& tag, const Material& material); - -private: -// static std::unordered_map g_ShaderPipelines; -}; - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CParticleSwooshShaders.cpp b/Runtime/Graphics/Shaders/CParticleSwooshShaders.cpp deleted file mode 100644 index ebc3fc54b..000000000 --- a/Runtime/Graphics/Shaders/CParticleSwooshShaders.cpp +++ /dev/null @@ -1,112 +0,0 @@ -#include "Runtime/Graphics/Shaders/CParticleSwooshShaders.hpp" - -#include - -#include "Runtime/Particle/CParticleSwoosh.hpp" -#include "Runtime/Particle/CSwooshDescription.hpp" - -//#include - -namespace metaforce { - -//std::array, 2> CParticleSwooshShaders::m_texZWrite; -//std::array, 2> CParticleSwooshShaders::m_texNoZWrite; -//std::array, 2> CParticleSwooshShaders::m_texAdditiveZWrite; -//std::array, 2> CParticleSwooshShaders::m_texAdditiveNoZWrite; -// -//std::array, 2> CParticleSwooshShaders::m_noTexZWrite; -//std::array, 2> CParticleSwooshShaders::m_noTexNoZWrite; -//std::array, 2> CParticleSwooshShaders::m_noTexAdditiveZWrite; -//std::array, 2> CParticleSwooshShaders::m_noTexAdditiveNoZWrite; - -void CParticleSwooshShaders::Initialize() { -// m_texZWrite = {hecl::conv->convert(Shader_CParticleSwooshShaderTexZWrite{}), -// hecl::conv->convert(Shader_CParticleSwooshShaderTexZWriteAWrite{})}; -// m_texNoZWrite = {hecl::conv->convert(Shader_CParticleSwooshShaderTexNoZWrite{}), -// hecl::conv->convert(Shader_CParticleSwooshShaderTexNoZWriteAWrite{})}; -// m_texAdditiveZWrite = {hecl::conv->convert(Shader_CParticleSwooshShaderTexAdditiveZWrite{}), -// hecl::conv->convert(Shader_CParticleSwooshShaderTexAdditiveZWriteAWrite{})}; -// m_texAdditiveNoZWrite = {hecl::conv->convert(Shader_CParticleSwooshShaderTexAdditiveNoZWrite{}), -// hecl::conv->convert(Shader_CParticleSwooshShaderTexAdditiveNoZWriteAWrite{})}; -// m_noTexZWrite = {hecl::conv->convert(Shader_CParticleSwooshShaderNoTexZWrite{}), -// hecl::conv->convert(Shader_CParticleSwooshShaderNoTexZWriteAWrite{})}; -// m_noTexNoZWrite = {hecl::conv->convert(Shader_CParticleSwooshShaderNoTexNoZWrite{}), -// hecl::conv->convert(Shader_CParticleSwooshShaderNoTexNoZWriteAWrite{})}; -// m_noTexAdditiveZWrite = {hecl::conv->convert(Shader_CParticleSwooshShaderNoTexAdditiveZWrite{}), -// hecl::conv->convert(Shader_CParticleSwooshShaderNoTexAdditiveZWriteAWrite{})}; -// m_noTexAdditiveNoZWrite = {hecl::conv->convert(Shader_CParticleSwooshShaderNoTexAdditiveNoZWrite{}), -// hecl::conv->convert(Shader_CParticleSwooshShaderNoTexAdditiveNoZWriteAWrite{})}; -} - -void CParticleSwooshShaders::Shutdown() { -// for (auto& s : m_texZWrite) -// s.reset(); -// for (auto& s : m_texNoZWrite) -// s.reset(); -// for (auto& s : m_texAdditiveZWrite) -// s.reset(); -// for (auto& s : m_texAdditiveNoZWrite) -// s.reset(); -// for (auto& s : m_noTexZWrite) -// s.reset(); -// for (auto& s : m_noTexNoZWrite) -// s.reset(); -// for (auto& s : m_noTexAdditiveZWrite) -// s.reset(); -// for (auto& s : m_noTexAdditiveNoZWrite) -// s.reset(); -} - -CParticleSwooshShaders::EShaderClass CParticleSwooshShaders::GetShaderClass(CParticleSwoosh& gen) { - CSwooshDescription* desc = gen.GetDesc(); - - if (desc->x3c_TEXR) - return EShaderClass::Tex; - else - return EShaderClass::NoTex; -} - -void CParticleSwooshShaders::BuildShaderDataBinding(CParticleSwoosh& gen) { - CSwooshDescription* desc = gen.GetDesc(); -// std::array, 2>* pipeline = nullptr; -// -// if (desc->x3c_TEXR) { -// if (desc->x44_31_AALP) { -// if (desc->x45_24_ZBUF) -// pipeline = &m_texAdditiveZWrite; -// else -// pipeline = &m_texAdditiveNoZWrite; -// } else { -// if (desc->x45_24_ZBUF) -// pipeline = &m_texZWrite; -// else -// pipeline = &m_texNoZWrite; -// } -// } else { -// if (desc->x44_31_AALP) { -// if (desc->x45_24_ZBUF) -// pipeline = &m_noTexAdditiveZWrite; -// else -// pipeline = &m_noTexAdditiveNoZWrite; -// } else { -// if (desc->x45_24_ZBUF) -// pipeline = &m_noTexZWrite; -// else -// pipeline = &m_noTexNoZWrite; -// } -// } -// -// const CUVElement* const texr = desc->x3c_TEXR.get(); -// const std::array, 1> textures{ -// texr ? texr->GetValueTexture(0).GetObj()->GetBooTexture() : nullptr, -// }; -// -// const std::array, 1> uniforms{gen.m_uniformBuf.get()}; -// for (size_t i = 0; i < gen.m_dataBind.size(); ++i) { -// gen.m_dataBind[i] = -// ctx.newShaderDataBinding((*pipeline)[i], gen.m_vertBuf.get(), nullptr, nullptr, uniforms.size(), -// uniforms.data(), nullptr, texr ? 1 : 0, textures.data(), nullptr, nullptr); -// } -} - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CParticleSwooshShaders.hpp b/Runtime/Graphics/Shaders/CParticleSwooshShaders.hpp deleted file mode 100644 index 5b4211a12..000000000 --- a/Runtime/Graphics/Shaders/CParticleSwooshShaders.hpp +++ /dev/null @@ -1,42 +0,0 @@ -#pragma once - -#include - -//#include - -#include -#include -#include - -namespace metaforce { -class CParticleSwoosh; - -class CParticleSwooshShaders { -public: - enum class EShaderClass { Tex, NoTex }; - - struct Vert { - zeus::CVector3f m_pos; - zeus::CVector2f m_uv; - zeus::CColor m_color; - }; - -private: -// static std::array, 2> m_texZWrite; -// static std::array, 2> m_texNoZWrite; -// static std::array, 2> m_texAdditiveZWrite; -// static std::array, 2> m_texAdditiveNoZWrite; -// -// static std::array, 2> m_noTexZWrite; -// static std::array, 2> m_noTexNoZWrite; -// static std::array, 2> m_noTexAdditiveZWrite; -// static std::array, 2> m_noTexAdditiveNoZWrite; - -public: - static void Initialize(); - static void Shutdown(); - static EShaderClass GetShaderClass(CParticleSwoosh& gen); - static void BuildShaderDataBinding(CParticleSwoosh& gen); -}; - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CPhazonSuitFilter.cpp b/Runtime/Graphics/Shaders/CPhazonSuitFilter.cpp deleted file mode 100644 index fdabdcb07..000000000 --- a/Runtime/Graphics/Shaders/CPhazonSuitFilter.cpp +++ /dev/null @@ -1,154 +0,0 @@ -#include "Runtime/Graphics/Shaders/CPhazonSuitFilter.hpp" - -#include - -#include "Runtime/Graphics/CCubeRenderer.hpp" -#include "Runtime/Graphics/CGraphics.hpp" -#include "Runtime/Graphics/CTexture.hpp" - -//#include - -#include -#include -#include -#include - -namespace metaforce { - -// 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(); -} - -void CPhazonSuitFilter::drawBlurPasses(float radius, const CTexture* indTex) { - SCOPED_GRAPHICS_DEBUG_GROUP("CPhazonSuitFilter::drawBlurPasses", zeus::skMagenta); - // if (!m_dataBind || indTex != m_indTex) { - // m_indTex = indTex; - // CGraphics::CommitResources([this](boo::IGraphicsDataFactory::Context& ctx) { - // m_uniBufBlurX = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(zeus::CVector4f), 1); - // m_uniBufBlurY = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(zeus::CVector4f), 1); - // m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(zeus::CVector4f) * 2, 1); - // - // struct BlurVert { - // zeus::CVector3f pos; - // zeus::CVector2f uv; - // }; - // const std::array blurVerts{{ - // {{-1.f, 1.f, 0.f}, {0.f, 1.f}}, - // {{-1.f, -1.f, 0.f}, {0.f, 0.f}}, - // {{1.f, 1.f, 0.f}, {1.f, 1.f}}, - // {{1.f, -1.f, 0.f}, {1.f, 0.f}}, - // }}; - // m_blurVbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, blurVerts.data(), sizeof(BlurVert), blurVerts.size()); - // - // struct Vert { - // zeus::CVector3f pos; - // zeus::CVector2f screenUv; - // zeus::CVector2f indUv; - // zeus::CVector2f maskUv; - // }; - // const std::array verts{{ - // {{-1.f, 1.f, 0.f}, {0.01f, 0.99f}, {0.f, 4.f}, {0.f, 1.f}}, - // {{-1.f, -1.f, 0.f}, {0.01f, 0.01f}, {0.f, 0.f}, {0.f, 0.f}}, - // {{1.f, 1.f, 0.f}, {0.99f, 0.99f}, {g_Viewport.aspect * 4.f, 4.f}, {1.f, 1.f}}, - // {{1.f, -1.f, 0.f}, {0.99f, 0.01f}, {g_Viewport.aspect * 4.f, 0.f}, {1.f, 0.f}}, - // }}; - // m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), sizeof(Vert), verts.size()); - // - // std::array, 1> bufs{m_uniBufBlurX.get()}; - // constexpr std::array stages{boo::PipelineStage::Vertex}; - // std::array, 4> texs; - // std::array texBindIdxs; - // - // texs[0] = CGraphics::g_SpareTexture.get(); - // texBindIdxs[0] = 1; - // m_dataBindBlurX = - // ctx.newShaderDataBinding(s_BlurPipeline, m_blurVbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), - // stages.data(), nullptr, nullptr, 1, texs.data(), texBindIdxs.data(), 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, bufs.size(), bufs.data(), - // stages.data(), nullptr, nullptr, 1, texs.data(), texBindIdxs.data(), 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, - // bufs.size(), bufs.data(), stages.data(), nullptr, nullptr, texCount, - // texs.data(), texBindIdxs.data(), nullptr); - // return true; - // } BooTrace); - // } - - SClipScreenRect rect; - rect.x4_left = CGraphics::GetViewportLeft(); - rect.x8_top = CGraphics::GetViewportTop(); - rect.xc_width = CGraphics::GetViewportWidth(); - rect.x10_height = CGraphics::GetViewportTop(); - - constexpr float blurScale = 1.0f / 128.0f; - - /* X Pass */ - auto blurDir = zeus::CVector4f{ - CGraphics::GetViewportHeight() / float(CGraphics::GetViewportWidth()) * radius * blurScale, 0.f, 0.f, 0.f}; - // m_uniBufBlurX->load(&blurDir, sizeof(zeus::CVector4f)); - - // CGraphics::SetShaderDataBinding(m_dataBindBlurX); - // CGraphics::DrawArray(0, 4); -// CGraphics::ResolveSpareTexture(rect, 2); - - /* Y Pass */ - blurDir = zeus::CVector4f{0.f, radius * blurScale, 0.f, 0.f}; - // m_uniBufBlurY->load(&blurDir, sizeof(zeus::CVector4f)); - - // CGraphics::SetShaderDataBinding(m_dataBindBlurY); - // CGraphics::DrawArray(0, 4); -// CGraphics::ResolveSpareTexture(rect, 2); -} - -void CPhazonSuitFilter::draw(const zeus::CColor& color, float indScale, float indOffX, float indOffY) { - SCOPED_GRAPHICS_DEBUG_GROUP("CPhazonSuitFilter::draw", zeus::skMagenta); - struct Uniform { - zeus::CColor color; - zeus::CVector4f indScaleOff; - } uniform = {color, zeus::CVector4f(indScale, indScale, indOffX, indOffY)}; - - // m_uniBuf->load(&uniform, sizeof(Uniform)); - // CGraphics::SetShaderDataBinding(m_dataBind); - // CGraphics::DrawArray(0, 4); -} - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CPhazonSuitFilter.hpp b/Runtime/Graphics/Shaders/CPhazonSuitFilter.hpp deleted file mode 100644 index c3e39a3d1..000000000 --- a/Runtime/Graphics/Shaders/CPhazonSuitFilter.hpp +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once - -//#include - -namespace zeus { -class CColor; -} // namespace zeus - -namespace metaforce { -class CTexture; - -class CPhazonSuitFilter { -// boo::ObjToken m_uniBufBlurX; -// boo::ObjToken m_uniBufBlurY; -// boo::ObjToken m_uniBuf; -// boo::ObjToken m_blurVbo; -// boo::ObjToken m_vbo; - const CTexture* m_indTex = nullptr; -// boo::ObjToken m_dataBindBlurX; -// boo::ObjToken m_dataBindBlurY; -// 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); -}; - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CRadarPaintShader.cpp b/Runtime/Graphics/Shaders/CRadarPaintShader.cpp deleted file mode 100644 index 26dc50508..000000000 --- a/Runtime/Graphics/Shaders/CRadarPaintShader.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include "Runtime/Graphics/Shaders/CRadarPaintShader.hpp" - -#include - -#include "Runtime/Graphics/CGraphics.hpp" -#include "Runtime/Graphics/CTexture.hpp" - -//#include - -namespace metaforce { - -//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()) - return; - SCOPED_GRAPHICS_DEBUG_GROUP("CRadarPaintShader::draw", zeus::skMagenta); - - if (instances.size() > m_maxInsts) { - m_maxInsts = instances.size(); - m_tex = tex; -// CGraphics::CommitResources([this](boo::IGraphicsDataFactory::Context& ctx) { -// m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(Instance), m_maxInsts); -// m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(zeus::CMatrix4f), 1); -// -// const std::array, 1> bufs{m_uniBuf.get()}; -// constexpr std::array stages{boo::PipelineStage::Vertex}; -// const std::array, 1> texs{m_tex->GetBooTexture()}; -// -// m_dataBind = -// ctx.newShaderDataBinding(s_Pipeline, nullptr, m_vbo.get(), nullptr, bufs.size(), bufs.data(), stages.data(), -// nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr); -// return true; -// } BooTrace); - } - - zeus::CMatrix4f uniMtx = CGraphics::GetPerspectiveProjectionMatrix(/*true*/) * CGraphics::g_GXModelView.toMatrix4f(); -// m_uniBuf->load(&uniMtx, sizeof(zeus::CMatrix4f)); - - size_t mapSz = sizeof(Instance) * instances.size(); -// Instance* insts = reinterpret_cast(m_vbo->map(mapSz)); -// memmove(insts, instances.data(), mapSz); -// m_vbo->unmap(); - -// CGraphics::SetShaderDataBinding(m_dataBind); -// CGraphics::DrawInstances(0, 4, instances.size()); -} - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CRadarPaintShader.hpp b/Runtime/Graphics/Shaders/CRadarPaintShader.hpp deleted file mode 100644 index eb8acbbef..000000000 --- a/Runtime/Graphics/Shaders/CRadarPaintShader.hpp +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once - -#include -#include - -//#include - -#include -#include -#include - -namespace metaforce { -class CTexture; - -class CRadarPaintShader { -public: - struct Instance { - std::array pos; - std::array uv; - zeus::CColor color; - }; - -private: -// boo::ObjToken m_vbo; -// boo::ObjToken m_uniBuf; -// boo::ObjToken m_dataBind; - const CTexture* m_tex = nullptr; - size_t m_maxInsts = 0; - -public: - static void Initialize(); - static void Shutdown(); - void draw(const std::vector& instances, const CTexture* tex); -}; - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CRandomStaticFilter.cpp b/Runtime/Graphics/Shaders/CRandomStaticFilter.cpp deleted file mode 100644 index 1751d3376..000000000 --- a/Runtime/Graphics/Shaders/CRandomStaticFilter.cpp +++ /dev/null @@ -1,83 +0,0 @@ -#include "Runtime/Graphics/Shaders/CRandomStaticFilter.hpp" - -#include - -#include "Runtime/GameGlobalObjects.hpp" -#include "Runtime/Camera/CCameraFilter.hpp" -#include "Runtime/Graphics/CCubeRenderer.hpp" - -//#include - -namespace metaforce { - -//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) { -// CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { -// struct Vert { -// zeus::CVector2f m_pos; -// zeus::CVector2f m_uv; -// }; -// const std::array verts{{ -// {{-1.f, -1.f}, {0.f, 0.f}}, -// {{-1.f, 1.f}, {0.f, 448.f}}, -// {{1.f, -1.f}, {640.f, 0.f}}, -// {{1.f, 1.f}, {640.f, 448.f}}, -// }}; -// m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), sizeof(Vert), verts.size()); -// m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); -// -// const std::array, 1> bufs{m_uniBuf.get()}; -// constexpr std::array stages{boo::PipelineStage::Vertex}; -// const std::array, 1> texs{g_Renderer->GetRandomStaticEntropyTex()}; -// m_dataBind = ctx.newShaderDataBinding(m_cookieCutter ? s_CookieCutterPipeline : SelectPipeline(type), m_vbo.get(), -// nullptr, nullptr, bufs.size(), bufs.data(), stages.data(), nullptr, nullptr, -// texs.size(), texs.data(), nullptr, nullptr); -// return true; -// } BooTrace); -} - -void CRandomStaticFilter::draw(const zeus::CColor& color, float t) { - SCOPED_GRAPHICS_DEBUG_GROUP("CRandomStaticFilter::draw", zeus::skMagenta); - - m_uniform.color = color; - m_uniform.randOff = ROUND_UP_32(int64_t(rand()) * 32767 / RAND_MAX); - m_uniform.discardThres = 1.f - t; - -// m_uniBuf->load(&m_uniform, sizeof(Uniform)); -// -// CGraphics::SetShaderDataBinding(m_dataBind); -// CGraphics::DrawArray(0, 4); -} - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CRandomStaticFilter.hpp b/Runtime/Graphics/Shaders/CRandomStaticFilter.hpp deleted file mode 100644 index 64a78a131..000000000 --- a/Runtime/Graphics/Shaders/CRandomStaticFilter.hpp +++ /dev/null @@ -1,42 +0,0 @@ -#pragma once - -#include "Runtime/CToken.hpp" - -//#include -#include - -namespace metaforce { -class CTexture; - -enum class EFilterShape; -enum class EFilterType; - -class CRandomStaticFilter { - struct Uniform { - zeus::CColor color; - float randOff; - float discardThres; - }; -// boo::ObjToken m_vbo; -// boo::ObjToken m_uniBuf; -// boo::ObjToken m_dataBind; - Uniform m_uniform; - bool m_cookieCutter; - -public: - static void Initialize(); - static void Shutdown(); - explicit CRandomStaticFilter(EFilterType type, bool cookieCutter = false); - explicit 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); } -}; - -class CCookieCutterDepthRandomStaticFilter : public CRandomStaticFilter { -public: - explicit CCookieCutterDepthRandomStaticFilter(EFilterType type) : CRandomStaticFilter(type, true) {} - explicit CCookieCutterDepthRandomStaticFilter(EFilterType type, const TLockedToken&) - : CCookieCutterDepthRandomStaticFilter(type) {} -}; - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CScanLinesFilter.cpp b/Runtime/Graphics/Shaders/CScanLinesFilter.cpp deleted file mode 100644 index 2fb9f8a56..000000000 --- a/Runtime/Graphics/Shaders/CScanLinesFilter.cpp +++ /dev/null @@ -1,67 +0,0 @@ -#include "Runtime/Graphics/Shaders/CScanLinesFilter.hpp" - -#include - -#include "Runtime/GameGlobalObjects.hpp" -#include "Runtime/Camera/CCameraFilter.hpp" -#include "Runtime/Graphics/CCubeRenderer.hpp" -#include "Runtime/Graphics/CGraphics.hpp" - -//#include - -namespace metaforce { - -//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); -// boo::ObjToken vbo = -// m_even ? g_Renderer->GetScanLinesEvenVBO().get() : g_Renderer->GetScanLinesOddVBO().get(); -// const std::array, 1> bufs{m_uniBuf.get()}; -// constexpr std::array stages{boo::PipelineStage::Vertex}; -// -// m_dataBind = ctx.newShaderDataBinding(SelectPipeline(type), vbo, nullptr, nullptr, bufs.size(), bufs.data(), -// stages.data(), nullptr, nullptr, 0, nullptr, nullptr, nullptr); -// return true; -// } BooTrace); -} - -void CScanLinesFilter::draw(const zeus::CColor& color) { - SCOPED_GRAPHICS_DEBUG_GROUP("CScanLinesFilter::draw", zeus::skMagenta); - - m_uniform.color = color; -// m_uniBuf->load(&m_uniform, sizeof(Uniform)); -// -// CGraphics::SetShaderDataBinding(m_dataBind); -// CGraphics::DrawArray(0, 670); -} - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CScanLinesFilter.hpp b/Runtime/Graphics/Shaders/CScanLinesFilter.hpp deleted file mode 100644 index 3b2b28f28..000000000 --- a/Runtime/Graphics/Shaders/CScanLinesFilter.hpp +++ /dev/null @@ -1,43 +0,0 @@ -#pragma once - -#include "Runtime/CToken.hpp" - -//#include -#include - -namespace metaforce { -class CTexture; - -enum class EFilterShape; -enum class EFilterType; - -class CScanLinesFilter { - struct Uniform { - zeus::CColor color; - }; -// boo::ObjToken m_uniBuf; -// boo::ObjToken m_dataBind; - Uniform m_uniform; - bool m_even; - -public: - static void Initialize(); - static void Shutdown(); - explicit CScanLinesFilter(EFilterType type, bool even); - void draw(const zeus::CColor& color); - void DrawFilter(EFilterShape, const zeus::CColor& color, float) { draw(color); } -}; - -class CScanLinesFilterEven : public CScanLinesFilter { -public: - explicit CScanLinesFilterEven(EFilterType type) : CScanLinesFilter(type, true) {} - explicit CScanLinesFilterEven(EFilterType type, const TLockedToken&) : CScanLinesFilterEven(type) {} -}; - -class CScanLinesFilterOdd : public CScanLinesFilter { -public: - explicit CScanLinesFilterOdd(EFilterType type) : CScanLinesFilter(type, false) {} - explicit CScanLinesFilterOdd(EFilterType type, const TLockedToken&) : CScanLinesFilterOdd(type) {} -}; - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CSpaceWarpFilter.cpp b/Runtime/Graphics/Shaders/CSpaceWarpFilter.cpp deleted file mode 100644 index 0a8dcee46..000000000 --- a/Runtime/Graphics/Shaders/CSpaceWarpFilter.cpp +++ /dev/null @@ -1,171 +0,0 @@ -#include "Runtime/Graphics/Shaders/CSpaceWarpFilter.hpp" - -#include "Runtime/Graphics/CCubeRenderer.hpp" -#include "Runtime/Graphics/CGraphics.hpp" - -//#include - -#define WARP_RAMP_RES 32 - -namespace metaforce { - -// static boo::ObjToken s_Pipeline; - -void CSpaceWarpFilter::Initialize() { - // s_Pipeline = hecl::conv->convert(Shader_CSpaceWarpFilter{}); -} - -void CSpaceWarpFilter::Shutdown() { - // s_Pipeline.reset(); -} - -void CSpaceWarpFilter::GenerateWarpRampTex() { - std::array, WARP_RAMP_RES + 1>, WARP_RAMP_RES + 1> data{}; - const float halfRes = WARP_RAMP_RES / 2.f; - for (int y = 0; y < WARP_RAMP_RES + 1; ++y) { - for (int x = 0; x < WARP_RAMP_RES + 1; ++x) { - zeus::CVector2f vec((x - halfRes) / halfRes, (y - halfRes) / halfRes); - const float mag = vec.magnitude(); - if (mag < 1.f && vec.canBeNormalized()) { - vec.normalize(); - vec *= zeus::CVector2f(std::sqrt(mag)); - } - data[y][x][3] = zeus::clamp(0, int((((vec.x() / 2.f + 0.5f) - x / float(WARP_RAMP_RES)) + 0.5f) * 255), 255); - data[y][x][2] = zeus::clamp(0, int((((vec.y() / 2.f + 0.5f) - y / float(WARP_RAMP_RES)) + 0.5f) * 255), 255); - data[y][x][0] = data[y][x][1] = data[y][x][2]; - } - } - m_warpTex.emplace(ETexelFormat::RGBA8PC, WARP_RAMP_RES + 1, WARP_RAMP_RES + 1, 1, "Warp Ramp"); -} - -CSpaceWarpFilter::CSpaceWarpFilter() { - // CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { - // GenerateWarpRampTex(ctx); - // - // struct Vert { - // zeus::CVector2f m_pos; - // zeus::CVector2f m_uv; - // }; - // const std::array verts{{ - // {{-1.f, -1.f}, {0.f, 0.f}}, - // {{-1.f, 1.f}, {0.f, 1.f}}, - // {{1.f, -1.f}, {1.f, 0.f}}, - // {{1.f, 1.f}, {1.f, 1.f}}, - // }}; - // - // m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), 32, verts.size()); - // m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); - // - // const std::array, 1> bufs{m_uniBuf.get()}; - // constexpr std::array stages{boo::PipelineStage::Vertex}; - // const std::array, 2> texs{ - // CGraphics::g_SpareTexture.get(), - // m_warpTex.get(), - // }; - // m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), - // stages.data(), nullptr, nullptr, texs.size(), texs.data(), nullptr, - // nullptr); - // return true; - // } BooTrace); -} - -void CSpaceWarpFilter::draw(const zeus::CVector3f& pt) { - SCOPED_GRAPHICS_DEBUG_GROUP("CSpaceWarpFilter::draw", zeus::skMagenta); - - /* Indirect coords are full-texture sampling when warp is completely in viewport */ - m_uniform.m_indXf[1][1] = 1.f; - m_uniform.m_indXf[0][0] = 1.f; - m_uniform.m_indXf[2][0] = 0.f; - m_uniform.m_indXf[2][1] = 0.f; - - /* Warp effect is fixed at 192x192 rectangle in original (1/2.5 viewport height) */ - float aspect = CGraphics::g_CroppedViewport.xc_width / float(CGraphics::g_CroppedViewport.x10_height); - m_uniform.m_matrix[1][1] = 1.f / 2.5f; - m_uniform.m_matrix[0][0] = m_uniform.m_matrix[1][1] / aspect; - - SClipScreenRect clipRect = {}; - clipRect.x4_left = ((pt[0] - m_uniform.m_matrix[0][0]) / 2.f + 0.5f) * CGraphics::g_CroppedViewport.xc_width; - if (clipRect.x4_left >= CGraphics::g_CroppedViewport.xc_width) - return; - clipRect.x8_top = ((pt[1] - m_uniform.m_matrix[1][1]) / 2.f + 0.5f) * CGraphics::g_CroppedViewport.x10_height; - if (clipRect.x8_top >= CGraphics::g_CroppedViewport.x10_height) - return; - clipRect.xc_width = CGraphics::g_CroppedViewport.xc_width * m_uniform.m_matrix[0][0]; - if (clipRect.x4_left + clipRect.xc_width <= 0) - return; - clipRect.x10_height = CGraphics::g_CroppedViewport.x10_height * m_uniform.m_matrix[1][1]; - if (clipRect.x8_top + clipRect.x10_height <= 0) - return; - - float oldW = clipRect.xc_width; - if (clipRect.x4_left < 0) { - clipRect.xc_width += clipRect.x4_left; - m_uniform.m_indXf[0][0] = clipRect.xc_width / oldW; - m_uniform.m_indXf[2][0] = -clipRect.x4_left / oldW; - clipRect.x4_left = 0; - } - - float oldH = clipRect.x10_height; - if (clipRect.x8_top < 0) { - clipRect.x10_height += clipRect.x8_top; - m_uniform.m_indXf[1][1] = clipRect.x10_height / oldH; - m_uniform.m_indXf[2][1] = -clipRect.x8_top / oldH; - clipRect.x8_top = 0; - } - - float tmp = clipRect.x4_left + clipRect.xc_width; - if (tmp >= CGraphics::g_CroppedViewport.xc_width) { - clipRect.xc_width = CGraphics::g_CroppedViewport.xc_width - clipRect.x4_left; - m_uniform.m_indXf[0][0] = clipRect.xc_width / oldW; - } - - tmp = clipRect.x8_top + clipRect.x10_height; - if (tmp >= CGraphics::g_CroppedViewport.x10_height) { - clipRect.x10_height = CGraphics::g_CroppedViewport.x10_height - clipRect.x8_top; - m_uniform.m_indXf[1][1] = clipRect.x10_height / oldH; - } - - /* Transform UV coordinates of rectangle within viewport and sampled scene texels (clamped to viewport bounds) */ - zeus::CVector2f vp{float(CGraphics::g_CroppedViewport.xc_width), float(CGraphics::g_CroppedViewport.x10_height)}; - m_uniform.m_matrix[0][0] = clipRect.xc_width / vp.x(); - m_uniform.m_matrix[1][1] = clipRect.x10_height / vp.y(); - m_uniform.m_matrix[3][0] = pt.x() + (1.f / vp.x()); - m_uniform.m_matrix[3][1] = pt.y() + (1.f / vp.y()); - // if (CGraphics::g_BooPlatform == boo::IGraphicsDataFactory::Platform::OpenGL) { - // m_uniform.m_matrix[3][2] = pt.z() * 2.f - 1.f; - // } else if (CGraphics::g_BooPlatform == boo::IGraphicsDataFactory::Platform::Vulkan) { - // m_uniform.m_matrix[1][1] *= -1.f; - // m_uniform.m_matrix[3][1] *= -1.f; - // m_uniform.m_matrix[3][2] = pt.z(); - // } else { - // m_uniform.m_matrix[3][2] = pt.z(); - // } - - if (clipRect.x4_left) { - clipRect.x4_left -= 1; - clipRect.xc_width += 1; - } - if (clipRect.x8_top) { - clipRect.x8_top -= 1; - clipRect.x10_height += 1; - } - if (clipRect.x4_left + clipRect.xc_width < CGraphics::g_CroppedViewport.xc_width) - clipRect.xc_width += 1; - if (clipRect.x8_top + clipRect.x10_height < CGraphics::g_CroppedViewport.x10_height) - clipRect.x10_height += 1; - - clipRect.x4_left += CGraphics::g_CroppedViewport.x4_left; - clipRect.x8_top += CGraphics::g_CroppedViewport.x8_top; - clipRect.x8_top = CGraphics::GetViewportHeight() - clipRect.x10_height - clipRect.x8_top; - // CGraphics::ResolveSpareTexture(clipRect); - - m_uniform.m_strength.x() = - m_uniform.m_matrix[0][0] * m_strength * 0.5f * (clipRect.x10_height / float(clipRect.xc_width)); - m_uniform.m_strength.y() = m_uniform.m_matrix[1][1] * m_strength * 0.5f; - // m_uniBuf->load(&m_uniform, sizeof(m_uniform)); - - // CGraphics::SetShaderDataBinding(m_dataBind); - // CGraphics::DrawArray(0, 4); -} - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CSpaceWarpFilter.hpp b/Runtime/Graphics/Shaders/CSpaceWarpFilter.hpp deleted file mode 100644 index a7c18a2b6..000000000 --- a/Runtime/Graphics/Shaders/CSpaceWarpFilter.hpp +++ /dev/null @@ -1,38 +0,0 @@ -#pragma once - -#include - -#include "Runtime/GCNTypes.hpp" -#include "Runtime/Graphics/CGraphics.hpp" -#include "Runtime/Graphics/CTexture.hpp" - -#include -#include - -namespace metaforce { - -class CSpaceWarpFilter { - struct Uniform { - zeus::CMatrix4f m_matrix; - zeus::CMatrix4f m_indXf; - zeus::CVector3f m_strength; - }; - std::array, 8>, 4> m_shiftTexture{}; - std::optional m_warpTex; -// boo::ObjToken m_vbo; -// boo::ObjToken m_uniBuf; -// boo::ObjToken m_dataBind; - Uniform m_uniform; - float m_strength = 1.f; - - void GenerateWarpRampTex(); - -public: - static void Initialize(); - static void Shutdown(); - CSpaceWarpFilter(); - void setStrength(float strength) { m_strength = strength; } - void draw(const zeus::CVector3f& pt); -}; - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CTextSupportShader.cpp b/Runtime/Graphics/Shaders/CTextSupportShader.cpp deleted file mode 100644 index a00604956..000000000 --- a/Runtime/Graphics/Shaders/CTextSupportShader.cpp +++ /dev/null @@ -1,81 +0,0 @@ -#include "Runtime/Graphics/Shaders/CTextSupportShader.hpp" - -#include "Runtime/GuiSys/CFontImageDef.hpp" -#include "Runtime/GuiSys/CRasterFont.hpp" - -//#include - -namespace metaforce { - -//boo::ObjToken CTextSupportShader::s_TextAlphaPipeline; -//boo::ObjToken CTextSupportShader::s_TextAddPipeline; -//boo::ObjToken CTextSupportShader::s_TextAddOverdrawPipeline; -// -//boo::ObjToken CTextSupportShader::s_ImageAlphaPipeline; -//boo::ObjToken CTextSupportShader::s_ImageAddPipeline; -//boo::ObjToken CTextSupportShader::s_ImageAddOverdrawPipeline; -// -//hecl::VertexBufferPool CTextSupportShader::s_CharInsts; -//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) { - float layer = glyph.GetLayer(); - - m_pos[0].assign(offset.x, 0.f, offset.y); - m_uv[0].assign(glyph.GetStartU(), 1.f - glyph.GetStartV(), layer); - - m_pos[1].assign(offset.x + glyph.GetCellWidth(), 0.f, offset.y); - m_uv[1].assign(glyph.GetEndU(), 1.f - glyph.GetStartV(), layer); - - m_pos[2].assign(offset.x, 0.f, offset.y + glyph.GetCellHeight()); - m_uv[2].assign(glyph.GetStartU(), 1.f - glyph.GetEndV(), layer); - - m_pos[3].assign(offset.x + glyph.GetCellWidth(), 0.f, offset.y + glyph.GetCellHeight()); - m_uv[3].assign(glyph.GetEndU(), 1.f - glyph.GetEndV(), layer); -} - -void CTextSupportShader::ImageInstance::SetMetrics(const CFontImageDef& imgDef, const zeus::CVector2i& offset) { - zeus::CVector2f imgSize; - if (imgDef.x4_texs.size()) { - const CTexture& tex = *imgDef.x4_texs[0].GetObj(); - imgSize.assign(tex.GetWidth() * imgDef.x14_cropFactor.x(), tex.GetHeight() * imgDef.x14_cropFactor.y()); - } - zeus::CVector2f cropPad = imgDef.x14_cropFactor * 0.5f; - - m_pos[0].assign(offset.x, 0.f, offset.y); - m_uv[0].assign(0.5f - cropPad.x(), 0.5f + cropPad.y()); - - m_pos[1].assign(offset.x + imgSize.x(), 0.f, offset.y); - m_uv[1].assign(0.5f + cropPad.x(), 0.5f + cropPad.y()); - - m_pos[2].assign(offset.x, 0.f, offset.y + imgSize.y()); - m_uv[2].assign(0.5f - cropPad.x(), 0.5f - cropPad.y()); - - m_pos[3].assign(offset.x + imgSize.x(), 0.f, offset.y + imgSize.y()); - m_uv[3].assign(0.5f + cropPad.x(), 0.5f - cropPad.y()); -} - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CTextSupportShader.hpp b/Runtime/Graphics/Shaders/CTextSupportShader.hpp deleted file mode 100644 index 580b29d73..000000000 --- a/Runtime/Graphics/Shaders/CTextSupportShader.hpp +++ /dev/null @@ -1,100 +0,0 @@ -#pragma once - -#include - -#include "Runtime/GuiSys/CGuiWidget.hpp" - -//#include -//#include - -#include -#include -#include -#include -#include - -namespace metaforce { -class CGlyph; -class CFontImageDef; -class CTextRenderBuffer; - -class CTextSupportShader { - friend class CTextRenderBuffer; - -// static boo::ObjToken s_TextAlphaPipeline; -// static boo::ObjToken s_TextAddPipeline; -// static boo::ObjToken s_TextAddOverdrawPipeline; -// -// static boo::ObjToken s_ImageAlphaPipeline; -// static boo::ObjToken s_ImageAddPipeline; -// static boo::ObjToken s_ImageAddOverdrawPipeline; - - struct Uniform { - zeus::CMatrix4f m_mvp; - zeus::CColor m_uniformColor; - }; - - struct CharacterInstance { - std::array m_pos; - std::array m_uv; - zeus::CColor m_fontColor; - zeus::CColor m_outlineColor; - zeus::CColor m_mulColor; - void SetMetrics(const CGlyph& glyph, const zeus::CVector2i& offset); - }; - - struct ImageInstance { - std::array m_pos; - std::array m_uv; - zeus::CColor m_color; - void SetMetrics(const CFontImageDef& imgDef, const zeus::CVector2i& offset); - }; - -// static hecl::VertexBufferPool s_CharInsts; -// static hecl::VertexBufferPool s_ImgInsts; -// static hecl::UniformBufferPool s_Uniforms; - -public: -// static boo::ObjToken SelectTextPipeline(CGuiWidget::EGuiModelDrawFlags df) { -// switch (df) { -// case CGuiWidget::EGuiModelDrawFlags::Shadeless: -// case CGuiWidget::EGuiModelDrawFlags::Opaque: -// case CGuiWidget::EGuiModelDrawFlags::Alpha: -// case CGuiWidget::EGuiModelDrawFlags::AlphaAdditiveOverdraw: -// return s_TextAlphaPipeline; -// case CGuiWidget::EGuiModelDrawFlags::Additive: -// return s_TextAddPipeline; -// default: -// return {}; -// } -// } -// -// static boo::ObjToken SelectImagePipeline(CGuiWidget::EGuiModelDrawFlags df) { -// switch (df) { -// case CGuiWidget::EGuiModelDrawFlags::Shadeless: -// case CGuiWidget::EGuiModelDrawFlags::Opaque: -// case CGuiWidget::EGuiModelDrawFlags::Alpha: -// case CGuiWidget::EGuiModelDrawFlags::AlphaAdditiveOverdraw: -// return s_ImageAlphaPipeline; -// case CGuiWidget::EGuiModelDrawFlags::Additive: -// return s_ImageAddPipeline; -// default: -// return {}; -// } -// } -// -// static boo::ObjToken GetTextAdditiveOverdrawPipeline() { return s_TextAddOverdrawPipeline; } -// -// static boo::ObjToken GetImageAdditiveOverdrawPipeline() { return s_ImageAddOverdrawPipeline; } - - static void UpdateBuffers() { -// s_CharInsts.updateBuffers(); -// s_ImgInsts.updateBuffers(); -// s_Uniforms.updateBuffers(); - } - - static void Initialize(); - static void Shutdown(); -}; - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CTexturedQuadFilter.cpp b/Runtime/Graphics/Shaders/CTexturedQuadFilter.cpp deleted file mode 100644 index f8c26e728..000000000 --- a/Runtime/Graphics/Shaders/CTexturedQuadFilter.cpp +++ /dev/null @@ -1,346 +0,0 @@ -#include "Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp" - -#include - -#include "Runtime/Camera/CCameraFilter.hpp" -#include "Runtime/Graphics/CTexture.hpp" - -//#include - -namespace metaforce { - -//static boo::ObjToken s_AlphaPipeline; -//static boo::ObjToken s_AlphaGEqualPipeline; -//static boo::ObjToken s_AlphaGEqualZWritePipeline; -//static boo::ObjToken s_AlphaLEqualPipeline; -//static boo::ObjToken s_AddPipeline; -//static boo::ObjToken s_AddGEqualPipeline; -//static boo::ObjToken s_AddGEqualZWritePipeline; -//static boo::ObjToken s_AddLEqualPipeline; -//static boo::ObjToken s_SubtractPipeline; -//static boo::ObjToken s_SubtractGEqualPipeline; -//static boo::ObjToken s_SubtractGEqualZWritePipeline; -//static boo::ObjToken s_SubtractLEqualPipeline; -//static boo::ObjToken s_MultPipeline; -//static boo::ObjToken s_MultGEqualPipeline; -//static boo::ObjToken s_MultGEqualZWritePipeline; -//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_AlphaGEqualZWritePipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAlphaGEqualZWrite{}); -// s_AlphaLEqualPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAlphaLEqual{}); -// s_AddPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAdd{}); -// s_AddGEqualPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAddGEqual{}); -// s_AddGEqualZWritePipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAddGEqualZWrite{}); -// s_AddLEqualPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterAddLEqual{}); -// s_SubtractPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterSubtract{}); -// s_SubtractGEqualPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterSubtractGEqual{}); -// s_SubtractGEqualZWritePipeline = hecl::conv->convert(Shader_CTexturedQuadFilterSubtractGEqualZWrite{}); -// s_SubtractLEqualPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterSubtractLEqual{}); -// s_MultPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterMult{}); -// s_MultGEqualPipeline = hecl::conv->convert(Shader_CTexturedQuadFilterMultGEqual{}); -// s_MultGEqualZWritePipeline = hecl::conv->convert(Shader_CTexturedQuadFilterMultGEqualZWrite{}); -// 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_AlphaGEqualZWritePipeline.reset(); -// s_AlphaLEqualPipeline.reset(); -// s_AddPipeline.reset(); -// s_AddGEqualPipeline.reset(); -// s_AddGEqualZWritePipeline.reset(); -// s_AddLEqualPipeline.reset(); -// s_SubtractPipeline.reset(); -// s_SubtractGEqualPipeline.reset(); -// s_SubtractGEqualZWritePipeline.reset(); -// s_SubtractLEqualPipeline.reset(); -// s_MultPipeline.reset(); -// s_MultGEqualPipeline.reset(); -// s_MultGEqualZWritePipeline.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; -// } -// break; -// case CTexturedQuadFilter::ZTest::GEqualZWrite: -// switch (type) { -// case EFilterType::Blend: -// return s_AlphaGEqualZWritePipeline; -// case EFilterType::Add: -// return s_AddGEqualZWritePipeline; -// case EFilterType::Subtract: -// return s_SubtractGEqualZWritePipeline; -// case EFilterType::Multiply: -// return s_MultGEqualZWritePipeline; -// default: -// break; -// } -// 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; -// } -// 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 aurora::gfx::TextureHandle& tex) : m_booTex(tex) { - m_flipRect = true; // TODO? -} - -CTexturedQuadFilter::CTexturedQuadFilter(EFilterType type, const aurora::gfx::TextureHandle& tex, ERglEnum ztest) -: m_booTex(tex), m_zTest(ztest) { - m_flipRect = true; // TODO? -// tex->setClampMode(boo::TextureClampMode::ClampToEdge); -// CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { -// m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, 32, 16); -// m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); -// -// const std::array, 1> bufs{m_uniBuf.get()}; -// const std::array stages{boo::PipelineStage::Vertex}; -// const std::array, 1> texs{m_booTex.get()}; -// m_dataBind = -// ctx.newShaderDataBinding(SelectPipeline(type, m_zTest), m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), -// stages.data(), nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr); -// return true; -// } BooTrace); -} - -CTexturedQuadFilter::CTexturedQuadFilter(EFilterType type, TLockedToken tex, ERglEnum ztest) -: CTexturedQuadFilter(type, aurora::gfx::TextureHandle{}, ztest) { - m_flipRect = true; // TODO? - m_tex = tex; -} - -void CTexturedQuadFilter::draw(const zeus::CColor& color, float uvScale, const zeus::CRectangle& rect, float z) { - SCOPED_GRAPHICS_DEBUG_GROUP("CTexturedQuadFilter::draw", zeus::skMagenta); - - const std::array verts{{ - {{0.f, 0.f, z}, {0.f, 0.f}}, - {{0.f, 1.f, z}, {0.f, uvScale}}, - {{1.f, 0.f, z}, {uvScale, 0.f}}, - {{1.f, 1.f, z}, {uvScale, uvScale}}, - }}; -// m_vbo->load(verts.data(), sizeof(verts)); - - if (!m_flipRect) { - 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; - } else { - 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)); - -// CGraphics::SetShaderDataBinding(m_dataBind); -// CGraphics::DrawArray(0, 4); -} - -void CTexturedQuadFilter::drawCropped(const zeus::CColor& color, float uvScale) { - SCOPED_GRAPHICS_DEBUG_GROUP("CTexturedQuadFilter::drawCropped", zeus::skMagenta); - - const float xFac = CGraphics::GetCroppedViewportWidth() / float(CGraphics::GetViewportWidth()); - const float yFac = CGraphics::GetCroppedViewportHeight() / float(CGraphics::GetViewportHeight()); - const float xBias = CGraphics::GetCroppedViewportLeft() / float(CGraphics::GetViewportWidth()); - const float yBias = CGraphics::GetCroppedViewportTop() / float(CGraphics::GetViewportHeight()); - - const std::array verts{{ - {{-1.f, -1.f, 0.f}, {xBias * uvScale, yBias * uvScale}}, - {{-1.f, 1.f, 0.f}, {xBias * uvScale, (yBias + yFac) * uvScale}}, - {{1.f, -1.f, 0.f}, {(xBias + xFac) * uvScale, yBias * uvScale}}, - {{1.f, 1.f, 0.f}, {(xBias + xFac) * uvScale, (yBias + yFac) * uvScale}}, - }}; -// m_vbo->load(verts.data(), sizeof(verts)); - - m_uniform.m_color = color; -// m_uniBuf->load(&m_uniform, sizeof(m_uniform)); - -// CGraphics::SetShaderDataBinding(m_dataBind); -// CGraphics::DrawArray(0, 4); -} - -void CTexturedQuadFilter::drawVerts(const zeus::CColor& color, std::array verts, float lod) { - SCOPED_GRAPHICS_DEBUG_GROUP("CTexturedQuadFilter::drawVerts", zeus::skMagenta); - -// m_vbo->load(verts.data(), sizeof(Vert) * verts.size()); - - m_uniform.m_matrix = CGraphics::GetPerspectiveProjectionMatrix(/*true*/) * CGraphics::g_GXModelView.toMatrix4f(); - m_uniform.m_color = color; - m_uniform.m_lod = lod; -// m_uniBuf->load(&m_uniform, sizeof(m_uniform)); - -// CGraphics::SetShaderDataBinding(m_dataBind); -// CGraphics::DrawArray(0, verts.size()); -} - -void CTexturedQuadFilter::DrawFilter(EFilterShape shape, const zeus::CColor& color, float t) { - SCOPED_GRAPHICS_DEBUG_GROUP("CTexturedQuadFilter::DrawFilter", zeus::skMagenta); - - m_uniform.m_matrix = zeus::CMatrix4f(); - m_uniform.m_lod = 0.f; - m_uniform.m_color = color; -// m_uniBuf->load(&m_uniform, sizeof(m_uniform)); - -// CGraphics::SetShaderDataBinding(m_dataBind); - - if (shape == EFilterShape::FullscreenQuarters) { - const std::array QuadVerts{{ - // ll - {{-1.f, -1.f, 0.f}, {t, t}}, - {{-1.f, 0.f, 0.f}, {t, 0.f}}, - {{0.f, -1.f, 0.f}, {0.f, t}}, - {{0.f, 0.f, 0.f}, {0.f, 0.f}}, - // ul - {{-1.f, 1.f, 0.f}, {t, t}}, - {{-1.f, 0.f, 0.f}, {t, 0.f}}, - {{0.f, 1.f, 0.f}, {0.f, t}}, - {{0.f, 0.f, 0.f}, {0.f, 0.f}}, - // lr - {{1.f, -1.f, 0.f}, {t, t}}, - {{1.f, 0.f, 0.f}, {t, 0.f}}, - {{0.f, -1.f, 0.f}, {0.f, t}}, - {{0.f, 0.f, 0.f}, {0.f, 0.f}}, - // ur - {{1.f, 1.f, 0.f}, {t, t}}, - {{1.f, 0.f, 0.f}, {t, 0.f}}, - {{0.f, 1.f, 0.f}, {0.f, t}}, - {{0.f, 0.f, 0.f}, {0.f, 0.f}}, - }}; -// m_vbo->load(QuadVerts.data(), sizeof(QuadVerts)); -// CGraphics::DrawArray(0, 4); -// CGraphics::DrawArray(4, 4); -// CGraphics::DrawArray(8, 4); -// CGraphics::DrawArray(12, 4); - } else { - const std::array FullscreenVerts{{ - {{-1.f, -1.f, 0.f}, {0.f, 0.f}}, - {{-1.f, 1.f, 0.f}, {0.f, t}}, - {{1.f, -1.f, 0.f}, {t, 0.f}}, - {{1.f, 1.f, 0.f}, {t, t}}, - }}; -// m_vbo->load(FullscreenVerts.data(), sizeof(FullscreenVerts)); -// CGraphics::DrawArray(0, FullscreenVerts.size()); - } -} - -CTexturedQuadFilterAlpha::CTexturedQuadFilterAlpha(EFilterType type, const aurora::gfx::TextureHandle& tex) -: CTexturedQuadFilter(tex) { -// CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { -// m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, 32, 4); -// m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); -// -// const std::array, 1> bufs{m_uniBuf.get()}; -// constexpr std::array stages{boo::PipelineStage::Vertex}; -// const std::array, 1> texs{m_booTex.get()}; -// m_dataBind = -// ctx.newShaderDataBinding(SelectAlphaPipeline(type), m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), -// stages.data(), nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr); -// return true; -// } BooTrace); -} - -CTexturedQuadFilterAlpha::CTexturedQuadFilterAlpha(EFilterType type, TLockedToken tex) -: CTexturedQuadFilterAlpha(type, aurora::gfx::TextureHandle{}) { - m_tex = tex; -} - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp b/Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp deleted file mode 100644 index 1af3d9e8f..000000000 --- a/Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp +++ /dev/null @@ -1,70 +0,0 @@ -#pragma once - -#include "Runtime/CToken.hpp" -#include "Runtime/Graphics/CGraphics.hpp" - -#include -#include -#include -#include -#include - -namespace metaforce { -class CTexture; - -enum class EFilterShape; -enum class EFilterType; - -class CTexturedQuadFilter { -public: - enum class ZTest { Never, Less, Equal, LEqual, Greater, NEqual, GEqual, Always }; - -protected: - struct Uniform { - zeus::CMatrix4f m_matrix; - zeus::CColor m_color; - float m_lod = 0.f; - }; - TLockedToken m_tex; - aurora::gfx::TextureHandle m_booTex; - // boo::ObjToken m_vbo; - // boo::ObjToken m_uniBuf; - // boo::ObjToken m_dataBind; - Uniform m_uniform; - ERglEnum m_zTest; - bool m_flipRect = false; - - explicit CTexturedQuadFilter(const aurora::gfx::TextureHandle& tex); - -public: - struct Vert { - zeus::CVector3f m_pos; - zeus::CVector2f m_uv; - }; - static void Initialize(); - static void Shutdown(); - static constexpr zeus::CRectangle DefaultRect{0.f, 0.f, 1.f, 1.f}; - explicit CTexturedQuadFilter(EFilterType type, TLockedToken tex, ERglEnum zTest = ERglEnum::Never); - explicit CTexturedQuadFilter(EFilterType type, const aurora::gfx::TextureHandle& tex, - ERglEnum zTest = ERglEnum::Never); - CTexturedQuadFilter(const CTexturedQuadFilter&) = delete; - CTexturedQuadFilter& operator=(const CTexturedQuadFilter&) = delete; - CTexturedQuadFilter(CTexturedQuadFilter&&) = default; - CTexturedQuadFilter& operator=(CTexturedQuadFilter&&) = default; - void draw(const zeus::CColor& color, float uvScale, const zeus::CRectangle& rect = DefaultRect, float z = 0.f); - void drawCropped(const zeus::CColor& color, float uvScale); - void drawVerts(const zeus::CColor& color, std::array verts, float lod = 0.f); - void DrawFilter(EFilterShape shape, const zeus::CColor& color, float t); - const TLockedToken& GetTex() const { return m_tex; } - const aurora::gfx::TextureHandle& GetBooTex() const { return m_booTex; } -}; - -class CTexturedQuadFilterAlpha : public CTexturedQuadFilter { -public: - static void Initialize(); - static void Shutdown(); - explicit CTexturedQuadFilterAlpha(EFilterType type, TLockedToken tex); - explicit CTexturedQuadFilterAlpha(EFilterType type, const aurora::gfx::TextureHandle& tex); -}; - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CThermalColdFilter.cpp b/Runtime/Graphics/Shaders/CThermalColdFilter.cpp deleted file mode 100644 index 221f6be1c..000000000 --- a/Runtime/Graphics/Shaders/CThermalColdFilter.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include "Runtime/Graphics/Shaders/CThermalColdFilter.hpp" - -#include "Runtime/GameGlobalObjects.hpp" -#include "Runtime/Graphics/CCubeRenderer.hpp" -#include "Runtime/Graphics/CGraphics.hpp" - -//#include -#include - -namespace metaforce { - -//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) { -// struct Vert { -// zeus::CVector2f m_pos; -// zeus::CVector2f m_uv; -// zeus::CVector2f m_uvNoise; -// }; -// const std::array verts{{ -// {{-1.f, -1.f}, {0.f, 0.f}, {0.f, 0.f}}, -// {{-1.f, 1.f}, {0.f, 1.f}, {0.f, 448.f}}, -// {{1.f, -1.f}, {1.f, 0.f}, {640.f, 0.f}}, -// {{1.f, 1.f}, {1.f, 1.f}, {640.f, 448.f}}, -// }}; -// m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), 48, verts.size()); -// m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); -// -// const std::array, 1> bufs{m_uniBuf.get()}; -// constexpr std::array stages{boo::PipelineStage::Vertex}; -// const std::array, 2> texs{ -// CGraphics::g_SpareTexture.get(), -// g_Renderer->GetRandomStaticEntropyTex(), -// }; -// m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), -// stages.data(), nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr); -// return true; -// } BooTrace); - - setNoiseOffset(0); - setScale(0.f); -} - -void CThermalColdFilter::draw() { - SCOPED_GRAPHICS_DEBUG_GROUP("CThermalColdFilter::draw", zeus::skMagenta); - -// CGraphics::ResolveSpareTexture(CGraphics::g_CroppedViewport); -// m_uniBuf->load(&m_uniform, sizeof(m_uniform)); -// CGraphics::SetShaderDataBinding(m_dataBind); -// CGraphics::DrawArray(0, 4); -} - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CThermalColdFilter.hpp b/Runtime/Graphics/Shaders/CThermalColdFilter.hpp deleted file mode 100644 index 19c53dfaf..000000000 --- a/Runtime/Graphics/Shaders/CThermalColdFilter.hpp +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once - -#include - -//#include - -#include -#include - -namespace metaforce { - -class CThermalColdFilter { - struct Uniform { - zeus::CMatrix4f m_indMtx; - std::array m_colorRegs; - float m_randOff = 0.f; - }; -// boo::ObjToken m_vbo; -// boo::ObjToken m_uniBuf; -// boo::ObjToken m_dataBind; - Uniform m_uniform; - -public: - static void Initialize(); - static void Shutdown(); - CThermalColdFilter(); - void setNoiseOffset(unsigned shift) { m_uniform.m_randOff = float(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.025f * (1.f - scale); - m_uniform.m_indMtx[0][0] = scale; - m_uniform.m_indMtx[1][1] = scale; - } - void draw(); -}; - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CThermalHotFilter.cpp b/Runtime/Graphics/Shaders/CThermalHotFilter.cpp deleted file mode 100644 index 05eec49ce..000000000 --- a/Runtime/Graphics/Shaders/CThermalHotFilter.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include "Runtime/Graphics/Shaders/CThermalHotFilter.hpp" - -#include "Runtime/GameGlobalObjects.hpp" -#include "Runtime/Graphics/CCubeRenderer.hpp" -#include "Runtime/Graphics/CGraphics.hpp" - -//#include -#include - -namespace metaforce { - -//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) { -// struct Vert { -// zeus::CVector2f m_pos; -// zeus::CVector2f m_uv; -// }; -// const std::array verts{{ -// {{-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.data(), 32, verts.size()); -// m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); -// -// const std::array, 1> bufs{m_uniBuf.get()}; -// constexpr std::array stages{boo::PipelineStage::Vertex}; -// const std::array, 2> texs{ -// CGraphics::g_SpareTexture.get(), -// g_Renderer->GetThermoPalette(), -// }; -// m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), -// stages.data(), nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr); -// return true; -// } BooTrace); -} - -void CThermalHotFilter::draw() { - SCOPED_GRAPHICS_DEBUG_GROUP("CThermalHotFilter::draw", zeus::skMagenta); - -// CGraphics::ResolveSpareTexture(CGraphics::g_CroppedViewport); - - // m_uniBuf->load(&m_uniform, sizeof(m_uniform)); - -// CGraphics::SetShaderDataBinding(m_dataBind); -// CGraphics::DrawArray(0, 4); -} - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CThermalHotFilter.hpp b/Runtime/Graphics/Shaders/CThermalHotFilter.hpp deleted file mode 100644 index 74ba9416e..000000000 --- a/Runtime/Graphics/Shaders/CThermalHotFilter.hpp +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once - -#include - -//#include - -#include - -namespace metaforce { - -class CThermalHotFilter { - struct Uniform { - std::array m_colorRegs; - }; -// boo::ObjToken m_vbo; -// boo::ObjToken m_uniBuf; -// boo::ObjToken m_dataBind; - 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(); -}; - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CWorldShadowShader.cpp b/Runtime/Graphics/Shaders/CWorldShadowShader.cpp deleted file mode 100644 index d5956ae53..000000000 --- a/Runtime/Graphics/Shaders/CWorldShadowShader.cpp +++ /dev/null @@ -1,90 +0,0 @@ -#include "Runtime/Graphics/Shaders/CWorldShadowShader.hpp" - -#include - -#include "Runtime/Camera/CCameraFilter.hpp" -#include "Runtime/Graphics/CGraphics.hpp" - -//#include -#include - -namespace metaforce { - -//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) { -// CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { -// m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, 16, 4); -// m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); -// -// const std::array, 1> bufs{m_uniBuf.get()}; -// constexpr std::array stages{boo::PipelineStage::Vertex}; -// m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), -// stages.data(), nullptr, nullptr, 0, nullptr, nullptr, nullptr); -// m_zDataBind = ctx.newShaderDataBinding(s_ZPipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), -// stages.data(), nullptr, nullptr, 0, nullptr, nullptr, nullptr); -// -// m_tex = ctx.newRenderTexture(m_w, m_h, boo::TextureClampMode::ClampToWhite, 1, 0); -// return true; -// } BooTrace); -} - -void CWorldShadowShader::bindRenderTarget() { -// CGraphics::g_BooMainCommandQueue->setRenderTarget(m_tex); -} - -void CWorldShadowShader::drawBase(float extent) { - SCOPED_GRAPHICS_DEBUG_GROUP("CWorldShadowShader::drawBase", zeus::skMagenta); - - const std::array verts{{ - {-extent, 0.f, extent}, - {extent, 0.f, extent}, - {-extent, 0.f, -extent}, - {extent, 0.f, -extent}, - }}; -// m_vbo->load(verts.data(), sizeof(verts)); - - m_uniform.m_matrix = CGraphics::GetPerspectiveProjectionMatrix(/*true*/) * CGraphics::g_GXModelView.toMatrix4f(); - m_uniform.m_color = zeus::skWhite; -// m_uniBuf->load(&m_uniform, sizeof(m_uniform)); -// -// CGraphics::SetShaderDataBinding(m_zDataBind); -// CGraphics::DrawArray(0, 4); -} - -void CWorldShadowShader::lightenShadow() { - SCOPED_GRAPHICS_DEBUG_GROUP("CWorldShadowShader::lightenShadow", zeus::skMagenta); - - m_uniform.m_color = zeus::CColor(1.f, 0.25f); -// m_uniBuf->load(&m_uniform, sizeof(m_uniform)); -// -// CGraphics::SetShaderDataBinding(m_dataBind); -// CGraphics::DrawArray(0, 4); -} - -void CWorldShadowShader::blendPreviousShadow() { - SCOPED_GRAPHICS_DEBUG_GROUP("CWorldShadowShader::blendPreviousShadow", zeus::skMagenta); - -// if (!m_prevQuad) -// m_prevQuad.emplace(EFilterType::Blend, m_tex); -// zeus::CRectangle rect(0.f, 1.f, 1.f, -1.f); -// m_prevQuad->draw({1.f, 0.85f}, 1.f, rect); -} - -void CWorldShadowShader::resolveTexture() { -// boo::SWindowRect rect = {0, 0, int(m_w), int(m_h)}; -// CGraphics::g_BooMainCommandQueue->resolveBindTexture(m_tex, rect, false, 0, true, false, true); -} - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CWorldShadowShader.hpp b/Runtime/Graphics/Shaders/CWorldShadowShader.hpp deleted file mode 100644 index 4f649fa12..000000000 --- a/Runtime/Graphics/Shaders/CWorldShadowShader.hpp +++ /dev/null @@ -1,45 +0,0 @@ -#pragma once - -#include - -#include "Runtime/GCNTypes.hpp" - -//#include - -#include -#include - -namespace metaforce { - -class CWorldShadowShader { -// aurora::gfx::TextureHandle m_tex; -// std::optional m_prevQuad; - u32 m_w, m_h; - - struct Uniform { - zeus::CMatrix4f m_matrix; - zeus::CColor m_color; - }; -// boo::ObjToken m_vbo; -// boo::ObjToken m_uniBuf; -// boo::ObjToken m_dataBind; -// boo::ObjToken m_zDataBind; - Uniform m_uniform; - -public: - static void Initialize(); - static void Shutdown(); - explicit CWorldShadowShader(u32 w, u32 h); - void bindRenderTarget(); - void drawBase(float extent); - void lightenShadow(); - void blendPreviousShadow(); - void resolveTexture(); - - u32 GetWidth() const { return m_w; } - u32 GetHeight() const { return m_h; } - -// const aurora::gfx::TextureHandle& GetTexture() const { return m_tex; } -}; - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CXRayBlurFilter.cpp b/Runtime/Graphics/Shaders/CXRayBlurFilter.cpp deleted file mode 100644 index f34967fee..000000000 --- a/Runtime/Graphics/Shaders/CXRayBlurFilter.cpp +++ /dev/null @@ -1,72 +0,0 @@ -#include "Runtime/Graphics/Shaders/CXRayBlurFilter.hpp" - -#include "Runtime/GameGlobalObjects.hpp" -#include "Runtime/Graphics/CGraphics.hpp" -#include "Runtime/Graphics/CTexture.hpp" - -//#include -#include - -namespace metaforce { - -//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()) -// CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { -// struct Vert { -// zeus::CVector2f m_pos; -// zeus::CVector2f m_uv; -// }; -// const std::array verts{{ -// {{-1.f, -1.f}, {0.f, 0.f}}, -// {{-1.f, 1.f}, {0.f, 1.f}}, -// {{1.f, -1.f}, {1.f, 0.f}}, -// {{1.f, 1.f}, {1.f, 1.f}}, -// }}; -// m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), 32, verts.size()); -// m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); -// -// const std::array, 1> bufs{m_uniBuf.get()}; -// constexpr std::array stages{boo::PipelineStage::Vertex}; -// const std::array, 2> texs{ -// CGraphics::g_SpareTexture.get(), -// m_booTex, -// }; -// m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), -// stages.data(), nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr); -// return true; -// } BooTrace); -} - -void CXRayBlurFilter::draw(float amount) { - SCOPED_GRAPHICS_DEBUG_GROUP("CXRayBlurFilter::draw", zeus::skMagenta); - -// CGraphics::ResolveSpareTexture(CGraphics::g_CroppedViewport); - - const float blurL = amount * g_tweakGui->GetXrayBlurScaleLinear() * 0.25f; - const float blurQ = amount * g_tweakGui->GetXrayBlurScaleQuadratic() * 0.25f; - - for (size_t i = 0; i < m_uniform.m_uv.size(); ++i) { - const float iflt = float(i) / 2.f; - const float uvScale = (1.f - (blurL * iflt + blurQ * iflt * iflt)); - const 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::SetShaderDataBinding(m_dataBind); -// CGraphics::DrawArray(0, 4); -} - -} // namespace metaforce diff --git a/Runtime/Graphics/Shaders/CXRayBlurFilter.hpp b/Runtime/Graphics/Shaders/CXRayBlurFilter.hpp deleted file mode 100644 index 86928529d..000000000 --- a/Runtime/Graphics/Shaders/CXRayBlurFilter.hpp +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once - -#include - -#include "Runtime/CToken.hpp" -#include "Runtime/Graphics/CGraphics.hpp" - -#include - -namespace metaforce { -class CTexture; - -class CXRayBlurFilter { - struct Uniform { - std::array m_uv; - }; - TLockedToken m_paletteTex; -// aurora::gfx::TextureHandle m_booTex; -// boo::ObjToken m_vbo; -// boo::ObjToken m_uniBuf; -// boo::ObjToken m_dataBind; - Uniform m_uniform; - -public: - static void Initialize(); - static void Shutdown(); - explicit CXRayBlurFilter(TLockedToken& tex); - void draw(float amount); -}; - -} // namespace metaforce diff --git a/Runtime/GuiSys/CAuiEnergyBarT01.cpp b/Runtime/GuiSys/CAuiEnergyBarT01.cpp index f04696361..477bceec3 100644 --- a/Runtime/GuiSys/CAuiEnergyBarT01.cpp +++ b/Runtime/GuiSys/CAuiEnergyBarT01.cpp @@ -113,7 +113,7 @@ void CAuiEnergyBarT01::Draw(const CGuiWidgetDrawParms& drawParms) { CGraphics::SetTevOp(ERglTevStage::Stage0, CTevCombiners::kEnvModulate); CGraphics::SetTevOp(ERglTevStage::Stage1, CTevCombiners::kEnvPassthru); xbc_tex->Load(GX_TEXMAP0, EClampMode::Repeat); - CGraphics::StreamBegin(GX_TRIANGLESTRIP); + CGraphics::StreamBegin(ERglPrimitive::TriangleStrip); CGraphics::StreamColor(useCol); auto coords = xd8_coordFunc(barOffT); while (barOffT < barMaxT) { diff --git a/Runtime/GuiSys/CAuiEnergyBarT01.hpp b/Runtime/GuiSys/CAuiEnergyBarT01.hpp index 2e5586eee..a47d710e0 100644 --- a/Runtime/GuiSys/CAuiEnergyBarT01.hpp +++ b/Runtime/GuiSys/CAuiEnergyBarT01.hpp @@ -6,7 +6,6 @@ #include "Runtime/CToken.hpp" #include "Runtime/Graphics/CTexture.hpp" -#include "Runtime/Graphics/Shaders/CEnergyBarShader.hpp" #include "Runtime/GuiSys/CGuiWidget.hpp" #include diff --git a/Runtime/GuiSys/CAuiImagePane.cpp b/Runtime/GuiSys/CAuiImagePane.cpp index 1258433b5..4a17137c0 100644 --- a/Runtime/GuiSys/CAuiImagePane.cpp +++ b/Runtime/GuiSys/CAuiImagePane.cpp @@ -81,7 +81,7 @@ void CAuiImagePane::DoDrawImagePane(const zeus::CColor& color, CTexture& tex, in CGraphics::SetTevOp(ERglTevStage::Stage0, CTevCombiners::kEnvModulate); CGraphics::SetTevOp(ERglTevStage::Stage1, CTevCombiners::kEnvPassthru); tex.LoadMipLevel(0, GX_TEXMAP0, EClampMode::Repeat); - CGraphics::StreamBegin(GX_TRIANGLESTRIP); + CGraphics::StreamBegin(ERglPrimitive::TriangleStrip); CGraphics::StreamColor(useColor); for (u32 i = 0; i < useUVs->size(); ++i) { CGraphics::StreamTexcoord((*useUVs)[i] + xd0_uvBias0); @@ -147,7 +147,7 @@ void CAuiImagePane::DoDrawImagePane(const zeus::CColor& color, CTexture& tex, in CGraphics::SetTevOp(ERglTevStage::Stage0, CTevCombiners::kEnvModulateAlpha); CGraphics::SetTevOp(ERglTevStage::Stage1, CTevCombiners::kEnvPassthru); tex.Load(GX_TEXMAP0, EClampMode::Repeat); - CGraphics::StreamBegin(GX_TRIANGLESTRIP); + CGraphics::StreamBegin(ERglPrimitive::TriangleStrip); CGraphics::StreamColor(useColor); for (u32 i = 0; i < useUVs->size(); ++i) { CGraphics::StreamTexcoord((*useUVs)[i]); diff --git a/Runtime/GuiSys/CCompoundTargetReticle.cpp b/Runtime/GuiSys/CCompoundTargetReticle.cpp index a8b83e4f9..fd4a50e82 100644 --- a/Runtime/GuiSys/CCompoundTargetReticle.cpp +++ b/Runtime/GuiSys/CCompoundTargetReticle.cpp @@ -70,7 +70,7 @@ CCompoundTargetReticle::CCompoundTargetReticle(const CStateManager& mgr) x34_crosshairs.Lock(); } -CCompoundTargetReticle::SScanReticuleRenderer::SScanReticuleRenderer() { +// CCompoundTargetReticle::SScanReticuleRenderer::SScanReticuleRenderer() { // CGraphics::CommitResources([this](boo::IGraphicsDataFactory::Context& ctx) { // for (size_t i = 0; i < m_lineRenderers.size(); ++i) { // m_lineRenderers[i].emplace(CLineRenderer::EPrimitiveMode::Lines, 8, {}, true, true); @@ -80,7 +80,7 @@ CCompoundTargetReticle::SScanReticuleRenderer::SScanReticuleRenderer() { // } // return true; // } BooTrace); -} +// } CCompoundTargetReticle::EReticleState CCompoundTargetReticle::GetDesiredReticleState(const CStateManager& mgr) const { switch (mgr.GetPlayerState()->GetCurrentVisor()) { @@ -896,33 +896,33 @@ void CCompoundTargetReticle::DrawNextLockOnGroup(const zeus::CMatrix3f& rot, con float alpha = 0.5f * factor; zeus::CColor color = g_tweakGuiColors->GetScanReticuleColor(); color.a() *= alpha; - for (size_t i = 0; i < m_scanRetRenderer.m_lineRenderers.size(); ++i) { - const float lineWidth = i != 0 ? 2.5f : 1.f; - auto& rend = *m_scanRetRenderer.m_lineRenderers[i]; - rend.Reset(); - rend.AddVertex({-0.5f, 0.f, 0.f}, color, lineWidth); - rend.AddVertex({-20.5f, 0.f, 0.f}, color, lineWidth); - rend.AddVertex({0.5f, 0.f, 0.f}, color, lineWidth); - rend.AddVertex({20.5f, 0.f, 0.f}, color, lineWidth); - rend.AddVertex({0.f, 0.f, -0.5f}, color, lineWidth); - rend.AddVertex({0.f, 0.f, -20.5f}, color, lineWidth); - rend.AddVertex({0.f, 0.f, 0.5f}, color, lineWidth); - rend.AddVertex({0.f, 0.f, 20.5f}, color, lineWidth); - rend.Render(); - - for (size_t j = 0; j < m_scanRetRenderer.m_stripRenderers[i].size(); ++j) { - const float xSign = j < 2 ? -1.f : 1.f; - const float zSign = (j & 0x1) != 0 ? -1.f : 1.f; - // begin line strip - auto& stripRend = *m_scanRetRenderer.m_stripRenderers[i][j]; - stripRend.Reset(); - stripRend.AddVertex({0.5f * xSign, 0.f, 0.1f * zSign}, color, lineWidth); - stripRend.AddVertex({0.5f * xSign, 0.f, 0.35f * zSign}, color, lineWidth); - stripRend.AddVertex({0.35f * xSign, 0.f, 0.5f * zSign}, color, lineWidth); - stripRend.AddVertex({0.1f * xSign, 0.f, 0.5f * zSign}, color, lineWidth); - stripRend.Render(); - } - } + // for (size_t i = 0; i < m_scanRetRenderer.m_lineRenderers.size(); ++i) { + // const float lineWidth = i != 0 ? 2.5f : 1.f; + // auto& rend = *m_scanRetRenderer.m_lineRenderers[i]; + // rend.Reset(); + // rend.AddVertex({-0.5f, 0.f, 0.f}, color, lineWidth); + // rend.AddVertex({-20.5f, 0.f, 0.f}, color, lineWidth); + // rend.AddVertex({0.5f, 0.f, 0.f}, color, lineWidth); + // rend.AddVertex({20.5f, 0.f, 0.f}, color, lineWidth); + // rend.AddVertex({0.f, 0.f, -0.5f}, color, lineWidth); + // rend.AddVertex({0.f, 0.f, -20.5f}, color, lineWidth); + // rend.AddVertex({0.f, 0.f, 0.5f}, color, lineWidth); + // rend.AddVertex({0.f, 0.f, 20.5f}, color, lineWidth); + // rend.Render(); + // + // for (size_t j = 0; j < m_scanRetRenderer.m_stripRenderers[i].size(); ++j) { + // const float xSign = j < 2 ? -1.f : 1.f; + // const float zSign = (j & 0x1) != 0 ? -1.f : 1.f; + // // begin line strip + // auto& stripRend = *m_scanRetRenderer.m_stripRenderers[i][j]; + // stripRend.Reset(); + // stripRend.AddVertex({0.5f * xSign, 0.f, 0.1f * zSign}, color, lineWidth); + // stripRend.AddVertex({0.5f * xSign, 0.f, 0.35f * zSign}, color, lineWidth); + // stripRend.AddVertex({0.35f * xSign, 0.f, 0.5f * zSign}, color, lineWidth); + // stripRend.AddVertex({0.1f * xSign, 0.f, 0.5f * zSign}, color, lineWidth); + // stripRend.Render(); + // } + // } } } @@ -1004,7 +1004,6 @@ float CCompoundTargetReticle::CalculateClampedScale(const zeus::CVector3f& pos, const CGameCamera* cam = mgr.GetCameraManager()->GetCurrentCamera(mgr); mgr.GetCameraManager()->GetCurrentCameraTransform(mgr); zeus::CVector3f viewPos = cam->GetTransform().transposeRotate(pos - cam->GetTransform().origin); - viewPos = zeus::CVector3f(viewPos.x(), viewPos.z(), -viewPos.y()); const float realX = cam->GetPerspectiveMatrix().multiplyOneOverW(viewPos).x(); const float offsetX = cam->GetPerspectiveMatrix().multiplyOneOverW(viewPos + zeus::CVector3f(scale, 0.f, 0.f)).x(); const float unclampedX = (offsetX - realX) * 640; diff --git a/Runtime/GuiSys/CCompoundTargetReticle.hpp b/Runtime/GuiSys/CCompoundTargetReticle.hpp index 5273d69fa..30f7fbe89 100644 --- a/Runtime/GuiSys/CCompoundTargetReticle.hpp +++ b/Runtime/GuiSys/CCompoundTargetReticle.hpp @@ -5,7 +5,6 @@ #include "Runtime/CPlayerState.hpp" #include "Runtime/CToken.hpp" -#include "Runtime/Graphics/CLineRenderer.hpp" #include "Runtime/RetroTypes.hpp" #include @@ -125,13 +124,6 @@ private: u32 x220_ = 0; u32 x228_ = 0; - struct SScanReticuleRenderer { - std::array, 2> m_lineRenderers; - std::array, 4>, 2> m_stripRenderers; - SScanReticuleRenderer(); - }; - SScanReticuleRenderer m_scanRetRenderer; - void DrawGrapplePoint(const CScriptGrapplePoint& point, float t, const CStateManager& mgr, const zeus::CMatrix3f& rot, bool zEqual); diff --git a/Runtime/GuiSys/CGuiFrame.cpp b/Runtime/GuiSys/CGuiFrame.cpp index 15ecd2598..b9efbcc5a 100644 --- a/Runtime/GuiSys/CGuiFrame.cpp +++ b/Runtime/GuiSys/CGuiFrame.cpp @@ -142,7 +142,7 @@ void CGuiFrame::Draw(const CGuiWidgetDrawParms& parms) const { CGuiWidget* CGuiFrame::BestCursorHit(const zeus::CVector2f& point, const CGuiWidgetDrawParms& parms) const { x14_camera->Draw(parms); - zeus::CMatrix4f vp = CGraphics::GetPerspectiveProjectionMatrix() * CGraphics::g_CameraMatrix.toMatrix4f(); + zeus::CMatrix4f vp = CGraphics::GetPerspectiveProjectionMatrix(); // TODO * CGraphics::mCameraMtx; CGuiWidget* ret = nullptr; for (const auto& widget : x2c_widgets) if (widget->GetMouseActive() && widget->TestCursorHit(vp, point)) diff --git a/Runtime/GuiSys/CGuiPane.cpp b/Runtime/GuiSys/CGuiPane.cpp index f9640f03b..08f45029c 100644 --- a/Runtime/GuiSys/CGuiPane.cpp +++ b/Runtime/GuiSys/CGuiPane.cpp @@ -17,7 +17,7 @@ void CGuiPane::Draw(const CGuiWidgetDrawParms& parms) { col.a() = parms.x0_alphaMod * xa8_color2.a(); CGraphics::SetTevOp(ERglTevStage::Stage0, CTevCombiners::kEnvPassthru); - CGraphics::DrawPrimitive(GX_TRIANGLESTRIP, xc0_verts.data(), skDefaultNormal, col, xc0_verts.size()); + CGraphics::DrawPrimitive(ERglPrimitive::TriangleStrip, xc0_verts.data(), skDefaultNormal, col, xc0_verts.size()); } CGuiWidget::Draw(parms); } diff --git a/Runtime/GuiSys/CGuiTextSupport.cpp b/Runtime/GuiSys/CGuiTextSupport.cpp index d89004efe..05b085802 100644 --- a/Runtime/GuiSys/CGuiTextSupport.cpp +++ b/Runtime/GuiSys/CGuiTextSupport.cpp @@ -227,7 +227,7 @@ void CGuiTextSupport::Render() { CheckAndRebuildRenderBuffer(); if (CTextRenderBuffer* buf = GetCurrentPageRenderBuffer()) { SCOPED_GRAPHICS_DEBUG_GROUP("CGuiTextSupport::Render", zeus::skBlue); - zeus::CTransform oldModel = CGraphics::g_GXModelMatrix; + zeus::CTransform oldModel = CGraphics::mModelMatrix; CGraphics::SetModelMatrix(oldModel * zeus::CTransform::Scale(1.f, 1.f, -1.f)); buf->Render(x2c_geometryColor, x10_curTimeMod900); CGraphics::SetModelMatrix(oldModel); diff --git a/Runtime/GuiSys/CHudRadarInterface.cpp b/Runtime/GuiSys/CHudRadarInterface.cpp index 45b8fe9bb..3f0f58243 100644 --- a/Runtime/GuiSys/CHudRadarInterface.cpp +++ b/Runtime/GuiSys/CHudRadarInterface.cpp @@ -29,7 +29,7 @@ CHudRadarInterface::CHudRadarInterface(CGuiFrame& baseHud, CStateManager& stateM void CHudRadarInterface::DoDrawRadarPaint(float radius) { radius *= 4.f; - CGraphics::StreamBegin(GX_TRIANGLESTRIP); + CGraphics::StreamBegin(ERglPrimitive::TriangleStrip); CGraphics::StreamTexcoord(0.f, 1.f); CGraphics::StreamVertex(-radius, 0.f, radius); CGraphics::StreamTexcoord(0.f, 0.f); diff --git a/Runtime/GuiSys/COrbitPointMarker.cpp b/Runtime/GuiSys/COrbitPointMarker.cpp index f1ac2b7d3..d52e6876b 100644 --- a/Runtime/GuiSys/COrbitPointMarker.cpp +++ b/Runtime/GuiSys/COrbitPointMarker.cpp @@ -73,7 +73,7 @@ void COrbitPointMarker::Draw(const CStateManager& mgr) { const CGameCamera* curCam = mgr.GetCameraManager()->GetCurrentCamera(mgr); zeus::CTransform camXf = mgr.GetCameraManager()->GetCurrentCameraTransform(mgr); CGraphics::SetViewPointMatrix(camXf); - zeus::CFrustum frustum = mgr.SetupDrawFrustum(CGraphics::g_Viewport); + zeus::CFrustum frustum = mgr.SetupDrawFrustum(CGraphics::mViewport); frustum.updatePlanes( camXf, zeus::SProjPersp(zeus::degToRad(curCam->GetFov()), CGraphics::GetViewportAspect(), 1.f, 100.f)); g_Renderer->SetClippingPlanes(frustum); diff --git a/Runtime/GuiSys/CScanDisplay.cpp b/Runtime/GuiSys/CScanDisplay.cpp index 37b909c72..ea1625909 100644 --- a/Runtime/GuiSys/CScanDisplay.cpp +++ b/Runtime/GuiSys/CScanDisplay.cpp @@ -42,7 +42,7 @@ void CScanDisplay::CDataDot::Draw(const zeus::CColor& col, float radius) { const zeus::CTransform xf = zeus::CTransform::Translate(xc_curPos.x(), 0.f, xc_curPos.y()); g_Renderer->SetModelMatrix(xf); - CGraphics::StreamBegin(GX_TRIANGLESTRIP); + CGraphics::StreamBegin(ERglPrimitive::TriangleStrip); zeus::CColor useColor = col; useColor.a() *= x24_alpha; CGraphics::StreamColor(useColor); diff --git a/Runtime/GuiSys/CSplashScreen.cpp b/Runtime/GuiSys/CSplashScreen.cpp index 834cfbf69..375c82241 100644 --- a/Runtime/GuiSys/CSplashScreen.cpp +++ b/Runtime/GuiSys/CSplashScreen.cpp @@ -78,7 +78,7 @@ void CSplashScreen::Draw() { const auto y = static_cast(170 - (height - 104) / 2); CGraphics::SetOrtho(-10.f, 650.f, -5.5f, 484.5f, -1.f, 1.f); CGraphics::SetCullMode(ERglCullMode::None); - CGraphics::StreamBegin(GX_TRIANGLESTRIP); + CGraphics::StreamBegin(ERglPrimitive::TriangleStrip); CGraphics::StreamColor(color); CGraphics::StreamTexcoord(0.f, 0.f); CGraphics::StreamVertex({x, 0.f, y + static_cast(height)}); diff --git a/Runtime/GuiSys/CTextRenderBuffer.cpp b/Runtime/GuiSys/CTextRenderBuffer.cpp index 8b300d31d..83cab40be 100644 --- a/Runtime/GuiSys/CTextRenderBuffer.cpp +++ b/Runtime/GuiSys/CTextRenderBuffer.cpp @@ -4,7 +4,6 @@ #include "Runtime/Graphics/CGraphics.hpp" #include "Runtime/Graphics/CGraphicsPalette.hpp" #include "Runtime/Graphics/CTexture.hpp" -#include "Runtime/Graphics/Shaders/CTextSupportShader.hpp" #include "Runtime/GuiSys/CFontImageDef.hpp" #include "Runtime/GuiSys/CFontRenderState.hpp" #include "Runtime/GuiSys/CInstruction.hpp" diff --git a/Runtime/GuiSys/CTextRenderBuffer.hpp b/Runtime/GuiSys/CTextRenderBuffer.hpp index d2f08d2c1..a8962b4fe 100644 --- a/Runtime/GuiSys/CTextRenderBuffer.hpp +++ b/Runtime/GuiSys/CTextRenderBuffer.hpp @@ -5,7 +5,6 @@ #include "Runtime/CToken.hpp" #include "Runtime/RetroTypes.hpp" -#include "Runtime/Graphics/Shaders/CTextSupportShader.hpp" #include "Runtime/GuiSys/CFontImageDef.hpp" #include "Runtime/GuiSys/CGuiWidget.hpp" diff --git a/Runtime/MP1/CInGameGuiManager.hpp b/Runtime/MP1/CInGameGuiManager.hpp index bac2dd31a..6856dfb7a 100644 --- a/Runtime/MP1/CInGameGuiManager.hpp +++ b/Runtime/MP1/CInGameGuiManager.hpp @@ -12,7 +12,6 @@ #include "Runtime/CToken.hpp" #include "Runtime/CStateManager.hpp" #include "Runtime/Camera/CCameraFilter.hpp" -#include "Runtime/Graphics/Shaders/CRandomStaticFilter.hpp" #include "Runtime/MP1/CFaceplateDecoration.hpp" #include "Runtime/MP1/CInGameGuiManagerCommon.hpp" #include "Runtime/MP1/CInventoryScreen.hpp" diff --git a/Runtime/MP1/CPlayerVisor.cpp b/Runtime/MP1/CPlayerVisor.cpp index 7daf617d3..3c2acc928 100644 --- a/Runtime/MP1/CPlayerVisor.cpp +++ b/Runtime/MP1/CPlayerVisor.cpp @@ -352,7 +352,7 @@ void CPlayerVisor::DrawScanEffect(const CStateManager& mgr, CTargetingManager* t GXSetTexCopySrc(int((CGraphics::GetViewportWidth() - vpW) / 2.f), int((CGraphics::GetViewportHeight() - vpH) / 2.f), vpW, vpH); GXSetTexCopyDst(vpW, vpH, GX_TF_RGB565, false); - GXCopyTex(CGraphics::sSpareTextureData, false); + GXCopyTex(CGraphics::mpSpareBuffer, false); GXPixModeSync(); { @@ -366,7 +366,7 @@ void CPlayerVisor::DrawScanEffect(const CStateManager& mgr, CTargetingManager* t const zeus::CTransform seventeenScale = zeus::CTransform::Scale(17.f * vpScale, 1.f, 17.f * vpScale); const zeus::CTransform mm = seventeenScale * windowScale; g_Renderer->SetModelMatrix(mm); - CGraphics::LoadDolphinSpareTexture(vpW, vpH, GX_TF_RGB565, CGraphics::sSpareTextureData, GX_TEXMAP0); + CGraphics::LoadDolphinSpareTexture(vpW, vpH, GX_TF_RGB565, CGraphics::mpSpareBuffer, GX_TEXMAP0); if (x108_newScanPane) { SCOPED_GRAPHICS_DEBUG_GROUP("x108_newScanPane Draw", zeus::skMagenta); diff --git a/Runtime/MP1/CSamusHud.hpp b/Runtime/MP1/CSamusHud.hpp index d927d7eea..a66248db9 100644 --- a/Runtime/MP1/CSamusHud.hpp +++ b/Runtime/MP1/CSamusHud.hpp @@ -8,7 +8,6 @@ #include "Runtime/CToken.hpp" #include "Runtime/rstl.hpp" #include "Runtime/Camera/CCameraFilter.hpp" -#include "Runtime/Graphics/Shaders/CRandomStaticFilter.hpp" #include "Runtime/GuiSys/CHudBallInterface.hpp" #include "Runtime/GuiSys/CHudBossEnergyInterface.hpp" #include "Runtime/GuiSys/CHudDecoInterface.hpp" diff --git a/Runtime/MP1/MP1.cpp b/Runtime/MP1/MP1.cpp index d42d82b52..a1a71d01d 100644 --- a/Runtime/MP1/MP1.cpp +++ b/Runtime/MP1/MP1.cpp @@ -678,7 +678,6 @@ void CMain::ShutdownSubsystems() { CElementGen::Shutdown(); CAnimData::FreeCache(); CMemoryCardSys::Shutdown(); - CMappableObject::Shutdown(); // Metaforce additions CMoviePlayer::Shutdown(); CFont::Shutdown(); diff --git a/Runtime/MP1/Tweaks/CTweakAutoMapper.cpp b/Runtime/MP1/Tweaks/CTweakAutoMapper.cpp index d8d52890c..13950d2f6 100644 --- a/Runtime/MP1/Tweaks/CTweakAutoMapper.cpp +++ b/Runtime/MP1/Tweaks/CTweakAutoMapper.cpp @@ -91,7 +91,9 @@ CTweakAutoMapper::CTweakAutoMapper(CInputStream& in) { x98_alphaSurfaceUnvisited = in.ReadFloat(); x9c_miniAlphaOutlineUnvisited = in.ReadFloat(); xa0_alphaOutlineUnvisited = in.ReadFloat(); - xa4_doorCenter = in.Get(); + xa4_doorCenterA = in.ReadFloat(); + xa8_doorCenterB = in.ReadFloat(); + xac_doorCenterC = in.ReadFloat(); xb0_ = in.ReadFloat(); xb4_ = in.ReadFloat(); xb8_miniMapViewportWidth = in.ReadFloat(); diff --git a/Runtime/MP1/Tweaks/CTweakAutoMapper.hpp b/Runtime/MP1/Tweaks/CTweakAutoMapper.hpp index 1952aed91..7e9eeb837 100644 --- a/Runtime/MP1/Tweaks/CTweakAutoMapper.hpp +++ b/Runtime/MP1/Tweaks/CTweakAutoMapper.hpp @@ -48,8 +48,9 @@ struct CTweakAutoMapper final : public Tweaks::ITweakAutoMapper { float x98_alphaSurfaceUnvisited; float x9c_miniAlphaOutlineUnvisited; float xa0_alphaOutlineUnvisited; - /* Originally 4 separate floats */ - zeus::CVector3f xa4_doorCenter; + float xa4_doorCenterA; + float xa8_doorCenterB; + float xac_doorCenterC; float xb0_; float xb4_; float xb8_miniMapViewportWidth; @@ -113,7 +114,6 @@ struct CTweakAutoMapper final : public Tweaks::ITweakAutoMapper { float GetAlphaSurfaceUnvisited() const override { return x98_alphaSurfaceUnvisited; } float GetMiniAlphaOutlineUnvisited() const override { return x9c_miniAlphaOutlineUnvisited; } float GetAlphaOutlineUnvisited() const override { return xa0_alphaOutlineUnvisited; } - const zeus::CVector3f& GetDoorCenter() const override { return xa4_doorCenter; } float GetMiniMapViewportWidth() const override { return xb8_miniMapViewportWidth; } float GetMiniMapViewportHeight() const override { return xbc_miniMapViewportHeight; } float GetMiniMapCamDistScale() const override { return xc0_miniMapCamDistScale; } diff --git a/Runtime/MP1/World/CIceAttackProjectile.cpp b/Runtime/MP1/World/CIceAttackProjectile.cpp index 68fa87c4a..5eb4a221c 100644 --- a/Runtime/MP1/World/CIceAttackProjectile.cpp +++ b/Runtime/MP1/World/CIceAttackProjectile.cpp @@ -52,7 +52,7 @@ void CIceAttackProjectile::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId o } void CIceAttackProjectile::AddToRenderer(const zeus::CFrustum& frustum, CStateManager& mgr) { - mgr.AddDrawableActor(*this, -1000.f * CGraphics::g_ViewMatrix.frontVector(), x9c_renderBounds); + mgr.AddDrawableActor(*this, -1000.f * CGraphics::mViewMatrix.frontVector(), x9c_renderBounds); } void CIceAttackProjectile::Render(CStateManager& mgr) {} diff --git a/Runtime/MP1/World/COmegaPirate.cpp b/Runtime/MP1/World/COmegaPirate.cpp index 9a1af15c7..8763a34d7 100644 --- a/Runtime/MP1/World/COmegaPirate.cpp +++ b/Runtime/MP1/World/COmegaPirate.cpp @@ -102,8 +102,8 @@ void COmegaPirate::CFlash::Render(CStateManager& mgr) { } float size = xfc_size * sizeMul; - const auto rightVec = size * CGraphics::g_ViewMatrix.rightVector(); - const auto upVec = size * CGraphics::g_ViewMatrix.upVector(); + const auto rightVec = size * CGraphics::mViewMatrix.rightVector(); + const auto upVec = size * CGraphics::mViewMatrix.upVector(); const auto rvS = GetTranslation() - rightVec; const auto rvP = GetTranslation() + rightVec; CGraphics::SetModelMatrix(zeus::CTransform()); @@ -111,7 +111,7 @@ void COmegaPirate::CFlash::Render(CStateManager& mgr) { CGraphics::SetTevOp(ERglTevStage::Stage1, CTevCombiners::kEnvPassthru); CGraphics::SetDepthWriteMode(false, ERglEnum::Always, false); CGraphics::StreamColor(zeus::CColor{1.f, std::min(1.f, size)}); - CGraphics::StreamBegin(GX_TRIANGLEFAN); + CGraphics::StreamBegin(ERglPrimitive::TriangleFan); CGraphics::StreamTexcoord(0.f, 0.f); CGraphics::StreamVertex(rvS + upVec); CGraphics::StreamTexcoord(1.f, 0.f); @@ -648,7 +648,7 @@ void COmegaPirate::Render(CStateManager& mgr) { if (mgr.GetPlayerState()->GetCurrentVisor() != CPlayerState::EPlayerVisor::XRay && xa2c_skeletonAlpha > 0.f) { const CModelFlags flags{5, 0, 3, zeus::CColor{1.f, xa2c_skeletonAlpha}}; - animData->Render(x9f0_skeletonModel, flags, nullptr, nullptr); + animData->Render(x9f0_skeletonModel, flags, nullptr, {}); } if (x9a0_visible) { bool isXRay = mgr.GetPlayerState()->GetActiveVisor(mgr) == CPlayerState::EPlayerVisor::XRay; @@ -656,7 +656,7 @@ void COmegaPirate::Render(CStateManager& mgr) { g_Renderer->SetWorldFog(ERglFogMode::None, 0.f, 1.f, zeus::skBlack); const CModelFlags flags{5, 0, 1, zeus::CColor{1.f, 0.2f}}; auto& model = *animData->GetModelData().GetObj(); - animData->Render(model, flags, nullptr, nullptr); + animData->Render(model, flags, nullptr, {}); } CPatterned::Render(mgr); if (isXRay) { diff --git a/Runtime/MP1/World/CThardus.cpp b/Runtime/MP1/World/CThardus.cpp index 9c8e97a11..5ae3fcdef 100644 --- a/Runtime/MP1/World/CThardus.cpp +++ b/Runtime/MP1/World/CThardus.cpp @@ -1390,16 +1390,16 @@ void CThardus::RenderFlare(const CStateManager& mgr, float t) { x91c_flareTexture->Load(GX_TEXMAP0, EClampMode::Repeat); const float scale = 30.f * t; - zeus::CVector3f offset = scale * CGraphics::g_ViewMatrix.basis[2]; - zeus::CVector3f max = x92c_currentRockPos + (scale * CGraphics::g_ViewMatrix.basis[0]); - zeus::CVector3f min = x92c_currentRockPos - (scale * CGraphics::g_ViewMatrix.basis[0]); + zeus::CVector3f offset = scale * CGraphics::mViewMatrix.basis[2]; + zeus::CVector3f max = x92c_currentRockPos + (scale * CGraphics::mViewMatrix.basis[0]); + zeus::CVector3f min = x92c_currentRockPos - (scale * CGraphics::mViewMatrix.basis[0]); CGraphics::SetModelMatrix({}); CGraphics::SetBlendMode(ERglBlendMode::Blend, ERglBlendFactor::One, ERglBlendFactor::One, ERglLogicOp::Clear); CGraphics::SetTevOp(ERglTevStage::Stage0, CTevCombiners::kEnvModulate); CGraphics::SetTevOp(ERglTevStage::Stage1, CTevCombiners::kEnvPassthru); CGraphics::SetDepthWriteMode(false, ERglEnum::Always, false); CGraphics::StreamColor({t, t}); - CGraphics::StreamBegin(GX_TRIANGLEFAN); + CGraphics::StreamBegin(ERglPrimitive::TriangleFan); CGraphics::StreamTexcoord(0.f, 0.f); CGraphics::StreamVertex(min + offset); CGraphics::StreamTexcoord(1.f, 0.f); diff --git a/Runtime/Particle/CDecal.cpp b/Runtime/Particle/CDecal.cpp index 2f3c65632..803145acf 100644 --- a/Runtime/Particle/CDecal.cpp +++ b/Runtime/Particle/CDecal.cpp @@ -1,7 +1,6 @@ #include "Runtime/Particle/CDecal.hpp" #include "Runtime/Graphics/CModel.hpp" -#include "Runtime/Graphics/Shaders/CDecalShaders.hpp" #include "Runtime/Particle/CParticleGlobals.hpp" #include "Runtime/Graphics/CGX.hpp" diff --git a/Runtime/Particle/CDecalManager.cpp b/Runtime/Particle/CDecalManager.cpp index 94991b3f9..a505a7038 100644 --- a/Runtime/Particle/CDecalManager.cpp +++ b/Runtime/Particle/CDecalManager.cpp @@ -3,7 +3,6 @@ #include "Runtime/CStateManager.hpp" #include "Runtime/GameGlobalObjects.hpp" #include "Runtime/Graphics/CCubeRenderer.hpp" -#include "Runtime/Graphics/Shaders/CDecalShaders.hpp" #include "Runtime/Particle/CDecal.hpp" #include "Runtime/Particle/CDecalDescription.hpp" @@ -30,9 +29,6 @@ void CDecalManager::Initialize() { m_DeltaTimeSinceLastDecalCreation = 0.f; m_LastDecalCreatedIndex = -1; m_LastDecalCreatedAssetId = {}; - - /* Compile shaders */ - CDecalShaders::Initialize(); } void CDecalManager::Reinitialize() { @@ -52,7 +48,6 @@ void CDecalManager::Reinitialize() { void CDecalManager::Shutdown() { m_ActiveIndexList.clear(); m_DecalPool.clear(); - 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 bf773bf3f..428294040 100644 --- a/Runtime/Particle/CElementGen.cpp +++ b/Runtime/Particle/CElementGen.cpp @@ -5,7 +5,6 @@ #include "Runtime/Graphics/CCubeRenderer.hpp" #include "Runtime/Graphics/CGX.hpp" #include "Runtime/Graphics/CModel.hpp" -#include "Runtime/Graphics/Shaders/CElementGenShaders.hpp" #include "Runtime/Particle/CElectricDescription.hpp" #include "Runtime/Particle/CGenDescription.hpp" #include "Runtime/Particle/CParticleGlobals.hpp" @@ -19,14 +18,6 @@ #define MAX_GLOBAL_PARTICLES 2560 namespace metaforce { -namespace { -// constexpr std::array ShadClsSizes{ -// sizeof(SParticleInstanceTex), -// sizeof(SParticleInstanceIndTex), -// sizeof(SParticleInstanceNoTex), -// }; -} // Anonymous namespace - u16 CElementGen::g_GlobalSeed = 99; bool CElementGen::g_subtractBlend = false; @@ -36,10 +27,6 @@ bool CElementGen::g_ParticleSystemInitialized = false; bool CElementGen::sMoveRedToAlphaBuffer = false; CParticle* CElementGen::g_currentParticle = nullptr; -// std::vector g_instTexData; -// std::vector g_instIndTexData; -// std::vector g_instNoTexData; - void CElementGen::Initialize() { if (g_ParticleSystemInitialized) return; @@ -47,12 +34,9 @@ void CElementGen::Initialize() { g_ParticleAliveCount = 0; g_ParticleSystemAliveCount = 0; g_ParticleSystemInitialized = true; - - /* Compile shaders */ - CElementGenShaders::Initialize(); } -void CElementGen::Shutdown() { CElementGenShaders::Shutdown(); } +void CElementGen::Shutdown() { g_ParticleSystemInitialized = false; } CElementGen::CElementGen(TToken gen, EModelOrientationType orientType, EOptionalSystemFlags flags) : x1c_genDesc(std::move(gen)) @@ -218,7 +202,7 @@ CElementGen::CElementGen(TToken gen, EModelOrientationType orie // m_lineRenderer.reset( // new CLineRenderer(CLineRenderer::EPrimitiveMode::Lines, maxVerts * 2, tex, x26c_26_AAPH, x26c_28_zTest)); } else { - m_shaderClass = CElementGenShaders::GetShaderClass(*this); + // m_shaderClass = CElementGenShaders::GetShaderClass(*this); } _RecreatePipelines(); @@ -842,7 +826,7 @@ void CElementGen::Render() { CGenDescription* desc = x1c_genDesc.GetObj(); - x274_backupLightActive = CGraphics::g_LightActive; + x274_backupLightActive = CGraphics::mLightActive; CGraphics::DisableAllLights(); for (std::unique_ptr& child : x290_activePartChildren) @@ -1050,7 +1034,7 @@ void CElementGen::RenderModels() { GXTexCoord2f32(uvs.xMax, uvs.yMin); CGX::End(); } else { - CGraphics::StreamBegin(GX_QUADS); + CGraphics::StreamBegin(ERglPrimitive::Quads); CGraphics::StreamColor(col); CGraphics::StreamTexcoord(uvs.xMax, uvs.yMax); CGraphics::StreamVertex(0.5f, 0.f, 0.5f); @@ -1097,7 +1081,7 @@ void CElementGen::RenderLines() { CGenDescription* desc = x1c_genDesc.GetObj(); CGlobalRandom gr(x27c_randState); - zeus::CTransform systemViewPointMatrix(CGraphics::g_ViewMatrix); + zeus::CTransform systemViewPointMatrix(CGraphics::mViewMatrix); systemViewPointMatrix.origin.zeroOut(); zeus::CTransform systemCameraMatrix = systemViewPointMatrix.inverse() * x22c_globalOrientation; systemViewPointMatrix = @@ -1216,7 +1200,7 @@ void CElementGen::RenderParticles() { bool hasModuColor = x338_moduColor != zeus::skWhite; CGraphics::SetCullMode(ERglCullMode::None); - zeus::CTransform systemModelMatrix(CGraphics::g_ViewMatrix); + zeus::CTransform systemModelMatrix(CGraphics::mViewMatrix); systemModelMatrix.origin.zeroOut(); zeus::CTransform systemCameraMatrix = systemModelMatrix.inverse() * x22c_globalOrientation; systemModelMatrix = @@ -1330,7 +1314,7 @@ void CElementGen::RenderParticles() { GXSetVtxAttrFmt(GX_VTXFMT6, GX_VA_POS, GX_POS_XYZ, GX_F32, 0); GXSetVtxAttrFmt(GX_VTXFMT6, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0); if (constUVs) { - GXSetVtxAttrFmt(GX_VTXFMT6, GX_VA_TEX0, GX_TEX_ST, GX_RGBA8, 1); + GXSetVtxAttrFmt(GX_VTXFMT6, GX_VA_TEX0, GX_TEX_ST, GX_S8, 1); } else { GXSetVtxAttrFmt(GX_VTXFMT6, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0); } @@ -1393,37 +1377,65 @@ void CElementGen::RenderParticles() { CParticleGlobals::instance()->SetParticleLifetime(particle.x0_endFrame - particle.x28_startFrame); CParticleGlobals::instance()->UpdateParticleLifetimeTweenValues(partFrame); texr->GetValueUV(partFrame, uvs); - } - - if (noRota) { + if (noRota) { + GXPosition3f32(viewPoint.x() + size, viewPoint.y(), viewPoint.z() + size); + GXColor4f32(particle.x34_color); + GXTexCoord2f32(uvs.xMax, uvs.yMax); + GXPosition3f32(viewPoint.x() - size, viewPoint.y(), viewPoint.z() + size); + GXColor4f32(particle.x34_color); + GXTexCoord2f32(uvs.xMin, uvs.yMax); + GXPosition3f32(viewPoint.x() - size, viewPoint.y(), viewPoint.z() - size); + GXColor4f32(particle.x34_color); + GXTexCoord2f32(uvs.xMin, uvs.yMin); + GXPosition3f32(viewPoint.x() + size, viewPoint.y(), viewPoint.z() - size); + GXColor4f32(particle.x34_color); + GXTexCoord2f32(uvs.xMax, uvs.yMin); + } else { + const float theta = zeus::degToRad(particle.x30_lineWidthOrRota); + const float sinT = std::sin(theta) * size; + const float cosT = std::cos(theta) * size; + GXPosition3f32(viewPoint.x() + (sinT + cosT), viewPoint.y(), viewPoint.z() + (cosT - sinT)); + GXColor4f32(particle.x34_color); + GXTexCoord2f32(uvs.xMax, uvs.yMax); + GXPosition3f32(viewPoint.x() + (sinT - cosT), viewPoint.y(), viewPoint.z() + (sinT + cosT)); + GXColor4f32(particle.x34_color); + GXTexCoord2f32(uvs.xMin, uvs.yMax); + GXPosition3f32(viewPoint.x() - (sinT + cosT), viewPoint.y(), viewPoint.z() - (cosT - sinT)); + GXColor4f32(particle.x34_color); + GXTexCoord2f32(uvs.xMin, uvs.yMin); + GXPosition3f32(viewPoint.x() + (-sinT + cosT), viewPoint.y(), viewPoint.z() + (-cosT - sinT)); + GXColor4f32(particle.x34_color); + GXTexCoord2f32(uvs.xMax, uvs.yMin); + } + } else if (noRota) { GXPosition3f32(viewPoint.x() + size, viewPoint.y(), viewPoint.z() + size); GXColor4f32(particle.x34_color); - GXTexCoord2f32(uvs.xMax, uvs.yMax); + GXTexCoord2s8(2, 2); GXPosition3f32(viewPoint.x() - size, viewPoint.y(), viewPoint.z() + size); GXColor4f32(particle.x34_color); - GXTexCoord2f32(uvs.xMin, uvs.yMax); + GXTexCoord2s8(0, 2); GXPosition3f32(viewPoint.x() - size, viewPoint.y(), viewPoint.z() - size); GXColor4f32(particle.x34_color); - GXTexCoord2f32(uvs.xMin, uvs.yMin); + GXTexCoord2s8(0, 0); GXPosition3f32(viewPoint.x() + size, viewPoint.y(), viewPoint.z() - size); GXColor4f32(particle.x34_color); - GXTexCoord2f32(uvs.xMax, uvs.yMin); + GXTexCoord2s8(2, 0); } else { const float theta = zeus::degToRad(particle.x30_lineWidthOrRota); const float sinT = std::sin(theta) * size; const float cosT = std::cos(theta) * size; GXPosition3f32(viewPoint.x() + (sinT + cosT), viewPoint.y(), viewPoint.z() + (cosT - sinT)); GXColor4f32(particle.x34_color); - GXTexCoord2f32(uvs.xMax, uvs.yMax); + GXTexCoord2s8(2, 2); GXPosition3f32(viewPoint.x() + (sinT - cosT), viewPoint.y(), viewPoint.z() + (sinT + cosT)); GXColor4f32(particle.x34_color); - GXTexCoord2f32(uvs.xMin, uvs.yMax); + GXTexCoord2s8(0, 2); GXPosition3f32(viewPoint.x() - (sinT + cosT), viewPoint.y(), viewPoint.z() - (cosT - sinT)); GXColor4f32(particle.x34_color); - GXTexCoord2f32(uvs.xMin, uvs.yMin); + GXTexCoord2s8(0, 0); GXPosition3f32(viewPoint.x() + (-sinT + cosT), viewPoint.y(), viewPoint.z() + (-cosT - sinT)); GXColor4f32(particle.x34_color); - GXTexCoord2f32(uvs.xMax, uvs.yMin); + GXTexCoord2s8(2, 0); } } } else { @@ -1450,17 +1462,17 @@ void CElementGen::RenderParticles() { zeus::CVector3f foreVec = particle.x2c_lineLengthOrSize * dir; zeus::CVector3f rightVec; if (desc->x30_31_RSOP) { - rightVec = dir.cross(CGraphics::g_ViewMatrix.basis[1]); + rightVec = dir.cross(CGraphics::mViewMatrix.basis[1]); if (rightVec.canBeNormalized()) { rightVec = rightVec.normalized() * (particle.x2c_lineLengthOrSize * width); } else { - rightVec = dir.cross((CGraphics::g_ViewMatrix.origin - particle.x4_pos).normalized()); + rightVec = dir.cross((CGraphics::mViewMatrix.origin - particle.x4_pos).normalized()); if (rightVec.canBeNormalized()) { rightVec = rightVec.normalized() * (particle.x2c_lineLengthOrSize * width); } } } else { - rightVec = foreVec.cross(CGraphics::g_ViewMatrix.basis[1]) * width; + rightVec = foreVec.cross(CGraphics::mViewMatrix.basis[1]) * width; } if (!constUVs) { @@ -1502,18 +1514,18 @@ void CElementGen::RenderParticles() { } } - switch (m_shaderClass) { - case CElementGenShaders::EShaderClass::Tex: - // m_instBuf->load(g_instTexData.data(), g_instTexData.size() * sizeof(SParticleInstanceTex)); - // CGraphics::DrawInstances(0, 4, g_instTexData.size()); - break; - case CElementGenShaders::EShaderClass::NoTex: - // m_instBuf->load(g_instNoTexData.data(), g_instNoTexData.size() * sizeof(SParticleInstanceNoTex)); - // CGraphics::DrawInstances(0, 4, g_instNoTexData.size()); - break; - default: - break; - } + // switch (m_shaderClass) { + // case CElementGenShaders::EShaderClass::Tex: + // m_instBuf->load(g_instTexData.data(), g_instTexData.size() * sizeof(SParticleInstanceTex)); + // CGraphics::DrawInstances(0, 4, g_instTexData.size()); + // break; + // case CElementGenShaders::EShaderClass::NoTex: + // m_instBuf->load(g_instNoTexData.data(), g_instNoTexData.size() * sizeof(SParticleInstanceNoTex)); + // CGraphics::DrawInstances(0, 4, g_instNoTexData.size()); + // break; + // default: + // break; + // } } else { // switch (m_shaderClass) { // case CElementGenShaders::EShaderClass::Tex: @@ -1616,18 +1628,18 @@ void CElementGen::RenderParticles() { } } } - switch (m_shaderClass) { - case CElementGenShaders::EShaderClass::Tex: - // m_instBuf->load(g_instTexData.data(), g_instTexData.size() * sizeof(SParticleInstanceTex)); - // CGraphics::DrawInstances(0, 4, g_instTexData.size()); - break; - case CElementGenShaders::EShaderClass::NoTex: - // m_instBuf->load(g_instNoTexData.data(), g_instNoTexData.size() * sizeof(SParticleInstanceNoTex)); - // CGraphics::DrawInstances(0, 4, g_instNoTexData.size()); - break; - default: - break; - } + // switch (m_shaderClass) { + // case CElementGenShaders::EShaderClass::Tex: + // // m_instBuf->load(g_instTexData.data(), g_instTexData.size() * sizeof(SParticleInstanceTex)); + // // CGraphics::DrawInstances(0, 4, g_instTexData.size()); + // break; + // case CElementGenShaders::EShaderClass::NoTex: + // // m_instBuf->load(g_instNoTexData.data(), g_instNoTexData.size() * sizeof(SParticleInstanceNoTex)); + // // CGraphics::DrawInstances(0, 4, g_instNoTexData.size()); + // break; + // default: + // break; + // } } CGX::End(); @@ -1643,7 +1655,7 @@ void CElementGen::RenderParticlesIndirectTexture() { CGenDescription* desc = x1c_genDesc.GetObj(); - zeus::CTransform systemViewPointMatrix(CGraphics::g_ViewMatrix); + zeus::CTransform systemViewPointMatrix(CGraphics::mViewMatrix); systemViewPointMatrix.origin.zeroOut(); zeus::CTransform systemCameraMatrix = systemViewPointMatrix.inverse() * x22c_globalOrientation; systemViewPointMatrix = @@ -1749,9 +1761,9 @@ void CElementGen::RenderParticlesIndirectTexture() { float size = 0.5f * particle.x2c_lineLengthOrSize; zeus::CVector3f p1 = {viewPoint.x() - size, viewPoint.y(), viewPoint.z() - size}; zeus::CVector3f p2 = {viewPoint.x() + size, viewPoint.y(), viewPoint.z() + size}; - SClipScreenRect clipRect = CGraphics::ClipScreenRectFromMS(p1, p2); + CGraphics::CClippedScreenRect clipRect = CGraphics::ClipScreenRectFromMS(p1, p2, ETexelFormat::RGB565); - if (!clipRect.x0_valid) + if (!clipRect.IsValid()) continue; // CGraphics::ResolveSpareTexture(clipRect); @@ -1953,16 +1965,16 @@ void CElementGen::RenderBasicParticlesNoRotNoTS(const zeus::CTransform& xf) noex const auto size = 0.5f * particle.x2c_lineLengthOrSize; GXPosition3f32(pos.x() + size, pos.y(), pos.z() + size); GXColor4f32(particle.x34_color); - GXTexCoord2f32(1.f, 1.f); + GXTexCoord2s8(2, 2); GXPosition3f32(pos.x() - size, pos.y(), pos.z() + size); GXColor4f32(particle.x34_color); - GXTexCoord2f32(0.f, 1.f); + GXTexCoord2s8(0, 2); GXPosition3f32(pos.x() - size, pos.y(), pos.z() - size); GXColor4f32(particle.x34_color); - GXTexCoord2f32(0.f, 0.f); + GXTexCoord2s8(0, 0); GXPosition3f32(pos.x() + size, pos.y(), pos.z() - size); GXColor4f32(particle.x34_color); - GXTexCoord2f32(1.f, 0.f); + GXTexCoord2s8(2, 0); } } @@ -1972,16 +1984,16 @@ void CElementGen::RenderBasicParticlesNoRotTS(const zeus::CTransform& xf) noexce const auto size = 0.5f * particle.x2c_lineLengthOrSize; GXPosition3f32(pos.x() + size, pos.y(), pos.z() + size); GXColor4f32(particle.x34_color); - GXTexCoord2f32(1.f, 1.f); + GXTexCoord2s8(2, 2); GXPosition3f32(pos.x() - size, pos.y(), pos.z() + size); GXColor4f32(particle.x34_color); - GXTexCoord2f32(0.f, 1.f); + GXTexCoord2s8(0, 2); GXPosition3f32(pos.x() - size, pos.y(), pos.z() - size); GXColor4f32(particle.x34_color); - GXTexCoord2f32(0.f, 0.f); + GXTexCoord2s8(0, 0); GXPosition3f32(pos.x() + size, pos.y(), pos.z() - size); GXColor4f32(particle.x34_color); - GXTexCoord2f32(1.f, 0.f); + GXTexCoord2s8(2, 0); } } @@ -1994,16 +2006,16 @@ void CElementGen::RenderBasicParticlesRotNoTS(const zeus::CTransform& xf) noexce const float cosT = std::cos(theta) * size; GXPosition3f32(pos.x() + (sinT + cosT), pos.y(), pos.z() + (cosT - sinT)); GXColor4f32(particle.x34_color); - GXTexCoord2f32(1.f, 1.f); + GXTexCoord2s8(2, 2); GXPosition3f32(pos.x() + (sinT - cosT), pos.y(), pos.z() + (sinT + cosT)); GXColor4f32(particle.x34_color); - GXTexCoord2f32(0.f, 1.f); + GXTexCoord2s8(0, 2); GXPosition3f32(pos.x() - (sinT + cosT), pos.y(), pos.z() - (cosT - sinT)); GXColor4f32(particle.x34_color); - GXTexCoord2f32(0.f, 0.f); + GXTexCoord2s8(0, 0); GXPosition3f32(pos.x() + (-sinT + cosT), pos.y(), pos.z() + (-cosT - sinT)); GXColor4f32(particle.x34_color); - GXTexCoord2f32(1.f, 0.f); + GXTexCoord2s8(2, 0); } } @@ -2016,16 +2028,16 @@ void CElementGen::RenderBasicParticlesRotTS(const zeus::CTransform& xf) noexcept const float cosT = std::cos(theta) * size; GXPosition3f32(pos.x() + (sinT + cosT), pos.y(), pos.z() + (cosT - sinT)); GXColor4f32(particle.x34_color); - GXTexCoord2f32(1.f, 1.f); + GXTexCoord2s8(2, 2); GXPosition3f32(pos.x() + (sinT - cosT), pos.y(), pos.z() + (sinT + cosT)); GXColor4f32(particle.x34_color); - GXTexCoord2f32(0.f, 1.f); + GXTexCoord2s8(0, 2); GXPosition3f32(pos.x() - (sinT + cosT), pos.y(), pos.z() - (cosT - sinT)); GXColor4f32(particle.x34_color); - GXTexCoord2f32(0.f, 0.f); + GXTexCoord2s8(0, 0); GXPosition3f32(pos.x() + (-sinT + cosT), pos.y(), pos.z() + (-cosT - sinT)); GXColor4f32(particle.x34_color); - GXTexCoord2f32(1.f, 0.f); + GXTexCoord2s8(2, 0); } } } // namespace metaforce diff --git a/Runtime/Particle/CElementGen.hpp b/Runtime/Particle/CElementGen.hpp index 3897e851c..aeddc2158 100644 --- a/Runtime/Particle/CElementGen.hpp +++ b/Runtime/Particle/CElementGen.hpp @@ -8,8 +8,6 @@ #include "Runtime/RetroTypes.hpp" #include "Runtime/Graphics/CGraphics.hpp" #include "Runtime/Graphics/CLight.hpp" -#include "Runtime/Graphics/CLineRenderer.hpp" -#include "Runtime/Graphics/Shaders/CElementGenShaders.hpp" #include "Runtime/Particle/CGenDescription.hpp" #include "Runtime/Particle/CParticleGen.hpp" @@ -129,9 +127,6 @@ private: float x334_LSLA = 45.f; zeus::CColor x338_moduColor = {1.f, 1.f, 1.f, 1.f}; - std::unique_ptr m_lineRenderer; - CElementGenShaders::EShaderClass m_shaderClass; - void AccumulateBounds(const zeus::CVector3f& pos, float size); void _RecreatePipelines(); @@ -141,18 +136,6 @@ public: EOptionalSystemFlags flags = EOptionalSystemFlags::One); ~CElementGen() override; -// std::array, 2> m_normalDataBind; -// std::array, 2> m_normalSubDataBind; -// std::array, 2> m_redToAlphaDataBind; -// std::array, 2> m_redToAlphaSubDataBind; -// boo::ObjToken m_instBuf; -// boo::ObjToken m_uniformBuf; -// -// std::array, 2> m_normalDataBindPmus; -// std::array, 2> m_redToAlphaDataBindPmus; -// boo::ObjToken m_instBufPmus; -// boo::ObjToken m_uniformBufPmus; - CGenDescription* GetDesc() { return x1c_genDesc.GetObj(); } const SObjectTag* GetDescTag() const { return x1c_genDesc.GetObjectTag(); } CGenDescription* GetLoadedDesc() { return x28_loadedGenDesc; } diff --git a/Runtime/Particle/CParticleElectric.cpp b/Runtime/Particle/CParticleElectric.cpp index b7a9a95c6..be5875417 100644 --- a/Runtime/Particle/CParticleElectric.cpp +++ b/Runtime/Particle/CParticleElectric.cpp @@ -113,7 +113,7 @@ void CParticleElectric::DrawLineStrip(const std::vector& verts, } void CParticleElectric::RenderLines() { - m_nextLineRenderer = 0; + // m_nextLineRenderer = 0; CGraphics::DisableAllLights(); // Z-test, no write // Additive blend diff --git a/Runtime/Particle/CParticleElectric.hpp b/Runtime/Particle/CParticleElectric.hpp index bca07fa1d..12670b47f 100644 --- a/Runtime/Particle/CParticleElectric.hpp +++ b/Runtime/Particle/CParticleElectric.hpp @@ -9,7 +9,6 @@ #include "Runtime/CRandom16.hpp" #include "Runtime/CToken.hpp" #include "Runtime/rstl.hpp" -#include "Runtime/Graphics/CLineRenderer.hpp" #include "Runtime/Particle/CElementGen.hpp" #include "Runtime/Particle/CParticleGen.hpp" #include "Runtime/Particle/CParticleSwoosh.hpp" @@ -92,9 +91,6 @@ private: bool x450_28_haveLWD : 1 = false; bool x450_29_transformDirty : 1 = true; - size_t m_nextLineRenderer = 0; - std::vector> m_lineRenderers; - void SetupLineGXMaterial(); void DrawLineStrip(const std::vector& verts, float width, const zeus::CColor& color); void RenderLines(); diff --git a/Runtime/Particle/CParticleSwoosh.cpp b/Runtime/Particle/CParticleSwoosh.cpp index 0630f7a5e..0c9d399b7 100644 --- a/Runtime/Particle/CParticleSwoosh.cpp +++ b/Runtime/Particle/CParticleSwoosh.cpp @@ -67,11 +67,11 @@ CParticleSwoosh::CParticleSwoosh(const TToken& desc, int len if (x1c_desc->x44_29_WIRE) { const int maxVerts = x1b4_LENG * (x1b0_SPLN + 1) * x1b8_SIDE * 12; - m_lineRenderer.reset( - new CLineRenderer(CLineRenderer::EPrimitiveMode::Lines, maxVerts * 2, {}, x1d0_25_AALP)); + // m_lineRenderer.reset( + // new CLineRenderer(CLineRenderer::EPrimitiveMode::Lines, maxVerts * 2, {}, x1d0_25_AALP)); } else { const auto maxVerts = size_t(x1b4_LENG * (x1b0_SPLN + 1) * x1b8_SIDE * 4); - m_cachedVerts.reserve(maxVerts); + // m_cachedVerts.reserve(maxVerts); // CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { // m_vertBuf = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(CParticleSwooshShaders::Vert), maxVerts); // m_uniformBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(zeus::CMatrix4f), 1); @@ -308,7 +308,7 @@ int CParticleSwoosh::WrapIndex(int i) const { void CParticleSwoosh::RenderNSidedSpline() { if (x1c_desc->x44_29_WIRE) { x1bc_prim = GX_LINES; - m_lineRenderer->Reset(); + // m_lineRenderer->Reset(); } else { x1bc_prim = GX_QUADS; } @@ -434,10 +434,10 @@ void CParticleSwoosh::RenderNSidedSpline() { const auto v2 = GetSplinePoint(x16c_p0[otherK], x17c_p1[otherK], x18c_p2[otherK], x19c_p3[otherK], t1); const auto v3 = GetSplinePoint(x16c_p0[k], x17c_p1[k], x18c_p2[k], x19c_p3[k], t1); - m_cachedVerts.push_back({v0, {x1d4_uvs.xMin, x1d4_uvs.yMin}, color}); - m_cachedVerts.push_back({v1, {x1d4_uvs.xMin, x1d4_uvs.yMax}, color}); - m_cachedVerts.push_back({v2, {x1d4_uvs.xMax, x1d4_uvs.yMin}, color}); - m_cachedVerts.push_back({v3, {x1d4_uvs.xMax, x1d4_uvs.yMax}, color}); + // m_cachedVerts.push_back({v0, {x1d4_uvs.xMin, x1d4_uvs.yMin}, color}); + // m_cachedVerts.push_back({v1, {x1d4_uvs.xMin, x1d4_uvs.yMax}, color}); + // m_cachedVerts.push_back({v2, {x1d4_uvs.xMax, x1d4_uvs.yMin}, color}); + // m_cachedVerts.push_back({v3, {x1d4_uvs.xMax, x1d4_uvs.yMax}, color}); // CGraphics::DrawArray(m_cachedVerts.size() - 4, 4); } else { const auto v0 = GetSplinePoint(x16c_p0[k], x17c_p1[k], x18c_p2[k], x19c_p3[k], t0); @@ -446,23 +446,23 @@ void CParticleSwoosh::RenderNSidedSpline() { const auto v3 = GetSplinePoint(x16c_p0[k], x17c_p1[k], x18c_p2[k], x19c_p3[k], t1); if (x1bc_prim == GX_LINES) { - m_lineRenderer->AddVertex(v0, color, 1.f); - m_lineRenderer->AddVertex(v1, color, 1.f); - m_lineRenderer->AddVertex(v1, color, 1.f); - m_lineRenderer->AddVertex(v2, color, 1.f); - m_lineRenderer->AddVertex(v2, color, 1.f); - m_lineRenderer->AddVertex(v0, color, 1.f); - m_lineRenderer->AddVertex(v0, color, 1.f); - m_lineRenderer->AddVertex(v2, color, 1.f); - m_lineRenderer->AddVertex(v2, color, 1.f); - m_lineRenderer->AddVertex(v3, color, 1.f); - m_lineRenderer->AddVertex(v3, color, 1.f); - m_lineRenderer->AddVertex(v0, color, 1.f); + // m_lineRenderer->AddVertex(v0, color, 1.f); + // m_lineRenderer->AddVertex(v1, color, 1.f); + // m_lineRenderer->AddVertex(v1, color, 1.f); + // m_lineRenderer->AddVertex(v2, color, 1.f); + // m_lineRenderer->AddVertex(v2, color, 1.f); + // m_lineRenderer->AddVertex(v0, color, 1.f); + // m_lineRenderer->AddVertex(v0, color, 1.f); + // m_lineRenderer->AddVertex(v2, color, 1.f); + // m_lineRenderer->AddVertex(v2, color, 1.f); + // m_lineRenderer->AddVertex(v3, color, 1.f); + // m_lineRenderer->AddVertex(v3, color, 1.f); + // m_lineRenderer->AddVertex(v0, color, 1.f); } else if (x1bc_prim == GX_QUADS) { - m_cachedVerts.push_back({v0, {x1d4_uvs.xMin, x1d4_uvs.yMin}, color}); - m_cachedVerts.push_back({v1, {x1d4_uvs.xMin, x1d4_uvs.yMax}, color}); - m_cachedVerts.push_back({v2, {x1d4_uvs.xMax, x1d4_uvs.yMin}, color}); - m_cachedVerts.push_back({v3, {x1d4_uvs.xMax, x1d4_uvs.yMax}, color}); + // m_cachedVerts.push_back({v0, {x1d4_uvs.xMin, x1d4_uvs.yMin}, color}); + // m_cachedVerts.push_back({v1, {x1d4_uvs.xMin, x1d4_uvs.yMax}, color}); + // m_cachedVerts.push_back({v2, {x1d4_uvs.xMax, x1d4_uvs.yMin}, color}); + // m_cachedVerts.push_back({v3, {x1d4_uvs.xMax, x1d4_uvs.yMax}, color}); // CGraphics::DrawArray(m_cachedVerts.size() - 4, 4); } } @@ -590,22 +590,22 @@ void CParticleSwoosh::Render3SidedSolidSpline() { c1 = zeus::CColor::lerp(useColor0, useColor1, t1); uv1 = t1 * uvDelta + curUvSpan; - m_cachedVerts.push_back({v00, {uv0, x1d4_uvs.yMin}, c0}); - m_cachedVerts.push_back({v10, {uv0, x1d4_uvs.yMax}, c0}); - m_cachedVerts.push_back({v01, {uv1, x1d4_uvs.yMin}, c1}); - m_cachedVerts.push_back({v11, {uv1, x1d4_uvs.yMax}, c1}); + // m_cachedVerts.push_back({v00, {uv0, x1d4_uvs.yMin}, c0}); + // m_cachedVerts.push_back({v10, {uv0, x1d4_uvs.yMax}, c0}); + // m_cachedVerts.push_back({v01, {uv1, x1d4_uvs.yMin}, c1}); + // m_cachedVerts.push_back({v11, {uv1, x1d4_uvs.yMax}, c1}); // CGraphics::DrawArray(m_cachedVerts.size() - 4, 4); - m_cachedVerts.push_back({v10, {uv0, x1d4_uvs.yMin}, c0}); - m_cachedVerts.push_back({v20, {uv0, x1d4_uvs.yMax}, c0}); - m_cachedVerts.push_back({v11, {uv1, x1d4_uvs.yMin}, c1}); - m_cachedVerts.push_back({v21, {uv1, x1d4_uvs.yMax}, c1}); + // m_cachedVerts.push_back({v10, {uv0, x1d4_uvs.yMin}, c0}); + // m_cachedVerts.push_back({v20, {uv0, x1d4_uvs.yMax}, c0}); + // m_cachedVerts.push_back({v11, {uv1, x1d4_uvs.yMin}, c1}); + // m_cachedVerts.push_back({v21, {uv1, x1d4_uvs.yMax}, c1}); // CGraphics::DrawArray(m_cachedVerts.size() - 4, 4); - m_cachedVerts.push_back({v20, {uv0, x1d4_uvs.yMin}, c0}); - m_cachedVerts.push_back({v00, {uv0, x1d4_uvs.yMax}, c0}); - m_cachedVerts.push_back({v21, {uv1, x1d4_uvs.yMin}, c1}); - m_cachedVerts.push_back({v01, {uv1, x1d4_uvs.yMax}, c1}); + // m_cachedVerts.push_back({v20, {uv0, x1d4_uvs.yMin}, c0}); + // m_cachedVerts.push_back({v00, {uv0, x1d4_uvs.yMax}, c0}); + // m_cachedVerts.push_back({v21, {uv1, x1d4_uvs.yMin}, c1}); + // m_cachedVerts.push_back({v01, {uv1, x1d4_uvs.yMax}, c1}); // CGraphics::DrawArray(m_cachedVerts.size() - 4, 4); } } @@ -682,22 +682,22 @@ void CParticleSwoosh::Render3SidedSolidNoSplineNoGaps() { const float uv1 = uv0; uv0 += x1e8_uvSpan; - m_cachedVerts.push_back({p0[i & 1], {uv0, x1d4_uvs.yMin}, c0}); - m_cachedVerts.push_back({p1[i & 1], {uv0, x1d4_uvs.yMax}, c0}); - m_cachedVerts.push_back({p0[!(i & 1)], {uv1, x1d4_uvs.yMin}, c1}); - m_cachedVerts.push_back({p1[!(i & 1)], {uv1, x1d4_uvs.yMax}, c1}); + // m_cachedVerts.push_back({p0[i & 1], {uv0, x1d4_uvs.yMin}, c0}); + // m_cachedVerts.push_back({p1[i & 1], {uv0, x1d4_uvs.yMax}, c0}); + // m_cachedVerts.push_back({p0[!(i & 1)], {uv1, x1d4_uvs.yMin}, c1}); + // m_cachedVerts.push_back({p1[!(i & 1)], {uv1, x1d4_uvs.yMax}, c1}); // CGraphics::DrawArray(m_cachedVerts.size() - 4, 4); - m_cachedVerts.push_back({p1[i & 1], {uv0, x1d4_uvs.yMin}, c0}); - m_cachedVerts.push_back({p2[i & 1], {uv0, x1d4_uvs.yMax}, c0}); - m_cachedVerts.push_back({p1[!(i & 1)], {uv1, x1d4_uvs.yMin}, c1}); - m_cachedVerts.push_back({p2[!(i & 1)], {uv1, x1d4_uvs.yMax}, c1}); + // m_cachedVerts.push_back({p1[i & 1], {uv0, x1d4_uvs.yMin}, c0}); + // m_cachedVerts.push_back({p2[i & 1], {uv0, x1d4_uvs.yMax}, c0}); + // m_cachedVerts.push_back({p1[!(i & 1)], {uv1, x1d4_uvs.yMin}, c1}); + // m_cachedVerts.push_back({p2[!(i & 1)], {uv1, x1d4_uvs.yMax}, c1}); // CGraphics::DrawArray(m_cachedVerts.size() - 4, 4); - m_cachedVerts.push_back({p2[i & 1], {uv0, x1d4_uvs.yMin}, c0}); - m_cachedVerts.push_back({p0[i & 1], {uv0, x1d4_uvs.yMax}, c0}); - m_cachedVerts.push_back({p2[!(i & 1)], {uv1, x1d4_uvs.yMin}, c1}); - m_cachedVerts.push_back({p0[!(i & 1)], {uv1, x1d4_uvs.yMax}, c1}); + // m_cachedVerts.push_back({p2[i & 1], {uv0, x1d4_uvs.yMin}, c0}); + // m_cachedVerts.push_back({p0[i & 1], {uv0, x1d4_uvs.yMax}, c0}); + // m_cachedVerts.push_back({p2[!(i & 1)], {uv1, x1d4_uvs.yMin}, c1}); + // m_cachedVerts.push_back({p0[!(i & 1)], {uv1, x1d4_uvs.yMax}, c1}); // CGraphics::DrawArray(m_cachedVerts.size() - 4, 4); } } @@ -733,7 +733,7 @@ void CParticleSwoosh::Render2SidedNoSplineGaps() { continue; } streaming = true; - drawStart = m_cachedVerts.size(); + // drawStart = m_cachedVerts.size(); } float ang = zeus::degToRad(swoosh.x30_irot + swoosh.x34_rotm); @@ -759,10 +759,10 @@ void CParticleSwoosh::Render2SidedNoSplineGaps() { const zeus::CColor color = swoosh.x6c_color * x20c_moduColor; - m_cachedVerts.push_back({v0, {1.f, x1d4_uvs.yMin}, color}); - m_cachedVerts.push_back({v1, {1.f, x1d4_uvs.yMax}, color}); - m_cachedVerts.push_back({v0, {0.f, x1d4_uvs.yMin}, color}); - m_cachedVerts.push_back({v1, {0.f, x1d4_uvs.yMax}, color}); + // m_cachedVerts.push_back({v0, {1.f, x1d4_uvs.yMin}, color}); + // m_cachedVerts.push_back({v1, {1.f, x1d4_uvs.yMax}, color}); + // m_cachedVerts.push_back({v0, {0.f, x1d4_uvs.yMin}, color}); + // m_cachedVerts.push_back({v1, {0.f, x1d4_uvs.yMax}, color}); } // if (streaming) @@ -779,7 +779,7 @@ void CParticleSwoosh::Render2SidedNoSplineNoGaps() { if (x1c_desc->x45_25_ORNT) { const zeus::CVector3f camToParticle = ((zeus::CTransform::Translate(xa4_globalTranslation) * xb0_globalOrientation * xec_scaleXf).inverse() * - CGraphics::g_ViewMatrix) + CGraphics::mViewMatrix) .origin; zeus::CVector3f dotVec = zeus::skZero3f; @@ -816,14 +816,14 @@ void CParticleSwoosh::Render2SidedNoSplineNoGaps() { const zeus::CColor color = swoosh.x6c_color * x20c_moduColor; - m_cachedVerts.push_back({v0, {uvOffset, x1d4_uvs.yMin}, color}); - m_cachedVerts.push_back({v1, {uvOffset, x1d4_uvs.yMax}, color}); + // m_cachedVerts.push_back({v0, {uvOffset, x1d4_uvs.yMin}, color}); + // m_cachedVerts.push_back({v1, {uvOffset, x1d4_uvs.yMax}, color}); if (uvOffset >= 1.f && particleCount) { // CGraphics::DrawArray(drawStart, m_cachedVerts.size() - drawStart); - drawStart = m_cachedVerts.size(); + // drawStart = m_cachedVerts.size(); uvOffset -= 1.f; - m_cachedVerts.push_back({v0, {uvOffset, x1d4_uvs.yMin}, color}); - m_cachedVerts.push_back({v1, {uvOffset, x1d4_uvs.yMax}, color}); + // m_cachedVerts.push_back({v0, {uvOffset, x1d4_uvs.yMin}, color}); + // m_cachedVerts.push_back({v1, {uvOffset, x1d4_uvs.yMax}, color}); } if (x1ec_TSPN > 0) { @@ -870,14 +870,14 @@ void CParticleSwoosh::Render2SidedNoSplineNoGaps() { const zeus::CColor color = swoosh.x6c_color * x20c_moduColor; - m_cachedVerts.push_back({v0, {uvOffset, x1d4_uvs.yMin}, color}); - m_cachedVerts.push_back({v1, {uvOffset, x1d4_uvs.yMax}, color}); + // m_cachedVerts.push_back({v0, {uvOffset, x1d4_uvs.yMin}, color}); + // m_cachedVerts.push_back({v1, {uvOffset, x1d4_uvs.yMax}, color}); if (uvOffset >= 1.f && particleCount) { // CGraphics::DrawArray(drawStart, m_cachedVerts.size() - drawStart); - drawStart = m_cachedVerts.size(); + // drawStart = m_cachedVerts.size(); uvOffset -= 1.f; - m_cachedVerts.push_back({v0, {uvOffset, x1d4_uvs.yMin}, color}); - m_cachedVerts.push_back({v1, {uvOffset, x1d4_uvs.yMax}, color}); + // m_cachedVerts.push_back({v0, {uvOffset, x1d4_uvs.yMin}, color}); + // m_cachedVerts.push_back({v1, {uvOffset, x1d4_uvs.yMax}, color}); } if (x1ec_TSPN > 0) { @@ -920,8 +920,8 @@ void CParticleSwoosh::Render2SidedNoSplineNoGaps() { useOffset; const zeus::CColor color = swoosh.x6c_color * x20c_moduColor; - m_cachedVerts.push_back({v0, {}, color}); - m_cachedVerts.push_back({v1, {}, color}); + // m_cachedVerts.push_back({v0, {}, color}); + // m_cachedVerts.push_back({v1, {}, color}); } } } @@ -937,7 +937,7 @@ void CParticleSwoosh::Render() { SCOPED_GRAPHICS_DEBUG_GROUP(fmt::format("CParticleSwoosh::Render {}", *x1c_desc.GetObjectTag()).c_str(), zeus::skYellow); - m_cachedVerts.clear(); + // m_cachedVerts.clear(); // if (m_dataBind[0]) { // CGraphics::SetShaderDataBinding(m_dataBind[g_Renderer->IsThermalVisorHotPass()]); // } @@ -1007,7 +1007,7 @@ void CParticleSwoosh::Render() { } } - zeus::CMatrix4f mvp = CGraphics::GetPerspectiveProjectionMatrix(/*true*/) * CGraphics::g_GXModelView.toMatrix4f(); + // zeus::CMatrix4f mvp = CGraphics::GetPerspectiveProjectionMatrix(/*true*/) * CGraphics::g_GXModelView.toMatrix4f(); // m_uniformBuf->load(&mvp, sizeof(zeus::CMatrix4f)); // if (m_cachedVerts.size()) { // m_vertBuf->load(m_cachedVerts.data(), m_cachedVerts.size() * sizeof(CParticleSwooshShaders::Vert)); diff --git a/Runtime/Particle/CParticleSwoosh.hpp b/Runtime/Particle/CParticleSwoosh.hpp index 89fd56527..1365df0e9 100644 --- a/Runtime/Particle/CParticleSwoosh.hpp +++ b/Runtime/Particle/CParticleSwoosh.hpp @@ -6,9 +6,7 @@ #include "Runtime/CRandom16.hpp" #include "Runtime/CToken.hpp" -#include "Runtime/Graphics/CLineRenderer.hpp" #include "Runtime/Graphics/CTexture.hpp" -#include "Runtime/Graphics/Shaders/CParticleSwooshShaders.hpp" #include "Runtime/Particle/CParticleGen.hpp" #include "Runtime/Particle/CUVElement.hpp" @@ -102,12 +100,6 @@ private: float x208_maxRadius = 0.f; zeus::CColor x20c_moduColor = zeus::skWhite; -// std::array, 2> m_dataBind; -// boo::ObjToken m_vertBuf; -// boo::ObjToken m_uniformBuf; - std::unique_ptr m_lineRenderer; - std::vector m_cachedVerts; - static int g_ParticleSystemAliveCount; bool IsValid() const { return x1b4_LENG >= 2 && x1b8_SIDE >= 2; } diff --git a/Runtime/Tweaks/ITweakAutoMapper.hpp b/Runtime/Tweaks/ITweakAutoMapper.hpp index 1d5c4b74c..267d93023 100644 --- a/Runtime/Tweaks/ITweakAutoMapper.hpp +++ b/Runtime/Tweaks/ITweakAutoMapper.hpp @@ -40,7 +40,6 @@ struct ITweakAutoMapper : public ITweak { virtual float GetAlphaSurfaceUnvisited() const = 0; virtual float GetMiniAlphaOutlineUnvisited() const = 0; virtual float GetAlphaOutlineUnvisited() const = 0; - virtual const zeus::CVector3f& GetDoorCenter() const = 0; virtual float GetMiniMapViewportWidth() const = 0; virtual float GetMiniMapViewportHeight() const = 0; virtual float GetMiniMapCamDistScale() const = 0; diff --git a/Runtime/Weapon/CBomb.cpp b/Runtime/Weapon/CBomb.cpp index a42d1f23d..c97d47883 100644 --- a/Runtime/Weapon/CBomb.cpp +++ b/Runtime/Weapon/CBomb.cpp @@ -117,7 +117,7 @@ void CBomb::AddToRenderer(const zeus::CFrustum& frustum, CStateManager& mgr) { float ballRadius = mgr.GetPlayer().GetMorphBall()->GetBallRadius(); zeus::CAABox aabox(origin - (0.9f * ballRadius), origin + (0.9f * ballRadius)); - zeus::CVector3f closestPoint = aabox.closestPointAlongVector(CGraphics::g_ViewMatrix.frontVector()); + zeus::CVector3f closestPoint = aabox.closestPointAlongVector(CGraphics::mViewMatrix.frontVector()); if (x190_24_isNotDetonated && x17c_fuseTime > 0.5f) g_Renderer->AddParticleGen(*x180_particle1, closestPoint, aabox); diff --git a/Runtime/Weapon/CGrappleArm.cpp b/Runtime/Weapon/CGrappleArm.cpp index 483f8a8ae..66802730a 100644 --- a/Runtime/Weapon/CGrappleArm.cpp +++ b/Runtime/Weapon/CGrappleArm.cpp @@ -201,7 +201,7 @@ void CGrappleArm::RenderGrappleBeam(const CStateManager& mgr, const zeus::CVecto x394_grappleClawGen->Render(); x3a0_grappleSwooshGen->Render(); x390_grappleSegmentGen->Render(); - const zeus::CTransform backupViewMtx = CGraphics::g_ViewMatrix; + const zeus::CTransform backupViewMtx = CGraphics::mViewMatrix; CGraphics::SetViewPointMatrix(tmpXf.inverse() * backupViewMtx); CGraphics::SetModelMatrix(zeus::CTransform()); x39c_grappleMuzzleGen->Render(); @@ -496,7 +496,7 @@ void CGrappleArm::RenderXRayModel(const CStateManager& mgr, const zeus::CTransfo // g_Renderer->SetAmbientColor(zeus::skWhite); CSkinnedModel& model = *x50_grappleArmSkeletonModel->GetAnimationData()->GetModelData(); // model.GetModelInst()->ActivateLights({CLight::BuildLocalAmbient({}, zeus::skWhite)}); - x0_grappleArmModel->GetAnimationData()->Render(model, flags, nullptr, nullptr); + x0_grappleArmModel->GetAnimationData()->Render(model, flags, nullptr, {}); // g_Renderer->SetAmbientColor(zeus::skWhite); // CGraphics::DisableAllLights(); } diff --git a/Runtime/Weapon/CGunWeapon.cpp b/Runtime/Weapon/CGunWeapon.cpp index b3cb91c1e..7b2723a2f 100644 --- a/Runtime/Weapon/CGunWeapon.cpp +++ b/Runtime/Weapon/CGunWeapon.cpp @@ -510,7 +510,7 @@ void CGunWeapon::DrawHologram(const CStateManager& mgr, const zeus::CTransform& CGraphics::DisableAllLights(); g_Renderer->SetAmbientColor(zeus::skWhite); CSkinnedModel& model = *x60_holoModelData->GetAnimationData()->GetModelData(); - x10_solidModelData->GetAnimationData()->Render(model, flags, nullptr, nullptr); + x10_solidModelData->GetAnimationData()->Render(model, flags, nullptr, {}); g_Renderer->SetAmbientColor(zeus::skWhite); CGraphics::DisableAllLights(); } diff --git a/Runtime/Weapon/CNewFlameThrower.cpp b/Runtime/Weapon/CNewFlameThrower.cpp index 98776aa35..079f0db94 100644 --- a/Runtime/Weapon/CNewFlameThrower.cpp +++ b/Runtime/Weapon/CNewFlameThrower.cpp @@ -179,7 +179,7 @@ void CNewFlameThrower::Render(CStateManager& mgr) { void CNewFlameThrower::RenderParticles(std::array const& elem_gens) { LoadParticleGenQuads(); - zeus::CTransform xf(CGraphics::g_ViewMatrix); + zeus::CTransform xf(CGraphics::mViewMatrix); zeus::CTransform xf2 = xf; xf2.origin = zeus::skZero3f; zeus::CTransform xf3 = xf2.inverse(); diff --git a/Runtime/Weapon/CPhazonBeam.cpp b/Runtime/Weapon/CPhazonBeam.cpp index 0c78af813..73f0448d5 100644 --- a/Runtime/Weapon/CPhazonBeam.cpp +++ b/Runtime/Weapon/CPhazonBeam.cpp @@ -20,8 +20,8 @@ CPhazonBeam::CPhazonBeam(CAssetId characterId, EWeaponType type, TUniqueId playe zeus::CVector3f(0.0625f, -0.25f, 0.09375f) * scale.y()) { x21c_phazonVeins = g_SimplePool->GetObj("PhazonVeins"); x228_phazon2nd1 = g_SimplePool->GetObj("Phazon2nd_1"); - m_aaboxShaderScale.setAABB(x238_aaBoxScale); - m_aaboxShaderTranslate.setAABB(x250_aaBoxTranslate); + // m_aaboxShaderScale.setAABB(x238_aaBoxScale); + // m_aaboxShaderTranslate.setAABB(x250_aaBoxTranslate); } void CPhazonBeam::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId sender, CStateManager& mgr) { @@ -54,7 +54,7 @@ void CPhazonBeam::CreateBeam(CStateManager& mgr) { void CPhazonBeam::PreRenderGunFx(const CStateManager& mgr, const zeus::CTransform& xf) { if (IsFiring()) { - zeus::CTransform backupView = CGraphics::g_ViewMatrix; + zeus::CTransform backupView = CGraphics::mViewMatrix; CGraphics::SetViewPointMatrix(xf.inverse() * backupView); CGraphics::SetModelMatrix(zeus::CTransform()); CGunWeapon::DrawMuzzleFx(mgr); @@ -170,12 +170,12 @@ bool CPhazonBeam::IsLoaded() const { return CGunWeapon::IsLoaded() && x274_24_lo void CPhazonBeam::DrawClipScaleCube() { // Render AABB as completely transparent object, only modifying Z-buffer - m_aaboxShaderScale.draw(zeus::skClear); + // m_aaboxShaderScale.draw(zeus::skClear); } void CPhazonBeam::DrawClipTranslateCube() { // Render AABB as completely transparent object, only modifying Z-buffer - m_aaboxShaderTranslate.draw(zeus::skClear); + // m_aaboxShaderTranslate.draw(zeus::skClear); } void CPhazonBeam::Draw(bool drawSuitArm, const CStateManager& mgr, const zeus::CTransform& xf, const CModelFlags& flags, diff --git a/Runtime/Weapon/CPhazonBeam.hpp b/Runtime/Weapon/CPhazonBeam.hpp index 3b1318457..39e78570e 100644 --- a/Runtime/Weapon/CPhazonBeam.hpp +++ b/Runtime/Weapon/CPhazonBeam.hpp @@ -2,7 +2,6 @@ #include -#include "Runtime/Graphics/Shaders/CAABoxShader.hpp" #include "Runtime/Weapon/CGunWeapon.hpp" namespace metaforce { @@ -22,8 +21,7 @@ class CPhazonBeam final : public CGunWeapon { bool x274_26_veinsAlphaActive : 1 = false; bool x274_27_phazonVeinsIdx : 1 = false; float x278_fireTime = 1.f / 3.f; - CAABoxShader m_aaboxShaderScale{true}; - CAABoxShader m_aaboxShaderTranslate{true}; + void ReInitVariables(); void DrawClipScaleCube(); void DrawClipTranslateCube(); diff --git a/Runtime/Weapon/CPlasmaProjectile.cpp b/Runtime/Weapon/CPlasmaProjectile.cpp index c26dd4747..f254e037f 100644 --- a/Runtime/Weapon/CPlasmaProjectile.cpp +++ b/Runtime/Weapon/CPlasmaProjectile.cpp @@ -139,54 +139,54 @@ void CPlasmaProjectile::RenderMotionBlur() { zeus::CColor color2 = x494_outerColor; color1.a() = 63.f / 255.f; color2.a() = 0.f; - std::array verts; - for (size_t i = 0; i < verts.size() / 2; ++i) { - auto& v1 = verts[i * 2]; - auto& v2 = verts[i * 2 + 1]; - v1.m_pos = GetBeamTransform().origin; - v1.m_color = zeus::CColor::lerp(color1, color2, float(i) / 8.f); - v2.m_pos = GetPointCache()[i]; - v2.m_color = v1.m_color; - } + // std::array verts; + // for (size_t i = 0; i < verts.size() / 2; ++i) { + // auto& v1 = verts[i * 2]; + // auto& v2 = verts[i * 2 + 1]; + // v1.m_pos = GetBeamTransform().origin; + // v1.m_color = zeus::CColor::lerp(color1, color2, float(i) / 8.f); + // v2.m_pos = GetPointCache()[i]; + // v2.m_color = v1.m_color; + // } // m_renderObjs->m_motionBlurStrip.draw(zeus::skWhite, verts.size(), verts.data()); } -void CPlasmaProjectile::RenderBeam(s32 subdivs, float width, const zeus::CColor& color, s32 flags, - CColoredStripShader& shader) const { - // Flags: 0x1: textured, 0x2: length controlled UVY 0x4: alpha controlled additive blend, - // 0x8: glow texture, 0x10: subtractive blend - if ((flags & 0x1) == 0 || (flags & 0x8) ? x4f4_glowTexture.IsLoaded() : x4e8_texture.IsLoaded()) { - float angIncrement = 2.f * M_PIF / float(subdivs); - float uvY1 = -(x4cc_energyPulseStartY / 16.f); - float uvY2 = (uvY1 + float((flags & 0x3) == 0x3) != 0.f) ? 2.f : 0.5f * GetCurrentLength(); - std::array verts; - s32 numNodes = subdivs + 1; - float angle = 0.f; - bool flip = false; - for (s32 i = 0; i < numNodes; ++i) { - CColoredStripShader::Vert& v0 = verts[i * 2]; - CColoredStripShader::Vert& v1 = verts[i * 2 + 1]; - float x = std::cos(angle); - float y = std::sin(angle); - float uvX; - if (flags & 0x8) - uvX = 0.5f * y; - else if (flip) - uvX = width; - else - uvX = 0.f; - flip ^= true; - v0.m_pos = zeus::CVector3f(width * x, 0.f, width * y); - v0.m_color = color; - v0.m_uv = zeus::CVector2f(uvX, uvY1); - v1.m_pos = zeus::CVector3f(width * x, GetCurrentLength(), width * y); - v1.m_color = color; - v1.m_uv = zeus::CVector2f(uvX, uvY2); - angle += angIncrement; - } - shader.draw(zeus::skWhite, numNodes * 2, verts.data()); - } -} +// void CPlasmaProjectile::RenderBeam(s32 subdivs, float width, const zeus::CColor& color, s32 flags, +// CColoredStripShader& shader) const { +// // Flags: 0x1: textured, 0x2: length controlled UVY 0x4: alpha controlled additive blend, +// // 0x8: glow texture, 0x10: subtractive blend +// if ((flags & 0x1) == 0 || (flags & 0x8) ? x4f4_glowTexture.IsLoaded() : x4e8_texture.IsLoaded()) { +// float angIncrement = 2.f * M_PIF / float(subdivs); +// float uvY1 = -(x4cc_energyPulseStartY / 16.f); +// float uvY2 = (uvY1 + float((flags & 0x3) == 0x3) != 0.f) ? 2.f : 0.5f * GetCurrentLength(); +// std::array verts; +// s32 numNodes = subdivs + 1; +// float angle = 0.f; +// bool flip = false; +// for (s32 i = 0; i < numNodes; ++i) { +// CColoredStripShader::Vert& v0 = verts[i * 2]; +// CColoredStripShader::Vert& v1 = verts[i * 2 + 1]; +// float x = std::cos(angle); +// float y = std::sin(angle); +// float uvX; +// if (flags & 0x8) +// uvX = 0.5f * y; +// else if (flip) +// uvX = width; +// else +// uvX = 0.f; +// flip ^= true; +// v0.m_pos = zeus::CVector3f(width * x, 0.f, width * y); +// v0.m_color = color; +// v0.m_uv = zeus::CVector2f(uvX, uvY1); +// v1.m_pos = zeus::CVector3f(width * x, GetCurrentLength(), width * y); +// v1.m_color = color; +// v1.m_uv = zeus::CVector2f(uvX, uvY2); +// angle += angIncrement; +// } +// shader.draw(zeus::skWhite, numNodes * 2, verts.data()); +// } +// } void CPlasmaProjectile::ResetBeam(CStateManager& mgr, bool fullReset) { if (fullReset) { diff --git a/Runtime/Weapon/CPlasmaProjectile.hpp b/Runtime/Weapon/CPlasmaProjectile.hpp index f492273fd..13bf42bb8 100644 --- a/Runtime/Weapon/CPlasmaProjectile.hpp +++ b/Runtime/Weapon/CPlasmaProjectile.hpp @@ -8,7 +8,6 @@ #include "Runtime/GCNTypes.hpp" #include "Runtime/rstl.hpp" -#include "Runtime/Graphics/Shaders/CColoredStripShader.hpp" #include "Runtime/Weapon/CBeamInfo.hpp" #include "Runtime/Weapon/CBeamProjectile.hpp" #include "Runtime/World/CDamageInfo.hpp" @@ -101,7 +100,7 @@ private: void UpdateLights(float expansion, float dt, CStateManager& mgr); void UpdateEnergyPulse(float dt); void RenderMotionBlur(); - void RenderBeam(s32 subdivs, float width, const zeus::CColor& color, s32 flags, CColoredStripShader& shader) const; + // void RenderBeam(s32 subdivs, float width, const zeus::CColor& color, s32 flags, CColoredStripShader& shader) const; float UpdateBeamState(float dt, CStateManager& mgr); void MakeBillboardEffect(const std::optional>& particle, const std::optional>& electric, std::string_view name, diff --git a/Runtime/Weapon/CPlayerGun.cpp b/Runtime/Weapon/CPlayerGun.cpp index 4cde5fdec..b991125cd 100644 --- a/Runtime/Weapon/CPlayerGun.cpp +++ b/Runtime/Weapon/CPlayerGun.cpp @@ -2146,11 +2146,11 @@ zeus::CVector3f CPlayerGun::ConvertToScreenSpace(const zeus::CVector3f& pos, con void CPlayerGun::CopyScreenTex() { // Copy lower right quadrant to gpCopyTexBuf as RGBA8 - u16 width = CGraphics::g_Viewport.x8_width / 2; - u16 height = CGraphics::g_Viewport.xc_height / 2; + u16 width = CGraphics::mViewport.mWidth / 2; + u16 height = CGraphics::mViewport.mHeight / 2; GXSetTexCopySrc(width, height, width, height); GXSetTexCopyDst(width, height, GX_TF_RGBA8, false); - GXCopyTex(CGraphics::sSpareTextureData, false); + GXCopyTex(CGraphics::mpSpareBuffer, false); GXPixModeSync(); } @@ -2158,13 +2158,13 @@ void CPlayerGun::DrawScreenTex(float z) { // Use CopyScreenTex rendering to draw over framebuffer pixels in front of `z` // This is accomplished using orthographic projection quad with sweeping `y` coordinates // Depth is set to GEQUAL to obscure pixels in front rather than behind - const auto backupViewMatrix = CGraphics::g_ViewMatrix; + const auto backupViewMatrix = CGraphics::mViewMatrix; const auto backupProjectionState = CGraphics::GetProjectionState(); g_Renderer->SetViewportOrtho(false, -1.f, 1.f); g_Renderer->SetBlendMode_AlphaBlended(); CGraphics::SetDepthWriteMode(true, ERglEnum::GEqual, true); - u16 width = CGraphics::g_Viewport.x8_width / 2; - u16 height = CGraphics::g_Viewport.xc_height / 2; + u16 width = CGraphics::mViewport.mWidth / 2; + u16 height = CGraphics::mViewport.mHeight / 2; CGraphics::LoadDolphinSpareTexture(width, height, GX_TF_RGBA8, nullptr, GX_TEXMAP7); constexpr std::array vtxDescList{ GXVtxDescList{GX_VA_POS, GX_DIRECT}, @@ -2178,13 +2178,13 @@ void CPlayerGun::DrawScreenTex(float z) { CGX::SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP7, GX_COLOR_NULL); CGX::SetChanCtrl(CGX::EChannelId::Channel0, false, GX_SRC_REG, GX_SRC_REG, {}, GX_DF_NONE, GX_AF_NONE); CGX::Begin(GX_TRIANGLESTRIP, GX_VTXFMT0, 4); - GXPosition3f32(CGraphics::g_Viewport.x10_halfWidth, z, 0.f); + GXPosition3f32(CGraphics::mViewport.mHalfWidth, z, 0.f); GXTexCoord2f32(0.f, 1.f); - GXPosition3f32(CGraphics::g_Viewport.x8_width, z, 0.f); + GXPosition3f32(CGraphics::mViewport.mWidth, z, 0.f); GXTexCoord2f32(1.f, 1.f); - GXPosition3f32(CGraphics::g_Viewport.x10_halfWidth, z, CGraphics::g_Viewport.x14_halfHeight); + GXPosition3f32(CGraphics::mViewport.mHalfWidth, z, CGraphics::mViewport.mHalfHeight); GXTexCoord2f32(0.f, 0.f); - GXPosition3f32(CGraphics::g_Viewport.x8_width, z, CGraphics::g_Viewport.x14_halfHeight); + GXPosition3f32(CGraphics::mViewport.mWidth, z, CGraphics::mViewport.mHalfHeight); GXTexCoord2f32(1.f, 0.f); CGX::End(); CGraphics::SetDepthWriteMode(true, ERglEnum::LEqual, true); @@ -2268,7 +2268,7 @@ void CPlayerGun::Render(const CStateManager& mgr, const zeus::CVector3f& pos, co offsetWorldXf.origin += zeus::CVector3f(x34c_shakeX, 0.f, x350_shakeZ); } - zeus::CTransform oldViewMtx = CGraphics::g_ViewMatrix; + zeus::CTransform oldViewMtx = CGraphics::mViewMatrix; CGraphics::SetViewPointMatrix(offsetWorldXf.inverse() * oldViewMtx); CGraphics::SetModelMatrix(zeus::CTransform()); if (x32c_chargePhase >= EChargePhase::FxGrown && x32c_chargePhase < EChargePhase::ComboXfer) { @@ -2340,7 +2340,7 @@ void CPlayerGun::Render(const CStateManager& mgr, const zeus::CVector3f& pos, co break; } - oldViewMtx = CGraphics::g_ViewMatrix; + oldViewMtx = CGraphics::mViewMatrix; CGraphics::SetViewPointMatrix(offsetWorldXf.inverse() * oldViewMtx); CGraphics::SetModelMatrix(zeus::CTransform()); x72c_currentBeam->PostRenderGunFx(mgr, offsetWorldXf); diff --git a/Runtime/Weapon/CPowerBeam.cpp b/Runtime/Weapon/CPowerBeam.cpp index a1331e52e..06266d8fe 100644 --- a/Runtime/Weapon/CPowerBeam.cpp +++ b/Runtime/Weapon/CPowerBeam.cpp @@ -16,7 +16,7 @@ CPowerBeam::CPowerBeam(CAssetId characterId, EWeaponType type, TUniqueId playerI } void CPowerBeam::PreRenderGunFx(const CStateManager& mgr, const zeus::CTransform& xf) { - zeus::CTransform backupView = CGraphics::g_ViewMatrix; + zeus::CTransform backupView = CGraphics::mViewMatrix; CGraphics::SetViewPointMatrix(xf.inverse() * backupView); g_Renderer->SetModelMatrix(zeus::CTransform()); diff --git a/Runtime/Weapon/CWaveBuster.cpp b/Runtime/Weapon/CWaveBuster.cpp index 159a94367..63ab65850 100644 --- a/Runtime/Weapon/CWaveBuster.cpp +++ b/Runtime/Weapon/CWaveBuster.cpp @@ -24,9 +24,7 @@ CWaveBuster::CWaveBuster(const TToken& desc, EWeaponType typ , x354_busterSwoosh1(g_SimplePool->GetObj("BusterSwoosh1")) , x360_busterSwoosh2(g_SimplePool->GetObj("BusterSwoosh2")) , x36c_busterSparks(g_SimplePool->GetObj("BusterSparks")) -, x378_busterLight(g_SimplePool->GetObj("BusterLight")) -, m_lineRenderer1(CLineRenderer::EPrimitiveMode::LineStrip, 36 * 6, {}, true) -, m_lineRenderer2(CLineRenderer::EPrimitiveMode::LineStrip, 36 * 6, {}, true) { +, x378_busterLight(g_SimplePool->GetObj("BusterLight")) { x354_busterSwoosh1.GetObj(); x360_busterSwoosh2.GetObj(); x36c_busterSparks.GetObj(); @@ -276,17 +274,17 @@ void CWaveBuster::RenderBeam() { splineBaseIndex += 36; } g_Renderer->SetModelMatrix(x2e8_originalXf); - m_lineRenderer1.Reset(); - for (const zeus::CVector3f& vec : linePoints) { - m_lineRenderer1.AddVertex(vec, zeus::skWhite, 12.f / 6.f); - } - m_lineRenderer1.Render(); - - m_lineRenderer2.Reset(); - for (const zeus::CVector3f& vec : linePoints) { - m_lineRenderer2.AddVertex(vec, zeus::CColor{1.f, 0.f, 1.f, 0.5f}, 48.f / 6); - } - m_lineRenderer2.Render(); + // m_lineRenderer1.Reset(); + // for (const zeus::CVector3f& vec : linePoints) { + // m_lineRenderer1.AddVertex(vec, zeus::skWhite, 12.f / 6.f); + // } + // m_lineRenderer1.Render(); + // + // m_lineRenderer2.Reset(); + // for (const zeus::CVector3f& vec : linePoints) { + // m_lineRenderer2.AddVertex(vec, zeus::CColor{1.f, 0.f, 1.f, 0.5f}, 48.f / 6); + // } + // m_lineRenderer2.Render(); } CRayCastResult CWaveBuster::SeekDamageTarget(TUniqueId& uid, const zeus::CVector3f& pos, const zeus::CVector3f& dir, diff --git a/Runtime/Weapon/CWaveBuster.hpp b/Runtime/Weapon/CWaveBuster.hpp index ab9bea9e0..e8ead0073 100644 --- a/Runtime/Weapon/CWaveBuster.hpp +++ b/Runtime/Weapon/CWaveBuster.hpp @@ -48,8 +48,6 @@ class CWaveBuster : public CGameProjectile { bool x3d0_26_trackingTarget : 1 = false; bool x3d0_27_ : 1 = false; bool x3d0_28_ : 1 = true; - CLineRenderer m_lineRenderer1; - CLineRenderer m_lineRenderer2; void RenderParticles(); void RenderBeam(); diff --git a/Runtime/World/CActor.cpp b/Runtime/World/CActor.cpp index dde1b9951..24764b1b4 100644 --- a/Runtime/World/CActor.cpp +++ b/Runtime/World/CActor.cpp @@ -201,21 +201,20 @@ void CActor::AddToRenderer(const zeus::CFrustum& planes, CStateManager& mgr) { void CActor::DrawTouchBounds() { // Empty in retail if (m_debugHovered || m_debugSelected) { - auto aabox = GetTouchBounds(); - if (aabox) { - if (!m_actorDebugRender) { - m_actorDebugRender = CAABoxShader(); - } - m_actorDebugRender->setAABB(*aabox); - m_actorDebugRender->draw(m_debugAddColor); - } + // auto aabox = GetTouchBounds(); + // if (aabox) { + // if (!m_actorDebugRender) { + // m_actorDebugRender = CAABoxShader(); + // } + // m_actorDebugRender->setAABB(*aabox); + // m_actorDebugRender->draw(m_debugAddColor); + // } } } void CActor::RenderInternal(const CStateManager& mgr) const { - SCOPED_GRAPHICS_DEBUG_GROUP( - fmt::format("CActor::RenderInternal {} {} {}", x8_uid, xc_editorId, x10_name).c_str(), - zeus::skOrange); + SCOPED_GRAPHICS_DEBUG_GROUP(fmt::format("CActor::RenderInternal {} {} {}", x8_uid, xc_editorId, x10_name).c_str(), + zeus::skOrange); CModelData::EWhichModel which = CModelData::GetRenderingModel(mgr); if (which == CModelData::EWhichModel::ThermalHot) { @@ -247,7 +246,7 @@ void CActor::RenderInternal(const CStateManager& mgr) const { 1.f); CModelFlags flags(2, xb4_drawFlags.x1_matSetIdx, xb4_drawFlags.x2_flags, color); if (m_debugSelected || m_debugHovered) { - // TODO flags.addColor += m_debugAddColor; + flags.x4_color += m_debugAddColor; } x64_modelData->Render(mgr, x34_transform, x90_actorLights.get(), flags); return; @@ -255,7 +254,12 @@ void CActor::RenderInternal(const CStateManager& mgr) const { } CModelFlags flags = xb4_drawFlags; if (m_debugSelected || m_debugHovered) { - // TODO flags.addColor += m_debugAddColor; + if (flags.x0_blendMode == 0) { + flags.x0_blendMode = 2; + flags.x4_color = m_debugAddColor; + } else { + flags.x4_color += m_debugAddColor; + } } x64_modelData->Render(which, x34_transform, x90_actorLights.get(), flags); } @@ -457,12 +461,12 @@ void CActor::_CreateShadow() { } void CActor::_CreateReflectionCube() { -// if (hecl::com_cubemaps->toBoolean()) { -// CGraphics::CommitResources([this](boo::IGraphicsDataFactory::Context& ctx) { -// m_reflectionCube = ctx.newCubeRenderTexture(CUBEMAP_RES, CUBEMAP_MIPS); -// return true; -// } BooTrace); -// } + // if (hecl::com_cubemaps->toBoolean()) { + // CGraphics::CommitResources([this](boo::IGraphicsDataFactory::Context& ctx) { + // m_reflectionCube = ctx.newCubeRenderTexture(CUBEMAP_RES, CUBEMAP_MIPS); + // return true; + // } BooTrace); + // } } void CActor::SetCallTouch(bool callTouch) { xe5_28_callTouch = callTouch; } @@ -527,7 +531,7 @@ float CActor::GetYaw() const { return zeus::CQuaternion(x34_transform.buildMatri void CActor::EnsureRendered(const CStateManager& mgr) { const auto bounds = GetSortingBounds(mgr); - EnsureRendered(mgr, bounds.closestPointAlongVector(CGraphics::g_ViewMatrix.frontVector()), bounds); + EnsureRendered(mgr, bounds.closestPointAlongVector(CGraphics::mViewMatrix.frontVector()), bounds); } void CActor::EnsureRendered(const CStateManager& stateMgr, const zeus::CVector3f& pos, const zeus::CAABox& aabb) { diff --git a/Runtime/World/CActor.hpp b/Runtime/World/CActor.hpp index acc39962d..4b01d6e16 100644 --- a/Runtime/World/CActor.hpp +++ b/Runtime/World/CActor.hpp @@ -8,7 +8,6 @@ #include "Runtime/Character/CModelData.hpp" #include "Runtime/Graphics/CGraphics.hpp" #include "Runtime/Graphics/CSimpleShadow.hpp" -#include "Runtime/Graphics/Shaders/CAABoxShader.hpp" #include "Runtime/Weapon/WeaponCommon.hpp" #include "Runtime/World/CEntity.hpp" @@ -86,8 +85,6 @@ protected: void RenderInternal(const CStateManager& mgr) const; bool IsModelOpaque(const CStateManager& mgr) const; - std::optional m_actorDebugRender; - public: enum class EFluidState { EnteredFluid, InFluid, LeftFluid }; diff --git a/Runtime/World/CActorModelParticles.cpp b/Runtime/World/CActorModelParticles.cpp index ad1179dd4..a5268090f 100644 --- a/Runtime/World/CActorModelParticles.cpp +++ b/Runtime/World/CActorModelParticles.cpp @@ -32,12 +32,14 @@ CActorModelParticles::CItem::CItem(const CEntity& ent, CActorModelParticles& par static s32 GetNextBestPt(s32 start, const SSkinningWorkspace& workspace, CRandom16& rnd) { const auto& verts = workspace.m_vertexWorkspace; - const zeus::CVector3f& startVec = verts[start]; + const auto& startVecA = verts[start]; + const zeus::CVector3f startVec{startVecA.x, startVecA.y, startVecA.z}; s32 ret = start; float maxMag = 0.f; for (s32 i = 0; i < 10; ++i) { s32 idx = rnd.Range(0, s32(verts.size()) - 1); - const zeus::CVector3f& rndVec = verts[idx]; + const auto& rndVecA = verts[idx]; + const zeus::CVector3f rndVec{rndVecA.x, rndVecA.y, rndVecA.z}; float mag = (startVec - rndVec).magSquared(); if (mag > maxMag) { ret = idx; @@ -54,7 +56,8 @@ void CActorModelParticles::CItem::GeneratePoints(const SSkinningWorkspace& works for (std::pair, u32>& pair : x8_onFireGens) { if (pair.first) { CRandom16 rnd(pair.second); - const zeus::CVector3f& vec = verts[rnd.Float() * (verts.size() - 1)]; + const auto& vecA = verts[rnd.Float() * (verts.size() - 1)]; + const zeus::CVector3f vec{vecA.x, vecA.y, vecA.z}; pair.first->SetTranslation(xec_particleOffsetScale * vec); } } @@ -65,8 +68,10 @@ void CActorModelParticles::CItem::GeneratePoints(const SSkinningWorkspace& works s32 idx = x80_ashPointIterator; for (u32 i = 0; i < count; ++i) { idx = GetNextBestPt(idx, workspace, rnd); - x78_ashGen->SetTranslation(xec_particleOffsetScale * verts[idx]); - zeus::CVector3f v = norms[idx]; + const auto& vertA = verts[idx]; + x78_ashGen->SetTranslation(xec_particleOffsetScale * zeus::CVector3f{vertA.x, vertA.y, vertA.z}); + const auto& normA = norms[idx]; + zeus::CVector3f v{normA.x, normA.y, normA.z}; if (v.canBeNormalized()) { v.normalize(); x78_ashGen->SetOrientation(zeus::CTransform{v.cross(zeus::skUp), v, zeus::skUp, zeus::skZero3f}); @@ -85,9 +90,15 @@ void CActorModelParticles::CItem::GeneratePoints(const SSkinningWorkspace& works iceGen->SetGlobalOrientAndTrans(xf8_iceXf); s32 idx = GetNextBestPt(xb0_icePointIterator, workspace, rnd); - iceGen->SetTranslation(xec_particleOffsetScale * verts[idx]); - iceGen->SetOrientation(zeus::CTransform::MakeRotationsBasedOnY(zeus::CUnitVector3f(norms[idx]))); + const auto& vertA = verts[idx]; + zeus::CVector3f vert{vertA.x, vertA.y, vertA.z}; + const auto& normA = norms[idx]; + zeus::CVector3f norm{normA.x, normA.y, normA.z}; + + iceGen->SetTranslation(xec_particleOffsetScale * vert); + + iceGen->SetOrientation(zeus::CTransform::MakeRotationsBasedOnY(zeus::CUnitVector3f(norm))); x8c_iceGens.push_back(std::move(iceGen)); xb0_icePointIterator = (x8c_iceGens.size() == 4 ? -1 : idx); @@ -102,9 +113,11 @@ void CActorModelParticles::CItem::GeneratePoints(const SSkinningWorkspace& works #endif s32 idx = xc8_electricPointIterator; for (u32 i = 0; i < end; ++i) { - xc0_electricGen->SetOverrideIPos(verts[rnd.Range(0, s32(verts.size()) - 1)] * xec_particleOffsetScale); + const auto& iPosA = verts[rnd.Range(0, s32(verts.size()) - 1)]; + xc0_electricGen->SetOverrideIPos(zeus::CVector3f{iPosA.x, iPosA.y, iPosA.z} * xec_particleOffsetScale); idx = rnd.Range(0, s32(verts.size()) - 1); - xc0_electricGen->SetOverrideFPos(verts[idx] * xec_particleOffsetScale); + const auto& vertA = verts[idx]; + xc0_electricGen->SetOverrideFPos(zeus::CVector3f{vertA.x, vertA.y, vertA.z} * xec_particleOffsetScale); xc0_electricGen->ForceParticleCreation(1); } @@ -642,7 +655,7 @@ void CActorModelParticles::RemoveRainSplashGenerator(CActor& act) { } void CActorModelParticles::Render(const CStateManager& mgr, const CActor& actor) const { - zeus::CTransform backupModel = CGraphics::g_GXModelMatrix; + zeus::CTransform backupModel = CGraphics::mModelMatrix; auto search = FindSystem(actor.GetUniqueId()); if (search == x0_items.end()) return; diff --git a/Runtime/World/CEnvFxManager.cpp b/Runtime/World/CEnvFxManager.cpp index bb4e7b21b..9736699fb 100644 --- a/Runtime/World/CEnvFxManager.cpp +++ b/Runtime/World/CEnvFxManager.cpp @@ -23,16 +23,8 @@ static rstl::reserved_vector g_SnowForces; CEnvFxManagerGrid::CEnvFxManagerGrid(const zeus::CVector2i& position, const zeus::CVector2i& extent, std::vector initialParticles, int reserve, CEnvFxManager& parent) -: x4_position(position) -, xc_extent(extent) -, x1c_particles(std::move(initialParticles)) -//, m_instBuf(parent.m_instPool.allocateBlock(CGraphics::g_BooFactory, reserve)) -//, m_uniformBuf(parent.m_uniformPool.allocateBlock(CGraphics::g_BooFactory)) -//, m_lineRenderer(CLineRenderer::EPrimitiveMode::Lines, reserve * 2, parent.x40_txtrEnvGradient->GetTexture(), -// true, true) -{ +: x4_position(position), xc_extent(extent), x1c_particles(std::move(initialParticles)) { x1c_particles.reserve(reserve); - CEnvFxShaders::BuildShaderDataBinding(parent, *this); } CEnvFxManager::CEnvFxManager() { @@ -365,33 +357,33 @@ void CEnvFxManager::Update(float dt, CStateManager& mgr) { } } -static zeus::CColor GetFlakeColor(const zeus::CMatrix4f& mvp, const CEnvFxShaders::Instance& inst) { - float screenHeight = - std::fabs(mvp.multiplyOneOverW(inst.positions[1]).y() - mvp.multiplyOneOverW(inst.positions[0]).y()) / 2.f; - screenHeight -= (32.f / 480.f); - screenHeight /= (32.f / 480.f); - return zeus::CColor(1.f - zeus::clamp(0.f, screenHeight, 1.f), 1.f); -} +// static zeus::CColor GetFlakeColor(const zeus::CMatrix4f& mvp, const CEnvFxShaders::Instance& inst) { +// float screenHeight = +// std::fabs(mvp.multiplyOneOverW(inst.positions[1]).y() - mvp.multiplyOneOverW(inst.positions[0]).y()) / 2.f; +// screenHeight -= (32.f / 480.f); +// screenHeight /= (32.f / 480.f); +// return zeus::CColor(1.f - zeus::clamp(0.f, screenHeight, 1.f), 1.f); +// } void CEnvFxManagerGrid::RenderSnowParticles(const zeus::CTransform& camXf) { const zeus::CVector3f xVec = 0.2f * camXf.basis[0]; const zeus::CVector3f zVec = 0.2f * camXf.basis[2]; - const zeus::CMatrix4f mvp = CGraphics::GetPerspectiveProjectionMatrix() * CGraphics::g_GXModelView.toMatrix4f(); -// auto* bufOut = m_instBuf.access(); -// for (const auto& particle : x1c_particles) { -// bufOut->positions[0] = particle.toVec3f(); -// bufOut->uvs[0] = zeus::CVector2f(0.f, 0.f); -// bufOut->positions[1] = bufOut->positions[0] + zVec; -// bufOut->uvs[1] = zeus::CVector2f(0.f, 1.f); -// bufOut->positions[3] = bufOut->positions[1] + xVec; -// bufOut->uvs[3] = zeus::CVector2f(1.f, 1.f); -// bufOut->positions[2] = bufOut->positions[3] - zVec; -// bufOut->uvs[2] = zeus::CVector2f(1.f, 0.f); -// bufOut->color = GetFlakeColor(mvp, *bufOut); -// ++bufOut; -// } -// CGraphics::SetShaderDataBinding(m_snowBinding); -// CGraphics::DrawInstances(0, 4, x1c_particles.size()); + // const zeus::CMatrix4f mvp = CGraphics::GetPerspectiveProjectionMatrix() * CGraphics::g_GXModelView.toMatrix4f(); + // auto* bufOut = m_instBuf.access(); + // for (const auto& particle : x1c_particles) { + // bufOut->positions[0] = particle.toVec3f(); + // bufOut->uvs[0] = zeus::CVector2f(0.f, 0.f); + // bufOut->positions[1] = bufOut->positions[0] + zVec; + // bufOut->uvs[1] = zeus::CVector2f(0.f, 1.f); + // bufOut->positions[3] = bufOut->positions[1] + xVec; + // bufOut->uvs[3] = zeus::CVector2f(1.f, 1.f); + // bufOut->positions[2] = bufOut->positions[3] - zVec; + // bufOut->uvs[2] = zeus::CVector2f(1.f, 0.f); + // bufOut->color = GetFlakeColor(mvp, *bufOut); + // ++bufOut; + // } + // CGraphics::SetShaderDataBinding(m_snowBinding); + // CGraphics::DrawInstances(0, 4, x1c_particles.size()); } void CEnvFxManagerGrid::RenderRainParticles(const zeus::CTransform& camXf) { @@ -413,30 +405,30 @@ void CEnvFxManagerGrid::RenderRainParticles(const zeus::CTransform& camXf) { void CEnvFxManagerGrid::RenderUnderwaterParticles(const zeus::CTransform& camXf) { const zeus::CVector3f xVec = 0.5f * camXf.basis[0]; const zeus::CVector3f zVec = 0.5f * camXf.basis[2]; - const zeus::CMatrix4f mvp = CGraphics::GetPerspectiveProjectionMatrix() * CGraphics::g_GXModelView.toMatrix4f(); -// auto* bufOut = m_instBuf.access(); -// for (const auto& particle : x1c_particles) { -// bufOut->positions[0] = particle.toVec3f(); -// bufOut->uvs[0] = zeus::CVector2f(0.f, 0.f); -// bufOut->positions[1] = bufOut->positions[0] + zVec; -// bufOut->uvs[1] = zeus::CVector2f(0.f, 1.f); -// bufOut->positions[3] = bufOut->positions[1] + xVec; -// bufOut->uvs[3] = zeus::CVector2f(1.f, 1.f); -// bufOut->positions[2] = bufOut->positions[3] - zVec; -// bufOut->uvs[2] = zeus::CVector2f(1.f, 0.f); -// bufOut->color = GetFlakeColor(mvp, *bufOut); -// ++bufOut; -// } -// CGraphics::SetShaderDataBinding(m_underwaterBinding); -// CGraphics::DrawInstances(0, 4, x1c_particles.size()); + // const zeus::CMatrix4f mvp = CGraphics::GetPerspectiveProjectionMatrix() * CGraphics::g_GXModelView.toMatrix4f(); + // auto* bufOut = m_instBuf.access(); + // for (const auto& particle : x1c_particles) { + // bufOut->positions[0] = particle.toVec3f(); + // bufOut->uvs[0] = zeus::CVector2f(0.f, 0.f); + // bufOut->positions[1] = bufOut->positions[0] + zVec; + // bufOut->uvs[1] = zeus::CVector2f(0.f, 1.f); + // bufOut->positions[3] = bufOut->positions[1] + xVec; + // bufOut->uvs[3] = zeus::CVector2f(1.f, 1.f); + // bufOut->positions[2] = bufOut->positions[3] - zVec; + // bufOut->uvs[2] = zeus::CVector2f(1.f, 0.f); + // bufOut->color = GetFlakeColor(mvp, *bufOut); + // ++bufOut; + // } + // CGraphics::SetShaderDataBinding(m_underwaterBinding); + // CGraphics::DrawInstances(0, 4, x1c_particles.size()); } void CEnvFxManagerGrid::Render(const zeus::CTransform& xf, const zeus::CTransform& invXf, const zeus::CTransform& camXf, float fxDensity, EEnvFxType fxType, CEnvFxManager& parent) { if (!x1c_particles.empty() && x14_block.first) { CGraphics::SetModelMatrix(xf * zeus::CTransform::Translate(x4_position.toVec2f() / 256.f)); - parent.m_uniformData.mv = CGraphics::g_GXModelView.toMatrix4f(); - parent.m_uniformData.proj = CGraphics::GetPerspectiveProjectionMatrix(/*true*/); + // parent.m_uniformData.mv = CGraphics::g_GXModelView.toMatrix4f(); + // parent.m_uniformData.proj = CGraphics::GetPerspectiveProjectionMatrix(/*true*/); switch (fxType) { case EEnvFxType::Snow: case EEnvFxType::Rain: { @@ -444,13 +436,13 @@ void CEnvFxManagerGrid::Render(const zeus::CTransform& xf, const zeus::CTransfor envTexMtx[2][1] = 10.f; envTexMtx[3][1] = 0.5f - (invXf * (zeus::skUp * x14_block.second)).z() * 10.f; m_uvyOffset = envTexMtx[3][1]; - parent.m_uniformData.envMtx = envTexMtx; + // parent.m_uniformData.envMtx = envTexMtx; break; } default: break; } -// m_uniformBuf.access() = parent.m_uniformData; + // m_uniformBuf.access() = parent.m_uniformData; switch (fxType) { case EEnvFxType::Snow: RenderSnowParticles(camXf); @@ -471,7 +463,7 @@ void CEnvFxManager::SetupSnowTevs(const CStateManager& mgr) { mgr.GetCameraManager()->GetCurrentCamera(mgr); if (mgr.GetCameraManager()->GetFluidCounter() != 0) { g_Renderer->SetWorldFog(ERglFogMode::PerspExp, 0.f, 35.f, zeus::skBlack); - m_uniformData.moduColor = zeus::CColor(1.f, 0.5f); + // m_uniformData.moduColor = zeus::CColor(1.f, 0.5f); } else { g_Renderer->SetWorldFog(ERglFogMode::PerspLin, 52.f, 57.f, zeus::skBlack); } @@ -545,7 +537,7 @@ void CEnvFxManager::Render(const CStateManager& mgr) { zeus::CTransform xf = GetParticleBoundsToWorldTransform(); zeus::CTransform invXf = xf.inverse(); zeus::CTransform camXf = mgr.GetCameraManager()->GetCurrentCameraTransform(mgr); - m_uniformData.moduColor = zeus::skWhite; + // m_uniformData.moduColor = zeus::skWhite; switch (fxType) { case EEnvFxType::Snow: SetupSnowTevs(mgr); diff --git a/Runtime/World/CEnvFxManager.hpp b/Runtime/World/CEnvFxManager.hpp index 0b3f56803..c22b3b61d 100644 --- a/Runtime/World/CEnvFxManager.hpp +++ b/Runtime/World/CEnvFxManager.hpp @@ -8,8 +8,6 @@ #include "Runtime/rstl.hpp" #include "Runtime/Audio/CSfxManager.hpp" #include "Runtime/Particle/CGenDescription.hpp" -#include "Runtime/Graphics/CLineRenderer.hpp" -#include "Runtime/Graphics/Shaders/CEnvFxShaders.hpp" #include #include @@ -84,7 +82,7 @@ class CEnvFxManager { // hecl::VertexBufferPool m_instPool; // hecl::UniformBufferPool m_uniformPool; - CEnvFxShaders::Uniform m_uniformData; + // CEnvFxShaders::Uniform m_uniformData; // boo::ObjToken m_fogUniformBuf; zeus::CAABox x0_particleBounds = zeus::CAABox(-63.5f, 63.5f); diff --git a/Runtime/World/CFishCloud.cpp b/Runtime/World/CFishCloud.cpp index 0ed487df9..9887d0fdc 100644 --- a/Runtime/World/CFishCloud.cpp +++ b/Runtime/World/CFishCloud.cpp @@ -577,12 +577,12 @@ void CFishCloud::RenderBoid(int idx, const CBoid& boid, u32& drawMask, bool ther if ((drawMask & thisDrawMask) != 0) { drawMask &= ~thisDrawMask; mData.GetAnimationData()->BuildPose(); - model.Calculate(mData.GetAnimationData()->GetPose(), nullptr, nullptr, &x178_workspaces[modelIndex]); + model.Calculate(mData.GetAnimationData()->GetPose(), nullptr, {}, &x178_workspaces[modelIndex]); } CGraphics::SetModelMatrix(zeus::lookAt(boid.x0_pos, boid.x0_pos + boid.xc_vel)); - const auto* positions = &x178_workspaces[modelIndex].m_vertexWorkspace; - const auto* normals = &x178_workspaces[modelIndex].m_normalWorkspace; + const auto& positions = x178_workspaces[modelIndex].m_vertexWorkspace; + const auto& normals = x178_workspaces[modelIndex].m_normalWorkspace; if (thermalHot) { constexpr CModelFlags thermFlags(0, 0, 3, zeus::skWhite); CModelData::ThermalDraw(model, positions, normals, zeus::skWhite, zeus::CColor(0.f, 0.25f), thermFlags); diff --git a/Runtime/World/CFluidPlane.cpp b/Runtime/World/CFluidPlane.cpp index 37a7eff8f..2d7cabd05 100644 --- a/Runtime/World/CFluidPlane.cpp +++ b/Runtime/World/CFluidPlane.cpp @@ -83,397 +83,397 @@ void CFluidPlane::AddRipple(const CRipple& ripple, const CScriptWater& water, CS mgr.GetFluidPlaneManager()->RippleManager().AddRipple(ripple); } -void CFluidPlane::RenderStripWithRipples(float curY, const Heights& heights, const Flags& flags, int startYDiv, - const CFluidPlaneRender::SPatchInfo& info, - std::vector& vOut, - std::vector& pvOut) { - m_shader->bindRegular(); - - int yTile = (startYDiv + CFluidPlaneRender::numSubdivisionsInTile - 1) / CFluidPlaneRender::numSubdivisionsInTile; - int endXTile = - (info.x0_xSubdivs + CFluidPlaneRender::numSubdivisionsInTile - 4) / CFluidPlaneRender::numSubdivisionsInTile; - - int midDiv = CFluidPlaneRender::numSubdivisionsInTile / 2; - float tileMid = info.x18_rippleResolution * midDiv; - float yMin = curY; - float yMid = curY + tileMid; - - float curX = info.x4_localMin.x(); - int gridCell = info.x28_tileX + info.x2a_gridDimX * (info.x2e_tileY + yTile - 1); - int xTile = 1; - int tileSpan; - for (int i = 1; i < info.x0_xSubdivs - 2; i += CFluidPlaneRender::numSubdivisionsInTile * tileSpan, - gridCell += tileSpan, xTile += tileSpan, curX += info.x14_tileSize * tileSpan) { - tileSpan = 1; - if (info.x30_gridFlags && !info.x30_gridFlags[gridCell]) - continue; - - if ((flags[yTile][xTile] & 0x1f) == 0x1f) { - for (; xTile + tileSpan <= endXTile; ++tileSpan) { - if ((flags[yTile][xTile + tileSpan] & 0x1f) != 0x1f) - break; - if (info.x30_gridFlags && !info.x30_gridFlags[gridCell + tileSpan]) - break; - } - - int stripDivCount = tileSpan * CFluidPlaneRender::numSubdivisionsInTile + 1; - int remSubdivs = CFluidPlaneRender::numSubdivisionsInTile; - std::function func; - - switch (info.x37_normalMode) { - case CFluidPlaneRender::NormalMode::None: - func = [&](float x, float y, const CFluidPlaneRender::SHFieldSample& samp) { - vOut.emplace_back(zeus::CVector3f(x, y, samp.height)); - }; - break; - case CFluidPlaneRender::NormalMode::NoNormals: - func = [&](float x, float y, const CFluidPlaneRender::SHFieldSample& samp) { - vOut.emplace_back(zeus::CVector3f(x, y, samp.height), samp.MakeColor(info)); - }; - break; - case CFluidPlaneRender::NormalMode::Normals: - func = [&](float x, float y, const CFluidPlaneRender::SHFieldSample& samp) { - vOut.emplace_back(zeus::CVector3f(x, y, samp.height), samp.MakeNormal(), samp.MakeColor(info)); - }; - break; - case CFluidPlaneRender::NormalMode::NBT: - func = [&](float x, float y, const CFluidPlaneRender::SHFieldSample& samp) { - vOut.emplace_back(zeus::CVector3f(x, y, samp.height), samp.MakeNormal(), samp.MakeBinormal(), - samp.MakeTangent(), samp.MakeColor(info)); - }; - break; - } - - float curTileY = yMin; - int curYDiv = startYDiv; - for (; remSubdivs > 0; --remSubdivs, ++curYDiv, curTileY += info.x18_rippleResolution) { - size_t start = vOut.size(); - float curTileX = curX; - for (int v = 0; v < stripDivCount; ++v) { - func(curTileX, curTileY, heights[curYDiv][i + v]); - func(curTileX, curTileY + info.x18_rippleResolution, heights[curYDiv + 1][i + v]); - curTileX += info.x18_rippleResolution; - } -// CGraphics::DrawArray(start, vOut.size() - start); - } - } else { - bool r19 = (flags[yTile + 1][xTile] & 0x2) != 0; // North - bool r16 = (flags[yTile][xTile - 1] & 0x8) != 0; // West - bool r18 = (flags[yTile][xTile + 1] & 0x4) != 0; // East - bool r17 = (flags[yTile - 1][xTile] & 0x1) != 0; // South - - int r6 = (r19 ? CFluidPlaneRender::numSubdivisionsInTile : 1) + 2; - r6 += r18 ? CFluidPlaneRender::numSubdivisionsInTile : 1; - r6 += r17 ? CFluidPlaneRender::numSubdivisionsInTile : 1; - r6 += r16 ? CFluidPlaneRender::numSubdivisionsInTile : 1; - - if (r6 == 6 && (info.x37_normalMode == CFluidPlaneRender::NormalMode::Normals || - info.x37_normalMode == CFluidPlaneRender::NormalMode::NBT)) { - for (; xTile + tileSpan <= endXTile; ++tileSpan) { - if ((flags[yTile][xTile + tileSpan] & 0x1f) == 0x1f) - break; - if (info.x30_gridFlags && !info.x30_gridFlags[gridCell + tileSpan]) - break; - if ((flags[yTile + 1][xTile + tileSpan] & 0x2) != 0x0) - break; - if ((flags[yTile][xTile + tileSpan + 1] & 0x4) != 0x0) - break; - if ((flags[yTile - 1][xTile + tileSpan] & 0x1) != 0x0) - break; - } - - int stripDivCount = tileSpan + 1; - size_t start = vOut.size(); - switch (info.x37_normalMode) { - case CFluidPlaneRender::NormalMode::Normals: { - int curYDiv0 = startYDiv; - int curYDiv1 = startYDiv + CFluidPlaneRender::numSubdivisionsInTile; - float curTileX = curX; - for (int v = 0; v < stripDivCount; ++v) { - int curXDiv = v * CFluidPlaneRender::numSubdivisionsInTile + i; - const CFluidPlaneRender::SHFieldSample& samp0 = heights[curYDiv0][curXDiv]; - const CFluidPlaneRender::SHFieldSample& samp1 = heights[curYDiv1][curXDiv]; - vOut.emplace_back(zeus::CVector3f(curTileX, yMin, samp0.height), samp0.MakeNormal(), samp0.MakeColor(info)); - vOut.emplace_back(zeus::CVector3f(curTileX, yMin + info.x14_tileSize, samp1.height), samp1.MakeNormal(), - samp1.MakeColor(info)); - curTileX += info.x14_tileSize; - } - break; - } - case CFluidPlaneRender::NormalMode::NBT: { - int curYDiv0 = startYDiv; - int curYDiv1 = startYDiv + CFluidPlaneRender::numSubdivisionsInTile; - float curTileX = curX; - for (int v = 0; v < stripDivCount; ++v) { - int curXDiv = v * CFluidPlaneRender::numSubdivisionsInTile + i; - const CFluidPlaneRender::SHFieldSample& samp0 = heights[curYDiv0][curXDiv]; - const CFluidPlaneRender::SHFieldSample& samp1 = heights[curYDiv1][curXDiv]; - vOut.emplace_back(zeus::CVector3f(curTileX, yMin, samp0.height), samp0.MakeNormal(), samp0.MakeBinormal(), - samp0.MakeTangent(), samp0.MakeColor(info)); - vOut.emplace_back(zeus::CVector3f(curTileX, yMin + info.x14_tileSize, samp1.height), samp1.MakeNormal(), - samp1.MakeBinormal(), samp1.MakeTangent(), samp1.MakeColor(info)); - curTileX += info.x14_tileSize; - } - break; - } - default: - break; - } -// CGraphics::DrawArray(start, vOut.size() - start); - } else { - TriFanToStrip toStrip(vOut); - std::function func; - - switch (info.x37_normalMode) { - case CFluidPlaneRender::NormalMode::None: - func = [&](float x, float y, const CFluidPlaneRender::SHFieldSample& samp) { - toStrip.EmplaceVert(zeus::CVector3f(x, y, samp.height)); - }; - break; - case CFluidPlaneRender::NormalMode::NoNormals: - func = [&](float x, float y, const CFluidPlaneRender::SHFieldSample& samp) { - toStrip.EmplaceVert(zeus::CVector3f(x, y, samp.height), samp.MakeColor(info)); - }; - break; - case CFluidPlaneRender::NormalMode::Normals: - func = [&](float x, float y, const CFluidPlaneRender::SHFieldSample& samp) { - toStrip.EmplaceVert(zeus::CVector3f(x, y, samp.height), samp.MakeNormal(), samp.MakeColor(info)); - }; - break; - case CFluidPlaneRender::NormalMode::NBT: - func = [&](float x, float y, const CFluidPlaneRender::SHFieldSample& samp) { - toStrip.EmplaceVert(zeus::CVector3f(x, y, samp.height), samp.MakeNormal(), samp.MakeBinormal(), - samp.MakeTangent(), samp.MakeColor(info)); - }; - break; - } - - func(tileMid + curX, yMid, heights[startYDiv + midDiv][i + midDiv]); - - int curXDiv = i; - int curYDiv = startYDiv + CFluidPlaneRender::numSubdivisionsInTile; - float curTileX = curX; - float curTileY = yMin + info.x14_tileSize; - for (int v = 0; v < (r19 ? CFluidPlaneRender::numSubdivisionsInTile : 1); ++v) { - const CFluidPlaneRender::SHFieldSample& samp = heights[curYDiv][curXDiv + v]; - func(curTileX, curTileY, samp); - curTileX += info.x18_rippleResolution; - } - - curXDiv = i + CFluidPlaneRender::numSubdivisionsInTile; - curYDiv = startYDiv + CFluidPlaneRender::numSubdivisionsInTile; - curTileX = curX + info.x14_tileSize; - curTileY = yMin + info.x14_tileSize; - for (int v = 0; v < (r18 ? CFluidPlaneRender::numSubdivisionsInTile : 1); ++v) { - const CFluidPlaneRender::SHFieldSample& samp = heights[curYDiv - v][curXDiv]; - func(curTileX, curTileY, samp); - curTileY -= info.x18_rippleResolution; - } - - curXDiv = i + CFluidPlaneRender::numSubdivisionsInTile; - curYDiv = startYDiv; - curTileX = curX + info.x14_tileSize; - curTileY = yMin; - for (int v = 0; v < (r17 ? CFluidPlaneRender::numSubdivisionsInTile : 1); ++v) { - const CFluidPlaneRender::SHFieldSample& samp = heights[curYDiv][curXDiv - v]; - func(curTileX, curTileY, samp); - curTileX -= info.x18_rippleResolution; - } - - curXDiv = i; - curYDiv = startYDiv; - curTileX = curX; - curTileY = yMin; - if (r16) { - for (int v = 0; v < CFluidPlaneRender::numSubdivisionsInTile + 1; ++v) { - const CFluidPlaneRender::SHFieldSample& samp = heights[curYDiv + v][curXDiv]; - func(curTileX, curTileY, samp); - curTileY += info.x18_rippleResolution; - } - } else { - { - const CFluidPlaneRender::SHFieldSample& samp = heights[curYDiv][curXDiv]; - func(curTileX, curTileY, samp); - } - curTileY += info.x14_tileSize; - { - const CFluidPlaneRender::SHFieldSample& samp = - heights[curYDiv + CFluidPlaneRender::numSubdivisionsInTile][curXDiv]; - func(curTileX, curTileY, samp); - } - } - -// toStrip.Draw(); - } - } - } -} - -void CFluidPlane::RenderPatch(const CFluidPlaneRender::SPatchInfo& info, const Heights& heights, const Flags& flags, - bool noRipples, bool flagIs1, std::vector& vOut, - std::vector& pvOut) { - OPTICK_EVENT(); - if (noRipples) { - m_shader->bindRegular(); - - float xMin = info.x4_localMin.x(); - float yMin = info.x4_localMin.y(); - float xMax = info.x18_rippleResolution * (info.x0_xSubdivs - 2) + xMin; - float yMax = info.x18_rippleResolution * (info.x1_ySubdivs - 2) + yMin; - - switch (info.x37_normalMode) { - case CFluidPlaneRender::NormalMode::None: { - size_t start = vOut.size(); - vOut.emplace_back(zeus::CVector3f(xMin, yMin, 0.f)); - vOut.emplace_back(zeus::CVector3f(xMin, yMax, 0.f)); - vOut.emplace_back(zeus::CVector3f(xMax, yMin, 0.f)); - vOut.emplace_back(zeus::CVector3f(xMax, yMax, 0.f)); -// CGraphics::DrawArray(start, 4); - break; - } - case CFluidPlaneRender::NormalMode::NoNormals: { - size_t start = vOut.size(); - vOut.emplace_back(zeus::CVector3f(xMin, yMin, 0.f), zeus::skBlack); - vOut.emplace_back(zeus::CVector3f(xMin, yMax, 0.f), zeus::skBlack); - vOut.emplace_back(zeus::CVector3f(xMax, yMin, 0.f), zeus::skBlack); - vOut.emplace_back(zeus::CVector3f(xMax, yMax, 0.f), zeus::skBlack); -// CGraphics::DrawArray(start, 4); - break; - } - case CFluidPlaneRender::NormalMode::Normals: { - int yTiles = (info.x1_ySubdivs - 3) / CFluidPlaneRender::numSubdivisionsInTile + 1; - int xTiles = (info.x0_xSubdivs - 3) / CFluidPlaneRender::numSubdivisionsInTile + 1; - int xTileStart = info.x28_tileX + info.x2e_tileY * info.x2a_gridDimX; - yMax = yMin; - for (int curYTile = yTiles; curYTile > 0; - --curYTile, yMax += info.x14_tileSize, xTileStart += info.x2a_gridDimX) { - xMax = xMin; - int nextXTile; - for (int curXTile = 0; curXTile < xTiles; curXTile = nextXTile) { - if (!info.x30_gridFlags || info.x30_gridFlags[xTileStart + curXTile]) { - if (curYTile == yTiles || curYTile == 1 || curXTile == 0 || xTiles - 1 == curXTile) { - TriFanToStrip toStrip(vOut); - - toStrip.EmplaceVert( - zeus::CVector3f(xMax + 0.5f * info.x14_tileSize, yMax + 0.5f * info.x14_tileSize, 0.f), zeus::skUp, - zeus::skBlack); - - float tmp = xMax; - for (int v = 0; v < ((curYTile == 1) ? CFluidPlaneRender::numSubdivisionsInTile : 1); ++v) { - toStrip.EmplaceVert(zeus::CVector3f(tmp, yMax + info.x14_tileSize, 0.f), zeus::skUp, zeus::skBlack); - tmp += info.x18_rippleResolution; - } - - tmp = yMax + info.x14_tileSize; - for (int v = 0; v < ((xTiles - 1 == curXTile) ? CFluidPlaneRender::numSubdivisionsInTile : 1); ++v) { - toStrip.EmplaceVert(zeus::CVector3f(xMax + info.x14_tileSize, tmp, 0.f), zeus::skUp, zeus::skBlack); - tmp -= info.x18_rippleResolution; - } - - tmp = xMax + info.x14_tileSize; - for (int v = 0; v < ((curYTile == yTiles) ? CFluidPlaneRender::numSubdivisionsInTile : 1); ++v) { - toStrip.EmplaceVert(zeus::CVector3f(tmp, yMax, 0.f), zeus::skUp, zeus::skBlack); - tmp -= info.x18_rippleResolution; - } - - tmp = yMax; - for (int v = 0; v < ((curXTile == 0) ? CFluidPlaneRender::numSubdivisionsInTile : 1); ++v) { - toStrip.EmplaceVert(zeus::CVector3f(xMax, tmp, 0.f), zeus::skUp, zeus::skBlack); - tmp += info.x18_rippleResolution; - } - - toStrip.EmplaceVert(zeus::CVector3f(xMax, yMax + info.x14_tileSize, 0.f), zeus::skUp, zeus::skBlack); - -// toStrip.Draw(); - - nextXTile = curXTile + 1; - xMax += info.x14_tileSize; - } else { - nextXTile = curXTile + 1; - while (nextXTile < xTiles - 1 && (!info.x30_gridFlags || info.x30_gridFlags[xTileStart + nextXTile])) - ++nextXTile; - - size_t start = vOut.size(); - for (int v = 0; v < nextXTile - curXTile + 1; ++v) { - vOut.emplace_back(zeus::CVector3f(xMax, yMax, 0.f), zeus::skUp, zeus::skBlack); - vOut.emplace_back(zeus::CVector3f(xMax, yMax + info.x14_tileSize, 0.f), zeus::skUp, zeus::skBlack); - xMax += info.x14_tileSize; - } -// CGraphics::DrawArray(start, vOut.size() - start); - - ++nextXTile; - if (nextXTile == xTiles) { - --nextXTile; - xMax -= info.x14_tileSize; - } - } - } else { - nextXTile = curXTile + 1; - xMax += info.x14_tileSize; - while (nextXTile < xTiles && !info.x30_gridFlags[xTileStart + nextXTile]) { - xMax += info.x14_tileSize; - ++nextXTile; - } - } - } - } - break; - } - case CFluidPlaneRender::NormalMode::NBT: { - if (flagIs1 || !info.x30_gridFlags) { - size_t start = vOut.size(); - vOut.emplace_back(zeus::CVector3f(xMin, yMin, 0.f), zeus::skUp, zeus::skForward, zeus::skRight, zeus::skBlack); - vOut.emplace_back(zeus::CVector3f(xMin, yMax, 0.f), zeus::skUp, zeus::skForward, zeus::skRight, zeus::skBlack); - vOut.emplace_back(zeus::CVector3f(xMax, yMin, 0.f), zeus::skUp, zeus::skForward, zeus::skRight, zeus::skBlack); - vOut.emplace_back(zeus::CVector3f(xMax, yMax, 0.f), zeus::skUp, zeus::skForward, zeus::skRight, zeus::skBlack); -// CGraphics::DrawArray(start, 4); - } else { - int xTiles = (info.x0_xSubdivs - 3) / CFluidPlaneRender::numSubdivisionsInTile + 1; - int yTiles = (info.x1_ySubdivs - 3) / CFluidPlaneRender::numSubdivisionsInTile + 1; - int xTileStart = info.x28_tileX + info.x2e_tileY * info.x2a_gridDimX; - for (; yTiles > 0; --yTiles, yMin += info.x14_tileSize, xTileStart += info.x2a_gridDimX) { - xMax = xMin; - int nextXTile; - for (int curXTile = 0; curXTile < xTiles; curXTile = nextXTile) { - if (info.x30_gridFlags[xTileStart + curXTile]) { - nextXTile = curXTile + 1; - int tile = xTileStart + nextXTile; - while (nextXTile < xTiles && info.x30_gridFlags[tile]) { - ++nextXTile; - ++tile; - } - - size_t start = vOut.size(); - for (int v = 0; v < nextXTile - curXTile + 1; ++v) { - vOut.emplace_back(zeus::CVector3f(xMax, yMin, 0.f), zeus::skUp, zeus::skForward, zeus::skRight, - zeus::skBlack); - vOut.emplace_back(zeus::CVector3f(xMax, yMin + info.x14_tileSize, 0.f), zeus::skUp, zeus::skForward, - zeus::skRight, zeus::skBlack); - xMax += info.x14_tileSize; - } -// CGraphics::DrawArray(start, vOut.size() - start); - } else { - nextXTile = curXTile + 1; - xMax += info.x14_tileSize; - int tile = xTileStart + nextXTile; - while (nextXTile < xTiles && !info.x30_gridFlags[tile]) { - xMax += info.x14_tileSize; - ++nextXTile; - ++tile; - } - } - } - } - } - break; - } - } - } else { - float curY = info.x4_localMin.y(); - for (int startYDiv = 1; startYDiv < info.x1_ySubdivs - 2; - startYDiv += CFluidPlaneRender::numSubdivisionsInTile, curY += info.x14_tileSize) - RenderStripWithRipples(curY, heights, flags, startYDiv, info, vOut, pvOut); - } -} +// void CFluidPlane::RenderStripWithRipples(float curY, const Heights& heights, const Flags& flags, int startYDiv, +// const CFluidPlaneRender::SPatchInfo& info, +// std::vector& vOut, +// std::vector& pvOut) { +// m_shader->bindRegular(); +// +// int yTile = (startYDiv + CFluidPlaneRender::numSubdivisionsInTile - 1) / CFluidPlaneRender::numSubdivisionsInTile; +// int endXTile = +// (info.x0_xSubdivs + CFluidPlaneRender::numSubdivisionsInTile - 4) / CFluidPlaneRender::numSubdivisionsInTile; +// +// int midDiv = CFluidPlaneRender::numSubdivisionsInTile / 2; +// float tileMid = info.x18_rippleResolution * midDiv; +// float yMin = curY; +// float yMid = curY + tileMid; +// +// float curX = info.x4_localMin.x(); +// int gridCell = info.x28_tileX + info.x2a_gridDimX * (info.x2e_tileY + yTile - 1); +// int xTile = 1; +// int tileSpan; +// for (int i = 1; i < info.x0_xSubdivs - 2; i += CFluidPlaneRender::numSubdivisionsInTile * tileSpan, +// gridCell += tileSpan, xTile += tileSpan, curX += info.x14_tileSize * tileSpan) { +// tileSpan = 1; +// if (info.x30_gridFlags && !info.x30_gridFlags[gridCell]) +// continue; +// +// if ((flags[yTile][xTile] & 0x1f) == 0x1f) { +// for (; xTile + tileSpan <= endXTile; ++tileSpan) { +// if ((flags[yTile][xTile + tileSpan] & 0x1f) != 0x1f) +// break; +// if (info.x30_gridFlags && !info.x30_gridFlags[gridCell + tileSpan]) +// break; +// } +// +// int stripDivCount = tileSpan * CFluidPlaneRender::numSubdivisionsInTile + 1; +// int remSubdivs = CFluidPlaneRender::numSubdivisionsInTile; +// std::function func; +// +// switch (info.x37_normalMode) { +// case CFluidPlaneRender::NormalMode::None: +// func = [&](float x, float y, const CFluidPlaneRender::SHFieldSample& samp) { +// vOut.emplace_back(zeus::CVector3f(x, y, samp.height)); +// }; +// break; +// case CFluidPlaneRender::NormalMode::NoNormals: +// func = [&](float x, float y, const CFluidPlaneRender::SHFieldSample& samp) { +// vOut.emplace_back(zeus::CVector3f(x, y, samp.height), samp.MakeColor(info)); +// }; +// break; +// case CFluidPlaneRender::NormalMode::Normals: +// func = [&](float x, float y, const CFluidPlaneRender::SHFieldSample& samp) { +// vOut.emplace_back(zeus::CVector3f(x, y, samp.height), samp.MakeNormal(), samp.MakeColor(info)); +// }; +// break; +// case CFluidPlaneRender::NormalMode::NBT: +// func = [&](float x, float y, const CFluidPlaneRender::SHFieldSample& samp) { +// vOut.emplace_back(zeus::CVector3f(x, y, samp.height), samp.MakeNormal(), samp.MakeBinormal(), +// samp.MakeTangent(), samp.MakeColor(info)); +// }; +// break; +// } +// +// float curTileY = yMin; +// int curYDiv = startYDiv; +// for (; remSubdivs > 0; --remSubdivs, ++curYDiv, curTileY += info.x18_rippleResolution) { +// size_t start = vOut.size(); +// float curTileX = curX; +// for (int v = 0; v < stripDivCount; ++v) { +// func(curTileX, curTileY, heights[curYDiv][i + v]); +// func(curTileX, curTileY + info.x18_rippleResolution, heights[curYDiv + 1][i + v]); +// curTileX += info.x18_rippleResolution; +// } +// // CGraphics::DrawArray(start, vOut.size() - start); +// } +// } else { +// bool r19 = (flags[yTile + 1][xTile] & 0x2) != 0; // North +// bool r16 = (flags[yTile][xTile - 1] & 0x8) != 0; // West +// bool r18 = (flags[yTile][xTile + 1] & 0x4) != 0; // East +// bool r17 = (flags[yTile - 1][xTile] & 0x1) != 0; // South +// +// int r6 = (r19 ? CFluidPlaneRender::numSubdivisionsInTile : 1) + 2; +// r6 += r18 ? CFluidPlaneRender::numSubdivisionsInTile : 1; +// r6 += r17 ? CFluidPlaneRender::numSubdivisionsInTile : 1; +// r6 += r16 ? CFluidPlaneRender::numSubdivisionsInTile : 1; +// +// if (r6 == 6 && (info.x37_normalMode == CFluidPlaneRender::NormalMode::Normals || +// info.x37_normalMode == CFluidPlaneRender::NormalMode::NBT)) { +// for (; xTile + tileSpan <= endXTile; ++tileSpan) { +// if ((flags[yTile][xTile + tileSpan] & 0x1f) == 0x1f) +// break; +// if (info.x30_gridFlags && !info.x30_gridFlags[gridCell + tileSpan]) +// break; +// if ((flags[yTile + 1][xTile + tileSpan] & 0x2) != 0x0) +// break; +// if ((flags[yTile][xTile + tileSpan + 1] & 0x4) != 0x0) +// break; +// if ((flags[yTile - 1][xTile + tileSpan] & 0x1) != 0x0) +// break; +// } +// +// int stripDivCount = tileSpan + 1; +// size_t start = vOut.size(); +// switch (info.x37_normalMode) { +// case CFluidPlaneRender::NormalMode::Normals: { +// int curYDiv0 = startYDiv; +// int curYDiv1 = startYDiv + CFluidPlaneRender::numSubdivisionsInTile; +// float curTileX = curX; +// for (int v = 0; v < stripDivCount; ++v) { +// int curXDiv = v * CFluidPlaneRender::numSubdivisionsInTile + i; +// const CFluidPlaneRender::SHFieldSample& samp0 = heights[curYDiv0][curXDiv]; +// const CFluidPlaneRender::SHFieldSample& samp1 = heights[curYDiv1][curXDiv]; +// vOut.emplace_back(zeus::CVector3f(curTileX, yMin, samp0.height), samp0.MakeNormal(), samp0.MakeColor(info)); +// vOut.emplace_back(zeus::CVector3f(curTileX, yMin + info.x14_tileSize, samp1.height), samp1.MakeNormal(), +// samp1.MakeColor(info)); +// curTileX += info.x14_tileSize; +// } +// break; +// } +// case CFluidPlaneRender::NormalMode::NBT: { +// int curYDiv0 = startYDiv; +// int curYDiv1 = startYDiv + CFluidPlaneRender::numSubdivisionsInTile; +// float curTileX = curX; +// for (int v = 0; v < stripDivCount; ++v) { +// int curXDiv = v * CFluidPlaneRender::numSubdivisionsInTile + i; +// const CFluidPlaneRender::SHFieldSample& samp0 = heights[curYDiv0][curXDiv]; +// const CFluidPlaneRender::SHFieldSample& samp1 = heights[curYDiv1][curXDiv]; +// vOut.emplace_back(zeus::CVector3f(curTileX, yMin, samp0.height), samp0.MakeNormal(), samp0.MakeBinormal(), +// samp0.MakeTangent(), samp0.MakeColor(info)); +// vOut.emplace_back(zeus::CVector3f(curTileX, yMin + info.x14_tileSize, samp1.height), samp1.MakeNormal(), +// samp1.MakeBinormal(), samp1.MakeTangent(), samp1.MakeColor(info)); +// curTileX += info.x14_tileSize; +// } +// break; +// } +// default: +// break; +// } +// // CGraphics::DrawArray(start, vOut.size() - start); +// } else { +// TriFanToStrip toStrip(vOut); +// std::function func; +// +// switch (info.x37_normalMode) { +// case CFluidPlaneRender::NormalMode::None: +// func = [&](float x, float y, const CFluidPlaneRender::SHFieldSample& samp) { +// toStrip.EmplaceVert(zeus::CVector3f(x, y, samp.height)); +// }; +// break; +// case CFluidPlaneRender::NormalMode::NoNormals: +// func = [&](float x, float y, const CFluidPlaneRender::SHFieldSample& samp) { +// toStrip.EmplaceVert(zeus::CVector3f(x, y, samp.height), samp.MakeColor(info)); +// }; +// break; +// case CFluidPlaneRender::NormalMode::Normals: +// func = [&](float x, float y, const CFluidPlaneRender::SHFieldSample& samp) { +// toStrip.EmplaceVert(zeus::CVector3f(x, y, samp.height), samp.MakeNormal(), samp.MakeColor(info)); +// }; +// break; +// case CFluidPlaneRender::NormalMode::NBT: +// func = [&](float x, float y, const CFluidPlaneRender::SHFieldSample& samp) { +// toStrip.EmplaceVert(zeus::CVector3f(x, y, samp.height), samp.MakeNormal(), samp.MakeBinormal(), +// samp.MakeTangent(), samp.MakeColor(info)); +// }; +// break; +// } +// +// func(tileMid + curX, yMid, heights[startYDiv + midDiv][i + midDiv]); +// +// int curXDiv = i; +// int curYDiv = startYDiv + CFluidPlaneRender::numSubdivisionsInTile; +// float curTileX = curX; +// float curTileY = yMin + info.x14_tileSize; +// for (int v = 0; v < (r19 ? CFluidPlaneRender::numSubdivisionsInTile : 1); ++v) { +// const CFluidPlaneRender::SHFieldSample& samp = heights[curYDiv][curXDiv + v]; +// func(curTileX, curTileY, samp); +// curTileX += info.x18_rippleResolution; +// } +// +// curXDiv = i + CFluidPlaneRender::numSubdivisionsInTile; +// curYDiv = startYDiv + CFluidPlaneRender::numSubdivisionsInTile; +// curTileX = curX + info.x14_tileSize; +// curTileY = yMin + info.x14_tileSize; +// for (int v = 0; v < (r18 ? CFluidPlaneRender::numSubdivisionsInTile : 1); ++v) { +// const CFluidPlaneRender::SHFieldSample& samp = heights[curYDiv - v][curXDiv]; +// func(curTileX, curTileY, samp); +// curTileY -= info.x18_rippleResolution; +// } +// +// curXDiv = i + CFluidPlaneRender::numSubdivisionsInTile; +// curYDiv = startYDiv; +// curTileX = curX + info.x14_tileSize; +// curTileY = yMin; +// for (int v = 0; v < (r17 ? CFluidPlaneRender::numSubdivisionsInTile : 1); ++v) { +// const CFluidPlaneRender::SHFieldSample& samp = heights[curYDiv][curXDiv - v]; +// func(curTileX, curTileY, samp); +// curTileX -= info.x18_rippleResolution; +// } +// +// curXDiv = i; +// curYDiv = startYDiv; +// curTileX = curX; +// curTileY = yMin; +// if (r16) { +// for (int v = 0; v < CFluidPlaneRender::numSubdivisionsInTile + 1; ++v) { +// const CFluidPlaneRender::SHFieldSample& samp = heights[curYDiv + v][curXDiv]; +// func(curTileX, curTileY, samp); +// curTileY += info.x18_rippleResolution; +// } +// } else { +// { +// const CFluidPlaneRender::SHFieldSample& samp = heights[curYDiv][curXDiv]; +// func(curTileX, curTileY, samp); +// } +// curTileY += info.x14_tileSize; +// { +// const CFluidPlaneRender::SHFieldSample& samp = +// heights[curYDiv + CFluidPlaneRender::numSubdivisionsInTile][curXDiv]; +// func(curTileX, curTileY, samp); +// } +// } +// +// // toStrip.Draw(); +// } +// } +// } +// } +// +// void CFluidPlane::RenderPatch(const CFluidPlaneRender::SPatchInfo& info, const Heights& heights, const Flags& flags, +// bool noRipples, bool flagIs1, std::vector& vOut, +// std::vector& pvOut) { +// OPTICK_EVENT(); +// if (noRipples) { +// m_shader->bindRegular(); +// +// float xMin = info.x4_localMin.x(); +// float yMin = info.x4_localMin.y(); +// float xMax = info.x18_rippleResolution * (info.x0_xSubdivs - 2) + xMin; +// float yMax = info.x18_rippleResolution * (info.x1_ySubdivs - 2) + yMin; +// +// switch (info.x37_normalMode) { +// case CFluidPlaneRender::NormalMode::None: { +// size_t start = vOut.size(); +// vOut.emplace_back(zeus::CVector3f(xMin, yMin, 0.f)); +// vOut.emplace_back(zeus::CVector3f(xMin, yMax, 0.f)); +// vOut.emplace_back(zeus::CVector3f(xMax, yMin, 0.f)); +// vOut.emplace_back(zeus::CVector3f(xMax, yMax, 0.f)); +// // CGraphics::DrawArray(start, 4); +// break; +// } +// case CFluidPlaneRender::NormalMode::NoNormals: { +// size_t start = vOut.size(); +// vOut.emplace_back(zeus::CVector3f(xMin, yMin, 0.f), zeus::skBlack); +// vOut.emplace_back(zeus::CVector3f(xMin, yMax, 0.f), zeus::skBlack); +// vOut.emplace_back(zeus::CVector3f(xMax, yMin, 0.f), zeus::skBlack); +// vOut.emplace_back(zeus::CVector3f(xMax, yMax, 0.f), zeus::skBlack); +// // CGraphics::DrawArray(start, 4); +// break; +// } +// case CFluidPlaneRender::NormalMode::Normals: { +// int yTiles = (info.x1_ySubdivs - 3) / CFluidPlaneRender::numSubdivisionsInTile + 1; +// int xTiles = (info.x0_xSubdivs - 3) / CFluidPlaneRender::numSubdivisionsInTile + 1; +// int xTileStart = info.x28_tileX + info.x2e_tileY * info.x2a_gridDimX; +// yMax = yMin; +// for (int curYTile = yTiles; curYTile > 0; +// --curYTile, yMax += info.x14_tileSize, xTileStart += info.x2a_gridDimX) { +// xMax = xMin; +// int nextXTile; +// for (int curXTile = 0; curXTile < xTiles; curXTile = nextXTile) { +// if (!info.x30_gridFlags || info.x30_gridFlags[xTileStart + curXTile]) { +// if (curYTile == yTiles || curYTile == 1 || curXTile == 0 || xTiles - 1 == curXTile) { +// TriFanToStrip toStrip(vOut); +// +// toStrip.EmplaceVert( +// zeus::CVector3f(xMax + 0.5f * info.x14_tileSize, yMax + 0.5f * info.x14_tileSize, 0.f), zeus::skUp, +// zeus::skBlack); +// +// float tmp = xMax; +// for (int v = 0; v < ((curYTile == 1) ? CFluidPlaneRender::numSubdivisionsInTile : 1); ++v) { +// toStrip.EmplaceVert(zeus::CVector3f(tmp, yMax + info.x14_tileSize, 0.f), zeus::skUp, zeus::skBlack); +// tmp += info.x18_rippleResolution; +// } +// +// tmp = yMax + info.x14_tileSize; +// for (int v = 0; v < ((xTiles - 1 == curXTile) ? CFluidPlaneRender::numSubdivisionsInTile : 1); ++v) { +// toStrip.EmplaceVert(zeus::CVector3f(xMax + info.x14_tileSize, tmp, 0.f), zeus::skUp, zeus::skBlack); +// tmp -= info.x18_rippleResolution; +// } +// +// tmp = xMax + info.x14_tileSize; +// for (int v = 0; v < ((curYTile == yTiles) ? CFluidPlaneRender::numSubdivisionsInTile : 1); ++v) { +// toStrip.EmplaceVert(zeus::CVector3f(tmp, yMax, 0.f), zeus::skUp, zeus::skBlack); +// tmp -= info.x18_rippleResolution; +// } +// +// tmp = yMax; +// for (int v = 0; v < ((curXTile == 0) ? CFluidPlaneRender::numSubdivisionsInTile : 1); ++v) { +// toStrip.EmplaceVert(zeus::CVector3f(xMax, tmp, 0.f), zeus::skUp, zeus::skBlack); +// tmp += info.x18_rippleResolution; +// } +// +// toStrip.EmplaceVert(zeus::CVector3f(xMax, yMax + info.x14_tileSize, 0.f), zeus::skUp, zeus::skBlack); +// +// // toStrip.Draw(); +// +// nextXTile = curXTile + 1; +// xMax += info.x14_tileSize; +// } else { +// nextXTile = curXTile + 1; +// while (nextXTile < xTiles - 1 && (!info.x30_gridFlags || info.x30_gridFlags[xTileStart + nextXTile])) +// ++nextXTile; +// +// size_t start = vOut.size(); +// for (int v = 0; v < nextXTile - curXTile + 1; ++v) { +// vOut.emplace_back(zeus::CVector3f(xMax, yMax, 0.f), zeus::skUp, zeus::skBlack); +// vOut.emplace_back(zeus::CVector3f(xMax, yMax + info.x14_tileSize, 0.f), zeus::skUp, zeus::skBlack); +// xMax += info.x14_tileSize; +// } +// // CGraphics::DrawArray(start, vOut.size() - start); +// +// ++nextXTile; +// if (nextXTile == xTiles) { +// --nextXTile; +// xMax -= info.x14_tileSize; +// } +// } +// } else { +// nextXTile = curXTile + 1; +// xMax += info.x14_tileSize; +// while (nextXTile < xTiles && !info.x30_gridFlags[xTileStart + nextXTile]) { +// xMax += info.x14_tileSize; +// ++nextXTile; +// } +// } +// } +// } +// break; +// } +// case CFluidPlaneRender::NormalMode::NBT: { +// if (flagIs1 || !info.x30_gridFlags) { +// size_t start = vOut.size(); +// vOut.emplace_back(zeus::CVector3f(xMin, yMin, 0.f), zeus::skUp, zeus::skForward, zeus::skRight, zeus::skBlack); +// vOut.emplace_back(zeus::CVector3f(xMin, yMax, 0.f), zeus::skUp, zeus::skForward, zeus::skRight, zeus::skBlack); +// vOut.emplace_back(zeus::CVector3f(xMax, yMin, 0.f), zeus::skUp, zeus::skForward, zeus::skRight, zeus::skBlack); +// vOut.emplace_back(zeus::CVector3f(xMax, yMax, 0.f), zeus::skUp, zeus::skForward, zeus::skRight, zeus::skBlack); +// // CGraphics::DrawArray(start, 4); +// } else { +// int xTiles = (info.x0_xSubdivs - 3) / CFluidPlaneRender::numSubdivisionsInTile + 1; +// int yTiles = (info.x1_ySubdivs - 3) / CFluidPlaneRender::numSubdivisionsInTile + 1; +// int xTileStart = info.x28_tileX + info.x2e_tileY * info.x2a_gridDimX; +// for (; yTiles > 0; --yTiles, yMin += info.x14_tileSize, xTileStart += info.x2a_gridDimX) { +// xMax = xMin; +// int nextXTile; +// for (int curXTile = 0; curXTile < xTiles; curXTile = nextXTile) { +// if (info.x30_gridFlags[xTileStart + curXTile]) { +// nextXTile = curXTile + 1; +// int tile = xTileStart + nextXTile; +// while (nextXTile < xTiles && info.x30_gridFlags[tile]) { +// ++nextXTile; +// ++tile; +// } +// +// size_t start = vOut.size(); +// for (int v = 0; v < nextXTile - curXTile + 1; ++v) { +// vOut.emplace_back(zeus::CVector3f(xMax, yMin, 0.f), zeus::skUp, zeus::skForward, zeus::skRight, +// zeus::skBlack); +// vOut.emplace_back(zeus::CVector3f(xMax, yMin + info.x14_tileSize, 0.f), zeus::skUp, zeus::skForward, +// zeus::skRight, zeus::skBlack); +// xMax += info.x14_tileSize; +// } +// // CGraphics::DrawArray(start, vOut.size() - start); +// } else { +// nextXTile = curXTile + 1; +// xMax += info.x14_tileSize; +// int tile = xTileStart + nextXTile; +// while (nextXTile < xTiles && !info.x30_gridFlags[tile]) { +// xMax += info.x14_tileSize; +// ++nextXTile; +// ++tile; +// } +// } +// } +// } +// } +// break; +// } +// } +// } else { +// float curY = info.x4_localMin.y(); +// for (int startYDiv = 1; startYDiv < info.x1_ySubdivs - 2; +// startYDiv += CFluidPlaneRender::numSubdivisionsInTile, curY += info.x14_tileSize) +// RenderStripWithRipples(curY, heights, flags, startYDiv, info, vOut, pvOut); +// } +// } } // namespace metaforce diff --git a/Runtime/World/CFluidPlane.hpp b/Runtime/World/CFluidPlane.hpp index e1bdd8a30..0cab6b79f 100644 --- a/Runtime/World/CFluidPlane.hpp +++ b/Runtime/World/CFluidPlane.hpp @@ -9,7 +9,6 @@ #include "Runtime/CToken.hpp" #include "Runtime/RetroTypes.hpp" #include "Runtime/Graphics/CTexture.hpp" -#include "Runtime/Graphics/Shaders/CFluidPlaneShader.hpp" #include "Runtime/World/CFluidUVMotion.hpp" #include @@ -116,6 +115,8 @@ public: }; }; +enum class EFluidType { NormalWater, PoisonWater, Lava, PhazonFluid, Four, ThickLava }; + class CFluidPlane { public: using Flags = std::array, 9>; @@ -133,20 +134,20 @@ protected: float x48_rippleIntensity; CFluidUVMotion x4c_uvMotion; - std::vector m_verts; - std::vector m_pVerts; - std::optional m_shader; + // std::vector m_verts; + // std::vector m_pVerts; + // std::optional m_shader; float ProjectRippleVelocity(float baseI, float velDot) const; float CalculateRippleIntensity(float baseI) const; - virtual void RenderStripWithRipples(float curY, const Heights& heights, const Flags& flags, int startYDiv, - const CFluidPlaneRender::SPatchInfo& info, - std::vector& vOut, - std::vector& pvOut); - void RenderPatch(const CFluidPlaneRender::SPatchInfo& info, const Heights& heights, const Flags& flags, - bool noRipples, bool flagIs1, std::vector& vOut, - std::vector& pvOut); + // virtual void RenderStripWithRipples(float curY, const Heights& heights, const Flags& flags, int startYDiv, + // const CFluidPlaneRender::SPatchInfo& info, + // std::vector& vOut, + // std::vector& pvOut); + // void RenderPatch(const CFluidPlaneRender::SPatchInfo& info, const Heights& heights, const Flags& flags, + // bool noRipples, bool flagIs1, std::vector& vOut, + // std::vector& pvOut); public: virtual ~CFluidPlane() = default; diff --git a/Runtime/World/CFluidPlaneCPU.cpp b/Runtime/World/CFluidPlaneCPU.cpp index e5bf24c76..4faf30f96 100644 --- a/Runtime/World/CFluidPlaneCPU.cpp +++ b/Runtime/World/CFluidPlaneCPU.cpp @@ -125,158 +125,158 @@ static void InitializeSineWave() { #define kEnableWaterBumpMaps true -CFluidPlaneShader::RenderSetupInfo CFluidPlaneCPU::RenderSetup(const CStateManager& mgr, float alpha, - const zeus::CTransform& xf, - const zeus::CTransform& areaXf, const zeus::CAABox& aabb, - const CScriptWater* water) { - OPTICK_EVENT(); - CFluidPlaneShader::RenderSetupInfo out; - - const float uvT = mgr.GetFluidPlaneManager()->GetUVT(); - const bool hasBumpMap = HasBumpMap() && kEnableWaterBumpMaps; - bool doubleLightmapBlend = false; - const bool hasEnvMap = mgr.GetCameraManager()->GetFluidCounter() == 0 && HasEnvMap(); - const bool hasEnvBumpMap = HasEnvBumpMap(); - InitializeSineWave(); - CGraphics::SetModelMatrix(xf); - - if (hasBumpMap) { - // Build 50% grey directional light with xf0_bumpLightDir and load into LIGHT_3 - // Light 3 in channel 1 - // Vertex colors in channel 0 - out.lights.resize(4); - out.lights[3] = CLight::BuildDirectional(xf0_bumpLightDir, zeus::skGrey); - } else { - // Normal light mask in channel 1 - // Vertex colors in channel 0 - out.lights = water->GetActorLights()->BuildLightVector(); - } - - int curTex = 3; - - if (hasBumpMap) { - // Load into next - curTex++; - } - - if (hasEnvMap) { - // Load into next - curTex++; - } - - if (hasEnvBumpMap) { - // Load into next - curTex++; - } - - const auto fluidUVs = x4c_uvMotion.CalculateFluidTextureOffset(uvT); - - out.texMtxs[0][0][0] = x4c_uvMotion.GetFluidLayers()[1].GetUVScale(); - out.texMtxs[0][1][1] = x4c_uvMotion.GetFluidLayers()[1].GetUVScale(); - out.texMtxs[0][3][0] = fluidUVs[1][0]; - out.texMtxs[0][3][1] = fluidUVs[1][1]; - - out.texMtxs[1][0][0] = x4c_uvMotion.GetFluidLayers()[2].GetUVScale(); - out.texMtxs[1][1][1] = x4c_uvMotion.GetFluidLayers()[2].GetUVScale(); - out.texMtxs[1][3][0] = fluidUVs[2][0]; - out.texMtxs[1][3][1] = fluidUVs[2][1]; - - out.texMtxs[2][0][0] = x4c_uvMotion.GetFluidLayers()[0].GetUVScale(); - out.texMtxs[2][1][1] = x4c_uvMotion.GetFluidLayers()[0].GetUVScale(); - out.texMtxs[2][3][0] = fluidUVs[0][0]; - out.texMtxs[2][3][1] = fluidUVs[0][1]; - - // Load normal mtx 0 with - out.normMtx = (zeus::CTransform::Scale(xfc_bumpScale) * CGraphics::g_ViewMatrix.getRotation().inverse()).toMatrix4f(); - - // Setup TCGs - int nextTexMtx = 3; - - if (hasEnvBumpMap) { - float pttScale; - if (hasEnvMap) - pttScale = 0.5f * (1.f - x118_reflectionSize); - else - pttScale = g_tweakGame->GetFluidEnvBumpScale() * x4c_uvMotion.GetFluidLayers()[0].GetUVScale(); - - // Load GX_TEXMTX3 with identity - zeus::CMatrix4f& texMtx = out.texMtxs[nextTexMtx++]; - texMtx[0][0] = pttScale; - texMtx[1][1] = pttScale; - texMtx[3][0] = 0.5f; - texMtx[3][1] = 0.5f; - // Load GX_PTTEXMTX0 with scale of pttScale - // Next: GX_TG_MTX2x4 GX_TG_NRM, GX_TEXMTX3, true, GX_PTTEXMTX0 - - out.indScale = 0.5f * (hasEnvMap ? x118_reflectionSize : 1.f); - // Load ind mtx with scale of (indScale, -indScale) - // Load envBumpMap into ind stage 0 with previous TCG - } - - if (hasEnvMap) { - float scale = std::max(aabb.max.x() - aabb.min.x(), aabb.max.y() - aabb.min.y()); - zeus::CMatrix4f& texMtx = out.texMtxs[nextTexMtx++]; - texMtx[0][0] = 1.f / scale; - texMtx[1][1] = 1.f / scale; - zeus::CVector3f center = aabb.center(); - texMtx[3][0] = 0.5f + -center.x() / scale; - texMtx[3][1] = 0.5f + -center.y() / scale; - // Next: GX_TG_MTX2x4 GX_TG_POS, mtxNext, false, GX_PTIDENTITY - } - - if (HasLightMap()) { - float lowLightBlend = 1.f; - const CGameArea* area = mgr.GetWorld()->GetAreaAlways(mgr.GetNextAreaId()); - float lightLevel = area->GetPostConstructed()->x1128_worldLightingLevel; - const CScriptWater* nextWater = water->GetNextConnectedWater(mgr); - if (std::fabs(water->GetMorphFactor()) < 0.00001f || !nextWater || !nextWater->GetFluidPlane().HasLightMap()) { - // Load lightmap - CalculateLightmapMatrix(areaXf, xf, aabb, out.texMtxs[nextTexMtx++]); - // Next: GX_TG_MTX2x4 GX_TG_POS, mtxNext, false, GX_PTIDENTITY - } else if (nextWater && nextWater->GetFluidPlane().HasLightMap()) { - if (std::fabs(water->GetMorphFactor() - 1.f) < 0.00001f) { - // Load lightmap - CalculateLightmapMatrix(areaXf, xf, aabb, out.texMtxs[nextTexMtx++]); - // Next: GX_TG_MTX2x4 GX_TG_POS, mtxNext, false, GX_PTIDENTITY - } else { - // Load lightmap - CalculateLightmapMatrix(areaXf, xf, aabb, out.texMtxs[nextTexMtx++]); - // Next: GX_TG_MTX2x4 GX_TG_POS, mtxNext, false, GX_PTIDENTITY - // Load lightmap - CalculateLightmapMatrix(areaXf, xf, aabb, out.texMtxs[nextTexMtx++]); - // Next: GX_TG_MTX2x4 GX_TG_POS, mtxNext, false, GX_PTIDENTITY - - float lum = lightLevel * water->GetMorphFactor(); - out.kColors[3] = zeus::CColor(lum, 1.f); - lowLightBlend = (1.f - water->GetMorphFactor()) / (1.f - lum); - doubleLightmapBlend = true; - } - } - - out.kColors[2] = zeus::CColor(lowLightBlend * lightLevel, 1.f); - } - - float waterPlaneOrthoDot = - xf.transposeRotate(zeus::skUp).dot(CGraphics::g_ViewMatrix.inverse().transposeRotate(zeus::skForward)); - if (waterPlaneOrthoDot < 0.f) - waterPlaneOrthoDot = -waterPlaneOrthoDot; - - out.kColors[0] = - zeus::CColor((1.f - waterPlaneOrthoDot) * (x110_specularMax - x10c_specularMin) + x10c_specularMin, alpha); - out.kColors[1] = zeus::CColor(x114_reflectionBlend, 1.f); - - if (!m_shader || m_cachedDoubleLightmapBlend != doubleLightmapBlend || - m_cachedAdditive != (mgr.GetThermalDrawFlag() == EThermalDrawFlag::Hot)) { - m_cachedDoubleLightmapBlend = doubleLightmapBlend; - m_cachedAdditive = mgr.GetThermalDrawFlag() == EThermalDrawFlag::Hot; -// m_shader.emplace(x44_fluidType, x10_texPattern1, x20_texPattern2, x30_texColor, xb0_bumpMap, xc0_envMap, -// xd0_envBumpMap, xe0_lightmap, -// m_tessellation ? CFluidPlaneManager::RippleMapTex : aurora::gfx::TextureHandle{}, -// m_cachedDoubleLightmapBlend, m_cachedAdditive, m_maxVertCount); - } - - return out; -} +// CFluidPlaneShader::RenderSetupInfo CFluidPlaneCPU::RenderSetup(const CStateManager& mgr, float alpha, +// const zeus::CTransform& xf, +// const zeus::CTransform& areaXf, const zeus::CAABox& aabb, +// const CScriptWater* water) { +// OPTICK_EVENT(); +// CFluidPlaneShader::RenderSetupInfo out; +// +// const float uvT = mgr.GetFluidPlaneManager()->GetUVT(); +// const bool hasBumpMap = HasBumpMap() && kEnableWaterBumpMaps; +// bool doubleLightmapBlend = false; +// const bool hasEnvMap = mgr.GetCameraManager()->GetFluidCounter() == 0 && HasEnvMap(); +// const bool hasEnvBumpMap = HasEnvBumpMap(); +// InitializeSineWave(); +// CGraphics::SetModelMatrix(xf); +// +// if (hasBumpMap) { +// // Build 50% grey directional light with xf0_bumpLightDir and load into LIGHT_3 +// // Light 3 in channel 1 +// // Vertex colors in channel 0 +// out.lights.resize(4); +// out.lights[3] = CLight::BuildDirectional(xf0_bumpLightDir, zeus::skGrey); +// } else { +// // Normal light mask in channel 1 +// // Vertex colors in channel 0 +// out.lights = water->GetActorLights()->BuildLightVector(); +// } +// +// int curTex = 3; +// +// if (hasBumpMap) { +// // Load into next +// curTex++; +// } +// +// if (hasEnvMap) { +// // Load into next +// curTex++; +// } +// +// if (hasEnvBumpMap) { +// // Load into next +// curTex++; +// } +// +// const auto fluidUVs = x4c_uvMotion.CalculateFluidTextureOffset(uvT); +// +// out.texMtxs[0][0][0] = x4c_uvMotion.GetFluidLayers()[1].GetUVScale(); +// out.texMtxs[0][1][1] = x4c_uvMotion.GetFluidLayers()[1].GetUVScale(); +// out.texMtxs[0][3][0] = fluidUVs[1][0]; +// out.texMtxs[0][3][1] = fluidUVs[1][1]; +// +// out.texMtxs[1][0][0] = x4c_uvMotion.GetFluidLayers()[2].GetUVScale(); +// out.texMtxs[1][1][1] = x4c_uvMotion.GetFluidLayers()[2].GetUVScale(); +// out.texMtxs[1][3][0] = fluidUVs[2][0]; +// out.texMtxs[1][3][1] = fluidUVs[2][1]; +// +// out.texMtxs[2][0][0] = x4c_uvMotion.GetFluidLayers()[0].GetUVScale(); +// out.texMtxs[2][1][1] = x4c_uvMotion.GetFluidLayers()[0].GetUVScale(); +// out.texMtxs[2][3][0] = fluidUVs[0][0]; +// out.texMtxs[2][3][1] = fluidUVs[0][1]; +// +// // Load normal mtx 0 with +// out.normMtx = (zeus::CTransform::Scale(xfc_bumpScale) * CGraphics::mViewMatrix.getRotation().inverse()).toMatrix4f(); +// +// // Setup TCGs +// int nextTexMtx = 3; +// +// if (hasEnvBumpMap) { +// float pttScale; +// if (hasEnvMap) +// pttScale = 0.5f * (1.f - x118_reflectionSize); +// else +// pttScale = g_tweakGame->GetFluidEnvBumpScale() * x4c_uvMotion.GetFluidLayers()[0].GetUVScale(); +// +// // Load GX_TEXMTX3 with identity +// zeus::CMatrix4f& texMtx = out.texMtxs[nextTexMtx++]; +// texMtx[0][0] = pttScale; +// texMtx[1][1] = pttScale; +// texMtx[3][0] = 0.5f; +// texMtx[3][1] = 0.5f; +// // Load GX_PTTEXMTX0 with scale of pttScale +// // Next: GX_TG_MTX2x4 GX_TG_NRM, GX_TEXMTX3, true, GX_PTTEXMTX0 +// +// out.indScale = 0.5f * (hasEnvMap ? x118_reflectionSize : 1.f); +// // Load ind mtx with scale of (indScale, -indScale) +// // Load envBumpMap into ind stage 0 with previous TCG +// } +// +// if (hasEnvMap) { +// float scale = std::max(aabb.max.x() - aabb.min.x(), aabb.max.y() - aabb.min.y()); +// zeus::CMatrix4f& texMtx = out.texMtxs[nextTexMtx++]; +// texMtx[0][0] = 1.f / scale; +// texMtx[1][1] = 1.f / scale; +// zeus::CVector3f center = aabb.center(); +// texMtx[3][0] = 0.5f + -center.x() / scale; +// texMtx[3][1] = 0.5f + -center.y() / scale; +// // Next: GX_TG_MTX2x4 GX_TG_POS, mtxNext, false, GX_PTIDENTITY +// } +// +// if (HasLightMap()) { +// float lowLightBlend = 1.f; +// const CGameArea* area = mgr.GetWorld()->GetAreaAlways(mgr.GetNextAreaId()); +// float lightLevel = area->GetPostConstructed()->x1128_worldLightingLevel; +// const CScriptWater* nextWater = water->GetNextConnectedWater(mgr); +// if (std::fabs(water->GetMorphFactor()) < 0.00001f || !nextWater || !nextWater->GetFluidPlane().HasLightMap()) { +// // Load lightmap +// CalculateLightmapMatrix(areaXf, xf, aabb, out.texMtxs[nextTexMtx++]); +// // Next: GX_TG_MTX2x4 GX_TG_POS, mtxNext, false, GX_PTIDENTITY +// } else if (nextWater && nextWater->GetFluidPlane().HasLightMap()) { +// if (std::fabs(water->GetMorphFactor() - 1.f) < 0.00001f) { +// // Load lightmap +// CalculateLightmapMatrix(areaXf, xf, aabb, out.texMtxs[nextTexMtx++]); +// // Next: GX_TG_MTX2x4 GX_TG_POS, mtxNext, false, GX_PTIDENTITY +// } else { +// // Load lightmap +// CalculateLightmapMatrix(areaXf, xf, aabb, out.texMtxs[nextTexMtx++]); +// // Next: GX_TG_MTX2x4 GX_TG_POS, mtxNext, false, GX_PTIDENTITY +// // Load lightmap +// CalculateLightmapMatrix(areaXf, xf, aabb, out.texMtxs[nextTexMtx++]); +// // Next: GX_TG_MTX2x4 GX_TG_POS, mtxNext, false, GX_PTIDENTITY +// +// float lum = lightLevel * water->GetMorphFactor(); +// out.kColors[3] = zeus::CColor(lum, 1.f); +// lowLightBlend = (1.f - water->GetMorphFactor()) / (1.f - lum); +// doubleLightmapBlend = true; +// } +// } +// +// out.kColors[2] = zeus::CColor(lowLightBlend * lightLevel, 1.f); +// } +// +// float waterPlaneOrthoDot = +// xf.transposeRotate(zeus::skUp).dot(CGraphics::mViewMatrix.inverse().transposeRotate(zeus::skForward)); +// if (waterPlaneOrthoDot < 0.f) +// waterPlaneOrthoDot = -waterPlaneOrthoDot; +// +// out.kColors[0] = +// zeus::CColor((1.f - waterPlaneOrthoDot) * (x110_specularMax - x10c_specularMin) + x10c_specularMin, alpha); +// out.kColors[1] = zeus::CColor(x114_reflectionBlend, 1.f); +// +// if (!m_shader || m_cachedDoubleLightmapBlend != doubleLightmapBlend || +// m_cachedAdditive != (mgr.GetThermalDrawFlag() == EThermalDrawFlag::Hot)) { +// m_cachedDoubleLightmapBlend = doubleLightmapBlend; +// m_cachedAdditive = mgr.GetThermalDrawFlag() == EThermalDrawFlag::Hot; +// // m_shader.emplace(x44_fluidType, x10_texPattern1, x20_texPattern2, x30_texColor, xb0_bumpMap, xc0_envMap, +// // xd0_envBumpMap, xe0_lightmap, +// // m_tessellation ? CFluidPlaneManager::RippleMapTex : aurora::gfx::TextureHandle{}, +// // m_cachedDoubleLightmapBlend, m_cachedAdditive, m_maxVertCount); +// } +// +// return out; +// } int CFluidPlaneRender::numTilesInHField; int CFluidPlaneRender::numSubdivisionsInTile; @@ -743,7 +743,7 @@ void CFluidPlaneCPU::Render(const CStateManager& mgr, float alpha, const zeus::C const bool* gridFlags, u32 gridDimX, u32 gridDimY, const zeus::CVector3f& areaCenter) { SCOPED_GRAPHICS_DEBUG_GROUP("CFluidPlaneCPU::Render", zeus::skCyan); TCastToConstPtr water = mgr.GetObjectById(waterId); - CFluidPlaneShader::RenderSetupInfo setupInfo = RenderSetup(mgr, alpha, xf, areaXf, aabb, water.GetPtr()); + // CFluidPlaneShader::RenderSetupInfo setupInfo = RenderSetup(mgr, alpha, xf, areaXf, aabb, water.GetPtr()); // if (!m_shader->isReady()) // return; @@ -807,17 +807,17 @@ void CFluidPlaneCPU::Render(const CStateManager& mgr, float alpha, const zeus::C u32 patchDimX = (water && water->GetPatchDimensionX()) ? water->GetPatchDimensionX() : 128; u32 patchDimY = (water && water->GetPatchDimensionY()) ? water->GetPatchDimensionY() : 128; - m_verts.clear(); - m_pVerts.clear(); + // m_verts.clear(); + // m_pVerts.clear(); if (m_tessellation) { /* Additional uniform data for tessellation evaluation shader */ zeus::CColor colorMul; colorMul.r() = wavecapIntensityScale / 255.f / float(1 << redShift); colorMul.g() = wavecapIntensityScale / 255.f / float(1 << greenShift); colorMul.b() = wavecapIntensityScale / 255.f / float(1 << blueShift); - m_shader->prepareDraw(setupInfo, xf.origin, *rippleManager, colorMul, x108_rippleResolution / 4.f); + // m_shader->prepareDraw(setupInfo, xf.origin, *rippleManager, colorMul, x108_rippleResolution / 4.f); } else { - m_shader->prepareDraw(setupInfo); + // m_shader->prepareDraw(setupInfo); } u32 tileY = 0; @@ -857,7 +857,7 @@ void CFluidPlaneCPU::Render(const CStateManager& mgr, float alpha, const zeus::C bool noRipples = UpdatePatch(mgr.GetFluidPlaneManager()->GetUVT(), info, lc_heights, lc_flags, areaCenter, rippleManager, fromX, toX, fromY, toY); - RenderPatch(info, lc_heights, lc_flags, noRipples, renderFlags == 1, m_verts, m_pVerts); + // RenderPatch(info, lc_heights, lc_flags, noRipples, renderFlags == 1, m_verts, m_pVerts); } } curX += ripplePitch.x(); @@ -867,8 +867,8 @@ void CFluidPlaneCPU::Render(const CStateManager& mgr, float alpha, const zeus::C tileY += CFluidPlaneRender::numTilesInHField; } - m_shader->loadVerts(m_verts, m_pVerts); - m_shader->doneDrawing(); + // m_shader->loadVerts(m_verts, m_pVerts); + // m_shader->doneDrawing(); } } // namespace metaforce diff --git a/Runtime/World/CFluidPlaneCPU.hpp b/Runtime/World/CFluidPlaneCPU.hpp index 5d5329f5c..4bafdf193 100644 --- a/Runtime/World/CFluidPlaneCPU.hpp +++ b/Runtime/World/CFluidPlaneCPU.hpp @@ -91,9 +91,9 @@ public: void CreateRipple(const CRipple& ripple, CStateManager& mgr); void CalculateLightmapMatrix(const zeus::CTransform& areaXf, const zeus::CTransform& xf, const zeus::CAABox& aabb, zeus::CMatrix4f& mtxOut) const; - CFluidPlaneShader::RenderSetupInfo RenderSetup(const CStateManager& mgr, float, const zeus::CTransform& xf, - const zeus::CTransform& areaXf, const zeus::CAABox& aabb, - const CScriptWater* water); + // CFluidPlaneShader::RenderSetupInfo RenderSetup(const CStateManager& mgr, float, const zeus::CTransform& xf, + // const zeus::CTransform& areaXf, const zeus::CAABox& aabb, + // const CScriptWater* water); void Render(const CStateManager& mgr, float alpha, const zeus::CAABox& aabb, const zeus::CTransform& xf, const zeus::CTransform& areaXf, bool noNormals, const zeus::CFrustum& frustum, const std::optional& rippleManager, TUniqueId waterId, const bool* gridFlags, diff --git a/Runtime/World/CFluidPlaneDoor.cpp b/Runtime/World/CFluidPlaneDoor.cpp index 4f80c7f87..0820b6a1a 100644 --- a/Runtime/World/CFluidPlaneDoor.cpp +++ b/Runtime/World/CFluidPlaneDoor.cpp @@ -13,43 +13,43 @@ CFluidPlaneDoor::CFluidPlaneDoor(CAssetId patternTex1, CAssetId patternTex2, CAs , xa4_tileSubdivisions(tileSubdivisions & ~0x1) , xa8_rippleResolution(xa0_tileSize / float(xa4_tileSubdivisions)) {} -CFluidPlaneShader::RenderSetupInfo CFluidPlaneDoor::RenderSetup(const CStateManager& mgr, float alpha, - const zeus::CTransform& xf, const zeus::CAABox& aabb, - bool noNormals) { - CFluidPlaneShader::RenderSetupInfo out; - - const float uvT = mgr.GetFluidPlaneManager()->GetUVT(); - CGraphics::SetModelMatrix(xf); - - const auto fluidUVs = x4c_uvMotion.CalculateFluidTextureOffset(uvT); - - out.texMtxs[0][0][0] = x4c_uvMotion.GetFluidLayers()[1].GetUVScale(); - out.texMtxs[0][1][1] = x4c_uvMotion.GetFluidLayers()[1].GetUVScale(); - out.texMtxs[0][3][0] = fluidUVs[1][0]; - out.texMtxs[0][3][1] = fluidUVs[1][1]; - - out.texMtxs[1][0][0] = x4c_uvMotion.GetFluidLayers()[2].GetUVScale(); - out.texMtxs[1][1][1] = x4c_uvMotion.GetFluidLayers()[2].GetUVScale(); - out.texMtxs[1][3][0] = fluidUVs[2][0]; - out.texMtxs[1][3][1] = fluidUVs[2][1]; - - out.texMtxs[2][0][0] = x4c_uvMotion.GetFluidLayers()[0].GetUVScale(); - out.texMtxs[2][1][1] = x4c_uvMotion.GetFluidLayers()[0].GetUVScale(); - out.texMtxs[2][3][0] = fluidUVs[0][0]; - out.texMtxs[2][3][1] = fluidUVs[0][1]; - - out.kColors[0] = zeus::CColor(1.f, alpha); - - if (!m_shader) { - auto gridDimX = u32((xa0_tileSize + aabb.max.x() - aabb.min.x() - 0.01f) / xa0_tileSize); - auto gridDimY = u32((xa0_tileSize + aabb.max.y() - aabb.min.y() - 0.01f) / xa0_tileSize); - u32 gridCellCount = (gridDimX + 1) * (gridDimY + 1); - u32 maxVerts = gridCellCount * ((std::max(2, xa4_tileSubdivisions) * 4 + 2) * 4); - m_shader.emplace(x10_texPattern1, x20_texPattern2, x30_texColor, maxVerts); - } - - return out; -} +// CFluidPlaneShader::RenderSetupInfo CFluidPlaneDoor::RenderSetup(const CStateManager& mgr, float alpha, +// const zeus::CTransform& xf, const zeus::CAABox& aabb, +// bool noNormals) { +// CFluidPlaneShader::RenderSetupInfo out; +// +// const float uvT = mgr.GetFluidPlaneManager()->GetUVT(); +// CGraphics::SetModelMatrix(xf); +// +// const auto fluidUVs = x4c_uvMotion.CalculateFluidTextureOffset(uvT); +// +// out.texMtxs[0][0][0] = x4c_uvMotion.GetFluidLayers()[1].GetUVScale(); +// out.texMtxs[0][1][1] = x4c_uvMotion.GetFluidLayers()[1].GetUVScale(); +// out.texMtxs[0][3][0] = fluidUVs[1][0]; +// out.texMtxs[0][3][1] = fluidUVs[1][1]; +// +// out.texMtxs[1][0][0] = x4c_uvMotion.GetFluidLayers()[2].GetUVScale(); +// out.texMtxs[1][1][1] = x4c_uvMotion.GetFluidLayers()[2].GetUVScale(); +// out.texMtxs[1][3][0] = fluidUVs[2][0]; +// out.texMtxs[1][3][1] = fluidUVs[2][1]; +// +// out.texMtxs[2][0][0] = x4c_uvMotion.GetFluidLayers()[0].GetUVScale(); +// out.texMtxs[2][1][1] = x4c_uvMotion.GetFluidLayers()[0].GetUVScale(); +// out.texMtxs[2][3][0] = fluidUVs[0][0]; +// out.texMtxs[2][3][1] = fluidUVs[0][1]; +// +// out.kColors[0] = zeus::CColor(1.f, alpha); +// +// if (!m_shader) { +// auto gridDimX = u32((xa0_tileSize + aabb.max.x() - aabb.min.x() - 0.01f) / xa0_tileSize); +// auto gridDimY = u32((xa0_tileSize + aabb.max.y() - aabb.min.y() - 0.01f) / xa0_tileSize); +// u32 gridCellCount = (gridDimX + 1) * (gridDimY + 1); +// u32 maxVerts = gridCellCount * ((std::max(2, xa4_tileSubdivisions) * 4 + 2) * 4); +// m_shader.emplace(x10_texPattern1, x20_texPattern2, x30_texColor, maxVerts); +// } +// +// return out; +// } // Used to be part of locked cache // These are too big for stack allocation @@ -62,7 +62,7 @@ void CFluidPlaneDoor::Render(const CStateManager& mgr, float alpha, const zeus:: TUniqueId waterId, const bool* gridFlags, u32 gridDimX, u32 gridDimY, const zeus::CVector3f& areaCenter) { SCOPED_GRAPHICS_DEBUG_GROUP("CFluidPlaneDoor::Render", zeus::skCyan); - CFluidPlaneShader::RenderSetupInfo setupInfo = RenderSetup(mgr, alpha, xf, aabb, noNormals); + // CFluidPlaneShader::RenderSetupInfo setupInfo = RenderSetup(mgr, alpha, xf, aabb, noNormals); // if (!m_shader->isReady()) // return; @@ -74,9 +74,9 @@ void CFluidPlaneDoor::Render(const CStateManager& mgr, float alpha, const zeus:: float patchSize = xa8_rippleResolution * CFluidPlaneRender::numSubdivisionsInHField; float ooSubdivSize = 1.f / xa8_rippleResolution; - m_verts.clear(); - m_pVerts.clear(); - m_shader->prepareDraw(setupInfo); + // m_verts.clear(); + // m_pVerts.clear(); + // m_shader->prepareDraw(setupInfo); for (float curX = aabb.min.x(); curX < aabb.max.x(); curX += patchSize) { float remSubdivsX = (aabb.max.x() - curX) * ooSubdivSize; @@ -92,13 +92,13 @@ void CFluidPlaneDoor::Render(const CStateManager& mgr, float alpha, const zeus:: CFluidPlaneRender::numSubdivisionsInHField, CFluidPlaneRender::NormalMode::None, 0, 0, 0, 0, 0, 0, 0, nullptr); - RenderPatch(patchInfo, lc_heights, lc_flags, true, true, m_verts, m_pVerts); + // RenderPatch(patchInfo, lc_heights, lc_flags, true, true, m_verts, m_pVerts); } } } - m_shader->loadVerts(m_verts, m_pVerts); - m_shader->doneDrawing(); + // m_shader->loadVerts(m_verts, m_pVerts); + // m_shader->doneDrawing(); } } // namespace metaforce \ No newline at end of file diff --git a/Runtime/World/CFluidPlaneDoor.hpp b/Runtime/World/CFluidPlaneDoor.hpp index 333c6df41..19484a443 100644 --- a/Runtime/World/CFluidPlaneDoor.hpp +++ b/Runtime/World/CFluidPlaneDoor.hpp @@ -2,7 +2,6 @@ #include -#include "Runtime/Graphics/Shaders/CFluidPlaneShader.hpp" #include "Runtime/World/CFluidPlane.hpp" namespace metaforce { @@ -11,8 +10,8 @@ class CFluidPlaneDoor final : public CFluidPlane { int xa4_tileSubdivisions; float xa8_rippleResolution; - CFluidPlaneShader::RenderSetupInfo RenderSetup(const CStateManager& mgr, float alpha, const zeus::CTransform& xf, - const zeus::CAABox& aabb, bool noNormals); + // CFluidPlaneShader::RenderSetupInfo RenderSetup(const CStateManager& mgr, float alpha, const zeus::CTransform& xf, + // const zeus::CAABox& aabb, bool noNormals); public: CFluidPlaneDoor(CAssetId patternTex1, CAssetId patternTex2, CAssetId colorTex, float tileSize, u32 tileSubdivisions, diff --git a/Runtime/World/CFluidPlaneGPU.cpp b/Runtime/World/CFluidPlaneGPU.cpp index 4991eb794..49dd57622 100644 --- a/Runtime/World/CFluidPlaneGPU.cpp +++ b/Runtime/World/CFluidPlaneGPU.cpp @@ -17,65 +17,65 @@ CFluidPlaneGPU::CFluidPlaneGPU(CAssetId texPattern1, CAssetId texPattern2, CAsse m_tessellation = true; } -void CFluidPlaneGPU::RenderStripWithRipples(float curY, const Heights& heights, const Flags& flags, int startYDiv, - const CFluidPlaneRender::SPatchInfo& info, - std::vector& vOut, - std::vector& pvOut) { - m_shader->bindTessellation(); - - int yTile = (startYDiv + CFluidPlaneRender::numSubdivisionsInTile - 1) / CFluidPlaneRender::numSubdivisionsInTile; - int endXTile = - (info.x0_xSubdivs + CFluidPlaneRender::numSubdivisionsInTile - 4) / CFluidPlaneRender::numSubdivisionsInTile; - - float yMin = curY; - float subdivF = CFluidPlaneRender::numSubdivisionsInTile; - - float curX = info.x4_localMin.x(); - int gridCell = info.x28_tileX + info.x2a_gridDimX * (info.x2e_tileY + yTile - 1); - int xTile = 1; - int tileSpan; - for (int i = 1; i < info.x0_xSubdivs - 2; i += CFluidPlaneRender::numSubdivisionsInTile * tileSpan, - gridCell += tileSpan, xTile += tileSpan, curX += info.x14_tileSize * tileSpan) { - tileSpan = 1; - if (info.x30_gridFlags && !info.x30_gridFlags[gridCell]) - continue; - - CFluidPlaneShader::PatchVertex pv; - size_t start = pvOut.size(); - - if ((flags[yTile][xTile] & 0x1f) == 0x1f) { - for (; xTile + tileSpan <= endXTile; ++tileSpan) { - if ((flags[yTile][xTile + tileSpan] & 0x1f) != 0x1f) - break; - if (info.x30_gridFlags && !info.x30_gridFlags[gridCell + tileSpan]) - break; - } - - pv.m_outerLevels.fill(subdivF); - pv.m_innerLevels.fill(subdivF); - } else { - const bool north = (flags[yTile + 1][xTile] & 0x2) != 0; - const bool west = (flags[yTile][xTile - 1] & 0x8) != 0; - const bool east = (flags[yTile][xTile + 1] & 0x4) != 0; - const bool south = (flags[yTile - 1][xTile] & 0x1) != 0; - - pv.m_outerLevels[0] = west ? subdivF : 1.f; - pv.m_outerLevels[1] = south ? subdivF : 1.f; - pv.m_outerLevels[2] = east ? subdivF : 1.f; - pv.m_outerLevels[3] = north ? subdivF : 1.f; - pv.m_innerLevels.fill(subdivF); - } - - float curTileY = yMin; - float curTileX = curX; - for (int t = 0; t < tileSpan; ++t) { - pv.m_pos = zeus::CVector4f(curTileX, curTileY, curTileX + info.x14_tileSize, curTileY + info.x14_tileSize); - pvOut.push_back(pv); - curTileX += info.x14_tileSize; - } - -// CGraphics::DrawArray(start, pvOut.size() - start); - } -} +// void CFluidPlaneGPU::RenderStripWithRipples(float curY, const Heights& heights, const Flags& flags, int startYDiv, +// const CFluidPlaneRender::SPatchInfo& info, +// std::vector& vOut, +// std::vector& pvOut) { +// m_shader->bindTessellation(); +// +// int yTile = (startYDiv + CFluidPlaneRender::numSubdivisionsInTile - 1) / CFluidPlaneRender::numSubdivisionsInTile; +// int endXTile = +// (info.x0_xSubdivs + CFluidPlaneRender::numSubdivisionsInTile - 4) / CFluidPlaneRender::numSubdivisionsInTile; +// +// float yMin = curY; +// float subdivF = CFluidPlaneRender::numSubdivisionsInTile; +// +// float curX = info.x4_localMin.x(); +// int gridCell = info.x28_tileX + info.x2a_gridDimX * (info.x2e_tileY + yTile - 1); +// int xTile = 1; +// int tileSpan; +// for (int i = 1; i < info.x0_xSubdivs - 2; i += CFluidPlaneRender::numSubdivisionsInTile * tileSpan, +// gridCell += tileSpan, xTile += tileSpan, curX += info.x14_tileSize * tileSpan) { +// tileSpan = 1; +// if (info.x30_gridFlags && !info.x30_gridFlags[gridCell]) +// continue; +// +// CFluidPlaneShader::PatchVertex pv; +// size_t start = pvOut.size(); +// +// if ((flags[yTile][xTile] & 0x1f) == 0x1f) { +// for (; xTile + tileSpan <= endXTile; ++tileSpan) { +// if ((flags[yTile][xTile + tileSpan] & 0x1f) != 0x1f) +// break; +// if (info.x30_gridFlags && !info.x30_gridFlags[gridCell + tileSpan]) +// break; +// } +// +// pv.m_outerLevels.fill(subdivF); +// pv.m_innerLevels.fill(subdivF); +// } else { +// const bool north = (flags[yTile + 1][xTile] & 0x2) != 0; +// const bool west = (flags[yTile][xTile - 1] & 0x8) != 0; +// const bool east = (flags[yTile][xTile + 1] & 0x4) != 0; +// const bool south = (flags[yTile - 1][xTile] & 0x1) != 0; +// +// pv.m_outerLevels[0] = west ? subdivF : 1.f; +// pv.m_outerLevels[1] = south ? subdivF : 1.f; +// pv.m_outerLevels[2] = east ? subdivF : 1.f; +// pv.m_outerLevels[3] = north ? subdivF : 1.f; +// pv.m_innerLevels.fill(subdivF); +// } +// +// float curTileY = yMin; +// float curTileX = curX; +// for (int t = 0; t < tileSpan; ++t) { +// pv.m_pos = zeus::CVector4f(curTileX, curTileY, curTileX + info.x14_tileSize, curTileY + info.x14_tileSize); +// pvOut.push_back(pv); +// curTileX += info.x14_tileSize; +// } +// +// // CGraphics::DrawArray(start, pvOut.size() - start); +// } +// } } // namespace metaforce diff --git a/Runtime/World/CFluidPlaneGPU.hpp b/Runtime/World/CFluidPlaneGPU.hpp index e1f796bd9..ef5fdaea2 100644 --- a/Runtime/World/CFluidPlaneGPU.hpp +++ b/Runtime/World/CFluidPlaneGPU.hpp @@ -17,9 +17,9 @@ public: float turbAmplitudeMin, float specularMin, float specularMax, float reflectionBlend, float reflectionSize, float rippleIntensity, u32 maxVertCount); - void RenderStripWithRipples(float curY, const Heights& heights, const Flags& flags, int startYDiv, - const CFluidPlaneRender::SPatchInfo& info, std::vector& vOut, - std::vector& pvOut) override; + // void RenderStripWithRipples(float curY, const Heights& heights, const Flags& flags, int startYDiv, + // const CFluidPlaneRender::SPatchInfo& info, std::vector& vOut, + // std::vector& pvOut) override; }; } // namespace metaforce diff --git a/Runtime/World/CGameArea.cpp b/Runtime/World/CGameArea.cpp index b989c6d43..3d9875050 100644 --- a/Runtime/World/CGameArea.cpp +++ b/Runtime/World/CGameArea.cpp @@ -890,23 +890,23 @@ void CGameArea::PostConstructArea() { auto secIt = m_resolvedBufs.begin() + 3; x12c_postConstructed->x4c_insts.resize(header.modelCount); for (u32 i = 0; i < header.modelCount; ++i) { - u32 surfCount = CBasics::SwapBytes(*reinterpret_cast((secIt + 6)->first)); + u32 surfCount = CBasics::SwapBytes(*reinterpret_cast((secIt + 6)->data())); secIt += 7 + surfCount; } /* Render octree */ if (header.version > 14 && header.arotSecIdx != -1) { - x12c_postConstructed->xc_octTree.emplace(secIt->first); + x12c_postConstructed->xc_octTree.emplace(secIt->data()); ++secIt; } /* Scriptable layer section */ - x12c_postConstructed->x10c8_sclyBuf = secIt->first; - x12c_postConstructed->x10d0_sclySize = secIt->second; + x12c_postConstructed->x10c8_sclyBuf = secIt->data(); + x12c_postConstructed->x10d0_sclySize = secIt->size_bytes(); ++secIt; /* Collision section */ - x12c_postConstructed->x0_collision = CAreaOctTree::MakeFromMemory(secIt->first, secIt->second); + x12c_postConstructed->x0_collision = CAreaOctTree::MakeFromMemory(secIt->data(), secIt->size_bytes()); ++secIt; /* Unknown section */ @@ -914,7 +914,7 @@ void CGameArea::PostConstructArea() { /* Lights section */ if (header.version > 6) { - CMemoryInStream r(secIt->first, secIt->second, CMemoryInStream::EOwnerShip::NotOwned); + CMemoryInStream r(secIt->data(), secIt->size_bytes(), CMemoryInStream::EOwnerShip::NotOwned); u32 magic = r.ReadLong(); u32 aCount = magic; if (magic == 0xBABEDEAD) { @@ -947,8 +947,8 @@ void CGameArea::PostConstructArea() { /* PVS section */ if (header.version > 7) { - CMemoryInStream r(secIt->first, secIt->second, CMemoryInStream::EOwnerShip::NotOwned); - if (secIt->second > 0) { // TODO this works around CMemoryInStream inf loop on 0 len + CMemoryInStream r(secIt->data(), secIt->size_bytes(), CMemoryInStream::EOwnerShip::NotOwned); + if (secIt->size() > 0) { // TODO this works around CMemoryInStream inf loop on 0 len u32 magic = r.ReadLong(); if (magic == 'VISI') { x12c_postConstructed->x10a8_pvsVersion = r.ReadLong(); @@ -956,7 +956,7 @@ void CGameArea::PostConstructArea() { x12c_postConstructed->x1108_29_pvsHasActors = r.ReadBool(); x12c_postConstructed->x1108_30_ = r.ReadBool(); x12c_postConstructed->xa0_pvs = - std::make_unique(secIt->first + r.GetReadPosition(), secIt->second - r.GetReadPosition()); + std::make_unique(secIt->data() + r.GetReadPosition(), secIt->size_bytes() - r.GetReadPosition()); } } } @@ -966,7 +966,7 @@ void CGameArea::PostConstructArea() { /* Pathfinding section */ if (header.version > 9) { - CMemoryInStream r(secIt->first, secIt->second, CMemoryInStream::EOwnerShip::NotOwned); + CMemoryInStream r(secIt->data(), secIt->size_bytes(), CMemoryInStream::EOwnerShip::NotOwned); CAssetId pathId = r.Get(); x12c_postConstructed->x10ac_pathToken = g_SimplePool->GetObj(SObjectTag{FOURCC('PATH'), pathId}); x12c_postConstructed->x10bc_pathArea = x12c_postConstructed->x10ac_pathToken.GetObj(); @@ -1023,13 +1023,13 @@ void CGameArea::FillInStaticGeometry() { auto colors = *iter++; auto texCoords = *iter++; auto packedTexCoords = *iter++; - u32 surfaceCount = CBasics::SwapBytes(*reinterpret_cast(iter++->first)); + u32 surfaceCount = CBasics::SwapBytes(*reinterpret_cast(iter++->data())); if (surfaceCount != 0) { std::vector surfaces; surfaces.reserve(surfaceCount); for (int idx = 0; idx < surfaceCount; ++idx) { - auto [ptr, len] = *iter++; - surfaces.emplace_back(ptr, len); + const auto sp = *iter++; + surfaces.emplace_back(sp.data(), sp.size()); } inst = CMetroidModelInstance{ modelHeader, x12c_postConstructed->x10d4_firstMatPtr, diff --git a/Runtime/World/CGameArea.hpp b/Runtime/World/CGameArea.hpp index e8dea52f0..15b4e0347 100644 --- a/Runtime/World/CGameArea.hpp +++ b/Runtime/World/CGameArea.hpp @@ -255,7 +255,7 @@ public: private: std::vector, int>> x110_mreaSecBufs; - std::vector> m_resolvedBufs; + std::vector> m_resolvedBufs; u32 x124_secCount = 0; u32 x128_mreaDataOffset = 0; std::unique_ptr x12c_postConstructed; diff --git a/Runtime/World/CMorphBallShadow.cpp b/Runtime/World/CMorphBallShadow.cpp index ecffe6a7d..061ebe6f8 100644 --- a/Runtime/World/CMorphBallShadow.cpp +++ b/Runtime/World/CMorphBallShadow.cpp @@ -35,13 +35,14 @@ void CMorphBallShadow::RenderIdBuffer(const zeus::CAABox& aabb, const CStateMana GatherAreas(mgr); - SViewport backupVp = CGraphics::g_Viewport; + CViewport backupVp = CGraphics::mViewport; // g_Renderer->BindBallShadowIdTarget(); // CGraphics::g_BooMainCommandQueue->clearTarget(); - zeus::CTransform backupViewMtx = CGraphics::g_ViewMatrix; - CGraphics::CProjectionState backupProjection = CGraphics::g_Proj; - zeus::CVector2f backupDepth = CGraphics::g_CachedDepthRange; + zeus::CTransform backupViewMtx = CGraphics::mViewMatrix; + CGraphics::CProjectionState backupProjection = CGraphics::mProj; + float backupDepthNear = CGraphics::mDepthNear; + float backupDepthFar = CGraphics::mDepthFar; zeus::CTransform viewMtx( zeus::skRight, zeus::skDown, zeus::skForward, zeus::CVector3f((aabb.min.x() + aabb.max.x()) * 0.5f, (aabb.min.y() + aabb.max.y()) * 0.5f, aabb.max.z())); @@ -90,8 +91,8 @@ void CMorphBallShadow::RenderIdBuffer(const zeus::CAABox& aabb, const CStateMana // g_Renderer->BindMainDrawTarget(); CGraphics::SetViewPointMatrix(backupViewMtx); CGraphics::SetProjectionState(backupProjection); - g_Renderer->SetViewport(backupVp.x0_left, backupVp.x4_top, backupVp.x8_width, backupVp.xc_height); - CGraphics::SetDepthRange(backupDepth[0], backupDepth[1]); + g_Renderer->SetViewport(backupVp.mLeft, backupVp.mTop, backupVp.mWidth, backupVp.mHeight); + CGraphics::SetDepthRange(backupDepthNear, backupDepthFar); xd0_hasIds = alphaVal != 4; } diff --git a/Runtime/World/CPathFindSearch.cpp b/Runtime/World/CPathFindSearch.cpp index 0cc8a912f..f8a74fc05 100644 --- a/Runtime/World/CPathFindSearch.cpp +++ b/Runtime/World/CPathFindSearch.cpp @@ -351,10 +351,10 @@ bool CPathFindSearch::Search(rstl::reserved_vector& regs1, const } void CPathFindVisualizer::Draw(const CPathFindSearch& path) { - m_spline.Reset(); - for (const auto& wp : path.GetWaypoints()) - m_spline.AddVertex(wp, zeus::skBlue, 2.f); - m_spline.Render(); + // m_spline.Reset(); + // for (const auto& wp : path.GetWaypoints()) + // m_spline.AddVertex(wp, zeus::skBlue, 2.f); + // m_spline.Render(); } void CPathFindSearch::DebugDraw() { diff --git a/Runtime/World/CPathFindSearch.hpp b/Runtime/World/CPathFindSearch.hpp index 27b8ac883..2c2d27369 100644 --- a/Runtime/World/CPathFindSearch.hpp +++ b/Runtime/World/CPathFindSearch.hpp @@ -4,7 +4,6 @@ #include "Runtime/RetroTypes.hpp" #include "Runtime/rstl.hpp" -#include "Runtime/Graphics/CLineRenderer.hpp" #include "Runtime/World/CPathFindArea.hpp" #include @@ -13,8 +12,6 @@ namespace metaforce { class CPathFindSearch; class CPathFindVisualizer { - CLineRenderer m_spline = {CLineRenderer::EPrimitiveMode::LineStrip, 16, {}, true}; - public: void Draw(const CPathFindSearch& path); }; diff --git a/Runtime/World/CScriptMazeNode.cpp b/Runtime/World/CScriptMazeNode.cpp index fc1555ca8..711e0d268 100644 --- a/Runtime/World/CScriptMazeNode.cpp +++ b/Runtime/World/CScriptMazeNode.cpp @@ -462,8 +462,8 @@ void CMazeState::GenerateObstacles() { } void CMazeState::DebugRender() { - m_renderer.Reset(); - m_renderer.AddVertex(sDebugCellPos[skEnterCol + skEnterRow * skMazeCols], zeus::skBlue, 2.f); + // m_renderer.Reset(); + // m_renderer.AddVertex(sDebugCellPos[skEnterCol + skEnterRow * skMazeCols], zeus::skBlue, 2.f); for (s32 i = m_path.size() - 1; i >= 0; --i) { s32 idx = m_path[i]; zeus::CVector3f pos; @@ -473,8 +473,8 @@ void CMazeState::DebugRender() { } else { pos = sDebugCellPos[idx]; } - m_renderer.AddVertex(pos, zeus::skBlue, 2.f); + // m_renderer.AddVertex(pos, zeus::skBlue, 2.f); } - m_renderer.Render(); + // m_renderer.Render(); } } // namespace metaforce diff --git a/Runtime/World/CScriptMazeNode.hpp b/Runtime/World/CScriptMazeNode.hpp index 9c702a50d..e92974d4c 100644 --- a/Runtime/World/CScriptMazeNode.hpp +++ b/Runtime/World/CScriptMazeNode.hpp @@ -5,7 +5,6 @@ #include #include "Runtime/CRandom16.hpp" -#include "Runtime/Graphics/CLineRenderer.hpp" #include "Runtime/RetroTypes.hpp" #include "Runtime/World/CActor.hpp" @@ -55,7 +54,6 @@ class CMazeState { bool x94_24_initialized : 1 = false; std::vector m_path; - CLineRenderer m_renderer = {CLineRenderer::EPrimitiveMode::LineStrip, skMazeRows* skMazeCols, {}, true}; public: CMazeState(s32 enterCol, s32 enterRow, s32 targetCol, s32 targetRow) diff --git a/Runtime/World/CScriptPlatform.cpp b/Runtime/World/CScriptPlatform.cpp index 106223dbc..760e6456d 100644 --- a/Runtime/World/CScriptPlatform.cpp +++ b/Runtime/World/CScriptPlatform.cpp @@ -560,11 +560,11 @@ zeus::CQuaternion CScriptPlatform::Move(float dt, CStateManager& mgr) { } void CScriptPlatform::DebugDraw() { - if (!m_boxFilter) { - m_boxFilter = {CAABoxShader()}; - } - - m_boxFilter->setAABB(*GetTouchBounds()); - m_boxFilter->draw({1.f, 0.f, 1.f, .5f}); + // if (!m_boxFilter) { + // m_boxFilter = {CAABoxShader()}; + // } + // + // m_boxFilter->setAABB(*GetTouchBounds()); + // m_boxFilter->draw({1.f, 0.f, 1.f, .5f}); } } // namespace metaforce diff --git a/Runtime/World/CScriptPlatform.hpp b/Runtime/World/CScriptPlatform.hpp index ca4b5bd80..4c2c75679 100644 --- a/Runtime/World/CScriptPlatform.hpp +++ b/Runtime/World/CScriptPlatform.hpp @@ -12,7 +12,6 @@ #include "Runtime/World/CDamageVulnerability.hpp" #include "Runtime/World/CHealthInfo.hpp" #include "Runtime/World/CPhysicsActor.hpp" -#include "Runtime/Graphics/Shaders/CAABoxShader.hpp" #include #include @@ -73,8 +72,6 @@ class CScriptPlatform : public CPhysicsActor { const zeus::CQuaternion& rotDelta); static EntityList BuildNearListFromRiders(CStateManager& mgr, const std::vector& movedRiders); - std::optional m_boxFilter; - public: DEFINE_ENTITY CScriptPlatform(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf, diff --git a/Runtime/World/CScriptTrigger.cpp b/Runtime/World/CScriptTrigger.cpp index 7e8520227..5b28a4e31 100644 --- a/Runtime/World/CScriptTrigger.cpp +++ b/Runtime/World/CScriptTrigger.cpp @@ -310,8 +310,8 @@ zeus::CAABox CScriptTrigger::GetTriggerBoundsWR() const { void CScriptTrigger::DebugDraw() { if (m_debugSelected || m_debugHovered) { - m_debugBox.setAABB(GetTriggerBoundsWR()); - m_debugBox.draw(m_debugAddColor); + // m_debugBox.setAABB(GetTriggerBoundsWR()); + // m_debugBox.draw(m_debugAddColor); } } } // namespace metaforce diff --git a/Runtime/World/CScriptTrigger.hpp b/Runtime/World/CScriptTrigger.hpp index 24f451280..eeba26319 100644 --- a/Runtime/World/CScriptTrigger.hpp +++ b/Runtime/World/CScriptTrigger.hpp @@ -5,7 +5,6 @@ #include "Runtime/World/CActor.hpp" #include "Runtime/World/CDamageInfo.hpp" -#include "Runtime/Graphics/Shaders/CAABoxShader.hpp" #include #include @@ -61,8 +60,6 @@ protected: bool x148_28_playerTriggerProc : 1 = false; bool x148_29_didPhazonDamage : 1 = false; - CAABoxShader m_debugBox; - public: DEFINE_ENTITY CScriptTrigger(TUniqueId, std::string_view name, const CEntityInfo& info, const zeus::CVector3f& pos, diff --git a/Runtime/World/CSnakeWeedSwarm.cpp b/Runtime/World/CSnakeWeedSwarm.cpp index a484465d5..34dbc9c92 100644 --- a/Runtime/World/CSnakeWeedSwarm.cpp +++ b/Runtime/World/CSnakeWeedSwarm.cpp @@ -419,13 +419,13 @@ void CSnakeWeedSwarm::RenderBoid(u32 idx, const CBoid& boid, u32& posesToBuild) if (posesToBuild & 1 << modelIdx) { posesToBuild &= ~(1 << modelIdx); animData.BuildPose(); - model.Calculate(animData.GetPose(), nullptr, nullptr, &workspace); + model.Calculate(animData.GetPose(), nullptr, {}, &workspace); } CGraphics::SetModelMatrix( zeus::CTransform::Translate(boid.GetPosition() - zeus::CVector3f(0.f, 0.f, boid.GetZOffset())) * zeus::CTransform::Scale(boid.GetScale())); constexpr CModelFlags useFlags{0, 0, 3, zeus::skWhite}; - model.Draw(&workspace.m_vertexWorkspace, &workspace.m_normalWorkspace, useFlags); + model.Draw(workspace.m_vertexWorkspace, workspace.m_normalWorkspace, useFlags); } void CSnakeWeedSwarm::ApplyRadiusDamage(const zeus::CVector3f& pos, const CDamageInfo& info, CStateManager& mgr) { diff --git a/Runtime/World/CVisorFlare.cpp b/Runtime/World/CVisorFlare.cpp index b8e9351f1..4b66c81b5 100644 --- a/Runtime/World/CVisorFlare.cpp +++ b/Runtime/World/CVisorFlare.cpp @@ -102,8 +102,8 @@ void CVisorFlare::Render(const zeus::CVector3f& pos, const CStateManager& mgr) c const CGameCamera* cam = mgr.GetCameraManager()->GetCurrentCamera(mgr); zeus::CVector3f camPos = cam->GetTranslation(); zeus::CVector3f camFront = cam->GetTransform().frontVector(); - const auto invPos = CGraphics::g_ViewMatrix.inverse() * pos; - const auto invPos2 = CGraphics::g_ViewMatrix * zeus::CVector3f{-invPos.x(), invPos.y(), -invPos.z()}; + const auto invPos = CGraphics::mViewMatrix.inverse() * pos; + const auto invPos2 = CGraphics::mViewMatrix * zeus::CVector3f{-invPos.x(), invPos.y(), -invPos.z()}; if (!zeus::close_enough(x24_, 0.f, 1.0E-5f)) { float acos = 0.f; if (!zeus::close_enough(x20_f3, 0.f, 1.0E-5f)) { @@ -196,7 +196,7 @@ void CVisorFlare::ResetTevSwapMode(const CStateManager& mgr) const { void CVisorFlare::DrawDirect(const zeus::CColor& color, float f1, float f2) const { zeus::CColor kcolor = color; - kcolor.a() *= x24_; // TODO i think this is wrong + kcolor.a() *= x24_; CGX::SetTevKColor(GX_KCOLOR0, kcolor); CGX::Begin(GX_TRIANGLESTRIP, GX_VTXFMT0, 4); GXPosition3f32(f1 - f2, 0.f, f2 + f1); @@ -211,7 +211,7 @@ void CVisorFlare::DrawDirect(const zeus::CColor& color, float f1, float f2) cons } void CVisorFlare::DrawStreamed(const zeus::CColor& color, float f1, float f2) const { - CGraphics::StreamBegin(GX_TRIANGLESTRIP); + CGraphics::StreamBegin(ERglPrimitive::TriangleStrip); zeus::CColor kcolor = color; kcolor.a() *= x24_; CGraphics::StreamColor(kcolor); diff --git a/Runtime/World/CWallCrawlerSwarm.cpp b/Runtime/World/CWallCrawlerSwarm.cpp index ae07fb82a..d0ab58d59 100644 --- a/Runtime/World/CWallCrawlerSwarm.cpp +++ b/Runtime/World/CWallCrawlerSwarm.cpp @@ -1043,14 +1043,14 @@ void CWallCrawlerSwarm::RenderBoid(const CBoid* boid, u32& drawMask, bool therma if ((drawMask & thisDrawMask) != 0u) { drawMask &= ~thisDrawMask; mData.GetAnimationData()->BuildPose(); - model.Calculate(mData.GetAnimationData()->GetPose(), nullptr, nullptr, &x430_workspaces[modelIndex]); + model.Calculate(mData.GetAnimationData()->GetPose(), nullptr, {}, &x430_workspaces[modelIndex]); } g_Renderer->SetAmbientColor(boid->x40_ambientLighting); g_Renderer->SetModelMatrix(boid->GetTransform()); - const auto* positions = &x430_workspaces[modelIndex].m_vertexWorkspace; - const auto* normals = &x430_workspaces[modelIndex].m_normalWorkspace; + const auto& positions = x430_workspaces[modelIndex].m_vertexWorkspace; + const auto& normals = x430_workspaces[modelIndex].m_normalWorkspace; if (boid->x48_timeToDie > 0.f && !thermalHot) { constexpr CModelFlags useFlags(0, 0, 3, zeus::skWhite); model.Draw(positions, normals, useFlags); @@ -1059,7 +1059,7 @@ void CWallCrawlerSwarm::RenderBoid(const CBoid* boid, u32& drawMask, bool therma const float alpha = 1.f - boid->x48_timeToDie; const zeus::CColor color(1.f, alpha > 0.f ? boid->x48_timeToDie : 1.f); const CModelFlags iceFlags(5, 0, 3, color); - mData.GetAnimationData()->Render(*iceModel, iceFlags, nullptr, nullptr); + mData.GetAnimationData()->Render(*iceModel, iceFlags, nullptr, {}); } } else if (thermalHot) { constexpr CModelFlags thermFlags(5, 0, 3, zeus::skWhite); @@ -1086,7 +1086,7 @@ void CWallCrawlerSwarm::Render(CStateManager& mgr) { if (mgr.GetPlayerState()->GetActiveVisor(mgr) == CPlayerState::EPlayerVisor::XRay) { flags = CModelFlags(5, 0, 3, zeus::CColor(1.f, 0.3f)); } - CGX::SetChanCtrl(CGX::EChannelId::Channel0, CGraphics::g_LightActive); + CGX::SetChanCtrl(CGX::EChannelId::Channel0, CGraphics::mLightActive); for (int r27 = 0; r27 < 5; ++r27) { for (int r28 = 0; r28 < 5; ++r28) { diff --git a/Runtime/World/CWorldShadow.cpp b/Runtime/World/CWorldShadow.cpp index 5f3cf4ba9..ccdc7de51 100644 --- a/Runtime/World/CWorldShadow.cpp +++ b/Runtime/World/CWorldShadow.cpp @@ -60,8 +60,9 @@ void CWorldShadow::BuildLightShadowTexture(const CStateManager& mgr, TAreaId aid frustum.updatePlanes(x4_view, zeus::SProjPersp(zeus::degToRad(fov), 1.f, 0.1f, distance + x64_objHalfExtent)); g_Renderer->SetClippingPlanes(frustum); g_Renderer->SetPerspective(fov, x0_texture->GetWidth(), x0_texture->GetHeight(), 0.1f, 1000.f); - SViewport backupVp = CGraphics::g_Viewport; - zeus::CVector2f backupDepthRange = CGraphics::g_CachedDepthRange; + CViewport backupVp = CGraphics::mViewport; + float backupDepthNear = CGraphics::mDepthNear; + float backupDepthFar = CGraphics::mDepthFar; g_Renderer->SetViewport(0, 0, x0_texture->GetWidth(), x0_texture->GetHeight()); CGraphics::SetDepthRange(DEPTH_NEAR, DEPTH_FAR); @@ -99,7 +100,7 @@ void CWorldShadow::BuildLightShadowTexture(const CStateManager& mgr, TAreaId aid ERglLogicOp::Clear); CGraphics::SetTevOp(ERglTevStage::Stage0, CTevCombiners::kEnvPassthru); CGraphics::SetTevOp(ERglTevStage::Stage1, CTevCombiners::kEnvPassthru); - CGraphics::StreamBegin(GX_TRIANGLESTRIP); + CGraphics::StreamBegin(ERglPrimitive::TriangleStrip); CGraphics::StreamColor(1.f, 1.f, 1.f, 0.25f); CGraphics::StreamVertex(-extent, 0.f, extent); CGraphics::StreamVertex(extent, 0.f, extent); @@ -127,8 +128,8 @@ void CWorldShadow::BuildLightShadowTexture(const CStateManager& mgr, TAreaId aid // m_shader.resolveTexture(); // CBooRenderer::BindMainDrawTarget(); - g_Renderer->SetViewport(backupVp.x0_left, backupVp.x4_top, backupVp.x8_width, backupVp.xc_height); - CGraphics::SetDepthRange(backupDepthRange[0], backupDepthRange[1]); + g_Renderer->SetViewport(backupVp.mLeft, backupVp.mTop, backupVp.mWidth, backupVp.mHeight); + CGraphics::SetDepthRange(backupDepthNear, backupDepthFar); } } } diff --git a/Runtime/World/CWorldTransManager.cpp b/Runtime/World/CWorldTransManager.cpp index 7cc597df2..b158fd9a3 100644 --- a/Runtime/World/CWorldTransManager.cpp +++ b/Runtime/World/CWorldTransManager.cpp @@ -257,7 +257,7 @@ void CWorldTransManager::DrawEnabled() { else { float t = zeus::clamp(0.f, (x0_curTime - x4_modelData->x1d0_dissolveStartTime) / 2.f, 1.f); DrawFirstPass(&lights); - SClipScreenRect rect(CGraphics::g_Viewport); + // SClipScreenRect rect(CGraphics::g_Viewport); // CGraphics::ResolveSpareTexture(rect); // CGraphics::g_BooMainCommandQueue->clearTarget(true, true); // DrawSecondPass(&lights); diff --git a/Shaders/CAABoxShader.shader b/Shaders/CAABoxShader.shader deleted file mode 100644 index f5007a140..000000000 --- a/Shaders/CAABoxShader.shader +++ /dev/null @@ -1,125 +0,0 @@ -#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 deleted file mode 100644 index d9f7dac3d..000000000 --- a/Shaders/CCameraBlurFilter.shader +++ /dev/null @@ -1,242 +0,0 @@ -#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 deleted file mode 100644 index 1a26593e4..000000000 --- a/Shaders/CColoredQuadFilter.shader +++ /dev/null @@ -1,131 +0,0 @@ -#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 -#overwritealpha true diff --git a/Shaders/CColoredStripShader.shader b/Shaders/CColoredStripShader.shader deleted file mode 100644 index 16401b019..000000000 --- a/Shaders/CColoredStripShader.shader +++ /dev/null @@ -1,155 +0,0 @@ -#shader CColoredStripShader -#attribute position4 -#attribute color -#attribute uv4 -#srcfac srcalpha -#dstfac invsrcalpha -#primitive tristrips -#depthtest lequal -#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 ColoredQuadUniform -{ - mat4 xf; - vec4 color; -}; - -struct VertToFrag -{ - vec4 color; - vec2 uv; -}; - -SBINDING(0) out VertToFrag vtf; -void main() -{ - vtf.color = colorIn * 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 colorIn : COLOR; - float4 uvIn : UV; -}; - -cbuffer ColoredQuadUniform : 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 = v.colorIn * color; - vtf.uv = v.uvIn.xy; - vtf.position = mul(xf, float4(v.posIn.xyz, 1.0)); - 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 [[ attribute(0) ]]; - float4 colorIn [[ attribute(1) ]]; - float4 uvIn [[ attribute(2) ]]; -}; - -struct ColoredQuadUniform -{ - float4x4 xf; - float4 color; -}; - -struct VertToFrag -{ - float4 position [[ position ]]; - float4 color; - float2 uv; -}; - -vertex VertToFrag vmain(VertData v [[ stage_in ]], constant ColoredQuadUniform& cqu [[ buffer(2) ]]) -{ - VertToFrag vtf; - vtf.color = v.colorIn * cqu.color; - vtf.uv = v.uvIn.xy; - vtf.position = cqu.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 tex0 [[ texture(0) ]]) -{ - return vtf.color * tex0.sample(samp, vtf.uv); -} - -#shader CColoredStripShaderAdditive : CColoredStripShader -#srcfac srcalpha -#dstfac one - -#shader CColoredStripShaderFullAdditive : CColoredStripShader -#srcfac one -#dstfac one - -#shader CColoredStripShaderSubtractive : CColoredStripShader -#srcfac subtract -#dstfac subtract diff --git a/Shaders/CDecalShaders.shader b/Shaders/CDecalShaders.shader deleted file mode 100644 index c3c9efb41..000000000 --- a/Shaders/CDecalShaders.shader +++ /dev/null @@ -1,350 +0,0 @@ -#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 * texture(tex, vtf.uv); - colorOut.a = colorOut.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 -{ - float4 colorOut = vtf.color * tex0.Sample(samp, vtf.uv); - colorOut.a = colorOut.r; - return colorOut; -} - - -#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) ]]) -{ - float4 colorOut = vtf.color * tex0.sample(samp, vtf.uv); - colorOut.a = colorOut.r; - return colorOut; -} - - -#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 deleted file mode 100644 index b46b4a90f..000000000 --- a/Shaders/CElementGenShaders.shader +++ /dev/null @@ -1,787 +0,0 @@ -#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 -#alphawrite 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 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 CElementGenShaderTexZTestZWriteAWrite : CElementGenShaderTexZTestZWrite -#alphawrite true - -#shader CElementGenShaderTexNoZTestZWrite : CElementGenShaderTexZTestZWrite -#depthtest none -#depthwrite true -#alphawrite false - -#shader CElementGenShaderTexNoZTestZWriteAWrite : CElementGenShaderTexNoZTestZWrite -#alphawrite true - -#shader CElementGenShaderTexZTestNoZWrite : CElementGenShaderTexZTestZWrite -#depthtest lequal -#depthwrite false -#alphawrite false - -#shader CElementGenShaderTexZTestNoZWriteAWrite : CElementGenShaderTexZTestNoZWrite -#alphawrite true - -#shader CElementGenShaderTexNoZTestNoZWrite : CElementGenShaderTexZTestZWrite -#depthtest none -#depthwrite false -#alphawrite false - -#shader CElementGenShaderTexNoZTestNoZWriteAWrite : CElementGenShaderTexNoZTestNoZWrite -#alphawrite true - -#shader CElementGenShaderTexAdditiveZTest : CElementGenShaderTexZTestZWrite -#srcfac srcalpha -#dstfac one -#depthtest lequal -#depthwrite false -#alphawrite false - -#shader CElementGenShaderTexAdditiveZTestAWrite : CElementGenShaderTexAdditiveZTest -#alphawrite true - -#shader CElementGenShaderTexAdditiveNoZTest : CElementGenShaderTexZTestZWrite -#srcfac srcalpha -#dstfac one -#depthtest none -#depthwrite false -#alphawrite false - -#shader CElementGenShaderTexAdditiveNoZTestAWrite : CElementGenShaderTexAdditiveNoZTest -#alphawrite true - -#shader CElementGenShaderTexZTestNoZWriteSub : CElementGenShaderTexZTestZWrite -#srcfac subtract -#dstfac subtract -#depthtest lequal -#depthwrite false -#alphawrite false - -#shader CElementGenShaderTexZTestNoZWriteSubAWrite : CElementGenShaderTexZTestNoZWriteSub -#alphawrite true - -#shader CElementGenShaderTexNoZTestNoZWriteSub : CElementGenShaderTexZTestZWrite -#srcfac subtract -#dstfac subtract -#depthtest none -#depthwrite false -#alphawrite false - -#shader CElementGenShaderTexNoZTestNoZWriteSubAWrite : CElementGenShaderTexNoZTestNoZWriteSub -#alphawrite true - -#shader CElementGenShaderTexRedToAlphaZTest : CElementGenShaderTexZTestZWrite -#srcfac one -#dstfac one -#depthtest lequal -#depthwrite false -#alphawrite 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() -{ - vec4 texel = texture(tex, vtf.uv); - vec4 tmp = texel * vtf.color; - colorOut = tmp * tmp.a; - colorOut.a = tmp.a * texel.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 -{ - float4 texel = tex0.Sample(samp, vtf.uv); - float4 tmp = texel * vtf.color; - float4 colorOut = tmp * tmp.a; - colorOut.a = tmp.a * texel.r; - return colorOut; -} - -#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) ]]) -{ - float4 texel = tex0.sample(samp, vtf.uv); - float4 tmp = texel * vtf.color; - float4 colorOut = tmp * tmp.a; - colorOut.a = tmp.a * texel.r; - return colorOut; -} - -#shader CElementGenShaderTexRedToAlphaZTestAWrite : CElementGenShaderTexRedToAlphaZTest -#alphawrite true - -#shader CElementGenShaderTexRedToAlphaNoZTest : CElementGenShaderTexRedToAlphaZTest -#depthtest none -#alphawrite false - -#shader CElementGenShaderTexRedToAlphaNoZTestAWrite : CElementGenShaderTexRedToAlphaNoZTest -#alphawrite true - -#shader CElementGenShaderTexRedToAlphaZTestSub : CElementGenShaderTexRedToAlphaZTest -#srcfac subtract -#dstfac subtract -#depthtest lequal -#alphawrite false - -#shader CElementGenShaderTexRedToAlphaZTestSubAWrite : CElementGenShaderTexRedToAlphaZTestSub -#alphawrite true - -#shader CElementGenShaderTexRedToAlphaNoZTestSub : CElementGenShaderTexRedToAlphaZTest -#srcfac subtract -#dstfac subtract -#depthtest none -#alphawrite false - -#shader CElementGenShaderTexRedToAlphaNoZTestSubAWrite : CElementGenShaderTexRedToAlphaNoZTestSub -#alphawrite true - -#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 -#srcfac srcalpha -#dstfac invsrcalpha -#depthtest none -#depthwrite true -#alphawrite false - -#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; -} - -#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).ab; - 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; - colorOut.a = vtf.color.a * texrTexel.a; -} - -#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.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).ab; - 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.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).ab; - float4 sceneTexel = tex1.sample(samp, mix(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; -} - -#shader CElementGenShaderIndTexZWriteAWrite : CElementGenShaderIndTexZWrite -#alphawrite true - -#shader CElementGenShaderIndTexNoZWrite : CElementGenShaderIndTexZWrite -#depthwrite false -#alphawrite false - -#shader CElementGenShaderIndTexNoZWriteAWrite : CElementGenShaderIndTexNoZWrite -#alphawrite true - -#shader CElementGenShaderIndTexAdditive : CElementGenShaderIndTexZWrite -#depthwrite true -#srcfac srcalpha -#dstfac one -#alphawrite false - -#shader CElementGenShaderIndTexAdditiveAWrite : CElementGenShaderIndTexAdditive -#alphawrite true - -#shader CElementGenShaderCindTexZWrite : CElementGenShaderIndTexZWrite -#srcfac srcalpha -#dstfac invsrcalpha -#depthtest none -#depthwrite true -#alphawrite false - -#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).ab; - 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).ab; - 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).ab; - 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 CElementGenShaderCindTexZWriteAWrite : CElementGenShaderCindTexZWrite -#alphawrite true - -#shader CElementGenShaderCindTexNoZWrite : CElementGenShaderCindTexZWrite -#depthwrite false -#alphawrite false - -#shader CElementGenShaderCindTexNoZWriteAWrite : CElementGenShaderCindTexNoZWrite -#alphawrite true - -#shader CElementGenShaderCindTexAdditive : CElementGenShaderCindTexZWrite -#depthwrite true -#srcfac srcalpha -#dstfac one -#alphawrite false - -#shader CElementGenShaderCindTexAdditiveAWrite : CElementGenShaderCindTexAdditive -#alphawrite true - -#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 -#alphawrite false - -#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 CElementGenShaderNoTexZTestZWriteAWrite : CElementGenShaderNoTexZTestZWrite -#alphawrite true - -#shader CElementGenShaderNoTexNoZTestZWrite : CElementGenShaderNoTexZTestZWrite -#depthtest none -#depthwrite true -#alphawrite false - -#shader CElementGenShaderNoTexNoZTestZWriteAWrite : CElementGenShaderNoTexNoZTestZWrite -#alphawrite true - -#shader CElementGenShaderNoTexZTestNoZWrite : CElementGenShaderNoTexZTestZWrite -#depthtest lequal -#depthwrite false -#alphawrite false - -#shader CElementGenShaderNoTexZTestNoZWriteAWrite : CElementGenShaderNoTexZTestNoZWrite -#alphawrite true - -#shader CElementGenShaderNoTexNoZTestNoZWrite : CElementGenShaderNoTexZTestZWrite -#depthtest none -#depthwrite false -#alphawrite false - -#shader CElementGenShaderNoTexNoZTestNoZWriteAWrite : CElementGenShaderNoTexNoZTestNoZWrite -#alphawrite true - -#shader CElementGenShaderNoTexAdditiveZTest : CElementGenShaderNoTexZTestZWrite -#srcfac srcalpha -#dstfac one -#depthtest lequal -#depthwrite false -#alphawrite false - -#shader CElementGenShaderNoTexAdditiveZTestAWrite : CElementGenShaderNoTexAdditiveZTest -#alphawrite true - -#shader CElementGenShaderNoTexAdditiveNoZTest : CElementGenShaderNoTexZTestZWrite -#srcfac srcalpha -#dstfac one -#depthtest none -#depthwrite false -#alphawrite false - -#shader CElementGenShaderNoTexAdditiveNoZTestAWrite : CElementGenShaderNoTexAdditiveNoZTest -#alphawrite true diff --git a/Shaders/CEnergyBarShader.shader b/Shaders/CEnergyBarShader.shader deleted file mode 100644 index 93d3de21e..000000000 --- a/Shaders/CEnergyBarShader.shader +++ /dev/null @@ -1,138 +0,0 @@ -#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/CEnvFxShaders.shader b/Shaders/CEnvFxShaders.shader deleted file mode 100644 index ee43e3b4e..000000000 --- a/Shaders/CEnvFxShaders.shader +++ /dev/null @@ -1,302 +0,0 @@ -#shader CEnvFxSnowShader -#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 one -#dstfac one -#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; -layout(location=5) in vec4 uvsIn[4]; - -UBINDING0 uniform EnvFxUniform -{ - mat4 mv; - mat4 proj; - mat4 envMtx; - vec4 moduColor; -}; - -struct VertToFrag -{ - vec4 mvPos; - vec4 color; - vec2 uvFlake; - vec2 uvEnv; -}; - -SBINDING(0) out VertToFrag vtf; -void main() -{ - vec4 pos = vec4(posIn[gl_VertexID].xyz, 1.0); - vtf.color = colorIn * moduColor; - vtf.uvFlake = uvsIn[gl_VertexID].xy; - vtf.uvEnv = (envMtx * pos).xy; - vtf.mvPos = mv * pos; - gl_Position = proj * vtf.mvPos; -} - -#fragment glsl -struct VertToFrag -{ - vec4 mvPos; - vec4 color; - vec2 uvFlake; - vec2 uvEnv; -}; - -SBINDING(0) in VertToFrag vtf; -layout(location=0) out vec4 colorOut; -TBINDING0 uniform sampler2D texFlake; -TBINDING1 uniform sampler2D texEnv; - -UBINDING1 uniform FogUniform -{ - vec4 color; - float A; - float B; - float C; - int mode; -}; - -vec4 MainPostFunc(vec4 colorIn) -{ - float fogZ; - float fogF = clamp((A / (B - gl_FragCoord.z)) - C, 0.0, 1.0); - switch (mode) - { - case 2: - fogZ = fogF; - break; - case 4: - fogZ = 1.0 - exp2(-8.0 * fogF); - break; - case 5: - fogZ = 1.0 - exp2(-8.0 * fogF * fogF); - break; - case 6: - fogZ = exp2(-8.0 * (1.0 - fogF)); - break; - case 7: - fogF = 1.0 - fogF; - fogZ = exp2(-8.0 * fogF * fogF); - break; - default: - fogZ = 0.0; - break; - } - return vec4(mix(colorIn, vec4(0.0), clamp(fogZ, 0.0, 1.0)).rgb, colorIn.a); -} - -void main() -{ - colorOut = MainPostFunc(vtf.color * texture(texFlake, vtf.uvFlake) * texture(texEnv, vtf.uvEnv)); -} - -#vertex hlsl -struct VertData -{ - float4 posIn[4] : POSITION; - float4 colorIn : COLOR; - float4 uvsIn[4] : UV; -}; - -cbuffer EnvFxUniform : register(b0) -{ - float4x4 mv; - float4x4 proj; - float4x4 envMtx; - float4 moduColor; -}; - -struct VertToFrag -{ - float4 position : SV_Position; - float4 mvPos : POSITION; - float4 color : COLOR; - float2 uvFlake : UV0; - float2 uvEnv : UV1; -}; - -VertToFrag main(in VertData v, in uint vertId : SV_VertexID) -{ - VertToFrag vtf; - vtf.color = v.colorIn * moduColor; - vtf.uvFlake = v.uvsIn[vertId].xy; - float4 pos = float4(v.posIn[vertId].xyz, 1.0); - vtf.uvEnv = mul(envMtx, pos).xy; - vtf.mvPos = mul(mv, pos); - vtf.position = mul(proj, vtf.mvPos); - return vtf; -} - -#fragment hlsl -SamplerState samp : register(s0); -SamplerState sampClamp : register(s3); -Texture2D texFlake : register(t0); -Texture2D texEnv : register(t1); -struct VertToFrag -{ - float4 position : SV_Position; - float4 mvPos : POSITION; - float4 color : COLOR; - float2 uvFlake : UV0; - float2 uvEnv : UV1; -}; - -cbuffer FogUniform : register(b1) -{ - float4 color; - float A; - float B; - float C; - int mode; -}; - -static float4 MainPostFunc(in VertToFrag vtf, float4 colorIn) -{ - float fogZ; - float fogF = saturate((A / (B - (1.0 - vtf.position.z))) - C); - switch (mode) - { - case 2: - fogZ = fogF; - break; - case 4: - fogZ = 1.0 - exp2(-8.0 * fogF); - break; - case 5: - fogZ = 1.0 - exp2(-8.0 * fogF * fogF); - break; - case 6: - fogZ = exp2(-8.0 * (1.0 - fogF)); - break; - case 7: - fogF = 1.0 - fogF; - fogZ = exp2(-8.0 * fogF * fogF); - break; - default: - fogZ = 0.0; - break; - } - return float4(lerp(colorIn, float4(0.0,0.0,0.0,0.0), saturate(fogZ)).rgb, colorIn.a); -} - -float4 main(in VertToFrag vtf) : SV_Target0 -{ - return MainPostFunc(vtf, vtf.color * texFlake.Sample(samp, vtf.uvFlake) * texEnv.Sample(sampClamp, vtf.uvEnv)); -} - -#vertex metal -struct VertData -{ - float4 posIn[4]; - float4 colorIn; - float4 uvsIn[4]; -}; - -struct EnvFxUniform -{ - float4x4 mv; - float4x4 proj; - float4x4 envMtx; - float4 moduColor; -}; - -struct VertToFrag -{ - float4 position [[ position ]]; - float4 mvPos; - float4 color; - float2 uvFlake; - float2 uvEnv; -}; - -vertex VertToFrag vmain(constant VertData* va [[ buffer(1) ]], - uint vertId [[ vertex_id ]], uint instId [[ instance_id ]], - constant EnvFxUniform& particle [[ buffer(2) ]]) -{ - VertToFrag vtf; - constant VertData& v = va[instId]; - vtf.color = v.colorIn * particle.moduColor; - vtf.uvFlake = v.uvsIn[vertId].xy; - float4 pos = float4(v.posIn[vertId].xyz, 1.0); - vtf.uvEnv = (particle.envMtx * pos).xy; - vtf.mvPos = particle.mv * pos; - vtf.position = particle.proj * vtf.mvPos; - return vtf; -} - -#fragment metal -struct VertToFrag -{ - float4 position [[ position ]]; - float4 mvPos; - float4 color; - float2 uvFlake; - float2 uvEnv; -}; - -struct FogUniform -{ - float4 color; - float A; - float B; - float C; - int mode; -}; - -float4 MainPostFunc(thread VertToFrag& vtf, constant FogUniform& fu, float4 colorIn) -{ - float fogZ; - float fogF = saturate((fu.A / (fu.B - (1.0 - vtf.position.z))) - fu.C); - switch (fu.mode) - { - case 2: - fogZ = fogF; - break; - case 4: - fogZ = 1.0 - exp2(-8.0 * fogF); - break; - case 5: - fogZ = 1.0 - exp2(-8.0 * fogF * fogF); - break; - case 6: - fogZ = exp2(-8.0 * (1.0 - fogF)); - break; - case 7: - fogF = 1.0 - fogF; - fogZ = exp2(-8.0 * fogF * fogF); - break; - default: - fogZ = 0.0; - break; - } - return float4(mix(colorIn, float4(0.0), saturate(fogZ)).rgb, colorIn.a); -} - -fragment float4 fmain(VertToFrag vtf [[ stage_in ]], - sampler samp [[ sampler(0) ]], - sampler sampClamp [[ sampler(3) ]], - constant FogUniform& fu [[ buffer(3) ]], - texture2d texFlake [[ texture(0) ]], - texture2d texEnv [[ texture(1) ]]) -{ - return MainPostFunc(vtf, fu, vtf.color * texFlake.sample(samp, vtf.uvFlake) * texEnv.sample(sampClamp, vtf.uvEnv)); -} - -#shader CEnvFxUnderwaterShader : CEnvFxSnowShader -#srcfac srcalpha -#dstfac invsrcalpha diff --git a/Shaders/CFogVolumeFilter.shader b/Shaders/CFogVolumeFilter.shader deleted file mode 100644 index cf6847a96..000000000 --- a/Shaders/CFogVolumeFilter.shader +++ /dev/null @@ -1,237 +0,0 @@ -#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); -SamplerState zLinearizerSamp : register(s3); -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(zLinearizerSamp, float2(frontX * 255.0 / 256.0 + uvBias, frontY / 256.0 + uvBias)).r; - float backLin = zLinearizer.Sample(zLinearizerSamp, 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) ]], - sampler zLinearizerSamp [[ sampler(3) ]], - 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(zLinearizerSamp, float2(frontX * 255.0 / 256.0 + uvBias, frontY / 256.0 + uvBias)).r; - float backLin = zLinearizer.sample(zLinearizerSamp, 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 deleted file mode 100644 index 0757f1fa5..000000000 --- a/Shaders/CFogVolumePlaneShader.shader +++ /dev/null @@ -1,91 +0,0 @@ -#shader CFogVolumePlaneShader0 -#attribute position4 -#srcfac zero -#dstfac zero -#primitive tristrips -#depthtest lequal -#depthwrite true -#colorwrite false -#alphawrite true -#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 -#alphawrite true -#culling frontface - -#shader CFogVolumePlaneShader2 : CFogVolumePlaneShader0 -#depthtest lequal -#depthwrite true -#colorwrite false -#alphawrite true -#culling backface - -#shader CFogVolumePlaneShader3 : CFogVolumePlaneShader0 -#depthtest greater -#depthwrite false -#colorwrite false -#alphawrite true -#culling backface diff --git a/Shaders/CLineRendererShaders.shader b/Shaders/CLineRendererShaders.shader deleted file mode 100644 index 328e2535e..000000000 --- a/Shaders/CLineRendererShaders.shader +++ /dev/null @@ -1,916 +0,0 @@ -#shader CLineRendererShaderTexAlpha -#attribute position4 -#attribute color -#attribute uv4 -#srcfac srcalpha -#dstfac invsrcalpha -#primitive tristrips -#depthtest none -#depthwrite false -#alphawrite false -#culling none - -#vertex glsl -layout(location=0) in vec4 posIn; -layout(location=1) in vec4 colorIn; -layout(location=2) in vec4 uvIn; - -struct VertToFrag -{ - vec4 color; - vec2 uv; -}; - -SBINDING(0) out VertToFrag vtf; -void main() -{ - vtf.color = colorIn; - vtf.uv = uvIn.xy; - gl_Position = posIn; -} - -#fragment glsl -struct Fog -{ - vec4 color; - float A; - float B; - float C; - int mode; -}; - -UBINDING0 uniform LineUniform -{ - vec4 moduColor; - Fog fog; -}; - -struct VertToFrag -{ - vec4 color; - vec2 uv; -}; - -vec4 MainPostFunc(vec4 colorIn) -{ - float fogZ; - float fogF = clamp((fog.A / (fog.B - gl_FragCoord.z)) - fog.C, 0.0, 1.0); - switch (fog.mode) - { - case 2: - fogZ = fogF; - break; - case 4: - fogZ = 1.0 - exp2(-8.0 * fogF); - break; - case 5: - fogZ = 1.0 - exp2(-8.0 * fogF * fogF); - break; - case 6: - fogZ = exp2(-8.0 * (1.0 - fogF)); - break; - case 7: - fogF = 1.0 - fogF; - fogZ = exp2(-8.0 * fogF * fogF); - break; - default: - fogZ = 0.0; - break; - } - return vec4(mix(colorIn, fog.color, clamp(fogZ, 0.0, 1.0)).rgb, colorIn.a); -} - -SBINDING(0) in VertToFrag vtf; -layout(location=0) out vec4 colorOut; -TBINDING0 uniform sampler2D tex; -void main() -{ - colorOut = MainPostFunc(vtf.color * moduColor * texture(tex, vtf.uv)); -} - -#vertex hlsl -struct VertData -{ - float4 posIn : POSITION; - float4 colorIn : COLOR; - float4 uvIn : UV; -}; - -struct VertToFrag -{ - float4 position : 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.position = v.posIn; - return vtf; -} - -#fragment hlsl -struct Fog -{ - float4 color; - float A; - float B; - float C; - int mode; -}; - -cbuffer LineUniform : register(b0) -{ - float4 moduColor; - Fog fog; -}; - -SamplerState samp : register(s3); -Texture2D tex0 : register(t0); -struct VertToFrag -{ - float4 position : SV_Position; - float4 color : COLOR; - float2 uv : UV; -}; - -static float4 MainPostFunc(in VertToFrag vtf, float4 colorIn) -{ - float fogZ; - float fogF = saturate((fog.A / (fog.B - (1.0 - vtf.position.z))) - fog.C); - switch (fog.mode) - { - case 2: - fogZ = fogF; - break; - case 4: - fogZ = 1.0 - exp2(-8.0 * fogF); - break; - case 5: - fogZ = 1.0 - exp2(-8.0 * fogF * fogF); - break; - case 6: - fogZ = exp2(-8.0 * (1.0 - fogF)); - break; - case 7: - fogF = 1.0 - fogF; - fogZ = exp2(-8.0 * fogF * fogF); - break; - default: - fogZ = 0.0; - break; - } - return float4(lerp(colorIn, fog.color, saturate(fogZ)).rgb, colorIn.a); -} - -float4 main(in VertToFrag vtf) : SV_Target0 -{ - return MainPostFunc(vtf, vtf.color * moduColor * tex0.Sample(samp, vtf.uv)); -} - -#vertex metal -struct VertData -{ - float4 posIn; - float4 colorIn; - float4 uvIn; -}; - -struct VertToFrag -{ - float4 position [[ position ]]; - float4 color; - float2 uv; -}; - -vertex VertToFrag vmain(constant VertData* va [[ buffer(0) ]], - uint vertId [[ vertex_id ]]) -{ - VertToFrag vtf; - constant VertData& v = va[vertId]; - vtf.color = v.colorIn; - vtf.uv = v.uvIn.xy; - vtf.position = v.posIn; - return vtf; -} - -#fragment metal -struct Fog -{ - float4 color; - float A; - float B; - float C; - int mode; -}; - -struct LineUniform -{ - float4 moduColor; - Fog fog; -}; - -struct VertToFrag -{ - float4 position [[ position ]]; - float4 color; - float2 uv; -}; - -static float4 MainPostFunc(thread VertToFrag& vtf, constant LineUniform& line, float4 colorIn) -{ - float fogZ; - float fogF = saturate((line.fog.A / (line.fog.B - (1.0 - vtf.position.z))) - line.fog.C); - switch (line.fog.mode) - { - case 2: - fogZ = fogF; - break; - case 4: - fogZ = 1.0 - exp2(-8.0 * fogF); - break; - case 5: - fogZ = 1.0 - exp2(-8.0 * fogF * fogF); - break; - case 6: - fogZ = exp2(-8.0 * (1.0 - fogF)); - break; - case 7: - fogF = 1.0 - fogF; - fogZ = exp2(-8.0 * fogF * fogF); - break; - default: - fogZ = 0.0; - break; - } - return float4(mix(colorIn, line.fog.color, saturate(fogZ)).rgb, colorIn.a); -} - -fragment float4 fmain(VertToFrag vtf [[ stage_in ]], - sampler samp [[ sampler(3) ]], - texture2d tex0 [[ texture(0) ]], - constant LineUniform& line [[ buffer(2) ]]) -{ - return MainPostFunc(vtf, line, vtf.color * line.moduColor * tex0.sample(samp, vtf.uv)); -} - -#shader CLineRendererShaderTexAlphaAWrite : CLineRendererShaderTexAlpha -#alphawrite true - -#shader CLineRendererShaderTexAdditive : CLineRendererShaderTexAlpha -#srcfac srcalpha -#dstfac one -#depthtest none -#alphawrite false - -#fragment glsl -struct Fog -{ - vec4 color; - float A; - float B; - float C; - int mode; -}; - -UBINDING0 uniform LineUniform -{ - vec4 moduColor; - Fog fog; -}; - -struct VertToFrag -{ - vec4 color; - vec2 uv; -}; - -vec4 MainPostFunc(vec4 colorIn) -{ - float fogZ; - float fogF = clamp((fog.A / (fog.B - gl_FragCoord.z)) - fog.C, 0.0, 1.0); - switch (fog.mode) - { - case 2: - fogZ = fogF; - break; - case 4: - fogZ = 1.0 - exp2(-8.0 * fogF); - break; - case 5: - fogZ = 1.0 - exp2(-8.0 * fogF * fogF); - break; - case 6: - fogZ = exp2(-8.0 * (1.0 - fogF)); - break; - case 7: - fogF = 1.0 - fogF; - fogZ = exp2(-8.0 * fogF * fogF); - break; - default: - fogZ = 0.0; - break; - } - return vec4(mix(colorIn, vec4(0.0), clamp(fogZ, 0.0, 1.0)).rgb, colorIn.a); -} - -SBINDING(0) in VertToFrag vtf; -layout(location=0) out vec4 colorOut; -TBINDING0 uniform sampler2D tex; -void main() -{ - colorOut = MainPostFunc(vtf.color * moduColor * texture(tex, vtf.uv)); -} - -#fragment hlsl -struct Fog -{ - float4 color; - float A; - float B; - float C; - int mode; -}; - -cbuffer LineUniform : register(b0) -{ - float4 moduColor; - Fog fog; -}; - -SamplerState samp : register(s3); -Texture2D tex0 : register(t0); -struct VertToFrag -{ - float4 position : SV_Position; - float4 color : COLOR; - float2 uv : UV; -}; - -static float4 MainPostFunc(in VertToFrag vtf, float4 colorIn) -{ - float fogZ; - float fogF = saturate((fog.A / (fog.B - (1.0 - vtf.position.z))) - fog.C); - switch (fog.mode) - { - case 2: - fogZ = fogF; - break; - case 4: - fogZ = 1.0 - exp2(-8.0 * fogF); - break; - case 5: - fogZ = 1.0 - exp2(-8.0 * fogF * fogF); - break; - case 6: - fogZ = exp2(-8.0 * (1.0 - fogF)); - break; - case 7: - fogF = 1.0 - fogF; - fogZ = exp2(-8.0 * fogF * fogF); - break; - default: - fogZ = 0.0; - break; - } - return float4(lerp(colorIn, float4(0.0,0.0,0.0,0.0), saturate(fogZ)).rgb, colorIn.a); -} - -float4 main(in VertToFrag vtf) : SV_Target0 -{ - return MainPostFunc(vtf, vtf.color * moduColor * tex0.Sample(samp, vtf.uv)); -} - -#fragment metal -struct Fog -{ - float4 color; - float A; - float B; - float C; - int mode; -}; - -struct LineUniform -{ - float4 moduColor; - Fog fog; -}; - -struct VertToFrag -{ - float4 position [[ position ]]; - float4 color; - float2 uv; -}; - -static float4 MainPostFunc(thread VertToFrag& vtf, constant LineUniform& line, float4 colorIn) -{ - float fogZ; - float fogF = saturate((line.fog.A / (line.fog.B - (1.0 - vtf.position.z))) - line.fog.C); - switch (line.fog.mode) - { - case 2: - fogZ = fogF; - break; - case 4: - fogZ = 1.0 - exp2(-8.0 * fogF); - break; - case 5: - fogZ = 1.0 - exp2(-8.0 * fogF * fogF); - break; - case 6: - fogZ = exp2(-8.0 * (1.0 - fogF)); - break; - case 7: - fogF = 1.0 - fogF; - fogZ = exp2(-8.0 * fogF * fogF); - break; - default: - fogZ = 0.0; - break; - } - return float4(mix(colorIn, float4(0.0), saturate(fogZ)).rgb, colorIn.a); -} - -fragment float4 fmain(VertToFrag vtf [[ stage_in ]], - sampler samp [[ sampler(3) ]], - texture2d tex0 [[ texture(0) ]], - constant LineUniform& line [[ buffer(2) ]]) -{ - return MainPostFunc(vtf, line, vtf.color * line.moduColor * tex0.sample(samp, vtf.uv)); -} - -#shader CLineRendererShaderTexAdditiveAWrite : CLineRendererShaderTexAdditive -#alphawrite true - -#shader CLineRendererShaderTexAlphaZ : CLineRendererShaderTexAlpha -#srcfac srcalpha -#dstfac invsrcalpha -#depthtest lequal -#alphawrite false - -#shader CLineRendererShaderTexAlphaZAWrite : CLineRendererShaderTexAlphaZ -#alphawrite true - -#shader CLineRendererShaderTexAdditiveZ : CLineRendererShaderTexAdditive -#srcfac srcalpha -#dstfac one -#depthtest lequal -#alphawrite false - -#shader CLineRendererShaderTexAdditiveZAWrite : CLineRendererShaderTexAdditiveZ -#alphawrite true - -#shader CLineRendererShaderNoTexAlpha -#attribute position4 -#attribute color -#srcfac srcalpha -#dstfac invsrcalpha -#primitive tristrips -#depthtest none -#depthwrite false -#alphawrite false -#culling none - -#vertex glsl -layout(location=0) in vec4 posIn; -layout(location=1) in vec4 colorIn; - -struct VertToFrag -{ - vec4 color; -}; - -SBINDING(0) out VertToFrag vtf; -void main() -{ - vtf.color = colorIn; - gl_Position = posIn; -} - -#fragment glsl -struct Fog -{ - vec4 color; - float A; - float B; - float C; - int mode; -}; - -UBINDING0 uniform LineUniform -{ - vec4 moduColor; - Fog fog; -}; - -struct VertToFrag -{ - vec4 color; -}; - -vec4 MainPostFunc(vec4 colorIn) -{ - float fogZ; - float fogF = clamp((fog.A / (fog.B - gl_FragCoord.z)) - fog.C, 0.0, 1.0); - switch (fog.mode) - { - case 2: - fogZ = fogF; - break; - case 4: - fogZ = 1.0 - exp2(-8.0 * fogF); - break; - case 5: - fogZ = 1.0 - exp2(-8.0 * fogF * fogF); - break; - case 6: - fogZ = exp2(-8.0 * (1.0 - fogF)); - break; - case 7: - fogF = 1.0 - fogF; - fogZ = exp2(-8.0 * fogF * fogF); - break; - default: - fogZ = 0.0; - break; - } - return vec4(mix(colorIn, fog.color, clamp(fogZ, 0.0, 1.0)).rgb, colorIn.a); -} - -SBINDING(0) in VertToFrag vtf; -layout(location=0) out vec4 colorOut; -void main() -{ - colorOut = MainPostFunc(vtf.color * moduColor); -} - -#vertex hlsl -struct VertData -{ - float4 posIn : POSITION; - float4 colorIn : COLOR; -}; - -struct VertToFrag -{ - float4 position : SV_Position; - float4 color : COLOR; -}; - -VertToFrag main(in VertData v) -{ - VertToFrag vtf; - vtf.color = v.colorIn; - vtf.position = v.posIn; - return vtf; -} - -#fragment hlsl -struct Fog -{ - float4 color; - float A; - float B; - float C; - int mode; -}; - -cbuffer LineUniform : register(b0) -{ - float4 moduColor; - Fog fog; -}; - -struct VertToFrag -{ - float4 position : SV_Position; - float4 color : COLOR; -}; - -static float4 MainPostFunc(float4 colorIn, float4 FragCoord) -{ - float fogZ; - float fogF = saturate((fog.A / (fog.B - (1.0 - FragCoord.z))) - fog.C); - switch (fog.mode) - { - case 2: - fogZ = fogF; - break; - case 4: - fogZ = 1.0 - exp2(-8.0 * fogF); - break; - case 5: - fogZ = 1.0 - exp2(-8.0 * fogF * fogF); - break; - case 6: - fogZ = exp2(-8.0 * (1.0 - fogF)); - break; - case 7: - fogF = 1.0 - fogF; - fogZ = exp2(-8.0 * fogF * fogF); - break; - default: - fogZ = 0.0; - break; - } - return float4(lerp(colorIn, fog.color, saturate(fogZ)).rgb, colorIn.a); -} - -float4 main(in VertToFrag vtf) : SV_Target0 -{ - return MainPostFunc(vtf.color * moduColor, vtf.position); -} - -#vertex metal -struct VertData -{ - float4 posIn; - float4 colorIn; -}; - -struct VertToFrag -{ - float4 position [[ position ]]; - float4 color; -}; - -vertex VertToFrag vmain(constant VertData* va [[ buffer(0) ]], - uint vertId [[ vertex_id ]]) -{ - VertToFrag vtf; - constant VertData& v = va[vertId]; - vtf.color = v.colorIn; - vtf.position = v.posIn; - return vtf; -} - -#fragment metal -struct Fog -{ - float4 color; - float A; - float B; - float C; - int mode; -}; - -struct LineUniform -{ - float4 moduColor; - Fog fog; -}; - -struct VertToFrag -{ - float4 position [[ position ]]; - float4 color; -}; - -static float4 MainPostFunc(float4 colorIn, constant LineUniform& line, float4 FragCoord) -{ - float fogZ; - float fogF = saturate((line.fog.A / (line.fog.B - (1.0 - FragCoord.z))) - line.fog.C); - switch (line.fog.mode) - { - case 2: - fogZ = fogF; - break; - case 4: - fogZ = 1.0 - exp2(-8.0 * fogF); - break; - case 5: - fogZ = 1.0 - exp2(-8.0 * fogF * fogF); - break; - case 6: - fogZ = exp2(-8.0 * (1.0 - fogF)); - break; - case 7: - fogF = 1.0 - fogF; - fogZ = exp2(-8.0 * fogF * fogF); - break; - default: - fogZ = 0.0; - break; - } - return float4(mix(colorIn, line.fog.color, saturate(fogZ)).rgb, colorIn.a); -} - -fragment float4 fmain(VertToFrag vtf [[ stage_in ]], - constant LineUniform& line [[ buffer(2) ]]) -{ - return MainPostFunc(vtf.color * line.moduColor, line, vtf.position); -} - -#shader CLineRendererShaderNoTexAlphaAWrite : CLineRendererShaderNoTexAlpha -#alphawrite true - -#shader CLineRendererShaderNoTexAdditive : CLineRendererShaderNoTexAlpha -#srcfac srcalpha -#dstfac one -#depthtest none -#alphawrite false - -#fragment glsl -struct Fog -{ - vec4 color; - float A; - float B; - float C; - int mode; -}; - -UBINDING0 uniform LineUniform -{ - vec4 moduColor; - Fog fog; -}; - -struct VertToFrag -{ - vec4 color; -}; - -vec4 MainPostFunc(vec4 colorIn) -{ - float fogZ; - float fogF = clamp((fog.A / (fog.B - gl_FragCoord.z)) - fog.C, 0.0, 1.0); - switch (fog.mode) - { - case 2: - fogZ = fogF; - break; - case 4: - fogZ = 1.0 - exp2(-8.0 * fogF); - break; - case 5: - fogZ = 1.0 - exp2(-8.0 * fogF * fogF); - break; - case 6: - fogZ = exp2(-8.0 * (1.0 - fogF)); - break; - case 7: - fogF = 1.0 - fogF; - fogZ = exp2(-8.0 * fogF * fogF); - break; - default: - fogZ = 0.0; - break; - } - return vec4(mix(colorIn, vec4(0.0), clamp(fogZ, 0.0, 1.0)).rgb, colorIn.a); -} - -SBINDING(0) in VertToFrag vtf; -layout(location=0) out vec4 colorOut; -void main() -{ - colorOut = MainPostFunc(vtf.color * moduColor); -} - -#fragment hlsl -struct Fog -{ - float4 color; - float A; - float B; - float C; - int mode; -}; - -cbuffer LineUniform : register(b0) -{ - float4 moduColor; - Fog fog; -}; - -struct VertToFrag -{ - float4 position : SV_Position; - float4 color : COLOR; -}; - -static float4 MainPostFunc(float4 colorIn, float4 FragCoord) -{ - float fogZ; - float fogF = saturate((fog.A / (fog.B - (1.0 - FragCoord.z))) - fog.C); - switch (fog.mode) - { - case 2: - fogZ = fogF; - break; - case 4: - fogZ = 1.0 - exp2(-8.0 * fogF); - break; - case 5: - fogZ = 1.0 - exp2(-8.0 * fogF * fogF); - break; - case 6: - fogZ = exp2(-8.0 * (1.0 - fogF)); - break; - case 7: - fogF = 1.0 - fogF; - fogZ = exp2(-8.0 * fogF * fogF); - break; - default: - fogZ = 0.0; - break; - } - return float4(lerp(colorIn, float4(0.0,0.0,0.0,0.0), saturate(fogZ)).rgb, colorIn.a); -} - -float4 main(in VertToFrag vtf) : SV_Target0 -{ - return MainPostFunc(vtf.color * moduColor, vtf.position); -} - -#fragment metal -struct Fog -{ - float4 color; - float A; - float B; - float C; - int mode; -}; - -struct LineUniform -{ - float4 moduColor; - Fog fog; -}; - -struct VertToFrag -{ - float4 position [[ position ]]; - float4 color; -}; - -static float4 MainPostFunc(float4 colorIn, constant LineUniform& line, float4 FragCoord) -{ - float fogZ; - float fogF = saturate((line.fog.A / (line.fog.B - (1.0 - FragCoord.z))) - line.fog.C); - switch (line.fog.mode) - { - case 2: - fogZ = fogF; - break; - case 4: - fogZ = 1.0 - exp2(-8.0 * fogF); - break; - case 5: - fogZ = 1.0 - exp2(-8.0 * fogF * fogF); - break; - case 6: - fogZ = exp2(-8.0 * (1.0 - fogF)); - break; - case 7: - fogF = 1.0 - fogF; - fogZ = exp2(-8.0 * fogF * fogF); - break; - default: - fogZ = 0.0; - break; - } - return float4(mix(colorIn, float4(0.0), saturate(fogZ)).rgb, colorIn.a); -} - -fragment float4 fmain(VertToFrag vtf [[ stage_in ]], - constant LineUniform& line [[ buffer(2) ]]) -{ - return MainPostFunc(vtf.color * line.moduColor, line, vtf.position); -} - -#shader CLineRendererShaderNoTexAdditiveAWrite : CLineRendererShaderNoTexAdditive -#alphawrite true - -#shader CLineRendererShaderNoTexAlphaZ : CLineRendererShaderNoTexAlpha -#srcfac srcalpha -#dstfac invsrcalpha -#depthtest lequal -#alphawrite false - -#shader CLineRendererShaderNoTexAlphaZAWrite : CLineRendererShaderNoTexAlphaZ -#alphawrite true - -#shader CLineRendererShaderNoTexAdditiveZ : CLineRendererShaderNoTexAdditive -#srcfac srcalpha -#dstfac one -#depthtest lequal -#alphawrite false - -#shader CLineRendererShaderNoTexAdditiveZAWrite : CLineRendererShaderNoTexAdditiveZ -#alphawrite true - -#shader CLineRendererShaderNoTexAlphaZGEqual : CLineRendererShaderNoTexAlpha -#srcfac srcalpha -#dstfac invsrcalpha -#depthtest gequal -#alphawrite false - -#shader CLineRendererShaderNoTexAlphaZGEqualAWrite : CLineRendererShaderNoTexAlphaZGEqual -#alphawrite true diff --git a/Shaders/CMakeLists.txt b/Shaders/CMakeLists.txt deleted file mode 100644 index 73ba1eb03..000000000 --- a/Shaders/CMakeLists.txt +++ /dev/null @@ -1,65 +0,0 @@ -add_shader(CAABoxShader) -target_link_libraries(shader_CAABoxShader PRIVATE hecl-light) -add_shader(CCameraBlurFilter) -target_link_libraries(shader_CCameraBlurFilter PRIVATE hecl-light) -add_shader(CColoredQuadFilter) -target_link_libraries(shader_CColoredQuadFilter PRIVATE hecl-light) -add_shader(CColoredStripShader) -target_link_libraries(shader_CColoredStripShader PRIVATE hecl-light) -add_shader(CDecalShaders) -target_link_libraries(shader_CDecalShaders PRIVATE hecl-light) -add_shader(CElementGenShaders) -target_link_libraries(shader_CElementGenShaders PRIVATE hecl-light) -add_shader(CEnergyBarShader) -target_link_libraries(shader_CEnergyBarShader PRIVATE hecl-light) -add_shader(CEnvFxShaders) -target_link_libraries(shader_CEnvFxShaders PRIVATE hecl-light) -add_shader(CFogVolumeFilter) -target_link_libraries(shader_CFogVolumeFilter PRIVATE hecl-light) -add_shader(CFogVolumePlaneShader) -target_link_libraries(shader_CFogVolumePlaneShader PRIVATE hecl-light) -add_shader(CLineRendererShaders) -target_link_libraries(shader_CLineRendererShaders PRIVATE hecl-light) -add_shader(CMapSurfaceShader) -target_link_libraries(shader_CMapSurfaceShader PRIVATE hecl-light) -add_shader(CMoviePlayerShader) -target_link_libraries(shader_CMoviePlayerShader PRIVATE hecl-light) -add_shader(CNESShader) -target_link_libraries(shader_CNESShader PRIVATE hecl-light) -add_shader(CParticleSwooshShaders) -target_link_libraries(shader_CParticleSwooshShaders PRIVATE hecl-light) -add_shader(CPhazonSuitFilter) -target_link_libraries(shader_CPhazonSuitFilter PRIVATE hecl-light) -add_shader(CRadarPaintShader) -target_link_libraries(shader_CRadarPaintShader PRIVATE hecl-light) -add_shader(CRandomStaticFilter) -target_link_libraries(shader_CRandomStaticFilter PRIVATE hecl-light) -add_shader(CScanLinesFilter) -target_link_libraries(shader_CScanLinesFilter PRIVATE hecl-light) -add_shader(CSpaceWarpFilter) -target_link_libraries(shader_CSpaceWarpFilter PRIVATE hecl-light) -add_shader(CTextSupportShader) -target_link_libraries(shader_CTextSupportShader PRIVATE hecl-light) -add_shader(CTexturedQuadFilter) -target_link_libraries(shader_CTexturedQuadFilter PRIVATE hecl-light) -add_shader(CThermalColdFilter) -target_link_libraries(shader_CThermalColdFilter PRIVATE hecl-light) -add_shader(CThermalHotFilter) -target_link_libraries(shader_CThermalHotFilter PRIVATE hecl-light) -add_shader(CWorldShadowShader) -target_link_libraries(shader_CWorldShadowShader PRIVATE hecl-light) -add_shader(CXRayBlurFilter) -target_link_libraries(shader_CXRayBlurFilter PRIVATE hecl-light) -add_special_shader(shader_CFluidPlaneShader - shader_CFluidPlaneShader.cpp - shader_CFluidPlaneShaderGLSL.cpp - shader_CFluidPlaneShaderHLSL.cpp - shader_CFluidPlaneShaderMetal.cpp) -target_link_libraries(shader_CFluidPlaneShader PRIVATE hecl-light) -add_special_shader(shader_CModelShaders - shader_CModelShadersGLSL.cpp - shader_CModelShadersHLSL.cpp - shader_CModelShadersMetal.cpp) -target_link_libraries(shader_CModelShaders PRIVATE hecl-light nod) -# FIXME hack for DataSpec includes -target_include_directories(shader_CModelShaders PRIVATE ${CMAKE_SOURCE_DIR}) \ No newline at end of file diff --git a/Shaders/CMapSurfaceShader.shader b/Shaders/CMapSurfaceShader.shader deleted file mode 100644 index 645b3cbd4..000000000 --- a/Shaders/CMapSurfaceShader.shader +++ /dev/null @@ -1,118 +0,0 @@ -#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/CModelShaders.common.glsl b/Shaders/CModelShaders.common.glsl deleted file mode 100644 index e40749a21..000000000 --- a/Shaders/CModelShaders.common.glsl +++ /dev/null @@ -1,16 +0,0 @@ -#extension GL_ARB_shader_image_load_store: enable - -struct VertToFrag { - vec4 mvPos; - vec4 mvNorm; - vec2 lightmapUv; - vec2 diffuseUv; - vec2 emissiveUv; - vec2 specularUv; - vec2 extendedSpecularUv; - vec2 reflectionUv; - vec2 alphaUv; - vec2 extUvs[3]; - vec2 dynReflectionUvs[2]; - float dynReflectionAlpha; -}; diff --git a/Shaders/CModelShaders.common.hlsl b/Shaders/CModelShaders.common.hlsl deleted file mode 100644 index 49685d5bf..000000000 --- a/Shaders/CModelShaders.common.hlsl +++ /dev/null @@ -1,15 +0,0 @@ -struct VertToFrag { - float4 mvpPos : SV_Position; - float4 mvPos : POSITION; - float4 mvNorm : NORMAL; - float2 lightmapUv : UV0; - float2 diffuseUv : UV1; - float2 emissiveUv : UV2; - float2 specularUv : UV3; - float2 extendedSpecularUv : UV4; - float2 reflectionUv : UV5; - float2 alphaUv : UV6; - float2 extUvs[3] : EXTUV; - float2 dynReflectionUvs[2] : REFLECTUV; - float dynReflectionAlpha : REFLECTALPHA; -}; diff --git a/Shaders/CModelShaders.common.metal b/Shaders/CModelShaders.common.metal deleted file mode 100644 index 6e9e3cb69..000000000 --- a/Shaders/CModelShaders.common.metal +++ /dev/null @@ -1,21 +0,0 @@ -#include -using namespace metal; - -struct VertToFrag { - float4 mvpPos [[ position ]]; - float4 mvPos; - float4 mvNorm; - float2 lightmapUv; - float2 diffuseUv; - float2 emissiveUv; - float2 specularUv; - float2 extendedSpecularUv; - float2 reflectionUv; - float2 alphaUv; - float2 extUvs0; - float2 extUvs1; - float2 extUvs2; - float2 dynReflectionUvs0; - float2 dynReflectionUvs1; - float dynReflectionAlpha; -}; diff --git a/Shaders/CModelShaders.frag.glsl b/Shaders/CModelShaders.frag.glsl deleted file mode 100644 index e9612afc5..000000000 --- a/Shaders/CModelShaders.frag.glsl +++ /dev/null @@ -1,372 +0,0 @@ -#if !defined(URDE_ALPHA_TEST) && defined(GL_ARB_shader_image_load_store) -layout(early_fragment_tests) in; -#endif - -SBINDING(0) in VertToFrag vtf; -TBINDING0 uniform sampler2D lightmap; -TBINDING1 uniform sampler2D diffuse; -TBINDING2 uniform sampler2D emissive; -TBINDING3 uniform sampler2D specular; -TBINDING4 uniform sampler2D extendedSpecular; -TBINDING5 uniform sampler2D reflection; -TBINDING6 uniform sampler2D alpha; -TBINDING7 uniform sampler2D reflectionIndTex; -TBINDING8 uniform sampler2D extTex0; -TBINDING9 uniform sampler2D extTex1; -TBINDING10 uniform sampler2D extTex2; - -#if defined(URDE_LIGHTING_CUBE_REFLECTION) || defined(URDE_LIGHTING_CUBE_REFLECTION_SHADOW) -TBINDING11 uniform samplerCube reflectionTex; -#else -TBINDING11 uniform sampler2D reflectionTex; -#endif - -const vec3 kRGBToYPrime = vec3(0.299, 0.587, 0.114); - -/* -#if defined(ALPHA_%s) -vec3 SampleTexture_%s() { return texture(%s, vtf.%sUv).aaa; } -float SampleTextureAlpha_%s() { return texture(%s, vtf.%sUv).a; } -#else -vec3 SampleTexture_%s() { return texture(%s, vtf.%sUv).rgb; } -float SampleTextureAlpha_%s() { return dot(texture(%s, vtf.%sUv).rgb, kRGBToYPrime); } -#endif - */ - -#if defined(ALPHA_lightmap) -vec3 SampleTexture_lightmap() { return texture(lightmap, vtf.lightmapUv).aaa; } -float SampleTextureAlpha_lightmap() { return texture(lightmap, vtf.lightmapUv).a; } -#else -vec3 SampleTexture_lightmap() { return texture(lightmap, vtf.lightmapUv).rgb; } -float SampleTextureAlpha_lightmap() { return dot(texture(lightmap, vtf.lightmapUv).rgb, kRGBToYPrime); } -#endif - -#if defined(ALPHA_diffuse) -vec3 SampleTexture_diffuse() { return texture(diffuse, vtf.diffuseUv).aaa; } -float SampleTextureAlpha_diffuse() { return texture(diffuse, vtf.diffuseUv).a; } -#else -vec3 SampleTexture_diffuse() { return texture(diffuse, vtf.diffuseUv).rgb; } -float SampleTextureAlpha_diffuse() { return dot(texture(diffuse, vtf.diffuseUv).rgb, kRGBToYPrime); } -#endif - -#if defined(ALPHA_emissive) -vec3 SampleTexture_emissive() { return texture(emissive, vtf.emissiveUv).aaa; } -float SampleTextureAlpha_emissive() { return texture(emissive, vtf.emissiveUv).a; } -#else -vec3 SampleTexture_emissive() { return texture(emissive, vtf.emissiveUv).rgb; } -float SampleTextureAlpha_emissive() { return dot(texture(emissive, vtf.emissiveUv).rgb, kRGBToYPrime); } -#endif - -#if defined(ALPHA_specular) -vec3 SampleTexture_specular() { return texture(specular, vtf.specularUv).aaa; } -float SampleTextureAlpha_specular() { return texture(specular, vtf.specularUv).a; } -#else -vec3 SampleTexture_specular() { return texture(specular, vtf.specularUv).rgb; } -float SampleTextureAlpha_specular() { return dot(texture(specular, vtf.specularUv).rgb, kRGBToYPrime); } -#endif - -#if defined(ALPHA_extendedSpecular) -vec3 SampleTexture_extendedSpecular() { return texture(extendedSpecular, vtf.extendedSpecularUv).aaa; } -float SampleTextureAlpha_extendedSpecular() { return texture(extendedSpecular, vtf.extendedSpecularUv).a; } -#else -vec3 SampleTexture_extendedSpecular() { return texture(extendedSpecular, vtf.extendedSpecularUv).rgb; } -float SampleTextureAlpha_extendedSpecular() { return dot(texture(extendedSpecular, vtf.extendedSpecularUv).rgb, kRGBToYPrime); } -#endif - -#if defined(ALPHA_reflection) -vec3 SampleTexture_reflection() { return texture(reflection, vtf.reflectionUv).aaa; } -float SampleTextureAlpha_reflection() { return texture(reflection, vtf.reflectionUv).a; } -#else -vec3 SampleTexture_reflection() { return texture(reflection, vtf.reflectionUv).rgb; } -float SampleTextureAlpha_reflection() { return dot(texture(reflection, vtf.reflectionUv).rgb, kRGBToYPrime); } -#endif - -#if defined(ALPHA_alpha) -vec3 SampleTexture_alpha() { return texture(alpha, vtf.alphaUv).aaa; } -float SampleTextureAlpha_alpha() { return texture(alpha, vtf.alphaUv).a; } -#else -vec3 SampleTexture_alpha() { return texture(alpha, vtf.alphaUv).rgb; } -float SampleTextureAlpha_alpha() { return dot(texture(alpha, vtf.alphaUv).rgb, kRGBToYPrime); } -#endif - -#if defined(URDE_LIGHTING) || defined(URDE_LIGHTING_SHADOW) || defined(URDE_LIGHTING_CUBE_REFLECTION) || defined(URDE_LIGHTING_CUBE_REFLECTION_SHADOW) || defined(URDE_DISINTEGRATE) -struct Fog { - vec4 color; - float A; - float B; - float C; - int mode; -}; -#endif - -#if defined(URDE_LIGHTING) || defined(URDE_LIGHTING_SHADOW) || defined(URDE_LIGHTING_CUBE_REFLECTION) || defined(URDE_LIGHTING_CUBE_REFLECTION_SHADOW) -struct Light { - vec4 pos; - vec4 dir; - vec4 color; - vec4 linAtt; - vec4 angAtt; -}; - -UBINDING2 uniform LightingUniform { - Light lights[URDE_MAX_LIGHTS]; - vec4 ambient; - vec4 colorReg0; - vec4 colorReg1; - vec4 colorReg2; - vec4 mulColor; - vec4 addColor; - Fog fog; -}; -#else -const vec4 colorReg0 = vec4(1.0); -const vec4 colorReg1 = vec4(1.0); -const vec4 colorReg2 = vec4(1.0); -#endif - -#if defined(URDE_LIGHTING) || defined(URDE_LIGHTING_CUBE_REFLECTION) -vec3 LightingFunc() { - vec4 ret = ambient; - - for (int i = 0; i < URDE_MAX_LIGHTS; ++i) { - vec3 delta = vtf.mvPos.xyz - lights[i].pos.xyz; - float dist = length(delta); - vec3 deltaNorm = delta / dist; - float angDot = max(dot(deltaNorm, lights[i].dir.xyz), 0.0); - float att = 1.0 / (lights[i].linAtt[2] * dist * dist + - lights[i].linAtt[1] * dist + - lights[i].linAtt[0]); - float angAtt = lights[i].angAtt[2] * angDot * angDot + - lights[i].angAtt[1] * angDot + - lights[i].angAtt[0]; - ret += lights[i].color * angAtt * att * max(dot(-deltaNorm, vtf.mvNorm.xyz), 0.0); - } - - return clamp(ret.rgb, vec3(0.0), vec3(1.0)); -} -#endif - -#if defined(URDE_THERMAL_MODEL) -vec3 LightingFunc() { - return vec3(1.0); -} -UBINDING2 uniform ThermalUniform { - vec4 tmulColor; - vec4 taddColor; -}; -#endif - -#if defined(URDE_THERMAL_COLD) || defined(URDE_THERMAL_STATIC) -vec3 LightingFunc() { - return vec3(1.0); -} -#endif - -#if defined(URDE_SOLID) -vec3 LightingFunc() { - return vec3(1.0); -} -UBINDING2 uniform SolidUniform { - vec4 solidColor; -}; -#endif - -#if defined(URDE_MB_SHADOW) -vec3 LightingFunc() { - return vec3(1.0); -} -UBINDING2 uniform MBShadowUniform { - vec4 shadowUp; - float shadowId; -}; -#endif - -#if defined(URDE_LIGHTING_SHADOW) || defined(URDE_LIGHTING_CUBE_REFLECTION_SHADOW) -vec3 LightingFunc() { - vec2 shadowUV = vtf.extUvs[0]; - shadowUV.y = 1.0 - shadowUV.y; - - vec4 ret = ambient; - - vec3 delta = vtf.mvPos.xyz - lights[0].pos.xyz; - float dist = length(delta); - vec3 deltaNorm = delta / dist; - float angDot = max(dot(deltaNorm, lights[0].dir.xyz), 0.0); - float att = 1.0 / (lights[0].linAtt[2] * dist * dist + - lights[0].linAtt[1] * dist + - lights[0].linAtt[0]); - float angAtt = lights[0].angAtt[2] * angDot * angDot + - lights[0].angAtt[1] * angDot + - lights[0].angAtt[0]; - ret += lights[0].color * angAtt * att * max(dot(-deltaNorm, vtf.mvNorm.xyz), 0.0) * - texture(extTex0, shadowUV).r; - - for (int i = 1; i < URDE_MAX_LIGHTS; ++i) { - vec3 delta = vtf.mvPos.xyz - lights[i].pos.xyz; - float dist = length(delta); - vec3 deltaNorm = delta / dist; - float angDot = max(dot(deltaNorm, lights[i].dir.xyz), 0.0); - float att = 1.0 / (lights[i].linAtt[2] * dist * dist + - lights[i].linAtt[1] * dist + - lights[i].linAtt[0]); - float angAtt = lights[i].angAtt[2] * angDot * angDot + - lights[i].angAtt[1] * angDot + - lights[i].angAtt[0]; - ret += lights[i].color * angAtt * att * max(dot(-deltaNorm, vtf.mvNorm.xyz), 0.0); - } - - return clamp(ret.rgb, vec3(0.0), vec3(1.0)); -} -#endif - -#if defined(URDE_DISINTEGRATE) -UBINDING2 uniform DisintegrateUniform { - vec4 daddColor; - Fog fog; -}; -vec3 LightingFunc() { - return vec3(1.0); -} -#endif - -#if defined(URDE_LIGHTING) || defined(URDE_LIGHTING_SHADOW) || defined(URDE_LIGHTING_CUBE_REFLECTION) || defined(URDE_LIGHTING_CUBE_REFLECTION_SHADOW) || defined(URDE_DISINTEGRATE) -vec4 FogFunc(vec4 colorIn) { - float fogZ; - float fogF = clamp((fog.A / (fog.B - gl_FragCoord.z)) - fog.C, 0.0, 1.0); - switch (fog.mode) { - case 2: - fogZ = fogF; - break; - case 4: - fogZ = 1.0 - exp2(-8.0 * fogF); - break; - case 5: - fogZ = 1.0 - exp2(-8.0 * fogF * fogF); - break; - case 6: - fogZ = exp2(-8.0 * (1.0 - fogF)); - break; - case 7: - fogF = 1.0 - fogF; - fogZ = exp2(-8.0 * fogF * fogF); - break; - default: - fogZ = 0.0; - break; - } -#ifdef BLEND_DST_ONE - return vec4(mix(colorIn, vec4(0.0), clamp(fogZ, 0.0, 1.0)).rgb, colorIn.a); -#else - return vec4(mix(colorIn, fog.color, clamp(fogZ, 0.0, 1.0)).rgb, colorIn.a); -#endif -} -#endif - -#if defined(URDE_LIGHTING) || defined(URDE_LIGHTING_SHADOW) || defined(URDE_LIGHTING_CUBE_REFLECTION) || defined(URDE_LIGHTING_CUBE_REFLECTION_SHADOW) -vec4 PostFunc(vec4 colorIn) { - return FogFunc(colorIn) * mulColor + addColor; -} -#endif - -#if defined(URDE_THERMAL_MODEL) -vec4 PostFunc(vec4 colorIn) { - return texture(extTex0, vtf.extUvs[0]).rrrr * tmulColor + taddColor; -} -#endif - -#if defined(URDE_THERMAL_COLD) -vec4 PostFunc(vec4 colorIn) { - return colorIn * vec4(0.75); -} -#endif - -#if defined(URDE_THERMAL_STATIC) -vec4 PostFunc(vec4 colorIn) { - return colorIn; -} -#endif - -#if defined(URDE_SOLID) -vec4 PostFunc(vec4 colorIn) { - return solidColor; -} -#endif - -#if defined(URDE_MB_SHADOW) -vec4 PostFunc(vec4 colorIn) { - float idTexel = texture(extTex0, vtf.extUvs[0]).a; - float sphereTexel = texture(extTex1, vtf.extUvs[1]).r; - float fadeTexel = texture(extTex2, vtf.extUvs[2]).a; - float val = ((abs(idTexel - shadowId) < 0.001) ? - (dot(vtf.mvNorm.xyz, shadowUp.xyz) * shadowUp.w) : 0.0) * - sphereTexel * fadeTexel; - return vec4(0.0, 0.0, 0.0, val); -} -#endif - -#if defined(URDE_DISINTEGRATE) -vec4 PostFunc(vec4 colorIn) { - vec4 texel0 = texture(extTex0, vtf.extUvs[0]); - vec4 texel1 = texture(extTex0, vtf.extUvs[1]); - colorIn = mix(vec4(0.0), texel1, texel0); - colorIn.rgb += daddColor.rgb; - return FogFunc(colorIn); -} -#endif - -#if defined(URDE_LIGHTING_CUBE_REFLECTION) || defined(URDE_LIGHTING_CUBE_REFLECTION_SHADOW) -vec3 ReflectionFunc(float roughness) { - vec3 coords = reflect(vtf.mvPos.xyz, vtf.mvNorm.xyz); -#ifdef VULKAN - coords = vec3(coords.x, -coords.y, coords.z); -#endif - return texture(reflectionTex, coords, roughness).rgb; -} -#elif defined(URDE_REFLECTION_SIMPLE) -vec3 ReflectionFunc() { return texture(reflectionTex, vtf.dynReflectionUvs[1]).rgb * vtf.dynReflectionAlpha; } -#elif defined(URDE_REFLECTION_INDIRECT) -vec3 ReflectionFunc() { return texture(reflectionTex, (texture(reflectionIndTex, vtf.dynReflectionUvs[0]).ab - - vec2(0.5, 0.5)) * vec2(0.5, 0.5) + vtf.dynReflectionUvs[1]).rgb * vtf.dynReflectionAlpha; } -#else -vec3 ReflectionFunc() { return vec3(0.0); } -#endif - -layout(location=0) out vec4 colorOut; -void main() { - vec3 lighting = LightingFunc(); - vec4 tmp; -#if defined(URDE_LIGHTING_CUBE_REFLECTION) || defined(URDE_LIGHTING_CUBE_REFLECTION_SHADOW) - tmp.rgb = (SampleTexture_lightmap() * colorReg1.rgb + lighting) * SampleTexture_diffuse() + - SampleTexture_emissive() + (SampleTexture_specular() + SampleTexture_extendedSpecular() * lighting) * - (SampleTexture_reflection() * ReflectionFunc(clamp(0.5 - SampleTextureAlpha_specular(), 0.0, 1.0)) * 2.0); - tmp.a = SampleTextureAlpha_alpha(); -#elif defined(URDE_DIFFUSE_ONLY) - tmp.rgb = SampleTexture_diffuse(); - tmp.a = SampleTextureAlpha_alpha(); -#elif defined(RETRO_SHADER) - tmp.rgb = (SampleTexture_lightmap() * colorReg1.rgb + lighting) * SampleTexture_diffuse() + - SampleTexture_emissive() + (SampleTexture_specular() + SampleTexture_extendedSpecular() * lighting) * - SampleTexture_reflection() + ReflectionFunc(); - tmp.a = SampleTextureAlpha_alpha(); -#elif defined(RETRO_DYNAMIC_SHADER) - tmp.rgb = (SampleTexture_lightmap() * colorReg1.rgb + lighting) * SampleTexture_diffuse() * colorReg1.rgb + - SampleTexture_emissive() * colorReg1.rgb + (SampleTexture_specular() + SampleTexture_extendedSpecular() * lighting) * - SampleTexture_reflection() + ReflectionFunc(); - tmp.a = SampleTextureAlpha_alpha(); -#elif defined(RETRO_DYNAMIC_ALPHA_SHADER) - tmp.rgb = (SampleTexture_lightmap() * colorReg1.rgb + lighting) * SampleTexture_diffuse() * colorReg1.rgb + - SampleTexture_emissive() * colorReg1.rgb + (SampleTexture_specular() + SampleTexture_extendedSpecular() * lighting) * - SampleTexture_reflection() + ReflectionFunc(); - tmp.a = SampleTextureAlpha_alpha() * colorReg1.a; -#elif defined(RETRO_DYNAMIC_CHARACTER_SHADER) - tmp.rgb = (SampleTexture_lightmap() + lighting) * SampleTexture_diffuse() + - SampleTexture_emissive() * colorReg1.rgb + (SampleTexture_specular() + SampleTexture_extendedSpecular() * lighting) * - SampleTexture_reflection() + ReflectionFunc(); - tmp.a = SampleTextureAlpha_alpha(); -#endif - colorOut = PostFunc(tmp); -#if defined(URDE_ALPHA_TEST) - if (colorOut.a < 0.25) - discard; -#endif -} diff --git a/Shaders/CModelShaders.frag.hlsl b/Shaders/CModelShaders.frag.hlsl deleted file mode 100644 index d59f44185..000000000 --- a/Shaders/CModelShaders.frag.hlsl +++ /dev/null @@ -1,373 +0,0 @@ -SamplerState samp : register(s0); -SamplerState clampSamp : register(s1); -SamplerState reflectSamp : register(s2); -SamplerState clampEdgeSamp : register(s3); -Texture2D lightmap : register(t0); -Texture2D diffuse : register(t1); -Texture2D emissive : register(t2); -Texture2D specular : register(t3); -Texture2D extendedSpecular : register(t4); -Texture2D reflection : register(t5); -Texture2D alpha : register(t6); -Texture2D reflectionIndTex : register(t7); -Texture2D extTex0 : register(t8); -Texture2D extTex1 : register(t9); -Texture2D extTex2 : register(t10); - -#if defined(URDE_LIGHTING_CUBE_REFLECTION) || defined(URDE_LIGHTING_CUBE_REFLECTION_SHADOW) -TextureCube reflectionTex : register(t11); -#else -Texture2D reflectionTex : register(t11); -#endif - -static const float3 kRGBToYPrime = float3(0.299, 0.587, 0.114); - -/* -#if defined(ALPHA_%s) -float3 SampleTexture_%s(in VertToFrag vtf) { return %s.Sample(samp, vtf.%sUv).aaa; } -float SampleTextureAlpha_%s(in VertToFrag vtf) { return %s.Sample(samp, vtf.%sUv).a; } -#else -float3 SampleTexture_%s(in VertToFrag vtf) { return %s.Sample(samp, vtf.%sUv).rgb; } -float SampleTextureAlpha_%s(in VertToFrag vtf) { return dot(%s.Sample(samp, vtf.%sUv).rgb, kRGBToYPrime); } -#endif - */ - -#if defined(ALPHA_lightmap) -float3 SampleTexture_lightmap(in VertToFrag vtf) { return lightmap.Sample(samp, vtf.lightmapUv).aaa; } -float SampleTextureAlpha_lightmap(in VertToFrag vtf) { return lightmap.Sample(samp, vtf.lightmapUv).a; } -#else -float3 SampleTexture_lightmap(in VertToFrag vtf) { return lightmap.Sample(samp, vtf.lightmapUv).rgb; } -float SampleTextureAlpha_lightmap(in VertToFrag vtf) { return dot(lightmap.Sample(samp, vtf.lightmapUv).rgb, kRGBToYPrime); } -#endif - -#if defined(ALPHA_diffuse) -float3 SampleTexture_diffuse(in VertToFrag vtf) { return diffuse.Sample(samp, vtf.diffuseUv).aaa; } -float SampleTextureAlpha_diffuse(in VertToFrag vtf) { return diffuse.Sample(samp, vtf.diffuseUv).a; } -#else -float3 SampleTexture_diffuse(in VertToFrag vtf) { return diffuse.Sample(samp, vtf.diffuseUv).rgb; } -float SampleTextureAlpha_diffuse(in VertToFrag vtf) { return dot(diffuse.Sample(samp, vtf.diffuseUv).rgb, kRGBToYPrime); } -#endif - -#if defined(ALPHA_emissive) -float3 SampleTexture_emissive(in VertToFrag vtf) { return emissive.Sample(samp, vtf.emissiveUv).aaa; } -float SampleTextureAlpha_emissive(in VertToFrag vtf) { return emissive.Sample(samp, vtf.emissiveUv).a; } -#else -float3 SampleTexture_emissive(in VertToFrag vtf) { return emissive.Sample(samp, vtf.emissiveUv).rgb; } -float SampleTextureAlpha_emissive(in VertToFrag vtf) { return dot(emissive.Sample(samp, vtf.emissiveUv).rgb, kRGBToYPrime); } -#endif - -#if defined(ALPHA_specular) -float3 SampleTexture_specular(in VertToFrag vtf) { return specular.Sample(samp, vtf.specularUv).aaa; } -float SampleTextureAlpha_specular(in VertToFrag vtf) { return specular.Sample(samp, vtf.specularUv).a; } -#else -float3 SampleTexture_specular(in VertToFrag vtf) { return specular.Sample(samp, vtf.specularUv).rgb; } -float SampleTextureAlpha_specular(in VertToFrag vtf) { return dot(specular.Sample(samp, vtf.specularUv).rgb, kRGBToYPrime); } -#endif - -#if defined(ALPHA_extendedSpecular) -float3 SampleTexture_extendedSpecular(in VertToFrag vtf) { return extendedSpecular.Sample(samp, vtf.extendedSpecularUv).aaa; } -float SampleTextureAlpha_extendedSpecular(in VertToFrag vtf) { return extendedSpecular.Sample(samp, vtf.extendedSpecularUv).a; } -#else -float3 SampleTexture_extendedSpecular(in VertToFrag vtf) { return extendedSpecular.Sample(samp, vtf.extendedSpecularUv).rgb; } -float SampleTextureAlpha_extendedSpecular(in VertToFrag vtf) { return dot(extendedSpecular.Sample(samp, vtf.extendedSpecularUv).rgb, kRGBToYPrime); } -#endif - -#if defined(ALPHA_reflection) -float3 SampleTexture_reflection(in VertToFrag vtf) { return reflection.Sample(samp, vtf.reflectionUv).aaa; } -float SampleTextureAlpha_reflection(in VertToFrag vtf) { return reflection.Sample(samp, vtf.reflectionUv).a; } -#else -float3 SampleTexture_reflection(in VertToFrag vtf) { return reflection.Sample(samp, vtf.reflectionUv).rgb; } -float SampleTextureAlpha_reflection(in VertToFrag vtf) { return dot(reflection.Sample(samp, vtf.reflectionUv).rgb, kRGBToYPrime); } -#endif - -#if defined(ALPHA_alpha) -float3 SampleTexture_alpha(in VertToFrag vtf) { return alpha.Sample(samp, vtf.alphaUv).aaa; } -float SampleTextureAlpha_alpha(in VertToFrag vtf) { return alpha.Sample(samp, vtf.alphaUv).a; } -#else -float3 SampleTexture_alpha(in VertToFrag vtf) { return alpha.Sample(samp, vtf.alphaUv).rgb; } -float SampleTextureAlpha_alpha(in VertToFrag vtf) { return dot(alpha.Sample(samp, vtf.alphaUv).rgb, kRGBToYPrime); } -#endif - -#if defined(URDE_LIGHTING) || defined(URDE_LIGHTING_SHADOW) || defined(URDE_LIGHTING_CUBE_REFLECTION) || defined(URDE_LIGHTING_CUBE_REFLECTION_SHADOW) || defined(URDE_DISINTEGRATE) -struct Fog { - float4 color; - float A; - float B; - float C; - int mode; -}; -#endif - -#if defined(URDE_LIGHTING) || defined(URDE_LIGHTING_SHADOW) || defined(URDE_LIGHTING_CUBE_REFLECTION) || defined(URDE_LIGHTING_CUBE_REFLECTION_SHADOW) -struct Light { - float4 pos; - float4 dir; - float4 color; - float4 linAtt; - float4 angAtt; -}; - -cbuffer LightingUniform : register(b2) { - Light lights[URDE_MAX_LIGHTS]; - float4 ambient; - float4 colorReg0; - float4 colorReg1; - float4 colorReg2; - float4 mulColor; - float4 addColor; - Fog fog; -}; -#else -static const float4 colorReg0 = float4(1.0, 1.0, 1.0, 1.0); -static const float4 colorReg1 = float4(1.0, 1.0, 1.0, 1.0); -static const float4 colorReg2 = float4(1.0, 1.0, 1.0, 1.0); -#endif - -#if defined(URDE_LIGHTING) || defined(URDE_LIGHTING_CUBE_REFLECTION) -float3 LightingFunc(in VertToFrag vtf) { - float4 ret = ambient; - - for (int i = 0; i < URDE_MAX_LIGHTS; ++i) { - float3 delta = vtf.mvPos.xyz - lights[i].pos.xyz; - float dist = length(delta); - float3 deltaNorm = delta / dist; - float angDot = max(dot(deltaNorm, lights[i].dir.xyz), 0.0); - float att = 1.0 / (lights[i].linAtt[2] * dist * dist + - lights[i].linAtt[1] * dist + - lights[i].linAtt[0]); - float angAtt = lights[i].angAtt[2] * angDot * angDot + - lights[i].angAtt[1] * angDot + - lights[i].angAtt[0]; - ret += lights[i].color * angAtt * att * max(dot(-deltaNorm, vtf.mvNorm.xyz), 0.0); - } - - return saturate(ret.rgb); -} -#endif - -#if defined(URDE_THERMAL_MODEL) -float3 LightingFunc(in VertToFrag vtf) { - return float3(1.0, 1.0, 1.0); -} -cbuffer ThermalUniform : register(b2) { - float4 tmulColor; - float4 taddColor; -}; -#endif - -#if defined(URDE_THERMAL_COLD) || defined(URDE_THERMAL_STATIC) -float3 LightingFunc(in VertToFrag vtf) { - return float3(1.0, 1.0, 1.0); -} -#endif - -#if defined(URDE_SOLID) -float3 LightingFunc(in VertToFrag vtf) { - return float3(1.0, 1.0, 1.0); -} -cbuffer SolidUniform : register(b2) { - float4 solidColor; -}; -#endif - -#if defined(URDE_MB_SHADOW) -float3 LightingFunc(in VertToFrag vtf) { - return float3(1.0, 1.0, 1.0); -} -cbuffer MBShadowUniform : register(b2) { - float4 shadowUp; - float shadowId; -}; -#endif - -#if defined(URDE_LIGHTING_SHADOW) || defined(URDE_LIGHTING_CUBE_REFLECTION_SHADOW) -float3 LightingFunc(in VertToFrag vtf) { - float2 shadowUV = vtf.extUvs[0]; - shadowUV.y = 1.0 - shadowUV.y; - - float4 ret = ambient; - - float3 delta = vtf.mvPos.xyz - lights[0].pos.xyz; - float dist = length(delta); - float3 deltaNorm = delta / dist; - float angDot = max(dot(deltaNorm, lights[0].dir.xyz), 0.0); - float att = 1.0 / (lights[0].linAtt[2] * dist * dist + - lights[0].linAtt[1] * dist + - lights[0].linAtt[0]); - float angAtt = lights[0].angAtt[2] * angDot * angDot + - lights[0].angAtt[1] * angDot + - lights[0].angAtt[0]; - ret += lights[0].color * angAtt * att * max(dot(-deltaNorm, vtf.mvNorm.xyz), 0.0) * - extTex0.Sample(clampSamp, shadowUV).r; - - for (int i = 1; i < URDE_MAX_LIGHTS; ++i) { - float3 delta = vtf.mvPos.xyz - lights[i].pos.xyz; - float dist = length(delta); - float3 deltaNorm = delta / dist; - float angDot = max(dot(deltaNorm, lights[i].dir.xyz), 0.0); - float att = 1.0 / (lights[i].linAtt[2] * dist * dist + - lights[i].linAtt[1] * dist + - lights[i].linAtt[0]); - float angAtt = lights[i].angAtt[2] * angDot * angDot + - lights[i].angAtt[1] * angDot + - lights[i].angAtt[0]; - ret += lights[i].color * angAtt * att * max(dot(-deltaNorm, vtf.mvNorm.xyz), 0.0); - } - - return saturate(ret.rgb); -} -#endif - -#if defined(URDE_DISINTEGRATE) -cbuffer DisintegrateUniform : register(b2) { - float4 daddColor; - Fog fog; -}; -float3 LightingFunc(in VertToFrag vtf) { - return float3(1.0, 1.0, 1.0); -} -#endif - -#if defined(URDE_LIGHTING) || defined(URDE_LIGHTING_SHADOW) || defined(URDE_LIGHTING_CUBE_REFLECTION) || defined(URDE_LIGHTING_CUBE_REFLECTION_SHADOW) || defined(URDE_DISINTEGRATE) -float4 FogFunc(in VertToFrag vtf, float4 colorIn) { - float fogZ; - float fogF = saturate((fog.A / (fog.B - (1.0 - vtf.mvpPos.z))) - fog.C); - switch (fog.mode) { - case 2: - fogZ = fogF; - break; - case 4: - fogZ = 1.0 - exp2(-8.0 * fogF); - break; - case 5: - fogZ = 1.0 - exp2(-8.0 * fogF * fogF); - break; - case 6: - fogZ = exp2(-8.0 * (1.0 - fogF)); - break; - case 7: - fogF = 1.0 - fogF; - fogZ = exp2(-8.0 * fogF * fogF); - break; - default: - fogZ = 0.0; - break; - } -#ifdef BLEND_DST_ONE - return float4(lerp(colorIn, float4(0.0, 0.0, 0.0, 0.0), saturate(fogZ)).rgb, colorIn.a); -#else - return float4(lerp(colorIn, fog.color, saturate(fogZ)).rgb, colorIn.a); -#endif -} -#endif - -#if defined(URDE_LIGHTING) || defined(URDE_LIGHTING_SHADOW) || defined(URDE_LIGHTING_CUBE_REFLECTION) || defined(URDE_LIGHTING_CUBE_REFLECTION_SHADOW) -float4 PostFunc(in VertToFrag vtf, float4 colorIn) { - return FogFunc(vtf, colorIn) * mulColor + addColor; -} -#endif - -#if defined(URDE_THERMAL_MODEL) -float4 PostFunc(in VertToFrag vtf, float4 colorIn) { - return extTex0.Sample(samp, vtf.extUvs[0]).rrrr * tmulColor + taddColor; -} -#endif - -#if defined(URDE_THERMAL_COLD) -float4 PostFunc(in VertToFrag vtf, float4 colorIn) { - return colorIn * float4(0.75, 0.75, 0.75, 0.75); -} -#endif - -#if defined(URDE_THERMAL_STATIC) -float4 PostFunc(in VertToFrag vtf, float4 colorIn) { - return colorIn; -} -#endif - -#if defined(URDE_SOLID) -float4 PostFunc(in VertToFrag vtf, float4 colorIn) { - return solidColor; -} -#endif - -#if defined(URDE_MB_SHADOW) -float4 PostFunc(in VertToFrag vtf, float4 colorIn) { - float idTexel = extTex0.Sample(samp, vtf.extUvs[0]).a; - float sphereTexel = extTex1.Sample(clampEdgeSamp, vtf.extUvs[1]).r; - float fadeTexel = extTex2.Sample(clampEdgeSamp, vtf.extUvs[2]).a; - float val = ((abs(idTexel - shadowId) < 0.001) ? - (dot(vtf.mvNorm.xyz, shadowUp.xyz) * shadowUp.w) : 0.0) * - sphereTexel * fadeTexel; - return float4(0.0, 0.0, 0.0, val); -} -#endif - -#if defined(URDE_DISINTEGRATE) -float4 PostFunc(in VertToFrag vtf, float4 colorIn) { - float4 texel0 = extTex0.Sample(samp, vtf.extUvs[0]); - float4 texel1 = extTex0.Sample(samp, vtf.extUvs[1]); - colorIn = lerp(float4(0.0, 0.0, 0.0, 0.0), texel1, texel0); - colorIn.rgb += daddColor.rgb; - return FogFunc(vtf, colorIn); -} -#endif - -#if defined(URDE_LIGHTING_CUBE_REFLECTION) || defined(URDE_LIGHTING_CUBE_REFLECTION_SHADOW) -float3 ReflectionFunc(in VertToFrag vtf, float roughness) { - float3 coords = reflect(vtf.mvPos.xyz, vtf.mvNorm.xyz); - return reflectionTex.SampleBias(reflectSamp, float3(coords.x, -coords.y, coords.z), roughness).rgb; -} -#elif defined(URDE_REFLECTION_SIMPLE) -float3 ReflectionFunc(in VertToFrag vtf) -{ return reflectionTex.Sample(reflectSamp, vtf.dynReflectionUvs[1]).rgb * vtf.dynReflectionAlpha; } -#elif defined(URDE_REFLECTION_INDIRECT) -float3 ReflectionFunc(in VertToFrag vtf) -{ return reflectionTex.Sample(reflectSamp, (reflectionIndTex.Sample(samp, vtf.dynReflectionUvs[0]).ab - - float2(0.5, 0.5)) * float2(0.5, 0.5) + vtf.dynReflectionUvs[1]).rgb * vtf.dynReflectionAlpha; } -#else -float3 ReflectionFunc(in VertToFrag vtf) { return float3(0.0, 0.0, 0.0); } -#endif - -#if !defined(URDE_ALPHA_TEST) -[earlydepthstencil] -#endif -float4 main(in VertToFrag vtf) : SV_Target0 { - float3 lighting = LightingFunc(vtf); - float4 tmp; -#if defined(URDE_LIGHTING_CUBE_REFLECTION) || defined(URDE_LIGHTING_CUBE_REFLECTION_SHADOW) - tmp.rgb = (SampleTexture_lightmap(vtf) * colorReg1.rgb + lighting) * SampleTexture_diffuse(vtf) + - SampleTexture_emissive(vtf) + (SampleTexture_specular(vtf) + SampleTexture_extendedSpecular(vtf) * lighting) * - (SampleTexture_reflection(vtf) * ReflectionFunc(vtf, saturate(0.5 - SampleTextureAlpha_specular(vtf))) * 2.0); - tmp.a = SampleTextureAlpha_alpha(vtf); -#elif defined(URDE_DIFFUSE_ONLY) - tmp.rgb = SampleTexture_diffuse(vtf); - tmp.a = SampleTextureAlpha_alpha(vtf); -#elif defined(RETRO_SHADER) - tmp.rgb = (SampleTexture_lightmap(vtf) * colorReg1.rgb + lighting) * SampleTexture_diffuse(vtf) + - SampleTexture_emissive(vtf) + (SampleTexture_specular(vtf) + SampleTexture_extendedSpecular(vtf) * lighting) * - SampleTexture_reflection(vtf) + ReflectionFunc(vtf); - tmp.a = SampleTextureAlpha_alpha(vtf); -#elif defined(RETRO_DYNAMIC_SHADER) - tmp.rgb = (SampleTexture_lightmap(vtf) * colorReg1.rgb + lighting) * SampleTexture_diffuse(vtf) * colorReg1.rgb + - SampleTexture_emissive(vtf) * colorReg1.rgb + (SampleTexture_specular(vtf) + SampleTexture_extendedSpecular(vtf) * lighting) * - SampleTexture_reflection(vtf) + ReflectionFunc(vtf); - tmp.a = SampleTextureAlpha_alpha(vtf); -#elif defined(RETRO_DYNAMIC_ALPHA_SHADER) - tmp.rgb = (SampleTexture_lightmap(vtf) * colorReg1.rgb + lighting) * SampleTexture_diffuse(vtf) * colorReg1.rgb + - SampleTexture_emissive(vtf) * colorReg1.rgb + (SampleTexture_specular(vtf) + SampleTexture_extendedSpecular(vtf) * lighting) * - SampleTexture_reflection(vtf) + ReflectionFunc(vtf); - tmp.a = SampleTextureAlpha_alpha(vtf) * colorReg1.a; -#elif defined(RETRO_DYNAMIC_CHARACTER_SHADER) - tmp.rgb = (SampleTexture_lightmap(vtf) + lighting) * SampleTexture_diffuse(vtf) + - SampleTexture_emissive(vtf) * colorReg1.rgb + (SampleTexture_specular(vtf) + SampleTexture_extendedSpecular(vtf) * lighting) * - SampleTexture_reflection(vtf) + ReflectionFunc(vtf); - tmp.a = SampleTextureAlpha_alpha(vtf); -#endif - float4 colorOut = PostFunc(vtf, tmp); -#if defined(URDE_ALPHA_TEST) - if (colorOut.a < 0.25) - discard; -#endif - return colorOut; -} diff --git a/Shaders/CModelShaders.frag.metal b/Shaders/CModelShaders.frag.metal deleted file mode 100644 index 679e02f92..000000000 --- a/Shaders/CModelShaders.frag.metal +++ /dev/null @@ -1,389 +0,0 @@ -constant float3 kRGBToYPrime = float3(0.299, 0.587, 0.114); - -/* -#if defined(ALPHA_%s) -#define SampleTexture_%s() %s.sample(samp, vtf.%sUv).aaa -#define SampleTextureAlpha_%s() %s.sample(samp, vtf.%sUv).a -#else -#define SampleTexture_%s() %s.sample(samp, vtf.%sUv).rgb -#define SampleTextureAlpha_%s() dot(%s.sample(samp, vtf.%sUv).rgb, kRGBToYPrime) -#endif - */ - -#if defined(ALPHA_lightmap) -#define SampleTexture_lightmap() lightmap.sample(samp, vtf.lightmapUv).aaa -#define SampleTextureAlpha_lightmap() lightmap.sample(samp, vtf.lightmapUv).a -#else -#define SampleTexture_lightmap() lightmap.sample(samp, vtf.lightmapUv).rgb -#define SampleTextureAlpha_lightmap() dot(lightmap.sample(samp, vtf.lightmapUv).rgb, kRGBToYPrime) -#endif - -#if defined(ALPHA_diffuse) -#define SampleTexture_diffuse() diffuse.sample(samp, vtf.diffuseUv).aaa -#define SampleTextureAlpha_diffuse() diffuse.sample(samp, vtf.diffuseUv).a -#else -#define SampleTexture_diffuse() diffuse.sample(samp, vtf.diffuseUv).rgb -#define SampleTextureAlpha_diffuse() dot(diffuse.sample(samp, vtf.diffuseUv).rgb, kRGBToYPrime) -#endif - -#if defined(ALPHA_emissive) -#define SampleTexture_emissive() emissive.sample(samp, vtf.emissiveUv).aaa -#define SampleTextureAlpha_emissive() emissive.sample(samp, vtf.emissiveUv).a -#else -#define SampleTexture_emissive() emissive.sample(samp, vtf.emissiveUv).rgb -#define SampleTextureAlpha_emissive() dot(emissive.sample(samp, vtf.emissiveUv).rgb, kRGBToYPrime) -#endif - -#if defined(ALPHA_specular) -#define SampleTexture_specular() specular.sample(samp, vtf.specularUv).aaa -#define SampleTextureAlpha_specular() specular.sample(samp, vtf.specularUv).a -#else -#define SampleTexture_specular() specular.sample(samp, vtf.specularUv).rgb -#define SampleTextureAlpha_specular() dot(specular.sample(samp, vtf.specularUv).rgb, kRGBToYPrime) -#endif - -#if defined(ALPHA_extendedSpecular) -#define SampleTexture_extendedSpecular() extendedSpecular.sample(samp, vtf.extendedSpecularUv).aaa -#define SampleTextureAlpha_extendedSpecular() extendedSpecular.sample(samp, vtf.extendedSpecularUv).a -#else -#define SampleTexture_extendedSpecular() extendedSpecular.sample(samp, vtf.extendedSpecularUv).rgb -#define SampleTextureAlpha_extendedSpecular() dot(extendedSpecular.sample(samp, vtf.extendedSpecularUv).rgb, kRGBToYPrime) -#endif - -#if defined(ALPHA_reflection) -#define SampleTexture_reflection() reflection.sample(samp, vtf.reflectionUv).aaa -#define SampleTextureAlpha_reflection() reflection.sample(samp, vtf.reflectionUv).a -#else -#define SampleTexture_reflection() reflection.sample(samp, vtf.reflectionUv).rgb -#define SampleTextureAlpha_reflection() dot(reflection.sample(samp, vtf.reflectionUv).rgb, kRGBToYPrime) -#endif - -#if defined(ALPHA_alpha) -#define SampleTexture_alpha() alpha.sample(samp, vtf.alphaUv).aaa -#define SampleTextureAlpha_alpha() alpha.sample(samp, vtf.alphaUv).a -#else -#define SampleTexture_alpha() alpha.sample(samp, vtf.alphaUv).rgb -#define SampleTextureAlpha_alpha() dot(alpha.sample(samp, vtf.alphaUv).rgb, kRGBToYPrime) -#endif - -#if defined(URDE_LIGHTING) || defined(URDE_LIGHTING_SHADOW) || defined(URDE_LIGHTING_CUBE_REFLECTION) || defined(URDE_LIGHTING_CUBE_REFLECTION_SHADOW) || defined(URDE_DISINTEGRATE) -struct Fog { - float4 color; - float A; - float B; - float C; - int mode; -}; -#endif - -#if defined(URDE_LIGHTING) || defined(URDE_LIGHTING_SHADOW) || defined(URDE_LIGHTING_CUBE_REFLECTION) || defined(URDE_LIGHTING_CUBE_REFLECTION_SHADOW) -struct Light { - float4 pos; - float4 dir; - float4 color; - float4 linAtt; - float4 angAtt; -}; - -struct LightingUniform { - Light lights[URDE_MAX_LIGHTS]; - float4 ambient; - float4 colorReg0; - float4 colorReg1; - float4 colorReg2; - float4 mulColor; - float4 addColor; - Fog fog; -}; -#define colorReg0 lu.colorReg0 -#define colorReg1 lu.colorReg1 -#define colorReg2 lu.colorReg2 -#else -constant float4 colorReg0 = float4(1.0, 1.0, 1.0, 1.0); -constant float4 colorReg1 = float4(1.0, 1.0, 1.0, 1.0); -constant float4 colorReg2 = float4(1.0, 1.0, 1.0, 1.0); -#endif - -#if defined(URDE_LIGHTING) || defined(URDE_LIGHTING_CUBE_REFLECTION) -float3 LightingFunc(thread VertToFrag& vtf, constant LightingUniform& lu, texture2d extTex0, sampler clampSamp) { - float4 ret = lu.ambient; - - for (int i = 0; i < URDE_MAX_LIGHTS; ++i) { - float3 delta = vtf.mvPos.xyz - lu.lights[i].pos.xyz; - float dist = length(delta); - float3 deltaNorm = delta / dist; - float angDot = max(dot(deltaNorm, lu.lights[i].dir.xyz), 0.0); - float att = 1.0 / (lu.lights[i].linAtt[2] * dist * dist + - lu.lights[i].linAtt[1] * dist + - lu.lights[i].linAtt[0]); - float angAtt = lu.lights[i].angAtt[2] * angDot * angDot + - lu.lights[i].angAtt[1] * angDot + - lu.lights[i].angAtt[0]; - ret += lu.lights[i].color * angAtt * att * max(dot(-deltaNorm, vtf.mvNorm.xyz), 0.0); - } - - return saturate(ret.rgb); -} -#endif - -#if defined(URDE_THERMAL_MODEL) -struct LightingUniform { - float4 tmulColor; - float4 taddColor; -}; -float3 LightingFunc(thread VertToFrag& vtf, constant LightingUniform& lu, texture2d extTex0, sampler clampSamp) { - return float3(1.0, 1.0, 1.0); -} -#endif - -#if defined(URDE_THERMAL_COLD) || defined(URDE_THERMAL_STATIC) -struct LightingUniform {}; -float3 LightingFunc(thread VertToFrag& vtf, constant LightingUniform& lu, texture2d extTex0, sampler clampSamp) { - return float3(1.0, 1.0, 1.0); -} -#endif - -#if defined(URDE_SOLID) -struct LightingUniform { - float4 solidColor; -}; -float3 LightingFunc(thread VertToFrag& vtf, constant LightingUniform& lu, texture2d extTex0, sampler clampSamp) { - return float3(1.0, 1.0, 1.0); -} -#endif - -#if defined(URDE_MB_SHADOW) -struct LightingUniform { - float4 shadowUp; - float shadowId; -}; -float3 LightingFunc(thread VertToFrag& vtf, constant LightingUniform& lu, texture2d extTex0, sampler clampSamp) { - return float3(1.0, 1.0, 1.0); -} -#endif - -#if defined(URDE_LIGHTING_SHADOW) || defined(URDE_LIGHTING_CUBE_REFLECTION_SHADOW) -float3 LightingFunc(thread VertToFrag& vtf, constant LightingUniform& lu, texture2d extTex0, sampler clampSamp) { - float2 shadowUV = vtf.extUvs0; - shadowUV.y = 1.0 - shadowUV.y; - - float4 ret = lu.ambient; - - float3 delta = vtf.mvPos.xyz - lu.lights[0].pos.xyz; - float dist = length(delta); - float3 deltaNorm = delta / dist; - float angDot = max(dot(deltaNorm, lu.lights[0].dir.xyz), 0.0); - float att = 1.0 / (lu.lights[0].linAtt[2] * dist * dist + - lu.lights[0].linAtt[1] * dist + - lu.lights[0].linAtt[0]); - float angAtt = lu.lights[0].angAtt[2] * angDot * angDot + - lu.lights[0].angAtt[1] * angDot + - lu.lights[0].angAtt[0]; - ret += lu.lights[0].color * angAtt * att * max(dot(-deltaNorm, vtf.mvNorm.xyz), 0.0) * - extTex0.sample(clampSamp, shadowUV).r; - - for (int i = 1; i < URDE_MAX_LIGHTS; ++i) { - float3 delta = vtf.mvPos.xyz - lu.lights[i].pos.xyz; - float dist = length(delta); - float3 deltaNorm = delta / dist; - float angDot = max(dot(deltaNorm, lu.lights[i].dir.xyz), 0.0); - float att = 1.0 / (lu.lights[i].linAtt[2] * dist * dist + - lu.lights[i].linAtt[1] * dist + - lu.lights[i].linAtt[0]); - float angAtt = lu.lights[i].angAtt[2] * angDot * angDot + - lu.lights[i].angAtt[1] * angDot + - lu.lights[i].angAtt[0]; - ret += lu.lights[i].color * angAtt * att * max(dot(-deltaNorm, vtf.mvNorm.xyz), 0.0); - } - - return saturate(ret.rgb); -} -#endif - -#if defined(URDE_DISINTEGRATE) -struct LightingUniform { - float4 daddColor; - Fog fog; -}; -float3 LightingFunc(thread VertToFrag& vtf, constant LightingUniform& lu, texture2d extTex0, sampler clampSamp) { - return float3(1.0, 1.0, 1.0); -} -#endif - -#if defined(URDE_LIGHTING) || defined(URDE_LIGHTING_SHADOW) || defined(URDE_LIGHTING_CUBE_REFLECTION) || defined(URDE_LIGHTING_CUBE_REFLECTION_SHADOW) || defined(URDE_DISINTEGRATE) -float4 FogFunc(thread VertToFrag& vtf, constant LightingUniform& lu, float4 colorIn) { - float fogZ; - float fogF = saturate((lu.fog.A / (lu.fog.B - (1.0 - vtf.mvpPos.z))) - lu.fog.C); - switch (lu.fog.mode) { - case 2: - fogZ = fogF; - break; - case 4: - fogZ = 1.0 - exp2(-8.0 * fogF); - break; - case 5: - fogZ = 1.0 - exp2(-8.0 * fogF * fogF); - break; - case 6: - fogZ = exp2(-8.0 * (1.0 - fogF)); - break; - case 7: - fogF = 1.0 - fogF; - fogZ = exp2(-8.0 * fogF * fogF); - break; - default: - fogZ = 0.0; - break; - } -#ifdef BLEND_DST_ONE - return float4(mix(colorIn, float4(0.0, 0.0, 0.0, 0.0), saturate(fogZ)).rgb, colorIn.a); -#else - return float4(mix(colorIn, lu.fog.color, saturate(fogZ)).rgb, colorIn.a); -#endif -} -#endif - -#if defined(URDE_LIGHTING) || defined(URDE_LIGHTING_SHADOW) || defined(URDE_LIGHTING_CUBE_REFLECTION) || defined(URDE_LIGHTING_CUBE_REFLECTION_SHADOW) -float4 PostFunc(thread VertToFrag& vtf, constant LightingUniform& lu, - texture2d extTex0, texture2d extTex1, texture2d extTex2, - sampler samp, sampler clampSamp, sampler clampEdgeSamp, float4 colorIn) { - return FogFunc(vtf, lu, colorIn) * lu.mulColor + lu.addColor; -} -#endif - -#if defined(URDE_THERMAL_MODEL) -float4 PostFunc(thread VertToFrag& vtf, constant LightingUniform& lu, - texture2d extTex0, texture2d extTex1, texture2d extTex2, - sampler samp, sampler clampSamp, sampler clampEdgeSamp, float4 colorIn) { - return extTex0.sample(samp, vtf.extUvs0).rrrr * lu.tmulColor + lu.taddColor; -} -#endif - -#if defined(URDE_THERMAL_COLD) -float4 PostFunc(thread VertToFrag& vtf, constant LightingUniform& lu, - texture2d extTex0, texture2d extTex1, texture2d extTex2, - sampler samp, sampler clampSamp, sampler clampEdgeSamp, float4 colorIn) { - return colorIn * float4(0.75, 0.75, 0.75, 0.75); -} -#endif - -#if defined(URDE_THERMAL_STATIC) -float4 PostFunc(thread VertToFrag& vtf, constant LightingUniform& lu, - texture2d extTex0, texture2d extTex1, texture2d extTex2, - sampler samp, sampler clampSamp, sampler clampEdgeSamp, float4 colorIn) { - return colorIn; -} -#endif - -#if defined(URDE_SOLID) -float4 PostFunc(thread VertToFrag& vtf, constant LightingUniform& lu, - texture2d extTex0, texture2d extTex1, texture2d extTex2, - sampler samp, sampler clampSamp, sampler clampEdgeSamp, float4 colorIn) { - return lu.solidColor; -} -#endif - -#if defined(URDE_MB_SHADOW) -float4 PostFunc(thread VertToFrag& vtf, constant LightingUniform& lu, - texture2d extTex0, texture2d extTex1, texture2d extTex2, - sampler samp, sampler clampSamp, sampler clampEdgeSamp, float4 colorIn) { - float idTexel = extTex0.sample(samp, vtf.extUvs0).a; - float sphereTexel = extTex1.sample(clampEdgeSamp, vtf.extUvs1).r; - float fadeTexel = extTex2.sample(clampEdgeSamp, vtf.extUvs2).a; - float val = ((abs(idTexel - lu.shadowId) < 0.001) ? - (dot(vtf.mvNorm.xyz, lu.shadowUp.xyz) * lu.shadowUp.w) : 0.0) * - sphereTexel * fadeTexel; - return float4(0.0, 0.0, 0.0, val); -} -#endif - -#if defined(URDE_DISINTEGRATE) -float4 PostFunc(thread VertToFrag& vtf, constant LightingUniform& lu, - texture2d extTex0, texture2d extTex1, texture2d extTex2, - sampler samp, sampler clampSamp, sampler clampEdgeSamp, float4 colorIn) { - float4 texel0 = extTex0.sample(samp, vtf.extUvs0); - float4 texel1 = extTex0.sample(samp, vtf.extUvs1); - colorIn = mix(float4(0.0, 0.0, 0.0, 0.0), texel1, texel0); - colorIn.rgb += lu.daddColor.rgb; - return FogFunc(vtf, lu, colorIn); -} -#endif - -#if defined(URDE_LIGHTING_CUBE_REFLECTION) || defined(URDE_LIGHTING_CUBE_REFLECTION_SHADOW) -#define ReflectionFunc(roughness) \ - (reflectionTex.sample(reflectSamp, float3(reflectionCoords.x, -reflectionCoords.y, reflectionCoords.z), bias(roughness)).rgb) -#elif defined(URDE_REFLECTION_SIMPLE) -#define ReflectionFunc() \ - (reflectionTex.sample(reflectSamp, vtf.dynReflectionUvs1).rgb * vtf.dynReflectionAlpha) -#elif defined(URDE_REFLECTION_INDIRECT) -#define ReflectionFunc() \ - (reflectionTex.sample(reflectSamp, (reflectionIndTex.sample(samp, vtf.dynReflectionUvs0).ab - \ - float2(0.5, 0.5)) * float2(0.5, 0.5) + vtf.dynReflectionUvs1).rgb * vtf.dynReflectionAlpha) -#else -#define ReflectionFunc() float3(0.0, 0.0, 0.0) -#endif - -#if !defined(URDE_ALPHA_TEST) -[[ early_fragment_tests ]] -#endif -fragment float4 fmain(VertToFrag vtf [[ stage_in ]], - sampler samp [[ sampler(0) ]], - sampler clampSamp [[ sampler(1) ]], - sampler reflectSamp [[ sampler(2) ]], - sampler clampEdgeSamp [[ sampler(3) ]], - texture2d lightmap [[ texture(0) ]], - texture2d diffuse [[ texture(1) ]], - texture2d emissive [[ texture(2) ]], - texture2d specular [[ texture(3) ]], - texture2d extendedSpecular [[ texture(4) ]], - texture2d reflection [[ texture(5) ]], - texture2d alpha [[ texture(6) ]], - texture2d reflectionIndTex [[ texture(7) ]], - texture2d extTex0 [[ texture(8) ]], - texture2d extTex1 [[ texture(9) ]], - texture2d extTex2 [[ texture(10) ]], -#if defined(URDE_LIGHTING_CUBE_REFLECTION) || defined(URDE_LIGHTING_CUBE_REFLECTION_SHADOW) - texturecube reflectionTex [[ texture(11) ]], -#else - texture2d reflectionTex [[ texture(11) ]], -#endif - constant LightingUniform& lu [[ buffer(4) ]]) { - float3 lighting = LightingFunc(vtf, lu, extTex0, clampSamp); - float4 tmp; -#if defined(URDE_LIGHTING_CUBE_REFLECTION) || defined(URDE_LIGHTING_CUBE_REFLECTION_SHADOW) - float3 reflectionCoords = reflect(vtf.mvPos.xyz, vtf.mvNorm.xyz); - tmp.rgb = (SampleTexture_lightmap() * colorReg1.rgb + lighting) * SampleTexture_diffuse() + - SampleTexture_emissive() + (SampleTexture_specular() + SampleTexture_extendedSpecular() * lighting) * - (SampleTexture_reflection() * ReflectionFunc(saturate(0.5 - SampleTextureAlpha_specular())) * 2.0); - tmp.a = SampleTextureAlpha_alpha(); -#elif defined(URDE_DIFFUSE_ONLY) - tmp.rgb = SampleTexture_diffuse(); - tmp.a = SampleTextureAlpha_alpha(); -#elif defined(RETRO_SHADER) - tmp.rgb = (SampleTexture_lightmap() * colorReg1.rgb + lighting) * SampleTexture_diffuse() + - SampleTexture_emissive() + (SampleTexture_specular() + SampleTexture_extendedSpecular() * lighting) * - SampleTexture_reflection() + ReflectionFunc(); - tmp.a = SampleTextureAlpha_alpha(); -#elif defined(RETRO_DYNAMIC_SHADER) - tmp.rgb = (SampleTexture_lightmap() * colorReg1.rgb + lighting) * SampleTexture_diffuse() * colorReg1.rgb + - SampleTexture_emissive() * colorReg1.rgb + (SampleTexture_specular() + SampleTexture_extendedSpecular() * lighting) * - SampleTexture_reflection() + ReflectionFunc(); - tmp.a = SampleTextureAlpha_alpha(); -#elif defined(RETRO_DYNAMIC_ALPHA_SHADER) - tmp.rgb = (SampleTexture_lightmap() * colorReg1.rgb + lighting) * SampleTexture_diffuse() * colorReg1.rgb + - SampleTexture_emissive() * colorReg1.rgb + (SampleTexture_specular() + SampleTexture_extendedSpecular() * lighting) * - SampleTexture_reflection() + ReflectionFunc(); - tmp.a = SampleTextureAlpha_alpha() * colorReg1.a; -#elif defined(RETRO_DYNAMIC_CHARACTER_SHADER) - tmp.rgb = (SampleTexture_lightmap() + lighting) * SampleTexture_diffuse() + - SampleTexture_emissive() * colorReg1.rgb + (SampleTexture_specular() + SampleTexture_extendedSpecular() * lighting) * - SampleTexture_reflection() + ReflectionFunc(); - tmp.a = SampleTextureAlpha_alpha(); -#endif - float4 colorOut = PostFunc(vtf, lu, extTex0, extTex1, extTex2, samp, clampSamp, clampEdgeSamp, tmp); -#if defined(URDE_ALPHA_TEST) - if (colorOut.a < 0.25) - discard_fragment(); -#endif - return colorOut; -} diff --git a/Shaders/CModelShaders.vert.glsl b/Shaders/CModelShaders.vert.glsl deleted file mode 100644 index 83884b406..000000000 --- a/Shaders/CModelShaders.vert.glsl +++ /dev/null @@ -1,58 +0,0 @@ -UBINDING0 uniform URDEVertUniform { -#if URDE_SKIN_SLOTS - mat4 objs[URDE_SKIN_SLOTS]; - mat4 objsInv[URDE_SKIN_SLOTS]; -#endif - mat4 mv; - mat4 mvInv; - mat4 proj; -}; - -struct URDETCGMatrix { - mat4 mtx; - mat4 postMtx; -}; -UBINDING1 uniform URDETexMtxUniform { - URDETCGMatrix texMtxs[8]; -}; - -UBINDING3 uniform URDEReflectMtx { - mat4 indMtx; - mat4 reflectMtx; - float reflectAlpha; -}; - -URDE_VERT_DATA_DECL - -SBINDING(0) out VertToFrag vtf; -void main() { -#if URDE_SKIN_SLOTS - vec4 objPos = vec4(0.0); - vec4 objNorm = vec4(0.0); - for (int i = 0; i < URDE_SKIN_SLOTS; ++i) { - objPos += (objs[i] * vec4(posIn, 1.0)) * weightIn[i / 4][i % 4]; - objNorm += (objsInv[i] * vec4(normIn, 1.0)) * weightIn[i / 4][i % 4]; - } - objPos[3] = 1.0; - objNorm = vec4(normalize(objNorm.xyz), 0.0); - vtf.mvPos = mv * objPos; - vtf.mvNorm = vec4(normalize((mvInv * objNorm).xyz), 0.0); - gl_Position = proj * vtf.mvPos; -#else - vec4 objPos = vec4(posIn, 1.0); - vec4 objNorm = vec4(normIn, 0.0); - vtf.mvPos = mv * objPos; - vtf.mvNorm = mvInv * objNorm; - gl_Position = proj * vtf.mvPos; -#endif - - vec4 tmpProj; - vtf.lightmapUv = vec2(0.0); - vtf.diffuseUv = vec2(0.0); - vtf.emissiveUv = vec2(0.0); - vtf.specularUv = vec2(0.0); - vtf.extendedSpecularUv = vec2(0.0); - vtf.reflectionUv = vec2(0.0); - vtf.alphaUv = vec2(0.0); - URDE_TCG_EXPR -} diff --git a/Shaders/CModelShaders.vert.hlsl b/Shaders/CModelShaders.vert.hlsl deleted file mode 100644 index d37a27818..000000000 --- a/Shaders/CModelShaders.vert.hlsl +++ /dev/null @@ -1,72 +0,0 @@ -cbuffer URDEVertUniform : register(b0) { -#if URDE_SKIN_SLOTS - float4x4 objs[URDE_SKIN_SLOTS]; - float4x4 objsInv[URDE_SKIN_SLOTS]; -#endif - float4x4 mv; - float4x4 mvInv; - float4x4 proj; -}; - -struct URDETCGMatrix { - float4x4 mtx; - float4x4 postMtx; -}; -cbuffer URDETexMtxUniform : register(b1) { - URDETCGMatrix texMtxs[8]; -}; - -cbuffer URDEReflectMtx : register(b3) { - float4x4 indMtx; - float4x4 reflectMtx; - float reflectAlpha; -}; - -struct VertData { - float3 posIn : POSITION; - float3 normIn : NORMAL; -#if URDE_COL_SLOTS - float4 colIn[URDE_COL_SLOTS] : COLOR; -#endif -#if URDE_UV_SLOTS - float2 uvIn[URDE_UV_SLOTS] : UV; -#endif -#if URDE_WEIGHT_SLOTS - float4 weightIn[URDE_WEIGHT_SLOTS] : WEIGHT; -#endif -}; - -VertToFrag main(in VertData v) { - VertToFrag vtf; -#if URDE_SKIN_SLOTS - float4 objPos = float4(0.0, 0.0, 0.0, 0.0); - float4 objNorm = float4(0.0, 0.0, 0.0, 0.0); - for (int i = 0; i < URDE_SKIN_SLOTS; ++i) { - objPos += mul(objs[i], float4(v.posIn, 1.0)) * v.weightIn[i / 4][i % 4]; - objNorm += mul(objsInv[i], float4(v.normIn, 1.0)) * v.weightIn[i / 4][i % 4]; - } - objPos[3] = 1.0; - objNorm = float4(normalize(objNorm.xyz), 0.0); - vtf.mvPos = mul(mv, objPos); - vtf.mvNorm = float4(normalize(mul(mvInv, objNorm).xyz), 0.0); - vtf.mvpPos = mul(proj, vtf.mvPos); -#else - float4 objPos = float4(v.posIn, 1.0); - float4 objNorm = float4(v.normIn, 0.0); - vtf.mvPos = mul(mv, objPos); - vtf.mvNorm = mul(mvInv, objNorm); - vtf.mvpPos = mul(proj, vtf.mvPos); -#endif - - vtf.lightmapUv = float2(0.0, 0.0); - vtf.diffuseUv = float2(0.0, 0.0); - vtf.emissiveUv = float2(0.0, 0.0); - vtf.specularUv = float2(0.0, 0.0); - vtf.extendedSpecularUv = float2(0.0, 0.0); - vtf.reflectionUv = float2(0.0, 0.0); - vtf.alphaUv = float2(0.0, 0.0); - float4 tmpProj; - URDE_TCG_EXPR - - return vtf; -} diff --git a/Shaders/CModelShaders.vert.metal b/Shaders/CModelShaders.vert.metal deleted file mode 100644 index d97837edb..000000000 --- a/Shaders/CModelShaders.vert.metal +++ /dev/null @@ -1,60 +0,0 @@ -struct URDEVertUniform { -#if URDE_SKIN_SLOTS - float4x4 objs[URDE_SKIN_SLOTS]; - float4x4 objsInv[URDE_SKIN_SLOTS]; -#endif - float4x4 mv; - float4x4 mvInv; - float4x4 proj; -}; - -struct URDETCGMatrix { - float4x4 mtx; - float4x4 postMtx; -}; -struct URDETexMtxUniform { - URDETCGMatrix texMtxs[8]; -}; - -struct URDEReflectMtx { - float4x4 indMtx; - float4x4 reflectMtx; - float reflectAlpha; -}; - -URDE_VERT_DATA_DECL - -vertex VertToFrag vmain(VertData v [[ stage_in ]], - constant URDEVertUniform& vu [[ buffer(2) ]], - constant URDETexMtxUniform& tu [[ buffer(3) ]], - constant URDEReflectMtx& ru [[ buffer(5) ]]) { - VertToFrag vtf; -#if URDE_SKIN_SLOTS - float4 objPos = float4(0.0, 0.0, 0.0, 0.0); - float4 objNorm = float4(0.0, 0.0, 0.0, 0.0); -URDE_WEIGHTING_EXPR - objPos[3] = 1.0; - objNorm = float4(normalize(objNorm.xyz), 0.0); - vtf.mvPos = vu.mv * objPos; - vtf.mvNorm = float4(normalize((vu.mvInv * objNorm).xyz), 0.0); - vtf.mvpPos = vu.proj * vtf.mvPos; -#else - float4 objPos = float4(v.posIn, 1.0); - float4 objNorm = float4(v.normIn, 0.0); - vtf.mvPos = vu.mv * objPos; - vtf.mvNorm = vu.mvInv * objNorm; - vtf.mvpPos = vu.proj * vtf.mvPos; -#endif - - vtf.lightmapUv = float2(0.0, 0.0); - vtf.diffuseUv = float2(0.0, 0.0); - vtf.emissiveUv = float2(0.0, 0.0); - vtf.specularUv = float2(0.0, 0.0); - vtf.extendedSpecularUv = float2(0.0, 0.0); - vtf.reflectionUv = float2(0.0, 0.0); - vtf.alphaUv = float2(0.0, 0.0); - float4 tmpProj; - URDE_TCG_EXPR - - return vtf; -} diff --git a/Shaders/CMoviePlayerShader.shader b/Shaders/CMoviePlayerShader.shader deleted file mode 100644 index 288bec710..000000000 --- a/Shaders/CMoviePlayerShader.shader +++ /dev/null @@ -1,155 +0,0 @@ -#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); -} - -#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 deleted file mode 100644 index 51cdff59b..000000000 --- a/Shaders/CNESShader.shader +++ /dev/null @@ -1,137 +0,0 @@ -#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); -} - -#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 deleted file mode 100644 index 31b8fd613..000000000 --- a/Shaders/CParticleSwooshShaders.shader +++ /dev/null @@ -1,245 +0,0 @@ -#shader CParticleSwooshShaderTexZWrite -#attribute position4 -#attribute uv4 -#attribute color -#srcfac srcalpha -#dstfac invsrcalpha -#primitive tristrips -#depthtest lequal -#depthwrite true -#alphawrite false -#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 CParticleSwooshShaderTexZWriteAWrite : CParticleSwooshShaderTexZWrite -#alphawrite true - -#shader CParticleSwooshShaderTexNoZWrite : CParticleSwooshShaderTexZWrite -#srcfac srcalpha -#dstfac invsrcalpha -#depthwrite false -#alphawrite false - -#shader CParticleSwooshShaderTexNoZWriteAWrite : CParticleSwooshShaderTexNoZWrite -#alphawrite true - -#shader CParticleSwooshShaderTexAdditiveZWrite : CParticleSwooshShaderTexZWrite -#srcfac srcalpha -#dstfac one -#depthwrite true -#alphawrite false - -#shader CParticleSwooshShaderTexAdditiveZWriteAWrite : CParticleSwooshShaderTexAdditiveZWrite -#alphawrite true - -#shader CParticleSwooshShaderTexAdditiveNoZWrite : CParticleSwooshShaderTexZWrite -#srcfac srcalpha -#dstfac one -#depthwrite false -#alphawrite false - -#shader CParticleSwooshShaderTexAdditiveNoZWriteAWrite : CParticleSwooshShaderTexAdditiveNoZWrite -#alphawrite true - -#shader CParticleSwooshShaderNoTexZWrite : CParticleSwooshShaderTexZWrite -#srcfac srcalpha -#dstfac invsrcalpha -#depthtest lequal -#depthwrite true -#alphawrite false - -#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 CParticleSwooshShaderNoTexZWriteAWrite : CParticleSwooshShaderNoTexZWrite -#alphawrite true - -#shader CParticleSwooshShaderNoTexNoZWrite : CParticleSwooshShaderNoTexZWrite -#srcfac srcalpha -#dstfac invsrcalpha -#depthwrite false -#alphawrite false - -#shader CParticleSwooshShaderNoTexNoZWriteAWrite : CParticleSwooshShaderNoTexNoZWrite -#alphawrite true - -#shader CParticleSwooshShaderNoTexAdditiveZWrite : CParticleSwooshShaderNoTexZWrite -#srcfac srcalpha -#dstfac one -#depthwrite true -#alphawrite false - -#shader CParticleSwooshShaderNoTexAdditiveZWriteAWrite : CParticleSwooshShaderNoTexAdditiveZWrite -#alphawrite true - -#shader CParticleSwooshShaderNoTexAdditiveNoZWrite : CParticleSwooshShaderNoTexZWrite -#srcfac srcalpha -#dstfac one -#depthwrite false -#alphawrite false - -#shader CParticleSwooshShaderNoTexAdditiveNoZWriteAWrite : CParticleSwooshShaderNoTexAdditiveNoZWrite -#alphawrite true diff --git a/Shaders/CPhazonSuitFilter.shader b/Shaders/CPhazonSuitFilter.shader deleted file mode 100644 index f18de24fa..000000000 --- a/Shaders/CPhazonSuitFilter.shader +++ /dev/null @@ -1,485 +0,0 @@ -#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).ab - 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).ab - 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).ab - 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 -#colorwrite false -#alphawrite true -#depthwrite false -#culling none -#depthtest none -#primitive tristrips -#overwritealpha true - -#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 deleted file mode 100644 index 615269341..000000000 --- a/Shaders/CRadarPaintShader.shader +++ /dev/null @@ -1,148 +0,0 @@ -#shader CRadarPaintShader -#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 -#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 deleted file mode 100644 index 3c23b212e..000000000 --- a/Shaders/CRandomStaticFilter.shader +++ /dev/null @@ -1,301 +0,0 @@ -#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) -{ - int bx = int(uv.x) >> 3; - int rx = int(uv.x) & 0x7; - int by = int(uv.y) >> 2; - int ry = int(uv.y) & 0x3; - int bidx = by * 128 + bx; - int addr = bidx * 32 + ry * 8 + rx + int(randOff); - return ivec2(addr & 0x3ff, addr >> 10); -} - -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) -{ - int bx = int(uv.x) >> 3; - int rx = int(uv.x) & 0x7; - int by = int(uv.y) >> 2; - int ry = int(uv.y) & 0x3; - int bidx = by * 128 + bx; - int addr = bidx * 32 + ry * 8 + rx + int(randOff); - return int3(addr & 0x3ff, addr >> 10, 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) -{ - int bx = int(uv.x) >> 3; - int rx = int(uv.x) & 0x7; - int by = int(uv.y) >> 2; - int ry = int(uv.y) & 0x3; - int bidx = by * 128 + bx; - int addr = bidx * 32 + ry * 8 + rx + int(randOff); - return uint2(addr & 0x3ff, addr >> 10); -} - -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 zero -#dstfac srccolor -#overwritealpha true - -#shader CRandomStaticFilterCookieCutter : CRandomStaticFilterAlpha -#srcfac zero -#dstfac srccolor -#overwritealpha true -#depthwrite true -#colorwrite false -#depthtest lequal - -#fragment glsl -struct VertToFrag -{ - vec4 color; - vec2 uv; - float randOff; - float discardThres; -}; - -ivec2 Lookup8BPP(in vec2 uv, in float randOff) -{ - int bx = int(uv.x) >> 3; - int rx = int(uv.x) & 0x7; - int by = int(uv.y) >> 2; - int ry = int(uv.y) & 0x3; - int bidx = by * 128 + bx; - int addr = bidx * 32 + ry * 8 + rx + int(randOff); - return ivec2(addr & 0x3ff, addr >> 10); -} - -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) -{ - int bx = int(uv.x) >> 3; - int rx = int(uv.x) & 0x7; - int by = int(uv.y) >> 2; - int ry = int(uv.y) & 0x3; - int bidx = by * 128 + bx; - int addr = bidx * 32 + ry * 8 + rx + int(randOff); - return int3(addr & 0x3ff, addr >> 10, 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) -{ - int bx = int(uv.x) >> 3; - int rx = int(uv.x) & 0x7; - int by = int(uv.y) >> 2; - int ry = int(uv.y) & 0x3; - int bidx = by * 128 + bx; - int addr = bidx * 32 + ry * 8 + rx + int(randOff); - return uint2(addr & 0x3ff, addr >> 10); -} - -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 deleted file mode 100644 index b7b2c040b..000000000 --- a/Shaders/CScanLinesFilter.shader +++ /dev/null @@ -1,124 +0,0 @@ -#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 -#overwritealpha true diff --git a/Shaders/CSpaceWarpFilter.shader b/Shaders/CSpaceWarpFilter.shader deleted file mode 100644 index f57322288..000000000 --- a/Shaders/CSpaceWarpFilter.shader +++ /dev/null @@ -1,156 +0,0 @@ -#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).ab * 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).ab * 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).ab * 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 deleted file mode 100644 index b96a52fde..000000000 --- a/Shaders/CTextSupportShader.shader +++ /dev/null @@ -1,351 +0,0 @@ -#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 deleted file mode 100644 index 504700f9f..000000000 --- a/Shaders/CTexturedQuadFilter.shader +++ /dev/null @@ -1,292 +0,0 @@ -#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); -} - -#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 -#overwritealpha true - -#shader CTexturedQuadFilterMultGEqual : CTexturedQuadFilterMult -#depthtest gequal - -#shader CTexturedQuadFilterMultLEqual : CTexturedQuadFilterMult -#depthtest lequal - -#shader CTexturedQuadFilterInvDstMult : CTexturedQuadFilterAlpha -#srcfac zero -#dstfac invsrccolor -#depthtest none -#overwritealpha true - -#shader CTexturedQuadFilterInvDstMultGEqual : CTexturedQuadFilterInvDstMult -#depthtest gequal - -#shader CTexturedQuadFilterInvDstMultLEqual : CTexturedQuadFilterInvDstMult -#depthtest lequal - -#shader CTexturedQuadFilterAlphaTexAlpha : CTexturedQuadFilterAlpha -#attribute position4 -#attribute uv4 -#srcfac srcalpha -#dstfac invsrcalpha -#depthtest none -#overwritealpha false - -#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 -#overwritealpha true - -#shader CTexturedQuadFilterAlphaTexInvDstMult : CTexturedQuadFilterAlphaTexAlpha -#srcfac zero -#dstfac invsrccolor -#overwritealpha true - -#shader CTexturedQuadFilterAlphaGEqualZWrite : CTexturedQuadFilterAlpha -#depthtest gequal -#depthwrite true - -#shader CTexturedQuadFilterAddGEqualZWrite : CTexturedQuadFilterAdd -#depthtest gequal -#depthwrite true - -#shader CTexturedQuadFilterSubtractGEqualZWrite : CTexturedQuadFilterSubtract -#depthtest gequal -#depthwrite true - -#shader CTexturedQuadFilterMultGEqualZWrite : CTexturedQuadFilterMult -#depthtest gequal -#depthwrite true diff --git a/Shaders/CThermalColdFilter.shader b/Shaders/CThermalColdFilter.shader deleted file mode 100644 index 9bf590ca3..000000000 --- a/Shaders/CThermalColdFilter.shader +++ /dev/null @@ -1,257 +0,0 @@ -#shader CThermalColdFilter -#attribute position4 -#attribute uv4 0 -#attribute uv4 1 -#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; -layout(location=2) in vec4 uvNoiseIn; - -UBINDING0 uniform ThermalColdUniform -{ - mat4 indMtx; - vec4 colorReg0; - vec4 colorReg1; - vec4 colorReg2; - float randOff; -}; - -struct VertToFrag -{ - mat3 indMtx; - vec4 colorReg0; - vec4 colorReg1; - vec4 colorReg2; - vec2 sceneUv; - vec2 noiseUv; - float randOff; -}; - -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.noiseUv = uvNoiseIn.xy; - vtf.randOff = randOff; - gl_Position = vec4(posIn.xyz, 1.0); -} - -#fragment glsl -struct VertToFrag -{ - mat3 indMtx; - vec4 colorReg0; - vec4 colorReg1; - vec4 colorReg2; - vec2 sceneUv; - vec2 noiseUv; - float randOff; -}; - -ivec2 Lookup8BPP(in vec2 uv, in float randOff) -{ - int bx = int(uv.x) >> 3; - int rx = int(uv.x) & 0x7; - int by = int(uv.y) >> 2; - int ry = int(uv.y) & 0x3; - int bidx = by * 128 + bx; - int addr = bidx * 32 + ry * 8 + rx + int(randOff); - return ivec2(addr & 0x3ff, addr >> 10); -} - -SBINDING(0) in VertToFrag vtf; -layout(location=0) out vec4 colorOut; -TBINDING0 uniform sampler2D sceneTex; -TBINDING1 uniform sampler2D noiseTex; -const vec4 kRGBToYPrime = vec4(0.257, 0.504, 0.098, 0.0); -void main() -{ - vec4 noiseTexel = texelFetch(noiseTex, Lookup8BPP(vtf.noiseUv, vtf.randOff), 0); - vec2 indCoord = (vtf.indMtx * vec3(noiseTexel.r - 0.5, noiseTexel.a - 0.5, 1.0)).xy; - float indScene = dot(texture(sceneTex, vtf.sceneUv + indCoord), kRGBToYPrime) + 16.0 / 255.0; - colorOut = vtf.colorReg0 * indScene + vtf.colorReg2 - vtf.colorReg1 * noiseTexel.r; - colorOut.a = vtf.colorReg1.a + vtf.colorReg1.a * noiseTexel.r + vtf.colorReg2.a; -} - -#vertex hlsl -struct VertData -{ - float4 posIn : POSITION; - float4 uvIn : UV0; - float4 uvNoiseIn : UV1; -}; - -cbuffer ThermalColdUniform : register(b0) -{ - float4x4 indMtx; - float4 colorReg0; - float4 colorReg1; - float4 colorReg2; - float randOff; -}; - -struct VertToFrag -{ - float4 position : SV_Position; - float3x3 indMtx : INDMTX; - float4 colorReg0 : COLORREG0; - float4 colorReg1 : COLORREG1; - float4 colorReg2 : COLORREG2; - float2 sceneUv : SCENEUV; - float2 noiseUv : NOISEUV; - float randOff : RANDOFF; -}; - -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.noiseUv = v.uvNoiseIn.xy; - vtf.randOff = randOff; - vtf.position = float4(v.posIn.xyz, 1.0); - return vtf; -} - -#fragment hlsl -Texture2D sceneTex : register(t0); -Texture2D noiseTex : 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 noiseUv : NOISEUV; - float randOff : RANDOFF; -}; - -static int3 Lookup8BPP(float2 uv, float randOff) -{ - int bx = int(uv.x) >> 3; - int rx = int(uv.x) & 0x7; - int by = int(uv.y) >> 2; - int ry = int(uv.y) & 0x3; - int bidx = by * 128 + bx; - int addr = bidx * 32 + ry * 8 + rx + int(randOff); - return int3(addr & 0x3ff, addr >> 10, 0); -} - -static const float4 kRGBToYPrime = {0.257, 0.504, 0.098, 0.0}; -float4 main(in VertToFrag vtf) : SV_Target0 -{ - float4 noiseTexel = noiseTex.Load(Lookup8BPP(vtf.noiseUv, vtf.randOff)); - float2 indCoord = mul(vtf.indMtx, float3(noiseTexel.r - 0.5, noiseTexel.a - 0.5, 1.0)).xy; - float2 sceneUv = vtf.sceneUv + indCoord; - sceneUv.y = 1.0 - sceneUv.y; - float indScene = dot(sceneTex.Sample(samp, sceneUv), kRGBToYPrime) + 16.0 / 255.0; - float4 colorOut = vtf.colorReg0 * indScene + vtf.colorReg2 - vtf.colorReg1 * noiseTexel.r; - colorOut.a = vtf.colorReg1.a + vtf.colorReg1.a * noiseTexel.r + vtf.colorReg2.a; - return colorOut; -} - -#vertex metal -struct VertData -{ - float4 posIn [[ attribute(0) ]]; - float4 uvIn [[ attribute(1) ]]; - float4 uvNoiseIn [[ attribute(2) ]]; -}; - -struct ThermalColdUniform -{ - float4x4 indMtx; - float4 colorReg0; - float4 colorReg1; - float4 colorReg2; - float randOff; -}; - -struct VertToFrag -{ - float4 position [[ position ]]; - float3 indMtx0; - float3 indMtx1; - float3 indMtx2; - float4 colorReg0; - float4 colorReg1; - float4 colorReg2; - float2 sceneUv; - float2 noiseUv; - float randOff; -}; - -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.noiseUv = v.uvNoiseIn.xy; - vtf.randOff = tcu.randOff; - 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 noiseUv; - float randOff; -}; - -static uint2 Lookup8BPP(float2 uv, float randOff) -{ - int bx = int(uv.x) >> 3; - int rx = int(uv.x) & 0x7; - int by = int(uv.y) >> 2; - int ry = int(uv.y) & 0x3; - int bidx = by * 128 + bx; - int addr = bidx * 32 + ry * 8 + rx + int(randOff); - return uint2(addr & 0x3ff, addr >> 10); -} - -constant float4 kRGBToYPrime = {0.257, 0.504, 0.098, 0.0}; -fragment float4 fmain(VertToFrag vtf [[ stage_in ]], - sampler samp [[ sampler(3) ]], - texture2d sceneTex [[ texture(0) ]], - texture2d noiseTex [[ texture(1) ]]) -{ - float4 noiseTexel = noiseTex.read(Lookup8BPP(vtf.noiseUv, vtf.randOff)); - float2 indCoord = (float3x3(vtf.indMtx0, vtf.indMtx1, vtf.indMtx2) * float3(noiseTexel.r - 0.5, noiseTexel.a - 0.5, 1.0)).xy; - float2 sceneUv = vtf.sceneUv + indCoord; - sceneUv.y = 1.0 - sceneUv.y; - float indScene = dot(sceneTex.sample(samp, sceneUv), kRGBToYPrime) + 16.0 / 255.0; - float4 colorOut = vtf.colorReg0 * indScene + vtf.colorReg2 - vtf.colorReg1 * noiseTexel.r; - colorOut.a = vtf.colorReg1.a + vtf.colorReg1.a * noiseTexel.r + vtf.colorReg2.a; - return colorOut; -} diff --git a/Shaders/CThermalHotFilter.shader b/Shaders/CThermalHotFilter.shader deleted file mode 100644 index a71038fe0..000000000 --- a/Shaders/CThermalHotFilter.shader +++ /dev/null @@ -1,144 +0,0 @@ -#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.257, 0.504, 0.098, 0.0); -void main() -{ - float sceneSample = dot(texture(sceneTex, vtf.sceneUv), kRGBToYPrime) + 16.0 / 255.0; - vec4 colorSample = texture(paletteTex, vec2(sceneSample / 16.0, 0.5)); - colorOut = vec4(colorSample.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.257, 0.504, 0.098, 0.0); -float4 main(in VertToFrag vtf) : SV_Target0 -{ - float sceneSample = dot(sceneTex.Sample(samp, vtf.sceneUv), kRGBToYPrime) + 16.0 / 255.0; - float4 colorSample = paletteTex.Sample(samp, float2(sceneSample / 16.0, 0.5)); - return float4(colorSample.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.257, 0.504, 0.098, 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) + 16.0 / 255.0; - float4 colorSample = paletteTex.sample(samp, float2(sceneSample / 16.0, 0.5)); - return float4(colorSample.rgb, 0.0); -} diff --git a/Shaders/CWorldShadowShader.shader b/Shaders/CWorldShadowShader.shader deleted file mode 100644 index 6ac76c129..000000000 --- a/Shaders/CWorldShadowShader.shader +++ /dev/null @@ -1,122 +0,0 @@ -#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 deleted file mode 100644 index 01e067eae..000000000 --- a/Shaders/CXRayBlurFilter.shader +++ /dev/null @@ -1,254 +0,0 @@ -#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 deleted file mode 100644 index 1d51a066b..000000000 --- a/Shaders/shader_CFluidPlaneShader.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#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 deleted file mode 100644 index 6424008d1..000000000 --- a/Shaders/shader_CFluidPlaneShader.hpp +++ /dev/null @@ -1,112 +0,0 @@ -#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 ? boo::VertexFormatInfo(TessVtxFmtElems) : boo::VertexFormatInfo(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 ? 1u : 0u}) -// , HasTessellation(tessellation) {} -// -// const boo::VertexFormatInfo VtxFmt; -// const boo::AdditionalPipelineInfo PipelineInfo; -// bool HasTessellation; -// static constexpr bool HasHash = false; -// static constexpr bool HasStageHash = false; -// 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(boo::VertexFormatInfo(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 bool HasStageHash = false; -// 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 STAGES_shader_CFluidPlaneShader(P, S) -// ::StageObject_CFluidPlaneShader, ::StageObject_CFluidPlaneDoorShader, diff --git a/Shaders/shader_CFluidPlaneShaderGLSL.cpp b/Shaders/shader_CFluidPlaneShaderGLSL.cpp deleted file mode 100644 index 12011089d..000000000 --- a/Shaders/shader_CFluidPlaneShaderGLSL.cpp +++ /dev/null @@ -1,785 +0,0 @@ -#include "shader_CFluidPlaneShader.hpp" -#include -#include - -#define FOG_STRUCT_GLSL \ - "struct Fog\n" \ - "{\n" \ - " vec4 color;\n" \ - " float A;\n" \ - " float B;\n" \ - " float C;\n" \ - " int mode;\n" \ - " float indScale;\n" \ -"};\n" - -#define FOG_ALGORITHM_GLSL \ - "vec4 MainPostFunc(vec4 colorIn)\n" \ - "{\n" \ - " float fogZ;\n" \ - " float fogF = clamp((fog.A / (fog.B - gl_FragCoord.z)) - fog.C, 0.0, 1.0);\n" \ - " switch (fog.mode)\n" \ - " {\n" \ - " case 2:\n" \ - " fogZ = fogF;\n" \ - " break;\n" \ - " case 4:\n" \ - " fogZ = 1.0 - exp2(-8.0 * fogF);\n" \ - " break;\n" \ - " case 5:\n" \ - " fogZ = 1.0 - exp2(-8.0 * fogF * fogF);\n" \ - " break;\n" \ - " case 6:\n" \ - " fogZ = exp2(-8.0 * (1.0 - fogF));\n" \ - " break;\n" \ - " case 7:\n" \ - " fogF = 1.0 - fogF;\n" \ - " fogZ = exp2(-8.0 * fogF * fogF);\n" \ - " break;\n" \ - " default:\n" \ - " fogZ = 0.0;\n" \ - " break;\n" \ - " }\n" \ - "#if IS_ADDITIVE\n" \ - " return vec4(mix(colorIn, vec4(0.0), clamp(fogZ, 0.0, 1.0)).rgb, colorIn.a);\n" \ - "#else\n" \ - " return vec4(mix(colorIn, fog.color, clamp(fogZ, 0.0, 1.0)).rgb, colorIn.a);\n" \ - "#endif\n" \ - "}\n" - -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" - " ADDITIONAL_TCGS\n" // 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" - "RIPPLE_TEXTURE_BINDING 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" - " ADDITIONAL_TCGS\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" -FOG_STRUCT_GLSL -"\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" -" vec4 addColor;\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" -" vec3 deltaNorm = delta / dist;\n" -" float angDot = max(dot(deltaNorm, lights[i].dir.xyz), 0.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 * angAtt * att * max(dot(-deltaNorm, mvNormIn), 0.0);\n" -" }\n" -" \n" -" return clamp(ret, 0.0, 1.0);\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" -FOG_ALGORITHM_GLSL -"\n" -"layout(location=0) out vec4 colorOut;\n" -"TEXTURE_DECLS\n" // Textures here -"void main()\n" -"{\n" -" vec4 lighting = LightingFunc(vtf.mvPos.xyz, normalize(vtf.mvNorm.xyz));\n" -" COMBINER_EXPRS\n" // Combiner expression here -" colorOut = MainPostFunc(colorOut);\n" -"}\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" -FOG_STRUCT_GLSL -"\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" -" vec4 addColor;\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" -FOG_ALGORITHM_GLSL -"\n" -"SBINDING(0) in VertToFrag vtf;\n" -"layout(location=0) out vec4 colorOut;\n" -"TEXTURE_DECLS\n" // Textures here -"void main()\n" -"{\n" -" COMBINER_EXPRS\n" // Combiner expression here -" colorOut = MainPostFunc(colorOut);\n" -"}\n"; - -static std::string _BuildFS(const SFluidPlaneShaderInfo& info) { - std::stringstream out; - int nextTex = 0; - int nextTCG = 3; - int bumpMapUv = -1; - int envBumpMapUv = -1; - int envMapUv = -1; - int lightmapUv = -1; - - out << "#define TEXTURE_DECLS "; - if (info.m_hasPatternTex1) - fmt::print(out, FMT_STRING("TBINDING{} uniform sampler2D patternTex1;"), nextTex++); - if (info.m_hasPatternTex2) - fmt::print(out, FMT_STRING("TBINDING{} uniform sampler2D patternTex2;"), nextTex++); - if (info.m_hasColorTex) - fmt::print(out, FMT_STRING("TBINDING{} uniform sampler2D colorTex;"), nextTex++); - if (info.m_hasBumpMap) - fmt::print(out, FMT_STRING("TBINDING{} uniform sampler2D bumpMap;"), nextTex++); - if (info.m_hasEnvMap) - fmt::print(out, FMT_STRING("TBINDING{} uniform sampler2D envMap;"), nextTex++); - if (info.m_hasEnvBumpMap) - fmt::print(out, FMT_STRING("TBINDING{} uniform sampler2D envBumpMap;"), nextTex++); - if (info.m_hasLightmap) - fmt::print(out, FMT_STRING("TBINDING{} uniform sampler2D lightMap;"), nextTex++); - out << '\n'; - - if (info.m_hasBumpMap) - bumpMapUv = nextTCG++; - if (info.m_hasEnvBumpMap) - envBumpMapUv = nextTCG++; - if (info.m_hasEnvMap) - envMapUv = nextTCG++; - if (info.m_hasLightmap) - lightmapUv = nextTCG; - - out << "#define COMBINER_EXPRS "; - switch (info.m_type) { - case EFluidType::NormalWater: - case EFluidType::PhazonFluid: - case EFluidType::Four: - if (info.m_hasLightmap) { - fmt::print(out, FMT_STRING("vec4 lightMapTexel = texture(lightMap, vtf.uvs[{}]);"), 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 - out << "lighting += mix(lightMapTexel * kColor2, lightMapTexel, kColor3);"; - } else { - // mix(Tex * K2, Tex, K3) + Lighting - out << "lighting += lightMapTexel * kColor2;"; - } - } - - // 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) - out << - "colorOut = (texture(patternTex1, vtf.uvs[0]) * kColor0 + lighting) * " - "texture(patternTex2, vtf.uvs[1]) + vtf.color;"; - else - out << "colorOut = lighting * texture(patternTex2, vtf.uvs[1]) + vtf.color;"; - } else { - out << "colorOut = vtf.color;"; - } - - if (info.m_hasColorTex && !info.m_hasEnvMap && info.m_hasEnvBumpMap) { - // Make previous stage indirect, mtx0 - fmt::print(out, FMT_STRING( - "vec2 indUvs = (texture(envBumpMap, vtf.uvs[{}]).ra - vec2(0.5, 0.5)) * " - "vec2(fog.indScale, -fog.indScale);"), - envBumpMapUv); - out << "colorOut += texture(colorTex, indUvs + vtf.uvs[2]) * lighting;"; - } 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) - out << "colorOut += texture(colorTex, vtf.uvs[2]) * lighting;"; - fmt::print(out, FMT_STRING( - "vec2 indUvs = (texture(envBumpMap, vtf.uvs[{}]).ra - vec2(0.5, 0.5)) * " - "vec2(fog.indScale, -fog.indScale);"), - envBumpMapUv); - fmt::print(out, FMT_STRING("colorOut = mix(colorOut, texture(envMap, indUvs + vtf.uvs[{}]), kColor1);"), envMapUv); - } else if (info.m_hasColorTex) { - out << "colorOut += texture(colorTex, vtf.uvs[2]) * lighting;"; - } - - break; - - case EFluidType::PoisonWater: - if (info.m_hasLightmap) { - fmt::print(out, FMT_STRING("vec4 lightMapTexel = texture(lightMap, vtf.uvs[{}]);"), 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 - out << "lighting += mix(lightMapTexel * kColor2, lightMapTexel, kColor3);"; - } else { - // mix(Tex * K2, Tex, K3) + Lighting - out << "lighting += lightMapTexel * kColor2;"; - } - } - - // 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) - out << - "colorOut = (texture(patternTex1, vtf.uvs[0]) * kColor0 + lighting) * " - "texture(patternTex2, vtf.uvs[1]) + vtf.color;"; - else - out << "colorOut = lighting * texture(patternTex2, vtf.uvs[1]) + vtf.color;"; - } else { - out << "colorOut = vtf.color;"; - } - - if (info.m_hasColorTex) { - if (info.m_hasEnvBumpMap) { - // Make previous stage indirect, mtx0 - fmt::print(out, FMT_STRING( - "vec2 indUvs = (texture(envBumpMap, vtf.uvs[{}]).ra - vec2(0.5, 0.5)) * " - "vec2(fog.indScale, -fog.indScale);"), - envBumpMapUv); - out << "colorOut += texture(colorTex, indUvs + vtf.uvs[2]) * lighting;"; - } else { - out << "colorOut += texture(colorTex, vtf.uvs[2]) * lighting;"; - } - } - - 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) - out << - "colorOut = (texture(patternTex1, vtf.uvs[0]) * kColor0 + vtf.color) * " - "texture(patternTex2, vtf.uvs[1]) + vtf.color;"; - else - out << "colorOut = vtf.color * texture(patternTex2, vtf.uvs[1]) + vtf.color;"; - } else { - out << "colorOut = vtf.color;"; - } - - if (info.m_hasColorTex) - out << "colorOut += texture(colorTex, vtf.uvs[2]);"; - - 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 - - out << - "vec3 lightVec = lights[3].pos.xyz - vtf.mvPos.xyz;" - "float lx = dot(vtf.mvTangent.xyz, lightVec);" - "float ly = dot(vtf.mvBinorm.xyz, lightVec);"; - fmt::print(out, FMT_STRING( - "vec4 emboss1 = texture(bumpMap, vtf.uvs[{}]) + vec4(0.5);" - "vec4 emboss2 = texture(bumpMap, vtf.uvs[{}] + vec2(lx, ly));"), - 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 - out << "colorOut *= clamp((emboss1 + vec4(0.5) - emboss2) * vec4(2.0), vec4(0.0), vec4(1.0));"; - } - - 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) - out << - "colorOut = (texture(patternTex1, vtf.uvs[0]) * kColor0 + vtf.color) * " - "texture(patternTex2, vtf.uvs[1]) + vtf.color;"; - else - out << "colorOut = vtf.color * texture(patternTex2, vtf.uvs[1]) + vtf.color;"; - } else { - out << "colorOut = vtf.color;"; - } - - if (info.m_hasColorTex) - out << "colorOut += texture(colorTex, vtf.uvs[2]);"; - - if (info.m_hasBumpMap) { - // 3: bumpMapTCG, bumpMap, NULL - // ZERO, TEX, PREV, ZERO - // Output reg prev, scale 2 - fmt::print(out, FMT_STRING("vec4 emboss1 = texture(bumpMap, vtf.uvs[{}]) + vec4(0.5);"), bumpMapUv); - out << "colorOut *= emboss1 * vec4(2.0);"; - } - - break; - } - - out << "colorOut.a = kColor0.a;\n"; - - out << "#define IS_ADDITIVE " << int(info.m_additive) << '\n'; - out << FS; - return out.str(); -} - -static void _BuildAdditionalTCGs(std::stringstream& out, const SFluidPlaneShaderInfo& info) { - int nextTCG = 3; - int nextMtx = 4; - - out << "#define ADDITIONAL_TCGS "; - if (info.m_hasBumpMap) - fmt::print(out, FMT_STRING("vtf.uvs[{}] = (texMtxs[0] * pos).xy;"), nextTCG++); - if (info.m_hasEnvBumpMap) - fmt::print(out, FMT_STRING("vtf.uvs[{}] = (texMtxs[3] * vec4(normalIn.xyz, 1.0)).xy;"), nextTCG++); - if (info.m_hasEnvMap) - fmt::print(out, FMT_STRING("vtf.uvs[{}] = (texMtxs[{}] * pos).xy;"), nextTCG++, nextMtx++); - if (info.m_hasLightmap) - fmt::print(out, FMT_STRING("vtf.uvs[{}] = (texMtxs[{}] * pos).xy;"), nextTCG, nextMtx); - out << '\n'; -} - -static std::string _BuildVS(const SFluidPlaneShaderInfo& info, bool tessellation) { - if (tessellation) - return TessVS; - - std::stringstream out; - _BuildAdditionalTCGs(out, info); - out << VS; - return out.str(); -} -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::stringstream out; - _BuildAdditionalTCGs(out, info); - out << "#define RIPPLE_TEXTURE_BINDING TBINDING" << nextTex << '\n'; - out << TessES; - return out.str(); -} -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) { - std::stringstream out; - out << "#define ADDITIONAL_TCGS\n"; - out << VS; - return out.str(); -} - -static std::string _BuildFS(const SFluidPlaneDoorShaderInfo& info) { - int nextTex = 0; - std::stringstream out; - - out << "#define TEXTURE_DECLS "; - if (info.m_hasPatternTex1) - fmt::print(out, FMT_STRING("TBINDING{} uniform sampler2D patternTex1;"), nextTex++); - if (info.m_hasPatternTex2) - fmt::print(out, FMT_STRING("TBINDING{} uniform sampler2D patternTex2;"), nextTex++); - if (info.m_hasColorTex) - fmt::print(out, FMT_STRING("TBINDING{} uniform sampler2D colorTex;"), nextTex++); - out << '\n'; - - // Tex0 * kColor0 * Tex1 + Tex2 - out << "#define COMBINER_EXPRS "; - if (info.m_hasPatternTex1 && info.m_hasPatternTex2) { - out << - "colorOut = texture(patternTex1, vtf.uvs[0]) * kColor0 * " - "texture(patternTex2, vtf.uvs[1]);"; - } else { - out << "colorOut = vec4(0.0);"; - } - - if (info.m_hasColorTex) { - out << "colorOut += texture(colorTex, vtf.uvs[2]);"; - } - - out << "colorOut.a = kColor0.a;\n"; - - out << "#define IS_ADDITIVE 0\n"; - out << FSDoor; - return out.str(); -} - -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 deleted file mode 100644 index 824936bf9..000000000 --- a/Shaders/shader_CFluidPlaneShaderHLSL.cpp +++ /dev/null @@ -1,771 +0,0 @@ -#include "shader_CFluidPlaneShader.hpp" -#include -#include - -#define FOG_STRUCT_HLSL \ - "struct Fog\n" \ - "{\n" \ - " float4 color;\n" \ - " float A;\n" \ - " float B;\n" \ - " float C;\n" \ - " int mode;\n" \ - " float indScale;\n" \ -"};\n" - -#define FOG_ALGORITHM_HLSL \ - "static float4 MainPostFunc(in VertToFrag vtf, float4 colorIn)\n" \ - "{\n" \ - " float fogZ;\n" \ - " float fogF = saturate((fog.A / (fog.B - (1.0 - vtf.pos.z))) - fog.C);\n" \ - " switch (fog.mode)\n" \ - " {\n" \ - " case 2:\n" \ - " fogZ = fogF;\n" \ - " break;\n" \ - " case 4:\n" \ - " fogZ = 1.0 - exp2(-8.0 * fogF);\n" \ - " break;\n" \ - " case 5:\n" \ - " fogZ = 1.0 - exp2(-8.0 * fogF * fogF);\n" \ - " break;\n" \ - " case 6:\n" \ - " fogZ = exp2(-8.0 * (1.0 - fogF));\n" \ - " break;\n" \ - " case 7:\n" \ - " fogF = 1.0 - fogF;\n" \ - " fogZ = exp2(-8.0 * fogF * fogF);\n" \ - " break;\n" \ - " default:\n" \ - " fogZ = 0.0;\n" \ - " break;\n" \ - " }\n" \ - "#if IS_ADDITIVE\n" \ - " return float4(lerp(colorIn, float4(0.0,0.0,0.0,0.0), saturate(fogZ)).rgb, colorIn.a);\n" \ - "#else\n" \ - " return float4(lerp(colorIn, fog.color, saturate(fogZ)).rgb, colorIn.a);\n" \ - "#endif\n" \ - "}\n" - -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" - " ADDITIONAL_TCGS\n" // 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(RIPPLE_TEXTURE_REG);\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" - " ADDITIONAL_TCGS\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" -FOG_STRUCT_HLSL -"\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" -" float4 addColor;\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 * angAtt * att * saturate(dot(normalize(-delta), mvNormIn));\n" -" }\n" -" \n" -" return saturate(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" -FOG_ALGORITHM_HLSL -"\n" -"SamplerState samp : register(s0);\n" -"TEXTURE_DECLS\n" // 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" -" COMBINER_EXPRS\n" // Combiner expression here -" return MainPostFunc(vtf, 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" -FOG_STRUCT_HLSL -"\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" -" float4 addColor;\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" -FOG_ALGORITHM_HLSL -"\n" -"SamplerState samp : register(s0);\n" -"TEXTURE_DECLS\n" // Textures here -"float4 main(in VertToFrag vtf) : SV_Target0\n" -"{\n" -" float4 colorOut;\n" -" COMBINER_EXPRS\n" // Combiner expression here -" return MainPostFunc(vtf, colorOut);\n" -"}\n"; - -static std::string _BuildFS(const SFluidPlaneShaderInfo& info) { - std::stringstream out; - int nextTex = 0; - int nextTCG = 3; - int nextMtx = 4; - int bumpMapUv = -1; - int envBumpMapUv = -1; - int envMapUv = -1; - int lightmapUv = -1; - - out << "#define TEXTURE_DECLS "; - if (info.m_hasPatternTex1) - fmt::print(out, FMT_STRING("Texture2D patternTex1 : register(t{});"), nextTex++); - if (info.m_hasPatternTex2) - fmt::print(out, FMT_STRING("Texture2D patternTex2 : register(t{});"), nextTex++); - if (info.m_hasColorTex) - fmt::print(out, FMT_STRING("Texture2D colorTex : register(t{});"), nextTex++); - if (info.m_hasBumpMap) - fmt::print(out, FMT_STRING("Texture2D bumpMap : register(t{});"), nextTex++); - if (info.m_hasEnvMap) - fmt::print(out, FMT_STRING("Texture2D envMap : register(t{});"), nextTex++); - if (info.m_hasEnvBumpMap) - fmt::print(out, FMT_STRING("Texture2D envBumpMap : register(t{});"), nextTex++); - if (info.m_hasLightmap) - fmt::print(out, FMT_STRING("Texture2D lightMap : register(t{});"), nextTex++); - out << '\n'; - - out << "#define ADDITIONAL_TCGS "; - if (info.m_hasBumpMap) { - bumpMapUv = nextTCG; - fmt::print(out, FMT_STRING("vtf.uvs[{}] = mul(texMtxs[0], pos).xy;"), nextTCG++); - } - if (info.m_hasEnvBumpMap) { - envBumpMapUv = nextTCG; - fmt::print(out, FMT_STRING("vtf.uvs[{}] = mul(texMtxs[3], float4(normalIn.xyz, 1.0)).xy;"), nextTCG++); - } - if (info.m_hasEnvMap) { - envMapUv = nextTCG; - fmt::print(out, FMT_STRING("vtf.uvs[{}] = mul(texMtxs[{}], pos).xy;"), nextTCG++, nextMtx++); - } - if (info.m_hasLightmap) { - lightmapUv = nextTCG; - fmt::print(out, FMT_STRING("vtf.uvs[{}] = mul(texMtxs[{}], pos).xy;"), nextTCG++, nextMtx++); - } - out << '\n'; - - out << "#define COMBINER_EXPRS "; - switch (info.m_type) { - case EFluidType::NormalWater: - case EFluidType::PhazonFluid: - case EFluidType::Four: - if (info.m_hasLightmap) { - fmt::print(out, FMT_STRING("float4 lightMapTexel = lightMap.Sample(samp, vtf.uvs[{}]);"), 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 - out << "lighting += lerp(lightMapTexel * kColor2, lightMapTexel, kColor3);"; - } else { - // mix(Tex * K2, Tex, K3) + Lighting - out << "lighting += lightMapTexel * kColor2;"; - } - } - - // 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) - out << - "colorOut = (patternTex1.Sample(samp, vtf.uvs[0]) * kColor0 + lighting) * " - "patternTex2.Sample(samp, vtf.uvs[1]) + vtf.color;"; - else - out << "colorOut = lighting * patternTex2.Sample(samp, vtf.uvs[1]) + vtf.color;"; - } else { - out << "colorOut = vtf.color;"; - } - - if (info.m_hasColorTex && !info.m_hasEnvMap && info.m_hasEnvBumpMap) { - // Make previous stage indirect, mtx0 - fmt::print(out, FMT_STRING( - "float2 indUvs = (envBumpMap.Sample(samp, vtf.uvs[{}]).ra - float2(0.5, 0.5)) * " - "float2(fog.indScale, -fog.indScale);"), - envBumpMapUv); - out << "colorOut += colorTex.Sample(samp, indUvs + vtf.uvs[2]) * lighting;"; - } 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) - out << "colorOut += colorTex.Sample(samp, vtf.uvs[2]) * lighting;"; - fmt::print(out, FMT_STRING( - "float2 indUvs = (envBumpMap.Sample(samp, vtf.uvs[{}]).ra - float2(0.5, 0.5)) * " - "float2(fog.indScale, -fog.indScale);"), - envBumpMapUv); - fmt::print(out, FMT_STRING("colorOut = lerp(colorOut, envMap.Sample(samp, indUvs + vtf.uvs[{}]), kColor1);"), envMapUv); - } else if (info.m_hasColorTex) { - out << "colorOut += colorTex.Sample(samp, vtf.uvs[2]) * lighting;"; - } - - break; - - case EFluidType::PoisonWater: - if (info.m_hasLightmap) { - fmt::print(out, FMT_STRING("float4 lightMapTexel = lightMap.Sample(samp, vtf.uvs[{}]);"), 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 - out << "lighting += lerp(lightMapTexel * kColor2, lightMapTexel, kColor3);"; - } else { - // mix(Tex * K2, Tex, K3) + Lighting - out << "lighting += lightMapTexel * kColor2;"; - } - } - - // 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) - out << - "colorOut = (patternTex1.Sample(samp, vtf.uvs[0]) * kColor0 + lighting) * " - "patternTex2.Sample(samp, vtf.uvs[1]) + vtf.color;"; - else - out << "colorOut = lighting * patternTex2.Sample(samp, vtf.uvs[1]) + vtf.color;"; - } else { - out << "colorOut = vtf.color;"; - } - - if (info.m_hasColorTex) { - if (info.m_hasEnvBumpMap) { - // Make previous stage indirect, mtx0 - fmt::print(out, FMT_STRING( - "float2 indUvs = (envBumpMap.Sample(samp, vtf.uvs[{}]).ra - float2(0.5, 0.5)) * " - "float2(fog.indScale, -fog.indScale);"), - envBumpMapUv); - out << "colorOut += colorTex.Sample(samp, indUvs + vtf.uvs[2]) * lighting;"; - } else { - out << "colorOut += colorTex.Sample(samp, vtf.uvs[2]) * lighting;"; - } - } - - 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) - out << - "colorOut = (patternTex1.Sample(samp, vtf.uvs[0]) * kColor0 + vtf.color) * " - "patternTex2.Sample(samp, vtf.uvs[1]) + vtf.color;"; - else - out << "colorOut = vtf.color * patternTex2.Sample(samp, vtf.uvs[1]) + vtf.color;"; - } else { - out << "colorOut = vtf.color;"; - } - - if (info.m_hasColorTex) - out << "colorOut += colorTex.Sample(samp, vtf.uvs[2]);"; - - 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 - - out << - "float3 lightVec = lights[3].pos.xyz - vtf.mvPos.xyz;" - "float lx = dot(vtf.mvTangent.xyz, lightVec);" - "float ly = dot(vtf.mvBinorm.xyz, lightVec);"; - fmt::print(out, FMT_STRING( - "float4 emboss1 = bumpMap.Sample(samp, vtf.uvs[{}]) + float4(0.5);" - "float4 emboss2 = bumpMap.Sample(samp, vtf.uvs[{}] + float2(lx, ly));"), - 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 - out << "colorOut *= clamp((emboss1 + float4(0.5) - emboss2) * float4(2.0), float4(0.0), float4(1.0));"; - } - - 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) - out << - "colorOut = (patternTex1.Sample(samp, vtf.uvs[0]) * kColor0 + vtf.color) * " - "patternTex2.Sample(samp, vtf.uvs[1]) + vtf.color;"; - else - out << "colorOut = vtf.color * patternTex2.Sample(samp, vtf.uvs[1]) + vtf.color;"; - } else { - out << "colorOut = vtf.color;"; - } - - if (info.m_hasColorTex) - out << "colorOut += colorTex.Sample(samp, vtf.uvs[2]);"; - - if (info.m_hasBumpMap) { - // 3: bumpMapTCG, bumpMap, NULL - // ZERO, TEX, PREV, ZERO - // Output reg prev, scale 2 - fmt::print(out, FMT_STRING("float4 emboss1 = bumpMap.Sample(samp, vtf.uvs[{}]) + float4(0.5);"), bumpMapUv); - out << "colorOut *= emboss1 * float4(2.0);"; - } - - break; - } - - out << "colorOut.a = kColor0.a;\n"; - - out << "#define IS_ADDITIVE " << int(info.m_additive) << '\n'; - out << FS; - return out.str(); -} - -static void _BuildAdditionalTCGs(std::stringstream& out, const SFluidPlaneShaderInfo& info) { - int nextTCG = 3; - int nextMtx = 4; - - out << "#define ADDITIONAL_TCGS "; - if (info.m_hasBumpMap) - fmt::print(out, FMT_STRING("vtf.uvs[{}] = mul(texMtxs[0], pos).xy;"), nextTCG++); - if (info.m_hasEnvBumpMap) - fmt::print(out, FMT_STRING("vtf.uvs[{}] = mul(texMtxs[3], float4(normalIn.xyz, 1.0)).xy;"), nextTCG++); - if (info.m_hasEnvMap) - fmt::print(out, FMT_STRING("vtf.uvs[{}] = mul(texMtxs[{}], pos).xy;"), nextTCG++, nextMtx++); - if (info.m_hasLightmap) - fmt::print(out, FMT_STRING("vtf.uvs[{}] = mul(texMtxs[{}], pos).xy;"), nextTCG, nextMtx); - out << '\n'; -} - -static std::string _BuildVS(const SFluidPlaneShaderInfo& info, bool tessellation) { - if (tessellation) - return TessVS; - - std::stringstream out; - _BuildAdditionalTCGs(out, info); - out << VS; - return out.str(); -} -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 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::stringstream out; - _BuildAdditionalTCGs(out, info); - out << "#define RIPPLE_TEXTURE_REG t" << nextTex << '\n'; - out << TessES; - return out.str(); -} -template <> -std::string StageObject_CFluidPlaneShader::BuildShader( - const SFluidPlaneShaderInfo& in, bool tessellation) { - return BuildES(in); -} - -static std::string _BuildVS(const SFluidPlaneDoorShaderInfo& info) { - std::stringstream out; - out << "#define ADDITIONAL_TCGS\n"; - out << VS; - return out.str(); -} - -static std::string _BuildFS(const SFluidPlaneDoorShaderInfo& info) { - int nextTex = 0; - std::stringstream out; - - out << "#define TEXTURE_DECLS "; - if (info.m_hasPatternTex1) - fmt::print(out, FMT_STRING("Texture2D patternTex1 : register(t{});"), nextTex++); - if (info.m_hasPatternTex2) - fmt::print(out, FMT_STRING("Texture2D patternTex2 : register(t{});"), nextTex++); - if (info.m_hasColorTex) - fmt::print(out, FMT_STRING("Texture2D colorTex : register(t{});"), nextTex++); - out << '\n'; - - // Tex0 * kColor0 * Tex1 + Tex2 - out << "#define COMBINER_EXPRS "; - if (info.m_hasPatternTex1 && info.m_hasPatternTex2) { - out << - "colorOut = patternTex1.Sample(samp, vtf.uvs[0]) * kColor0 * " - "patternTex2.Sample(samp, vtf.uvs[1]);"; - } else { - out << "colorOut = float4(0.0);"; - } - - if (info.m_hasColorTex) { - out << "colorOut += colorTex.Sample(samp, vtf.uvs[2]);"; - } - - out << "colorOut.a = kColor0.a;\n"; - - out << "#define IS_ADDITIVE 0\n"; - out << FSDoor; - return out.str(); -} - -template <> -std::string StageObject_CFluidPlaneDoorShader::BuildShader( - const SFluidPlaneDoorShaderInfo& in) { - return _BuildVS(in); -} - -template <> -std::string StageObject_CFluidPlaneDoorShader::BuildShader( - const SFluidPlaneDoorShaderInfo& in) { - return _BuildFS(in); -} diff --git a/Shaders/shader_CFluidPlaneShaderMetal.cpp b/Shaders/shader_CFluidPlaneShaderMetal.cpp deleted file mode 100644 index 035d00c50..000000000 --- a/Shaders/shader_CFluidPlaneShaderMetal.cpp +++ /dev/null @@ -1,762 +0,0 @@ -#include "shader_CFluidPlaneShader.hpp" -#include -#include - -#define FOG_STRUCT_METAL \ - "struct Fog\n" \ - "{\n" \ - " float4 color;\n" \ - " float A;\n" \ - " float B;\n" \ - " float C;\n" \ - " int mode;\n" \ - " float indScale;\n" \ -"};\n" - -#define FOG_ALGORITHM_METAL \ - "static float4 MainPostFunc(thread VertToFrag& vtf, constant LightingUniform& lu, float4 colorIn)\n" \ - "{\n" \ - " float fogZ;\n" \ - " float fogF = saturate((lu.fog.A / (lu.fog.B - (1.0 - vtf.pos.z))) - lu.fog.C);\n" \ - " switch (lu.fog.mode)\n" \ - " {\n" \ - " case 2:\n" \ - " fogZ = fogF;\n" \ - " break;\n" \ - " case 4:\n" \ - " fogZ = 1.0 - exp2(-8.0 * fogF);\n" \ - " break;\n" \ - " case 5:\n" \ - " fogZ = 1.0 - exp2(-8.0 * fogF * fogF);\n" \ - " break;\n" \ - " case 6:\n" \ - " fogZ = exp2(-8.0 * (1.0 - fogF));\n" \ - " break;\n" \ - " case 7:\n" \ - " fogF = 1.0 - fogF;\n" \ - " fogZ = exp2(-8.0 * fogF * fogF);\n" \ - " break;\n" \ - " default:\n" \ - " fogZ = 0.0;\n" \ - " break;\n" \ - " }\n" \ - "#if IS_ADDITIVE\n" \ - " return float4(mix(colorIn, float4(0.0), saturate(fogZ)).rgb, colorIn.a);\n" \ - "#else\n" \ - " return float4(mix(colorIn, lu.fog.color, saturate(fogZ)).rgb, colorIn.a);\n" \ - "#endif\n" \ - "}\n" - -static const char* VS = - "struct VertData\n" - "{\n" - " float4 posIn [[ attribute(0) ]];\n" - " float4 normalIn [[ attribute(1) ]];\n" - " float4 binormalIn [[ attribute(2) ]];\n" - " float4 tangentIn [[ attribute(3) ]];\n" - " float4 colorIn [[ attribute(4) ]];\n" - "};\n" - "\n" - "struct FluidPlaneUniform\n" - "{\n" - " float4x4 mv;\n" - " float4x4 mvNorm;\n" - " float4x4 proj;\n" - " float4x4 texMtxs[6];\n" - "};\n" - "\n" - "struct VertToFrag\n" - "{\n" - " float4 pos [[ position ]];\n" - " float4 mvPos;\n" - " float4 mvNorm;\n" - " float4 mvBinorm;\n" - " float4 mvTangent;\n" - " float4 color;\n" - " float2 uv0;\n" - " float2 uv1;\n" - " float2 uv2;\n" - " float2 uv3;\n" - " float2 uv4;\n" - " float2 uv5;\n" - " float2 uv6;\n" - "};\n" - "\n" - "vertex VertToFrag vmain(VertData v [[ stage_in ]],\n" - " constant FluidPlaneUniform& fu [[ buffer(2) ]])\n" - "{\n" - " VertToFrag vtf;\n" - " float4 pos = float4(v.posIn.xyz, 1.0);\n" - " float4 normalIn = v.normalIn;\n" - " vtf.mvPos = fu.mv * pos;\n" - " vtf.pos = fu.proj * vtf.mvPos;\n" - " vtf.mvNorm = fu.mvNorm * v.normalIn;\n" - " vtf.mvBinorm = fu.mvNorm * v.binormalIn;\n" - " vtf.mvTangent = fu.mvNorm * v.tangentIn;\n" - " vtf.color = v.colorIn;\n" - " vtf.uv0 = (fu.texMtxs[0] * pos).xy;\n" - " vtf.uv1 = (fu.texMtxs[1] * pos).xy;\n" - " vtf.uv2 = (fu.texMtxs[2] * pos).xy;\n" - " ADDITIONAL_TCGS\n" // Additional TCGs here - " return vtf;\n" - "}\n"; - -static const char* TessCS = - "struct VertData\n" - "{\n" - " float4 minMaxPos [[ attribute(0) ]];\n" - " float4 outerLevelsIn [[ attribute(1) ]];\n" - " float2 innerLevelsIn [[ attribute(2) ]];\n" - "};\n" - "\n" - "struct KernelPatchInfo {\n" - " uint numPatches; // total number of patches to process.\n" - " // we need this because this value may\n" - " // not be a multiple of threadgroup size.\n" - " ushort numPatchesInThreadGroup; // number of patches processed by a\n" - " // thread-group\n" - " ushort numControlPointsPerPatch;\n" - "};\n" - "\n" - "kernel void\n" - "cmain(VertData v [[ stage_in ]],\n" - " constant KernelPatchInfo& patchInfo [[ buffer(2) ]],\n" - " device MTLQuadTessellationFactorsHalf* tessellationFactorBuffer [[ buffer(3) ]],\n" - " ushort lID [[ thread_position_in_threadgroup ]],\n" - " ushort groupID [[ threadgroup_position_in_grid ]])\n" - "{\n" - " uint patchGroupID = groupID * patchInfo.numPatchesInThreadGroup;\n" - "\n" - " // execute the per-patch hull function\n" - " if (lID < patchInfo.numPatchesInThreadGroup)\n" - " {\n" - " uint patchID = patchGroupID + lID;\n" - " device MTLQuadTessellationFactorsHalf& patchOut = tessellationFactorBuffer[patchID];\n" - " for (int i=0 ; i<4 ; ++i)\n" - " patchOut.edgeTessellationFactor[i] = v.outerLevelsIn[i];\n" - " for (int i=0 ; i<2 ; ++i)\n" - " patchOut.insideTessellationFactor[i] = v.innerLevelsIn[i];\n" - " }\n" - "}\n"; - -static const char* TessES = - "struct Ripple\n" - "{\n" - " float4 center; // time, distFalloff\n" - " float4 params; // amplitude, lookupPhase, lookupTime\n" - "};\n" - "\n" - "struct FluidPlaneUniform\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 [[ position ]];\n" - " float4 mvPos;\n" - " float4 mvNorm;\n" - " float4 mvBinorm;\n" - " float4 mvTangent;\n" - " float4 color;\n" - " float2 uv0;\n" - " float2 uv1;\n" - " float2 uv2;\n" - " float2 uv3;\n" - " float2 uv4;\n" - " float2 uv5;\n" - " float2 uv6;\n" - "};\n" - "\n" - "struct VertData\n" - "{\n" - " float4 minMaxPos [[ attribute(0) ]];\n" - " float4 outerLevelsIn [[ attribute(1) ]];\n" - " float2 innerLevelsIn [[ attribute(2) ]];\n" - "};\n" - "\n" - "#define PI_X2 6.283185307179586\n" - "\n" - "static void ApplyRipple(constant Ripple& ripple, float2 pos, thread float& height,\n" - " sampler samp, texture2d RippleMap)\n" - "{\n" - " float dist = length(ripple.center.xy - pos);\n" - " float rippleV = RippleMap.sample(samp, float2(dist * ripple.center.w, ripple.center.z), level(0.0)).r;\n" - " height += rippleV * ripple.params.x * sin((dist * ripple.params.y + ripple.params.z) * PI_X2);\n" - "}\n" - "\n" - "[[ patch(quad, 1) ]]\n" - "vertex VertToFrag emain(VertData v [[ stage_in ]], float2 TessCoord [[ position_in_patch ]],\n" - " constant FluidPlaneUniform& fu [[ buffer(2) ]],\n" - " sampler samp [[ sampler(2) ]],\n" - " texture2d RippleMap [[ texture(RIPPLE_TEXTURE_IDX) ]])\n" - "{\n" - " float2 posIn = float2(mix(v.minMaxPos.x, v.minMaxPos.z, TessCoord.x),\n" - " mix(v.minMaxPos.y, v.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(fu.ripples[i], posIn, height, samp, RippleMap);\n" - " ApplyRipple(fu.ripples[i], posIn + float2(0.0, fu.rippleNormResolution), upHeight, samp, RippleMap);\n" - " ApplyRipple(fu.ripples[i], posIn - float2(0.0, fu.rippleNormResolution), downHeight, samp, RippleMap);\n" - " ApplyRipple(fu.ripples[i], posIn + float2(fu.rippleNormResolution, 0.0), rightHeight, samp, RippleMap);\n" - " ApplyRipple(fu.ripples[i], posIn - float2(fu.rippleNormResolution, 0.0), leftHeight, samp, RippleMap);\n" - " }\n" - " float4 normalIn = float4(normalize(float3((leftHeight - rightHeight),\n" - " (downHeight - upHeight),\n" - " fu.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 = (fu.mv * pos);\n" - " vtf.pos = (fu.proj * vtf.mvPos);\n" - " vtf.mvNorm = (fu.mvNorm * normalIn);\n" - " vtf.mvBinorm = (fu.mvNorm * binormalIn);\n" - " vtf.mvTangent = (fu.mvNorm * tangentIn);\n" - " vtf.color = max(height, 0.0) * fu.colorMul;\n" - " vtf.color.a = 1.0;\n" - " vtf.uv0 = (fu.texMtxs[0] * pos).xy;\n" - " vtf.uv1 = (fu.texMtxs[1] * pos).xy;\n" - " vtf.uv2 = (fu.texMtxs[2] * pos).xy;\n" - " ADDITIONAL_TCGS\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" -FOG_STRUCT_METAL -"\n" -"struct LightingUniform\n" -"{\n" -" Light lights[" _XSTR(URDE_MAX_LIGHTS) "];\n" -" float4 ambient;\n" -" float4 kColor0;\n" -" float4 kColor1;\n" -" float4 kColor2;\n" -" float4 kColor3;\n" -" float4 addColor;\n" -" Fog fog;\n" -"};\n" -"\n" -"static float4 LightingFunc(constant LightingUniform& lu, float3 mvPosIn, float3 mvNormIn)\n" -"{\n" -" float4 ret = lu.ambient;\n" -" \n" -" for (int i=0 ; i<" _XSTR(URDE_MAX_LIGHTS) " ; ++i)\n" -" {\n" -" float3 delta = mvPosIn - lu.lights[i].pos.xyz;\n" -" float dist = length(delta);\n" -" float angDot = clamp(dot(normalize(delta), lu.lights[i].dir.xyz), 0.0, 1.0);\n" -" float att = 1.0 / (lu.lights[i].linAtt[2] * dist * dist +\n" -" lu.lights[i].linAtt[1] * dist +\n" -" lu.lights[i].linAtt[0]);\n" -" float angAtt = lu.lights[i].angAtt[2] * angDot * angDot +\n" -" lu.lights[i].angAtt[1] * angDot +\n" -" lu.lights[i].angAtt[0];\n" -" ret += lu.lights[i].color * angAtt * att * saturate(dot(normalize(-delta), mvNormIn));\n" -" }\n" -" \n" -" return saturate(ret);\n" -"}\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 pos [[ position ]];\n" -" float4 mvPos;\n" -" float4 mvNorm;\n" -" float4 mvBinorm;\n" -" float4 mvTangent;\n" -" float4 color;\n" -" float2 uv0;\n" -" float2 uv1;\n" -" float2 uv2;\n" -" float2 uv3;\n" -" float2 uv4;\n" -" float2 uv5;\n" -" float2 uv6;\n" -"};\n" -"\n" -FOG_ALGORITHM_METAL -"\n" -"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n" -" sampler samp [[ sampler(0) ]],\n" -" constant LightingUniform& lu [[ buffer(4) ]]" -" TEXTURE_PARAMS)\n" // Textures here -"{\n" -" float4 lighting = LightingFunc(lu, vtf.mvPos.xyz, normalize(vtf.mvNorm.xyz));\n" -" float4 colorOut;\n" -" COMBINER_EXPRS\n" // Combiner expression here -" return MainPostFunc(vtf, lu, 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" -FOG_STRUCT_METAL -"\n" -"struct LightingUniform\n" -"{\n" -" Light lights[" _XSTR(URDE_MAX_LIGHTS) "];\n" -" float4 ambient;\n" -" float4 kColor0;\n" -" float4 kColor1;\n" -" float4 kColor2;\n" -" float4 kColor3;\n" -" float4 addColor;\n" -" Fog fog;\n" -"};\n" -"\n" -"struct VertToFrag\n" -"{\n" -" float4 pos [[ position ]];\n" -" float4 mvPos;\n" -" float4 mvNorm;\n" -" float4 mvBinorm;\n" -" float4 mvTangent;\n" -" float4 color;\n" -" float2 uv0;\n" -" float2 uv1;\n" -" float2 uv2;\n" -" float2 uv3;\n" -" float2 uv4;\n" -" float2 uv5;\n" -" float2 uv6;\n" -"};\n" -FOG_ALGORITHM_METAL -"\n" -"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n" -" sampler samp [[ sampler(0) ]],\n" -" constant LightingUniform& lu [[ buffer(4) ]]" -" TEXTURE_PARAMS)\n" // Textures here -"{\n" -" float4 colorOut;\n" -" COMBINER_EXPRS\n" // Combiner expression here -" return MainPostFunc(vtf, lu, colorOut);\n" -"}\n"; - -static std::string _BuildFS(const SFluidPlaneShaderInfo& info) { - std::stringstream out; - int nextTex = 0; - int nextTCG = 3; - int bumpMapUv = -1; - int envBumpMapUv = -1; - int envMapUv = -1; - int lightmapUv = -1; - - out << "#define TEXTURE_PARAMS "; - if (info.m_hasPatternTex1) - fmt::print(out, FMT_STRING(",texture2d patternTex1 [[ texture({}) ]]"), nextTex++); - if (info.m_hasPatternTex2) - fmt::print(out, FMT_STRING(",texture2d patternTex2 [[ texture({}) ]]"), nextTex++); - if (info.m_hasColorTex) - fmt::print(out, FMT_STRING(",texture2d colorTex [[ texture({}) ]]"), nextTex++); - if (info.m_hasBumpMap) - fmt::print(out, FMT_STRING(",texture2d bumpMap [[ texture({}) ]]"), nextTex++); - if (info.m_hasEnvMap) - fmt::print(out, FMT_STRING(",texture2d envMap [[ texture({}) ]]"), nextTex++); - if (info.m_hasEnvBumpMap) - fmt::print(out, FMT_STRING(",texture2d envBumpMap [[ texture({}) ]]"), nextTex++); - if (info.m_hasLightmap) - fmt::print(out, FMT_STRING(",texture2d lightMap [[ texture({}) ]]"), nextTex++); - out << '\n'; - - if (info.m_hasBumpMap) { - bumpMapUv = nextTCG; - } - if (info.m_hasEnvBumpMap) { - envBumpMapUv = nextTCG; - } - if (info.m_hasEnvMap) { - envMapUv = nextTCG; - } - if (info.m_hasLightmap) { - lightmapUv = nextTCG; - } - - out << "#define COMBINER_EXPRS "; - switch (info.m_type) { - case EFluidType::NormalWater: - case EFluidType::PhazonFluid: - case EFluidType::Four: - if (info.m_hasLightmap) { - fmt::print(out, FMT_STRING("float4 lightMapTexel = lightMap.sample(samp, vtf.uv{});"), 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 - out << "lighting += mix(lightMapTexel * lu.kColor2, lightMapTexel, lu.kColor3);"; - } else { - // mix(Tex * K2, Tex, K3) + Lighting - out << "lighting += lightMapTexel * lu.kColor2;"; - } - } - - // 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) - out << - "colorOut = (patternTex1.sample(samp, vtf.uv0) * lu.kColor0 + lighting) * " - "patternTex2.sample(samp, vtf.uv1) + vtf.color;"; - else - out << "colorOut = lighting * patternTex2.sample(samp, vtf.uv1) + vtf.color;"; - } else { - out << "colorOut = vtf.color;"; - } - - if (info.m_hasColorTex && !info.m_hasEnvMap && info.m_hasEnvBumpMap) { - // Make previous stage indirect, mtx0 - fmt::print(out, FMT_STRING( - "float2 indUvs = (envBumpMap.sample(samp, vtf.uv{}).ra - float2(0.5, 0.5)) * " - "float2(lu.fog.indScale, -lu.fog.indScale);"), - envBumpMapUv); - out << "colorOut += colorTex.sample(samp, indUvs + vtf.uv2) * lighting;"; - } 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) - out << "colorOut += colorTex.sample(samp, vtf.uv2) * lighting;"; - fmt::print(out, FMT_STRING( - "float2 indUvs = (envBumpMap.sample(samp, vtf.uv{}).ra - float2(0.5, 0.5)) * " - "float2(lu.fog.indScale, -lu.fog.indScale);"), - envBumpMapUv); - fmt::print(out, FMT_STRING( - "colorOut = mix(colorOut, envMap.sample(samp, indUvs + vtf.uv{}), lu.kColor1);"), envMapUv); - } else if (info.m_hasColorTex) { - out << "colorOut += colorTex.sample(samp, vtf.uv2) * lighting;"; - } - - break; - - case EFluidType::PoisonWater: - if (info.m_hasLightmap) { - fmt::print(out, FMT_STRING("float4 lightMapTexel = lightMap.sample(samp, vtf.uv{});"), 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 - out << "lighting += mix(lightMapTexel * lu.kColor2, lightMapTexel, lu.kColor3);"; - } else { - // mix(Tex * K2, Tex, K3) + Lighting - out << "lighting += lightMapTexel * lu.kColor2;"; - } - } - - // 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) - out << - "colorOut = (patternTex1.sample(samp, vtf.uv0) * lu.kColor0 + lighting) * " - "patternTex2.sample(samp, vtf.uv1) + vtf.color;"; - else - out << "colorOut = lighting * patternTex2.sample(samp, vtf.uv1) + vtf.color;"; - } else { - out << "colorOut = vtf.color;"; - } - - if (info.m_hasColorTex) { - if (info.m_hasEnvBumpMap) { - // Make previous stage indirect, mtx0 - fmt::print(out, FMT_STRING( - "float2 indUvs = (envBumpMap.sample(samp, vtf.uv{}).ra - float2(0.5, 0.5)) * " - "float2(lu.fog.indScale, -lu.fog.indScale);"), - envBumpMapUv); - out << "colorOut += colorTex.sample(samp, indUvs + vtf.uv2) * lighting;"; - } else { - out << "colorOut += colorTex.sample(samp, vtf.uv2) * lighting;"; - } - } - - 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) - out << - "colorOut = (patternTex1.sample(samp, vtf.uv0) * lu.kColor0 + vtf.color) * " - "patternTex2.sample(samp, vtf.uv1) + vtf.color;"; - else - out << "colorOut = vtf.color * patternTex2.sample(samp, vtf.uv1) + vtf.color;"; - } else { - out << "colorOut = vtf.color;"; - } - - if (info.m_hasColorTex) - out << "colorOut += colorTex.sample(samp, vtf.uv2);"; - - 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 - - out << - "float3 lightVec = lu.lights[3].pos.xyz - vtf.mvPos.xyz;" - "float lx = dot(vtf.mvTangent.xyz, lightVec);" - "float ly = dot(vtf.mvBinorm.xyz, lightVec);"; - fmt::print(out, FMT_STRING( - "float4 emboss1 = bumpMap.sample(samp, vtf.uv{}) + float4(0.5);" - "float4 emboss2 = bumpMap.sample(samp, vtf.uv{} + float2(lx, ly));"), - 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 - out << "colorOut *= clamp((emboss1 + float4(0.5) - emboss2) * float4(2.0), float4(0.0), float4(1.0));"; - } - - 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) - out << - "colorOut = (patternTex1.sample(samp, vtf.uv0) * lu.kColor0 + vtf.color) * " - "patternTex2.sample(samp, vtf.uv1) + vtf.color;"; - else - out << "colorOut = vtf.color * patternTex2.sample(samp, vtf.uv1) + vtf.color;"; - } else { - out << "colorOut = vtf.color;"; - } - - if (info.m_hasColorTex) - out << "colorOut += colorTex.sample(samp, vtf.uv2);"; - - if (info.m_hasBumpMap) { - // 3: bumpMapTCG, bumpMap, NULL - // ZERO, TEX, PREV, ZERO - // Output reg prev, scale 2 - fmt::print(out, FMT_STRING("float4 emboss1 = bumpMap.sample(samp, vtf.uv{}) + float4(0.5);"), bumpMapUv); - out << "colorOut *= emboss1 * float4(2.0);"; - } - - break; - } - - out << "colorOut.a = lu.kColor0.a;\n"; - - out << "#define IS_ADDITIVE " << int(info.m_additive) << '\n'; - out << FS; - return out.str(); -} - -static void _BuildAdditionalTCGs(std::stringstream& out, const SFluidPlaneShaderInfo& info) { - int nextTCG = 3; - int nextMtx = 4; - - out << "#define ADDITIONAL_TCGS "; - if (info.m_hasBumpMap) - fmt::print(out, FMT_STRING("vtf.uv{} = (fu.texMtxs[0] * pos).xy;"), nextTCG++); - if (info.m_hasEnvBumpMap) - fmt::print(out, FMT_STRING("vtf.uv{} = (fu.texMtxs[3] * float4(normalIn.xyz, 1.0)).xy;"), nextTCG++); - if (info.m_hasEnvMap) - fmt::print(out, FMT_STRING("vtf.uv{} = (fu.texMtxs[{}] * pos).xy;"), nextTCG++, nextMtx++); - if (info.m_hasLightmap) - fmt::print(out, FMT_STRING("vtf.uv{} = (fu.texMtxs[{}] * pos).xy;"), nextTCG++, nextMtx++); - out << '\n'; -} - -static std::string _BuildVS(const SFluidPlaneShaderInfo& info, bool tessellation) { - std::stringstream out; - _BuildAdditionalTCGs(out, info); - out << VS; - return out.str(); -} -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 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::stringstream out; - _BuildAdditionalTCGs(out, info); - out << "#define RIPPLE_TEXTURE_IDX " << nextTex << '\n'; - out << TessES; - return out.str(); -} - -template <> -std::string StageObject_CFluidPlaneShader::BuildShader( - const SFluidPlaneShaderInfo& in, bool tessellation) { - return BuildES(in); -} - -static std::string _BuildVS(const SFluidPlaneDoorShaderInfo& info) { - std::stringstream out; - out << "#define ADDITIONAL_TCGS\n"; - out << VS; - return out.str(); -} - -static std::string _BuildFS(const SFluidPlaneDoorShaderInfo& info) { - int nextTex = 0; - std::stringstream out; - - out << "#define TEXTURE_PARAMS "; - if (info.m_hasPatternTex1) - fmt::print(out, FMT_STRING(",texture2d patternTex1 [[ texture({}) ]]"), nextTex++); - if (info.m_hasPatternTex2) - fmt::print(out, FMT_STRING(",texture2d patternTex2 [[ texture({}) ]]"), nextTex++); - if (info.m_hasColorTex) - fmt::print(out, FMT_STRING(",texture2d colorTex [[ texture({}) ]]"), nextTex++); - out << '\n'; - - // Tex0 * kColor0 * Tex1 + Tex2 - out << "#define COMBINER_EXPRS "; - if (info.m_hasPatternTex1 && info.m_hasPatternTex2) { - out << - "colorOut = patternTex1.sample(samp, vtf.uv0) * lu.kColor0 * " - "patternTex2.sample(samp, vtf.uv1);"; - } else { - out << "colorOut = float4(0.0);"; - } - - if (info.m_hasColorTex) { - out << "colorOut += colorTex.sample(samp, vtf.uv2);"; - } - - out << "colorOut.a = lu.kColor0.a;\n"; - - out << "#define IS_ADDITIVE 0\n"; - out << FSDoor; - return out.str(); -} - -template <> -std::string StageObject_CFluidPlaneDoorShader::BuildShader( - const SFluidPlaneDoorShaderInfo& in) { - return _BuildVS(in); -} - -template <> -std::string StageObject_CFluidPlaneDoorShader::BuildShader( - const SFluidPlaneDoorShaderInfo& in) { - return _BuildFS(in); -} diff --git a/Shaders/shader_CModelShaders.hpp b/Shaders/shader_CModelShaders.hpp deleted file mode 100644 index b44ecc88a..000000000 --- a/Shaders/shader_CModelShaders.hpp +++ /dev/null @@ -1,68 +0,0 @@ -#pragma once -#include "hecl/PipelineBase.hpp" -#include "hecl/hecl.hpp" -#include "DataSpec/DNAMP1/CMDLMaterials.hpp" - -struct SModelShadersInfo { - uint64_t m_hash; - using Material = DataSpec::DNAMP1::HMDLMaterialSet::Material; - const Material& m_material; - const hecl::Backend::ShaderTag& m_tag; - const hecl::Backend::ExtensionSlot& m_extension; - std::vector m_vtxFmtData; - boo::VertexFormatInfo m_vtxFmt; - boo::AdditionalPipelineInfo m_additionalInfo; - - explicit SModelShadersInfo(const Material& material, - const hecl::Backend::ShaderTag& tag, - const hecl::Backend::ExtensionSlot& extension) - : m_material(material), m_tag(tag), m_extension(extension) { - m_hash = m_tag.val64(); - hecl::hash_combine_impl(m_hash, std::hash()(m_extension.hash())); - - m_vtxFmtData = tag.vertexFormat(); - m_vtxFmt = boo::VertexFormatInfo(m_vtxFmtData.size(), m_vtxFmtData.data()); - - m_additionalInfo = m_tag.additionalInfo(extension, material.blendFactors()); - } - - static constexpr bool HasHash = true; - uint64_t Hash() const { return m_hash; } -}; - -class Shader_CModelShaders : public hecl::GeneralShader { - const SModelShadersInfo& m_info; - uint64_t m_vertHash, m_fragHash; - static uint64_t BuildVertHash(const SModelShadersInfo& in); - static uint64_t BuildFragHash(const SModelShadersInfo& in); -public: - Shader_CModelShaders(const SModelShadersInfo& in) - : m_info(in) - , m_vertHash(BuildVertHash(in)) - , m_fragHash(BuildFragHash(in)) - , VtxFmt(in.m_vtxFmt) - , PipelineInfo(in.m_additionalInfo) {} - - const boo::VertexFormatInfo VtxFmt; - const boo::AdditionalPipelineInfo PipelineInfo; - static constexpr bool HasHash = true; - uint64_t Hash() const { return m_info.m_hash; } - static constexpr bool HasStageHash = true; - template uint64_t StageHash() const; - const SModelShadersInfo& info() const { return m_info; } -}; -template <> inline uint64_t Shader_CModelShaders::StageHash() const { return m_vertHash; } -template <> inline uint64_t Shader_CModelShaders::StageHash() const { return m_fragHash; } - -template -class StageObject_CModelShaders : public hecl::StageBinary { - static std::string BuildShader(const SModelShadersInfo& in); - -public: - StageObject_CModelShaders(hecl::StageConverter& conv, hecl::FactoryCtx& ctx, - const Shader_CModelShaders& in) - : hecl::StageBinary(conv, ctx, hecl::StageSourceText(BuildShader(in.info()))) {} -}; - -#define UNIVERSAL_PIPELINES_shader_CModelShaders ::Shader_CModelShaders -#define STAGES_shader_CModelShaders(P, S) ::StageObject_CModelShaders, diff --git a/Shaders/shader_CModelShadersGLSL.cpp b/Shaders/shader_CModelShadersGLSL.cpp deleted file mode 100644 index 812d83dec..000000000 --- a/Shaders/shader_CModelShadersGLSL.cpp +++ /dev/null @@ -1,286 +0,0 @@ -#include -#include -#include -#include "shader_CModelShaders.hpp" -#include "Runtime/Graphics/Shaders/CModelShaders.hpp" - -extern "C" const uint8_t CMODELSHADERS_COMMON_GLSL[]; -extern "C" size_t CMODELSHADERS_COMMON_GLSL_SZ; -static std::string_view CMODELSHADERS_COMMON_GLSL_SV((char*)CMODELSHADERS_COMMON_GLSL, CMODELSHADERS_COMMON_GLSL_SZ); - -extern "C" const uint8_t CMODELSHADERS_VERT_GLSL[]; -extern "C" size_t CMODELSHADERS_VERT_GLSL_SZ; -static std::string_view CMODELSHADERS_VERT_GLSL_SV((char*)CMODELSHADERS_VERT_GLSL, CMODELSHADERS_VERT_GLSL_SZ); - -extern "C" const uint8_t CMODELSHADERS_FRAG_GLSL[]; -extern "C" size_t CMODELSHADERS_FRAG_GLSL_SZ; -static std::string_view CMODELSHADERS_FRAG_GLSL_SV((char*)CMODELSHADERS_FRAG_GLSL, CMODELSHADERS_FRAG_GLSL_SZ); - -using BlendMaterial = SModelShadersInfo::Material::BlendMaterial; -using TexCoordSource = BlendMaterial::TexCoordSource; - -static std::string_view EmitTexGenSource2(TexCoordSource src) { - switch (src) { - case TexCoordSource::Position: - return "objPos.xy"sv; - case TexCoordSource::Normal: - return "objNorm.xy"sv; - case TexCoordSource::Tex0: - return "uvIn[0]"sv; - case TexCoordSource::Tex1: - return "uvIn[1]"sv; - case TexCoordSource::Tex2: - return "uvIn[2]"sv; - case TexCoordSource::Tex3: - return "uvIn[3]"sv; - case TexCoordSource::Tex4: - return "uvIn[4]"sv; - case TexCoordSource::Tex5: - return "uvIn[5]"sv; - case TexCoordSource::Tex6: - return "uvIn[6]"sv; - case TexCoordSource::Tex7: - return "uvIn[7]"sv; - default: - assert(false && "Unknown source type"); - break; - } - return {}; -} - -static std::string_view EmitTexGenSource4(TexCoordSource src) { - switch (src) { - case TexCoordSource::Position: - return "vec4(objPos.xyz, 1.0)"sv; - case TexCoordSource::Normal: - return "vec4(objNorm.xyz, 1.0)"sv; - case TexCoordSource::Tex0: - return "vec4(uvIn[0], 0.0, 1.0)"sv; - case TexCoordSource::Tex1: - return "vec4(uvIn[1], 0.0, 1.0)"sv; - case TexCoordSource::Tex2: - return "vec4(uvIn[2], 0.0, 1.0)"sv; - case TexCoordSource::Tex3: - return "vec4(uvIn[3], 0.0, 1.0)"sv; - case TexCoordSource::Tex4: - return "vec4(uvIn[4], 0.0, 1.0)"sv; - case TexCoordSource::Tex5: - return "vec4(uvIn[5], 0.0, 1.0)"sv; - case TexCoordSource::Tex6: - return "vec4(uvIn[6], 0.0, 1.0)"sv; - case TexCoordSource::Tex7: - return "vec4(uvIn[7], 0.0, 1.0)"sv; - default: - assert(false && "Unknown source type"); - break; - } - return {}; -} - -static std::string _BuildVS(const SModelShadersInfo& info) { - std::stringstream vertOut; - vertOut << CMODELSHADERS_COMMON_GLSL_SV; - vertOut << "#define URDE_COL_SLOTS "sv << unsigned(info.m_tag.getColorCount()) << '\n'; - vertOut << "#define URDE_UV_SLOTS "sv << unsigned(info.m_tag.getUvCount()) << '\n'; - vertOut << "#define URDE_SKIN_SLOTS "sv << unsigned(info.m_tag.getSkinSlotCount()) << '\n'; - vertOut << "#define URDE_WEIGHT_SLOTS "sv << unsigned(info.m_tag.getWeightCount()) << '\n'; - - vertOut << "#define URDE_VERT_DATA_DECL " - "layout(location=0) in vec3 posIn;" - "layout(location=1) in vec3 normIn;"sv; - if (info.m_tag.getColorCount()) - vertOut << "layout(location=2) in vec4 colIn["sv << unsigned(info.m_tag.getColorCount()) << "];"sv; - if (info.m_tag.getUvCount()) - vertOut << "layout(location="sv << 2 + info.m_tag.getColorCount() << - ") in vec2 uvIn["sv << unsigned(info.m_tag.getUvCount()) << "];"sv; - if (info.m_tag.getWeightCount()) - vertOut << "layout(location="sv << 2 + info.m_tag.getColorCount() + info.m_tag.getUvCount() << - ") in vec4 weightIn["sv << unsigned(info.m_tag.getWeightCount()) << "];"sv; - vertOut << '\n'; - - vertOut << "\n#define URDE_TCG_EXPR "sv; - using UVAnimType = BlendMaterial::UVAnimType; - using PassType = BlendMaterial::PassType; - int mtxIdx = 0; - for (const auto& chunk : info.m_material.chunks) { - if (auto passChunk = chunk.get_if()) { - if (passChunk->type != PassType::IndirectTex) { - std::string_view tpStr = BlendMaterial::PassTypeToString(passChunk->type); - if (passChunk->uvAnimType == UVAnimType::Invalid) { - vertOut << "vtf."sv << tpStr << "Uv = "sv << EmitTexGenSource2(passChunk->source) << ";"sv; - } else { - vertOut << "tmpProj = texMtxs["sv << mtxIdx << "].postMtx * vec4("sv << - (passChunk->shouldNormalizeUv() ? "normalize"sv : ""sv) << "((texMtxs["sv << mtxIdx << "].mtx * "sv << - EmitTexGenSource4(passChunk->source) << ").xyz), 1.0);"sv << - "vtf."sv << tpStr << "Uv = (tmpProj / tmpProj.w).xy;"sv; - } - } - } else if (auto clrChunk = chunk.get_if()) { - std::string_view tpStr = BlendMaterial::PassTypeToString(clrChunk->type); - vertOut << "vtf."sv << tpStr << "Uv = vec2(0.0,0.0);"sv; - } - } - if (!info.m_extension.noReflection && info.m_tag.getReflectionType() != hecl::Backend::ReflectionType::None) - vertOut << "vtf.dynReflectionUvs[0] = normalize((indMtx * vec4(objPos.xyz, 1.0)).xz) * vec2(0.5, 0.5) + vec2(0.5, 0.5);" - "vtf.dynReflectionUvs[1] = (reflectMtx * vec4(objPos.xyz, 1.0)).xy;" - "vtf.dynReflectionAlpha = reflectAlpha;"; - - for (size_t i = 0; i < info.m_extension.texCount; ++i) { - const auto& extTex = info.m_extension.texs[i]; - if (extTex.mtxIdx == 0xff) - vertOut << "vtf.extUvs["sv << i << "] = "sv << EmitTexGenSource2(extTex.src) << ";"sv; - else - vertOut << "tmpProj = texMtxs["sv << unsigned(extTex.mtxIdx) << "].postMtx * vec4("sv << - (extTex.normalize ? "normalize"sv : ""sv) << "((texMtxs["sv << unsigned(extTex.mtxIdx) << "].mtx * "sv << - EmitTexGenSource4(extTex.src) << ").xyz), 1.0);"sv << - "vtf.extUvs["sv << i << "] = (tmpProj / tmpProj.w).xy;"sv; - } - vertOut << '\n'; - - vertOut << CMODELSHADERS_VERT_GLSL_SV; - return vertOut.str(); -} - -template -static void _Hash(XXH64_state_t& st, T val) { - XXH64_update(&st, &val, sizeof(val)); -} - -uint64_t Shader_CModelShaders::BuildVertHash(const SModelShadersInfo& info) { - XXH64_state_t st; - XXH64_reset(&st, 0); - _Hash(st, info.m_tag.getColorCount()); - _Hash(st, info.m_tag.getUvCount()); - _Hash(st, info.m_tag.getSkinSlotCount()); - _Hash(st, info.m_tag.getWeightCount()); - for (const auto& chunk : info.m_material.chunks) { - if (auto passChunk = chunk.get_if()) { - _Hash(st, passChunk->type); - _Hash(st, passChunk->uvAnimType); - _Hash(st, passChunk->source); - _Hash(st, passChunk->shouldNormalizeUv()); - } else if (auto clrChunk = chunk.get_if()) { - _Hash(st, clrChunk->type); - } - } - _Hash(st, info.m_extension.noReflection); - _Hash(st, info.m_tag.getReflectionType()); - for (size_t i = 0; i < info.m_extension.texCount; ++i) { - const auto& extTex = info.m_extension.texs[i]; - _Hash(st, extTex.mtxIdx); - _Hash(st, extTex.src); - _Hash(st, extTex.normalize); - } - return XXH64_digest(&st); -} - -static std::string _BuildFS(const SModelShadersInfo& info) { - std::stringstream fragOut; - fragOut << CMODELSHADERS_COMMON_GLSL_SV; - fragOut << "#define URDE_MAX_LIGHTS " _XSTR(URDE_MAX_LIGHTS) "\n"; - fragOut << "#define " << info.m_extension.shaderMacro << "\n"; - - using ShaderType = BlendMaterial::ShaderType; - switch (info.m_material.shaderType) { - case ShaderType::RetroShader: - fragOut << "#define RETRO_SHADER\n"; break; - case ShaderType::RetroDynamicShader: - fragOut << "#define RETRO_DYNAMIC_SHADER\n"; break; - case ShaderType::RetroDynamicAlphaShader: - fragOut << "#define RETRO_DYNAMIC_ALPHA_SHADER\n"; break; - case ShaderType::RetroDynamicCharacterShader: - fragOut << "#define RETRO_DYNAMIC_CHARACTER_SHADER\n"; break; - default: - assert(false && "Unknown shader type"); - break; - } - - fragOut << "#define BLEND_SRC_"sv << hecl::Backend::BlendFactorToDefine( - hecl::Backend::BlendFactor(info.m_additionalInfo.srcFac), hecl::Backend::BlendFactor::One) << '\n'; - fragOut << "#define BLEND_DST_"sv << hecl::Backend::BlendFactorToDefine( - hecl::Backend::BlendFactor(info.m_additionalInfo.dstFac), hecl::Backend::BlendFactor::Zero) << '\n'; - - using PassType = BlendMaterial::PassType; - for (const auto& chunk : info.m_material.chunks) { - if (auto passChunk = chunk.get_if()) { - if (passChunk->alpha) { - std::string_view tpStr = BlendMaterial::PassTypeToString(passChunk->type); - fragOut << "#define ALPHA_" << tpStr << '\n'; - } - } else if (auto clrChunk = chunk.get_if()) { - if (clrChunk->type == PassType::Alpha) - fragOut << "#define ALPHA_alpha\n"; - } - } - - if (info.m_tag.getAlphaTest() || info.m_extension.forceAlphaTest) - fragOut << "#define URDE_ALPHA_TEST\n"; - - if (info.m_extension.diffuseOnly) - fragOut << "#define URDE_DIFFUSE_ONLY\n"; - - if (!info.m_extension.noReflection) { - if (info.m_tag.getReflectionType() == hecl::Backend::ReflectionType::Indirect) - fragOut << "#define URDE_REFLECTION_INDIRECT\n"sv; - else if (info.m_tag.getReflectionType() == hecl::Backend::ReflectionType::Simple) - fragOut << "#define URDE_REFLECTION_SIMPLE\n"sv; - } - - fragOut << CMODELSHADERS_FRAG_GLSL_SV; - return fragOut.str(); -} - -uint64_t Shader_CModelShaders::BuildFragHash(const SModelShadersInfo& info) { - XXH64_state_t st; - XXH64_reset(&st, 0); - XXH64_update(&st, info.m_extension.shaderMacro, strlen(info.m_extension.shaderMacro)); - _Hash(st, info.m_material.shaderType); - _Hash(st, info.m_additionalInfo.srcFac); - _Hash(st, info.m_additionalInfo.dstFac); - for (const auto& chunk : info.m_material.chunks) { - if (auto passChunk = chunk.get_if()) { - _Hash(st, passChunk->alpha); - _Hash(st, passChunk->type); - } else if (auto clrChunk = chunk.get_if()) { - _Hash(st, clrChunk->type); - } - } - _Hash(st, info.m_tag.getAlphaTest()); - _Hash(st, info.m_extension.forceAlphaTest); - _Hash(st, info.m_extension.diffuseOnly); - _Hash(st, info.m_extension.noReflection); - _Hash(st, info.m_tag.getReflectionType()); - return XXH64_digest(&st); -} - -template <> -std::string StageObject_CModelShaders::BuildShader( - const SModelShadersInfo& in) { - return _BuildVS(in); -} -template <> -std::string StageObject_CModelShaders::BuildShader( - const SModelShadersInfo& in) { - return _BuildVS(in); -} -template <> -std::string StageObject_CModelShaders::BuildShader( - const SModelShadersInfo& in) { - return _BuildVS(in); -} - -template <> -std::string StageObject_CModelShaders::BuildShader( - const SModelShadersInfo& in) { - return _BuildFS(in); -} -template <> -std::string StageObject_CModelShaders::BuildShader( - const SModelShadersInfo& in) { - return _BuildFS(in); -} -template <> -std::string StageObject_CModelShaders::BuildShader( - const SModelShadersInfo& in) { - return _BuildFS(in); -} diff --git a/Shaders/shader_CModelShadersHLSL.cpp b/Shaders/shader_CModelShadersHLSL.cpp deleted file mode 100644 index 6faf7c05c..000000000 --- a/Shaders/shader_CModelShadersHLSL.cpp +++ /dev/null @@ -1,197 +0,0 @@ -#include -#include -#include -#include "shader_CModelShaders.hpp" -#include "Runtime/Graphics/Shaders/CModelShaders.hpp" - -extern "C" const uint8_t CMODELSHADERS_COMMON_HLSL[]; -extern "C" size_t CMODELSHADERS_COMMON_HLSL_SZ; -static std::string_view CMODELSHADERS_COMMON_HLSL_SV((char*)CMODELSHADERS_COMMON_HLSL, CMODELSHADERS_COMMON_HLSL_SZ); - -extern "C" const uint8_t CMODELSHADERS_VERT_HLSL[]; -extern "C" size_t CMODELSHADERS_VERT_HLSL_SZ; -static std::string_view CMODELSHADERS_VERT_HLSL_SV((char*)CMODELSHADERS_VERT_HLSL, CMODELSHADERS_VERT_HLSL_SZ); - -extern "C" const uint8_t CMODELSHADERS_FRAG_HLSL[]; -extern "C" size_t CMODELSHADERS_FRAG_HLSL_SZ; -static std::string_view CMODELSHADERS_FRAG_HLSL_SV((char*)CMODELSHADERS_FRAG_HLSL, CMODELSHADERS_FRAG_HLSL_SZ); - -using BlendMaterial = SModelShadersInfo::Material::BlendMaterial; -using TexCoordSource = BlendMaterial::TexCoordSource; - -static std::string_view EmitTexGenSource2(TexCoordSource src) { - switch (src) { - case TexCoordSource::Position: - return "objPos.xy"sv; - case TexCoordSource::Normal: - return "objNorm.xy"sv; - case TexCoordSource::Tex0: - return "v.uvIn[0]"sv; - case TexCoordSource::Tex1: - return "v.uvIn[1]"sv; - case TexCoordSource::Tex2: - return "v.uvIn[2]"sv; - case TexCoordSource::Tex3: - return "v.uvIn[3]"sv; - case TexCoordSource::Tex4: - return "v.uvIn[4]"sv; - case TexCoordSource::Tex5: - return "v.uvIn[5]"sv; - case TexCoordSource::Tex6: - return "v.uvIn[6]"sv; - case TexCoordSource::Tex7: - return "v.uvIn[7]"sv; - default: - assert(false && "Unknown source type"); - break; - } - return {}; -} - -static std::string_view EmitTexGenSource4(TexCoordSource src) { - switch (src) { - case TexCoordSource::Position: - return "float4(objPos.xyz, 1.0)"sv; - case TexCoordSource::Normal: - return "float4(objNorm.xyz, 1.0)"sv; - case TexCoordSource::Tex0: - return "float4(v.uvIn[0], 0.0, 1.0)"sv; - case TexCoordSource::Tex1: - return "float4(v.uvIn[1], 0.0, 1.0)"sv; - case TexCoordSource::Tex2: - return "float4(v.uvIn[2], 0.0, 1.0)"sv; - case TexCoordSource::Tex3: - return "float4(v.uvIn[3], 0.0, 1.0)"sv; - case TexCoordSource::Tex4: - return "float4(v.uvIn[4], 0.0, 1.0)"sv; - case TexCoordSource::Tex5: - return "float4(v.uvIn[5], 0.0, 1.0)"sv; - case TexCoordSource::Tex6: - return "float4(v.uvIn[6], 0.0, 1.0)"sv; - case TexCoordSource::Tex7: - return "float4(v.uvIn[7], 0.0, 1.0)"sv; - default: - assert(false && "Unknown source type"); - break; - } - return {}; -} - -static std::string _BuildVS(const SModelShadersInfo& info) { - std::stringstream vertOut; - vertOut << CMODELSHADERS_COMMON_HLSL_SV; - vertOut << "#define URDE_COL_SLOTS "sv << unsigned(info.m_tag.getColorCount()) << '\n'; - vertOut << "#define URDE_UV_SLOTS "sv << unsigned(info.m_tag.getUvCount()) << '\n'; - vertOut << "#define URDE_SKIN_SLOTS "sv << unsigned(info.m_tag.getSkinSlotCount()) << '\n'; - vertOut << "#define URDE_WEIGHT_SLOTS "sv << unsigned(info.m_tag.getWeightCount()) << '\n'; - - vertOut << "#define URDE_TCG_EXPR "sv; - using UVAnimType = BlendMaterial::UVAnimType; - using PassType = BlendMaterial::PassType; - int mtxIdx = 0; - for (const auto& chunk : info.m_material.chunks) { - if (auto passChunk = chunk.get_if()) { - if (passChunk->type != PassType::IndirectTex) { - std::string_view tpStr = BlendMaterial::PassTypeToString(passChunk->type); - if (passChunk->uvAnimType == UVAnimType::Invalid) { - vertOut << "vtf."sv << tpStr << "Uv = "sv << EmitTexGenSource2(passChunk->source) << ";"sv; - } else { - vertOut << "tmpProj = mul(texMtxs["sv << mtxIdx << "].postMtx, float4("sv << - (passChunk->shouldNormalizeUv() ? "normalize"sv : ""sv) << "(mul(texMtxs["sv << mtxIdx << "].mtx, "sv << - EmitTexGenSource4(passChunk->source) << ").xyz), 1.0));"sv << - "vtf."sv << tpStr << "Uv = (tmpProj / tmpProj.w).xy;"sv; - } - } - } else if (auto clrChunk = chunk.get_if()) { - std::string_view tpStr = BlendMaterial::PassTypeToString(clrChunk->type); - vertOut << "vtf."sv << tpStr << "Uv = float2(0.0,0.0);"sv; - } - } - if (!info.m_extension.noReflection && info.m_tag.getReflectionType() != hecl::Backend::ReflectionType::None) - vertOut << "vtf.dynReflectionUvs[0] = normalize(mul(indMtx, float4(objPos.xyz, 1.0)).xz) * float2(0.5, 0.5) + float2(0.5, 0.5);" - "vtf.dynReflectionUvs[1] = mul(reflectMtx, float4(objPos.xyz, 1.0)).xy;" - "vtf.dynReflectionAlpha = reflectAlpha;"; - - for (size_t i = 0; i < info.m_extension.texCount; ++i) { - const auto& extTex = info.m_extension.texs[i]; - if (extTex.mtxIdx == 0xff) - vertOut << "vtf.extUvs["sv << i << "] = "sv << EmitTexGenSource2(extTex.src) << ";"sv; - else - vertOut << "tmpProj = mul(texMtxs["sv << unsigned(extTex.mtxIdx) << "].postMtx, float4("sv << - (extTex.normalize ? "normalize"sv : ""sv) << "(mul(texMtxs["sv << unsigned(extTex.mtxIdx) << "].mtx, "sv << - EmitTexGenSource4(extTex.src) << ").xyz), 1.0));"sv << - "vtf.extUvs["sv << i << "] = (tmpProj / tmpProj.w).xy;"sv; - } - vertOut << '\n'; - - vertOut << CMODELSHADERS_VERT_HLSL_SV; - return vertOut.str(); -} - -static std::string _BuildFS(const SModelShadersInfo& info) { - std::stringstream fragOut; - fragOut << CMODELSHADERS_COMMON_HLSL_SV; - fragOut << "#define URDE_MAX_LIGHTS " _XSTR(URDE_MAX_LIGHTS) "\n"; - fragOut << "#define " << info.m_extension.shaderMacro << "\n"; - - using ShaderType = BlendMaterial::ShaderType; - switch (info.m_material.shaderType) { - case ShaderType::RetroShader: - fragOut << "#define RETRO_SHADER\n"; break; - case ShaderType::RetroDynamicShader: - fragOut << "#define RETRO_DYNAMIC_SHADER\n"; break; - case ShaderType::RetroDynamicAlphaShader: - fragOut << "#define RETRO_DYNAMIC_ALPHA_SHADER\n"; break; - case ShaderType::RetroDynamicCharacterShader: - fragOut << "#define RETRO_DYNAMIC_CHARACTER_SHADER\n"; break; - default: - assert(false && "Unknown shader type"); - break; - } - - fragOut << "#define BLEND_SRC_"sv << hecl::Backend::BlendFactorToDefine( - hecl::Backend::BlendFactor(info.m_additionalInfo.srcFac), hecl::Backend::BlendFactor::One) << '\n'; - fragOut << "#define BLEND_DST_"sv << hecl::Backend::BlendFactorToDefine( - hecl::Backend::BlendFactor(info.m_additionalInfo.dstFac), hecl::Backend::BlendFactor::Zero) << '\n'; - - using PassType = BlendMaterial::PassType; - for (const auto& chunk : info.m_material.chunks) { - if (auto passChunk = chunk.get_if()) { - if (passChunk->alpha) { - std::string_view tpStr = BlendMaterial::PassTypeToString(passChunk->type); - fragOut << "#define ALPHA_" << tpStr << '\n'; - } - } else if (auto clrChunk = chunk.get_if()) { - if (clrChunk->type == PassType::Alpha) - fragOut << "#define ALPHA_alpha\n"; - } - } - - if (info.m_tag.getAlphaTest() || info.m_extension.forceAlphaTest) - fragOut << "#define URDE_ALPHA_TEST\n"; - - if (info.m_extension.diffuseOnly) - fragOut << "#define URDE_DIFFUSE_ONLY\n"; - - if (!info.m_extension.noReflection) { - if (info.m_tag.getReflectionType() == hecl::Backend::ReflectionType::Indirect) - fragOut << "#define URDE_REFLECTION_INDIRECT\n"sv; - else if (info.m_tag.getReflectionType() == hecl::Backend::ReflectionType::Simple) - fragOut << "#define URDE_REFLECTION_SIMPLE\n"sv; - } - - fragOut << CMODELSHADERS_FRAG_HLSL_SV; - return fragOut.str(); -} - -template <> -std::string StageObject_CModelShaders::BuildShader( - const SModelShadersInfo& in) { - return _BuildVS(in); -} - -template <> -std::string StageObject_CModelShaders::BuildShader( - const SModelShadersInfo& in) { - return _BuildFS(in); -} diff --git a/Shaders/shader_CModelShadersMetal.cpp b/Shaders/shader_CModelShadersMetal.cpp deleted file mode 100644 index a7cb6eeaf..000000000 --- a/Shaders/shader_CModelShadersMetal.cpp +++ /dev/null @@ -1,218 +0,0 @@ -#include -#include -#include -#include "shader_CModelShaders.hpp" -#include "Runtime/Graphics/Shaders/CModelShaders.hpp" - -extern "C" const uint8_t CMODELSHADERS_COMMON_METAL[]; -extern "C" size_t CMODELSHADERS_COMMON_METAL_SZ; -static std::string_view CMODELSHADERS_COMMON_METAL_SV((char*)CMODELSHADERS_COMMON_METAL, CMODELSHADERS_COMMON_METAL_SZ); - -extern "C" const uint8_t CMODELSHADERS_VERT_METAL[]; -extern "C" size_t CMODELSHADERS_VERT_METAL_SZ; -static std::string_view CMODELSHADERS_VERT_METAL_SV((char*)CMODELSHADERS_VERT_METAL, CMODELSHADERS_VERT_METAL_SZ); - -extern "C" const uint8_t CMODELSHADERS_FRAG_METAL[]; -extern "C" size_t CMODELSHADERS_FRAG_METAL_SZ; -static std::string_view CMODELSHADERS_FRAG_METAL_SV((char*)CMODELSHADERS_FRAG_METAL, CMODELSHADERS_FRAG_METAL_SZ); - -using BlendMaterial = SModelShadersInfo::Material::BlendMaterial; -using TexCoordSource = BlendMaterial::TexCoordSource; - -static std::string_view EmitTexGenSource2(TexCoordSource src) { - switch (src) { - case TexCoordSource::Position: - return "objPos.xy"sv; - case TexCoordSource::Normal: - return "objNorm.xy"sv; - case TexCoordSource::Tex0: - return "v.uvIn0"sv; - case TexCoordSource::Tex1: - return "v.uvIn1"sv; - case TexCoordSource::Tex2: - return "v.uvIn2"sv; - case TexCoordSource::Tex3: - return "v.uvIn3"sv; - case TexCoordSource::Tex4: - return "v.uvIn4"sv; - case TexCoordSource::Tex5: - return "v.uvIn5"sv; - case TexCoordSource::Tex6: - return "v.uvIn6"sv; - case TexCoordSource::Tex7: - return "v.uvIn7"sv; - default: - assert(false && "Unknown source type"); - break; - } - return {}; -} - -static std::string_view EmitTexGenSource4(TexCoordSource src) { - switch (src) { - case TexCoordSource::Position: - return "float4(objPos.xyz, 1.0)"sv; - case TexCoordSource::Normal: - return "float4(objNorm.xyz, 1.0)"sv; - case TexCoordSource::Tex0: - return "float4(v.uvIn0, 0.0, 1.0)"sv; - case TexCoordSource::Tex1: - return "float4(v.uvIn1, 0.0, 1.0)"sv; - case TexCoordSource::Tex2: - return "float4(v.uvIn2, 0.0, 1.0)"sv; - case TexCoordSource::Tex3: - return "float4(v.uvIn3, 0.0, 1.0)"sv; - case TexCoordSource::Tex4: - return "float4(v.uvIn4, 0.0, 1.0)"sv; - case TexCoordSource::Tex5: - return "float4(v.uvIn5, 0.0, 1.0)"sv; - case TexCoordSource::Tex6: - return "float4(v.uvIn6, 0.0, 1.0)"sv; - case TexCoordSource::Tex7: - return "float4(v.uvIn7, 0.0, 1.0)"sv; - default: - assert(false && "Unknown source type"); - break; - } - return {}; -} - -static std::string _BuildVS(const SModelShadersInfo& info) { - std::stringstream vertOut; - vertOut << CMODELSHADERS_COMMON_METAL_SV; - vertOut << "#define URDE_COL_SLOTS "sv << unsigned(info.m_tag.getColorCount()) << '\n'; - vertOut << "#define URDE_UV_SLOTS "sv << unsigned(info.m_tag.getUvCount()) << '\n'; - vertOut << "#define URDE_SKIN_SLOTS "sv << unsigned(info.m_tag.getSkinSlotCount()) << '\n'; - vertOut << "#define URDE_WEIGHT_SLOTS "sv << unsigned(info.m_tag.getWeightCount()) << '\n'; - - vertOut << "#define URDE_VERT_DATA_DECL struct VertData {" - "float3 posIn [[ attribute(0) ]];" - "float3 normIn [[ attribute(1) ]];"sv; - for (unsigned i = 0; i < unsigned(info.m_tag.getColorCount()); ++i) - vertOut << "float4 colIn"sv << i << " [[ attribute("sv << 2 + i << ") ]];"sv; - for (unsigned i = 0; i < unsigned(info.m_tag.getUvCount()); ++i) - vertOut << "float2 uvIn"sv << i << " [[ attribute("sv << 2 + info.m_tag.getColorCount() + i << ") ]];"sv; - for (unsigned i = 0; i < unsigned(info.m_tag.getWeightCount()); ++i) - vertOut << "float4 weightIn"sv << i << " [[ attribute("sv << - 2 + info.m_tag.getColorCount() + info.m_tag.getUvCount() + i << ") ]];"sv; - vertOut << "};\n"sv; - - if (info.m_tag.getSkinSlotCount()) { - vertOut << "#define URDE_WEIGHTING_EXPR "sv; - for (unsigned i = 0; i < info.m_tag.getSkinSlotCount(); ++i) { - vertOut << "objPos += (vu.objs["sv << i << "] * float4(v.posIn, 1.0)) * v.weightIn"sv << i / 4 << "["sv << i % 4 <<"];"sv; - vertOut << "objNorm += (vu.objsInv["sv << i << "] * float4(v.normIn, 1.0)) * v.weightIn"sv << i / 4 << "["sv << i % 4 <<"];"sv; - } - vertOut << '\n'; - } - - vertOut << "#define URDE_TCG_EXPR "sv; - using UVAnimType = BlendMaterial::UVAnimType; - using PassType = BlendMaterial::PassType; - int mtxIdx = 0; - for (const auto& chunk : info.m_material.chunks) { - if (auto passChunk = chunk.get_if()) { - if (passChunk->type != PassType::IndirectTex) { - std::string_view tpStr = BlendMaterial::PassTypeToString(passChunk->type); - if (passChunk->uvAnimType == UVAnimType::Invalid) { - vertOut << "vtf."sv << tpStr << "Uv = "sv << EmitTexGenSource2(passChunk->source) << ";"sv; - } else { - vertOut << "tmpProj = tu.texMtxs["sv << mtxIdx << "].postMtx * float4("sv << - (passChunk->shouldNormalizeUv() ? "normalize"sv : ""sv) << "((tu.texMtxs["sv << mtxIdx << "].mtx * "sv << - EmitTexGenSource4(passChunk->source) << ").xyz), 1.0);"sv << - "vtf."sv << tpStr << "Uv = (tmpProj / tmpProj.w).xy;"sv; - } - } - } else if (auto clrChunk = chunk.get_if()) { - std::string_view tpStr = BlendMaterial::PassTypeToString(clrChunk->type); - vertOut << "vtf."sv << tpStr << "Uv = float2(0.0,0.0);"sv; - } - } - if (!info.m_extension.noReflection && info.m_tag.getReflectionType() != hecl::Backend::ReflectionType::None) - vertOut << "vtf.dynReflectionUvs0 = normalize((ru.indMtx * float4(objPos.xyz, 1.0)).xz) * float2(0.5, 0.5) + float2(0.5, 0.5);" - "vtf.dynReflectionUvs1 = (ru.reflectMtx * float4(objPos.xyz, 1.0)).xy;" - "vtf.dynReflectionAlpha = ru.reflectAlpha;"; - - for (size_t i = 0; i < info.m_extension.texCount; ++i) { - const auto& extTex = info.m_extension.texs[i]; - if (extTex.mtxIdx == 0xff) - vertOut << "vtf.extUvs"sv << i << " = "sv << EmitTexGenSource2(extTex.src) << ";"sv; - else - vertOut << "tmpProj = tu.texMtxs["sv << unsigned(extTex.mtxIdx) << "].postMtx * float4("sv << - (extTex.normalize ? "normalize"sv : ""sv) << "((tu.texMtxs["sv << unsigned(extTex.mtxIdx) << "].mtx * "sv << - EmitTexGenSource4(extTex.src) << ").xyz), 1.0);"sv << - "vtf.extUvs"sv << i << " = (tmpProj / tmpProj.w).xy;"sv; - } - vertOut << '\n'; - - vertOut << CMODELSHADERS_VERT_METAL_SV; - return vertOut.str(); -} - -static std::string _BuildFS(const SModelShadersInfo& info) { - std::stringstream fragOut; - fragOut << CMODELSHADERS_COMMON_METAL_SV; - fragOut << "#define URDE_MAX_LIGHTS " _XSTR(URDE_MAX_LIGHTS) "\n"; - fragOut << "#define " << info.m_extension.shaderMacro << "\n"; - - using ShaderType = BlendMaterial::ShaderType; - switch (info.m_material.shaderType) { - case ShaderType::RetroShader: - fragOut << "#define RETRO_SHADER\n"; break; - case ShaderType::RetroDynamicShader: - fragOut << "#define RETRO_DYNAMIC_SHADER\n"; break; - case ShaderType::RetroDynamicAlphaShader: - fragOut << "#define RETRO_DYNAMIC_ALPHA_SHADER\n"; break; - case ShaderType::RetroDynamicCharacterShader: - fragOut << "#define RETRO_DYNAMIC_CHARACTER_SHADER\n"; break; - default: - assert(false && "Unknown shader type"); - break; - } - - fragOut << "#define BLEND_SRC_"sv << hecl::Backend::BlendFactorToDefine( - hecl::Backend::BlendFactor(info.m_additionalInfo.srcFac), hecl::Backend::BlendFactor::One) << '\n'; - fragOut << "#define BLEND_DST_"sv << hecl::Backend::BlendFactorToDefine( - hecl::Backend::BlendFactor(info.m_additionalInfo.dstFac), hecl::Backend::BlendFactor::Zero) << '\n'; - - using PassType = BlendMaterial::PassType; - for (const auto& chunk : info.m_material.chunks) { - if (auto passChunk = chunk.get_if()) { - if (passChunk->alpha) { - std::string_view tpStr = BlendMaterial::PassTypeToString(passChunk->type); - fragOut << "#define ALPHA_" << tpStr << '\n'; - } - } else if (auto clrChunk = chunk.get_if()) { - if (clrChunk->type == PassType::Alpha) - fragOut << "#define ALPHA_alpha\n"; - } - } - - if (info.m_tag.getAlphaTest() || info.m_extension.forceAlphaTest) - fragOut << "#define URDE_ALPHA_TEST\n"; - - if (info.m_extension.diffuseOnly) - fragOut << "#define URDE_DIFFUSE_ONLY\n"; - - if (!info.m_extension.noReflection) { - if (info.m_tag.getReflectionType() == hecl::Backend::ReflectionType::Indirect) - fragOut << "#define URDE_REFLECTION_INDIRECT\n"sv; - else if (info.m_tag.getReflectionType() == hecl::Backend::ReflectionType::Simple) - fragOut << "#define URDE_REFLECTION_SIMPLE\n"sv; - } - - fragOut << CMODELSHADERS_FRAG_METAL_SV; - return fragOut.str(); -} - -template <> -std::string StageObject_CModelShaders::BuildShader( - const SModelShadersInfo& in) { - return _BuildVS(in); -} - -template <> -std::string StageObject_CModelShaders::BuildShader( - const SModelShadersInfo& in) { - return _BuildFS(in); -} diff --git a/extern/CMakeLists.txt b/extern/CMakeLists.txt index 843b584f0..9a65d862b 100644 --- a/extern/CMakeLists.txt +++ b/extern/CMakeLists.txt @@ -5,7 +5,6 @@ if (CMAKE_SYSTEM_NAME STREQUAL Linux) set(DAWN_USE_WAYLAND ON CACHE BOOL "Enable support for Wayland surface" FORCE) endif () -set(AURORA_NATIVE_MATRIX ON CACHE BOOL "Assume OpenGL-layout matrices, disables transposing" FORCE) add_subdirectory(aurora) if (NOT TARGET spdlog) diff --git a/extern/aurora b/extern/aurora index 3b56e337c..a600b0b84 160000 --- a/extern/aurora +++ b/extern/aurora @@ -1 +1 @@ -Subproject commit 3b56e337c08a1dd4946c226298011364c319c7a2 +Subproject commit a600b0b84c08d1addee1f03a584d9f83d4a3a102 diff --git a/extern/musyx b/extern/musyx index de1344911..37e8ecd4e 160000 --- a/extern/musyx +++ b/extern/musyx @@ -1 +1 @@ -Subproject commit de1344911bd846ef23b41061bd389631f0a21f27 +Subproject commit 37e8ecd4e6503e90b97ea81cd7d669357861d501 diff --git a/extern/zeus b/extern/zeus index d63744eb0..655ca9e03 160000 --- a/extern/zeus +++ b/extern/zeus @@ -1 +1 @@ -Subproject commit d63744eb078ba4ee18c551b18097225115db2473 +Subproject commit 655ca9e0360bd638f9f5e5fb57b8acf71eec9a61 diff --git a/imgui/ImGuiEngine.cpp b/imgui/ImGuiEngine.cpp index f5452dae9..4f15bf2a2 100644 --- a/imgui/ImGuiEngine.cpp +++ b/imgui/ImGuiEngine.cpp @@ -34,9 +34,9 @@ void ImGuiEngine_Initialize(float scale) { auto* fontData = ImGui::MemAlloc(NOTO_MONO_FONT_DECOMPRESSED_SZ); { - auto stream = std::make_unique( - static_cast(NOTO_MONO_FONT), NOTO_MONO_FONT_SZ, metaforce::CMemoryInStream::EOwnerShip::NotOwned); - metaforce::CZipInputStream zipInputStream{std::move(stream)}; + auto stream = std::make_unique(static_cast(NOTO_MONO_FONT), NOTO_MONO_FONT_SZ, + CMemoryInStream::EOwnerShip::NotOwned); + CZipInputStream zipInputStream{std::move(stream)}; zipInputStream.Get(static_cast(fontData), NOTO_MONO_FONT_DECOMPRESSED_SZ); } @@ -135,8 +135,8 @@ void ImGuiEngine_Initialize(float scale) { Icon GetIcon() { int iconWidth = 0; int iconHeight = 0; - auto* data = stbi_load_from_memory(static_cast(METAFORCE_ICON), int(METAFORCE_ICON_SZ), &iconWidth, - &iconHeight, nullptr, 4); + auto* data = + stbi_load_from_memory(METAFORCE_ICON, static_cast(METAFORCE_ICON_SZ), &iconWidth, &iconHeight, nullptr, 4); size_t size = static_cast(iconWidth) * static_cast(iconHeight) * 4; auto ptr = std::make_unique(size); memcpy(ptr.get(), data, size);