LMGUI - another free lightmapper, with LMTS export

A forum to store posts deemed exceptionally wise and useful
puh
Posts: 356
Joined: Tue Aug 26, 2003 3:53 pm

LMGUI - another free lightmapper, with LMTS export

Post by puh »

Hello,

I have found pretty nice free application called LMGUI which is front end for Pulsar LMTools. So far i have pretty nice results with it:
here is screenshot of the app itself:

Image

and here is lmts model loaded into Irrlicht:

Image

I have to tweak lmts file though - it seems app write additional chunk of data into "MATI" block - so i just opened the file in HEX editor and deleted all from "MATI" untill "TEXT". Then file loaded just nice.

I modeled the scene in Blender, then exported to 3ds and opened it in LMGUI. Then added lights and created lightmaps.

I used the app from both original site

http://fig.emperion-empire.com/nav.php? ... cene/lmgui

and from

http://userlink.ru/glscene/download.php?view.58

and only last one is seems bugs-free to me...

Thank you, Fig for such great free tool!

Hope this could be usefull for Irr community as well...
Virion
Competition winner
Posts: 2148
Joined: Mon Dec 18, 2006 5:04 am

Post by Virion »

does it work when got transparency on my textures? can i still remain the transparent part and attach the light map?
frostysnowman
Posts: 83
Joined: Fri Apr 11, 2008 3:06 am
Location: Beaverton, Oregon, US

Post by frostysnowman »

Virion wrote:does it work when got transparency on my textures? can i still remain the transparent part and attach the light map?
+ Quality Settings
--------------------------------------------------------------------

A - Enable alpha channel

