Lightmapped terrain: The quick and dirty q3map 2.0.x how-to.

Note: lightmapped terrain is a hack, and as such, has limitations. It cannot be environment mapped, or have any effect that requires a surface normal. Such is life unless Id makes a PR to support it.


Before you make ANY terrain with q3map 2.0.x or higher, your terrain shaders (typically textures/common/terrain and terrain2) must have the "q3map_terrain" keyword. Terrain is handled completely differently than from previous versions of q3map, and as such, it doesn't have any built-in shader name mangling for terrain entities.


The terrain shader MUST BE LISTED IN SHADERLIST.TXT or this will NOT WORK.


Use the following crib sheet to convert a typical terrain shader into lightmapped terrain:


// old-style vertex lit terrain shader

textures/terrain/hillside_0
{
	q3map_forcesunlight
	q3map_novertexshadows
	surfaceparm nolightmap
	
	{
		map textures/terrain/hillside_0.tga
		tcMod scale 0.05 0.05
		rgbGen vertex
	}
}



// lightmapped terrain shader

textures/terrain/hillside_0
{
	q3map_lightmapsamplesize 64
	q3map_lightmapaxis z
	q3map_texturesize 256 256
	q3map_tcGen ivector ( 256 0 0 ) ( 0 256 0 )
	
	{
		map textures/terrain/hillside_0.tga
	}
	{
		map $lightmap
		blendFunc GL_DST_COLOR GL_ZERO
	}
}




// lightmapped terrain shader for blending between two layers

textures/terrain/hillside_0to1
{
	q3map_lightmapsamplesize 64
	q3map_lightmapaxis z
	q3map_texturesize 256 256
	q3map_tcGen ivector ( 256 0 0 ) ( 0 256 0 )
	
	{
		map textures/terrain/hillside_0.tga
	}
	{
		map textures/terrain/hillside_1.tga
		blendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
		alphaGen vertex
	}
	{
		map $lightmap
		blendFunc GL_DST_COLOR GL_ZERO
	}
}




