diff --git a/SAFix/SilentPatchSA.cpp b/SAFix/SilentPatchSA.cpp index 0e777b0..ece9dd2 100644 --- a/SAFix/SilentPatchSA.cpp +++ b/SAFix/SilentPatchSA.cpp @@ -382,16 +382,55 @@ RpAtomic* TwoPassAlphaRender(RpAtomic* atomic) int nZWrite; int nAlphaBlending; -// RwRenderStateGet(rwRENDERSTATEALPHATESTFUNCTIONREF, &nPushedAlpha); + RwRenderStateGet(rwRENDERSTATEALPHATESTFUNCTIONREF, &nPushedAlpha); RwRenderStateGet(rwRENDERSTATEZWRITEENABLE, &nZWrite); RwRenderStateGet(rwRENDERSTATEVERTEXALPHAENABLE, &nAlphaBlending); RwRenderStateGet(rwRENDERSTATEALPHATESTFUNCTION, &nAlphaFunction); // 1st pass - RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, FALSE); - RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTION, reinterpret_cast(rwALPHATESTFUNCTIONALWAYS)); -// RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTION, reinterpret_cast(rwALPHATESTFUNCTIONLESS)); - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, FALSE); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, reinterpret_cast(TRUE)); + if (nPushedAlpha == 100) // or should we just force it? do we ever use something else anyway? + RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTIONREF, reinterpret_cast(128)); + RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTION, reinterpret_cast(rwALPHATESTFUNCTIONGREATEREQUAL)); + + atomic = AtomicDefaultRenderCallBack(atomic); + + if ( atomic ) + { + // 2nd pass + RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTION, reinterpret_cast(rwALPHATESTFUNCTIONLESS)); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, FALSE); + + AtomicDefaultRenderCallBack(atomic); + } + + RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTIONREF, reinterpret_cast(nPushedAlpha)); + RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTION, reinterpret_cast(nAlphaFunction)); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, reinterpret_cast(nZWrite)); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, reinterpret_cast(nAlphaBlending)); + + return atomic; +} + +RpAtomic* TwoPassAlphaRenderSilent(RpAtomic* atomic) +{ + // For cutscenes, fall back to one-pass render + if ( CCutsceneMgr__ms_running && !CanSeeOutSideFromCurrArea() ) + return OnePassAlphaRender(atomic); + + int nPushedAlpha, nAlphaFunction; + int nZWrite; + int nAlphaBlending; + + RwRenderStateGet(rwRENDERSTATEALPHATESTFUNCTIONREF, &nPushedAlpha); + RwRenderStateGet(rwRENDERSTATEZWRITEENABLE, &nZWrite); + RwRenderStateGet(rwRENDERSTATEVERTEXALPHAENABLE, &nAlphaBlending); + RwRenderStateGet(rwRENDERSTATEALPHATESTFUNCTION, &nAlphaFunction); + + // 1st pass + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, reinterpret_cast(FALSE)); + RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTIONREF, reinterpret_cast(255)); + RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTION, reinterpret_cast(rwALPHATESTFUNCTIONEQUAL)); atomic = AtomicDefaultRenderCallBack(atomic); @@ -399,16 +438,15 @@ RpAtomic* TwoPassAlphaRender(RpAtomic* atomic) { // 2nd pass RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, reinterpret_cast(TRUE)); - RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTION, reinterpret_cast(rwALPHATESTFUNCTIONGREATEREQUAL)); -// RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, FALSE); - RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, reinterpret_cast(nZWrite)); + RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTION, reinterpret_cast(rwALPHATESTFUNCTIONLESS)); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, FALSE); AtomicDefaultRenderCallBack(atomic); } -// RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTIONREF, reinterpret_cast(nPushedAlpha)); + RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTIONREF, reinterpret_cast(nPushedAlpha)); RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTION, reinterpret_cast(nAlphaFunction)); -// RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, reinterpret_cast(nZWrite)); + RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, reinterpret_cast(nZWrite)); RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, reinterpret_cast(nAlphaBlending)); return atomic; @@ -459,7 +497,7 @@ void SetRendererForAtomic(RpAtomic* pAtomic) BOOL bHasAlpha = FALSE; RpGeometryForAllMaterials(RpAtomicGetGeometry(pAtomic), AlphaTest, &bHasAlpha); - if ( bHasAlpha ) +// if ( bHasAlpha ) RpAtomicSetRenderCallBack(pAtomic, renderer); }