class myLight
{
public:
D3DLIGHT8* Light;
bool Alive;
};
//----------------------------------------------------------------
// Class that encapsulates the lights
//----------------------------------------------------------------
class myLightSystem
{
public:
myLightSystem();
~myLightSystem();
//----------------------------------------------------------------
// The lights that the system makes sure directx updates
//----------------------------------------------------------------
myLight* Lights[MAX_LIGHTS];
//----------------------------------------------------------------
// The current number of lights in the system
//----------------------------------------------------------------
int m_nLights;
//----------------------------------------------------------------
// Adds a light to the Lights array
//----------------------------------------------------------------
void addLight( myLight* );
//----------------------------------------------------------------
// Makes sure that if a light has changed it is updated
//----------------------------------------------------------------
void Update(float);
};
//----------------------------------------------------------------
// Adds a light to the Lights array
//----------------------------------------------------------------
void myLightSystem::addLight( myLight* pLight )
{
for ( int i=0; i<MAX_LIGHTS; i++ )
{
if ( Lights[i] == NULL )
{
Lights[ i ] = pLight;
d3dApp.m_pd3dDevice->SetLight( i, pLight->Light );
d3dApp.m_pd3dDevice->LightEnable( i, TRUE );
return;
}
}
}
//------------------------------------------------------------
// Makes sure that if a light has changed it is updated
//------------------------------------------------------------
void myLightSystem::Update(float m_fElapsedTime)
{
for ( int i=0; i<MAX_LIGHTS; i++ )
{
if( Lights[i] == NULL )
{
continue;
}
d3dApp.m_pd3dDevice->SetLight( i, Lights[i]->Light );
d3dApp.m_pd3dDevice->LightEnable( i, Lights[i]->Alive );
//------------------------------------------------------------
// No longer process this light if it isn''t alive anymore
//------------------------------------------------------------
if ( !Lights[i]->Alive )
{
Lights[i] = NULL;
}
}
}
void classA :: createLight()
{
m_Light = new myLight();
//code to set all the values for the light, diffuse, etc....
g_LightSystem.addLight( m_Light );
}
void classA :: Load ()
{
createLight();
}
void classA :: Update ()
{
if ( m_Light && m_Light->Light )
{
if( m_Light->Alive )
{
m_Light->Light->Position.x = Position.x; //left right
m_Light->Light->Position.y = Position.y + 5; // torwards camera
m_Light->Light->Position.z = Position.z; //up down
m_Light->Changed = true;
m_Light->Alive = m_Alive;
}
else
{
SAFE_DELETE( m_Light );
}
}
}
Have odd problem with dx8 lighting
Greetings fellow game developers,
I have been mulling over a problem for 2 days now and decided that a second opinion is probably best for me .
I am current creating a lighting class to manage all the dynamically created lights ( DirectX 8 ).
The problem is that whenever I create ~10 lights, only 2-3 of them are turned on. I can''t decide if this is due to my video card
or my code?
The video card has a limit on how many lights can be enabled in the fixed-function pipeline. The MaxActiveLights member of the D3DCAPS9 (or D3DCAPS8 in your case) indicates how many can be active at once.
Dustin Franklin
Mircrosoft DirectX MVP
Dustin Franklin
Mircrosoft DirectX MVP
10 lights seems to be a very very low amount of lights to start having problems with a 64 MB card, I will definately check that value though on light addition
Are there other known ways to implement lighting? I know of vertex shading but having to permutate through all meshes within line of sight of a light source seems like a horrid method
Are there other known ways to implement lighting? I know of vertex shading but having to permutate through all meshes within line of sight of a light source seems like a horrid method
Yes, the card I am on now actually supports 0 lights . My old GF4 420MX supported 8 lights. I''m not sure what my new Raedon 9600xt supports.
Most cards I''ve seen support a maximum of 8 active lights. Even high-end ones like the 9700.
I think that it''s rare to have a scene with 8 lights enabled at the same time. Plus, the focus is on shaders these days, not the FFP.
Muhammad Haggag
I think that it''s rare to have a scene with 8 lights enabled at the same time. Plus, the focus is on shaders these days, not the FFP.
Muhammad Haggag
Don''t quote me on it, but I have a feeling DirectX 8 will only support 8 active lights - nevermind your graphics card.
Yeah, 8 lights was the magic number
Hmmm I could have sword reading the sdk docs that lighting was limited only by available memory, at least according to:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndir3d/html/dx7light.asp (but this is a directx 7 article)
Anyways, are there tutorials for adding dynamic lighting to scenes without using the dx8 setLight APIs?? I am wondering how difficult vertex lighting is to implement on a fast level...
Looks like I have some more research cut out for me :0
Hmmm I could have sword reading the sdk docs that lighting was limited only by available memory, at least according to:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndir3d/html/dx7light.asp (but this is a directx 7 article)
Anyways, are there tutorials for adding dynamic lighting to scenes without using the dx8 setLight APIs?? I am wondering how difficult vertex lighting is to implement on a fast level...
Looks like I have some more research cut out for me :0
One option would be to render the scene one light at a time, and use addition blending of the colour buffer, not too disimilar from the D3D9 shadow rendering example on the front page: http://www.gamedev.net/columns/hardcore/shadowvol/
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement