Page 1 of 1

Adding a bump map to an animated scene node?

Posted: Sun Mar 13, 2011 12:52 am
by agamemnus
Tutorial 11 shows how to add a bump map to a regular scene node, but what is the best way to add a bump map to an animated scene node?

Here's my code:

Code: Select all

void IrrSetAndAddBumpMap (IAnimatedMeshSceneNode* node,  irr::video::ITexture* texture) {
 driver->makeNormalMapTexture (texture, 20.0f);
 node->setMaterialTexture (1, texture);
 node->setMaterialType (video::EMT_NORMAL_MAP_TRANSPARENT_VERTEX_ALPHA);
 IMesh* oldMesh = node->getMesh()->getMesh(0);
 IMesh* tangentMesh = smgr->getMeshManipulator()->createMeshWithTangents( node->getMesh()->getMesh(0));
 SAnimatedMesh* sanimmesh = new SAnimatedMesh;
 sanimmesh->addMesh(oldMesh);
 sanimmesh->addMesh(tangentMesh);
 node->setMesh(sanimmesh);
}
Edit: the following makes a black node. :shock:

Code: Select all

void IrrSetAndAddBumpMap (IAnimatedMeshSceneNode* node,  irr::video::ITexture* texture) {
 driver->makeNormalMapTexture (texture, 1.0f);
 irr::video::ITexture* oldTexture = node->getMaterial(0).getTexture(0);
 IMesh* tangentMesh = smgr->getMeshManipulator()->createMeshWithTangents(node->getMesh()->getMesh(0));
 SAnimatedMesh* sanimmesh = new SAnimatedMesh;
 sanimmesh->addMesh(tangentMesh);
 node->drop();
 node = smgr->addAnimatedMeshSceneNode(sanimmesh);
 node->setMaterialTexture (0, oldTexture);
 node->setMaterialTexture (1, texture);
 node->setMaterialType(video::EMT_NORMAL_MAP_SOLID);
 tangentMesh->drop();
}
Edit 2:
I almost entirely copied the tutorial code. All I get is a white rectangle.

Code: Select all

ISceneNode* IrrSetAndAddBumpMap () {
 scene::IAnimatedMesh* roomMesh = smgr->getMesh("models/rectangle.obj");
 scene::ISceneNode* room = 0;
 smgr->getMeshManipulator()->makePlanarTextureMapping(roomMesh->getMesh(0), 0.003f);
 video::ITexture* normalMap = driver->getTexture("models/common_textures/waterbump_0.png");
 driver->makeNormalMapTexture(normalMap, 9.0f);
 scene::IMesh* tangentMesh = smgr->getMeshManipulator()-> createMeshWithTangents(roomMesh->getMesh(0));
 room = smgr->addMeshSceneNode(tangentMesh);
 room->setMaterialTexture(0, driver->getTexture("models/common_textures/water.png"));
 room->setMaterialTexture(1, normalMap);
 room->getMaterial(0).SpecularColor.set(0,0,0,0);
 room->setMaterialFlag(video::EMF_FOG_ENABLE, true);
 room->setMaterialType(video::EMT_PARALLAX_MAP_SOLID);

 // adjust height for parallax effect
 room->getMaterial(0).MaterialTypeParam = 0.035f;

 // drop mesh because we created it with a create.. call.
 tangentMesh->drop();
 return room;
} 

Posted: Sun Mar 13, 2011 2:24 am
by Iyad
You need to use tangents for adding normal maps to animated mesh, check out the forum's code snippet section, i know that someone already wrote a shader for this.

Posted: Sun Mar 13, 2011 3:00 am
by agamemnus
Hence smgr->getMeshManipulator()->createMeshWithTangents( node->getMesh()->getMesh(0));

:D

Posted: Sun Mar 13, 2011 5:35 am
by Iyad
I mean, you should calculate the tangent mesh for every frame, then apply the normal map. This would not be efficient, check out this, it is using shaders : http://irrlicht.sourceforge.net/phpBB2/ ... mated+mesh

Posted: Sun Mar 13, 2011 9:00 am
by agamemnus
There's only one frame really.. it's not a lot. That shader looks nice, but I'd rather know how to do the simple case correctly.

Atm it isn't applying any bump maps at all and I am sure the shader one will be even harder to implement... if it even works. (my gfx card doesn't like complex shaders I guess...)

Posted: Sun Mar 13, 2011 11:06 am
by shadowslair
agamemnus wrote:There's only one frame really.. it's not a lot. That shader looks nice, but I'd rather know how to do the simple case correctly.
If you have only one frame, then your animated node is a static one and you can use IMeshSceneNode, so you`re free to use the build-in materials, but for anything more you don`t have many options despite to use shaders. Even the build-in materials use build-in shaders with very low shader models- 1.1 and 2.0 or sth. You need to calculate the tangent in realtime for the skinned and normalmapped meshes only.
agamemnus wrote:Atm it isn't applying any bump maps at all and I am sure the shader one will be even harder to implement... if it even works. (my gfx card doesn't like complex shaders I guess...)
Shaders are really easy, especially such a basic one. And I cannot think of a single reason why it may not work for you despite the a) you`re doing sth wrong b) your card is really an ancient one (over say 8 years old). If that`s the case, you cannot expect to use normalmapping or many other effects on that old gpu. A normalmapping shader is not complex for the gpu at all.

Posted: Sun Mar 13, 2011 6:06 pm
by agamemnus
It's an animated mesh scene node with 1 frame. Can anyone just please tell me how to fix my code?

Posted: Sun Mar 13, 2011 6:12 pm
by Radikalizm
agamemnus wrote:It's an animated mesh scene node with 1 frame. Can anyone just please tell me how to fix my code?
Shadowslair just did explain it, why use an animated mesh node when you're using a static mesh?

Posted: Sun Mar 13, 2011 7:06 pm
by agamemnus
Everything in my Irrlicht wrapper is set up around animated mesh scene nodes... so can anyone please tell me how to do it with animated mesh scene nodes with one frame? Pretty please? :(

My current code doesn't work and I don't know why. Can someone just look at the code.. I am sure something is not right. My gfx card does support bump maps.

Edit: tried the tutorial code... just switched the textures and models. No go.

Posted: Mon Mar 14, 2011 7:25 am
by agamemnus
I'm going to shelve this method for now and try moving textures.