When you enable alpha channel processing; when a ray of light
colides against a polygon, LMGen checks the color of the
texel (texture's pixel) that the ray hits. If the alpha channel
of that texel has;
- 100% opacity, the ray stops. (a shadow is projected)
- 0% opacity, the ray passes trhough the polygon.
- otherwise, the ray color and intensity are modified
according to the texel values.

Only enable alpha channel if you need it.

F - Disable lightmap filtering.

The lightmaps are filtered using a 3x3 average filter.

Disabling this is always a bad idea; lightmaps are better
with it.

H - Enable hight quality shadows (oversample).

LMGen uses 4 rays for each lumel instead of one; so takes more
time, but the lightmaps are nicest.

Use this (at least) the last time that you create the lightmaps
for your maps.

S - Disable shadows.

The rays of light will not collide agains the 3D world.

Very fast, but lightmaps without shadows are very poor.

Note: alpha channel will not be used if shadow casting is
disabled.
From LMGen.txt in "Pulsar LMTools\bin"

EDIT: Oh, but if you mean in Irrlicht if it has built-in support for transparency + lightmap- the answer is no. There is no material type that can have transparency and lightmapping. But, it looks like someone made this material type for D3D9.
puh
Posts: 356
Joined: Tue Aug 26, 2003 3:53 pm

Modified CLMTSMeshFileLoader.cpp

Post by puh »

To load lmts files generated in LMGUI you have to slightly modify 2 functions in CLMTSMeshFileLoader.cpp:

Code: Select all

IAnimatedMesh* CLMTSMeshFileLoader::createMesh(io::IReadFile* file)
{
	u32 i;
	u32 id;

	// HEADER

	file->read(&Header, sizeof(SLMTSHeader));
	if (Header.MagicID != 0x53544D4C) { // "LMTS"
		os::Printer::log("LMTS ERROR: wrong header magic id!", ELL_ERROR);
		return 0;
	}

   //Skip any User Data (this is caused by additional chunk of data called MATI)
    
   s32 UserSize = Header.HeaderSize - sizeof(SLMTSHeader);
   if (UserSize>0) {
      file->seek(UserSize,true);
   }

	// TEXTURES

	file->read(&id, sizeof(u32));
	if (id != 0x54584554) { // "TEXT"
		os::Printer::log("LMTS ERROR: wrong texture magic id!", ELL_ERROR);
		return 0;
	}

	Textures = new SLMTSTextureInfoEntry[Header.TextureCount];
	core::array<u32> textureIDs;
	textureIDs.reallocate(Header.TextureCount);

	u32 numLightMaps = 0;
	u32 numTextures = 0;

	for (i=0; i<Header.TextureCount; ++i)
	{
		file->read(&Textures[i], sizeof(SLMTSTextureInfoEntry));
		if (Textures[i].Flags & 1)
			textureIDs.push_back(numLightMaps++);
		else
			textureIDs.push_back(numTextures++);
	}

	// SUBSETS

	file->read(&id, sizeof(u32));
	if (id != 0x53425553) // "SUBS"
	{
		os::Printer::log("LMTS ERROR: wrong subset magic id!", ELL_ERROR);
		cleanup();
		return 0;
	}

	Subsets = new SLMTSSubsetInfoEntry[Header.SubsetCount];

	for (i=0; i<Header.SubsetCount; ++i)
		file->read(&Subsets[i], sizeof(SLMTSSubsetInfoEntry));

	// TRIANGLES

	file->read(&id, sizeof(u32));
	if (id != 0x53495254) // "TRIS"
	{
		os::Printer::log("LMTS ERROR: wrong triangle magic id!", ELL_ERROR);
		cleanup();
		return 0;
	}

	Triangles = new SLMTSTriangleDataEntry[(Header.TriangleCount*3)];

	for (i=0; i<(Header.TriangleCount*3); ++i)
		file->read(&Triangles[i], sizeof(SLMTSTriangleDataEntry));

	/////////////////////////////////////////////////////////////////

	SMesh* mesh = new SMesh();

	constructMesh(mesh);

	loadTextures(mesh, numLightMaps, numTextures, textureIDs);

	cleanup();

	SAnimatedMesh* am = new SAnimatedMesh();
	am->Type = EAMT_LMTS; // not unknown to irrlicht anymore

	am->addMesh(mesh);
	am->recalculateBoundingBox();
	mesh->drop();
	return am;
}
and

Code: Select all

void CLMTSMeshFileLoader::loadTextures(SMesh* mesh, u32 numTextures, u32 numLightMaps, const core::array<u32>& textureIDs)
{
	if (!Driver || !FileSystem)
		return;

	core::stringc s;

	// load textures

	core::array<video::ITexture*> tex;
	tex.set_used(numTextures);

	core::array<video::ITexture*> lig;
	lig.set_used(numLightMaps);

	s32 tx_count = 0;
	s32 lm_count = 0;

	const core::stringc Path = Parameters->getAttributeAsString(LMTS_TEXTURE_PATH);

	s32 extpos;
	core::stringc fname,ext;

	for (s32 t=0; t<Header.TextureCount; ++t)
	{
		video::ITexture* tmptex = 0;

		fname =Textures[t].Filename;
		extpos = fname.findLast('.');
		fname =fname.subString(0,extpos);
		for (s32 i=0; i<3; i++)
                {
                    switch (i)
                    {
                        case 0: ext = ".png";break;
                        case 1: ext = ".jpg";break;
                        case 2: ext = ".tga";break;
                        //case 3: ext = ".bmp";break;
                        //case 4: ext = ".pcx";break;
                        //case 5: ext = ".psd";break;
                    }
                    s = Path;
                    s.append(fname);
                    s.append(ext);
                    //s.append(Textures[t].Filename);
                    if (FileSystem->existFile(s.c_str()))
                        break;
                }

		if (FileSystem->existFile(s.c_str()))
			tmptex = Driver->getTexture(s.c_str());
		else
		{
			char buf[512]; // filenames may be 256 bytes long
			sprintf(buf, "LMTS WARNING: Texture does not exist: %s", s.c_str());
			os::Printer::log(buf, ELL_WARNING);
		}

		if (Textures[t].Flags & 1)
			lig[lm_count++] = tmptex;
		else
			tex[tx_count++] = tmptex;
	}

	// attach textures to materials.

	for (s32 i=0; i<Header.SubsetCount; ++i)
	{
		if (Subsets[i].TextID1 < Header.TextureCount)
			mesh->getMeshBuffer(i)->getMaterial().setTexture(0, tex[textureIDs[Subsets[i].TextID1]]);
		if (Subsets[i].TextID2 < Header.TextureCount)
			mesh->getMeshBuffer(i)->getMaterial().setTexture(1, lig[textureIDs[Subsets[i].TextID2]]);

		if (!mesh->getMeshBuffer(i)->getMaterial().getTexture(1))
			mesh->getMeshBuffer(i)->getMaterial().MaterialType = video::EMT_SOLID;
	}
}
the last code is for loading any type of images, not only tga.

I think this could be added to IrrlichtSVN ?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Well, the first part is no problem, already commited. The file extension stuff seems unnecessary, though, because the file format doesn't require a fixed extension. Simply use a different texture name instead...
fmx

Post by fmx »

thanks puh for pointing out this lightmapping and thanks for commiting it so soon hybrid.

alternatives to irrEdit always welcome!
:)
puh
Posts: 356
Joined: Tue Aug 26, 2003 3:53 pm

