Game Development Community

Lighting Textures Leave Out-of-bounds Artifacts

by Jeff Faust · in Torque Game Engine Advanced · 04/23/2007 (9:47 am) · 2 replies

Observe this image with 5 sgLightObjects (the 5 lights make it more obvious, but just 1 is enough to produce the artifacts):
www.arcane-fx.com/visuals/forums_pics/criss_cross_lines.jpgThe lines that criss-cross to form a star pattern are artifacts that shouldn't be there.

Terrain lighting makes use of a procedurally created texture which is rendered using a texture address mode of GFXAddressClamp. This means that UV values outside the 0.0-1.0 range are clamped to 0.0 or 1.0. The resulting artifacts indicate that there are some non-zero border pixels in the procedurally created lighting texture and their values are repeated outside the lighting area.

In this particular case the problematic texture is created using sgLightingModel::sgGenerateDynamicLightingTexture() in sgLightingModel.cc. Presumably the texture created runs up too close to the edge of the texture. I don't recommend this as a general fix, but I was able to prevent the problem in the test case by making this change (in bold) in sgGenerateDynamicLightingTexture() .
// get the basics...
	F32 dist = sgGetMaxRadius(true)[b]*1.1[/b];
	Point3F halfamount(SG_DYNAMIC_LIGHTING_TEXTURE_HALFSIZE,
		SG_DYNAMIC_LIGHTING_TEXTURE_HALFSIZE, SG_DYNAMIC_LIGHTING_TEXTURE_HALFSIZE);
	Point3F invhalfamount(1 / SG_DYNAMIC_LIGHTING_TEXTURE_HALFSIZE,
		1 / SG_DYNAMIC_LIGHTING_TEXTURE_HALFSIZE, 1 / SG_DYNAMIC_LIGHTING_TEXTURE_HALFSIZE);
	Point3F radiusdist(dist, dist, dist);
This change causes the image of the texture to be drawn a little smaller so that it doesn't reach all the way to the texture edge. Ideally, this needs to be tuned to the size of the texture.

Another possible fix might be to change the texture address mode to GFXAddressBorder when rendering these. However, GFXAddressBorder capability may be slightly less universally available on cards than GFXAddressClamp.

About the author

Jeff Faust creates special effects indie middleware and games for Faust Logic. --- Blog: Effectronica.com --- Twitter: @FaustLogic


#1
04/23/2007 (11:29 am)
Yup, the dynamic lighting system was designed and developed using border filtering - it was only during compatibility testing towards the end that we realized how poorly supported that mode is, and had to switch to clamp. This caused a few unexpected problems that need to be addressed.
#2
04/23/2007 (1:10 pm)
Aren't those lighting textures generated by the engine itself based on the lighting model settings?

Maybe modifying their code a bit so they are drawn inside the 1 pixel border can fix the issue.