Archived

This topic is now archived and is closed to further replies.

Have odd problem with dx8 lighting

This topic is 5042 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?


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 );
		}
	}
}

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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/

Share this post


Link to post
Share on other sites