#include "globals.h" extern const float c_2PI= 6.2831853f; extern const float c_PI= 3.1415927f; LPDIRECT3D9 g_D3D; IDirect3DDevice9 *g_d3d_device; D3DPRESENT_PARAMETERS d3dpp= { 1024,//UINT BackBufferWidth; 768,//UINT BackBufferHeight; D3DFMT_A8R8G8B8,//D3DFORMAT BackBufferFormat; 2,//UINT BackBufferCount; D3DMULTISAMPLE_16_SAMPLES,//D3DMULTISAMPLE_TYPE MultiSampleType; 0,//DWORD MultiSampleQuality; D3DSWAPEFFECT_DISCARD,//D3DSWAPEFFECT SwapEffect; 0,//HWND hDeviceWindow; FALSE,//BOOL Windowed; TRUE,//BOOL EnableAutoDepthStencil; D3DFMT_D24S8,//D3DFORMAT AutoDepthStencilFormat; 0,//DWORD Flags; /* FullScreen_RefreshRateInHz must be zero for Windowed mode */ 0,//UINT FullScreen_RefreshRateInHz; D3DPRESENT_INTERVAL_ONE, //UINT PresentationInterval; }; UINT g_nShadowResolution = 1024; UINT g_nEnvResolution = 512; UINT g_nEnvBlurResolution = 64; float g_fResolutionFactor = 1.0f; int g_iResolutionFactorExp = 0; D3DLIGHT9 d3dLight[3]= { { D3DLIGHT_POINT,// D3DLIGHTTYPE Type; /* Type of light source */ { 1.0f, 1.0f, 0.85f, 0.0f },// D3DCOLORVALUE Diffuse; /* Diffuse color of light */ { 1.0f, 1.0f, 1.0f, 0.0f },// D3DCOLORVALUE Specular; /* Specular color of light */ { 0.0625f, 0.0625f, 0.0625f, 0.0f },// D3DCOLORVALUE Ambient; /* Ambient color of light */ { 48.0f, 96.0f, -48.0f },// D3DVECTOR Position; /* Position in world space */ { 0.0f, 0.0f, 0.0f },// D3DVECTOR Direction; /* Direction in world space */ 1024.0f, //float Range; /* Cutoff range */ 0.0f, //float Falloff; /* Falloff */ 1.0f / 4096.0f, //float Attenuation0; /* Constant attenuation */ 1.0f / 4096.0f, //float Attenuation1; /* Linear attenuation */ 1.0f / 4096.0f, //float Attenuation2; /* Quadratic attenuation */ 0.0f, //float Theta; /* Inner angle of spotlight cone */ 0.0f, //float Phi; /* Outer angle of spotlight cone */ }, { D3DLIGHT_POINT,// D3DLIGHTTYPE Type; /* Type of light source */ { 0.6f, 0.6f, 0.8f, 0.0f },// D3DCOLORVALUE Diffuse; /* Diffuse color of light */ { 0.0f, 0.0f, 0.0f, 0.0f },// D3DCOLORVALUE Specular; /* Specular color of light */ { 0.0f, 0.0f, 0.0f, 0.0f },// D3DCOLORVALUE Ambient; /* Ambient color of light */ { -16.0f, -32.0f, 64.0f },// D3DVECTOR Position; /* Position in world space */ { 0.0f, 0.0f, 0.0f },// D3DVECTOR Direction; /* Direction in world space */ 1024.0f, //float Range; /* Cutoff range */ 0.0f, //float Falloff; /* Falloff */ 1.0f / 4096.0f, //float Attenuation0; /* Constant attenuation */ 1.0f / 4096.0f, //float Attenuation1; /* Linear attenuation */ 1.0f / 4096.0f, //float Attenuation2; /* Quadratic attenuation */ 0.0f, //float Theta; /* Inner angle of spotlight cone */ 0.0f, //float Phi; /* Outer angle of spotlight cone */ }, { D3DLIGHT_POINT,// D3DLIGHTTYPE Type; /* Type of light source */ { 141.0f / 255.0f, 122.0f / 255.0f, 57.0f / 255.0f, 0.0f },// D3DCOLORVALUE Diffuse; /* Diffuse color of light */ { 205.0f / 255.0f, 186.0f / 255.0f, 121.0f / 255.0f, 0.0f },// D3DCOLORVALUE Specular; /* Specular color of light */ { 0.0f, 0.0f, 0.0f, 0.0f },// D3DCOLORVALUE Ambient; /* Ambient color of light */ { -48.0f, 64.0f, 48.0f },// D3DVECTOR Position; /* Position in world space */ { 0.0f, 0.0f, 0.0f },// D3DVECTOR Direction; /* Direction in world space */ 1024.0f, //float Range; /* Cutoff range */ 0.0f, //float Falloff; /* Falloff */ 1.0f / 4096.0f, //float Attenuation0; /* Constant attenuation */ 1.0f / 4096.0f, //float Attenuation1; /* Linear attenuation */ 1.0f / 4096.0f, //float Attenuation2; /* Quadratic attenuation */ 0.0f, //float Theta; /* Inner angle of spotlight cone */ 0.0f, //float Phi; /* Outer angle of spotlight cone */ } }; D3DMATERIAL9 d3dMaterial= { { 1.0f, 1.0f, 1.0f, 1.0f },// D3DCOLORVALUE Diffuse; /* Diffuse color RGBA */ { 1.0f, 1.0f, 1.0f, 1.0f },// D3DCOLORVALUE Ambient; /* Ambient color RGB */ { 1.0f, 1.0f, 1.0f, 0.0f },// Specular; /* Specular 'shininess' */ { 0.0f, 0.0f, 0.0f, 0.0f },// Emissive; /* Emissive color RGB */ 32.0f //float Power; /* Sharpness if specular highlight */ }; D3DXMATRIX g_matView; D3DXMATRIX g_matProjection; Texture g_pTextures[ TextureCount ]; IDirect3DTexture9* g_pFullScreenRT[ RT_COUNT ]; IDirect3DCubeTexture9* g_pCubeRT[RT_CUBE_COUNT]; IDirect3DSurface9* g_pFullScreenRTS[ RTS_COUNT ]; unsigned int g_nFullScreenResX[ RTS_COUNT ]; unsigned int g_nFullScreenResY[ RTS_COUNT ]; SCameraDefinition g_CubeMapCamera = { D3DXVECTOR3(0, 0, 0), D3DXVECTOR3(0, 0, 0), -1.0f, c_PI / 2, 0, 10 }; D3DXVECTOR3 g_CubeMapLightDir(0.84653091f, -0.37397960f, -0.37884632f ); //+ _D3DVECTOR {x=0.84653091 y=-0.37397960 z=-0.37884632 } _D3DVECTOR SCameraDefinition g_Camera; D3DXVECTOR3 g_CamFront; D3DXVECTOR3 g_LightDir; float g_fGlow; float g_fClouds; float g_fPlasmaGrid; float g_fCamTime; float g_fShaderBeat; PSSM g_PSSM; Water g_OceanWater; Environment g_Environment; TerrainGrid g_IsleTerrainGrid; TerrainGrid g_CaveTerrainGrid; TerrainGrid g_CaveGroundTerrainGrid; FluidContext g_FluidContext; Fluid g_Fluid; D3DXVECTOR4 g_FluidPointMap[PMI_Count][100000]; FluidParticleSystem g_FluidParticleSystem[FI_Count]; float g_FluidParticleSize[FI_Count] = { 0.2f, // SPIKE 0.4f, 0.25f, 0.25f, 0.25f, 0.25f, 0.25f }; float g_PointMapDistance[PMI_Count] = { 0.3f, // SPIKE 1.0f, 0.25f, 0.25f, 0.25f, 0.25f }; Renderjob g_Objects[ ObjectCount ]; Renderjob* g_pEditObject; int g_ObjGroupIndex[SceneObjCount]; #ifdef EXTRACODE DWORD g_SceneMask[g_SceneMaskCount]; #else #include "scenedata.h" #endif Renderjob g_SkyBox; Renderjob g_Ocean; Renderjob g_FullScreenQuad; Shader g_Shaders[ g_iShaderCount ]; DWORD g_dwTimeReplaceStart; int g_iTempo= ( 44100 * 60 * 2 ) / 135; int g_iSampleOffset= g_iSampleOffsetGeneral; int g_dwSamplesPassed= 0; int g_dwSamples= 0; SVUMeter g_vuBaseDrum; SVUMeter g_vuSnare; //ScriptState g_ScriptState; RandomGenerator g_Random; #ifdef EXTRACODE unsigned char g_Script[ 2048 ]; float g_ScriptParamFloat[ 512 ]; #endif #ifdef EXTRACODE char g_ShaderVSGeneral[ 65536 ]; char g_ShaderPSPhong[ 65536 ]; char g_ShaderPSCrystal[ 65536 ]; char g_ShaderPSDepth[ 65536 ]; char g_ShaderPSText[ 65536 ]; char g_ShaderPSEnvLit[ 65536 ]; char g_ShaderVSSky[ 65536 ]; char g_ShaderPSSky[ 65536 ]; char g_ShaderVSOcean[ 65536 ]; char g_ShaderPSOcean[ 65536 ]; char g_ShaderVSFSQuad[ 65536 ]; char g_ShaderPSTexGen[ 65536 ]; char g_ShaderPSPSSM[ 65536 ]; char g_ShaderPSAmbOcc[ 65536 ]; char g_ShaderPSDOF[ 65536 ]; char g_ShaderPSRay[ 65536 ]; char g_ShaderPSBlur[ 65536 ]; char g_ShaderPSTerrain[ 65536 ]; char g_ShaderVSFluid[ 65536 ]; char g_ShaderPSFluid[ 65536 ]; #endif void InitGlobals() { for( int i= 0; i < TextureCount; ++i ) { g_pTextures[ i ].Init(); } for( int i= 0; i < ObjectCount; i++ ) { g_Objects[ i ].Init(); } g_SkyBox.Init(); g_Ocean.Init(); g_Environment.Init(); g_FullScreenQuad.Init(); g_PSSM.Init(); g_OceanWater.Init(); for( int i= 0; i < g_iShaderCount; i++ ) { g_Shaders[ i ].Init(); } g_Random.setSeed( 0 ); int j= 0; while( g_ObjGroupsDesc[ j * 2 ] >= 0 ) { int Begin= g_ObjGroupsDesc[ j * 2 ]; int End= g_ObjGroupsDesc[ j * 2 + 1 ]; for( int i= Begin; i <= End; ++i ) { g_ObjGroupIndex[ i ]= j; } j++; } } bool IsObjInScene( ObjectIndices oi ) { #ifdef DISABLESCENEMANAGER return true; #else int iBit= g_ObjGroupIndex[ oi ]; assert( iBit >= 0 && iBit < 32 ); int iMask= 1 << iBit; return 0 != ( iMask & g_SceneMask[ g_Camera.m_iScene ] ); #endif }; float g_StartMeltTime = 0.0f; float g_EndMeltTime = 3.0f; float g_fFrozenT1= 3.5f; float g_fFrozenT2= 4.5f; float TimeToFrozenObj( float fTime ) { if( fTime < g_fFrozenT1 ) { return 0.0f; } else if( fTime < g_fFrozenT2 ) { float fDif= g_fFrozenT2 - g_fFrozenT1; float fWeight= ( fTime - g_fFrozenT1 ) / ( fDif ); fWeight*= fWeight; return 0.5f * fDif * fWeight ; } else { float fDif= g_fFrozenT2 - g_fFrozenT1; return 0.5f * fDif + fTime - g_fFrozenT2; } }