re3/src/render/WaterLevel.cpp

2680 lines
85 KiB
C++
Raw Normal View History

#include "common.h"
2019-07-19 11:58:19 +00:00
#include "main.h"
2019-07-11 00:22:01 +00:00
#include "FileMgr.h"
#include "TxdStore.h"
#include "Timer.h"
#include "Weather.h"
#include "Camera.h"
#include "Vehicle.h"
#include "Boat.h"
#include "World.h"
#include "General.h"
2019-07-31 15:54:18 +00:00
#include "Timecycle.h"
2019-07-11 00:22:01 +00:00
#include "ZoneCull.h"
#include "Clock.h"
#include "Particle.h"
#include "ParticleMgr.h"
#include "RwHelper.h"
#include "Streaming.h"
#include "CdStream.h"
#include "Pad.h"
#include "RenderBuffer.h"
2020-05-27 18:50:01 +00:00
#include <rwcore.h>
2019-07-11 00:22:01 +00:00
#include <rpworld.h>
2020-05-27 18:50:01 +00:00
#include <rpmatfx.h>
#include "Occlusion.h"
#include "WaterLevel.h"
2020-04-17 13:31:11 +00:00
2020-05-27 18:50:01 +00:00
#define RwIm3DVertexSet_RGBA(vert, rgba) RwIm3DVertexSetRGBA(vert, rgba.red, rgba.green, rgba.blue, rgba.alpha) // (RwRGBAAssign(&(_dst)->color, &_src))
2019-07-11 00:22:01 +00:00
float TEXTURE_ADDU;
float TEXTURE_ADDV;
2020-05-27 18:50:01 +00:00
float _TEXTURE_MASK_ADDU;
float _TEXTURE_MASK_ADDV;
float _TEXTURE_WAKE_ADDU;
float _TEXTURE_WAKE_ADDV;
2019-07-11 00:22:01 +00:00
int32 CWaterLevel::ms_nNoOfWaterLevels;
float CWaterLevel::ms_aWaterZs[48];
CRect CWaterLevel::ms_aWaterRects[48];
2020-05-27 18:50:01 +00:00
uint8 CWaterLevel::aWaterBlockList[WATER_BLOCK_SECTORS][WATER_BLOCK_SECTORS];
uint8 CWaterLevel::aWaterFineBlockList[WATER_FINEBLOCK_SECTORS][WATER_FINEBLOCK_SECTORS];
2019-07-11 00:22:01 +00:00
bool CWaterLevel::WavesCalculatedThisFrame;
2020-05-27 18:50:01 +00:00
bool CWaterLevel::RequireWavySector;
bool CWaterLevel::MaskCalculatedThisFrame;
CVector CWaterLevel::PreCalculatedMaskPosn;
bool CWaterLevel::m_bRenderSeaBed;
int32 CWaterLevel::m_nRenderWaterLayers;
2019-07-11 00:22:01 +00:00
RpAtomic *CWaterLevel::ms_pWavyAtomic;
2020-05-27 18:50:01 +00:00
RpAtomic *CWaterLevel::ms_pMaskAtomic;
2019-07-11 00:22:01 +00:00
2020-04-17 05:54:14 +00:00
RwTexture *gpWaterTex;
2020-05-27 18:50:01 +00:00
RwTexture *gpWaterEnvTex;
RwTexture *gpWaterEnvBaseTex;
RwTexture *gpWaterWakeTex;
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
RwRaster *gpWaterRaster;
RwRaster *gpWaterEnvRaster;
RwRaster *gpWaterEnvBaseRaster;
RwRaster *gpWaterWakeRaster;
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
bool _bSeaLife;
float _fWaterZOffset = 0.5f;
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
#ifdef PC_WATER
float fEnvScale = 0.25f;
#else
float fEnvScale = 0.5f;
#endif
float fWave2InvLength = 0.03f;
float fWave2NormScale = 0.5f;
float fWave2Ampl = 0.1f;
uint8 nWaterAlpha = 192;
uint8 nWakeAlpha = 192;
float fUnder1 = 4.0;
float fUnder2 = 2.5;
float fUnder3 = 1.5;
int nMaskAlpha = 230;
float fAdd1 = 180.0f;
float fAdd2 = 80.0;
float fRedMult = 0.6f;
float fGreenMult = 1.0f;
float fBlueMult = 1.4f;
float fAlphaMult = 500.0f;
float fAlphaBase = 30.0f;
float fRandomMoveDiv = 8.0f;
float fRandomDamp = 0.99f;
float fNormMult = 2.0f;
float fNormMultB = 1.0f;
float fBumpScale = 1.5;
float fBumpTexRepeat = 2.0;
float fNormalDirectionScalar1 = 2.0f;
float fNormalDirectionScalar2 = 1.0f;
bool bTestDoNormals = true;
float fSeaBedZ = 25.0f;
float aAlphaFade[5] = { 0.4f, 1.0f, 0.2f, 1.0f, 0.4f}; //CWaterLevel::RenderWakeSegment
float fFlatWaterBlendRange = 0.05f;
float fStartBlendDistanceAdd = 64.0f;
float fMinWaterAlphaMult = -30.0f;
2019-07-11 00:22:01 +00:00
void
2020-05-27 18:50:01 +00:00
WaterLevelInitialise(Const char *pWaterDat)
2019-07-11 00:22:01 +00:00
{
2020-05-27 18:50:01 +00:00
CWaterLevel::ms_nNoOfWaterLevels = 0;
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
int32 hFile;
2019-07-11 00:22:01 +00:00
do
{
hFile = CFileMgr::OpenFile("DATA\\waterpro.dat", "rb");
}
while ( hFile < 0 );
if ( hFile > 0 )
{
if ( hFile >= 0 )
{
2020-05-27 18:50:01 +00:00
CFileMgr::Read(hFile, (char *)&CWaterLevel::ms_nNoOfWaterLevels, sizeof(CWaterLevel::ms_nNoOfWaterLevels));
CFileMgr::Read(hFile, (char *)CWaterLevel::ms_aWaterZs, sizeof(CWaterLevel::ms_aWaterZs));
CFileMgr::Read(hFile, (char *)CWaterLevel::ms_aWaterRects, sizeof(CWaterLevel::ms_aWaterRects));
CFileMgr::Read(hFile, (char *)CWaterLevel::aWaterBlockList, sizeof(CWaterLevel::aWaterBlockList));
CFileMgr::Read(hFile, (char *)CWaterLevel::aWaterFineBlockList, sizeof(CWaterLevel::aWaterFineBlockList));
2019-07-11 00:22:01 +00:00
}
CFileMgr::CloseFile(hFile);
}
CTxdStore::PushCurrentTxd();
int32 slot = CTxdStore::FindTxdSlot("particle");
CTxdStore::SetCurrentTxd(slot);
if ( gpWaterTex == NULL )
2020-05-07 11:38:14 +00:00
gpWaterTex = RwTextureRead("waterclear256", NULL);
2019-07-11 00:22:01 +00:00
gpWaterRaster = RwTextureGetRaster(gpWaterTex);
2020-05-27 18:50:01 +00:00
if ( gpWaterEnvTex == NULL )
gpWaterEnvTex = RwTextureRead("waterreflection2", NULL);
gpWaterEnvRaster = RwTextureGetRaster(gpWaterEnvTex);
#ifdef PC_WATER
if ( gpWaterEnvBaseTex == NULL )
gpWaterEnvBaseTex = RwTextureRead("sandywater", NULL);
gpWaterEnvBaseRaster = RwTextureGetRaster(gpWaterEnvBaseTex);
#endif
if ( gpWaterWakeTex == NULL )
gpWaterWakeTex = RwTextureRead("waterwake", NULL);
gpWaterWakeRaster = RwTextureGetRaster(gpWaterWakeTex);
2019-07-11 00:22:01 +00:00
CTxdStore::PopCurrentTxd();
2020-05-27 18:50:01 +00:00
CWaterLevel::CreateWavyAtomic();
2019-07-11 00:22:01 +00:00
printf("Done Initing waterlevels\n");
}
void
CWaterLevel::Shutdown()
{
DestroyWavyAtomic();
2020-05-27 18:50:01 +00:00
#define _DELETE_TEXTURE(t) if ( t ) \
{ \
RwTextureDestroy(t); \
t = NULL; \
}
_DELETE_TEXTURE(gpWaterTex);
_DELETE_TEXTURE(gpWaterEnvTex);
_DELETE_TEXTURE(gpWaterEnvBaseTex);
#undef _DELETE_TEXTURE
2019-07-11 00:22:01 +00:00
}
void
CWaterLevel::CreateWavyAtomic()
{
RpGeometry *wavyGeometry;
2020-05-27 18:50:01 +00:00
RpGeometry *maskGeometry;
2019-07-11 00:22:01 +00:00
RpMaterial *wavyMaterial;
2020-05-27 18:50:01 +00:00
RpMaterial *maskMaterial;
RpTriangle *wavytlist;
RpTriangle *masktlist;
2019-07-11 00:22:01 +00:00
RpMorphTarget *wavyMorphTarget;
2020-05-27 18:50:01 +00:00
RpMorphTarget *maskMorphTarget;
RwSphere boundingSphere;
2019-07-11 00:22:01 +00:00
RwV3d *wavyVert;
2020-05-27 18:50:01 +00:00
RwV3d *wavyNormal;
RwV3d *maskVert;
RwV3d *maskNormal;
2019-07-11 00:22:01 +00:00
RwFrame *wavyFrame;
2020-05-27 18:50:01 +00:00
RwFrame *maskFrame;
2019-07-11 00:22:01 +00:00
{
2020-05-27 18:50:01 +00:00
wavyGeometry = RpGeometryCreate(17*17, 512, rpGEOMETRYTRISTRIP
2019-07-11 00:22:01 +00:00
|rpGEOMETRYTEXTURED
|rpGEOMETRYPRELIT
2020-05-27 18:50:01 +00:00
|rpGEOMETRYNORMALS
2019-07-11 00:22:01 +00:00
|rpGEOMETRYMODULATEMATERIALCOLOR);
2020-05-27 18:50:01 +00:00
#ifdef PC_WATER
RpGeometryAddMorphTarget(wavyGeometry);
#endif
}
{
maskGeometry = RpGeometryCreate(33*33, 2048, rpGEOMETRYTRISTRIP
|rpGEOMETRYTEXTURED
|rpGEOMETRYPRELIT
|rpGEOMETRYNORMALS
|rpGEOMETRYMODULATEMATERIALCOLOR);
#ifdef PC_WATER
RpGeometryAddMorphTarget(maskGeometry);
#endif
2019-07-11 00:22:01 +00:00
}
{
wavyMaterial = RpMaterialCreate();
RpMaterialSetTexture(wavyMaterial, gpWaterTex);
2020-05-27 18:50:01 +00:00
RwRGBA watercolor = { 255, 255, 255, 192 };
RpMaterialSetColor(wavyMaterial, &watercolor);
2019-07-11 00:22:01 +00:00
}
{
2020-05-27 18:50:01 +00:00
maskMaterial = RpMaterialCreate();
#ifdef PC_WATER
RpMaterialSetTexture(maskMaterial, gpWaterEnvBaseTex);
#else
RpMaterialSetTexture(maskMaterial, gpWaterTex);
#endif
RwRGBA watercolor = { 255, 255, 255, 192 };
RpMaterialSetColor(maskMaterial, &watercolor);
}
{
wavytlist = RpGeometryGetTriangles(wavyGeometry);
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
for ( int32 i = 0; i < 16; i++ )
2019-07-11 00:22:01 +00:00
{
2020-05-27 18:50:01 +00:00
for ( int32 j = 0; j < 16; j++ )
{
const RwUInt16 base = (RwUInt16)((16 + 1)*i+j);
RpGeometryTriangleSetVertexIndices(wavyGeometry,
wavytlist, (RwInt16)base, (RwInt16)(base+1), (RwInt16)(base+16+2));
2019-07-11 00:22:01 +00:00
RpGeometryTriangleSetVertexIndices(wavyGeometry,
2020-05-27 18:50:01 +00:00
(wavytlist+1), (RwInt16)base, (RwInt16)(base+16+2), (RwInt16)(base+16+1));
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
RpGeometryTriangleSetMaterial(wavyGeometry, wavytlist, wavyMaterial);
RpGeometryTriangleSetMaterial(wavyGeometry, (wavytlist+1), wavyMaterial);
wavytlist+=2;
2019-07-11 00:22:01 +00:00
}
}
}
2020-05-27 18:50:01 +00:00
{
masktlist = RpGeometryGetTriangles(maskGeometry);
for ( int32 i = 0; i < 32; i++ )
{
for ( int32 j = 0; j < 32; j++ )
{
const RwUInt16 base = (RwUInt16)((32 + 1)*i+j);
RpGeometryTriangleSetVertexIndices(maskGeometry,
masktlist, (RwInt16)base, (RwInt16)(base+1), (RwInt16)(base+32+2));
RpGeometryTriangleSetVertexIndices(maskGeometry,
(masktlist+1), (RwInt16)base, (RwInt16)(base+32+2), (RwInt16)(base+32+1));
RpGeometryTriangleSetMaterial(maskGeometry, masktlist, maskMaterial);
RpGeometryTriangleSetMaterial(maskGeometry, (masktlist+1), maskMaterial);
masktlist+=2;
}
}
}
2019-07-11 00:22:01 +00:00
{
wavyMorphTarget = RpGeometryGetMorphTarget(wavyGeometry, 0);
2020-05-27 18:50:01 +00:00
wavyVert = RpMorphTargetGetVertices(wavyMorphTarget);
wavyNormal = RpMorphTargetGetVertexNormals(wavyMorphTarget);
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
for ( int32 i = 0; i < 17; i++ )
2019-07-11 00:22:01 +00:00
{
2020-05-27 18:50:01 +00:00
for ( int32 j = 0; j < 17; j++ )
2019-07-11 00:22:01 +00:00
{
2020-05-27 18:50:01 +00:00
(*wavyVert).x = (float)i * 2.0f;
(*wavyVert).y = (float)j * 2.0f;
(*wavyVert).z = 0.0f;
(*wavyNormal).x = 0.0f;
(*wavyNormal).y = 0.0f;
(*wavyNormal).z = 1.0f;
wavyVert++;
wavyNormal++;
2019-07-11 00:22:01 +00:00
}
}
RpMorphTargetCalcBoundingSphere(wavyMorphTarget, &boundingSphere);
RpMorphTargetSetBoundingSphere(wavyMorphTarget, &boundingSphere);
RpGeometryUnlock(wavyGeometry);
}
{
2020-05-27 18:50:01 +00:00
maskMorphTarget = RpGeometryGetMorphTarget(maskGeometry, 0);
maskVert = RpMorphTargetGetVertices(maskMorphTarget);
maskNormal = RpMorphTargetGetVertexNormals(maskMorphTarget);
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
for ( int32 i = 0; i < 33; i++ )
{
for ( int32 j = 0; j < 33; j++ )
{
(*maskVert).x = (float)i * 2.0f;
(*maskVert).y = (float)j * 2.0f;
(*maskVert).z = 0.0f;
(*maskNormal).x = 0.0f;
(*maskNormal).y = 0.0f;
(*maskNormal).z = 1.0f;
maskVert++;
maskNormal++;
}
}
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
RpMorphTargetCalcBoundingSphere(maskMorphTarget, &boundingSphere);
RpMorphTargetSetBoundingSphere(maskMorphTarget, &boundingSphere);
RpGeometryUnlock(maskGeometry);
}
{
wavyFrame = RwFrameCreate();
ms_pWavyAtomic = RpAtomicCreate();
2019-07-11 00:22:01 +00:00
RpAtomicSetGeometry(ms_pWavyAtomic, wavyGeometry, 0);
RpAtomicSetFrame(ms_pWavyAtomic, wavyFrame);
RpMaterialDestroy(wavyMaterial);
RpGeometryDestroy(wavyGeometry);
}
2020-05-27 18:50:01 +00:00
{
maskFrame = RwFrameCreate();
ms_pMaskAtomic = RpAtomicCreate();
RpAtomicSetGeometry(ms_pMaskAtomic, maskGeometry, 0);
RpAtomicSetFrame(ms_pMaskAtomic, maskFrame);
RpMaterialDestroy(maskMaterial);
RpGeometryDestroy(maskGeometry);
}
static RwFrame *wakeEnvFrame;
if ( wakeEnvFrame == NULL )
{
wakeEnvFrame = RwFrameCreate();
RwMatrixSetIdentity(RwFrameGetMatrix(wakeEnvFrame));
RwFrameUpdateObjects(wakeEnvFrame);
}
RpMatFXMaterialSetEffects(maskMaterial, rpMATFXEFFECTENVMAP);
RpMatFXMaterialSetupEnvMap(maskMaterial, gpWaterEnvTex, wakeEnvFrame, TRUE, fEnvScale);
RpMatFXAtomicEnableEffects(ms_pMaskAtomic);
2019-07-11 00:22:01 +00:00
}
void
CWaterLevel::DestroyWavyAtomic()
{
2020-05-27 18:50:01 +00:00
#define _DELETE_ATOMIC(a) \
{ \
RwFrame *frame; \
frame = RpAtomicGetFrame(a); \
RpAtomicDestroy(a); \
RwFrameDestroy(frame); \
}
_DELETE_ATOMIC(ms_pWavyAtomic);
_DELETE_ATOMIC(ms_pMaskAtomic);
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
#undef _DELETE_ATOMIC
2019-07-11 00:22:01 +00:00
}
bool
CWaterLevel::GetWaterLevel(float fX, float fY, float fZ, float *pfOutLevel, bool bDontCheckZ)
{
2020-05-27 18:50:01 +00:00
int32 x = WATER_TO_SMALL_SECTOR_X(fX + WATER_X_OFFSET);
int32 y = WATER_TO_SMALL_SECTOR_Y(fY);
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
ASSERT( x >= 0 && x < MAX_SMALL_SECTORS );
ASSERT( y >= 0 && y < MAX_SMALL_SECTORS );
if ( x < 0 || x >= MAX_SMALL_SECTORS ) return false;
if ( y < 0 || y >= MAX_SMALL_SECTORS ) return false;
2019-07-11 00:22:01 +00:00
uint8 nBlock = aWaterFineBlockList[x][y];
2020-05-27 18:50:01 +00:00
if ( nBlock == 0x80 )
2019-07-11 00:22:01 +00:00
return false;
ASSERT( pfOutLevel != NULL );
*pfOutLevel = ms_aWaterZs[nBlock];
float fAngle = (CTimer::GetTimeInMilliseconds() & 4095) * (TWOPI / 4096.0f);
2019-07-24 16:55:43 +00:00
float fWave = Sin
2019-07-11 00:22:01 +00:00
(
2020-05-27 18:50:01 +00:00
( WATER_UNSIGN_Y(fY) - y*SMALL_SECTOR_SIZE
+ WATER_UNSIGN_X(fX + WATER_X_OFFSET) - x*SMALL_SECTOR_SIZE )
2020-05-27 18:50:01 +00:00
* (TWOPI / SMALL_SECTOR_SIZE ) + fAngle
2019-07-11 00:22:01 +00:00
);
2020-05-27 18:50:01 +00:00
float fWindFactor = CWeather::WindClipped * 0.4f + 0.2f;
2019-07-11 00:22:01 +00:00
*pfOutLevel += fWave * fWindFactor;
if ( bDontCheckZ == false && (*pfOutLevel - fZ) > 3.0f )
{
*pfOutLevel = 0.0f;
return false;
}
return true;
}
bool
CWaterLevel::GetWaterLevelNoWaves(float fX, float fY, float fZ, float *pfOutLevel)
{
2020-05-27 18:50:01 +00:00
int32 x = WATER_TO_SMALL_SECTOR_X(fX + WATER_X_OFFSET);
int32 y = WATER_TO_SMALL_SECTOR_Y(fY);
ASSERT( x >= 0 && x < MAX_SMALL_SECTORS );
ASSERT( y >= 0 && y < MAX_SMALL_SECTORS );
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
if ( x < 0 || x >= MAX_SMALL_SECTORS ) return false;
if ( y < 0 || y >= MAX_SMALL_SECTORS ) return false;
2019-07-11 00:22:01 +00:00
uint8 nBlock = aWaterFineBlockList[x][y];
2020-05-27 18:50:01 +00:00
if ( nBlock == 0x80 )
2019-07-11 00:22:01 +00:00
return false;
ASSERT( pfOutLevel != NULL );
*pfOutLevel = ms_aWaterZs[nBlock];
return true;
}
2020-05-27 18:50:01 +00:00
float CWaterLevel::GetWaterWavesOnly(short x, short y)
{
float fAngle = (CTimer::GetTimeInMilliseconds() & 4095) * (TWOPI / 4096.0f);
float fWindFactor = CWeather::WindClipped * 0.7f + 0.3f;
float fWave = Sin( float(float(4 * y + 4 * x) * (TWOPI / SMALL_SECTOR_SIZE )) + fAngle );
return fWave * fWindFactor;
}
CVector CWaterLevel::GetWaterNormal(float fX, float fY)
2019-07-11 00:22:01 +00:00
{
2020-05-27 18:50:01 +00:00
//TODO: BUG ? ignore x offset
int32 x = WATER_TO_SMALL_SECTOR_X(fX);
int32 y = WATER_TO_SMALL_SECTOR_Y(fY);
float fAngle = (CTimer::GetTimeInMilliseconds() & 4095) * (TWOPI / 4096.0f);
float fWindFactor = CWeather::WindClipped * 0.4f + 0.2f;
//TODO:
float _fWave = (WATER_UNSIGN_Y(fY) - y*SMALL_SECTOR_SIZE + WATER_UNSIGN_X(fX) - x*SMALL_SECTOR_SIZE)
* (TWOPI / SMALL_SECTOR_SIZE ) + fAngle;
CVector vA(1.0f, 0.0f, fWindFactor * (TWOPI / SMALL_SECTOR_SIZE ) * Cos(_fWave));
CVector vB(0.0f, 1.0f, fWindFactor * (TWOPI / SMALL_SECTOR_SIZE ) * Cos(_fWave));
CVector norm = CrossProduct(vA, vB);
norm.Normalise();
return norm;
}
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
inline float _GetWaterDrawDist()
{
if ( TheCamera.GetPosition().z < 15.0f ) return 1200.0f;
if ( TheCamera.GetPosition().z > 60.0f ) return 2000.0f;
return ( TheCamera.GetPosition().z + -15.0f ) * 800.0f / 45.0f + 1200.0f;
2019-07-11 00:22:01 +00:00
}
inline float
_GetWavyDrawDist()
{
if ( FindPlayerVehicle() && FindPlayerVehicle()->IsBoat() )
return 120.0f;
else
return 70.0f;
}
inline void
_GetCamBounds(bool *bUseCamStartY, bool *bUseCamEndY, bool *bUseCamStartX, bool *bUseCamEndX)
{
if ( TheCamera.GetForward().z > -0.8f )
{
2019-07-24 16:55:43 +00:00
if ( Abs(TheCamera.GetForward().x) > Abs(TheCamera.GetForward().y) )
2019-07-11 00:22:01 +00:00
{
if ( TheCamera.GetForward().x > 0.0f )
*bUseCamStartX = true;
else
*bUseCamEndX = true;
}
else
{
if ( TheCamera.GetForward().y > 0.0f )
*bUseCamStartY = true;
else
*bUseCamEndY = true;
}
}
}
2020-05-27 18:50:01 +00:00
inline bool _IsColideWithBlock(int32 x, int32 y, int32 &block)
{
block = CWaterLevel::aWaterFineBlockList[x + 0][y + 0];
if (!(block & 0x80))
return true;
block = CWaterLevel::aWaterFineBlockList[x + 0][y + 1];
if (!(block & 0x80))
{
block = CWaterLevel::aWaterFineBlockList[x + 0][y + 2];
if (!(block & 0x80))
return true;
}
block = CWaterLevel::aWaterFineBlockList[x + 1][y + 0];
if (!(block & 0x80))
return true;
block = CWaterLevel::aWaterFineBlockList[x + 1][y + 1];
if (!(block & 0x80))
{
block = CWaterLevel::aWaterFineBlockList[x + 1][y + 2];
if (!(block & 0x80))
return true;
}
block = CWaterLevel::aWaterFineBlockList[x + 2][y + 0];
if (!(block & 0x80))
return true;
block = CWaterLevel::aWaterFineBlockList[x + 2][y + 1];
if (!(block & 0x80))
{
block = CWaterLevel::aWaterFineBlockList[x + 2][y + 2];
if (!(block & 0x80))
return true;
}
return false;
}
2019-07-24 17:30:09 +00:00
inline float
2019-07-11 00:22:01 +00:00
SectorRadius(float fSize)
{
2019-07-24 16:55:43 +00:00
return Sqrt(Pow(fSize, 2) + Pow(fSize, 2));
2019-07-11 00:22:01 +00:00
}
void
CWaterLevel::RenderWater()
{
bool bUseCamEndX = false;
bool bUseCamStartY = false;
bool bUseCamStartX = false;
bool bUseCamEndY = false;
2020-05-27 18:50:01 +00:00
if ( !CGame::CanSeeWaterFromCurrArea() )
return;
2019-07-11 00:22:01 +00:00
_GetCamBounds(&bUseCamStartY, &bUseCamEndY, &bUseCamStartX, &bUseCamEndX);
float fHugeSectorMaxRenderDist = _GetWaterDrawDist();
float fHugeSectorMaxRenderDistSqr = SQR(fHugeSectorMaxRenderDist);
2020-05-27 18:50:01 +00:00
float windAddUV = CWeather::WindClipped * 0.0005f + 0.0006f;
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
float fAngle = (CTimer::GetTimeInMilliseconds() & 4095) * (TWOPI / 4096.0f);
2019-07-11 00:22:01 +00:00
if ( !CTimer::GetIsPaused() )
{
2020-05-27 18:50:01 +00:00
TEXTURE_ADDU += windAddUV;
TEXTURE_ADDV += windAddUV;
_TEXTURE_MASK_ADDU += Sin(fAngle) * 0.0005f + 1.1f * windAddUV;
_TEXTURE_MASK_ADDV -= Cos(fAngle * 1.3f) * 0.0005f + 1.2f * windAddUV;
_TEXTURE_WAKE_ADDU -= Sin(fAngle) * 0.0003f + windAddUV;
_TEXTURE_WAKE_ADDV += Cos(fAngle * 0.7f) * 0.0003f + windAddUV;
2019-07-11 00:22:01 +00:00
}
2020-05-27 18:50:01 +00:00
if ( _TEXTURE_MASK_ADDU >= 1.0f )
_TEXTURE_MASK_ADDU = 0.0f;
if ( _TEXTURE_MASK_ADDV >= 1.0f )
_TEXTURE_MASK_ADDV = 0.0f;
if ( _TEXTURE_WAKE_ADDU >= 1.0f )
_TEXTURE_WAKE_ADDU = 0.0f;
if ( _TEXTURE_WAKE_ADDV >= 1.0f )
_TEXTURE_WAKE_ADDV = 0.0f;
2019-07-11 00:22:01 +00:00
if ( TEXTURE_ADDU >= 1.0f )
TEXTURE_ADDU = 0.0f;
if ( TEXTURE_ADDV >= 1.0f )
TEXTURE_ADDV = 0.0f;
2020-05-27 18:50:01 +00:00
#ifdef PC_WATER
_fWaterZOffset = CWeather::WindClipped * 0.5f + 0.25f;
#endif
2019-07-11 00:22:01 +00:00
RwRGBA color = { 0, 0, 0, 255 };
2020-05-07 11:38:14 +00:00
color.red = CTimeCycle::GetWaterRed();
color.green = CTimeCycle::GetWaterGreen();
color.blue = CTimeCycle::GetWaterBlue();
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
#ifndef PC_WATER
RwRGBA colorUnderwater = { 0, 0, 0, 255 };
colorUnderwater.red = (uint32)(0.8f * (float)colorUnderwater.red);
colorUnderwater.green = (uint32)(0.8f * (float)colorUnderwater.green);
colorUnderwater.blue = (uint32)(0.8f * (float)colorUnderwater.blue);
#endif
2019-07-11 00:22:01 +00:00
TempBufferVerticesStored = 0;
TempBufferIndicesStored = 0;
2020-05-27 18:50:01 +00:00
#ifndef PC_WATER
WavesCalculatedThisFrame = false;
#endif
2019-07-11 00:22:01 +00:00
RwRenderStateSet(rwRENDERSTATETEXTURERASTER, (void *)gpWaterRaster);
RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void *)TRUE);
RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDONE);
RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDZERO);
2020-05-27 18:50:01 +00:00
CVector2D camPos(TheCamera.GetPosition().x, TheCamera.GetPosition().y);
2019-07-11 00:22:01 +00:00
int32 nStartX = WATER_TO_HUGE_SECTOR_X(camPos.x - fHugeSectorMaxRenderDist + WATER_X_OFFSET);
int32 nEndX = WATER_TO_HUGE_SECTOR_X(camPos.x + fHugeSectorMaxRenderDist + WATER_X_OFFSET) + 1;
2019-07-11 00:22:01 +00:00
int32 nStartY = WATER_TO_HUGE_SECTOR_Y(camPos.y - fHugeSectorMaxRenderDist);
int32 nEndY = WATER_TO_HUGE_SECTOR_Y(camPos.y + fHugeSectorMaxRenderDist) + 1;
if ( bUseCamStartX )
nStartX = WATER_TO_HUGE_SECTOR_X(camPos.x + WATER_X_OFFSET);
2019-07-11 00:22:01 +00:00
if ( bUseCamEndX )
nEndX = WATER_TO_HUGE_SECTOR_X(camPos.x + WATER_X_OFFSET);
2019-07-11 00:22:01 +00:00
if ( bUseCamStartY )
nStartY = WATER_TO_HUGE_SECTOR_Y(camPos.y);
if ( bUseCamEndY )
nEndY = WATER_TO_HUGE_SECTOR_Y(camPos.y);
nStartX = clamp(nStartX, 0, MAX_HUGE_SECTORS - 1);
nEndX = clamp(nEndX, 0, MAX_HUGE_SECTORS - 1);
nStartY = clamp(nStartY, 0, MAX_HUGE_SECTORS - 1);
nEndY = clamp(nEndY, 0, MAX_HUGE_SECTORS - 1);
for ( int32 x = nStartX; x <= nEndX; x++ )
{
for ( int32 y = nStartY; y <= nEndY; y++ )
{
2020-05-27 18:50:01 +00:00
if ( !(aWaterBlockList[2*x+0][2*y+0] & 0x80)
|| !(aWaterBlockList[2*x+1][2*y+0] & 0x80)
|| !(aWaterBlockList[2*x+0][2*y+1] & 0x80)
|| !(aWaterBlockList[2*x+1][2*y+1] & 0x80) )
2019-07-11 00:22:01 +00:00
{
float fX = WATER_FROM_HUGE_SECTOR_X(x) - WATER_X_OFFSET;
2019-07-11 00:22:01 +00:00
float fY = WATER_FROM_HUGE_SECTOR_Y(y);
2020-05-27 18:50:01 +00:00
CVector2D vecHugeSectorCentre(fX + HUGE_SECTOR_SIZE/2,fY + HUGE_SECTOR_SIZE/2);
2019-07-11 00:22:01 +00:00
float fHugeSectorDistToCamSqr = (camPos - vecHugeSectorCentre).MagnitudeSqr();
2020-05-27 18:50:01 +00:00
2019-07-11 00:22:01 +00:00
if ( fHugeSectorMaxRenderDistSqr > fHugeSectorDistToCamSqr )
{
2020-05-27 18:50:01 +00:00
if ( TheCamera.IsSphereVisible(CVector(vecHugeSectorCentre.x, vecHugeSectorCentre.y, 0.0f), SectorRadius(HUGE_SECTOR_SIZE), &TheCamera.GetCameraMatrix()) )
2019-07-11 00:22:01 +00:00
{
2020-05-27 18:50:01 +00:00
#ifndef PC_WATER
WavesCalculatedThisFrame = true;
#endif
float fZ;
if ( !(aWaterBlockList[2*x+0][2*y+0] & 0x80) )
fZ = ms_aWaterZs[ aWaterBlockList[2*x+0][2*y+0] ];
if ( !(aWaterBlockList[2*x+1][2*y+0] & 0x80) )
fZ = ms_aWaterZs[ aWaterBlockList[2*x+1][2*y+0] ];
if ( !(aWaterBlockList[2*x+0][2*y+1] & 0x80) )
fZ = ms_aWaterZs[ aWaterBlockList[2*x+0][2*y+1] ];
if ( !(aWaterBlockList[2*x+1][2*y+1] & 0x80) )
fZ = ms_aWaterZs[ aWaterBlockList[2*x+1][2*y+1] ];
if ( fHugeSectorDistToCamSqr >= SQR(500.0f) )
2019-07-11 00:22:01 +00:00
{
RenderOneFlatHugeWaterPoly(fX, fY, fZ, color);
}
else
{
2020-05-27 18:50:01 +00:00
#ifndef PC_WATER
if (m_bRenderSeaBed)
RenderOneSlopedUnderWaterPoly(fX, fY, fZ, colorUnderwater);
#endif
// see RenderTransparentWater()
;
2019-07-11 00:22:01 +00:00
}
}
}
}
}
}
/*
----------- ---------------------- ----------------------
| [N] | | [ EndY ] | | [ top ] |
| | | | | |
|[W] [0] [E]| |[StartX] [] [ EndX ]| |[ left ] [] [ right]|
| | | | | |
| [S] | | [StartY] | | [bottom] |
----------- ---------------------- ----------------------
[S] [StartY] [bottom]
[N] [EndY] [top]
[W] [StartX] [left]
[E] [EndX] [right]
[S] -> [N] && [W] -> [E]
bottom -> top && left -> right
*/
for ( int32 x = 0; x < 26; x++ )
2019-07-11 00:22:01 +00:00
{
for ( int32 y = 0; y < 5; y++ )
2019-07-11 00:22:01 +00:00
{
float fX = WATER_SIGN_X(float(x) * EXTRAHUGE_SECTOR_SIZE) - 1280.0f - 400.0f;
float fY = WATER_SIGN_Y(float(y) * EXTRAHUGE_SECTOR_SIZE) - 1280.0f;
if ( !bUseCamStartY )
2019-07-11 00:22:01 +00:00
{
2020-05-27 18:50:01 +00:00
CVector2D vecExtraHugeSectorCentre(fX + EXTRAHUGE_SECTOR_SIZE/2, fY + EXTRAHUGE_SECTOR_SIZE/2);
2019-07-11 00:22:01 +00:00
float fCamDistToSector = (vecExtraHugeSectorCentre - camPos).Magnitude();
if ( fCamDistToSector < fHugeSectorMaxRenderDistSqr )
{
if ( TheCamera.IsSphereVisible(CVector(vecExtraHugeSectorCentre.x, vecExtraHugeSectorCentre.y, 0.0f), SectorRadius(EXTRAHUGE_SECTOR_SIZE), &TheCamera.GetCameraMatrix()) )
{
RenderOneFlatExtraHugeWaterPoly(
vecExtraHugeSectorCentre.x - EXTRAHUGE_SECTOR_SIZE/2,
vecExtraHugeSectorCentre.y - EXTRAHUGE_SECTOR_SIZE/2,
0.0f,
color);
}
}
}
if ( !bUseCamEndY )
{
2020-05-27 18:50:01 +00:00
CVector2D vecExtraHugeSectorCentre(fX + EXTRAHUGE_SECTOR_SIZE/2, -(fY + EXTRAHUGE_SECTOR_SIZE/2));
float fCamDistToSector = (vecExtraHugeSectorCentre - camPos).Magnitude();
if ( fCamDistToSector < fHugeSectorMaxRenderDistSqr )
{
if ( TheCamera.IsSphereVisible(CVector(vecExtraHugeSectorCentre.x, vecExtraHugeSectorCentre.y, 0.0f), SectorRadius(EXTRAHUGE_SECTOR_SIZE), &TheCamera.GetCameraMatrix()) )
2019-07-11 00:22:01 +00:00
{
RenderOneFlatExtraHugeWaterPoly(
vecExtraHugeSectorCentre.x - EXTRAHUGE_SECTOR_SIZE/2,
vecExtraHugeSectorCentre.y - EXTRAHUGE_SECTOR_SIZE/2,
0.0f,
color);
}
}
}
}
}
for ( int32 y = 5; y < 21; y++ )
{
for ( int32 x = 0; x < 5; x++ )
{
2020-05-27 18:50:01 +00:00
float fX = WATER_SIGN_X(float(x) * EXTRAHUGE_SECTOR_SIZE) - 1280.0f - WATER_X_OFFSET;
float fX2 = WATER_SIGN_X(float(x) * EXTRAHUGE_SECTOR_SIZE) - 1280.0f + WATER_X_OFFSET;
float fY = WATER_SIGN_Y(float(y) * EXTRAHUGE_SECTOR_SIZE) - 1280.0f;
2019-07-11 00:22:01 +00:00
if ( !bUseCamStartX )
{
2020-05-27 18:50:01 +00:00
CVector2D vecExtraHugeSectorCentre(fX + EXTRAHUGE_SECTOR_SIZE/2, fY + EXTRAHUGE_SECTOR_SIZE/2);
2019-07-11 00:22:01 +00:00
float fCamDistToSector = (vecExtraHugeSectorCentre - camPos).Magnitude();
if ( fCamDistToSector < fHugeSectorMaxRenderDistSqr )
{
if ( TheCamera.IsSphereVisible(CVector(vecExtraHugeSectorCentre.x, vecExtraHugeSectorCentre.y, 0.0f), SectorRadius(EXTRAHUGE_SECTOR_SIZE), &TheCamera.GetCameraMatrix()) )
2019-07-11 00:22:01 +00:00
{
RenderOneFlatExtraHugeWaterPoly(
vecExtraHugeSectorCentre.x - EXTRAHUGE_SECTOR_SIZE/2,
vecExtraHugeSectorCentre.y - EXTRAHUGE_SECTOR_SIZE/2,
0.0f,
color);
}
}
}
if ( !bUseCamEndX )
{
2020-05-27 18:50:01 +00:00
CVector2D vecExtraHugeSectorCentre(-(fX2 + EXTRAHUGE_SECTOR_SIZE/2), fY + EXTRAHUGE_SECTOR_SIZE/2);
2019-07-11 00:22:01 +00:00
float fCamDistToSector = (vecExtraHugeSectorCentre - camPos).Magnitude();
if ( fCamDistToSector < fHugeSectorMaxRenderDistSqr )
{
2020-05-27 18:50:01 +00:00
if ( TheCamera.IsSphereVisible(CVector(vecExtraHugeSectorCentre.x, vecExtraHugeSectorCentre.x, 0.0f), SectorRadius(EXTRAHUGE_SECTOR_SIZE), &TheCamera.GetCameraMatrix()) )
2019-07-11 00:22:01 +00:00
{
RenderOneFlatExtraHugeWaterPoly(
vecExtraHugeSectorCentre.x - EXTRAHUGE_SECTOR_SIZE/2,
vecExtraHugeSectorCentre.y - EXTRAHUGE_SECTOR_SIZE/2,
0.0f,
color);
}
}
}
}
}
2020-05-27 18:50:01 +00:00
RenderAndEmptyRenderBuffer();
RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDSRCALPHA);
RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDINVSRCALPHA);
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
if ( WavesCalculatedThisFrame )
2019-07-11 00:22:01 +00:00
{
2020-05-27 18:50:01 +00:00
RenderSeaBirds();
RenderShipsOnHorizon();
CParticle::HandleShipsAtHorizonStuff();
HandleBeachToysStuff();
}
if ( _bSeaLife )
HandleSeaLifeForms();
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
DefinedState();
}
void CWaterLevel::RenderTransparentWater(void)
{
bool bUseCamEndX = false;
bool bUseCamStartY = false;
bool bUseCamStartX = false;
bool bUseCamEndY = false;
_bSeaLife = false;
if ( !CGame::CanSeeWaterFromCurrArea() )
return;
float fWaterDrawDist = _GetWavyDrawDist();
float fWaterDrawDistLarge = fWaterDrawDist + 90.0f;
float fWavySectorMaxRenderDistSqr = SQR(fWaterDrawDist);
_GetCamBounds(&bUseCamStartY, &bUseCamEndY, &bUseCamStartX, &bUseCamEndX);
float fHugeSectorMaxRenderDist = _GetWaterDrawDist();
float fHugeSectorMaxRenderDistSqr = SQR(fHugeSectorMaxRenderDist);
RenderBoatWakes();
RwRGBA color;
color.red = CTimeCycle::GetWaterRed();
color.green = CTimeCycle::GetWaterGreen();
color.blue = CTimeCycle::GetWaterBlue();
color.alpha = 255;
RwRGBA colorTrans;
colorTrans.red = CTimeCycle::GetWaterRed();
colorTrans.green = CTimeCycle::GetWaterGreen();
colorTrans.blue = CTimeCycle::GetWaterBlue();
colorTrans.alpha = CTimeCycle::GetWaterAlpha();
TempBufferVerticesStored = 0;
TempBufferIndicesStored = 0;
#ifndef PC_WATER
WavesCalculatedThisFrame = false;
#endif
RwRenderStateSet(rwRENDERSTATETEXTURERASTER, (void *)gpWaterRaster);
#ifndef PC_WATER
RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void *)TRUE);
RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDSRCALPHA);
RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDINVSRCALPHA);
#endif
CVector2D camPos(TheCamera.GetPosition().x, TheCamera.GetPosition().y);
int32 nStartX = WATER_TO_HUGE_SECTOR_X(camPos.x - fHugeSectorMaxRenderDist + WATER_X_OFFSET);
int32 nEndX = WATER_TO_HUGE_SECTOR_X(camPos.x + fHugeSectorMaxRenderDist + WATER_X_OFFSET) + 1;
int32 nStartY = WATER_TO_HUGE_SECTOR_Y(camPos.y - fHugeSectorMaxRenderDist );
int32 nEndY = WATER_TO_HUGE_SECTOR_Y(camPos.y + fHugeSectorMaxRenderDist ) + 1;
if ( bUseCamStartX )
nStartX = WATER_TO_HUGE_SECTOR_X(camPos.x + WATER_X_OFFSET);
if ( bUseCamEndX )
nEndX = WATER_TO_HUGE_SECTOR_X(camPos.x + WATER_X_OFFSET);
if ( bUseCamStartY )
nStartY = WATER_TO_HUGE_SECTOR_Y(camPos.y );
if ( bUseCamEndY )
nEndY = WATER_TO_HUGE_SECTOR_Y(camPos.y );
nStartX = clamp(nStartX, 0, MAX_HUGE_SECTORS - 1);
nEndX = clamp(nEndX, 0, MAX_HUGE_SECTORS - 1);
nStartY = clamp(nStartY, 0, MAX_HUGE_SECTORS - 1);
nEndY = clamp(nEndY, 0, MAX_HUGE_SECTORS - 1);
for ( int32 x = nStartX; x <= nEndX; x++ )
{
for ( int32 y = nStartY; y <= nEndY; y++ )
2019-07-11 00:22:01 +00:00
{
2020-05-27 18:50:01 +00:00
if ( !(aWaterBlockList[2*x+0][2*y+0] & 0x80)
|| !(aWaterBlockList[2*x+1][2*y+0] & 0x80)
|| !(aWaterBlockList[2*x+0][2*y+1] & 0x80)
|| !(aWaterBlockList[2*x+1][2*y+1] & 0x80) )
2019-07-11 00:22:01 +00:00
{
2020-05-27 18:50:01 +00:00
float fX = WATER_FROM_HUGE_SECTOR_X(x) - WATER_X_OFFSET;
float fY = WATER_FROM_HUGE_SECTOR_Y(y);
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
CVector2D vecHugeSectorCentre
(
fX + HUGE_SECTOR_SIZE/2,
fY + HUGE_SECTOR_SIZE/2
);
float fHugeSectorDistToCamSqr = (camPos - vecHugeSectorCentre).MagnitudeSqr();
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
if ( fHugeSectorMaxRenderDistSqr > fHugeSectorDistToCamSqr )
{
if ( TheCamera.IsSphereVisible(CVector(vecHugeSectorCentre.x, vecHugeSectorCentre.y, 0.0f), SectorRadius(HUGE_SECTOR_SIZE), &TheCamera.GetCameraMatrix()) )
{
if ( fHugeSectorDistToCamSqr >= SQR(500.0f) )
{
// see RenderWater()
;
}
else
{
for ( int32 x2 = 2*x; x2 <= 2*x+1; x2++ )
{
for ( int32 y2 = 2*y; y2 <= 2*y+1; y2++ )
{
if ( !(aWaterBlockList[x2][y2] & 0x80) )
{
float fLargeX = WATER_FROM_LARGE_SECTOR_X(x2) - WATER_X_OFFSET;
float fLargeY = WATER_FROM_LARGE_SECTOR_Y(y2);
CVector2D vecLargeSectorCentre(fLargeX + LARGE_SECTOR_SIZE/2, fLargeY + LARGE_SECTOR_SIZE/2);
float fLargeSectorDistToCamSqr = (camPos - vecLargeSectorCentre).MagnitudeSqr();
if ( fLargeSectorDistToCamSqr < fHugeSectorMaxRenderDistSqr )
{
if ( TheCamera.IsSphereVisible(CVector(vecLargeSectorCentre.x, vecLargeSectorCentre.y, 0.0f), SectorRadius(LARGE_SECTOR_SIZE), &TheCamera.GetCameraMatrix()) )
{
// Render four small(32x32) sectors, or one large(64x64).
//
// [N]
// ---------
// |0x1|1x1|
// [W] --------- [E]
// |0x0|1x0|
// ---------
// [S]
//
float fLargeSectorDrawDistSqr = SQR((fWaterDrawDistLarge + 16.0f));
if ( fLargeSectorDistToCamSqr < fLargeSectorDrawDistSqr )
{
_bSeaLife = true;
float fZ;
// WS
if ( !(aWaterFineBlockList[2*x2+0][2*y2+0] & 0x80) )
{
float fSmallX = fLargeX;
float fSmallY = fLargeY;
CVector2D vecSmallSectorCentre(fSmallX + SMALL_SECTOR_SIZE/2, fSmallY + SMALL_SECTOR_SIZE/2);
float fSmallSectorDistToCamSqr = (camPos - vecSmallSectorCentre).MagnitudeSqr();
fZ = ms_aWaterZs[ aWaterFineBlockList[2*x2+0][2*y2+0] ];
if ( fSmallSectorDistToCamSqr < fWavySectorMaxRenderDistSqr )
RenderOneWavySector(fSmallX, fSmallY, fZ, colorTrans);
else
RenderOneFlatSmallWaterPolyBlended(fSmallX, fSmallY, fZ, camPos.x, camPos.y, color, colorTrans, fWaterDrawDist);
}
// SE
if ( !(aWaterFineBlockList[2*x2+1][2*y2+0] & 0x80) )
{
float fSmallX = fLargeX + (LARGE_SECTOR_SIZE/2);
float fSmallY = fLargeY;
CVector2D vecSmallSectorCentre(fSmallX + SMALL_SECTOR_SIZE/2, fSmallY + SMALL_SECTOR_SIZE/2);
float fSmallSectorDistToCamSqr = (camPos - vecSmallSectorCentre).MagnitudeSqr();
fZ = ms_aWaterZs[ aWaterFineBlockList[2*x2+1][2*y2+0] ];
if ( fSmallSectorDistToCamSqr < fWavySectorMaxRenderDistSqr )
RenderOneWavySector(fSmallX, fSmallY, fZ, colorTrans);
else
RenderOneFlatSmallWaterPolyBlended(fSmallX, fSmallY, fZ, camPos.x, camPos.y, color, colorTrans, fWaterDrawDist);
}
// WN
if ( !(aWaterFineBlockList[2*x2+0][2*y2+1] & 0x80) )
{
float fSmallX = fLargeX;
float fSmallY = fLargeY + (LARGE_SECTOR_SIZE/2);
CVector2D vecSmallSectorCentre(fSmallX + SMALL_SECTOR_SIZE/2,fSmallY + SMALL_SECTOR_SIZE/2);
float fSmallSectorDistToCamSqr = (camPos - vecSmallSectorCentre).MagnitudeSqr();
fZ = ms_aWaterZs[ aWaterFineBlockList[2*x2+0][2*y2+1] ];
if ( fSmallSectorDistToCamSqr < fWavySectorMaxRenderDistSqr )
RenderOneWavySector(fSmallX, fSmallY, fZ, colorTrans);
else
RenderOneFlatSmallWaterPolyBlended(fSmallX, fSmallY, fZ, camPos.x, camPos.y, color, colorTrans, fWaterDrawDist);
}
//NE
if ( !(aWaterFineBlockList[2*x2+1][2*y2+1] & 0x80) )
{
float fSmallX = fLargeX + (LARGE_SECTOR_SIZE/2);
float fSmallY = fLargeY + (LARGE_SECTOR_SIZE/2);
CVector2D vecSmallSectorCentre(fSmallX + SMALL_SECTOR_SIZE/2, fSmallY + SMALL_SECTOR_SIZE/2);
float fSmallSectorDistToCamSqr = (camPos - vecSmallSectorCentre).MagnitudeSqr();
fZ = ms_aWaterZs[ aWaterFineBlockList[2*x2+1][2*y2+1] ];
if ( fSmallSectorDistToCamSqr < fWavySectorMaxRenderDistSqr )
RenderOneWavySector(fSmallX, fSmallY, fZ, colorTrans);
else
RenderOneFlatSmallWaterPolyBlended(fSmallX, fSmallY, fZ, camPos.x, camPos.y, color, colorTrans, fWaterDrawDist);
}
}
else
{
float fZ;
fZ = ms_aWaterZs[ aWaterBlockList[x2][y2] ];
RenderOneFlatLargeWaterPoly(fLargeX, fLargeY, fZ, color);
}
}
}
}
}
}
}
}
}
2019-07-11 00:22:01 +00:00
}
}
}
2020-05-27 18:50:01 +00:00
RenderAndEmptyRenderBuffer();
#ifdef PC_WATER
if ( MaskCalculatedThisFrame
&& (m_nRenderWaterLayers == 0 || m_nRenderWaterLayers == 2 || m_nRenderWaterLayers == 3) )
{
RwV3d pos = { 0.0f, 0.0f, 0.0f };
pos.x = PreCalculatedMaskPosn.x;
pos.y = PreCalculatedMaskPosn.y;
pos.z = PreCalculatedMaskPosn.z;
RpMatFXMaterialSetEnvMapFrame(RpGeometryGetMaterial(RpAtomicGetGeometry(ms_pMaskAtomic), 0),
RwCameraGetFrame(RwCameraGetCurrentCamera()));
RwFrameTranslate(RpAtomicGetFrame(ms_pMaskAtomic), &pos, rwCOMBINEREPLACE);
RpAtomicRender(ms_pMaskAtomic);
}
#else
if (!CCullZones::WaterFudge())
{
int32 signX = 0;
int32 signY = 0;
float fCamX = camPos.x - SMALL_SECTOR_SIZE;
float fCamY = camPos.y - SMALL_SECTOR_SIZE;
if (TheCamera.GetForward().x > 0.3f)
signX = 1;
else if (TheCamera.GetForward().x < -0.3f)
signX = -1;
fCamX += 0.3f * (float)signX * float(SMALL_SECTOR_SIZE * 2.0f); // 19.2f
if (TheCamera.GetForward().y > 0.3f)
signY = 1;
else if (TheCamera.GetForward().y < -0.3f)
signY = -1;
fCamY += 0.3f * (float)signY * float(SMALL_SECTOR_SIZE * 2.0f); // 19.2f
int32 nBlock;
int32 BlockX = WATER_TO_SMALL_SECTOR_X(fCamX + 400.0f) + 1;
int32 BlockY = WATER_TO_SMALL_SECTOR_Y(fCamY) + 1;
if (_IsColideWithBlock(BlockX, BlockY, nBlock))
{
if (m_nRenderWaterLayers != 1 && m_nRenderWaterLayers != 6)
{
float fMaskX = floorf(fCamX / 2.0f) * 2.0f;
float fMaskY = floorf(fCamY / 2.0f) * 2.0f;
float fWaterZ = CWaterLevel::ms_aWaterZs[nBlock];
float fSectorX = WATER_FROM_SMALL_SECTOR_X(BlockX) - 400.0f;
float fSectorY = WATER_FROM_SMALL_SECTOR_Y(BlockY);
RenderWavyMask(fMaskX, fMaskY, fWaterZ,
fSectorX, fSectorY,
signX, signY, colorTrans);
}
}
}
2019-07-11 00:22:01 +00:00
DefinedState();
2020-05-27 18:50:01 +00:00
#endif
2019-07-11 00:22:01 +00:00
}
2020-05-27 18:50:01 +00:00
void CWaterLevel::RenderOneFlatSmallWaterPoly(float fX, float fY, float fZ, RwRGBA const &color)
2019-07-11 00:22:01 +00:00
{
if ( TempBufferIndicesStored >= TEMPBUFFERINDEXSIZE-6 || TempBufferVerticesStored >= TEMPBUFFERVERTSIZE-4 )
RenderAndEmptyRenderBuffer();
int32 vidx = TempBufferVerticesStored;
2020-05-27 18:50:01 +00:00
RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 0], fX, fY, fZ - _fWaterZOffset);
2019-07-11 00:22:01 +00:00
RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 0], TEXTURE_ADDU);
RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 0], TEXTURE_ADDV);
2020-05-27 18:50:01 +00:00
RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 0], color);
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 1], fX, fY + SMALL_SECTOR_SIZE, fZ - _fWaterZOffset);
2019-07-11 00:22:01 +00:00
RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 1], TEXTURE_ADDU);
RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 1], TEXTURE_ADDV + 1.0f);
2020-05-27 18:50:01 +00:00
RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 1], color);
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 2], fX + SMALL_SECTOR_SIZE, fY + SMALL_SECTOR_SIZE, fZ - _fWaterZOffset);
2019-07-11 00:22:01 +00:00
RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 2], TEXTURE_ADDU + 1.0f);
RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 2], TEXTURE_ADDV + 1.0f);
2020-05-27 18:50:01 +00:00
RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 2], color);
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 3], fX + SMALL_SECTOR_SIZE, fY, fZ - _fWaterZOffset);
2019-07-11 00:22:01 +00:00
RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 3], TEXTURE_ADDU + 1.0f);
RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 3], TEXTURE_ADDV);
2020-05-27 18:50:01 +00:00
RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 3], color);
2019-07-11 00:22:01 +00:00
int32 iidx = TempBufferIndicesStored;
TempBufferRenderIndexList[iidx + 0] = TempBufferVerticesStored + 0;
TempBufferRenderIndexList[iidx + 1] = TempBufferVerticesStored + 2;
TempBufferRenderIndexList[iidx + 2] = TempBufferVerticesStored + 1;
TempBufferRenderIndexList[iidx + 3] = TempBufferVerticesStored + 0;
TempBufferRenderIndexList[iidx + 4] = TempBufferVerticesStored + 3;
TempBufferRenderIndexList[iidx + 5] = TempBufferVerticesStored + 2;
TempBufferVerticesStored += 4;
TempBufferIndicesStored += 6;
}
2020-05-27 18:50:01 +00:00
void CWaterLevel::RenderOneFlatLargeWaterPoly(float fX, float fY, float fZ, RwRGBA const &color)
2019-07-11 00:22:01 +00:00
{
if ( TempBufferIndicesStored >= TEMPBUFFERINDEXSIZE-6 || TempBufferVerticesStored >= TEMPBUFFERVERTSIZE-4 )
RenderAndEmptyRenderBuffer();
int32 vidx = TempBufferVerticesStored;
2020-05-27 18:50:01 +00:00
RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 0], fX, fY, fZ - _fWaterZOffset);
2019-07-11 00:22:01 +00:00
RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 0], TEXTURE_ADDU);
RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 0], TEXTURE_ADDV);
2020-05-27 18:50:01 +00:00
RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 0], color);
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 1], fX, fY + LARGE_SECTOR_SIZE, fZ - _fWaterZOffset);
2019-07-11 00:22:01 +00:00
RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 1], TEXTURE_ADDU);
RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 1], TEXTURE_ADDV + 2.0f);
2020-05-27 18:50:01 +00:00
RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 1], color);
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 2], fX + LARGE_SECTOR_SIZE, fY + LARGE_SECTOR_SIZE, fZ - _fWaterZOffset);
2019-07-11 00:22:01 +00:00
RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 2], TEXTURE_ADDU + 2.0f);
RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 2], TEXTURE_ADDV + 2.0f);
2020-05-27 18:50:01 +00:00
RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 2], color);
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 3], fX + LARGE_SECTOR_SIZE, fY, fZ - _fWaterZOffset);
2019-07-11 00:22:01 +00:00
RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 3], TEXTURE_ADDU + 2.0f);
RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 3], TEXTURE_ADDV);
2020-05-27 18:50:01 +00:00
RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 3], color);
2019-07-11 00:22:01 +00:00
int32 iidx = TempBufferIndicesStored;
TempBufferRenderIndexList[iidx + 0] = TempBufferVerticesStored + 0;
TempBufferRenderIndexList[iidx + 1] = TempBufferVerticesStored + 2;
TempBufferRenderIndexList[iidx + 2] = TempBufferVerticesStored + 1;
TempBufferRenderIndexList[iidx + 3] = TempBufferVerticesStored + 0;
TempBufferRenderIndexList[iidx + 4] = TempBufferVerticesStored + 3;
TempBufferRenderIndexList[iidx + 5] = TempBufferVerticesStored + 2;
TempBufferVerticesStored += 4;
TempBufferIndicesStored += 6;
}
2020-05-27 18:50:01 +00:00
void CWaterLevel::RenderOneFlatHugeWaterPoly(float fX, float fY, float fZ, RwRGBA const &color)
2019-07-11 00:22:01 +00:00
{
if ( TempBufferIndicesStored >= TEMPBUFFERINDEXSIZE-6 || TempBufferVerticesStored >= TEMPBUFFERVERTSIZE-4 )
RenderAndEmptyRenderBuffer();
int32 vidx = TempBufferVerticesStored;
2020-05-27 18:50:01 +00:00
RwRGBA c;
c.red = color.red;
c.green = color.green;
c.blue = color.blue;
c.alpha = 255;
RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 0], fX, fY, fZ - _fWaterZOffset);
2019-07-11 00:22:01 +00:00
RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 0], TEXTURE_ADDU);
RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 0], TEXTURE_ADDV);
2020-05-27 18:50:01 +00:00
RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 0], c);
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 1], fX, fY + HUGE_SECTOR_SIZE, fZ - _fWaterZOffset);
2019-07-11 00:22:01 +00:00
RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 1], TEXTURE_ADDU);
RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 1], TEXTURE_ADDV + 4.0f);
2020-05-27 18:50:01 +00:00
RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 1], c);
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 2], fX + HUGE_SECTOR_SIZE, fY + HUGE_SECTOR_SIZE, fZ - _fWaterZOffset);
2019-07-11 00:22:01 +00:00
RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 2], TEXTURE_ADDU + 4.0f);
RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 2], TEXTURE_ADDV + 4.0f);
2020-05-27 18:50:01 +00:00
RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 2], c);
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 3], fX + HUGE_SECTOR_SIZE, fY, fZ - _fWaterZOffset);
2019-07-11 00:22:01 +00:00
RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 3], TEXTURE_ADDU + 4.0f);
RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 3], TEXTURE_ADDV);
2020-05-27 18:50:01 +00:00
RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 3], c);
2019-07-11 00:22:01 +00:00
int32 iidx = TempBufferIndicesStored;
TempBufferRenderIndexList[iidx + 0] = TempBufferVerticesStored + 0;
TempBufferRenderIndexList[iidx + 1] = TempBufferVerticesStored + 2;
TempBufferRenderIndexList[iidx + 2] = TempBufferVerticesStored + 1;
TempBufferRenderIndexList[iidx + 3] = TempBufferVerticesStored + 0;
TempBufferRenderIndexList[iidx + 4] = TempBufferVerticesStored + 3;
TempBufferRenderIndexList[iidx + 5] = TempBufferVerticesStored + 2;
TempBufferVerticesStored += 4;
TempBufferIndicesStored += 6;
}
2020-05-27 18:50:01 +00:00
void CWaterLevel::RenderOneFlatExtraHugeWaterPoly(float fX, float fY, float fZ, RwRGBA const &color)
2019-07-11 00:22:01 +00:00
{
if ( TempBufferIndicesStored >= TEMPBUFFERINDEXSIZE-6 || TempBufferVerticesStored >= TEMPBUFFERVERTSIZE-4 )
RenderAndEmptyRenderBuffer();
int32 vidx = TempBufferVerticesStored;
2020-05-27 18:50:01 +00:00
RwRGBA c;
c.red = color.red;
c.green = color.green;
c.blue = color.blue;
c.alpha = 255;
RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 0], fX, fY, fZ - _fWaterZOffset);
2019-07-11 00:22:01 +00:00
RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 0], TEXTURE_ADDU);
RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 0], TEXTURE_ADDV);
2020-05-27 18:50:01 +00:00
RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 0], c);
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 1], fX, fY + EXTRAHUGE_SECTOR_SIZE, fZ - _fWaterZOffset);
2019-07-11 00:22:01 +00:00
RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 1], TEXTURE_ADDU);
RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 1], TEXTURE_ADDV + 8.0f);
2020-05-27 18:50:01 +00:00
RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 1], c);
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 2], fX + EXTRAHUGE_SECTOR_SIZE, fY + EXTRAHUGE_SECTOR_SIZE, fZ - _fWaterZOffset);
2019-07-11 00:22:01 +00:00
RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 2], TEXTURE_ADDU + 8.0f);
RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 2], TEXTURE_ADDV + 8.0f);
2020-05-27 18:50:01 +00:00
RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 2], c);
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 3], fX + EXTRAHUGE_SECTOR_SIZE, fY, fZ - _fWaterZOffset);
2019-07-11 00:22:01 +00:00
RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 3], TEXTURE_ADDU + 8.0f);
RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 3], TEXTURE_ADDV);
2020-05-27 18:50:01 +00:00
RwIm3DVertexSet_RGBA(&TempBufferRenderVertices[vidx + 3], c);
2019-07-11 00:22:01 +00:00
int32 iidx = TempBufferIndicesStored;
TempBufferRenderIndexList[iidx + 0] = TempBufferVerticesStored + 0;
TempBufferRenderIndexList[iidx + 1] = TempBufferVerticesStored + 2;
TempBufferRenderIndexList[iidx + 2] = TempBufferVerticesStored + 1;
TempBufferRenderIndexList[iidx + 3] = TempBufferVerticesStored + 0;
TempBufferRenderIndexList[iidx + 4] = TempBufferVerticesStored + 3;
TempBufferRenderIndexList[iidx + 5] = TempBufferVerticesStored + 2;
TempBufferVerticesStored += 4;
TempBufferIndicesStored += 6;
}
2020-05-27 18:50:01 +00:00
void CWaterLevel::RenderOneWavySector(float fX, float fY, float fZ, RwRGBA const &color, bool bDontRender)
2019-07-11 00:22:01 +00:00
{
2020-05-27 18:50:01 +00:00
CVector vecSectorPos(fX + (SMALL_SECTOR_SIZE/2), fY + (SMALL_SECTOR_SIZE/2), fZ + 2.0f);
if ( COcclusion::IsAABoxOccluded(vecSectorPos, SMALL_SECTOR_SIZE, SMALL_SECTOR_SIZE, 4.0f) )
return;
#ifdef PC_WATER
RequireWavySector = true;
#else
if (!WavesCalculatedThisFrame)
2019-07-11 00:22:01 +00:00
{
WavesCalculatedThisFrame = true;
2020-05-27 18:50:01 +00:00
float fAngle = (CTimer::GetTimeInMilliseconds() & 4095) * (TWOPI / 4096.0f);
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
RpGeometry *wavyGeometry = RpAtomicGetGeometry(ms_pWavyAtomic);
RwTexCoords *wavyTexCoords = RpGeometryGetVertexTexCoords(wavyGeometry, rwTEXTURECOORDINATEINDEX0);
RpMorphTarget *wavyMorph = RpGeometryGetMorphTarget(wavyGeometry, 0);
RwRGBA *wavyPreLight = RpGeometryGetPreLightColors(wavyGeometry);
RwV3d *wavyMorphVerts = RpMorphTargetGetVertices(wavyMorph);
RwV3d *wavyMorphNormals = RpMorphTargetGetVertexNormals(wavyMorph);
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
RpGeometryLock(wavyGeometry, rpGEOMETRYLOCKVERTICES | rpGEOMETRYLOCKNORMALS | rpGEOMETRYLOCKPRELIGHT | rpGEOMETRYLOCKTEXCOORDS);
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
RwMatrix *camMat = RwFrameGetLTM(RwCameraGetFrame(RwCameraGetCurrentCamera())); //or curWorld
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
float randomDampInv2 = (1.0f - fRandomDamp) * 2.0f;
float move = 1.0f / 16.0f;
float randomMove = 1.0f / (16.0f * fRandomMoveDiv);
float vertMul = 0.5f;
float wind = CWeather::WindClipped * 0.4f + 0.2f;
float waveWind = CWeather::WindClipped * fWave2Ampl + 0.05f;
float waveA = (TWOPI / 16.0f)
* ((fNormalDirectionScalar1 * fabs(camMat->at.x + camMat->at.y) + fNormMult) * (CWeather::WindClipped * 0.4f + 0.2f));
float waveB = TWOPI / (16.0f * fWave2NormScale)
* ((fNormalDirectionScalar2 * fabs(camMat->at.y - camMat->at.x) + fNormMultB) * (CWeather::WindClipped * 0.2f + 0.1f));
CVector vA(1.0f, 0.0f, 0.0f);
CVector vB(0.0f, 1.0f, 0.0f);
for ( int32 i = 0; i < 17; i++ )
2019-07-11 00:22:01 +00:00
{
2020-05-27 18:50:01 +00:00
for ( int32 j = 0; j < 17; j++ )
2019-07-11 00:22:01 +00:00
{
2020-05-27 18:50:01 +00:00
wavyTexCoords->u = float(i) * move + TEXTURE_ADDV;
wavyTexCoords->v = float(j) * move + TEXTURE_ADDU;
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
RwRGBAAssign(wavyPreLight, &color);
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
if (i > 0 && i < 16 && j > 0 && j < 16)
2019-07-11 00:22:01 +00:00
{
2020-05-27 18:50:01 +00:00
wavyMorphVerts->x += CGeneral::GetRandomNumberInRange(-1.0f, 1.0f) * randomMove;
wavyMorphVerts->x *= fRandomDamp;
wavyMorphVerts->x += float(i) * randomDampInv2;
wavyMorphVerts->y += CGeneral::GetRandomNumberInRange(-1.0f, 1.0f) * randomMove;
wavyMorphVerts->y *= fRandomDamp;
wavyMorphVerts->y += float(j) * randomDampInv2;
2019-07-11 00:22:01 +00:00
}
2020-05-27 18:50:01 +00:00
float morphVertXHalf = (i == 16) ? 0.0f : vertMul * wavyMorphVerts->x;
float morphVertYHalf = (j == 16) ? 0.0f : vertMul * wavyMorphVerts->y;
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
float waveMulA = (morphVertYHalf + morphVertXHalf) * (TWOPI / 16.0f) + fAngle;
float waveMulB = (morphVertYHalf - morphVertXHalf) * (TWOPI / (16.0f * fWave2InvLength)) + fAngle;
wavyMorphVerts->z = wind * Sin(waveMulA) + waveWind * Sin(waveMulB);
vA.z = (waveA * Cos(waveMulA)) - (waveB * cos(waveMulB));
vB.z = (waveA * Cos(waveMulA)) + (waveB * cos(waveMulB));
CVector norm = CrossProduct(vA, vB);
norm.Normalise();
wavyMorphNormals->x = norm.x;
wavyMorphNormals->y = norm.y;
wavyMorphNormals->z = norm.z;
++wavyPreLight;
++wavyTexCoords;
++wavyMorphVerts;
++wavyMorphNormals;
2019-07-11 00:22:01 +00:00
}
}
2020-05-27 18:50:01 +00:00
RpGeometryUnlock(wavyGeometry);
}
float fCentreX = fX + (SMALL_SECTOR_SIZE / 2);
float fCentreY = fY + (SMALL_SECTOR_SIZE / 2);
#endif
#ifdef PC_WATER
if ( WavesCalculatedThisFrame )
#endif
{
if (bDontRender == false
&& m_nRenderWaterLayers != 2
&& m_nRenderWaterLayers != 4
&& m_nRenderWaterLayers != 6 )
{
RwV3d pos = { 0.0f, 0.0f, 0.0f };
pos.x = fX;
pos.y = fY;
pos.z = fZ;
RwFrameTranslate(RpAtomicGetFrame(ms_pWavyAtomic), &pos, rwCOMBINEREPLACE);
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
RpAtomicRender(ms_pWavyAtomic);
}
}
}
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
int16 _RoundValue(int32 v)
{
int16 result = v;
while ( result < 0 ) result += 16;
while ( result > 16 ) result -= 16;
return result;
}
void CWaterLevel::RenderWavyMask(float fX, float fY, float fZ,
float fSectorX, float fSectorY,
#ifdef PC_WATER
float fCamPosX, float fCamPosY,
float fCamDirX, float fCamDirY, RwRGBA const&color)
#else
int32 nCamDirX, int32 nCamDirY, RwRGBA const&color)
#endif
{
#ifndef PC_WATER
bool bRender = true;
if (m_nRenderWaterLayers != 0 && m_nRenderWaterLayers != 2 && m_nRenderWaterLayers != 3)
bRender = false;
#endif
CVector vecSectorPos(fX + (LARGE_SECTOR_SIZE/2), fY + (LARGE_SECTOR_SIZE/2), fZ + 2.0f);
if ( COcclusion::IsAABoxOccluded(vecSectorPos, LARGE_SECTOR_SIZE, LARGE_SECTOR_SIZE, 4.0f) )
return;
#ifndef PC_WATER
float fUOffset = fX - (MAX_LARGE_SECTORS * (int32)floorf(fX / MAX_LARGE_SECTORS));
float fVOffset = fY - (MAX_LARGE_SECTORS * (int32)floorf(fY / MAX_LARGE_SECTORS));
int32 nSecsX = (int32)((fX - fSectorX) / 2.0f);
int32 nSecsY = (int32)((fY - fSectorY) / 2.0f);
#endif
RpGeometry *wavyGeometry = RpAtomicGetGeometry(ms_pWavyAtomic);
RpMorphTarget *wavyMorph = RpGeometryGetMorphTarget(wavyGeometry, 0);
RwV3d *wavyMorphVerts = RpMorphTargetGetVertices(wavyMorph);
RwV3d *wavyMorphNormals = RpMorphTargetGetVertexNormals(wavyMorph);
RpGeometry *maskGeometry = RpAtomicGetGeometry(ms_pMaskAtomic);
RwTexCoords *maskTexCoords = RpGeometryGetVertexTexCoords(maskGeometry, rwTEXTURECOORDINATEINDEX0);
RwRGBA *maskPreLight = RpGeometryGetPreLightColors(maskGeometry);
RpMorphTarget *maskMorph = RpGeometryGetMorphTarget(maskGeometry, 0);
RwV3d *maskMorphVerts = RpMorphTargetGetVertices(maskMorph);
RwV3d *maskMorphNormals = RpMorphTargetGetVertexNormals(maskMorph);
RpGeometryLock(maskGeometry, rpGEOMETRYLOCKVERTICES|rpGEOMETRYLOCKNORMALS|rpGEOMETRYLOCKPRELIGHT|rpGEOMETRYLOCKTEXCOORDS);
#ifndef PC_WATER
RpMaterial *maskMat = RpGeometryGetMaterial(maskGeometry, 0);
RpMatFXMaterialSetEnvMapFrame(maskMat, RwCameraGetFrame(RwCameraGetCurrentCamera()));
RpMatFXMaterialSetEnvMapCoefficient(maskMat, fEnvScale);
RpMatFXMaterialSetEnvMapFrameBufferAlpha(maskMat, TRUE);
#endif
#ifndef PC_WATER
float fMinSparkZ = (CWeather::WindClipped * fWave2Ampl + 0.05f +
CWeather::WindClipped * 0.4f + 0.2) * (1.0f - 0.04f * CWeather::SunGlare);
int32 randval = CGeneral::GetRandomNumber();
float fUVStep = 0.125f;
float f27 = 2.0f;
float fMinU = (fUOffset / 16.0f) + _TEXTURE_MASK_ADDU;
float fMinV = (fVOffset / 16.0f) + _TEXTURE_MASK_ADDV;
float fAlphaMul = ((float)color.alpha * 0.4f) / 16.0f;
float fXOffset = 16.0f;
if (nCamDirX > 0)
fXOffset = 6.4f;
else if (nCamDirX < 0)
fXOffset = 25.6f;
float fYOffset = 16.0f;
if (nCamDirY > 0)
fYOffset = 6.4f;
else if (nCamDirY < 0)
fYOffset = 25.6f;
int16 nX = _RoundValue(nSecsX - 1);
int16 nY = _RoundValue(nSecsY - 1);
#else
float fMinSparkZ = (fWave2Ampl * CWeather::WindClipped + 0.05f +
0.4f * CWeather::WindClipped + 0.2) * (1.0f - 0.02f * CWeather::SunGlare);
int32 randval = CGeneral::GetRandomNumber() & 255;
int16 nX = _RoundValue((int32)((fX - fSectorX) * 0.5f) - 1);
int16 nY = _RoundValue((int32)((fY - fSectorY) * 0.5f) - 1);
#endif
int16 idxX = nX;
for ( int32 i = 0; i < 17; i++ )
{
int16 idxY = nY;
if ( ++idxX > 16 )
idxX -= 16;
for ( int32 j = 0; j < 17; j++ )
{
if ( ++idxY > 16 )
idxY -= 16;
const int32 a = (0*16);
const int32 b = (1*16);
const int32 c = (33*16);
const int32 d = (34*16);
int32 base = (i*33+j);
#ifndef PC_WATER
maskTexCoords[base + a].u = fMinU + ((float)i * fUVStep);
maskTexCoords[base + a].v = fMinV + ((float)j * fUVStep);
maskTexCoords[base + b].u = maskTexCoords[base + a].u;
maskTexCoords[base + b].v = maskTexCoords[base + a].v + (16.0f * fUVStep);
maskTexCoords[base + c].u = maskTexCoords[base + a].u + (16.0f * fUVStep);
maskTexCoords[base + c].v = maskTexCoords[base + a].v;
maskTexCoords[base + d].u = maskTexCoords[base + a].u + (16.0f * fUVStep);
maskTexCoords[base + d].v = maskTexCoords[base + a].v + (16.0f * fUVStep);
#else
maskTexCoords[base+a].v = float(j) / SMALL_SECTOR_SIZE + ((fCamPosY - fY) / 64);
maskTexCoords[base+c].v = maskTexCoords[base+a].v;
maskTexCoords[base+d].v = maskTexCoords[base+a].v + 0.5f;
maskTexCoords[base+b].v = maskTexCoords[base+d].v;
maskTexCoords[base+a].u = float(i) / SMALL_SECTOR_SIZE + ((fCamPosX - fX) / 64);
maskTexCoords[base+b].u = maskTexCoords[base+a].u;
maskTexCoords[base+d].u = maskTexCoords[base+a].u + 0.5f;
maskTexCoords[base+c].u = maskTexCoords[base+d].u;
#endif
maskMorphVerts[base+a].x = (wavyMorphVerts[idxY + (17 * idxX)].x - (float)idxX * 2.0f) + (float(i) * 2.0f);
maskMorphVerts[base+b].x = maskMorphVerts[base+a].x;
maskMorphVerts[base+c].x = maskMorphVerts[base+a].x + SMALL_SECTOR_SIZE;
maskMorphVerts[base+d].x = maskMorphVerts[base+c].x;
maskMorphVerts[base+a].y = (wavyMorphVerts[idxY + (17 * idxX)].y - (float)idxY * 2.0f) + (float(j) * 2.0f);
maskMorphVerts[base+c].y = maskMorphVerts[base+a].y;
maskMorphVerts[base+b].y = maskMorphVerts[base+a].y + SMALL_SECTOR_SIZE;
maskMorphVerts[base+d].y = maskMorphVerts[base+b].y;
maskMorphVerts[base+a].z = wavyMorphVerts[idxY + (17 * idxX)].z;
maskMorphVerts[base+d].z = maskMorphVerts[base+a].z;
maskMorphVerts[base+c].z = maskMorphVerts[base+d].z;
maskMorphVerts[base+b].z = maskMorphVerts[base+c].z;
#ifndef PC_WATER
if (maskMorphVerts[base].z >= fMinSparkZ)
#else
if ( maskMorphVerts[base].z > fMinSparkZ )
#endif
{
switch ( (i + j + randval) & 3 )
{
case 0:
{
CVector vecPos
(
fX + maskMorphVerts[base+a].x,
fY + maskMorphVerts[base+a].y,
fZ + maskMorphVerts[base+a].z + 0.12f
);
vecPos -= 0.05f * TheCamera.GetForward();
CParticle::AddParticle(PARTICLE_WATER_SPARK,
vecPos,
CVector(0.0f, 0.0f, 0.0f),
NULL,
0.0f,
15,
CGeneral::GetRandomNumberInRange(-90, 90),
0,
0);
}
break;
case 1:
{
CVector vecPos
(
fX + maskMorphVerts[base+c].x,
fY + maskMorphVerts[base+c].y,
fZ + maskMorphVerts[base+c].z + 0.12f
);
vecPos -= 0.05f * TheCamera.GetForward();
CParticle::AddParticle(PARTICLE_WATER_SPARK,
vecPos,
CVector(0.0f, 0.0f, 0.0f),
NULL,
0.0f,
15,
CGeneral::GetRandomNumberInRange(-90, 90),
0,
0);
}
break;
case 2:
{
CVector vecPos
(
fX + maskMorphVerts[base+b].x,
fY + maskMorphVerts[base+b].y,
fZ + maskMorphVerts[base+b].z + 0.12f
);
vecPos -= 0.05f * TheCamera.GetForward();
CParticle::AddParticle(PARTICLE_WATER_SPARK,
vecPos,
CVector(0.0f, 0.0f, 0.0f),
NULL,
0.0f,
15,
CGeneral::GetRandomNumberInRange(-90, 90),
0,
0);
}
break;
case 3:
{
CVector vecPos
(
fX + maskMorphVerts[base+d].x,
fY + maskMorphVerts[base+d].y,
fZ + maskMorphVerts[base+d].z + 0.12f
);
vecPos -= 0.05f * TheCamera.GetForward();
CParticle::AddParticle(PARTICLE_WATER_SPARK,
vecPos,
CVector(0.0f, 0.0f, 0.0f),
NULL,
0.0f,
15,
CGeneral::GetRandomNumberInRange(-90, 90),
0,
0);
}
break;
}
}
maskMorphNormals[base+a].x = wavyMorphNormals[idxY + (17 * idxX)].x;
maskMorphNormals[base+a].y = wavyMorphNormals[idxY + (17 * idxX)].y;
maskMorphNormals[base+a].z = wavyMorphNormals[idxY + (17 * idxX)].z;
maskMorphNormals[base+d].x = maskMorphNormals[base+a].x;
maskMorphNormals[base+d].y = maskMorphNormals[base+a].y;
maskMorphNormals[base+d].z = maskMorphNormals[base+a].z;
maskMorphNormals[base+c].x = maskMorphNormals[base+d].x;
maskMorphNormals[base+c].y = maskMorphNormals[base+d].y;
maskMorphNormals[base+c].z = maskMorphNormals[base+d].z;
maskMorphNormals[base+b].x = maskMorphNormals[base+c].x;
maskMorphNormals[base+b].y = maskMorphNormals[base+c].y;
maskMorphNormals[base+b].z = maskMorphNormals[base+c].z;
maskPreLight[base+a].red = color.red;
maskPreLight[base+a].green = color.green;
maskPreLight[base+a].blue = color.blue;
maskPreLight[base+a].alpha = color.alpha;
maskPreLight[base+d].red = maskPreLight[base+a].red;
maskPreLight[base+d].green = maskPreLight[base+a].green;
maskPreLight[base+d].blue = maskPreLight[base+a].blue;
maskPreLight[base+d].alpha = maskPreLight[base+a].alpha;
maskPreLight[base+c].red = maskPreLight[base+d].red;
maskPreLight[base+c].green = maskPreLight[base+d].green;
maskPreLight[base+c].blue = maskPreLight[base+d].blue;
maskPreLight[base+c].alpha = maskPreLight[base+d].alpha;
maskPreLight[base+b].red = maskPreLight[base+c].red;
maskPreLight[base+b].green = maskPreLight[base+c].green;
maskPreLight[base+b].blue = maskPreLight[base+c].blue;
maskPreLight[base+b].alpha = maskPreLight[base+c].alpha;
#ifndef PC_WATER
maskPreLight[base + a].alpha = Max(0, (int32)((float)color.alpha - (fAlphaMul * (Abs((float)i - fXOffset) + Abs((float)j - fYOffset)))));
maskPreLight[base + b].alpha = Max(0, (int32)((float)color.alpha - (fAlphaMul * (Abs((float)i - fXOffset) + Abs(16.0f + (float)j - fYOffset)))));
maskPreLight[base + c].alpha = Max(0, (int32)((float)color.alpha - (fAlphaMul * (Abs(16.0f + (float)i - fXOffset) + Abs((float)j - fYOffset)))));
maskPreLight[base + d].alpha = Max(0, (int32)((float)color.alpha - (fAlphaMul * (Abs(16.0f + (float)i - fXOffset) + Abs(16.0f + (float)j - fYOffset)))));
#endif
}
}
RpGeometryUnlock(maskGeometry);
#ifndef PC_WATER
{
RwV3d pos = { 0.0f, 0.0f, 0.0f };
2019-07-11 00:22:01 +00:00
pos.x = fX;
pos.y = fY;
2020-05-27 18:50:01 +00:00
pos.z = fZ + 0.05f;
RwFrameTranslate(RpAtomicGetFrame(ms_pMaskAtomic), &pos, rwCOMBINEREPLACE);
if (bRender)
{
#ifdef PS2
RpSkyTexCacheFlush();
#endif
RpAtomicRender(ms_pMaskAtomic);
}
}
#endif
}
#ifdef PC_WATER
void CWaterLevel::PreCalcWaterGeometry(void)
{
if ( !RequireWavySector )
{
WavesCalculatedThisFrame = false;
MaskCalculatedThisFrame = false;
return;
}
RequireWavySector = false;
WavesCalculatedThisFrame = true;
RwRGBA color;
color.red = CTimeCycle::GetWaterRed();
color.green = CTimeCycle::GetWaterGreen();
color.blue = CTimeCycle::GetWaterBlue();
color.alpha = CTimeCycle::GetWaterAlpha();
PreCalcWavySector(color);
if ( CCullZones::WaterFudge() )
{
MaskCalculatedThisFrame = false;
return;
}
CVector CamFwdDir = TheCamera.GetForward();
CamFwdDir.z = 0.0f;
CamFwdDir.Normalise();
float fCamX = TheCamera.GetPosition().x - SMALL_SECTOR_SIZE;
float fCamY = TheCamera.GetPosition().y - SMALL_SECTOR_SIZE;
//1.4144272f; 1.4144f;
float signX = CamFwdDir.x * 1.4144272f;
float signY = CamFwdDir.y * 1.4144272f;
signX = clamp(signX, -1.0f, 1.0f);
fCamX += 0.4f * signX * float(SMALL_SECTOR_SIZE * 2.0f);
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
signY = clamp(signY, -1.0f, 1.0f);
fCamY += 0.4f * signY * float(SMALL_SECTOR_SIZE * 2.0f);
int32 nBlock;
int32 BlockX = WATER_TO_SMALL_SECTOR_X(fCamX + WATER_X_OFFSET) + 1;
int32 BlockY = WATER_TO_SMALL_SECTOR_Y(fCamY ) + 1;
if ( _IsColideWithBlock(BlockX, BlockY, nBlock) )
{
float fMaskX = floorf(fCamX / 2.0f) * 2.0f;
float fMaskY = floorf(fCamY / 2.0f) * 2.0f;
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
float fSectorX = WATER_FROM_SMALL_SECTOR_X(BlockX) - WATER_X_OFFSET;
float fSectorY = WATER_FROM_SMALL_SECTOR_Y(BlockY);
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
if ( PreCalcWavyMask( fMaskX, fMaskY, ms_aWaterZs[nBlock],
fSectorX, fSectorY, fCamX, fCamY, CamFwdDir.x, CamFwdDir.y, color ) )
{
PreCalculatedMaskPosn.x = fMaskX;
PreCalculatedMaskPosn.y = fMaskY;
PreCalculatedMaskPosn.z = ms_aWaterZs[nBlock] + 0.05f;
MaskCalculatedThisFrame = true;
}
else
MaskCalculatedThisFrame = false;
2019-07-11 00:22:01 +00:00
}
else
2020-05-27 18:50:01 +00:00
MaskCalculatedThisFrame = false;
}
bool CWaterLevel::PreCalcWavySector(RwRGBA const &color)
{
float fAngle = (CTimer::GetTimeInMilliseconds() & 4095) * (TWOPI / 4096.0f);
RpGeometry *wavyGeometry = RpAtomicGetGeometry(ms_pWavyAtomic);
RwTexCoords *wavyTexCoords = RpGeometryGetVertexTexCoords(wavyGeometry, rwTEXTURECOORDINATEINDEX0);
RpMorphTarget *wavyMorph = RpGeometryGetMorphTarget(wavyGeometry, 0);
RwRGBA *wavyPreLight = RpGeometryGetPreLightColors(wavyGeometry);
RwV3d *wavyMorphVerts = RpMorphTargetGetVertices(wavyMorph);
RwV3d *wavyMorphNormals = RpMorphTargetGetVertexNormals(wavyMorph);
if ( !m_bRenderSeaBed )
RpGeometryLock(wavyGeometry, rpGEOMETRYLOCKVERTICES
|rpGEOMETRYLOCKNORMALS
|rpGEOMETRYLOCKPRELIGHT
|rpGEOMETRYLOCKTEXCOORDS);
CVector camPosUp = TheCamera.GetForward();
float randomDampInv2 = (1.0f - fRandomDamp) * 2.0f;
float randomMove = 1.0f / (16.0f * fRandomMoveDiv);
float wind = CWeather::WindClipped * 0.4f + 0.2f;
float waveWind = CWeather::WindClipped * fWave2Ampl + 0.05f;
float waveA = (TWOPI / 16.0f)
* ((CWeather::WindClipped * 0.4f + 0.2f) * (fNormalDirectionScalar1 * Abs(camPosUp.x + camPosUp.y) + fNormMult));
float waveB = TWOPI / (16.0f * fWave2NormScale)
* ((CWeather::WindClipped * 0.2f + 0.1f) * (fNormalDirectionScalar2 * Abs(camPosUp.y - camPosUp.x) + fNormMultB));
CVector vA(1.0f, 0.0f, 0.0f);
CVector vB(0.0f, 1.0f, 0.0f);
for ( int32 i = 0; i < 17; i++ )
2019-07-11 00:22:01 +00:00
{
2020-05-27 18:50:01 +00:00
for ( int32 j = 0; j < 17; j++ )
{
wavyTexCoords->u = (float(i) / 16.0f) + TEXTURE_ADDV;
wavyTexCoords->v = (float(j) / 16.0f) + TEXTURE_ADDU;
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
RwRGBAAssign(wavyPreLight, &color);
if ( i > 0 && i < 16 && j > 0 && j < 16 )
{
wavyMorphVerts->x += CGeneral::GetRandomNumberInRange(-1.0f, 1.0f) * randomMove;
wavyMorphVerts->x *= fRandomDamp;
wavyMorphVerts->x += float(i) * randomDampInv2;
wavyMorphVerts->y += CGeneral::GetRandomNumberInRange(-1.0f, 1.0f) * randomMove;
wavyMorphVerts->y *= fRandomDamp;
wavyMorphVerts->y += float(j) * randomDampInv2;
}
float morphVertXHalf = ( i == 16 ) ? 0.0f : 0.5f * wavyMorphVerts->x;
float morphVertYHalf = ( j == 16 ) ? 0.0f : 0.5f * wavyMorphVerts->y;
float waveMulA = (morphVertYHalf + morphVertXHalf) * (TWOPI / 16.0f) + fAngle;
float waveMulB = (morphVertYHalf - morphVertXHalf) * (TWOPI / (16.0f * fWave2InvLength)) + fAngle;
wavyMorphVerts->z = wind * sinf(waveMulA) + waveWind * sin(waveMulB);
vA.z = (waveA * cos(waveMulA)) - (waveB * cos(waveMulB));
vB.z = (waveA * cos(waveMulA)) + (waveB * cos(waveMulB));
CVector norm = CrossProduct(vA, vB);
norm.Normalise();
wavyMorphNormals->x = norm.x;
wavyMorphNormals->y = norm.y;
wavyMorphNormals->z = norm.z;
++wavyPreLight;
++wavyTexCoords;
++wavyMorphVerts;
++wavyMorphNormals;
}
}
RpGeometryUnlock(wavyGeometry);
return true;
}
bool CWaterLevel::PreCalcWavyMask(float fX, float fY, float fZ,
float fSectorX, float fSectorY,
float fCamPosX, float fCamPosY,
float fCamDirX, float fCamDirY,
RwRGBA const&color)
{
CVector vecSectorPos(fX + (MAX_LARGE_SECTORS/2), fY + (MAX_LARGE_SECTORS/2), fZ + 2.0f);
if ( COcclusion::IsAABoxOccluded(vecSectorPos, MAX_LARGE_SECTORS, MAX_LARGE_SECTORS, 4.0f) )
return false;
floorf(fX / MAX_LARGE_SECTORS);
floorf(fY / MAX_LARGE_SECTORS);
RpGeometry *wavyGeometry = RpAtomicGetGeometry(ms_pWavyAtomic);
RpMorphTarget *wavyMorph = RpGeometryGetMorphTarget(wavyGeometry, 0);
RwV3d *wavyMorphVerts = RpMorphTargetGetVertices(wavyMorph);
RwV3d *wavyMorphNormals = RpMorphTargetGetVertexNormals(wavyMorph);
RpGeometry *maskGeometry = RpAtomicGetGeometry(ms_pMaskAtomic);
RwTexCoords *maskTexCoords = RpGeometryGetVertexTexCoords(maskGeometry, rwTEXTURECOORDINATEINDEX0);
RwRGBA *maskPreLight = RpGeometryGetPreLightColors(maskGeometry);
RpMorphTarget *maskMorph = RpGeometryGetMorphTarget(maskGeometry, 0);
RwV3d *maskMorphVerts = RpMorphTargetGetVertices(maskMorph);
RwV3d *maskMorphNormals = RpMorphTargetGetVertexNormals(maskMorph);
if ( !m_bRenderSeaBed )
RpGeometryLock(maskGeometry, rpGEOMETRYLOCKVERTICES | rpGEOMETRYLOCKNORMALS | rpGEOMETRYLOCKPRELIGHT | rpGEOMETRYLOCKTEXCOORDS);
float fMinSparkZ = (fWave2Ampl * CWeather::WindClipped + 0.05f +
0.4f * CWeather::WindClipped + 0.2) * (1.0f - 0.02f * CWeather::SunGlare);
int32 randval = CGeneral::GetRandomNumber() & 255;
int16 nX = _RoundValue((int32)((fX - fSectorX) * 0.5f) - 1);
int16 nY = _RoundValue((int32)((fY - fSectorY) * 0.5f) - 1);
int16 idxX = nX;
for ( int32 i = 0; i < 17; i++ )
{
int16 idxY = nY;
if ( ++idxX > 16 )
idxX -= 16;
for ( int32 j = 0; j < 17; j++ )
{
if ( ++idxY > 16 )
idxY -= 16;
const int32 a = (0*16);
const int32 b = (1*16);
const int32 c = (33*16);
const int32 d = (34*16);
int32 base = (i*33+j);
maskTexCoords[base+a].v = float(j) / 32 + ((fCamPosY - fY) / 64);
maskTexCoords[base+c].v = maskTexCoords[base+a].v;
maskTexCoords[base+d].v = maskTexCoords[base+a].v + 0.5f;
maskTexCoords[base+b].v = maskTexCoords[base+d].v;
maskTexCoords[base+a].u = float(i) / 32 + ((fCamPosX - fX) / 64);
maskTexCoords[base+b].u = maskTexCoords[base+a].u;
maskTexCoords[base+d].u = maskTexCoords[base+a].u + 0.5f;
maskTexCoords[base+c].u = maskTexCoords[base+d].u;
maskMorphVerts[base+a].x = (wavyMorphVerts[idxY + (17 * idxX)].x - (float)idxX * 2.0f) + (float(i) * 2.0f);
maskMorphVerts[base+b].x = maskMorphVerts[base+a].x;
maskMorphVerts[base+c].x = maskMorphVerts[base+a].x + SMALL_SECTOR_SIZE;
maskMorphVerts[base+d].x = maskMorphVerts[base+c].x;
maskMorphVerts[base+a].y = (wavyMorphVerts[idxY + (17 * idxX)].y - (float)idxY * 2.0f) + (float(j) * 2.0f);
maskMorphVerts[base+c].y = maskMorphVerts[base+a].y;
maskMorphVerts[base+b].y = maskMorphVerts[base+a].y + SMALL_SECTOR_SIZE;
maskMorphVerts[base+d].y = maskMorphVerts[base+b].y;
maskMorphVerts[base+a].z = wavyMorphVerts[idxY + (17 * idxX)].z;
maskMorphVerts[base+d].z = maskMorphVerts[base+a].z;
maskMorphVerts[base+c].z = maskMorphVerts[base+d].z;
maskMorphVerts[base+b].z = maskMorphVerts[base+c].z;
if ( maskMorphVerts[base].z > fMinSparkZ )
{
switch ( (i + j + randval) & 3 )
{
case 0:
{
CVector vecPos
(
fX + maskMorphVerts[base+a].x,
fY + maskMorphVerts[base+a].y,
fZ + maskMorphVerts[base+a].z + 0.12f
);
vecPos -= 0.05f * TheCamera.GetForward();
CParticle::AddParticle(PARTICLE_WATER_SPARK,
vecPos,
CVector(0.0f, 0.0f, 0.0f),
NULL,
0.0f,
15,
CGeneral::GetRandomNumberInRange(-90, 90),
0,
0);
}
break;
case 1:
{
CVector vecPos
(
fX + maskMorphVerts[base+c].x,
fY + maskMorphVerts[base+c].y,
fZ + maskMorphVerts[base+c].z + 0.12f
);
vecPos -= 0.05f * TheCamera.GetForward();
CParticle::AddParticle(PARTICLE_WATER_SPARK,
vecPos,
CVector(0.0f, 0.0f, 0.0f),
NULL,
0.0f,
15,
CGeneral::GetRandomNumberInRange(-90, 90),
0,
0);
}
break;
case 2:
{
CVector vecPos
(
fX + maskMorphVerts[base+b].x,
fY + maskMorphVerts[base+b].y,
fZ + maskMorphVerts[base+b].z + 0.12f
);
vecPos -= 0.05f * TheCamera.GetForward();
CParticle::AddParticle(PARTICLE_WATER_SPARK,
vecPos,
CVector(0.0f, 0.0f, 0.0f),
NULL,
0.0f,
15,
CGeneral::GetRandomNumberInRange(-90, 90),
0,
0);
}
break;
case 3:
{
CVector vecPos
(
fX + maskMorphVerts[base+d].x,
fY + maskMorphVerts[base+d].y,
fZ + maskMorphVerts[base+d].z + 0.12f
);
vecPos -= 0.05f * TheCamera.GetForward();
CParticle::AddParticle(PARTICLE_WATER_SPARK,
vecPos,
CVector(0.0f, 0.0f, 0.0f),
NULL,
0.0f,
15,
CGeneral::GetRandomNumberInRange(-90, 90),
0,
0);
}
break;
}
}
maskMorphNormals[base+a].x = wavyMorphNormals[idxY + (17 * idxX)].x;
maskMorphNormals[base+a].y = wavyMorphNormals[idxY + (17 * idxX)].y;
maskMorphNormals[base+a].z = wavyMorphNormals[idxY + (17 * idxX)].z;
maskMorphNormals[base+d].x = maskMorphNormals[base+a].x;
maskMorphNormals[base+d].y = maskMorphNormals[base+a].y;
maskMorphNormals[base+d].z = maskMorphNormals[base+a].z;
maskMorphNormals[base+c].x = maskMorphNormals[base+d].x;
maskMorphNormals[base+c].y = maskMorphNormals[base+d].y;
maskMorphNormals[base+c].z = maskMorphNormals[base+d].z;
maskMorphNormals[base+b].x = maskMorphNormals[base+c].x;
maskMorphNormals[base+b].y = maskMorphNormals[base+c].y;
maskMorphNormals[base+b].z = maskMorphNormals[base+c].z;
maskPreLight[base+a].red = color.red;
maskPreLight[base+a].green = color.green;
maskPreLight[base+a].blue = color.blue;
maskPreLight[base+a].alpha = color.alpha;
maskPreLight[base+d].red = maskPreLight[base+a].red;
maskPreLight[base+d].green = maskPreLight[base+a].green;
maskPreLight[base+d].blue = maskPreLight[base+a].blue;
maskPreLight[base+d].alpha = maskPreLight[base+a].alpha;
maskPreLight[base+c].red = maskPreLight[base+d].red;
maskPreLight[base+c].green = maskPreLight[base+d].green;
maskPreLight[base+c].blue = maskPreLight[base+d].blue;
maskPreLight[base+c].alpha = maskPreLight[base+d].alpha;
maskPreLight[base+b].red = maskPreLight[base+c].red;
maskPreLight[base+b].green = maskPreLight[base+c].green;
maskPreLight[base+b].blue = maskPreLight[base+c].blue;
maskPreLight[base+b].alpha = maskPreLight[base+c].alpha;
}
}
RpGeometryUnlock(maskGeometry);
return true;
}
#endif
void CWaterLevel::RenderBoatWakes(void)
{
RwRenderStateSet(rwRENDERSTATETEXTURERASTER, (void *)gpWaterWakeRaster);
#ifndef PC_WATER
RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void *)TRUE);
RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDSRCALPHA);
RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDINVSRCALPHA);
#endif
#ifdef _XBOX
// TODO save and restore rwRENDERSTATESRCBLEND rwRENDERSTATEDESTBLEND
#endif
CBoat::FillBoatList();
float fWakeZ = 5.97f;
float fWakeLifeTimeMult = 0.01f / CBoat::WAKE_LIFETIME;
for ( int32 idx = 0; idx < ARRAY_SIZE(CBoat::apFrameWakeGeneratingBoats); idx++ )
{
CBoat *pBoat = CBoat::apFrameWakeGeneratingBoats[idx];
if ( pBoat == NULL )
break;
CVector2D vecDistA(pBoat->GetForward().x, pBoat->GetForward().y);
float fSize = pBoat->GetColModel()->boundingBox.max.z
* 0.65f;
if ( pBoat->GetModelIndex() == MI_SKIMMER)
fSize *= 0.4f;
float fAplhaA = 255.0f;
float fSizeA = fSize;
float fAplhaB;
float fSizeB;
for ( int32 wake = 1; wake < pBoat->m_nNumWakePoints; wake++ )
{
bool bRender = true;
float fTimeleft = CBoat::WAKE_LIFETIME - pBoat->m_afWakePointLifeTime[wake];
float fWakeSizeB = ((float)wake * 0.19f) + fSize - fWakeLifeTimeMult * Max(fTimeleft, 0.0f);
fSizeB = fWakeSizeB / CBoat::MIN_WAKE_INTERVAL;
if ( fSizeB < 0.0f )
fSizeB = 1.0f;
if ( wake == pBoat->m_nNumWakePoints - 1 )
{
// set alpha to 0 if it's last point
fAplhaB = 0.0f;
}
else
{
// clip (-100, 500), less lifetime - less val
float val = 500.0f - (CBoat::WAKE_LIFETIME - pBoat->m_afWakePointLifeTime[wake])
* 600.0f / CBoat::WAKE_LIFETIME;
fAplhaB = clamp(val, 0.0f, 255.0f);
}
CVector2D vecDistB = pBoat->m_avec2dWakePoints[wake - 1] - pBoat->m_avec2dWakePoints[wake];
float fScal = vecDistB.MagnitudeSqr();
// normalize if distance between points is greater than 3
if ( fScal > SQR(3.0f) )
{
float fNorm = 1.0f / sqrt(fScal);
vecDistB.x *= fNorm;
vecDistB.y *= fNorm;
// disable render if distance between points too big
if ( sqrt(fScal) > 13.0f )
bRender = false;
}
CVector2D vecAA
(
pBoat->m_avec2dWakePoints[wake - 1].x - (fSizeA * vecDistA.y),
pBoat->m_avec2dWakePoints[wake - 1].y + (fSizeA * vecDistA.x)
);
CVector2D vecAB
(
pBoat->m_avec2dWakePoints[wake - 1].x + (fSizeA * vecDistA.y),
pBoat->m_avec2dWakePoints[wake - 1].y - (fSizeA * vecDistA.x)
);
CVector2D vecBA
(
pBoat->m_avec2dWakePoints[wake].x + (fSizeB * vecDistB.y),
pBoat->m_avec2dWakePoints[wake].y - (fSizeB * vecDistB.x)
);
CVector2D vecBB
(
pBoat->m_avec2dWakePoints[wake].x - (fSizeB * vecDistB.y),
pBoat->m_avec2dWakePoints[wake].y + (fSizeB * vecDistB.x)
);
if ( bRender )
RenderWakeSegment(vecAA, vecAB, vecBA, vecBB, fSizeA, fSizeB, fAplhaA, fAplhaB, fWakeZ);
vecDistA = vecDistB;
fSizeA = fSizeB;
fAplhaB = fAplhaA;
}
}
RenderAndEmptyRenderBuffer();
}
inline float _GetWindedWave(float fX, float fY)
{
float fAngle = (CTimer::GetTimeInMilliseconds() & 4095) * (TWOPI / 4096.0f);
float x = WATER_HUGE_X(fX + WATER_X_OFFSET);
float y = WATER_HUGE_Y(fY);
float fWindFactor (CWeather::WindClipped * 0.4f + 0.2f);
float fWave = sin(( (x - floorf(x)) + (y - floorf(y)) ) * TWOPI + fAngle);
return fWindFactor * fWave;
}
void CWaterLevel::RenderWakeSegment(CVector2D &vecA, CVector2D &vecB, CVector2D &vecC, CVector2D &vecD,
float &fSizeA, float &fSizeB,
float &fAlphaA, float &fAlphaB,
float &fWakeZ)
{
for ( int32 i = 0; i < 4; i++ )
{
if ( TempBufferIndicesStored >= TEMPBUFFERINDEXSIZE-6 || TempBufferVerticesStored >= TEMPBUFFERVERTSIZE-4 )
RenderAndEmptyRenderBuffer();
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
float fCurStep = (float)i / 4;
float fNxtStep = (float)(i + 1) / 4;
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
float fLeftCurStep = 1.0f - fCurStep;
float fLeftNxtStep = 1.0f - fNxtStep;
uint8 AlphaA = (uint32)(fAlphaA * aAlphaFade[i] );
uint8 AlphaB = (uint32)(fAlphaA * aAlphaFade[i + 1]);
uint8 AlphaC = (uint32)(fAlphaB * aAlphaFade[i + 1]);
uint8 AlphaD = (uint32)(fAlphaB * aAlphaFade[i] );
CVector2D PosA = vecB*fCurStep + vecA*fLeftCurStep;
CVector2D PosB = vecB*fNxtStep + vecA*fLeftNxtStep;
CVector2D PosC = vecC*fNxtStep + vecD*fLeftNxtStep;
CVector2D PosD = vecC*fCurStep + vecD*fLeftCurStep;
float fUA = (PosA.x / 4) + _TEXTURE_WAKE_ADDU;
float fVA = (PosA.y / 4) + _TEXTURE_WAKE_ADDV;
float fUB = (PosB.x / 4) + _TEXTURE_WAKE_ADDU;
float fVB = (PosB.y / 4) + _TEXTURE_WAKE_ADDV;
float fUC = (PosC.x / 4) + _TEXTURE_WAKE_ADDU;
float fVC = (PosC.y / 4) + _TEXTURE_WAKE_ADDV;
float fUD = (PosD.x / 4) + _TEXTURE_WAKE_ADDU;
float fVD = (PosD.y / 4) + _TEXTURE_WAKE_ADDV;
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
#define MIN4(a, b, c, d) (Min((a), Min((b), Min((c), (d)))))
float fMinU = floorf(MIN4(fUA, fUB, fUC, fUD));
float fMinV = floorf(MIN4(fVA, fVB, fVC, fVD));
#undef MIN4
float fZA = _GetWindedWave(PosA.x, PosA.y) + fWakeZ;
float fZB = _GetWindedWave(PosB.x, PosB.y) + fWakeZ;
float fZC = _GetWindedWave(PosC.x, PosC.y) + fWakeZ;
float fZD = _GetWindedWave(PosD.x, PosD.y) + fWakeZ;
int32 vidx = TempBufferVerticesStored;
RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 0], PosA.x, PosA.y, fZA);
RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 0], fUA - fMinU);
RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 0], fVA - fMinV);
RwIm3DVertexSetRGBA (&TempBufferRenderVertices[vidx + 0], 255, 255, 255, AlphaA);
RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 1], PosB.x, PosB.y, fZB);
RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 1], fUB - fMinU);
RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 1], fVB - fMinV);
RwIm3DVertexSetRGBA (&TempBufferRenderVertices[vidx + 1], 255, 255, 255, AlphaB);
RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 2], PosC.x, PosC.y, fZC);
RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 2], fUC - fMinU);
RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 2], fVC - fMinV);
RwIm3DVertexSetRGBA (&TempBufferRenderVertices[vidx + 2], 255, 255, 255, AlphaC);
RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 3], PosD.x, PosD.y, fZD);
RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 3], fUD - fMinU);
RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 3], fVD - fMinV);
RwIm3DVertexSetRGBA (&TempBufferRenderVertices[vidx + 3], 255, 255, 255, AlphaD);
int32 iidx = TempBufferIndicesStored;
TempBufferRenderIndexList[iidx + 0] = TempBufferVerticesStored + 0;
TempBufferRenderIndexList[iidx + 1] = TempBufferVerticesStored + 2;
TempBufferRenderIndexList[iidx + 2] = TempBufferVerticesStored + 1;
TempBufferRenderIndexList[iidx + 3] = TempBufferVerticesStored + 0;
TempBufferRenderIndexList[iidx + 4] = TempBufferVerticesStored + 3;
TempBufferRenderIndexList[iidx + 5] = TempBufferVerticesStored + 2;
TempBufferVerticesStored += 4;
TempBufferIndicesStored += 6;
2019-07-11 00:22:01 +00:00
}
}
2020-05-27 18:50:01 +00:00
void CWaterLevel::RenderOneSlopedUnderWaterPoly(float fX, float fY, float fZ, RwRGBA const&color)
{
CVector2D camPos(TheCamera.GetPosition().x, TheCamera.GetPosition().y);
float fDistA = (CVector2D(fX, fY) - camPos).Magnitude() + -140.0f;
float fDistB = (CVector2D(fX, fY + HUGE_SECTOR_SIZE) - camPos).Magnitude() + -140.0f;
float fDistC = (CVector2D(fX + HUGE_SECTOR_SIZE, fY + HUGE_SECTOR_SIZE) - camPos).Magnitude() + -140.0f;
float fDistD = (CVector2D(fX + HUGE_SECTOR_SIZE, fY) - camPos).Magnitude() + -140.0f;
#ifndef PC_WATER
#define CALCSEABED(v, d) \
{ \
if ( d < 0.0f ) \
v = 0.1f + fSeaBedZ; \
else if ( d > 240.0f ) \
v = 0.1f; \
else \
v = 0.1f + ((fSeaBedZ * (240.0f - d)) / 240.0f); \
}
#else
#define CALCSEABED(v, d) \
{ \
v = 0.1f; \
if ( d < 0.0f ) \
v += fSeaBedZ; \
else if ( d <= 240.0f ) \
v += (fSeaBedZ / 240.0f) * (240.0f - d); \
}
#endif
float fSeaBedA, fSeaBedB, fSeaBedC, fSeaBedD;
CALCSEABED(fSeaBedA, fDistA);
CALCSEABED(fSeaBedB, fDistB);
CALCSEABED(fSeaBedC, fDistC);
CALCSEABED(fSeaBedD, fDistD);
#undef CALCSEABED
if ( TempBufferIndicesStored >= TEMPBUFFERINDEXSIZE-6 || TempBufferVerticesStored >= TEMPBUFFERVERTSIZE-4 )
RenderAndEmptyRenderBuffer();
int32 vidx = TempBufferVerticesStored;
RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 0], fX, fY, fZ - _fWaterZOffset - fSeaBedA);
RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 0], 0.0f);
RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 0], 0.0f);
RwIm3DVertexSetRGBA(&TempBufferRenderVertices[vidx + 0], color.red, color.green, color.blue, 255);
RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 1], fX, fY + HUGE_SECTOR_SIZE, fZ - _fWaterZOffset - fSeaBedB);
RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 1], 0.0f);
RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 1], 4.0f);
RwIm3DVertexSetRGBA(&TempBufferRenderVertices[vidx + 1], color.red, color.green, color.blue, 255);
RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 2], fX + HUGE_SECTOR_SIZE, fY + HUGE_SECTOR_SIZE, fZ - _fWaterZOffset - fSeaBedC);
RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 2], 4.0f);
RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 2], 4.0f);
RwIm3DVertexSetRGBA(&TempBufferRenderVertices[vidx + 2], color.red, color.green, color.blue, 255);
RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 3], fX + HUGE_SECTOR_SIZE, fY, fZ - _fWaterZOffset - fSeaBedD);
RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 3], 4.0f);
RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 3], 0.0f);
RwIm3DVertexSetRGBA(&TempBufferRenderVertices[vidx + 3], color.red, color.green, color.blue, 255);
int32 iidx = TempBufferIndicesStored;
TempBufferRenderIndexList[iidx + 0] = TempBufferVerticesStored + 0;
TempBufferRenderIndexList[iidx + 1] = TempBufferVerticesStored + 2;
TempBufferRenderIndexList[iidx + 2] = TempBufferVerticesStored + 1;
TempBufferRenderIndexList[iidx + 3] = TempBufferVerticesStored + 0;
TempBufferRenderIndexList[iidx + 4] = TempBufferVerticesStored + 3;
TempBufferRenderIndexList[iidx + 5] = TempBufferVerticesStored + 2;
TempBufferVerticesStored += 4;
TempBufferIndicesStored += 6;
}
void CWaterLevel::RenderOneFlatSmallWaterPolyBlended(float fX, float fY, float fZ, float fCamX, float fCamY,
RwRGBA const &color, RwRGBA const &colorTrans,
float fDrawDist)
{
if ( TempBufferIndicesStored >= TEMPBUFFERINDEXSIZE-6 || TempBufferVerticesStored >= TEMPBUFFERVERTSIZE-4 )
RenderAndEmptyRenderBuffer();
int32 vidx = TempBufferVerticesStored;
float fBlendDrawDist = fDrawDist + fStartBlendDistanceAdd;
float fDistStartX = SQR(fX - fCamX);
float fDistStartY = SQR(fY - fCamY);
float fDistEndX = SQR((fX + SMALL_SECTOR_SIZE) - fCamX);
float fDistEndY = SQR((fY + SMALL_SECTOR_SIZE) - fCamY);
float fAlphaBlendMulA
= Min(fFlatWaterBlendRange * Max(sqrt(fDistStartX + fDistStartY) - fBlendDrawDist, fMinWaterAlphaMult), 1.0f);
float fAlphaBlendMulB
= Min(fFlatWaterBlendRange * Max(sqrt(fDistStartX + fDistEndY ) - fBlendDrawDist, fMinWaterAlphaMult), 1.0f);
float fAlphaBlendMulC
= Min(fFlatWaterBlendRange * Max(sqrt(fDistEndX + fDistEndY ) - fBlendDrawDist, fMinWaterAlphaMult), 1.0f);
float fAlphaBlendMulD
= Min(fFlatWaterBlendRange * Max(sqrt(fDistEndX + fDistStartY) - fBlendDrawDist, fMinWaterAlphaMult), 1.0f);
RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 0], fX, fY, fZ - _fWaterZOffset);
RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 0], TEXTURE_ADDU);
RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 0], TEXTURE_ADDV);
RwIm3DVertexSetRGBA(&TempBufferRenderVertices[vidx + 0], color.red, color.green, color.blue,
(colorTrans.alpha + (color.alpha - colorTrans.alpha) * (uint8)(int32)fAlphaBlendMulA));
RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 1], fX, fY + SMALL_SECTOR_SIZE, fZ - _fWaterZOffset);
RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 1], TEXTURE_ADDU);
RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 1], TEXTURE_ADDV + 1.0f);
RwIm3DVertexSetRGBA(&TempBufferRenderVertices[vidx + 1], color.red, color.green, color.blue,
(colorTrans.alpha + (color.alpha - colorTrans.alpha) * (uint8)(int32)fAlphaBlendMulB));
RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 2], fX + SMALL_SECTOR_SIZE, fY + SMALL_SECTOR_SIZE, fZ - _fWaterZOffset);
RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 2], TEXTURE_ADDU + 1.0f);
RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 2], TEXTURE_ADDV + 1.0f);
RwIm3DVertexSetRGBA(&TempBufferRenderVertices[vidx + 2], color.red, color.green, color.blue,
(colorTrans.alpha + (color.alpha - colorTrans.alpha) * (uint8)(int32)fAlphaBlendMulC));
RwIm3DVertexSetPos (&TempBufferRenderVertices[vidx + 3], fX + SMALL_SECTOR_SIZE, fY, fZ - _fWaterZOffset);
RwIm3DVertexSetU (&TempBufferRenderVertices[vidx + 3], TEXTURE_ADDU + 1.0f);
RwIm3DVertexSetV (&TempBufferRenderVertices[vidx + 3], TEXTURE_ADDV);
RwIm3DVertexSetRGBA(&TempBufferRenderVertices[vidx + 3], color.red, color.green, color.blue,
(colorTrans.alpha + (color.alpha - colorTrans.alpha) * (uint8)(int32)fAlphaBlendMulD));
int32 iidx = TempBufferIndicesStored;
TempBufferRenderIndexList[iidx + 0] = TempBufferVerticesStored + 0;
TempBufferRenderIndexList[iidx + 1] = TempBufferVerticesStored + 2;
TempBufferRenderIndexList[iidx + 2] = TempBufferVerticesStored + 1;
TempBufferRenderIndexList[iidx + 3] = TempBufferVerticesStored + 0;
TempBufferRenderIndexList[iidx + 4] = TempBufferVerticesStored + 3;
TempBufferRenderIndexList[iidx + 5] = TempBufferVerticesStored + 2;
TempBufferVerticesStored += 4;
TempBufferIndicesStored += 6;
}
2019-07-11 00:22:01 +00:00
float
CWaterLevel::CalcDistanceToWater(float fX, float fY)
{
2020-05-27 18:50:01 +00:00
const float fSectorMaxRenderDist = 250.0f;
2019-07-11 00:22:01 +00:00
int32 nStartX = WATER_TO_SMALL_SECTOR_X(fX - fSectorMaxRenderDist + WATER_X_OFFSET) - 1;
int32 nEndX = WATER_TO_SMALL_SECTOR_X(fX + fSectorMaxRenderDist + WATER_X_OFFSET) + 1;
2019-07-11 00:22:01 +00:00
int32 nStartY = WATER_TO_SMALL_SECTOR_Y(fY - fSectorMaxRenderDist) - 1;
int32 nEndY = WATER_TO_SMALL_SECTOR_Y(fY + fSectorMaxRenderDist) + 1;
nStartX = clamp(nStartX, 0, MAX_SMALL_SECTORS - 1);
nEndX = clamp(nEndX, 0, MAX_SMALL_SECTORS - 1);
nStartY = clamp(nStartY, 0, MAX_SMALL_SECTORS - 1);
nEndY = clamp(nEndY, 0, MAX_SMALL_SECTORS - 1);
float fDistSqr = 1.0e10f;
for ( int32 x = nStartX; x <= nEndX; x++ )
{
for ( int32 y = nStartY; y <= nEndY; y++ )
{
2020-05-27 18:50:01 +00:00
if ( !(aWaterFineBlockList[x][y] & 0x80) )
2019-07-11 00:22:01 +00:00
{
float fSectorX = WATER_FROM_SMALL_SECTOR_X(x) - WATER_X_OFFSET;
2019-07-11 00:22:01 +00:00
float fSectorY = WATER_FROM_SMALL_SECTOR_Y(y);
CVector2D vecDist
(
fSectorX + SMALL_SECTOR_SIZE - fX,
fSectorY + SMALL_SECTOR_SIZE - fY
);
2020-04-19 16:34:08 +00:00
fDistSqr = Min(vecDist.MagnitudeSqr(), fDistSqr);
2019-07-11 00:22:01 +00:00
}
}
}
2019-07-24 16:55:43 +00:00
return clamp(Sqrt(fDistSqr) - 23.0f, 0.0f, fSectorMaxRenderDist);
2019-07-11 00:22:01 +00:00
}
void
CWaterLevel::RenderAndEmptyRenderBuffer()
{
if ( TempBufferVerticesStored )
{
LittleTest();
if ( RwIm3DTransform(TempBufferRenderVertices, TempBufferVerticesStored, NULL, rwIM3D_VERTEXUV) )
{
RwIm3DRenderIndexedPrimitive(rwPRIMTYPETRILIST, TempBufferRenderIndexList, TempBufferIndicesStored);
RwIm3DEnd();
}
}
TempBufferIndicesStored = 0;
TempBufferVerticesStored = 0;
}
2020-05-27 18:50:01 +00:00
bool CWaterLevel::GetGroundLevel(CVector const &vecPosn, float *pfOutLevel, ColData *pData, float fDistance)
2019-07-11 00:22:01 +00:00
{
2020-05-27 18:50:01 +00:00
CColPoint point;
CEntity *entity;
if ( !CWorld::ProcessVerticalLine(vecPosn + CVector(0.0f, 0.0f, fDistance),
-fDistance, point, entity, true, false, false, false, true, false, NULL) )
return false;
*pfOutLevel = point.point.z;
if ( pData != NULL )
{
pData->SurfaceType = point.surfaceB;
pData->PieceType = point.pieceB;
}
return true;
}
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
bool CWaterLevel::IsLocationOutOfWorldBounds_WS(CVector const &vecPosn, int nOffset)
{
int32 x = int32((vecPosn.x / 50.0f) + 48.0f);
int32 y = int32((vecPosn.y / 50.0f) + 40.0f);
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
return x < nOffset || x >= 80 - nOffset || y < nOffset || y >= 80 - nOffset;
}
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
bool CWaterLevel::GetGroundLevel_WS(CVector const &vecPosn, float *pfOutLevel, ColData *pData, float fDistance)
{
if ( IsLocationOutOfWorldBounds_WS(vecPosn, 0) )
return false;
else
return GetGroundLevel(vecPosn, pfOutLevel, pData, fDistance);
}
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
bool CWaterLevel::GetWaterDepth(CVector const &vecPosn, float *pfDepth, float *pfLevelNoWaves, float *pfGroundLevel)
{
float fLevelNoWaves;
float fGroundLevel;
if ( !GetWaterLevelNoWaves(vecPosn.x, vecPosn.y, vecPosn.z, &fLevelNoWaves) )
return false;
if ( !GetGroundLevel(vecPosn, &fGroundLevel, NULL, 30.0f) )
fGroundLevel = -100.0;
if ( pfDepth != NULL )
*pfDepth = fLevelNoWaves - fGroundLevel;
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
if ( pfLevelNoWaves != NULL )
*pfLevelNoWaves = fLevelNoWaves;
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
if ( pfGroundLevel != NULL )
*pfGroundLevel = fGroundLevel;
return true;
}
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
void CWaterLevel::RenderSeaBirds()
{
}
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
void CWaterLevel::RenderShipsOnHorizon()
{
}
2019-07-11 00:22:01 +00:00
2020-05-27 18:50:01 +00:00
void CWaterLevel::HandleSeaLifeForms()
{
2019-07-11 00:22:01 +00:00
}
2020-05-27 18:50:01 +00:00
void CWaterLevel::HandleBeachToysStuff(void)
2019-07-11 00:22:01 +00:00
{
}
2020-05-27 18:50:01 +00:00
CEntity *CWaterLevel::CreateBeachToy(CVector const &vec, eBeachToy beachtoy)
{
return NULL;
}