shadows done

This commit is contained in:
Fire-Head
2019-07-24 19:55:43 +03:00
parent ad1920bc6f
commit b4ecb3e3da
20 changed files with 2412 additions and 60 deletions

View File

@ -226,6 +226,10 @@ int32 Randomizer;
int32 nParticleCreationInterval = 1;
float fParticleScaleLimit = 0.5f;
SETTWEAKPATH("Particle");
TWEAKINT32(nParticleCreationInterval, 0, 5, 1);
TWEAKFLOAT(fParticleScaleLimit, 0.0f, 1.0f, 0.1f);
TWEAKFUNC(CParticle::ReloadConfig);
void CParticle::ReloadConfig()
{
@ -1143,7 +1147,7 @@ void CParticle::Update()
{
bRemoveParticle = true;
int32 randVal = int32(CGeneral::GetRandomNumber());
int32 randVal = CGeneral::GetRandomNumber();
if ( randVal & 1 )
{
@ -1188,23 +1192,19 @@ void CParticle::Update()
if ( randVal == 5 )
{
int32 randTime = int32(CGeneral::GetRandomNumber());
CShadows::AddPermanentShadow(1, gpBloodPoolTex, &vecPosn,
0.1f, 0.0f, 0.0f, -0.1f,
255,
255, 0, 0,
4.0f, (randTime & 0xFFF) + 2000, 1.0f);
4.0f, (CGeneral::GetRandomNumber() & 4095) + 2000, 1.0f);
}
else if ( randVal == 2 )
{
int32 randTime = int32(CGeneral::GetRandomNumber());
CShadows::AddPermanentShadow(1, gpBloodPoolTex, &vecPosn,
0.2f, 0.0f, 0.0f, -0.2f,
255,
255, 0, 0,
4.0f, (randTime & 0xFFF) + 8000, 1.0f);
4.0f, (CGeneral::GetRandomNumber() & 4095) + 8000, 1.0f);
}
continue;
}
@ -1600,7 +1600,7 @@ void CParticle::Render()
fTrailLength = fDist;
//Float fRot = Atan2( vecDist.x / fDist, Sqrt(1.0f - vecDist.x / fDist * (vecDist.x / fDist)) );
float fRot = asinf(vecDist.x / fDist);
float fRot = Asin(vecDist.x / fDist);
fRotation = fRot;
@ -1652,7 +1652,7 @@ void CParticle::Render()
fTrailLength = fDist;
//Float fRot = Atan2(vecDist.x / fDist, Sqrt(1.0f - vecDist.x / fDist * (vecDist.x / fDist)));
float fRot = asinf(vecDist.x / fDist);
float fRot = Asin(vecDist.x / fDist);
fRotation = fRot;

View File

