Quote: "I changed the aCount from 40 to 140
my cps changed from 60 to 10 or less "
You must keep in mind that in that example 40 = 1600(40 * 40) asteroids.
Setting to 140 means you will have 19600(140 * 140) asteroids, which is quite alot more.
If you want that many asteroids then take a look at the advanced section in the docs on culling. It is really simple to implement for the static asteroids and you should then be able to get to the numbers you are looking for with a good frame rate.
I still need to do a culling example to really show what is possible. The landscape demo I made used some culling, I had four groups, each one had objects just in one corner of the terrain, this just give a little extra boost when you are not viewing the whole landscape.
I will expand upon the asteroid example when I do a culling example.
EDIT: Just looked at that example, aCount set to 40 is 1600 asteroids per group, and there are two groups. Therefore a value of 140 means you would have 39200 asteroids, culling will be needed for those kinds of numbers.
Here is the source code for the example you can download from the product page, the only thing that is added is the ability to set the values from the provided text file.
#include "DarkGDK.h"
#include "DarkImposters.h"
#pragma comment(lib, "DarkImposters.lib")
#include "SetupFile.h"
void updateDisplay();
SetupData *setupData;
bool IMPOSTERSON = true;
bool CULLINGON = true;
int SCREENWIDTH = 640;
int SCREENHEIGHT = 480;
int DETAIL = 40;
//-- Dynamic Imposters Demo
//-- We seperate static and dynamic imposters into
//-- two groups, if you put static objects in a dynamic
//-- group you will be unnecessarily repositioning
//-- the imposters each loop.
int getFreeObject();
void updateText();
void DarkGDK ( void )
{
setupData = new SetupData();
bool success = setupData->getData("Change me.txt");
if(success){
SCREENWIDTH = setupData->SCREENWIDTH;
SCREENHEIGHT = setupData->SCREENHEIGHT;
IMPOSTERSON = setupData->IMPOSTERSON;
DETAIL = setupData->DETAIL;
}
//-- Sync
dbSyncOn ( );
dbSyncRate ( 0 );
//********************************
dbSetDisplayModeVSync(SCREENWIDTH, SCREENHEIGHT, 32, false);
dbSetWindowPosition(dbDesktopWidth() / 2 - SCREENWIDTH / 2, dbDesktopHeight() / 2 - SCREENHEIGHT / 2);
dbSetWindowLayout(0, 0, 0);
dbCenterText(SCREENWIDTH / 2, SCREENHEIGHT / 2, "Loading...");
dbSync();
dbSync();
//-- Camera
dbAutoCamOff();
dbPositionCamera(0, 0, -10000);
dbPointCamera(0, 0, 0);
dbSetCameraRange(1, 100000);
dbColorBackdrop(dbRGB(0, 0, 0));
//-- Load our asteroids which we will instance from
dbLoadObject("Media/Asteroids/AST_01.X", 1);
dbLoadObject("Media/Asteroids/AST_02.X", 2);
dbHideObject(1);
dbHideObject(2);
//-- Create our background
dbLoadImage("Media/Asteroids/space.png", 1);
dbMakeObjectPlane(3, 100000, 100000);
dbTextureObject(3, 1);
dbPositionObject(3, 0, 0, 60000);
dbSetObjectTransparency(3, 1);
dbSetObjectLight(3, 0);
//-- How many asteroids? This is the square root of the
//-- amount of asteroids you will have per group. There
//-- will be two groups in this example, one for static
//-- asteroids and one for dynamic.
int aCount = DETAIL; //-- 40 * 40 per group.
//-- Set to 'false' to run scene without imposters.
bool impostersOn = IMPOSTERSON;
//-- Initialise Dark Imposters.
impStart();
//-- Make two groups with a texture size 2048x2048 split
//-- up depending on the amount of asteroids.
impMakeGroup(1, 2048, 2048, aCount, aCount);
impMakeGroup(2, 2048, 2048, aCount, aCount);
//-- Set imposter distance to 2000
impGroupSetDistanceSquared(1, 2000 * 2000);
impGroupSetDistanceSquared(2, 3000 * 3000);
//-- Objects will be affected by light when they
//-- are rendered to texture, imposters do not need to
//-- be affected by light.
impGroupSetLight(1, 1);
impGroupSetLight(2, 1);
//-- Set group 2 as dynamic, moving asteroids.
impGroupSetDynamic(2, 1);
//-- We will be rotating also, so we will regenerate
//-- every 0.2 seconds. Therefore we will turn off angle
//-- tests.
impGroupSetMaxAge(2, 200); //-- 200 = 0.2 seconds
impGroupSetAngleThreshold(2, 0);
//********************************
impGroupSetMaxRegenerations(2, aCount * aCount);
impGroupSetMaxRegenerations(1, aCount * aCount);
//-- Setup static imposters.
//-- We randomly select if they are instanced from
//-- asteroid 1 or asteroid 2.
for(int i = 1; i < aCount * aCount; i++){
int obj = getFreeObject();
int ast = dbRND(1) + 1;
dbInstanceObject(obj, ast);
dbRotateObject(obj, dbRND(360), dbRND(360), dbRND(360));
dbPositionObject(obj, dbRND(40000) - 20000, dbRND(5000) - 2500, dbRND(40000) - 20000);
dbScaleObject(obj, dbRND(50) + 75, dbRND(50) + 75, dbRND(50) + 75);
if(impostersOn) impGroupAddObject(1, obj, ast);
}
//-- Setup dynamic imposters.
//-- We randomly select if they are instanced from
//-- asteroid 1 or asteroid 2.
int dynamicStart = 0; //-- the first dynamic asteroid
for(int i = 1; i < aCount * aCount; i++){
int obj = getFreeObject();
if(i == 1){
dynamicStart = obj;
}
int ast = dbRND(1) + 1;
dbInstanceObject(obj, ast);
dbRotateObject(obj, dbRND(360), dbRND(360), dbRND(360));
dbScaleObject(obj, dbRND(50) + 75, dbRND(50) + 75, dbRND(50) + 75);
dbPositionObject(obj, dbRND(40000) - 20000, dbRND(5000) - 2500, dbRND(40000) - 20000);
if(impostersOn) impGroupAddObject(2, obj, ast);
}
//-- We will slowly rotate the dynamic asteroids, we have
//-- set these to regenerate on a timer so the rotations
//-- stay up to date.
float rotate = 0.0;
float speed = 2.0;
//-- We must sync before the first imposter update or
//-- we will get empty imposters.
dbSync();
impUpdate();
//********************************
impGroupSetMaxRegenerations(2, 30);
impGroupSetMaxRegenerations(1, 10);
while ( LoopGDK ( ) )
{
//-- Loop all dynamic(group 2) asteroids.
for(int i = dynamicStart; i < dynamicStart + (aCount * aCount); i++){
dbPositionObject(i, dbObjectPositionX(i) + speed, dbObjectPositionY(i), dbObjectPositionZ(i));
dbYRotateObject(i, rotate);
}
rotate = rotate + 0.3;
float x = dbMouseMoveX() * 0.1;
float y = dbMouseMoveY() * 0.1;
dbTurnCameraRight(x);
dbPitchCameraDown(y);
//*******************FPS
float fps = dbScreenFPS();
float time = 60 / fps;
if(dbUpKey()){
dbMoveCamera(10 * time);
}
if(dbDownKey()){
dbMoveCamera(-10 * time);
}
updateDisplay();
impUpdate();
dbSync();
}
impDeleteGroup(1);
impDeleteGroup(2);
return;
}
void updateText(){
char* buf;
buf = dbStr(dbScreenFPS());
int centre = dbScreenWidth() / 2;
dbCenterText(centre, 0, "Dynamic Imposters");
dbCenterText(centre, 20, "FPS");
dbCenterText(centre, 40, buf);
delete []buf;
}
int getFreeObject(){
int obj = 1;
while(dbObjectExist(obj)){
obj++;
}
return obj;
}
void updateDisplay(){
char* buf;
buf = dbStr(dbScreenFPS());
if(IMPOSTERSON)
dbCenterText(SCREENWIDTH / 2, 0, "IMPOSTERS ON");
else
dbCenterText(SCREENWIDTH / 2, 0, "IMPOSTERS OFF");
dbCenterText(SCREENWIDTH / 2, 15, "FPS");
dbCenterText(SCREENWIDTH / 2, 30, buf);
delete[] buf;
}