Post by puh »

EDITED: all links updated, now from googlepages

Thank you, hybrid and fmx

I want to add: LMGUI only exports all textures into tga, thats why Fig added the code for finding other extensions. Textures in tga are too huge for me, i always convert them to png/jpg (or simply use initial textures provided with 3ds file before importing to LMGUI)... Well, at first i changed final lmts files with hex-editor to change texture extension...

Anyway, right now i cant get any lmts file loaded into svn version of irrlicht. Anyone could confirm the problem? (i cant debug here, but noone renderer works - all crashed at the different points)

Please check Sample map.zip (1,516 KB), consists of 3 version:
1. map-orig.zip - initial map by Lord Trancos
2. lmgui-orig-map.zip - map exported from LMGUI
3. lmgui-map.zip - map exported from LMGUI but all textures converted from TGA to PNG/JPG (in case you want to check second code work)

And it seems Fig, original coder of LMGUI, is disappeared as well as his web-site, so i upload Fig's sent to me some time ago version of LMGUI v.0.2r1.1 (656 KB), where it is possible to select exported texture format (Bitmap, Targa, DDS, JPG) and other small fixes.

I want to mention, that official lmtools are not working with curved surfaces, but could work with alpha textures, as in this screenshot:

Image

In last e-mail Fig wrote that he made his own lightmapper:
I wrote my own lightmapper though that I planned to integrate into LMGUI, so there would be 3 supported lightmap engines. My lightmapper works pretty well as you can see from these images.

http://img264.imageshack.us/img264/2486/test2eq6.jpg
http://img125.imageshack.us/img125/5161/cartexqd2.jpg
http://img179.imageshack.us/img179/8875 ... xednk5.jpg
http://img167.imageshack.us/img167/7909/comparenm5.jpg
I still hope he will answer once and we could test his lighmapper 8)
Last edited by puh on Sun Nov 09, 2008 8:13 am, edited 3 times in total.
puh
Posts: 356
Joined: Tue Aug 26, 2003 3:53 pm

Post by puh »

Here is my last presentation lightmapped with LMGUI:
(If you want i can upload demo and source code, but its all Irrlicht 0.12 ;) )
Image
Last edited by puh on Sun Nov 09, 2008 8:11 am, edited 2 times in total.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Could you please upload your files somewhere else? I seem to be unable to download from 2shared...
Lambda
Posts: 126
Joined: Wed Feb 27, 2008 3:00 pm
Location: Spain, Huelva
Contact:

Post by Lambda »

hybrid wrote:Could you please upload your files somewhere else? I seem to be unable to download from 2shared...
i have uploaded it to rapidshare.

http://rapidshare.com/files/162028960/S ... p.zip.html

try to download from rapidshare :)
Image
puh
Posts: 356
Joined: Tue Aug 26, 2003 3:53 pm

Post by puh »

all links updated, now from googlepages
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Ok, the loader will be fixed very soon, just have to fix a strange texture loading problem I don't fully understand. But all other LMTS problems are resolved then.
puh
Posts: 356
Joined: Tue Aug 26, 2003 3:53 pm

Post by puh »

Thanks, hybrid, all works now.

BTW, why lmts looks so white in BurningsVideo driver?

BurningsVideo:
Image
OpenGL
Image
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Looks like some color values are not properly clamped, so the lightmap saturates the colors. You might want to submit a bug ticket...
burningreggae
Posts: 66
Joined: Wed Oct 04, 2006 2:07 pm

Post by burningreggae »

identified

use EMT_LIGHTMAP_2 or EMT_LIGHTMAP_4 for now, until solved.
burningreggae
Post Reply