Adding a bump map to an animated scene node?

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
agamemnus
Posts: 283
Joined: Sun Jan 31, 2010 6:06 pm

Adding a bump map to an animated scene node?

Post 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;
} 
Last edited by agamemnus on Sun Mar 13, 2011 9:19 pm, edited 3 times in total.
Iyad
Posts: 140
Joined: Sat Mar 07, 2009 1:18 am
Location: Montreal, Canada

Post 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.
#include <Iyad.h>
agamemnus
Posts: 283
Joined: Sun Jan 31, 2010 6:06 pm

Post by agamemnus »

Hence smgr->getMeshManipulator()->createMeshWithTangents( node->getMesh()->getMesh(0));

:D
Iyad
Posts: 140
Joined: Sat Mar 07, 2009 1:18 am
Location: Montreal, Canada

Post 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
#include <Iyad.h>
agamemnus
Posts: 283
Joined: Sun Jan 31, 2010 6:06 pm

Post 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...)
shadowslair
Posts: 758
Joined: Mon Mar 31, 2008 3:32 pm
Location: Bulgaria

Post 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.
"Although we walk on the ground and step in the mud... our dreams and endeavors reach the immense skies..."
agamemnus
Posts: 283
Joined: Sun Jan 31, 2010 6:06 pm

Post by agamemnus »

It's an animated mesh scene node with 1 frame. Can anyone just please tell me how to fix my code?
Radikalizm
Posts: 1215
Joined: Tue Jan 09, 2007 7:03 pm
Location: Leuven, Belgium

Post 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?
agamemnus
Posts: 283
Joined: Sun Jan 31, 2010 6:06 pm

Post 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.
agamemnus
Posts: 283
Joined: Sun Jan 31, 2010 6:06 pm

Post by agamemnus »

I'm going to shelve this method for now and try moving textures.
Post Reply