From e2ded2d6ceaf3dcf183701074ea572de0bdb672e Mon Sep 17 00:00:00 2001 From: Fire-Head Date: Thu, 30 Jul 2020 01:32:21 +0300 Subject: [PATCH] cutsceneshadow fixes --- src/render/CutsceneShadow.cpp | 32 +++++----- src/render/ShadowCamera.cpp | 8 +-- src/render/Shadows.cpp | 117 ++++++++++++++++++---------------- src/render/Shadows.h | 2 +- 4 files changed, 82 insertions(+), 77 deletions(-) diff --git a/src/render/CutsceneShadow.cpp b/src/render/CutsceneShadow.cpp index 4f9e7029..14f6a09f 100644 --- a/src/render/CutsceneShadow.cpp +++ b/src/render/CutsceneShadow.cpp @@ -26,6 +26,8 @@ CCutsceneShadow::~CCutsceneShadow() bool CCutsceneShadow::Create(RwObject *object, int32 rasterSize, bool resample, int32 blurPasses, bool gradient) { + ASSERT(object != NULL); + RwRGBAReal color; RwFrame *frame; @@ -33,6 +35,7 @@ CCutsceneShadow::Create(RwObject *object, int32 rasterSize, bool resample, int32 return false; m_pLight = RpLightCreate(rpLIGHTDIRECTIONAL); + ASSERT(m_pLight != NULL); if (!m_pLight) return false; @@ -43,6 +46,8 @@ CCutsceneShadow::Create(RwObject *object, int32 rasterSize, bool resample, int32 RpLightSetColor(m_pLight, &color); frame = RwFrameCreate(); + ASSERT(frame != NULL); + RpLightSetFrame(m_pLight, frame); SetLightProperties(180.0f, 90.0f, false); @@ -132,11 +137,15 @@ CCutsceneShadow::Create(RwObject *object, int32 rasterSize, bool resample, int32 RwFrame * CCutsceneShadow::SetLightProperties(float angleY, float angleX, bool setLight) { + ASSERT(m_pLight != NULL); + RwFrame *frame; static RwV3d Xaxis = { 1.0f, 0.0f, 0.0f }; static RwV3d Yaxis = { 0.0f, 1.0f, 0.0f }; frame = RpLightGetFrame(m_pLight); + ASSERT(frame != NULL); + if ( !frame ) return NULL; @@ -183,10 +192,12 @@ CCutsceneShadow::Update() switch ( m_nRwObjectType ) { case rpCLUMP: + ASSERT(m_pClump != NULL); RwV3dTransformPoints(&m_BaseSphere.center, &m_BoundingSphere.center, 1, RwFrameGetMatrix(RpClumpGetFrame(m_pClump))); break; case rpATOMIC: + ASSERT(m_pAtomic != NULL); RwV3dTransformPoints(&m_BaseSphere.center, &m_BoundingSphere.center, 1, RwFrameGetMatrix(RpAtomicGetFrame(m_pAtomic))); break; } @@ -205,6 +216,7 @@ CCutsceneShadow::Update() } RwRaster *raster = m_Camera.GetRwRenderRaster(); + ASSERT(raster != NULL); if ( m_bResample ) return m_ResampleCamera.RasterResample(raster); @@ -230,22 +242,12 @@ CCutsceneShadow::GetShadowCamera(int32 camType) { switch ( camType ) { - case RESAMPLE: - return &m_ResampleCamera; - break; - - case BLUR: - return &m_BlurCamera; - break; - - case GRADIENT: - return &m_GradientCamera; - break; - - default: - return &m_Camera; - break; + case RESAMPLE: return &m_ResampleCamera; break; + case BLUR: return &m_BlurCamera; break; + case GRADIENT: return &m_GradientCamera; break; } + + return &m_Camera; } RwTexture * diff --git a/src/render/ShadowCamera.cpp b/src/render/ShadowCamera.cpp index 82d10a88..8258b943 100644 --- a/src/render/ShadowCamera.cpp +++ b/src/render/ShadowCamera.cpp @@ -144,12 +144,10 @@ CShadowCamera::SetLight(RpLight *light) RwMatrix *lightMatrix = RwFrameGetMatrix(lightFrame); *RwMatrixGetRight(camMatrix) = *RwMatrixGetRight(lightMatrix); - *RwMatrixGetUp(camMatrix) = *RwMatrixGetUp(lightMatrix); - *RwMatrixGetAt(camMatrix) = *RwMatrixGetAt(lightMatrix); + *RwMatrixGetUp(camMatrix) = *RwMatrixGetUp(lightMatrix); + *RwMatrixGetAt(camMatrix) = *RwMatrixGetAt(lightMatrix); - //RwMatrixCopy(RwFrameGetMatrix(camFrame), RwFrameGetMatrix(lightFrame)); - - RwMatrixUpdate(RwFrameGetMatrix(camFrame)); + RwMatrixUpdate(camMatrix); RwFrameUpdateObjects(camFrame); return m_pCamera; diff --git a/src/render/Shadows.cpp b/src/render/Shadows.cpp index 57e7123e..a165309f 100644 --- a/src/render/Shadows.cpp +++ b/src/render/Shadows.cpp @@ -768,24 +768,6 @@ CShadows::StoreCarLightShadow(CAutomobile *pCar, int32 nID, RwTexture *pTexture, } } -void -CShadows::StoreShadowForPed(CPed *pPed, float fDisplacementX, float fDisplacementY, - float fFrontX, float fFrontY, float fSideX, float fSideY) -{ - ASSERT(pPed != NULL); - - if ( pPed->bIsVisible ) - { - if ( !(pPed->bInVehicle && pPed->m_nPedState != PED_DRAG_FROM_CAR && pPed->m_nPedState != PED_EXIT_CAR) ) - { - if ( CTimeCycle::GetShadowStrength() != 0 ) - StoreShadowForPedObject(pPed, - fDisplacementX, fDisplacementY, - fFrontX, fFrontY, - fSideX, fSideY); - } - } -} #if 1 void @@ -835,8 +817,8 @@ StoreShadowForCutscenePedObject(CPed *pObject, float fDisplacementX, float fDisp pos.x -= fDisplacementX; pos.y -= fDisplacementY; - float angleY = 360.0f - RADTODEG((CClock::ms_nGameClockMinutes+60* - CClock::ms_nGameClockHours+CClock::ms_nGameClockSeconds/60)*(HALFPI/360.0f)); + float angleY = 360.0f - RADTODEG((CClock::ms_nGameClockMinutes + +60*CClock::ms_nGameClockHours+CClock::ms_nGameClockSeconds/60)*(HALFPI/360.0f)); RwFrame *frame = shadow->SetLightProperties(angleY, -85.0f, true); ASSERT(frame); @@ -858,23 +840,45 @@ StoreShadowForCutscenePedObject(CPed *pObject, float fDisplacementX, float fDisp } #endif + +void +CShadows::StoreShadowForPed(CPed *pPed, float fDisplacementX, float fDisplacementY, + float fFrontX, float fFrontY, float fSideX, float fSideY) +{ + ASSERT(pPed != NULL); + + if ( pPed->bIsVisible ) + { + if ( !(pPed->bInVehicle && pPed->m_nPedState != PED_DRAG_FROM_CAR && pPed->m_nPedState != PED_EXIT_CAR) ) + { + if ( CTimeCycle::GetShadowStrength() != 0 ) + { + #if 1 + CCutsceneShadow *pShadow = pPed->m_pRTShadow; + + if (pShadow) + { + if (pShadow->IsInitialized()) + pShadow->UpdateForCutscene(); + ::StoreShadowForCutscenePedObject(pPed, fDisplacementX, fDisplacementY, fFrontX, fFrontY, fSideX, fSideY); + } + + return; + #endif + + StoreShadowForPedObject(pPed, + fDisplacementX, fDisplacementY, + fFrontX, fFrontY, + fSideX, fSideY); + } + } + } +} + void CShadows::StoreShadowForPedObject(CEntity *pPedObject, float fDisplacementX, float fDisplacementY, float fFrontX, float fFrontY, float fSideX, float fSideY) -{ -#if 1 - CPed *ped = (CPed*)pPedObject; - CCutsceneShadow *pShadow = ped->m_pRTShadow; - - if (pShadow) - { - if (pShadow->IsInitialized()) - pShadow->UpdateForCutscene(); - ::StoreShadowForCutscenePedObject(ped, fDisplacementX, fDisplacementY, fFrontX, fFrontY, fSideX, fSideY); - return; - } -#endif - +{ ASSERT(pPedObject != NULL); CVector PedPos = pPedObject->GetPosition(); @@ -2195,12 +2199,12 @@ CShadows::CastShadowEntityXYZ(CEntity *pEntity, CVector *pPosn, scl.z = 1.0f / (radius*0.8f); RwMatrixScale(&proj.invMatrix, &scl, rwCOMBINEPOSTCONCAT); - tr.x = tr.y = 0.5f; - tr.z = 0.0f; + tr.x = 0.5f; + tr.y = tr.z = 0.0f; RwMatrixTranslate(&proj.invMatrix, &tr, rwCOMBINEPOSTCONCAT); proj.shadowValue = nIntensity; - proj.numIm3DBatch = 0; + proj.fade = 0; RwMatrix matrix; pEntity->GetMatrix().CopyToRwMatrix(&matrix); @@ -2343,40 +2347,41 @@ CStaticShadow::Free(void) void CShadows::CalcPedShadowValues(CVector vecLightDir, - float *pfDisplacementX, float *pfDisplacementY, float *pfFrontX, float *pfFrontY, - float *pfSideX, float *pfSideY) + float *pfSideX, float *pfSideY, + float *pfDisplacementX, float *pfDisplacementY) { - ASSERT(pfDisplacementX != NULL); - ASSERT(pfDisplacementY != NULL); ASSERT(pfFrontX != NULL); ASSERT(pfFrontY != NULL); ASSERT(pfSideX != NULL); ASSERT(pfSideY != NULL); + ASSERT(pfDisplacementX != NULL); + ASSERT(pfDisplacementY != NULL); + + *pfFrontX = -vecLightDir.x; + *pfFrontY = -vecLightDir.y; + + float fDist = Sqrt(*pfFrontY * *pfFrontY + *pfFrontX * *pfFrontX); + float fMult = (fDist + 1.0f) / fDist; + + *pfFrontX *= fMult; + *pfFrontY *= fMult; + + *pfSideX = -vecLightDir.y / fDist; + *pfSideY = vecLightDir.x / fDist; *pfDisplacementX = -vecLightDir.x; *pfDisplacementY = -vecLightDir.y; - float fDist = Sqrt(*pfDisplacementY * *pfDisplacementY + *pfDisplacementX * *pfDisplacementX); - float fMult = (fDist + 1.0f) / fDist; - - *pfDisplacementX *= fMult; - *pfDisplacementY *= fMult; - - *pfFrontX = -vecLightDir.y / fDist; - *pfFrontY = vecLightDir.x / fDist; - - *pfSideX = -vecLightDir.x; - *pfSideY = -vecLightDir.y; - - *pfDisplacementX /= 2; - *pfDisplacementY /= 2; - *pfFrontX /= 2; *pfFrontY /= 2; *pfSideX /= 2; *pfSideY /= 2; + + *pfDisplacementX /= 2; + *pfDisplacementY /= 2; + } diff --git a/src/render/Shadows.h b/src/render/Shadows.h index adc27ed0..94b2981f 100644 --- a/src/render/Shadows.h +++ b/src/render/Shadows.h @@ -186,7 +186,7 @@ public: static void UpdateStaticShadows (void); static void UpdatePermanentShadows (void); - static void CalcPedShadowValues (CVector vecLightDir, float *pfDisplacementX, float *pfDisplacementY, float *pfFrontX, float *pfFrontY, float *pfSideX, float *pfSideY); + static void CalcPedShadowValues (CVector vecLightDir, float *pfFrontX, float *pfFrontY, float *pfSideX, float *pfSideY, float *pfDisplacementX, float *pfDisplacementY); static void RenderExtraPlayerShadows (void); static void TidyUpShadows (void); static void RenderIndicatorShadow (uint32 nID, uint8 ShadowType, RwTexture *pTexture, CVector *pPosn, float fFrontX, float fFrontY, float fSideX, float fSideY, int16 nIntensity);