DeferredRenderer 1.0
|
#include <LightingManager.h>
Public Member Functions | |
LightingManager () | |
null ctor | |
~LightingManager () | |
dtor | |
void | addPointLight (PointLight &_point) |
add point light by object | |
void | addSpotLight (SpotLight &_spot) |
add spot light by object | |
void | addShadowSpot (ShadowSpot &_spot) |
add shadowspot light by object | |
void | addPointLight (const ngl::Vector &_centre, const float &_radius, const ngl::Vector &_intensity) |
add point light by values | |
void | addSpotLight (const ngl::Vector &_position, const ngl::Vector &_target, const float &_distance, const float &_angle, const ngl::Vector &_col, const ngl::Vector &_up) |
add spot light by values | |
void | addShadowSpot (const ngl::Vector &_position, const ngl::Vector &_target, const float &_distance, const float &_angle, const ngl::Vector &_col, const ngl::Vector &_up) |
add shadowspot by value | |
void | addNamedPoint (const std::string &_name, const ngl::Vector &_centre, const float &_radius, const ngl::Vector &_intensity) |
add a named point light | |
void | addNamedSpot (const std::string &_name, const ngl::Vector &_position, const ngl::Vector &_target, const float &_distance, const float &_angle, const ngl::Vector &_col, const ngl::Vector &_up) |
add a named spot light | |
void | addNamedShadowSpot (const std::string &_name, const ngl::Vector &_position, const ngl::Vector &_target, const float &_distance, const float &_angle, const ngl::Vector &_col, const ngl::Vector &_up) |
add a named shadowspot | |
void | addNamedPoint (const std::string &_name, PointLight &_point) |
add name point by object | |
void | addNamedSpot (const std::string &_name, SpotLight &_spot) |
add name spot by object | |
void | addNamedShadowSpot (const std::string &_name, ShadowSpot &_spot) |
add name shadowspot by object | |
SpotLight & | getNamedSpot (const std::string &_name) |
retrieve spotlight by name | |
PointLight & | getNamedPoint (const std::string &_name) |
retrieve point light by name | |
ShadowSpot & | getNamedShadowSpot (const std::string &_name) |
retrieve shadwspot by name | |
SpotLight & | getSpot (int _index) |
access spot by id | |
PointLight & | getPoint (int _index) |
access point light by id | |
ShadowSpot & | getShadowSpot (int _index) |
access shadowspot by id | |
void | setGlobalAmbient (const ngl::Vector &_colour) |
set the gloabl ambient contribtution | |
void | setGlobalDirectional (const ngl::Vector &_colour, const ngl::Vector &_direction) |
set the global directional light | |
ngl::Vector | getGlobalAmbient () |
accessor for gloabl ambient | |
ngl::Vector | getDirectionalColour () |
accessor for directionl colour | |
ngl::Vector | getDirectionalVec () |
accessor for direction vector | |
void | accumulateLights (TextureManager &_textureManager, const ngl::Vector &_camPos) |
main update call to accumulate lights to scene | |
void | createLightGeometry () |
init the light geometry for rasterizing | |
Private Member Functions | |
void | blendPointLights (const ngl::Vector &_camPos) |
blend point lights onto scene | |
void | blendShadowSpots (const ngl::Vector &_camPos) |
blend shadowspots onto scene | |
void | blendSpotLights (const ngl::Vector &_camPos) |
blend spots onto scene | |
Private Attributes | |
unsigned int | m_pointLightVAO |
the point light vao handle | |
std::vector< PointLight > | m_pointLights |
list of point lights | |
std::vector< SpotLight > | m_spotLights |
list of spotlights | |
std::vector< ShadowSpot > | m_shadowSpots |
list of shadowspot | |
std::map< std::string, PointLight > | m_namedPointLights |
map of named points | |
std::map< std::string, SpotLight > | m_namedSpotLights |
map of named spots | |
std::map< std::string, ShadowSpot > | m_namedShadowSpots |
map of named shaodspots | |
ngl::Vector | m_globalAmbient |
the gloabl ambeint intensity | |
ngl::Vector | m_globalDirectional |
the (gloabl) direction llight intensity | |
ngl::Vector | m_globalDirectionalVec |
the (global) direction light vector |
Definition at line 18 of file LightingManager.h.
LightingManager::LightingManager | ( | ) |
LightingManager::~LightingManager | ( | ) | [inline] |
void LightingManager::accumulateLights | ( | TextureManager & | _textureManager, |
const ngl::Vector & | _camPos | ||
) |
main update call to accumulate lights to scene
[in] | _textureManager | the apps texture manager for blending |
[in] | _camPos | the cameras position for culling |
Definition at line 8 of file LightingManager.cpp.
References TextureManager::bindTexture(), blendPointLights(), blendShadowSpots(), and blendSpotLights().
{ glActiveTexture(GL_TEXTURE1); _textureManager.bindTexture("normal"); glActiveTexture(GL_TEXTURE2); _textureManager.bindTexture("albedo"); glActiveTexture(GL_TEXTURE3); _textureManager.bindTexture("position"); glActiveTexture(GL_TEXTURE4); _textureManager.bindTexture("shadow"); glClearColor(0.f, 0.f, 0.f, 1.0f); glEnable(GL_BLEND); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glBlendFunc(GL_ONE,GL_ONE); glDepthMask(false); blendShadowSpots(_camPos); blendPointLights(_camPos); blendSpotLights(_camPos); glDisable(GL_BLEND); glDepthMask(true); glDisable(GL_CULL_FACE); }
void LightingManager::addNamedPoint | ( | const std::string & | _name, |
PointLight & | _point | ||
) |
add name point by object
Definition at line 135 of file LightingManager.cpp.
References m_namedPointLights.
{ m_namedPointLights.insert(std::pair<std::string, PointLight>(_name, _point)); }
void LightingManager::addNamedPoint | ( | const std::string & | _name, |
const ngl::Vector & | _centre, | ||
const float & | _radius, | ||
const ngl::Vector & | _intensity | ||
) |
add a named point light
Definition at line 148 of file LightingManager.cpp.
{ PointLight tmp(_centre, _radius, _intensity); this->addNamedPoint(_name, tmp); }
void LightingManager::addNamedShadowSpot | ( | const std::string & | _name, |
const ngl::Vector & | _position, | ||
const ngl::Vector & | _target, | ||
const float & | _distance, | ||
const float & | _angle, | ||
const ngl::Vector & | _col, | ||
const ngl::Vector & | _up | ||
) |
add a named shadowspot
Definition at line 171 of file LightingManager.cpp.
References addNamedSpot().
{ ShadowSpot tmp(_position, _target, _distance, _angle, _col, _up); this->addNamedSpot(_name, tmp); }
void LightingManager::addNamedShadowSpot | ( | const std::string & | _name, |
ShadowSpot & | _spot | ||
) |
add name shadowspot by object
Definition at line 143 of file LightingManager.cpp.
References m_namedShadowSpots.
{ m_namedShadowSpots.insert(std::pair<std::string, ShadowSpot>(_name, _spot)); }
void LightingManager::addNamedSpot | ( | const std::string & | _name, |
const ngl::Vector & | _position, | ||
const ngl::Vector & | _target, | ||
const float & | _distance, | ||
const float & | _angle, | ||
const ngl::Vector & | _col, | ||
const ngl::Vector & | _up | ||
) |
add a named spot light
Definition at line 158 of file LightingManager.cpp.
{ SpotLight tmp(_position, _target, _distance, _angle, _col, _up); this->addNamedSpot(_name, tmp); }
void LightingManager::addNamedSpot | ( | const std::string & | _name, |
SpotLight & | _spot | ||
) |
add name spot by object
Definition at line 139 of file LightingManager.cpp.
References m_namedSpotLights.
{ m_namedSpotLights.insert(std::pair<std::string, SpotLight>(_name, _spot)); }
void LightingManager::addPointLight | ( | const ngl::Vector & | _centre, |
const float & | _radius, | ||
const ngl::Vector & | _intensity | ||
) |
add point light by values
Definition at line 184 of file LightingManager.cpp.
References m_pointLights.
{ PointLight tmp(_centre, _radius, _intensity); m_pointLights.push_back(tmp); }
void LightingManager::addPointLight | ( | PointLight & | _point | ) | [inline] |
add point light by object
Definition at line 28 of file LightingManager.h.
References m_pointLights.
{m_pointLights.push_back(_point);std::cout << m_pointLights.size() << std::endl;}
void LightingManager::addShadowSpot | ( | const ngl::Vector & | _position, |
const ngl::Vector & | _target, | ||
const float & | _distance, | ||
const float & | _angle, | ||
const ngl::Vector & | _col, | ||
const ngl::Vector & | _up | ||
) |
add shadowspot by value
Definition at line 203 of file LightingManager.cpp.
References m_shadowSpots.
{ ShadowSpot tmp(_position, _target, _distance, _angle, _col, _up); m_shadowSpots.push_back(tmp); }
void LightingManager::addShadowSpot | ( | ShadowSpot & | _spot | ) | [inline] |
add shadowspot light by object
Definition at line 34 of file LightingManager.h.
References m_shadowSpots.
{m_shadowSpots.push_back(_spot);}
void LightingManager::addSpotLight | ( | SpotLight & | _spot | ) | [inline] |
add spot light by object
Definition at line 31 of file LightingManager.h.
References m_spotLights.
{m_spotLights.push_back(_spot);}
void LightingManager::addSpotLight | ( | const ngl::Vector & | _position, |
const ngl::Vector & | _target, | ||
const float & | _distance, | ||
const float & | _angle, | ||
const ngl::Vector & | _col, | ||
const ngl::Vector & | _up | ||
) |
add spot light by values
Definition at line 192 of file LightingManager.cpp.
References m_spotLights.
{ SpotLight tmp(_position, _target, _distance, _angle, _col, _up); m_spotLights.push_back(tmp); }
void LightingManager::blendPointLights | ( | const ngl::Vector & | _camPos | ) | [private] |
blend point lights onto scene
Definition at line 59 of file LightingManager.cpp.
References m_pointLights, and m_pointLightVAO.
{ for(unsigned int i = 0; i < m_pointLights.size(); i++) { if(m_pointLights[i].collidesWithSphere(_camPos, 10.0)) { glCullFace(GL_FRONT); glDisable(GL_DEPTH_TEST); m_pointLights[i].draw(m_pointLightVAO, "PointLight"); glEnable(GL_DEPTH_TEST); glCullFace(GL_BACK); } else { m_pointLights[i].draw(m_pointLightVAO, "PointLight"); } } }
void LightingManager::blendShadowSpots | ( | const ngl::Vector & | _camPos | ) | [private] |
blend shadowspots onto scene
Definition at line 38 of file LightingManager.cpp.
References m_shadowSpots.
{ for(unsigned int i = 0; i < m_shadowSpots.size(); i++) { //check for near plane clip if(m_shadowSpots[i].collidesWithSphere(_camPos, 10.0)) { glCullFace(GL_FRONT); glDisable(GL_DEPTH_TEST); m_shadowSpots[i].draw("spotlight", "ShadowSpot"); glEnable(GL_DEPTH_TEST); glCullFace(GL_BACK); } else { m_shadowSpots[i].draw("spotlight", "ShadowSpot"); } } }
void LightingManager::blendSpotLights | ( | const ngl::Vector & | _camPos | ) | [private] |
blend spots onto scene
Definition at line 78 of file LightingManager.cpp.
References m_spotLights.
{ for(unsigned int i = 0; i < m_spotLights.size(); i++) { //check for near plane clip if(m_spotLights[i].collidesWithSphere(_camPos, 10.0)) { glCullFace(GL_FRONT); glDisable(GL_DEPTH_TEST); m_spotLights[i].draw("spotlight", "SpotLight"); glEnable(GL_DEPTH_TEST); glCullFace(GL_BACK); } else { m_spotLights[i].draw("spotlight", "SpotLight"); } } }
void LightingManager::createLightGeometry | ( | ) |
init the light geometry for rasterizing
Definition at line 98 of file LightingManager.cpp.
References m_pointLightVAO.
{ // vertex coords array GLfloat vertices[] = { 1, 1, 1, -1, 1, 1, -1,-1, 1, 1,-1, 1, // v0-v1-v2-v3 1, 1, 1, 1,-1, 1, 1,-1,-1, 1, 1,-1, // v0-v3-v4-v 1, 1, 1, 1, 1,-1, -1, 1,-1, -1, 1, 1, // v0-v5-v6-v -1, 1, 1, -1, 1,-1, -1,-1,-1, -1,-1, 1, // v1-v6-v7-v -1,-1,-1, 1,-1,-1, 1,-1, 1, -1,-1, 1, // v7-v4-v3-v 1,-1,-1, -1,-1,-1, -1, 1,-1, 1, 1,-1 // v4-v7-v6-v5 }; // first we create a vertex array Object glGenVertexArrays(1, &m_pointLightVAO); // now bind this to be the currently active one glBindVertexArray(m_pointLightVAO); // as they will be associated with the vertex array object GLuint vboID; glGenBuffers(1, &vboID); // now we will bind an array buffer to the first one and load the data for the verts glBindBuffer(GL_ARRAY_BUFFER, vboID); glBufferData(GL_ARRAY_BUFFER, 24*3*sizeof(GLfloat), vertices, GL_STATIC_DRAW); // now we bind the vertex attribute pointer for this object in this case the // vertex data ngl::ShaderManager *shader=ngl::ShaderManager::instance(); (*shader)["PointLight"]->vertexAttribPointer("a_VertexPosition",3,GL_FLOAT,0,0); (*shader)["PointLight"]->enableAttribArray("a_VertexPosition"); // finally switch back to the default so we don't overwrite glEnableVertexAttribArray(0); glBindVertexArray(0); ngl::VBOPrimitives *prim = ngl::VBOPrimitives::instance(); prim->createVBOCone("spotlight",1.0,1.0,30.0,1.0); }
ngl::Vector LightingManager::getDirectionalColour | ( | ) | [inline] |
accessor for directionl colour
Definition at line 129 of file LightingManager.h.
References m_globalDirectional.
{return m_globalDirectional;}
ngl::Vector LightingManager::getDirectionalVec | ( | ) | [inline] |
accessor for direction vector
Definition at line 132 of file LightingManager.h.
References m_globalDirectionalVec.
{return m_globalDirectionalVec;}
ngl::Vector LightingManager::getGlobalAmbient | ( | ) | [inline] |
accessor for gloabl ambient
Definition at line 126 of file LightingManager.h.
References m_globalAmbient.
{return m_globalAmbient;}
PointLight& LightingManager::getNamedPoint | ( | const std::string & | _name | ) | [inline] |
retrieve point light by name
Definition at line 99 of file LightingManager.h.
References m_namedPointLights.
{return m_namedPointLights[_name];}
ShadowSpot& LightingManager::getNamedShadowSpot | ( | const std::string & | _name | ) | [inline] |
retrieve shadwspot by name
Definition at line 102 of file LightingManager.h.
References m_namedShadowSpots.
{return m_namedShadowSpots[_name];}
SpotLight& LightingManager::getNamedSpot | ( | const std::string & | _name | ) | [inline] |
retrieve spotlight by name
Definition at line 96 of file LightingManager.h.
References m_namedSpotLights.
{return m_namedSpotLights[_name];}
PointLight& LightingManager::getPoint | ( | int | _index | ) | [inline] |
access point light by id
Definition at line 109 of file LightingManager.h.
References m_pointLights.
{return m_pointLights[_index];}
ShadowSpot& LightingManager::getShadowSpot | ( | int | _index | ) | [inline] |
access shadowspot by id
Definition at line 112 of file LightingManager.h.
References m_shadowSpots.
{return m_shadowSpots[_index];}
SpotLight& LightingManager::getSpot | ( | int | _index | ) | [inline] |
access spot by id
Definition at line 106 of file LightingManager.h.
References m_spotLights.
{return m_spotLights[_index];}
void LightingManager::setGlobalAmbient | ( | const ngl::Vector & | _colour | ) | [inline] |
set the gloabl ambient contribtution
Definition at line 116 of file LightingManager.h.
References m_globalAmbient.
{m_globalAmbient = _colour;}
void LightingManager::setGlobalDirectional | ( | const ngl::Vector & | _colour, |
const ngl::Vector & | _direction | ||
) | [inline] |
set the global directional light
[in] | _colour | the lights colour intensity |
[in] | _direction | the light vector |
Definition at line 122 of file LightingManager.h.
References m_globalDirectional, and m_globalDirectionalVec.
{m_globalDirectional = _colour; m_globalDirectionalVec = _direction;}
ngl::Vector LightingManager::m_globalAmbient [private] |
the gloabl ambeint intensity
Definition at line 169 of file LightingManager.h.
ngl::Vector LightingManager::m_globalDirectional [private] |
the (gloabl) direction llight intensity
Definition at line 171 of file LightingManager.h.
ngl::Vector LightingManager::m_globalDirectionalVec [private] |
the (global) direction light vector
Definition at line 173 of file LightingManager.h.
std::map<std::string, PointLight> LightingManager::m_namedPointLights [private] |
map of named points
Definition at line 162 of file LightingManager.h.
std::map<std::string, ShadowSpot> LightingManager::m_namedShadowSpots [private] |
map of named shaodspots
Definition at line 166 of file LightingManager.h.
std::map<std::string, SpotLight> LightingManager::m_namedSpotLights [private] |
map of named spots
Definition at line 164 of file LightingManager.h.
std::vector<PointLight> LightingManager::m_pointLights [private] |
list of point lights
Definition at line 155 of file LightingManager.h.
unsigned int LightingManager::m_pointLightVAO [private] |
the point light vao handle
Definition at line 145 of file LightingManager.h.
std::vector<ShadowSpot> LightingManager::m_shadowSpots [private] |
list of shadowspot
Definition at line 159 of file LightingManager.h.
std::vector<SpotLight> LightingManager::m_spotLights [private] |
list of spotlights
Definition at line 157 of file LightingManager.h.