• Create Account

Need scary sound effects or creepy audio loops for your next horror-themed game? Check out Highscore Vol.3 - The Horror Edition in our marketplace. 50 sounds and 10 loops for only \$9.99!

### #Actual_Slin_

Posted 13 May 2013 - 12:44 PM

For now it is just a list, later they will probably be sorted into an octree or something similar, which should of course be an improvement but for now it is good enough to optimize the culling itself a little (for less than 1000 lights, it performs very well, using multithreading and some basic code optimizations).

My code seems to work well and looks like this now:

#define Distance(plane, op, r) { \
float dot = (position.x * plane.normal.x + position.y * plane.normal.y + position.z * plane.normal.z);\
distance = dot - plane.d; \
if(distance op r) \
continue; \
}

const Vector3& position = light->_worldPosition;
const float range = light->_range;
float distance, dr, dl, dt, db;
Distance(plright, >, range);
dr = distance;
Distance(plleft, <, -range);
dl = distance;
Distance(plbottom, <, -range);
db = distance;
Distance(pltop, >, range);
dt = distance;

float sqrange = range*range;
if(dr > 0.0f && db < 0.0f && dr*dr+db*db > sqrange)
continue;
if(dr > 0.0f && dt > 0.0f && dr*dr+dt*dt > sqrange)
continue;
if(dl < 0.0f && db < 0.0f && dl*dl+db*db > sqrange)
continue;
if(dl < 0.0f && dt > 0.0f && dl*dl+dt*dt > sqrange)
continue;


It´s not pretty, but I have to fix some other things before cleaning up and while my planes have a function to get it´s distance to a point, at 32*24*1024*4 calls, the function call overhead was the biggest performance hit ;)

### #1_Slin_

Posted 13 May 2013 - 12:43 PM

For now it is just a list, later they will probably be sorted into an octree or something similar, which should of course be an improvement but for now it is good enough to optimize the culling itself a little (for less than 1000 lights, it performs very well, using multithreading and some basic code optimizations).

My code seems to work well and looks like this now:

#define Distance(plane, op, r) { \
float dot = (position.x * plane.normal.x + position.y * plane.normal.y + position.z * plane.normal.z);\
distance = dot - plane.d; \
if(distance op r) \
continue; \
}

const Vector3& position = light->_worldPosition;
const float range = light->_range;
float distance, dr, dl, dt, db;
Distance(plright, >, range);
dr = distance;
Distance(plleft, <, -range);
dl = distance;
Distance(plbottom, <, -range);
db = distance;
Distance(pltop, >, range);
dt = distance;

float sqrange = range*range;
if(dr > 0.0f && db < 0.0f && dr*dr+db*db > sqrange)
continue;
if(dr > 0.0f && dt > 0.0f && dr*dr+dt*dt > sqrange)
continue;
if(dl < 0.0f && db < 0.0f && dl*dl+db*db > sqrange)
continue;
if(dl < 0.0f && dt > 0.0f && dl*dl+dt*dt > sqrange)
continue;


It´s not pretty, but I have to fix some other things before cleaning up and while my planes have a function to get it´s distance to a point, however at 32*24*1024*4 calls, the function call overhead was the biggest performance hit ;)

PARTNERS