diff --git a/SilentPatch/dllmain.cpp b/SilentPatch/dllmain.cpp index 65ba324..6e7cd61 100644 --- a/SilentPatch/dllmain.cpp +++ b/SilentPatch/dllmain.cpp @@ -196,8 +196,7 @@ RpMaterial* AlphaTest(RpMaterial* pMaterial, void* pData) { if ( RpMaterialGetTexture(pMaterial) ) { - BOOL bHasAlpha = ((BOOL(*)(RwTexture*))0x4C9EA0)(RpMaterialGetTexture(pMaterial)); - if ( bHasAlpha ) + if ( ((BOOL(*)(RwTexture*))0x4C9EA0)(RpMaterialGetTexture(pMaterial)) ) { *static_cast(pData) = TRUE; return nullptr; @@ -212,6 +211,27 @@ RpMaterial* AlphaTest(RpMaterial* pMaterial, void* pData) return pMaterial; } +RpMaterial* AlphaTestAndPush(RpMaterial* pMaterial, void* pData) +{ + if ( RpMaterialGetTexture(pMaterial) ) + { + if ( !((BOOL(*)(RwTexture*))0x4C9EA0)(RpMaterialGetTexture(pMaterial)) ) + { + auto pStack = static_cast**>(pData); + *((*pStack)++) = std::make_pair(&pMaterial->color, *reinterpret_cast(&pMaterial->color)); + pMaterial->color.alpha = 0; + } + } + else if ( RpMaterialGetColor(pMaterial)->alpha == 255 ) + { + auto pStack = static_cast**>(pData); + *((*pStack)++) = std::make_pair(&pMaterial->color, *reinterpret_cast(&pMaterial->color)); + pMaterial->color.alpha = 0; + } + + return pMaterial; +} + RpAtomic* TwoPassAlphaRender(RpAtomic* atomic) { int nPushedAlpha, nAlphaFunction; @@ -232,15 +252,20 @@ RpAtomic* TwoPassAlphaRender(RpAtomic* atomic) // 2nd pass RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, reinterpret_cast(TRUE)); - RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTIONREF, reinterpret_cast(0)); RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTION, reinterpret_cast(rwALPHATESTFUNCTIONLESS)); RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, FALSE); - AtomicDefaultRenderCallBack(atomic); + // Push materials + std::pair MatsCache[16]; + auto* pMats = MatsCache; + + RpGeometryForAllMaterials(RpAtomicGetGeometry(atomic), AlphaTestAndPush, &pMats); + AtomicDefaultRenderCallBack(atomic); + pMats->first = nullptr; + + for ( auto i = MatsCache; i->first; i++ ) + *static_cast(i->first) = i->second; - /*RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTIONREF, 0); - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, FALSE); - auto* pAtomic = AtomicDefaultRenderCallBack(atomic);*/ RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTIONREF, reinterpret_cast(nPushedAlpha)); RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTION, reinterpret_cast(nAlphaFunction)); RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, reinterpret_cast(nZWrite));