diff --git a/Runtime/Graphics/CBooRenderer.cpp b/Runtime/Graphics/CBooRenderer.cpp index a9be99827..04eaa58de 100644 --- a/Runtime/Graphics/CBooRenderer.cpp +++ b/Runtime/Graphics/CBooRenderer.cpp @@ -1051,6 +1051,10 @@ void CBooRenderer::SetDebugOption(EDebugOption, int) {} void CBooRenderer::BeginScene() { CGraphics::SetViewport(0, 0, g_Viewport.x8_width, g_Viewport.xc_height); + 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_ProjAspect, 1.f, 4096.f); CGraphics::SetModelMatrix(zeus::CTransform()); #if 0 @@ -1065,6 +1069,8 @@ void CBooRenderer::BeginScene() { if (!x318_31_persistRGBA6) x318_26_requestRGBA6 = false; // GXSetPixelFmt(x318_27_currentRGBA6); + CGraphics::SetAlphaUpdate(true); + // GXSetDstAlpha(true, 0); CGraphics::BeginScene(); m_nextFogVolumePlaneShader = m_fogVolumePlaneShaders.begin(); m_nextFogVolumeFilter = m_fogVolumeFilters.begin(); diff --git a/Runtime/Graphics/CBooRenderer.hpp b/Runtime/Graphics/CBooRenderer.hpp index 96935ba9c..7ad7eecf7 100644 --- a/Runtime/Graphics/CBooRenderer.hpp +++ b/Runtime/Graphics/CBooRenderer.hpp @@ -40,13 +40,10 @@ class IObjectStore; class Buckets; -enum class EWorldShadowMode { - None, - WorldOnActorShadow, - BallOnWorldShadow, - BallOnWorldIds, - MAX -}; +enum class EWorldShadowMode { None, WorldOnActorShadow, BallOnWorldShadow, BallOnWorldIds, MAX }; + +constexpr u32 skBallShadowIdSize = 64; +constexpr u32 skReflectionDrawTargetSize = 256; class CBooRenderer final : public IRenderer { friend class CBooModel; @@ -128,9 +125,6 @@ class CBooRenderer final : public IRenderer { hsh::owner> m_scanLinesEvenVBO; hsh::owner> m_scanLinesOddVBO; - uint32_t m_ballShadowIdW = 64; - uint32_t m_ballShadowIdH = 64; - CRandom16 x2a8_thermalRand; std::list x2ac_fogVolumes; std::list m_fogVolumePlaneShaders; @@ -202,8 +196,8 @@ public: 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 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; @@ -224,15 +218,35 @@ public: 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 SetDepthReadWrite(bool test, bool write) override { + CGraphics::SetDepthWriteMode(test, ERglEnum::LEqual, write); + } + void SetBlendMode_AdditiveAlpha() override { + CGraphics::SetBlendMode(ERglBlendMode::Blend, ERglBlendFactor::SrcAlpha, ERglBlendFactor::One, ERglLogicOp::Clear); + } + void SetBlendMode_AlphaBlended() override { + CGraphics::SetBlendMode(ERglBlendMode::Blend, ERglBlendFactor::SrcAlpha, ERglBlendFactor::InvSrcAlpha, + ERglLogicOp::Clear); + } + void SetBlendMode_NoColorWrite() override { + CGraphics::SetBlendMode(ERglBlendMode::Blend, ERglBlendFactor::Zero, ERglBlendFactor::One, ERglLogicOp::Clear); + } + void SetBlendMode_ColorMultiply() override { + CGraphics::SetBlendMode(ERglBlendMode::Blend, ERglBlendFactor::Zero, ERglBlendFactor::SrcColor, ERglLogicOp::Clear); + } + void SetBlendMode_InvertDst() override { + CGraphics::SetBlendMode(ERglBlendMode::Blend, ERglBlendFactor::InvSrcColor, ERglBlendFactor::Zero, + ERglLogicOp::Clear); + } + void SetBlendMode_InvertSrc() override { + CGraphics::SetBlendMode(ERglBlendMode::Logic, ERglBlendFactor::One, ERglBlendFactor::Zero, ERglLogicOp::InvCopy); + } + void SetBlendMode_Replace() override { + CGraphics::SetBlendMode(ERglBlendMode::Blend, ERglBlendFactor::One, ERglBlendFactor::Zero, ERglLogicOp::Clear); + } + void SetBlendMode_AdditiveDestColor() override { + CGraphics::SetBlendMode(ERglBlendMode::Blend, ERglBlendFactor::SrcColor, ERglBlendFactor::One, ERglLogicOp::Clear); + } void SetDebugOption(EDebugOption, int) override; void BeginScene() override; void EndScene() override; diff --git a/Runtime/Graphics/CGraphics.cpp b/Runtime/Graphics/CGraphics.cpp index 39b40e27d..d2fca99bc 100644 --- a/Runtime/Graphics/CGraphics.cpp +++ b/Runtime/Graphics/CGraphics.cpp @@ -10,6 +10,18 @@ namespace urde { +/// GX global state +ERglEnum gx_DepthTest; +bool gx_DepthWrite; +ERglBlendMode gx_BlendMode; +ERglBlendFactor gx_BlendSrcFac; +ERglBlendFactor gx_BlendDstFac; +ERglLogicOp gx_BlendOp; +bool gx_AlphaWrite; +ERglCullMode gx_CullMode; +std::array gx_AmbientColors; +/// End GX state + CGraphics::CProjectionState CGraphics::g_Proj; CGraphics::CFogState CGraphics::g_Fog; std::array CGraphics::g_ColorRegs{}; @@ -77,7 +89,8 @@ void CGraphics::SetLightState(ERglLightBits lightState) { } void CGraphics::SetAmbientColor(const zeus::CColor& col) { - // TODO: set for real + gx_AmbientColors[0] = col; + gx_AmbientColors[1] = col; } void CGraphics::SetFog(ERglFogMode mode, float startz, float endz, const zeus::CColor& color) { @@ -96,11 +109,22 @@ void CGraphics::SetFog(ERglFogMode mode, float startz, float endz, const zeus::C } } -void CGraphics::SetDepthWriteMode(bool test, ERglEnum comp, bool write) {} +void CGraphics::SetDepthWriteMode(bool test, ERglEnum comp, bool write) { + gx_DepthTest = test ? ERglEnum::Always : comp; + gx_DepthWrite = write; +} -void CGraphics::SetBlendMode(ERglBlendMode, ERglBlendFactor, ERglBlendFactor, ERglLogicOp) {} +void CGraphics::SetBlendMode(ERglBlendMode type, ERglBlendFactor srcFac, ERglBlendFactor dstFac, ERglLogicOp op) { + gx_BlendMode = type; + gx_BlendSrcFac = srcFac; + gx_BlendDstFac = dstFac; + gx_BlendOp = op; +} -void CGraphics::SetCullMode(ERglCullMode) {} +void CGraphics::SetCullMode(ERglCullMode mode) { gx_CullMode = mode; } + +// URDE addition (GXSetAlphaUpdate) +void CGraphics::SetAlphaUpdate(bool value) { gx_AlphaWrite = value; } void CGraphics::BeginScene() {} @@ -441,4 +465,3 @@ const CTevCombiners::CTevPass CGraphics::sTevPass805a6084( {GX::TevColorArg::CC_ZERO, GX::TevColorArg::CC_CPREV, GX::TevColorArg::CC_APREV, GX::TevColorArg::CC_ZERO}, {GX::TevAlphaArg::CA_ZERO, GX::TevAlphaArg::CA_ZERO, GX::TevAlphaArg::CA_ZERO, GX::TevAlphaArg::CA_APREV}); } // namespace urde - diff --git a/Runtime/Graphics/CGraphics.hpp b/Runtime/Graphics/CGraphics.hpp index 016ec2d3c..8ae583688 100644 --- a/Runtime/Graphics/CGraphics.hpp +++ b/Runtime/Graphics/CGraphics.hpp @@ -112,6 +112,19 @@ struct SViewport { float aspect; }; +/// GX global state +extern ERglEnum gx_DepthTest; +extern bool gx_DepthWrite; +extern ERglBlendMode gx_BlendMode; +extern ERglBlendFactor gx_BlendSrcFac; +extern ERglBlendFactor gx_BlendDstFac; +extern ERglLogicOp gx_BlendOp; +extern bool gx_AlphaWrite; +extern ERglCullMode gx_CullMode; +// GX_COLOR0A0 & GX_COLOR1A1 +extern std::array gx_AmbientColors; +/// End GX state + extern SViewport g_Viewport; struct SClipScreenRect { @@ -283,8 +296,9 @@ public: static void SetAmbientColor(const zeus::CColor& col); static void SetFog(ERglFogMode mode, float startz, float endz, const zeus::CColor& color); static void SetDepthWriteMode(bool test, ERglEnum comp, bool write); - static void SetBlendMode(ERglBlendMode, ERglBlendFactor, ERglBlendFactor, ERglLogicOp); - static void SetCullMode(ERglCullMode); + static void SetBlendMode(ERglBlendMode type, ERglBlendFactor srcFac, ERglBlendFactor dstFac, ERglLogicOp op); + static void SetCullMode(ERglCullMode mode); + static void SetAlphaUpdate(bool value); static void BeginScene(); static void EndScene(); static void SetAlphaCompare(ERglAlphaFunc comp0, u8 ref0, ERglAlphaOp op, ERglAlphaFunc comp1, u8 ref1); @@ -466,11 +480,11 @@ using SubtractAttachmentExt = hsh::pipeline::color_attachment< template using InvDstMultiplyAttachmentExt = -hsh::pipeline::color_attachment::Factor, - AlphaDst::Factor, hsh::Add, - hsh::ColorComponentFlags( - hsh::CC_Red | hsh::CC_Green | hsh::CC_Blue | - (Alpha != AlphaMode::NoAlpha ? hsh::CC_Alpha : hsh::ColorComponentFlags()))>; + hsh::pipeline::color_attachment::Factor, + AlphaDst::Factor, hsh::Add, + hsh::ColorComponentFlags( + hsh::CC_Red | hsh::CC_Green | hsh::CC_Blue | + (Alpha != AlphaMode::NoAlpha ? hsh::CC_Alpha : hsh::ColorComponentFlags()))>; template using NoColorAttachmentExt = @@ -520,6 +534,90 @@ using NoColorAttachment = NoColorAttachmentExt +struct ERglCullModeAttachmentExt { + using type = hsh::pipeline::cull_mode<>; +}; +template <> +struct ERglCullModeAttachmentExt { + using type = hsh::pipeline::cull_mode; +}; +template <> +struct ERglCullModeAttachmentExt { + using type = hsh::pipeline::cull_mode; +}; +template <> +struct ERglCullModeAttachmentExt { + using type = hsh::pipeline::cull_mode; +}; +template <> +struct ERglCullModeAttachmentExt { + using type = hsh::pipeline::cull_mode; +}; +template +using ERglCullModeAttachment = typename ERglCullModeAttachmentExt::type; + +template +struct ERglDepthCompareAttachmentExt { + using type = hsh::pipeline::depth_compare<>; +}; +template <> +struct ERglDepthCompareAttachmentExt { + using type = hsh::pipeline::depth_compare; +}; +template <> +struct ERglDepthCompareAttachmentExt { + using type = hsh::pipeline::depth_compare; +}; +template <> +struct ERglDepthCompareAttachmentExt { + using type = hsh::pipeline::depth_compare; +}; +template <> +struct ERglDepthCompareAttachmentExt { + using type = hsh::pipeline::depth_compare; +}; +template <> +struct ERglDepthCompareAttachmentExt { + using type = hsh::pipeline::depth_compare; +}; +template <> +struct ERglDepthCompareAttachmentExt { + using type = hsh::pipeline::depth_compare; +}; +template <> +struct ERglDepthCompareAttachmentExt { + using type = hsh::pipeline::depth_compare; +}; +template <> +struct ERglDepthCompareAttachmentExt { + using type = hsh::pipeline::depth_compare; +}; +template +using ERglDepthCompareAttachment = typename ERglDepthCompareAttachmentExt::type; + +template +struct ERglBlendModeAttachmentExt { + using type = hsh::pipeline::color_attachment<>; +}; +template +struct ERglBlendModeAttachmentExt { + using type = hsh::pipeline::color_attachment< + hsh::SrcAlpha, hsh::InvSrcAlpha, hsh::Add, hsh::SrcAlpha, hsh::InvSrcAlpha, hsh::Add, + hsh::ColorComponentFlags(hsh::CC_Red | hsh::CC_Green | hsh::CC_Blue | + (AlphaWrite ? hsh::CC_Alpha : hsh::ColorComponentFlags()))>; +}; +template +struct ERglBlendModeAttachmentExt { + using type = hsh::pipeline::color_attachment; +}; +template +using ERglBlendModeAttachment = typename ERglBlendModeAttachmentExt::type; + #ifdef BOO_GRAPHICS_DEBUG_GROUPS class GraphicsDebugGroup { /* Stack only */ diff --git a/Runtime/Graphics/IRenderer.hpp b/Runtime/Graphics/IRenderer.hpp index 4817183ca..2555bf064 100644 --- a/Runtime/Graphics/IRenderer.hpp +++ b/Runtime/Graphics/IRenderer.hpp @@ -59,15 +59,15 @@ public: virtual std::pair SetViewportOrtho(bool centered, float znear, float zfar) = 0; virtual void SetClippingPlanes(const zeus::CFrustum& frustum) = 0; virtual void SetViewport(int left, int bottom, int width, int height) = 0; - // virtual void SetDepthReadWrite(bool, bool)=0; - // virtual void SetBlendMode_AdditiveAlpha()=0; - // virtual void SetBlendMode_AlphaBlended()=0; - // virtual void SetBlendMode_NoColorWrite()=0; - // virtual void SetBlendMode_ColorMultiply()=0; - // virtual void SetBlendMode_InvertDst()=0; - // virtual void SetBlendMode_InvertSrc()=0; - // virtual void SetBlendMode_Replace()=0; - // virtual void SetBlendMode_AdditiveDestColor()=0; + virtual void SetDepthReadWrite(bool test, bool write) = 0; + virtual void SetBlendMode_AdditiveAlpha() = 0; + virtual void SetBlendMode_AlphaBlended() = 0; + virtual void SetBlendMode_NoColorWrite() = 0; + virtual void SetBlendMode_ColorMultiply() = 0; + virtual void SetBlendMode_InvertDst() = 0; + virtual void SetBlendMode_InvertSrc() = 0; + virtual void SetBlendMode_Replace() = 0; + virtual void SetBlendMode_AdditiveDestColor() = 0; virtual void SetDebugOption(EDebugOption, int) = 0; virtual void BeginScene() = 0; virtual void EndScene() = 0; diff --git a/Runtime/Graphics/Shaders/CAABoxShader.cpp b/Runtime/Graphics/Shaders/CAABoxShader.cpp index 7712a0e82..568443278 100644 --- a/Runtime/Graphics/Shaders/CAABoxShader.cpp +++ b/Runtime/Graphics/Shaders/CAABoxShader.cpp @@ -9,19 +9,20 @@ namespace urde { using namespace hsh::pipeline; -template +template struct CAABoxShaderPipeline -: pipeline, std::conditional_t, BlendAttachment<>>, - depth_compare> { +: pipeline, ERglBlendModeAttachment, + ERglCullModeAttachment, ERglDepthCompareAttachment, depth_write> { CAABoxShaderPipeline(hsh::vertex_buffer vbo, hsh::uniform_buffer uniBuf) { this->position = uniBuf->m_xf * hsh::float4(vbo->m_pos, 1.f); this->color_out[0] = uniBuf->m_color; } }; -template struct CAABoxShaderPipeline; -template struct CAABoxShaderPipeline; +template struct CAABoxShaderPipeline; -CAABoxShader::CAABoxShader(const zeus::CAABox& aabb, bool zOnly) { +CAABoxShader::CAABoxShader(const zeus::CAABox& aabb) { const std::array verts{{ {{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()}}, @@ -50,8 +51,8 @@ CAABoxShader::CAABoxShader(const zeus::CAABox& aabb, bool zOnly) { m_vbo = hsh::create_vertex_buffer(verts); m_uniBuf = hsh::create_dynamic_uniform_buffer(); - - m_dataBind.hsh_bind(CAABoxShaderPipeline(m_vbo.get(), m_uniBuf.get())); + m_dataBind.hsh_bind(CAABoxShaderPipeline(m_vbo.get(), m_uniBuf.get())); } void CAABoxShader::draw(const zeus::CColor& color) { diff --git a/Runtime/Graphics/Shaders/CAABoxShader.hpp b/Runtime/Graphics/Shaders/CAABoxShader.hpp index 251a238d1..f53bee3ce 100644 --- a/Runtime/Graphics/Shaders/CAABoxShader.hpp +++ b/Runtime/Graphics/Shaders/CAABoxShader.hpp @@ -25,7 +25,7 @@ private: Uniform m_uniform{}; public: - CAABoxShader(const zeus::CAABox& aabb, bool zOnly = false); + CAABoxShader(const zeus::CAABox& aabb); void draw(const zeus::CColor& color); }; diff --git a/Runtime/Weapon/CPhazonBeam.cpp b/Runtime/Weapon/CPhazonBeam.cpp index 500f45bfc..7ef082a4a 100644 --- a/Runtime/Weapon/CPhazonBeam.cpp +++ b/Runtime/Weapon/CPhazonBeam.cpp @@ -18,8 +18,8 @@ CPhazonBeam::CPhazonBeam(CAssetId characterId, EWeaponType type, TUniqueId playe zeus::CVector3f(0.14664599f, 0.64619601f, 0.14909725f) * scale.y()) , x250_aaBoxTranslate(zeus::CVector3f(-0.0625f, 0.f, -0.09375f) * scale.y(), zeus::CVector3f(0.0625f, -0.25f, 0.09375f) * scale.y()) -, m_aaboxShaderScale(x238_aaBoxScale, true) -, m_aaboxShaderTranslate(x250_aaBoxTranslate, true) { +, m_aaboxShaderScale(x238_aaBoxScale) +, m_aaboxShaderTranslate(x250_aaBoxTranslate) { x21c_phazonVeins = g_SimplePool->GetObj("PhazonVeins"); x228_phazon2nd1 = g_SimplePool->GetObj("Phazon2nd_1"); } @@ -166,12 +166,18 @@ 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); + g_Renderer->SetBlendMode_AlphaBlended(); + CGraphics::SetCullMode(ERglCullMode::None); + m_aaboxShaderScale.draw(zeus::CColor{1.f, 1.f, 1.f, 0.f}); + CGraphics::SetCullMode(ERglCullMode::Front); } void CPhazonBeam::DrawClipTranslateCube() { // Render AABB as completely transparent object, only modifying Z-buffer - m_aaboxShaderTranslate.draw(zeus::skClear); + g_Renderer->SetBlendMode_AlphaBlended(); + CGraphics::SetCullMode(ERglCullMode::None); + m_aaboxShaderTranslate.draw(zeus::CColor{1.f, 1.f, 1.f, 0.f}); + CGraphics::SetCullMode(ERglCullMode::Front); } void CPhazonBeam::Draw(bool drawSuitArm, const CStateManager& mgr, const zeus::CTransform& xf, const CModelFlags& flags, diff --git a/Runtime/Weapon/CPlayerGun.cpp b/Runtime/Weapon/CPlayerGun.cpp index 48de6f3fb..eacb4a4f2 100644 --- a/Runtime/Weapon/CPlayerGun.cpp +++ b/Runtime/Weapon/CPlayerGun.cpp @@ -132,7 +132,7 @@ CPlayerGun::CPlayerGun(TUniqueId playerId) , x6c8_hologramClipCube(zeus::CVector3f(-0.29329199f, 0.f, -0.2481945f), zeus::CVector3f(0.29329199f, 1.292392f, 0.2481945f)) , x6e0_rightHandModel(CAnimRes(g_tweakGunRes->xc_rightHand, 0, zeus::CVector3f(3.f), 0, true)) -, m_aaboxShader(x6c8_hologramClipCube, true) { +, m_aaboxShader(x6c8_hologramClipCube) { x354_bombFuseTime = g_tweakPlayerGun->GetBombFuseTime(); x358_bombDropDelayTime = g_tweakPlayerGun->GetBombDropDelayTime(); x668_aimVerticalSpeed = g_tweakPlayerGun->GetAimVerticalSpeed(); @@ -2134,7 +2134,10 @@ void CPlayerGun::DrawScreenTex(float z) { void CPlayerGun::DrawClipCube(const zeus::CAABox& aabb) { // Render AABB as completely transparent object, only modifying Z-buffer // AABB has already been set in constructor (since it's constant) - m_aaboxShader.draw(zeus::skClear); + g_Renderer->SetBlendMode_AlphaBlended(); + CGraphics::SetCullMode(ERglCullMode::None); + m_aaboxShader.draw(zeus::CColor{1.f, 1.f, 1.f, 0.f}); + CGraphics::SetCullMode(ERglCullMode::Front); } void CPlayerGun::Render(const CStateManager& mgr, const zeus::CVector3f& pos, const CModelFlags& flags) {