Jump to content
  • Advertisement
Sign in to follow this  
dv

Problems with light culling

This topic is 4592 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

Hi, I'm developing a game, and have to resort to vertex lighting for now. (Ugh :( ) I noticed that something is wrong with the FFP lights. I use point lights only, and cull them using their bounding sphere. Once I started the whole thing, I noticed some very nasty flickering. Apparently, the lights affect vertices that are *outside* of their range, which is quite bad, since this means that vertices outside of the bounding sphere are lit by it, and once the bounding sphere is no longer visible, these vertices suddenly turn black. I do set the D3DLIGHT9.Range parameter to the radius of the sphere, and still get this problem. But *why*? Also, I noticed some flickering even when the lights are in the frustum. I perform multipass lighting when more than 8 lights are visible (8 being the maximum of the card). Artificially setting the lights per pass to 1 solves this. But I'm not sure why. Here's some code:
// Set for first pass
blending(false);
zwrite(true);
blendfunc(video::BlendFunc_One,video::BlendFunc_One);

// Setting lightsperpass to 1 solves the problem, but is less efficient
uint32 lightsperpass=videodevice()->fixedMaxLights();

for (uint32 l=0;l<lightlist.numLights();l+=lightsperpass) {
	uint32 numL=lightlist.numLights()-l;
	if (numL>lightsperpass) numL=lightsperpass;

	for (uint32 j=0;j<lightsperpass;++j) {
		if (j<numL) {
			video::FFLightProperties fflprops;

			const Light *pLight=lightlist.light(l+j);
			fflprops.m_Position=pLight->transform().position();
			fflprops.m_Direction=pLight->direction();
			fflprops.m_Color=pLight->color();
			fflprops.m_ConstantAttenuation=pLight->constantAttenuation();
			fflprops.m_LinearAttenuation=pLight->linearAttenuation();
			fflprops.m_QuadraticAttenuation=pLight->quadraticAttenuation();
			fflprops.m_Range=pLight->range();
			fflprops.m_Lighttype=pLight->lighttype();
			fflprops.m_Falloff=pLight->falloff();
			fflprops.m_InnerConeAngle=pLight->innerConeAngle();
			fflprops.m_OuterAngle=pLight->outerAngle();
			
			fixedSetLightEnabled(j,true);
			fixedSetLightProperties(j,fflprops);

		} else fixedSetLightEnabled(j,false);
	}

	drawIndexedPrimitives(
		primitivestype(),vertexstream(),indexstream(),
		indexOffset(),numElements());

	if ((l==0) && (lightlist.numLights()>lightsperpass)) {
		blending(true);
		zwrite(false);
	}

}

if (lightlist.numLights()>lightsperpass) {
	blending(false);
	zwrite(true);
}

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!