Lightmaps have only one color

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Bersi
Posts: 53
Joined: Tue Sep 04, 2007 8:23 pm

Lightmaps have only one color

Post by Bersi »

Hi, I have created a small tool to create my own lightmaps for my own map format. The created lightmap textures look good but when I load this textures and add it as a lightmap the whole texture is lighted by the same color.

Example:

A lightmap for a piece of wall is blue on the left side and becomes more green every pixel to the right. When I use the lightmap on a texture, the texture is lighted only with the same blue.


The lightmap is smaller then the texture and I use a different color format:

Texture: 64x96 Pixels, A8R8G8B8
Lightmap: 8x12 Pixels, R8G8B8

Is this the problem?


I have added the lightmap texture to the material as the second material texture (index 1) and the normal texture as index 0. The material type is EMT_LIGHTMAP.


Here you can see what I mean:

Image


On this picture you can see 4 pieces of a wall with the same base texture and 4 different lightmaps. The lightmaps are all colored in one color but the texture of the lightmap isn't.

Thanks for help.
Bersi
Posts: 53
Joined: Tue Sep 04, 2007 8:23 pm

Post by Bersi »

No idea? Here is the code for adding the lightmap texture:

Code: Select all

irr::video::ITexture* TextureManager::AddLightmapTexture(word Index, word Width, word Height, byte* PixelData)
	{
		irr::video::IImage* Image = irrVideoDriver->createImageFromData(irr::video::ECF_R8G8B8, irr::core::dimension2d<irr::s32>(Width, Height), PixelData, false, false);

		if(Image)
		{
			char LightmapName[16];
			sprintf(LightmapName, "Lightmap%04d", Index);

			irr::video::ITexture* Texture = irrVideoDriver->addTexture(LightmapName, Image);

			if(Texture)
			{
				Image->drop();
				return Texture;
			}

			Image->drop();
		}

		return 0;
	}

PixelData is a static array of bytes containing the pixel data in R8G8B8 format.
Bersi
Posts: 53
Joined: Tue Sep 04, 2007 8:23 pm

Post by Bersi »

Can someone answer please? :(
Bersi
Posts: 53
Joined: Tue Sep 04, 2007 8:23 pm

Post by Bersi »

Is it possible that the lightmap is scaled wrong and I have to scale it to fit it to the base texture? Seems that nobody used lightmaps in the irrlicht forums before. :roll:
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Post by greenya »

I can check if you like.
But please, ZIP small example with main.cpp, diffuseMap and lightMap that you using -- so i can test it.

p.s.: possible it is a driver bug, so it is good practice to check any visual artifact on more that one machine.

p.p.s.: you can use http://filebeam.com/ to share the ZIP.
Bersi
Posts: 53
Joined: Tue Sep 04, 2007 8:23 pm

Post by Bersi »

Thanks but unfortunately my program consists of about 50 files and it's impossible to extract only a few files (own file manager, package manager, graphic manager and so on). But perhaps I can test it on the computer of my girlfriend.

The question is: Is it a bug or is there a mistake in my code?
Bersi
Posts: 53
Joined: Tue Sep 04, 2007 8:23 pm

Post by Bersi »

Tested it on the computer of my girlfriend which has a much better and newer graphics adapter. The colors are a little bit different but the same problem occurs. Each quad has a lightmap which consists of one color.
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Post by greenya »

1. if you using OpenGL -- you must use textures with sizes of power of 2, if you use direct x -- it is not a "must" but it is a good practice.

it is better to change texture coordinates of vertices so part of the textures not used at all then using non power of 2 sized textures.

2. if you cannot give an example-project -- please, supply your maps (diffuseMap and lightMap).
Bersi
Posts: 53
Joined: Tue Sep 04, 2007 8:23 pm

Post by Bersi »

1. Yes I know but the basic textures are also non-power-of-two textures and work fine. I have testet some texture sizes. Important are only dimensions that are multiples of 4. I use DirectX9 btw.

2. As I said before the lightmap textures are ok. I have saved them as bitmaps and checked the colors. With lightmap textures I mean the color data and dimensions of the texture. It is also possible that the texture creation is the bad boy. I don't know if lightmaps should have an alpha channel or some important properities. At this time they are only RGB-Textures which represents the overlay colors for the texture. 1 Pixel in the lightmap should be 8x8 Pixels on the texture. Or should lightmaps have the same size than the textures?
Bersi
Posts: 53
Joined: Tue Sep 04, 2007 8:23 pm

Post by Bersi »

The problem seems to be the format a lightmap is used by irrlicht. I have tried A8R8G8B8 and add one 0xFF-Byte to every color-triple. Nothing changed, so it was the alpha byte.

Then I changed a few bytes in the middle of the data and nothing changed in the game.

But when I change the first 4 bytes to 0xFFFFFFFF (white) there is no white lightmap but the blue light appears more brighten on the walls. This is confusing me. How a lightmap texture should be passed to the irrlicht engine? How should it's data look like?


Next confusing thing is that textures which haven't got a lightmap will be white when I set the first 4 bytes to white in another lightmap.

When I pick a green color for the first 4 bytes the texture will be green but with blue light upon it (when there is blue light next to the quad). I don't understand this.
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Post by greenya »

I have played a bit and i guess it is a bug of Direct3D renderer.
Here i posted it -- http://irrlicht.sourceforge.net/phpBB2/ ... p?p=145313
Bersi
Posts: 53
Joined: Tue Sep 04, 2007 8:23 pm

Post by Bersi »

I don't think this is the problem because with OpenGL I get the same results and I can see the lightmap but only the first pixel seems to be the color for the whole lightmap texture.

I found the following line in the irrlicht code:

Code: Select all

pID3DDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1);

Looked like this means that only the first pixel is used for modulation but when I comment this out I get the same results.
Xenxe
Posts: 43
Joined: Sat Jan 26, 2008 9:54 pm
Location: U.S.A. Wasington

Post by Xenxe »

yeah and lightmaps work for me and i use DX
who else here is 14?
But confused about many things.
(\__/)
(='.'=) world domination!!!
(")_(")
Bersi
Posts: 53
Joined: Tue Sep 04, 2007 8:23 pm

Post by Bersi »

Maybe it's a bug in version 1.3.1 because I use it.
Bersi
Posts: 53
Joined: Tue Sep 04, 2007 8:23 pm

Post by Bersi »

I found out that all 4 corners of the image produce the lightmap-color. 4 black corners result in a fully black lightmap. 2 red and 2 green corners result in a fully yellow lightmap. The rest of the lightmap texture doesn't change anything.

I use drawIndexedTriangleList btw.
Post Reply