Game Development Reference
In-Depth Information
void CalcLighting(Scene *pScene);
void CalcLighting(ConstantBuffer_Lighting* pLighting, SceneNode *pNode);
};
The LightManager exists to pull relevant lighting information out of all the lights
in the scene and send just the lighting data affecting an individual object into the
shaders. In this simple example, the class assumes that all lights affect all objects.
But the architecture supports something more complicated
all that needs to be
done is to write code in the Get methods to return just the lighting information for
the SceneNode in question.
In each frame, the LightManager iterates over all the lights in the scene and
reads their color, position, and orientation information. It can also pull additional
information, such as what is contained in the LightProperties structure
for a more complicated lighting model. The method that accomplishes this task is
CalcLighting() :
void LightManager::CalcLighting(Scene *pScene)
{
pScene->GetRenderer()->VCalcLighting(&m_Lights, MAXIMUM_LIGHTS_SUPPORTED);
int count = 0;
GCC_ASSERT(m_Lights.size() < MAXIMUM_LIGHTS_SUPPORTED);
for(Lights::iterator i=m_Lights.begin();
i!=m_Lights.end();
++i, ++count)
{
shared_ptr<LightNode> light = *i;
if (count==0)
{
// Light 0 is the only one we use for ambient lighting. The rest are
// ignored in the simple shaders used for GameCode4.
Color ambient = light->VGet()->GetMaterial().GetAmbient();
m_vLightAmbient = Vec4(ambient.r, ambient.g, ambient.b, 1.0f);
}
Vec3 lightDir = light->GetDirection();
m_vLightDir[count] = D3DXVECTOR4(lightDir.x, lightDir.y, lightDir.z,
1.0f);
m_vLightDiffuse[count] = light->VGet()->GetMaterial().GetDiffuse();
}
}
Search WWH ::




Custom Search