Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your help!

We need 7 developers from Canada and 18 more from Australia to help us complete a research survey.

Support our site by taking a quick sponsored survey and win a chance at a $50 Amazon gift card. Click here to get started!






Lights from a render list

Posted by speciesUnknown, 02 January 2010 · 260 views

Made some structural changes today to prepare my newly created lighting system for use with the scene.

I've got my system gathering spotlights from a render list and drawing as many as possible in a single pass; it performs quite well with around 50 lights per pass. This render list is gathered by the scene (ill detail my scene system in a later post) but atm the lighting is only debug data.






My light manager is capable of taking lights from a render list, batching them up into uniforms, and rendering as many as possible with a single pass. This will cut down on the number of fullscreen quads to be rendered. Fillrate is my primary bottleneck right now. I've seen methods which render the AABB of a light system as some kind of volume on screen, which conveniently means projecting it and reducing the number of fragments to render by orders of magnitude, this will likely be a good option.

void LightManager::startList(RenderList3D& source){
current_position = source.light_begin(), last_position = source.light_end();
}

LightManager::Step LightManager::stepList(int shader_program)
{
static SpotLight dummy_light;
dummy_light.setOn(true);

static std::vector<float> pos(3 * available_spotlights);
static std::vector<float> dir(3 * available_spotlights);
static std::vector<float> colour(3 * available_spotlights);
static std::vector<float> radius(available_spotlights);
static std::vector<float> cosAngle(available_spotlights);

for(int i = 0; i < available_spotlights; i++)
{
SpotLight * l;

if(current_position != last_position)
{ // apply each light in turn
l = ( current_position->light );
current_position++;
}
else
{ // fill the remainder of the list with dummy lights
l = &dummy_light;
}

pos[3 * i + 0] = l->pos[0];
pos[3 * i + 1] = l->pos[1];
pos[3 * i + 2] = l->pos[2];

dir[3 * i + 0] = l->dir[0];
dir[3 * i + 1] = l->dir[1];
dir[3 * i + 2] = l->dir[2];

colour[3 * i + 0] = l->rgb[0];
colour[3 * i + 1] = l->rgb[1];
colour[3 * i + 2] = l->rgb[2];

cosAngle[i] = cos(l->angle * 0.0174532925f);

radius[i] = l->on ? l->radius : 1e-1f;
}

GLint location = glGetUniformLocation(shader_program, "uLightPos");
if(location != -1)
glUniform3fv(location, available_spotlights, &pos[0]);

location = glGetUniformLocation(shader_program, "uLightDir");
if(location != -1)
glUniform3fv(location, available_spotlights, &dir[0]);

location = glGetUniformLocation(shader_program, "uLightColour");
if(location != -1)
glUniform3fv(location, available_spotlights, &colour[0]);

location = glGetUniformLocation(shader_program, "uLightRadius");
if(location != -1)
glUniform1fv(location, available_spotlights, &radius[0]);

location = glGetUniformLocation(shader_program, "uLightCosAngle");
if(location != -1)
glUniform1fv(location, available_spotlights, &cosAngle[0]);

if(current_position != last_position)
{ // we are still iterating our spotlights
return SPOTLIGHTS;
}
else
{ // we have reached the end of the list
return FINISHED;
}
}



My next step is to work the way lights are gathered into the scene itself, I've created various code paths for lights in the scene but not integrated this with my 3d editor.
that: add point lights to the system.




September 2015 »

S M T W T F S
   1 2345
6789101112
13141516171819
20212223242526
27282930   

Recent Entries

Recent Comments

Recent Entries

Recent Comments

PARTNERS