@ -17,10 +17,10 @@ static_assert(sizeof(CRegisteredPointLight) == 0x2C, "CRegisteredPointLight: err
class CPointLights
{
// Probably have to make this public for shadows later
public:
static int16 &NumLights;
static CRegisteredPointLight *aLights; //[NUMPOINTLIGHTS]
public:
enum {
LIGHT_POINT,
LIGHT_DIRECTIONAL,

View File

@ -8,8 +8,8 @@ int32 &TempBufferIndicesStored = *(int32*)0x8F1A4C;
RwIm3DVertex *TempBufferRenderVertices = (RwIm3DVertex*)0x862330;
RwImVertexIndex *TempBufferRenderIndexList = (RwImVertexIndex*)0x846288;
int RenderBuffer::VerticesToBeStored;
int RenderBuffer::IndicesToBeStored;
int &RenderBuffer::VerticesToBeStored = *(int*)0x8F59C4;
int &RenderBuffer::IndicesToBeStored = *(int*)0x8E28B0;
void
RenderBuffer::ClearRenderBuffer(void)

View File

@ -1,8 +1,8 @@
class RenderBuffer
{
public:
static int VerticesToBeStored;
static int IndicesToBeStored;
static int &VerticesToBeStored;
static int &IndicesToBeStored;
static void ClearRenderBuffer(void);
static void StartStoring(int numIndices, int numVertices, RwImVertexIndex **indexStart, RwIm3DVertex **vertexStart);
static void StopStoring(void);

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,11 @@
#pragma once
#define MAX_STOREDSHADOWS 48
#define MAX_POLYBUNCHES 300
#define MAX_STATICSHADOWS 64
#define MAX_PERMAMENTSHADOWS 48
struct RwTexture;
class CEntity;
@ -8,19 +14,170 @@ enum
SHADOWTYPE_2 = 2
};
enum eShadowType
{
SHADOWTYPE_NONE = 0,
SHADOWTYPE_DARK,
SHADOWTYPE_ADDITIVE,
SHADOWTYPE_INVCOLOR
};
enum eShadowTextureType
{
SHADOWTEX_NONE = 0,
SHADOWTEX_CAR,
SHADOWTEX_PED,
SHADOWTEX_EXPLOSION,
SHADOWTEX_HELI,
SHADOWTEX_HEADLIGHTS,
SHADOWTEX_BLOOD
};
class CStoredShadow
{
public:
CVector m_vecPos;
CVector2D m_vecFront;
CVector2D m_vecSide;
float m_fZDistance;
float m_fScale;
int16 m_nIntensity;
uint8 m_ShadowType;
uint8 m_nRed;
uint8 m_nGreen;
uint8 m_nBlue;
struct
{
uint8 bDrawOnWater : 1;
uint8 bRendered : 1;
//uint8 bDrawOnBuildings : 1;
} m_nFlags;
char _pad0;
RwTexture *m_pTexture;
CStoredShadow()
{ }
};
VALIDATE_SIZE(CStoredShadow, 0x30);
class CPolyBunch
{
public:
int16 m_nNumVerts;
char _pad0[2];
CVector m_aVerts[7];
uint8 m_aU[7];
uint8 m_aV[7];
char _pad1[2];
CPolyBunch *m_pNext;
CPolyBunch()
{ }
};
VALIDATE_SIZE(CPolyBunch, 0x6C);
class CStaticShadow
{
public:
uint32 m_nId;
CPolyBunch *m_pPolyBunch;
uint32 m_nTimeCreated;
CVector m_vecPosn;
CVector2D m_vecFront;
CVector2D m_vecSide;
float m_fZDistance;
float m_fScale;
uint8 m_nType;
char _pad0;
int16 m_nIntensity; // unsigned ?
uint8 m_nRed;
uint8 m_nGreen;
uint8 m_nBlue;
bool m_bJustCreated;
bool m_bRendered;
bool m_bTemp;
char _pad1[2];
RwTexture *m_pTexture;
CStaticShadow()
{ }
void Free();
};
VALIDATE_SIZE(CStaticShadow, 0x40);
class CPermanentShadow
{
public:
CVector m_vecPos;
CVector2D m_vecFront;
CVector2D m_vecSide;
float m_fZDistance;
float m_fScale;
int16 m_nIntensity;
uint8 m_nType; // eShadowType
uint8 m_nRed;
uint8 m_nGreen;
uint8 m_nBlue;
char _pad0[2];
uint32 m_nTimeCreated;
uint32 m_nLifeTime;
RwTexture *m_pTexture;
CPermanentShadow()
{ }
};
VALIDATE_SIZE(CPermanentShadow, 0x38);
class CPtrList;
class CAutomobile;
class CPed;
class CShadows
{
public:
static void AddPermanentShadow(uint8 ShadowType, RwTexture* pTexture, CVector* pPosn, float fX1, float fY1, float fX2, float fY2, short nTransparency, uint8 nRed, uint8 nGreen, uint8 nBlue, float fZDistance, uint32 nTime, float fScale);
static void RenderStaticShadows(void);
static void RenderStoredShadows(void);
static void RenderExtraPlayerShadows(void);
static void CalcPedShadowValues(CVector light, float *frontX, float *frontY, float *sideX, float *sideY, float *dispX, float *dispY);
static void StoreShadowForTree(CEntity *ent);
static void StoreShadowForPole(CEntity *ent, float offsetX, float offsetY, float offsetZ, float poleHeight, float poleWidth, uint32 subId);
static void StoreShadowForPedObject(CEntity *ent, float dispX, float dispY, float frontX, float frontY, float sideX, float sideY);
static void StoreStaticShadow(uint32 id, uint8 type, RwTexture *texture, CVector *coors, float frontX, float frontY, float sideX, float sideY, int16 intensity, uint8 red, uint8 green, uint8 blue, float zDistance, float scale, float drawDistance, bool temporaryShadow, float upDistance);;
static void StoreShadowToBeRendered(uint8 type, RwTexture *texture, CVector *coors, float frontX, float frontY, float sideX, float sideY, int16 intensity, uint8 red, uint8 green, uint8 blue, float zDistance, bool drawOnWater, float upDistance);
#if 1
static int16 ShadowsStoredToBeRendered;
static CStoredShadow asShadowsStored [MAX_STOREDSHADOWS];
static CPolyBunch aPolyBunches [MAX_POLYBUNCHES];
static CStaticShadow aStaticShadows [MAX_STATICSHADOWS];
static CPolyBunch *pEmptyBunchList;
static CPermanentShadow aPermanentShadows[MAX_PERMAMENTSHADOWS];
#else
static int16 &ShadowsStoredToBeRendered;
static CStoredShadow (&asShadowsStored) [MAX_STOREDSHADOWS];
static CPolyBunch (&aPolyBunches) [MAX_POLYBUNCHES];
static CStaticShadow (&aStaticShadows) [MAX_STATICSHADOWS];
static CPolyBunch *&pEmptyBunchList;
static CPermanentShadow (&aPermanentShadows)[MAX_PERMAMENTSHADOWS];
#endif
static void Init (void);
static void Shutdown (void);
static void AddPermanentShadow ( uint8 ShadowType, RwTexture *pTexture, CVector *pPosn, float fFrontX, float fFrontY, float fSideX, float fSideY, int16 nIntensity, uint8 nRed, uint8 nGreen, uint8 nBlue, float fZDistance, uint32 nTime, float fScale);
static void StoreStaticShadow (uint32 nID, uint8 ShadowType, RwTexture *pTexture, CVector *pPosn, float fFrontX, float fFrontY, float fSideX, float fSideY, int16 nIntensity, uint8 nRed, uint8 nGreen, uint8 nBlue, float fZDistance, float fScale, float fDrawDistance, bool bTempShadow, float fUpDistance);
static void StoreShadowToBeRendered ( uint8 ShadowType, CVector *pPosn, float fFrontX, float fFrontY, float fSideX, float fSideY, int16 nIntensity, uint8 nRed, uint8 nGreen, uint8 nBlue);
static void StoreShadowToBeRendered ( uint8 ShadowType, RwTexture *pTexture, CVector *pPosn, float fFrontX, float fFrontY, float fSideX, float fSideY, int16 nIntensity, uint8 nRed, uint8 nGreen, uint8 nBlue, float fZDistance, bool bDrawOnWater, float fScale);
static void StoreShadowForCar (CAutomobile *pCar);
static void StoreCarLightShadow (CAutomobile *pCar, int32 nID, RwTexture *pTexture, CVector *pPosn, float fFrontX, float fFrontY, float fSideX, float fSideY, uint8 nRed, uint8 nGreen, uint8 nBlue, float fMaxViewAngle);
static void StoreShadowForPed (CPed *pPed, float fDisplacementX, float fDisplacementY, float fFrontX, float fFrontY, float fSideX, float fSideY);
static void StoreShadowForPedObject (CEntity *pPedObject, float fDisplacementX, float fDisplacementY, float fFrontX, float fFrontY, float fSideX, float fSideY);
static void StoreShadowForTree (CEntity *pTree);
static void StoreShadowForPole (CEntity *pPole, float fOffsetX, float fOffsetY, float fOffsetZ, float fPoleHeight, float fPoleWidth, uint32 nID);
static void SetRenderModeForShadowType (uint8 ShadowType);
static void RenderStoredShadows (void);
static void RenderStaticShadows (void);
static void GeneratePolysForStaticShadow (int16 nStaticShadowID);
static void CastShadowSectorList (CPtrList &PtrList, float fStartX, float fStartY, float fEndX, float fEndY,
CVector *pPosn, float fFrontX, float fFrontY, float fSideX, float fSideY, int16 nIntensity, uint8 nRed, uint8 nGreen, uint8 nBlue, float fZDistance, float fScale, CPolyBunch **ppPolyBunch);
static void CastShadowEntity (CEntity *pEntity, float fStartX, float fStartY, float fEndX, float fEndY,
CVector *pPosn, float fFrontX, float fFrontY, float fSideX, float fSideY, int16 nIntensity, uint8 nRed, uint8 nGreen, uint8 nBlue, float fZDistance, float fScale, CPolyBunch **ppPolyBunch);
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 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);
};
extern RwTexture *&gpBloodPoolTex;

View File

@ -10,3 +10,6 @@ WRAPPER void CMotionBlurStreaks::RegisterStreak(int32 id, uint8 r, uint8 g, uint
CBulletTrace (&CBulletTraces::aTraces)[16] = *(CBulletTrace(*)[16])*(uintptr*)0x72B1B8;
WRAPPER void CBulletTraces::Init(void) { EAXJMP(0x518DE0); }
WRAPPER void C3dMarkers::PlaceMarkerSet(uint32 id, uint16 type, CVector& pos, float size, uint8 r, uint8 g, uint8 b, uint8 a, uint16 pulsePeriod, float pulseFraction, int16 rotateRate) { EAXJMP(0x51BB80); }

View File

@ -28,3 +28,9 @@ public:
static void Init(void);
};
class C3dMarkers
{
public:
static void PlaceMarkerSet(uint32 id, uint16 type, CVector& pos, float size, uint8 r, uint8 g, uint8 b, uint8 a, uint16 pulsePeriod, float pulseFraction, int16 rotateRate);
};

View File

@ -119,6 +119,8 @@ public:
static int GetSunCoronaBlue(void) { return m_nCurrentSunCoronaBlue; }
static float GetSunSize(void) { return m_fCurrentSunSize; }
static float GetSpriteBrightness(void) { return m_fCurrentSpriteBrightness; }
static int GetShadowStrength(void) { return m_nCurrentShadowStrength; }
static int GetLightShadowStrength(void) { return m_nCurrentLightShadowStrength; }
static float GetFarClip(void) { return m_fCurrentFarClip; }
static float GetFogStart(void) { return m_fCurrentFogStart; }
@ -138,4 +140,10 @@ public:
static void Initialise(void);
static void Update(void);
static CVector &GetSunPosition(void) { return m_VectorToSun[m_CurrentStoredValue]; }
static float GetShadowFrontX(void) { return m_fShadowFrontX[m_CurrentStoredValue]; }
static float GetShadowFrontY(void) { return m_fShadowFrontY[m_CurrentStoredValue]; }
static float GetShadowSideX(void) { return m_fShadowSideX[m_CurrentStoredValue]; }
static float GetShadowSideY(void) { return m_fShadowSideY[m_CurrentStoredValue]; }
static float GetShadowDisplacementX(void) { return m_fShadowDisplacementX[m_CurrentStoredValue]; }
static float GetShadowDisplacementY(void) { return m_fShadowDisplacementY[m_CurrentStoredValue]; }
};

View File

@ -238,7 +238,7 @@ CWaterLevel::GetWaterLevel(float fX, float fY, float fZ, float *pfOutLevel, bool
float fAngle = (CTimer::GetTimeInMilliseconds() & 4095) * (TWOPI / 4096.0f);
float fWave = sin
float fWave = Sin
(
/*( WATER_UNSIGN_Y(fY) - float(y) * MAX_HUGE_SECTORS + WATER_UNSIGN_X(fX) - float(x) * MAX_HUGE_SECTORS )*/ // VC
(float)( ((int32)fX & (MAX_HUGE_SECTORS-1)) + ((int32)fY & (MAX_HUGE_SECTORS-1)) )
@ -306,7 +306,7 @@ _GetCamBounds(bool *bUseCamStartY, bool *bUseCamEndY, bool *bUseCamStartX, bool
{
if ( TheCamera.GetForward().z > -0.8f )
{
if ( fabsf(TheCamera.GetForward().x) > fabsf(TheCamera.GetForward().y) )
if ( Abs(TheCamera.GetForward().x) > Abs(TheCamera.GetForward().y) )
{
if ( TheCamera.GetForward().x > 0.0f )
*bUseCamStartX = true;
@ -326,7 +326,7 @@ _GetCamBounds(bool *bUseCamStartY, bool *bUseCamEndY, bool *bUseCamStartX, bool
float
SectorRadius(float fSize)
{
return sqrtf(powf(fSize, 2) + powf(fSize, 2));
return Sqrt(Pow(fSize, 2) + Pow(fSize, 2));
}
void
@ -714,7 +714,7 @@ CWaterLevel::RenderWater()
static CVector prev_front(0.0f, 0.0f, 0.0f);
static int32 timecounter;
if ( fabs(prev_pos.x - cur_pos.x) + fabs(prev_pos.y - cur_pos.y) + fabs(prev_pos.z - cur_pos.z) > 1.5f )
if ( Abs(prev_pos.x - cur_pos.x) + Abs(prev_pos.y - cur_pos.y) + Abs(prev_pos.z - cur_pos.z) > 1.5f )
{
prev_pos = cur_pos;
timecounter = CTimer::GetTimeInMilliseconds();
@ -962,8 +962,8 @@ CWaterLevel::RenderOneWavySector(float fX, float fY, float fZ, RwRGBA const &col
RwRGBAAssign(&wavyPreLights[9*i+j], &color);
wavyVertices[9*i+j].z = ( CWeather::Wind * 0.7f + 0.3f )
* ( sinf(float(i + j) * DEGTORAD(45.0f) + fAngle) )
+ ( CWeather::Wind * 0.2f * sinf(float(j - i) * PI + (2.0f * fAngle)) );
* ( Sin(float(i + j) * DEGTORAD(45.0f) + fAngle) )
+ ( CWeather::Wind * 0.2f * Sin(float(j - i) * PI + (2.0f * fAngle)) );
}
}
@ -1119,7 +1119,7 @@ CWaterLevel::CalcDistanceToWater(float fX, float fY)
}
}
return clamp(sqrt(fDistSqr) - 23.0f, 0.0f, fSectorMaxRenderDist);
return clamp(Sqrt(fDistSqr) - 23.0f, 0.0f, fSectorMaxRenderDist);
}
void