1309 lines
34 KiB
C++
1309 lines
34 KiB
C++
#include "defines.h"
|
|
|
|
int c_iScreenSizeX= DEFAULTSCREENX;
|
|
int c_iScreenSizeY= DEFAULTSCREENY;
|
|
#ifdef WINDOWED
|
|
bool bWindowed= true;
|
|
#else
|
|
bool bWindowed= false;
|
|
#endif
|
|
|
|
#ifdef LOW_DETAIL
|
|
bool bLowDetail= true;
|
|
#else
|
|
bool bLowDetail= false;
|
|
#endif
|
|
|
|
int c_iRealScreenY= c_iScreenSizeY;
|
|
|
|
#ifdef STARTMUSIC
|
|
#include "v2mplayer.h"
|
|
#include "libv2.h"
|
|
#include "music.h"
|
|
#include "musicdata.h"
|
|
|
|
static V2MPlayer player;
|
|
#endif
|
|
|
|
#include "intrin.h"
|
|
|
|
#include <windows.h>
|
|
#include <mmsystem.h>
|
|
#include <d3d9.h>
|
|
#include <d3dx9math.h>
|
|
|
|
#include "globals.h"
|
|
|
|
#include "camera.h"
|
|
|
|
#include "TargetValue.h"
|
|
#include "camerahelper.h"
|
|
|
|
#include "ShaderFactory.h"
|
|
#include "Renderpipe.h"
|
|
#include "textinfo.h"
|
|
#include "entityinfo.h"
|
|
|
|
#include "cave.h"
|
|
#include "swarm.h"
|
|
|
|
#define TWEAKABLES_INSTANCE
|
|
#include "tweak/main.txt"
|
|
#include "tweak/fluid.txt"
|
|
|
|
#include "fm_gen.h"
|
|
|
|
#include "objmesh.h"
|
|
|
|
#include "meshdata/duck.h"
|
|
#include "meshdata/atari.h"
|
|
#include "meshdata/commod.h"
|
|
#include "meshdata/speaker.h"
|
|
|
|
#include "meshdata/magier.h"
|
|
#include "meshdata/yeti.h"
|
|
|
|
#include "PointMapGenerator.h"
|
|
|
|
#if defined(MESHTESTER)
|
|
#include "MeshViewer.h"
|
|
#endif
|
|
#include "twist.h"
|
|
|
|
#undef WINAPI
|
|
#define WINAPI __declspec(nothrow) __stdcall
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
////
|
|
// CRT replacement functions
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
//extern "C" int _fltused = 1;
|
|
int __cdecl main(){return 0;};
|
|
|
|
|
|
#undef ZeroMemory
|
|
|
|
|
|
#ifdef EXTRACODE
|
|
|
|
#include <fstream>
|
|
#include <vector>
|
|
#include <sstream>
|
|
#include <string>
|
|
|
|
#include "StringHelper.h"
|
|
#include "TextFileReader.h"
|
|
|
|
#include "ConfigFiles.h"
|
|
|
|
HINSTANCE g_hInstance = NULL;
|
|
|
|
#endif
|
|
|
|
#include "mesher.h"
|
|
#include "camera.h"
|
|
#include "picstuff.h"
|
|
#include "bar16to9.h"
|
|
|
|
#include "textout.h"
|
|
#include "flockspline.h"
|
|
#include "spike.h"
|
|
#include "greeble.h"
|
|
|
|
void ReadDemoCommandLine()
|
|
{
|
|
char* pcCommand;
|
|
pcCommand= GetCommandLine();
|
|
{
|
|
int i= 0;
|
|
int iNumber= 0;
|
|
int iBool= -1;
|
|
{
|
|
while( pcCommand[ i ] != 0 )
|
|
{
|
|
if( pcCommand[ i ] == '+' )
|
|
{
|
|
iBool= 1;
|
|
iNumber= 0;
|
|
}
|
|
else if( pcCommand[ i ] == '-' )
|
|
{
|
|
iBool= 0;
|
|
iNumber= 0;
|
|
}
|
|
else if( pcCommand[ i ] >= '0' && pcCommand[ i ] <= '9' )
|
|
{
|
|
iNumber= 10 * iNumber + pcCommand[ i ] - '0';
|
|
}
|
|
else if( pcCommand[ i ] == 'w' )
|
|
{
|
|
if( iBool != -1 )
|
|
{
|
|
bWindowed= iBool == 1;
|
|
}
|
|
iBool= -1;
|
|
iNumber= 0;
|
|
}
|
|
else if( pcCommand[ i ] == 'l' )
|
|
{
|
|
if( iBool != -1 )
|
|
{
|
|
bLowDetail= iBool == 1;
|
|
}
|
|
iBool= -1;
|
|
iNumber= 0;
|
|
}
|
|
else if( pcCommand[ i ] == 'x' )
|
|
{
|
|
if( iNumber > 0 )
|
|
{
|
|
c_iScreenSizeX= iNumber;
|
|
}
|
|
iNumber= 0;
|
|
}
|
|
else if( pcCommand[ i ] == 'y' )
|
|
{
|
|
if( iNumber > 0 )
|
|
{
|
|
c_iScreenSizeY= iNumber;
|
|
}
|
|
iNumber= 0;
|
|
}
|
|
else
|
|
{
|
|
iNumber= 0;
|
|
iBool= -1;
|
|
}
|
|
|
|
i++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void PrepareDemoSetup()
|
|
{
|
|
#ifndef DISABLEAUTOSCREEN
|
|
c_iScreenSizeX = GetSystemMetrics( SM_CXSCREEN );
|
|
c_iScreenSizeY = GetSystemMetrics( SM_CYSCREEN );
|
|
#endif
|
|
/***********************************************************************************/
|
|
|
|
#if defined(CAMERATESTER)
|
|
ReadDemoCommandLine();
|
|
#elif defined(MESHTESTER)
|
|
ReadMeshviewerCommandLine();
|
|
#else
|
|
ReadDemoCommandLine();
|
|
#endif
|
|
|
|
c_iRealScreenY= c_iScreenSizeX * 9 / 16;
|
|
if( c_iRealScreenY > c_iScreenSizeY )
|
|
{
|
|
c_iRealScreenY= c_iScreenSizeY;
|
|
}
|
|
}
|
|
|
|
#ifdef EXTRACODE
|
|
LRESULT MessageCallback(HWND ar_Handle, UINT aw_Message, WPARAM aw_Param, LPARAM al_Param)
|
|
{
|
|
return DefWindowProc(ar_Handle, aw_Message, aw_Param, al_Param);
|
|
}
|
|
#endif
|
|
|
|
void CreateWnd()
|
|
{
|
|
HWND& hwnd= d3dpp.hDeviceWindow;
|
|
|
|
#ifdef EXTRACODE
|
|
WNDCLASSEX wndclass;
|
|
wndclass.cbSize = sizeof (wndclass) ;
|
|
wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
|
|
wndclass.lpfnWndProc = (WNDPROC)MessageCallback ;
|
|
wndclass.cbClsExtra = 0 ;
|
|
wndclass.cbWndExtra = 0 ;
|
|
wndclass.hInstance = g_hInstance ;
|
|
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
|
|
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
|
|
wndclass.hbrBackground = (HBRUSH) GetStockObject (DKGRAY_BRUSH) ;
|
|
wndclass.lpszMenuName = NULL;
|
|
wndclass.lpszClassName = "Evoke64kWindow" ;
|
|
wndclass.hIconSm = LoadIcon (NULL, IDI_APPLICATION) ;
|
|
|
|
RegisterClassEx(&wndclass);
|
|
|
|
hwnd = CreateWindow(
|
|
"Evoke64kWindow", /* Classname */
|
|
WindowTitle, /* Title Text */
|
|
WS_OVERLAPPED | WS_CAPTION, /* default window */
|
|
10, /* Windows decides the position */
|
|
30, /* where the window ends up on the screen */
|
|
c_iScreenSizeX, /* The programs width */
|
|
c_iScreenSizeY, /* and height in pixels */
|
|
NULL, /* The window is a child-window to desktop */
|
|
NULL, /* No menu */
|
|
g_hInstance, /* Program Instance handler */
|
|
NULL /* No Window Creation data */
|
|
);
|
|
#else
|
|
hwnd = CreateWindow(
|
|
"STATIC", /* Classname */
|
|
WindowTitle, /* Title Text */
|
|
WS_POPUP, /* default window */
|
|
10, /* Windows decides the position */
|
|
30, /* where the window ends up on the screen */
|
|
c_iScreenSizeX, /* The programs width */
|
|
c_iScreenSizeY, /* and height in pixels */
|
|
NULL, /* The window is a child-window to desktop */
|
|
NULL, /* No menu */
|
|
0, //GetModuleHandle(NULL), /* Program Instance handler */
|
|
NULL /* No Window Creation data */
|
|
);
|
|
#endif
|
|
#ifndef _DEBUG
|
|
ShowCursor(false);
|
|
#endif
|
|
|
|
#if defined(CAMERATESTER) || defined(MESHTESTER)
|
|
EditorHelp::SetHWND( hwnd );
|
|
#endif
|
|
}
|
|
|
|
void CreateD3DDevice()
|
|
{
|
|
HWND& hwnd= d3dpp.hDeviceWindow;
|
|
|
|
g_D3D= Direct3DCreate9( D3D_SDK_VERSION );
|
|
|
|
if( bWindowed )
|
|
{
|
|
ShowWindow (hwnd , SW_NORMAL );
|
|
#ifdef EXTRACODE
|
|
// set exact client size
|
|
RECT rcClient, rcWindow;
|
|
POINT ptDiff;
|
|
GetClientRect(hwnd, &rcClient);
|
|
GetWindowRect(hwnd, &rcWindow);
|
|
ptDiff.x = (rcWindow.right - rcWindow.left) - rcClient.right;
|
|
ptDiff.y = (rcWindow.bottom - rcWindow.top) - rcClient.bottom;
|
|
MoveWindow(hwnd,rcWindow.left, rcWindow.top, c_iScreenSizeX + ptDiff.x, c_iScreenSizeY + ptDiff.y, TRUE);
|
|
|
|
#endif
|
|
}
|
|
d3dpp.Windowed = bWindowed;
|
|
|
|
d3dpp.BackBufferWidth= c_iScreenSizeX;
|
|
d3dpp.BackBufferHeight= c_iScreenSizeY;
|
|
|
|
if( !bLowDetail )
|
|
{
|
|
if( g_d3d_device == NULL )
|
|
{
|
|
g_D3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hwnd,D3DCREATE_FPU_PRESERVE|D3DCREATE_HARDWARE_VERTEXPROCESSING,&d3dpp,&g_d3d_device);
|
|
}
|
|
|
|
if( g_d3d_device == NULL )
|
|
{
|
|
d3dpp.MultiSampleType= D3DMULTISAMPLE_8_SAMPLES;
|
|
g_D3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hwnd,D3DCREATE_FPU_PRESERVE|D3DCREATE_HARDWARE_VERTEXPROCESSING,&d3dpp,&g_d3d_device);
|
|
}
|
|
if( g_d3d_device == NULL )
|
|
{
|
|
d3dpp.MultiSampleType= D3DMULTISAMPLE_4_SAMPLES;
|
|
g_D3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hwnd,D3DCREATE_FPU_PRESERVE|D3DCREATE_HARDWARE_VERTEXPROCESSING,&d3dpp,&g_d3d_device);
|
|
}
|
|
if( g_d3d_device == NULL )
|
|
{
|
|
d3dpp.MultiSampleType= D3DMULTISAMPLE_2_SAMPLES;
|
|
g_D3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hwnd,D3DCREATE_FPU_PRESERVE|D3DCREATE_HARDWARE_VERTEXPROCESSING,&d3dpp,&g_d3d_device);
|
|
}
|
|
}
|
|
|
|
|
|
if( g_d3d_device == NULL )
|
|
{
|
|
d3dpp.MultiSampleType= D3DMULTISAMPLE_NONE;
|
|
g_D3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hwnd,D3DCREATE_FPU_PRESERVE|D3DCREATE_HARDWARE_VERTEXPROCESSING,&d3dpp,&g_d3d_device);
|
|
}
|
|
if( g_d3d_device == NULL )
|
|
{
|
|
d3dpp.MultiSampleType= D3DMULTISAMPLE_NONE;
|
|
g_D3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hwnd,D3DCREATE_FPU_PRESERVE|D3DCREATE_SOFTWARE_VERTEXPROCESSING,&d3dpp,&g_d3d_device);
|
|
}
|
|
|
|
if( g_d3d_device == NULL )
|
|
{
|
|
MessageBox( NULL,
|
|
"D3D not initialized!",
|
|
"fatal Error",
|
|
MB_OK );
|
|
ExitProcess( -1 );
|
|
}
|
|
}
|
|
|
|
void PrepareTextures()
|
|
{
|
|
g_pTextures[ TI_RotMatrix ].Create( 32, 32, 1, 1 );
|
|
g_pTextures[ TI_RotMatrix ].PrepareRotMatrix();
|
|
g_pTextures[ TI_Random ].Create( 32, 32, 1, 0 );
|
|
g_pTextures[ TI_Random ].PrepareRandomTexture();
|
|
g_pTextures[ TI_RandomCube ].Create( 32, 32, 32, 0 );
|
|
g_pTextures[ TI_RandomCube ].PrepareRandomTexture();
|
|
|
|
g_pTextures[ TI_Wave ].Create( 1024, 1024, 1, 0 );
|
|
}
|
|
|
|
void GenerateShaderTextures()
|
|
{
|
|
#ifdef EXTRACODE
|
|
static int iShaderTextureRevision = 0;
|
|
|
|
if(iShaderTextureRevision != g_Shaders[ TexGen_Perlin ].GetRevision())
|
|
{
|
|
#endif
|
|
g_pTextures[ TI_Wave ].PrepareShaderTexture( TexGen_Perlin, TexGen_Wave, TexGen_Normal );
|
|
|
|
#ifdef EXTRACODE
|
|
iShaderTextureRevision = g_Shaders[ TexGen_Perlin ].GetRevision();
|
|
}
|
|
#endif
|
|
}
|
|
|
|
D3DXCOLOR g_FadeColor(0.0f, 0.0f, 0.0f, 0.0f);
|
|
float g_fLogoIntensity;
|
|
|
|
void RenderCubeMap()
|
|
{
|
|
g_d3d_device->BeginScene();
|
|
|
|
// Set sky
|
|
g_SkyBox.m_iUsedShader[0] = CaveSky;
|
|
|
|
// Set cube camera & light
|
|
memcpy(&g_Camera, &g_CubeMapCamera, sizeof(g_Camera));
|
|
D3DXVec3Normalize(&g_LightDir, &g_CubeMapLightDir);
|
|
|
|
// Generate matrices
|
|
FillCameraMatrix( g_Camera.m_vec3Pos, g_Camera.m_vec3Rot, &g_matView );
|
|
g_Environment.Update(g_matView);
|
|
|
|
Shader::SetConstants(true);
|
|
|
|
// Render cube map
|
|
Renderpipe::CubeRenderPass();
|
|
Renderpipe::CubeBlurPass();
|
|
|
|
g_d3d_device->EndScene();
|
|
|
|
g_d3d_device->Present( NULL, NULL, NULL, NULL );
|
|
|
|
/* // Save to file
|
|
D3DXSaveTextureToFile( "EnvMap.dds", D3DXIFF_DDS, g_pCubeRT[RT_ENVCUBE], NULL );
|
|
D3DXSaveTextureToFile( "BlurredEnvMap.dds", D3DXIFF_DDS, g_pCubeRT[RT_ENVCUBEINT], NULL );
|
|
*/
|
|
}
|
|
|
|
void DoDemoMain()
|
|
{
|
|
PrepareText();
|
|
RenderLoading( 1 );
|
|
|
|
PrepareShaders();
|
|
|
|
/***********************************************************************************/
|
|
//generate Demo Zeugs...
|
|
g_Random.setSeed( 27 );
|
|
PrepareFlockObjects();
|
|
PrepareSwarm();
|
|
|
|
RenderLoading( 2 );
|
|
|
|
/***********************************************************************************/
|
|
g_FullScreenQuad.InitFullScreenQuad();
|
|
|
|
PrepareTextures();
|
|
GenerateShaderTextures();
|
|
|
|
RenderLoading( 2 );
|
|
Texture::Prepare1DTextures();
|
|
|
|
g_PSSM.m_iSplitCount = bLowDetail ? 3 : 6; //config
|
|
g_PSSM.m_fRange = 240.0f;
|
|
|
|
// Sky
|
|
g_SkyBox.Create( 24, 36 );
|
|
g_SkyBox.m_iUsedPreShader= SkyDepth;
|
|
g_SkyBox.m_iUsedShader[ 0 ]= Sky;
|
|
g_SkyBox.Lock();
|
|
g_SkyBox.AddBox(
|
|
D3DXVECTOR3( 0.0f, 0.0f, 0.0f),
|
|
D3DXVECTOR3( 1.0f, 1.0f, 1.0f),
|
|
D3DXVECTOR3( 0.0f, 0.0f, 0.0f ),
|
|
0xff20b0f0);
|
|
g_SkyBox.Unlock();
|
|
|
|
// Terrain
|
|
D3DXMATRIX matTerrainWorld, matTerrainPos;
|
|
D3DXMatrixScaling(&matTerrainWorld, 500, 100, 500);
|
|
D3DXMatrixRotationYawPitchRoll( &matTerrainPos, 0.0f, 0.0f, 0.0f );
|
|
D3DXMatrixMultiply( &matTerrainWorld,&matTerrainWorld,&matTerrainPos);
|
|
D3DXMatrixTranslation(&matTerrainPos, -250, -27.0f, -250);
|
|
D3DXMatrixMultiply(&matTerrainWorld, &matTerrainWorld, &matTerrainPos);
|
|
|
|
#ifdef TERRAIN
|
|
{
|
|
#ifdef EXTRACODE
|
|
OutputDebugString( "Creating isle: \n" );
|
|
DWORD dwTicks = GetTickCount();
|
|
#endif
|
|
|
|
if( bLowDetail )
|
|
{
|
|
g_IsleTerrainGrid.Init( 224, 48, &TerrainGrid::IsoSurfaceIsle );
|
|
}
|
|
else
|
|
{
|
|
g_IsleTerrainGrid.Init( 384, 64, &TerrainGrid::IsoSurfaceIsle );
|
|
}
|
|
|
|
#ifdef EXTRACODE
|
|
char cTime[128];
|
|
dwTicks = GetTickCount() - dwTicks;
|
|
sprintf_s( cTime, "Time: %d \n", dwTicks );
|
|
OutputDebugString( cTime );
|
|
#endif
|
|
}
|
|
|
|
g_Objects[ OI_ISLE_FIRST ].m_iUsedPreShader = TerrainDepth;
|
|
g_Objects[ OI_ISLE_FIRST ].m_iUsedShader[ 0 ] = Terrain;
|
|
g_Objects[ OI_ISLE_FIRST ].SetTransformation(matTerrainWorld);
|
|
g_Objects[ OI_ISLE_FIRST ].m_pTerrain = &g_IsleTerrainGrid;
|
|
#endif
|
|
|
|
/*
|
|
g_Objects[ OI_CAVE_GROUND ].m_iUsedPreShader = TerrainDepth;
|
|
g_Objects[ OI_CAVE_GROUND ].m_iUsedShader[ 0 ] = Terrain;
|
|
// g_Objects[ OI_CAVE_GROUND ].m_pTerrain = &g_CaveGroundTerrainGrid;
|
|
g_Objects[ OI_CAVE_GROUND ].SetTransformation(matTerrainWorld);
|
|
*/
|
|
// Ocean
|
|
g_Ocean.Create( 4 * 9, 6 * 9 );
|
|
g_Ocean.m_iUsedPreShader= PreDepth;
|
|
g_Ocean.m_iUsedShader[ 0 ]= Ocean;
|
|
|
|
g_OceanWater.m_fWaterLevel = 5.0f;
|
|
|
|
g_Ocean.Lock();
|
|
g_Ocean.AddPlane(
|
|
D3DXVECTOR3( 0, g_OceanWater.m_fWaterLevel, 0 ),
|
|
D3DXVECTOR3( 0.0f, 0.0f, 0.0f ),
|
|
0xFFB5DCFF, // 0x8040ff40
|
|
D3DXVECTOR3( 500.0f, 0.0f, 500.0f ),
|
|
D3DXVECTOR3( 5000.0f, 0.0f, 5000.0f ) );
|
|
|
|
g_Ocean.Unlock();
|
|
|
|
//g_Objects[ 1 ].Create( 127 * 127 * 4, 127 * 127 * 6 );
|
|
//g_Objects[ 1 ].m_iUsedPreShader= PreDepth;
|
|
//g_Objects[ 1 ].m_iUsedShader[ 0 ]= Tarmac;
|
|
//g_Objects[ 1 ].m_iUsedShader[ 1 ]= Grass;
|
|
//g_Objects[ 1 ].m_bAlphaEnable[ 1 ]= true;
|
|
//g_Objects[ 1 ].m_SrcBlend[ 1 ]= D3DBLEND_ONE;
|
|
//g_Objects[ 1 ].m_DestBlend[ 1 ]= D3DBLEND_INVSRCALPHA;
|
|
//g_Objects[ 1 ].m_BlendOp[ 1 ]= D3DBLENDOP_ADD;
|
|
|
|
//g_Objects[ 1 ].Lock();
|
|
//g_Objects[ 1 ].AddGround(
|
|
// D3DXVECTOR3( 0.0f, -1.0f, 0.0f ),
|
|
// D3DXVECTOR3( 500.0f, 1.0f, 500.0f ),
|
|
// D3DXVECTOR3( 0.0f, 0.0f, 0.0f ),
|
|
// 0xFFFFDCB5, // 0x8040ff40
|
|
// 80.0f,
|
|
// 112.0f,
|
|
// 0.75f,
|
|
// 120.0f,
|
|
// 127,
|
|
// 127);
|
|
|
|
//g_Objects[ 1 ].Unlock();
|
|
|
|
{
|
|
int iObj= OI_ISLE_FIRST + 1;
|
|
CreateDuck( g_Objects[ iObj ] );
|
|
g_Objects[ iObj ].m_iUsedPreShader= PreDepth;
|
|
g_Objects[ iObj ].m_iUsedShader[ 0 ]= EnvLit;
|
|
|
|
iObj++;
|
|
CreateDuck( g_Objects[ iObj ] );
|
|
g_Objects[ iObj ].m_iUsedPreShader= PreDepth;
|
|
g_Objects[ iObj ].m_iUsedShader[ 0 ]= EnvLit;
|
|
|
|
iObj++;
|
|
CreateAtari( g_Objects[ iObj ] );
|
|
g_Objects[ iObj ].m_iUsedPreShader= PreDepth;
|
|
g_Objects[ iObj].m_iUsedShader[ 0 ]= EnvLit;
|
|
|
|
iObj++;
|
|
CreateCommod( g_Objects[ iObj ] );
|
|
g_Objects[ iObj ].m_iUsedPreShader= PreDepth;
|
|
g_Objects[ iObj ].m_iUsedShader[ 0 ]= EnvLit;
|
|
|
|
// Logos fuer Endszene
|
|
iObj= OI_OUTRO1;
|
|
CreateAtari( g_Objects[ iObj ] );
|
|
g_Objects[ iObj ].m_iUsedPreShader= PreDepth;
|
|
g_Objects[ iObj].m_iUsedShader[ 0 ]= EnvLit;
|
|
|
|
iObj= OI_OUTRO2;
|
|
CreateCommod( g_Objects[ iObj ] );
|
|
g_Objects[ iObj ].m_iUsedPreShader= PreDepth;
|
|
g_Objects[ iObj ].m_iUsedShader[ 0 ]= EnvLit;
|
|
|
|
iObj= OI_OUTRO3;
|
|
CreateDuck( g_Objects[ iObj ] );
|
|
g_Objects[ iObj ].m_iUsedPreShader= PreDepth;
|
|
g_Objects[ iObj ].m_iUsedShader[ 0 ]= EnvLit;
|
|
//g_Objects[ iObj ].m_iUsedShader[ 0 ]= Terrain;
|
|
}
|
|
/*CreateSpeaker( g_Objects[ OI_OBJTEST + 3 ] );
|
|
g_Objects[ OI_OBJTEST + 3 ].m_iUsedPreShader= PreDepth;
|
|
g_Objects[ OI_OBJTEST + 3 ].m_iUsedShader[ 0 ]= EnvLit;*/
|
|
RenderLoading( 2 );
|
|
|
|
/*D3DXMatrixTranslation( &mat, -20.0f, 3.0f, 0.0f );
|
|
g_Objects[ OI_OBJTEST ].SetTransformation( mat );
|
|
D3DXMatrixTranslation( &mat, 0.0f, 10.0f, 0.0f );
|
|
g_Objects[ OI_OBJTEST + 1 ].SetTransformation( mat );
|
|
D3DXMatrixTranslation( &mat, 20.0f, 10.0f, 0.0f );
|
|
g_Objects[ OI_OBJTEST + 2 ].SetTransformation( mat );
|
|
D3DXMatrixTranslation( &mat, 0.0f, 25.0f, 0.0f );
|
|
g_Objects[ OI_OBJTEST + 3 ].SetTransformation( mat );*/
|
|
|
|
{
|
|
int iObj;
|
|
|
|
iObj= OI_MAGE;
|
|
CreateMagier( g_Objects[ iObj ] );
|
|
g_Objects[ iObj ].m_iUsedPreShader= PreDepth;
|
|
g_Objects[ iObj ].m_iUsedShader[ 0 ]= EnvLit;
|
|
|
|
iObj= OI_MAGE2;
|
|
CreateMagier( g_Objects[ iObj ] );
|
|
g_Objects[ iObj ].m_iUsedPreShader= PreDepth;
|
|
g_Objects[ iObj ].m_iUsedShader[ 0 ]= EnvLit;
|
|
|
|
iObj= OI_YETI1;
|
|
CreateYeti( g_Objects[ OI_YETI1 ] );
|
|
g_Objects[ iObj ].m_iUsedPreShader= PreDepth;
|
|
g_Objects[ iObj ].m_iUsedShader[ 0 ]= EnvLit;
|
|
|
|
iObj= OI_YETI2;
|
|
CreateYeti( g_Objects[ OI_YETI2 ] );
|
|
g_Objects[ iObj ].m_iUsedPreShader= PreDepth;
|
|
g_Objects[ iObj ].m_iUsedShader[ 0 ]= EnvLit;
|
|
|
|
/*D3DXMATRIX matResult;
|
|
D3DXMATRIX mat;
|
|
D3DXMatrixScaling( &matResult, g_MageScale, g_MageScale, g_MageScale );
|
|
D3DXMatrixRotationYawPitchRoll( &mat, 0.0f, 0.0f, 0.0f );
|
|
D3DXMatrixMultiply( &matResult,&matResult,&mat);
|
|
D3DXMatrixTranslation( &mat, 0.0f, g_MageHeight, 0.0f );
|
|
D3DXMatrixMultiply( &matResult,&matResult,&mat);
|
|
|
|
g_Objects[ iObj ].SetTransformation( matResult );*/
|
|
}
|
|
|
|
RenderLoading( 1 );
|
|
CreateCaveRenderJobs();
|
|
|
|
g_Objects[ OI_CYLINDER ].Create( 1 << 15, 1 << 16, true );
|
|
g_Objects[ OI_CYLINDER ].m_iUsedPreShader= PreDepth;
|
|
g_Objects[ OI_CYLINDER ].m_iUsedShader[ 0 ]= EnvLit;
|
|
//D3DXMatrixTranslation( &mat, 15.0f, 18.0f, -8.0f );
|
|
//g_Objects[ OI_CYLINDER ].SetTransformation( mat );
|
|
|
|
g_Objects[ OI_SPIKEBALL ].Create( 1 << 15, 1 << 16, true );
|
|
g_Objects[ OI_SPIKEBALL ].m_iUsedPreShader= PreDepth;
|
|
g_Objects[ OI_SPIKEBALL ].m_iUsedShader[ 0 ]= EnvLit;
|
|
D3DXMATRIX mat;
|
|
D3DXMatrixScaling( &mat, 3.0f, 3.0f, 3.0f );
|
|
g_Objects[ OI_SPIKEBALL ].SetTransformation( mat );
|
|
|
|
for( int i= OI_GREEBLE_1; i <= OI_GREEBLE_2; ++i )
|
|
{
|
|
g_Objects[ i ].Create( 1 << 16, 1 << 17, true );
|
|
g_Objects[ i ].m_iUsedPreShader= PreDepth;
|
|
g_Objects[ i ].m_iUsedShader[ 0 ]= EnvLit;
|
|
}
|
|
|
|
g_SpikeBall.PrepareBaseSphere();
|
|
RenderLoading( 2 );
|
|
|
|
// Fluid
|
|
#ifndef DISABLEFLUIDS
|
|
g_FluidContext.BuildUp(d3dpp.BackBufferWidth, d3dpp.BackBufferHeight, d3dpp.MultiSampleType);
|
|
FluidSettings fluidSettings;
|
|
fluidSettings.DiffuseTexture = g_pTextures[ TI_RandomCube ].GetPointer();
|
|
fluidSettings.BlurSteps = &g_FluidBlurSteps;
|
|
fluidSettings.LightTransferAmmount = &g_FluidLightTransferAmmount;
|
|
fluidSettings.Softness = &g_FluidSoftness;
|
|
fluidSettings.SpecularFactor = &g_FluidSpecularFactor;
|
|
fluidSettings.SpecularPower = &g_FluidSpecularPower;
|
|
fluidSettings.SurfaceTension = &g_FluidSurfaceTension;
|
|
fluidSettings.TextureScale = &g_FluidTextureScale;
|
|
fluidSettings.TranslucencyAmmount = &g_FluidTranslucencyAmmount;
|
|
fluidSettings.RefractAmmount = &g_FluidRefractAmmount;
|
|
fluidSettings.DepthDifferenceBlur = &g_DepthDifferenceBlur;
|
|
fluidSettings.RenderTextureSizeScale = &g_FluidRenderTextureSizeScale;
|
|
g_Fluid = g_FluidContext.GenerateFluid(fluidSettings);
|
|
|
|
|
|
#ifdef DISABLEFLOCKFLUIDS
|
|
|
|
g_SpikeBall.AddToScene( 0.0f, OI_SPIKEBALL );
|
|
PointMapGenerator::FillPointMap(PMI_Spike, OI_SPIKEBALL, FI_Spike, 4);
|
|
g_Objects[ OI_SPIKEBALL ].HideVertexData();
|
|
|
|
Twist::AddToScene(0.0f, OI_CYLINDER);
|
|
PointMapGenerator::FillPointMap(PMI_Cylinder, OI_CYLINDER, FI_Cylinder, 4);
|
|
g_Objects[ OI_CYLINDER ].HideVertexData();
|
|
|
|
for( int i= 0; i < 2; ++i )
|
|
{
|
|
D3DXMATRIX matTrans;
|
|
g_Greeble.AddToScene( 0.0f, OI_GREEBLE_1 + i, i );
|
|
PointMapGenerator::FillPointMap(PMI_Greeble1 + i, OI_GREEBLE_1 + i, FI_Greeble1 + i, 1);
|
|
g_Objects[ OI_GREEBLE_1 + i ].HideVertexData();
|
|
}
|
|
|
|
#else
|
|
g_FluidParticleSystem = g_FluidContext.GenerateFluidParticleSystem(10000);
|
|
g_FluidParticleSystem.InstanceCount = 0;
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
CreateTextRenderJobs();
|
|
|
|
#ifdef EXTRACODE
|
|
OutputDebugString( "Creating cubemap: \n" );
|
|
# endif
|
|
|
|
RenderLoading( 1 );
|
|
|
|
RenderCubeMap();
|
|
RenderLoading( 1 );
|
|
|
|
/***********************************************************************************/
|
|
// Sound
|
|
// Sound
|
|
#ifdef STARTMUSIC
|
|
player.Init();
|
|
# ifdef MUSICLOAD
|
|
|
|
if( loadMusic() )
|
|
{
|
|
player.Open(pLoadSong);
|
|
}
|
|
# else
|
|
player.Open(pSong);
|
|
# endif
|
|
|
|
|
|
dsInit(player.RenderProxy,&player,GetForegroundWindow());
|
|
|
|
# ifdef SCRIPTEDITOR
|
|
player.Play( g_iSkipTicks * g_iTempo / 1411 );
|
|
g_iSampleOffset= g_iSampleOffsetGeneral -
|
|
g_iSkipTicks * g_iTempo / 32;
|
|
# else
|
|
player.Play();
|
|
# endif
|
|
|
|
#else
|
|
g_dwTimeReplaceStart= timeGetTime();
|
|
#endif
|
|
|
|
/***********************************************************************************/
|
|
//Mainloop
|
|
int LastCamTick= 0;
|
|
|
|
//g_ScriptState.Prepare();
|
|
|
|
//STargetValue tvBumping1( 1.0f, 1.0f, 0.0f, 0.05f, 0.85f );
|
|
|
|
do
|
|
{
|
|
#ifdef EXTRACODE
|
|
if( CheckFileWatch() )
|
|
{
|
|
GenerateShaderTextures();
|
|
|
|
# ifndef STARTMUSIC
|
|
g_dwTimeReplaceStart= timeGetTime();
|
|
# else
|
|
# ifdef SCRIPTEDITOR
|
|
player.Play( g_iSkipTicks * g_iTempo / 1411 );
|
|
g_iSampleOffset= player.GetPlayTick() +
|
|
g_iSampleOffsetGeneral -
|
|
g_iSkipTicks * g_iTempo / 32;
|
|
# else
|
|
player.Play();
|
|
g_iSampleOffset= player.GetPlayTick() +
|
|
g_iSampleOffsetGeneral;
|
|
# endif
|
|
# endif
|
|
//g_ScriptState.Prepare();
|
|
}
|
|
#endif
|
|
|
|
#ifdef STARTMUSIC
|
|
g_dwSamplesPassed= (int)player.GetPlayTick() - g_iSampleOffset;
|
|
#else
|
|
g_dwSamplesPassed= (timeGetTime() - g_dwTimeReplaceStart ) * 441 / 10;
|
|
#endif
|
|
DWORD dwNewSamples= g_dwSamplesPassed - g_dwSamples;
|
|
g_dwSamples= g_dwSamplesPassed;
|
|
|
|
/***********************************************************************************/
|
|
#ifdef STARTMUSIC
|
|
float fL, fR;
|
|
player.GetChannelVU( 0, &fL, &fR );
|
|
g_vuBaseDrum.Set( g_dwSamples / 100 + 88, fL + fR );
|
|
player.GetChannelVU( 1, &fL, &fR );
|
|
g_vuSnare.Set( g_dwSamples / 100 + 88, fL + fR );
|
|
#endif
|
|
|
|
// Testkamera setzen
|
|
#if defined(CAMERATESTER)
|
|
EditorHelp::CheckKeys();
|
|
float fCamTime= (float)dwNewSamples / (float)g_iTempo * (float)g_iCamTickFactor;
|
|
InterpolateCamGlobal((int)fCamTime, g_Camera);
|
|
g_fCamTime+= fCamTime;
|
|
|
|
# ifdef STARTMUSIC
|
|
static DWORD LastMusicSetTick= timeGetTime();
|
|
if( !IsFreeCam() && EditorHelp::m_KeyPressed[ 'M' ] )
|
|
{
|
|
if( timeGetTime() > LastMusicSetTick + 1000 )
|
|
{
|
|
float fNeededSec= (float)GetRealTime() / (float)g_iCamTickFactor * (float)g_iTempo / 44100.0f;
|
|
float fMusicSec= (float)player.GetPlayTickOffset() / 44100.0f;
|
|
float fDiff= abs( fMusicSec - fNeededSec );
|
|
if( fDiff > 0.1f )
|
|
{
|
|
LastMusicSetTick= timeGetTime();
|
|
player.Play( (int)(fNeededSec * 1000.0f ) );
|
|
/*g_iSampleOffset= player.GetPlayTick() +
|
|
g_iSampleOffsetGeneral;*/
|
|
}
|
|
}
|
|
}
|
|
# endif
|
|
|
|
#elif defined(MESHTESTER)
|
|
EditorHelp::CheckKeys();
|
|
float fCamTime= (float)dwNewSamples / (float)g_iTempo * (float)g_iCamTickFactor;
|
|
UserCam( (int)(fCamTime * 1.0f ) );
|
|
GetEditCam( g_Camera );
|
|
g_fCamTime+= fCamTime;
|
|
#else
|
|
float fCamTime= (float)g_dwSamples / (float)g_iTempo * (float)g_iCamTickFactor;
|
|
int CurCamTick= (int)fCamTime;
|
|
PlayCam( CurCamTick - LastCamTick, g_Camera);
|
|
LastCamTick= CurCamTick;
|
|
g_fCamTime= fCamTime;
|
|
#endif
|
|
|
|
g_fShaderBeat= g_vuBaseDrum.Get( g_dwSamples / 100 );
|
|
|
|
float fDemoTime= (float)g_Camera.m_iDemoTime / (float)g_iCamTickFactor;
|
|
float fFrozenObjTime= TimeToFrozenObj( fDemoTime + g_vuSnare.Get( g_dwSamples / 100 ) / 8.0f );
|
|
|
|
//float fRes= 1.0f - minimum( 1.0f,( g_vuLightBeat.Get( g_dwSamples / 100 ) ) * 0.475f );
|
|
//d3dMaterial.Power= 1.25f + mypow( fRes, 0.33f ) * 31.0f;
|
|
|
|
/***********************************************************************************/
|
|
//Spline Test
|
|
if( false )
|
|
{
|
|
float fSplineTime= fDemoTime;
|
|
AddFlockObjectsToScene( fFrozenObjTime );
|
|
}
|
|
|
|
/***********************************************************************************/
|
|
if( IsObjInScene( OI_CYLINDER ) )
|
|
{
|
|
Twist::AddToScene( fFrozenObjTime, OI_CYLINDER );
|
|
#ifndef DISABLEFLUIDS
|
|
if( IsObjInScene( OI_FLUIDS ))
|
|
{
|
|
FluidContext::MeltObject(OI_CYLINDER, FI_Cylinder, PMI_Cylinder, fDemoTime);
|
|
g_FluidParticleSystem[FI_Cylinder].IsVisible = true;
|
|
}
|
|
else
|
|
{
|
|
g_FluidParticleSystem[FI_Cylinder].IsVisible = false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
g_FluidParticleSystem[FI_Cylinder].IsVisible = false;
|
|
#endif
|
|
}
|
|
|
|
if( IsObjInScene( OI_SPIKEBALL ))
|
|
{
|
|
g_SpikeBall.AddToScene( fFrozenObjTime, OI_SPIKEBALL );
|
|
#ifndef DISABLEFLUIDS
|
|
if( IsObjInScene( OI_FLUIDS ))
|
|
{
|
|
FluidContext::MeltObject(OI_SPIKEBALL, FI_Spike, PMI_Spike, fDemoTime);
|
|
g_FluidParticleSystem[FI_Spike].IsVisible = true;
|
|
}
|
|
else
|
|
{
|
|
g_FluidParticleSystem[FI_Spike].IsVisible = false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
g_FluidParticleSystem[FI_Spike].IsVisible = false;
|
|
#endif
|
|
}
|
|
|
|
for( int i= 0; i < 2; ++i )
|
|
{
|
|
if( IsObjInScene( (ObjectIndices)(OI_GREEBLE_1 + i) ))
|
|
{
|
|
D3DXMATRIX matTrans;
|
|
g_Greeble.AddToScene( fFrozenObjTime, OI_GREEBLE_1 + i, i );
|
|
D3DXMatrixScaling( &matTrans, 0.25f, 0.25f, 0.25f );
|
|
g_Objects[ OI_GREEBLE_1 + i ].SetTransformation( matTrans );
|
|
#ifndef DISABLEFLUIDS
|
|
if( IsObjInScene( OI_FLUIDS ))
|
|
{
|
|
FluidContext::MeltObject( OI_GREEBLE_1 + i, FI_Greeble1 + i, PMI_Greeble1 + i, fDemoTime);
|
|
g_FluidParticleSystem[FI_Greeble1 + i].IsVisible = true;
|
|
}
|
|
else
|
|
{
|
|
g_FluidParticleSystem[FI_Greeble1 + i].IsVisible = false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
g_FluidParticleSystem[FI_Greeble1 + i].IsVisible = false;
|
|
#endif
|
|
}
|
|
}
|
|
|
|
/***********************************************************************************/
|
|
// Logo
|
|
{
|
|
g_fLogoIntensity= 4.0f - abs( - 64.0f - fDemoTime );
|
|
g_fLogoIntensity= minimum( 1.0f, g_fLogoIntensity );
|
|
g_fLogoIntensity= maximum( 0.0f, g_fLogoIntensity );
|
|
}
|
|
|
|
/***********************************************************************************/
|
|
// Sonne bewegen
|
|
{
|
|
|
|
|
|
float fBaseHeight= 0.8f;
|
|
if( fDemoTime < -48.0f )
|
|
{
|
|
fDemoTime= -48.0f;
|
|
}
|
|
|
|
|
|
D3DXMATRIX mSunRotX, mSunRotY, mSunRotZ, mSun;
|
|
D3DXMatrixRotationX( &mSunRotX, fBaseHeight - 0.4f * sin( 0.08f * fDemoTime ));
|
|
D3DXMatrixRotationY( &mSunRotY, 0.3f * fDemoTime );
|
|
D3DXMatrixRotationZ( &mSunRotZ, 0.3f );
|
|
|
|
if( IsObjInScene(OI_CAVE_FIRST) )
|
|
{
|
|
D3DXMatrixRotationX( &mSunRotX, 1.1875f + 0.4f * sin( fDemoTime ));
|
|
D3DXMatrixRotationY( &mSunRotY, -0.6f + 0.25f * sin( fDemoTime * 0.61f ) );
|
|
D3DXMatrixRotationZ( &mSunRotZ, 0.0f );
|
|
}
|
|
/*D3DXMatrixRotationX( &mSunRotX, g_SunX );
|
|
D3DXMatrixRotationY( &mSunRotY, g_SunY );
|
|
D3DXMatrixRotationZ( &mSunRotZ, g_SunZ );*/
|
|
mSun = mSunRotX * mSunRotY * mSunRotZ;
|
|
g_LightDir.x = -mSun._21; g_LightDir.y = -mSun._22; g_LightDir.z = -mSun._23;
|
|
if( IsObjInScene(OI_SKY_CUBEMAP) )
|
|
{
|
|
g_LightDir= g_CubeMapLightDir;
|
|
}
|
|
D3DXVec3Normalize(&g_LightDir, &g_LightDir);
|
|
}
|
|
{
|
|
/*int time= timeGetTime();
|
|
g_fGlow= 1.0f + sin( 0.01f * (float)time );
|
|
g_fGlow= 0.25f * g_fGlow * g_fGlow;*/
|
|
g_fGlow= g_vuSnare.Get( g_dwSamples / 100 );
|
|
g_fGlow= 0.5f * g_fGlow * g_fGlow;
|
|
g_fGlow= min( g_fGlow, 1.5f );
|
|
g_fGlow= max( g_fGlow, 0.0f );
|
|
}
|
|
|
|
// Update sky
|
|
if( IsObjInScene( OI_SKY ) )
|
|
{
|
|
g_SkyBox.m_iUsedShader[0] = Sky;
|
|
}
|
|
else if( IsObjInScene( OI_SKY_CUBEMAP ) )
|
|
{
|
|
g_SkyBox.m_iUsedShader[0] = EnvSky;
|
|
}
|
|
else if( IsObjInScene( OI_SKY_CAVE ) )
|
|
{
|
|
g_SkyBox.m_iUsedShader[0] = CaveSky;
|
|
}
|
|
|
|
/*{
|
|
g_fPlasmaGrid= g_vuLightBeat.Get( g_dwSamples / 100 );
|
|
g_fPlasmaGrid= 1.0f - 0.5f * g_fPlasmaGrid;
|
|
g_fPlasmaGrid= max( g_fPlasmaGrid, 1.0f / 8.0f );
|
|
g_fPlasmaGrid= min( g_fPlasmaGrid, 0.5f );
|
|
}*/
|
|
|
|
/*{
|
|
float fCloudTime= (float)g_dwSamples / (float)g_iTempo;
|
|
g_fClouds= 0.0f;
|
|
if( fCloudTime > 66.0f )
|
|
{
|
|
g_fClouds= 1.0f;
|
|
}
|
|
else if( fCloudTime > 62.0f )
|
|
{
|
|
g_fClouds= (fCloudTime - 62.0f ) * 0.25f;
|
|
}
|
|
|
|
g_fClouds= 0.1875f + 0.35f * g_fClouds;
|
|
}*/
|
|
|
|
if( IsObjInScene( OI_TextFirst ) )
|
|
{
|
|
SetTextPos( (int)(1000.0f * fDemoTime ) );
|
|
}
|
|
|
|
SetEntityPos( (int)(1000.0f * fDemoTime ) );
|
|
|
|
if( IsObjInScene( OI_SWARM_FIRST) )
|
|
{
|
|
UpdateSwarm( fDemoTime );
|
|
}
|
|
|
|
/***********************************************************************************/
|
|
// Cube-Map Renderdurchlauf update
|
|
#ifdef EXTRACODE
|
|
if( ( GetAsyncKeyState( 'R' ) && GetAsyncKeyState( VK_MENU ) ) )
|
|
{
|
|
RenderCubeMap(); // der hier funktioniert so halb, z.b. Himmel ist nicht korrekt
|
|
}
|
|
#endif
|
|
/***********************************************************************************/
|
|
// begin paint loop
|
|
g_d3d_device->BeginScene();
|
|
|
|
// Projektion
|
|
D3DXMATRIX& mat= g_matProjection;
|
|
|
|
float zf= 4800.0f;
|
|
float zn= 0.125f;
|
|
float xScale = g_Camera.m_fFOV * g_Camera.m_fFOV;
|
|
float yScale= xScale / (float)c_iScreenSizeY * (float)c_iScreenSizeX;
|
|
|
|
mat._11= xScale; mat._12= 0; mat._13= 0; mat._14= 0;
|
|
mat._21= 0; mat._22= yScale; mat._23= 0; mat._24= 0;
|
|
mat._31= 0; mat._32= 0; mat._33= zf/(zf-zn); mat._34= 1;
|
|
mat._41= 0; mat._42= 0; mat._43= -zn*zf/(zf-zn);mat._44= 0;
|
|
|
|
/*
|
|
#ifdef EXTRACODE
|
|
// Cube Map lighting test
|
|
if(g_Camera.m_iScene == g_CubeMapCamera.m_iScene)
|
|
D3DXVec3Normalize(&g_LightDir, &g_CubeMapLightDir);
|
|
#endif
|
|
*/
|
|
/***********************************************************************************/
|
|
// main camera
|
|
|
|
FillCameraMatrix( g_Camera.m_vec3Pos, g_Camera.m_vec3Rot, &g_matView );
|
|
|
|
/***********************************************************************************/
|
|
// normaler Renderdurchlauf
|
|
|
|
// Shadow splits aktualisieren
|
|
g_PSSM.UpdateSplits(g_LightDir, g_matView, g_matProjection);
|
|
|
|
// Reflexion aktualisieren
|
|
if( IsObjInScene( OI_OCEAN ) )
|
|
{
|
|
g_OceanWater.Update(g_matView, g_matProjection);
|
|
}
|
|
|
|
#ifdef ULTRASHOT
|
|
// Ultra-shot
|
|
if(GetAsyncKeyState(VK_CONTROL) && GetAsyncKeyState(VK_SHIFT) && GetAsyncKeyState('U'))
|
|
{
|
|
const int iTilesX = ULTRASHOT_TILES, iTilesY = ULTRASHOT_TILES;
|
|
|
|
D3DXMATRIX matProjectionFull = g_matProjection;
|
|
LPDIRECT3DSURFACE9 pReadBackTarget = NULL;
|
|
|
|
// Allocate read-back buffer
|
|
g_d3d_device->CreateOffscreenPlainSurface(d3dpp.BackBufferWidth, d3dpp.BackBufferHeight,
|
|
d3dpp.BackBufferFormat, D3DPOOL_SYSTEMMEM, &pReadBackTarget, NULL);
|
|
|
|
float xTileScale = xScale * iTilesX;
|
|
float yTileScale = yScale * iTilesY;
|
|
|
|
for(int x = 0; x < iTilesX; x++)
|
|
{
|
|
for(int y = 0; y < iTilesY; y++)
|
|
{
|
|
// Projection matrix
|
|
g_matProjection._11= xTileScale;
|
|
g_matProjection._22= yTileScale;
|
|
g_matProjection._31= (float)((iTilesX - 1) - 2 * x);
|
|
g_matProjection._32= (float)(-(iTilesY - 1) + 2 * y);
|
|
|
|
// Render
|
|
g_d3d_device->SetTransform( D3DTS_PROJECTION, &g_matProjection );
|
|
g_d3d_device->SetTransform( D3DTS_VIEW, &g_matView );
|
|
Shader::SetConstants();
|
|
Shader::SetCamera(g_matView, g_matProjection,
|
|
g_Camera.m_vec3Pos, g_CamFront);
|
|
Renderpipe::FullRenderPass();
|
|
|
|
// Resolve render target
|
|
g_d3d_device->StretchRect( g_pFullScreenRTS[ RTS_COLOR_MS ], NULL,
|
|
g_pFullScreenRTS[ RTS_COLOR ], NULL, D3DTEXF_NONE );
|
|
|
|
// Read back target data
|
|
g_d3d_device->GetRenderTargetData( g_pFullScreenRTS[ RTS_COLOR ], pReadBackTarget );
|
|
|
|
char acFilename[512];
|
|
|
|
// Save to file
|
|
sprintf_s( acFilename, "ScreenTile%d_%d_%d.bmp", g_Camera.m_iDemoTime, x, y );
|
|
D3DXSaveSurfaceToFile( acFilename, D3DXIFF_BMP, pReadBackTarget, NULL, NULL );
|
|
}
|
|
}
|
|
|
|
// Release read-back buffer
|
|
pReadBackTarget->Release();
|
|
|
|
// Reset projection matrix
|
|
g_matProjection = matProjectionFull;
|
|
}
|
|
#endif
|
|
|
|
g_d3d_device->SetTransform( D3DTS_PROJECTION, &g_matProjection );
|
|
g_d3d_device->SetTransform( D3DTS_VIEW, &g_matView );
|
|
|
|
Shader::SetConstants();
|
|
Shader::SetCamera(g_matView, g_matProjection,
|
|
g_Camera.m_vec3Pos, g_CamFront);
|
|
|
|
#ifndef DISABLEPOSTPROCESSING
|
|
Renderpipe::FullRenderPass();
|
|
#else
|
|
Renderpipe::SimpleRenderPass();
|
|
#endif
|
|
/***********************************************************************************/
|
|
// Renderdurchlauf abschliessen
|
|
|
|
//Shader aus
|
|
Shader::Deactivate();
|
|
|
|
// Kinobalken
|
|
RenderBars();
|
|
|
|
#ifdef CAMERATESTER
|
|
DrawCameraDebugOutput();
|
|
#endif
|
|
|
|
g_d3d_device->EndScene();
|
|
g_d3d_device->Present( NULL, NULL, NULL, NULL );
|
|
/***********************************************************************************/
|
|
#ifdef _DEBUG
|
|
Sleep( 5 );
|
|
#endif
|
|
|
|
/***********************************************************************************/
|
|
#ifdef EXTRACODE
|
|
// Allow the window to get focus when clicking in it or at the taskbar icon.
|
|
MSG msg;
|
|
if (PeekMessage(&msg, d3dpp.hDeviceWindow, 0, 0, PM_REMOVE))
|
|
{
|
|
TranslateMessage(&msg);
|
|
DispatchMessage(&msg);
|
|
}
|
|
#endif
|
|
#ifdef DISABLEAUTOQUIT
|
|
bool bEsc= GetAsyncKeyState( VK_ESCAPE ) != 0;
|
|
bool bCtrl= GetAsyncKeyState( VK_CONTROL ) != 0 || GetAsyncKeyState( VK_SHIFT) != 0;
|
|
if( bEsc && bCtrl )
|
|
{
|
|
break;
|
|
}
|
|
} while ( true );
|
|
#else
|
|
if( g_dwSamples > g_DemoLength * g_iTempo )
|
|
{
|
|
break;
|
|
}
|
|
} while ( !GetAsyncKeyState( VK_ESCAPE ) );
|
|
#endif
|
|
}
|
|
|
|
#if defined(MESHTESTER)
|
|
void DoMeshViewerMain()
|
|
{
|
|
if( IsInstantQuit() )
|
|
{
|
|
DoInstantQuit();
|
|
}
|
|
else
|
|
{
|
|
PrepareText();
|
|
PrepareShaders();
|
|
PrepareTextures();
|
|
CreateTextRenderJobs();
|
|
|
|
PrepareMeshViewer();
|
|
MeshViewerMainLoop();
|
|
}
|
|
}
|
|
#endif
|
|
|
|
void WinEntry(void)
|
|
{
|
|
#ifdef EXTRACODE
|
|
ParseDir("tweak");
|
|
InitFileMon();
|
|
#endif
|
|
InitGlobals();
|
|
|
|
PrepareDemoSetup();
|
|
|
|
CreateWnd();
|
|
CreateD3DDevice();
|
|
|
|
#ifdef EXTRACODE
|
|
StartFileWatch();
|
|
ReadDataFromDisc();
|
|
#else
|
|
PreparePlayCam();
|
|
#endif
|
|
|
|
g_fResolutionFactor = max(d3dpp.BackBufferWidth / 1024.f, d3dpp.BackBufferHeight / 768.f);
|
|
|
|
{
|
|
g_iResolutionFactorExp = 0;
|
|
float fResFactor = g_fResolutionFactor;
|
|
while(fResFactor <= .75f) { g_iResolutionFactorExp--; fResFactor *= 2.f; }
|
|
while(fResFactor >= 1.75f) { g_iResolutionFactorExp++; fResFactor *= 0.5f; }
|
|
}
|
|
|
|
g_nShadowResolution= ( bLowDetail ? 1 : 26 ) * max(d3dpp.BackBufferWidth, d3dpp.BackBufferHeight);//config
|
|
g_nShadowResolution= min( g_nShadowResolution, (bLowDetail ? 2048u : 4096u ) );
|
|
g_nShadowResolution= max( g_nShadowResolution, (bLowDetail ? 768u : 1536u ) );
|
|
|
|
g_nEnvResolution= max(d3dpp.BackBufferWidth, d3dpp.BackBufferHeight);//config
|
|
if( bLowDetail )
|
|
{
|
|
g_nEnvResolution/= 2;
|
|
g_nEnvResolution= min( g_nEnvResolution, 512 );
|
|
g_nEnvBlurResolution= g_nEnvResolution / 8;
|
|
}
|
|
else
|
|
{
|
|
g_nEnvResolution= min( g_nEnvResolution, 2048 );
|
|
g_nEnvBlurResolution= g_nEnvResolution / 16;
|
|
}
|
|
g_nEnvBlurResolution= min( g_nEnvBlurResolution, 32 );
|
|
|
|
Renderpipe::PrepareRenderTargets( d3dpp.BackBufferWidth, d3dpp.BackBufferHeight,
|
|
g_nShadowResolution, g_nEnvResolution, g_nEnvBlurResolution, d3dpp.MultiSampleType );
|
|
|
|
#ifdef CAMERATESTER
|
|
ReadCameraAll();
|
|
HomeCam();
|
|
EditorHelp::PreparePrint();
|
|
#endif
|
|
#if defined(MESHTESTER)
|
|
HomeCam();
|
|
EditorHelp::PreparePrint();
|
|
#endif
|
|
/***********************************************************************************/
|
|
//Renderstates
|
|
|
|
g_d3d_device->SetMaterial( &d3dMaterial );
|
|
|
|
g_d3d_device->SetRenderState( D3DRS_SPECULARENABLE, TRUE );
|
|
g_d3d_device->SetRenderState( D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_COLOR1 );
|
|
g_d3d_device->SetRenderState( D3DRS_SPECULARMATERIALSOURCE, D3DMCS_MATERIAL );
|
|
g_d3d_device->SetRenderState( D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_COLOR1 );
|
|
g_d3d_device->SetRenderState( D3DRS_NORMALIZENORMALS, TRUE );
|
|
|
|
//g_d3d_device->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
|
|
//g_d3d_device->SetRenderState( D3DRS_FILLMODE, D3DFILL_WIREFRAME );
|
|
//g_d3d_device->SetRenderState( D3DRS_SHADEMODE, D3DSHADE_FLAT );
|
|
|
|
g_d3d_device->SetLight( 0, &d3dLight[ 0 ] );
|
|
g_d3d_device->SetLight( 1, &d3dLight[ 1 ] );
|
|
g_d3d_device->SetLight( 1, &d3dLight[ 2 ] );
|
|
|
|
g_d3d_device->LightEnable( 0, TRUE );
|
|
g_d3d_device->LightEnable( 1, TRUE );
|
|
g_d3d_device->LightEnable( 2, TRUE );
|
|
|
|
g_d3d_device->SetRenderState(D3DRS_FOGCOLOR, 0xffe0b0a0 );
|
|
g_d3d_device->SetRenderState( D3DRS_FOGTABLEMODE, D3DFOG_EXP2);
|
|
float fDensity= 1.0f / 16.0f;
|
|
g_d3d_device->SetRenderState( D3DRS_FOGDENSITY, *(DWORD *)(&fDensity) );
|
|
g_d3d_device->SetRenderState( D3DRS_FOGENABLE, TRUE );
|
|
|
|
|
|
#if defined(CAMERATESTER)
|
|
DoDemoMain();
|
|
#elif defined(MESHTESTER)
|
|
DoMeshViewerMain();
|
|
#else
|
|
DoDemoMain();
|
|
#endif
|
|
/***********************************************************************************/
|
|
//Shutdown
|
|
ExitProcess( 0 );
|
|
}
|
|
|
|
#ifdef EXTRACODE
|
|
|
|
int WINAPI
|
|
WinMain (HINSTANCE hInstance,
|
|
HINSTANCE hPrevInstance,
|
|
LPSTR lpCmdLine,
|
|
int iCmdShow)
|
|
{
|
|
g_hInstance = hInstance;
|
|
WinEntry();
|
|
return 0;
|
|
}
|
|
|
|
#endif
|
|
|
|
/* Declare Windows procedure */
|
|
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
|
|
|
|
|