lightmap query

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.
Post Reply
lostpencil
Posts: 17
Joined: Fri Dec 16, 2005 5:46 pm
Contact:

lightmap query

Post by lostpencil »

Hello Folks,

I'm trying to get a model from 3ds max 8 to Irrlicht and the result is a black character. I modeled the character in Max, lit the character and then I renderd to textures and created a lightmap (called Box01LightingMap.tga). The character has a diffuse texture for color. I exported out the model using Panda X exporter (I also tried a Max 8 version of the my3d plugin exporter - the results are the same). I understand that the Lightmap is supposed to be on the second layer of a texture. I'm not sure if I have the code right for this - I'm assuming layer 0 is the first texture and layer 1 is the next texture. Do I have that right?

Here is the code I'm using:

Code: Select all

scene::IAnimatedMesh* mesh2 = smgr->getMesh("../../../media/test.x");
scene::IAnimatedMeshSceneNode* node5 = smgr->addAnimatedMeshSceneNode( mesh2 );
node5->setPosition(core::vector3df(0,100,0));

node5->setMaterialTexture( 0, driver->getTexture("../../../media/Box01DiffuseMap.tga") );
node5->setMaterialTexture( 1, driver->getTexture("../../../media/Lightmaps/Box01LightingMap.tga") );		
node5->setMaterialFlag(video::EMF_LIGHTING, false);
node5->setMaterialType(video::EMT_LIGHTMAP);
<edit: removed image links>

The same thing happens when I use My3d (either exporting out the model with the builtin textures or separate textures. If I use the builtin textures I don't do the setMaterialTexture calls in the code above).

Suggestions?
Last edited by lostpencil on Fri Dec 16, 2005 8:56 pm, edited 1 time in total.
Cheers,
Paul Mikulecky
Lost Pencil Animation Studios Inc.
http://www.lostpencil.com

"The art of character animation is to try
to catch lightning in a bottle.... one volt
at a time." Brad Bird
lostpencil
Posts: 17
Joined: Fri Dec 16, 2005 5:46 pm
Contact:

Post by lostpencil »

I figured it out. Thanks for looking.

It appears that you have to have 'Automatic Flatten UVs' selected when rendering to texture.
Cheers,
Paul Mikulecky
Lost Pencil Animation Studios Inc.
http://www.lostpencil.com

"The art of character animation is to try
to catch lightning in a bottle.... one volt
at a time." Brad Bird
lostpencil
Posts: 17
Joined: Fri Dec 16, 2005 5:46 pm
Contact:

Post by lostpencil »

Me again. So that works fine for my3d objects. Any tips on using obj or x files? They still exhibit the same behavior.
Cheers,
Paul Mikulecky
Lost Pencil Animation Studios Inc.
http://www.lostpencil.com

"The art of character animation is to try
to catch lightning in a bottle.... one volt
at a time." Brad Bird
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

you might have to use the mesh manipulator to convert them to meshes with 2 sets of texture coords, it will probably break animation tho
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
lostpencil
Posts: 17
Joined: Fri Dec 16, 2005 5:46 pm
Contact:

Post by lostpencil »

Hi Bitplane,

Thanks very much for the reply. After some more experimentation I've discovered that I can generate 2 UV maps in Max. I can verify this by using Map Channel Info in Max. I also checked my material for the object and I have a multi/sub-object material where material 0 is the diffuse color map, material 1 is the lightmap. My modifier stack looks like this:

Material (set material to 2)
Poly Select (select all polygons)
Automatic Flatten UVs (UV map generated by render to texture)
Unwrap UVW (my original UV map for diffuse)
Editable poly (original mesh)

When I export the .x file, I can view it in the DirectX viewer. But what happens is that it displays the lightmap as a diffuse texture (since it is the second texture in the list), but with the incorrect UV mapping. I suspect .x can't contain more than one UV map.

So I collapsed my stack to look like this:

Material (set material to 2)
Poly Select (select all polygons)
Unwrap UVW (my original UV map for diffuse)
Editable poly (original mesh)

Now the DirectX viewer displays the Lightmap as a texture, properly UV mapped because I had another Lightmap I created using Render to Texture that did not use Automatic Unwrap (and hence it could use the diffuse color's UV map).

As expected, the model loads in Irrlicht displaying the Lightmap as the diffuse texture. The console says that both textures have been loaded. If I check the .x file in wordpad it contains both texture definitions.

Now I'm trying to figure out why Irrlicht isn't using the first texture as a diffuse and the second as a Lightmap. I suspect because the .x mesh importer isn't smart enough (like the my3d importer). But I have yet to verify this... I had assumed that if my mesh loads with two textures and if I call setMaterialType(EMT_LIGHTMAP), then it would do this for me - apparently not.

Anyway, any other suggestions?
Cheers,
Paul Mikulecky
Lost Pencil Animation Studios Inc.
http://www.lostpencil.com

"The art of character animation is to try
to catch lightning in a bottle.... one volt
at a time." Brad Bird
Pazystamo
Posts: 115
Joined: Sat Dec 03, 2005 5:56 pm
Location: Lithuania
Contact:

Post by Pazystamo »

maybe you see second texture because first is under it? it uses 2 textures, but i think when you set diferent textures on diferent faces, only then both will be visible.Sure it wont help with lightmaps...
Or if you set second texture alpha leyer say to 50% then maybe both will be visible...
lostpencil
Posts: 17
Joined: Fri Dec 16, 2005 5:46 pm
Contact:

Post by lostpencil »

Hey Pazystamo,

Yes, I think that is what is happening. I was hoping that by setting the mesh's material type to EMT_LIGHTMAP that it would use the second one as a lightmap instead of simply overlaying the two. I've started looking at the my3d importer and the x importer and it looks like the my3d version is doing extra with lightmaps that the x version isn't.
Cheers,
Paul Mikulecky
Lost Pencil Animation Studios Inc.
http://www.lostpencil.com

"The art of character animation is to try
to catch lightning in a bottle.... one volt
at a time." Brad Bird
Post Reply