cutsceneshadow fixes

This commit is contained in:
Fire-Head 2020-07-30 01:32:21 +03:00
parent f2f19ccea3
commit e2ded2d6ce
4 changed files with 82 additions and 77 deletions

View File

@ -26,6 +26,8 @@ CCutsceneShadow::~CCutsceneShadow()
bool bool
CCutsceneShadow::Create(RwObject *object, int32 rasterSize, bool resample, int32 blurPasses, bool gradient) CCutsceneShadow::Create(RwObject *object, int32 rasterSize, bool resample, int32 blurPasses, bool gradient)
{ {
ASSERT(object != NULL);
RwRGBAReal color; RwRGBAReal color;
RwFrame *frame; RwFrame *frame;
@ -33,6 +35,7 @@ CCutsceneShadow::Create(RwObject *object, int32 rasterSize, bool resample, int32
return false; return false;
m_pLight = RpLightCreate(rpLIGHTDIRECTIONAL); m_pLight = RpLightCreate(rpLIGHTDIRECTIONAL);
ASSERT(m_pLight != NULL);
if (!m_pLight) if (!m_pLight)
return false; return false;
@ -43,6 +46,8 @@ CCutsceneShadow::Create(RwObject *object, int32 rasterSize, bool resample, int32
RpLightSetColor(m_pLight, &color); RpLightSetColor(m_pLight, &color);
frame = RwFrameCreate(); frame = RwFrameCreate();
ASSERT(frame != NULL);
RpLightSetFrame(m_pLight, frame); RpLightSetFrame(m_pLight, frame);
SetLightProperties(180.0f, 90.0f, false); SetLightProperties(180.0f, 90.0f, false);
@ -132,11 +137,15 @@ CCutsceneShadow::Create(RwObject *object, int32 rasterSize, bool resample, int32
RwFrame * RwFrame *
CCutsceneShadow::SetLightProperties(float angleY, float angleX, bool setLight) CCutsceneShadow::SetLightProperties(float angleY, float angleX, bool setLight)
{ {
ASSERT(m_pLight != NULL);
RwFrame *frame; RwFrame *frame;
static RwV3d Xaxis = { 1.0f, 0.0f, 0.0f }; static RwV3d Xaxis = { 1.0f, 0.0f, 0.0f };
static RwV3d Yaxis = { 0.0f, 1.0f, 0.0f }; static RwV3d Yaxis = { 0.0f, 1.0f, 0.0f };
frame = RpLightGetFrame(m_pLight); frame = RpLightGetFrame(m_pLight);
ASSERT(frame != NULL);
if ( !frame ) if ( !frame )
return NULL; return NULL;
@ -183,10 +192,12 @@ CCutsceneShadow::Update()
switch ( m_nRwObjectType ) switch ( m_nRwObjectType )
{ {
case rpCLUMP: case rpCLUMP:
ASSERT(m_pClump != NULL);
RwV3dTransformPoints(&m_BaseSphere.center, &m_BoundingSphere.center, 1, RwFrameGetMatrix(RpClumpGetFrame(m_pClump))); RwV3dTransformPoints(&m_BaseSphere.center, &m_BoundingSphere.center, 1, RwFrameGetMatrix(RpClumpGetFrame(m_pClump)));
break; break;
case rpATOMIC: case rpATOMIC:
ASSERT(m_pAtomic != NULL);
RwV3dTransformPoints(&m_BaseSphere.center, &m_BoundingSphere.center, 1, RwFrameGetMatrix(RpAtomicGetFrame(m_pAtomic))); RwV3dTransformPoints(&m_BaseSphere.center, &m_BoundingSphere.center, 1, RwFrameGetMatrix(RpAtomicGetFrame(m_pAtomic)));
break; break;
} }
@ -205,6 +216,7 @@ CCutsceneShadow::Update()
} }
RwRaster *raster = m_Camera.GetRwRenderRaster(); RwRaster *raster = m_Camera.GetRwRenderRaster();
ASSERT(raster != NULL);
if ( m_bResample ) if ( m_bResample )
return m_ResampleCamera.RasterResample(raster); return m_ResampleCamera.RasterResample(raster);
@ -230,22 +242,12 @@ CCutsceneShadow::GetShadowCamera(int32 camType)
{ {
switch ( camType ) switch ( camType )
{ {
case RESAMPLE: case RESAMPLE: return &m_ResampleCamera; break;
return &m_ResampleCamera; case BLUR: return &m_BlurCamera; break;
break; case GRADIENT: return &m_GradientCamera; break;
case BLUR:
return &m_BlurCamera;
break;
case GRADIENT:
return &m_GradientCamera;
break;
default:
return &m_Camera;
break;
} }
return &m_Camera;
} }
RwTexture * RwTexture *

View File

@ -144,12 +144,10 @@ CShadowCamera::SetLight(RpLight *light)
RwMatrix *lightMatrix = RwFrameGetMatrix(lightFrame); RwMatrix *lightMatrix = RwFrameGetMatrix(lightFrame);
*RwMatrixGetRight(camMatrix) = *RwMatrixGetRight(lightMatrix); *RwMatrixGetRight(camMatrix) = *RwMatrixGetRight(lightMatrix);
*RwMatrixGetUp(camMatrix) = *RwMatrixGetUp(lightMatrix); *RwMatrixGetUp(camMatrix) = *RwMatrixGetUp(lightMatrix);
*RwMatrixGetAt(camMatrix) = *RwMatrixGetAt(lightMatrix); *RwMatrixGetAt(camMatrix) = *RwMatrixGetAt(lightMatrix);
//RwMatrixCopy(RwFrameGetMatrix(camFrame), RwFrameGetMatrix(lightFrame)); RwMatrixUpdate(camMatrix);
RwMatrixUpdate(RwFrameGetMatrix(camFrame));
RwFrameUpdateObjects(camFrame); RwFrameUpdateObjects(camFrame);
return m_pCamera; return m_pCamera;

View File

@ -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 #if 1
void void
@ -835,8 +817,8 @@ StoreShadowForCutscenePedObject(CPed *pObject, float fDisplacementX, float fDisp
pos.x -= fDisplacementX; pos.x -= fDisplacementX;
pos.y -= fDisplacementY; pos.y -= fDisplacementY;
float angleY = 360.0f - RADTODEG((CClock::ms_nGameClockMinutes+60* float angleY = 360.0f - RADTODEG((CClock::ms_nGameClockMinutes
CClock::ms_nGameClockHours+CClock::ms_nGameClockSeconds/60)*(HALFPI/360.0f)); +60*CClock::ms_nGameClockHours+CClock::ms_nGameClockSeconds/60)*(HALFPI/360.0f));
RwFrame *frame = shadow->SetLightProperties(angleY, -85.0f, true); RwFrame *frame = shadow->SetLightProperties(angleY, -85.0f, true);
ASSERT(frame); ASSERT(frame);
@ -858,23 +840,45 @@ StoreShadowForCutscenePedObject(CPed *pObject, float fDisplacementX, float fDisp
} }
#endif #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 void
CShadows::StoreShadowForPedObject(CEntity *pPedObject, float fDisplacementX, float fDisplacementY, CShadows::StoreShadowForPedObject(CEntity *pPedObject, float fDisplacementX, float fDisplacementY,
float fFrontX, float fFrontY, float fSideX, float fSideY) 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); ASSERT(pPedObject != NULL);
CVector PedPos = pPedObject->GetPosition(); CVector PedPos = pPedObject->GetPosition();
@ -2195,12 +2199,12 @@ CShadows::CastShadowEntityXYZ(CEntity *pEntity, CVector *pPosn,
scl.z = 1.0f / (radius*0.8f); scl.z = 1.0f / (radius*0.8f);
RwMatrixScale(&proj.invMatrix, &scl, rwCOMBINEPOSTCONCAT); RwMatrixScale(&proj.invMatrix, &scl, rwCOMBINEPOSTCONCAT);
tr.x = tr.y = 0.5f; tr.x = 0.5f;
tr.z = 0.0f; tr.y = tr.z = 0.0f;
RwMatrixTranslate(&proj.invMatrix, &tr, rwCOMBINEPOSTCONCAT); RwMatrixTranslate(&proj.invMatrix, &tr, rwCOMBINEPOSTCONCAT);
proj.shadowValue = nIntensity; proj.shadowValue = nIntensity;
proj.numIm3DBatch = 0; proj.fade = 0;
RwMatrix matrix; RwMatrix matrix;
pEntity->GetMatrix().CopyToRwMatrix(&matrix); pEntity->GetMatrix().CopyToRwMatrix(&matrix);
@ -2343,40 +2347,41 @@ CStaticShadow::Free(void)
void void
CShadows::CalcPedShadowValues(CVector vecLightDir, CShadows::CalcPedShadowValues(CVector vecLightDir,
float *pfDisplacementX, float *pfDisplacementY,
float *pfFrontX, float *pfFrontY, 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(pfFrontX != NULL);
ASSERT(pfFrontY != NULL); ASSERT(pfFrontY != NULL);
ASSERT(pfSideX != NULL); ASSERT(pfSideX != NULL);
ASSERT(pfSideY != 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; *pfDisplacementX = -vecLightDir.x;
*pfDisplacementY = -vecLightDir.y; *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; *pfFrontX /= 2;
*pfFrontY /= 2; *pfFrontY /= 2;
*pfSideX /= 2; *pfSideX /= 2;
*pfSideY /= 2; *pfSideY /= 2;
*pfDisplacementX /= 2;
*pfDisplacementY /= 2;
} }

View File

@ -186,7 +186,7 @@ public:
static void UpdateStaticShadows (void); static void UpdateStaticShadows (void);
static void UpdatePermanentShadows (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 RenderExtraPlayerShadows (void);
static void TidyUpShadows (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); static void RenderIndicatorShadow (uint32 nID, uint8 ShadowType, RwTexture *pTexture, CVector *pPosn, float fFrontX, float fFrontY, float fSideX, float fSideY, int16 nIntensity);