normal maps problem

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
TeTine
Posts: 17
Joined: Tue Nov 13, 2007 10:36 pm
Location: Nantes, France
Contact:

normal maps problem

Post by TeTine »

Hi,
I tried to aplly a normal map to a model I exported in .x from blender but when I try to render the object with the normal map I obtain messed up results:
[img=http://img410.imageshack.us/img410/222/sanstitregs2.th.jpg]
When I move the camera, the normal information seems to slide over the mesh (you can see the eye below its actual place)
I saw somewhere that when a normal map is rendered with an inappropriate coordinate system, it can cause this kind of bug but in blender 2.45 there's only one way to bake normal map so I don't really know what it means.

since this normal map would greatly improve the visual quality of my model, any help or suggestion will be greatly appreciated :roll:
Irrlicht noob =p
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Please show the full code. Also check example 11, there are all necessary steps explained in detail.
Praetor
Posts: 42
Joined: Wed Jun 20, 2007 2:31 am

Post by Praetor »

Without seeing the code my best guess would be that you didn't generate tangents for the mesh, look at tutorial 11, like hybrid said, for a full example.
"Surely we don’t need to waste resources on pathfinding; they just need to walk along the shortest route from one place to another." - EA Producer
TeTine
Posts: 17
Joined: Tue Nov 13, 2007 10:36 pm
Location: Nantes, France
Contact:

Post by TeTine »

I did try to make a tangent mesh like the tutorial but the result is even worse :
[img=http://img129.imageshack.us/img129/5297/sanstitrehi8.th.jpg]

Here is the code (I removed some part of it, not important for normal mapping):

Code: Select all

#include <irrlicht.h>
#include <iostream>

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

#pragma comment(lib, "Irrlicht.lib")

IMeshSceneNode* fixednode = 0;
IrrlichtDevice *device = 0;


int main(void)
{

	device = createDevice(EDT_OPENGL,
	dimension2d<s32>(1024, 768), 16,	false, false, false, &receiver);
	device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");

	IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->getSceneManager();
	IGUIEnvironment* guienv = device->getGUIEnvironment();

	guienv->addStaticText(L"test import .x", rect<int>(10,10,200,22), true);
	
	IAnimatedMesh* mesh = smgr->getMesh("../model/mycharacter.x");

	driver->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT, true);

	scene::IMesh* tangentMesh = smgr->getMeshManipulator()->createMeshWithTangents(mesh->getMesh(0));
	fixednode = smgr->addMeshSceneNode(tangentMesh);
	fixednode->setMaterialTexture(1, driver->getTexture("../model/normals2.png"));
	if (fixednode)
	{
		fixednode->setMaterialFlag(EMF_LIGHTING, true);
		fixednode->setMaterialFlag(EMF_BACK_FACE_CULLING, false);
		fixednode->setMaterialType(video::EMT_PARALLAX_MAP_SOLID); 
	}

	ILightSceneNode *light = smgr->addLightSceneNode(0, vector3df(0,0,50), SColorf(0.5f, 0.5f, 0.5f, 0.1f), 600.0f);
	ISceneNodeAnimator* anim = smgr->createFlyCircleAnimator(vector3df(0,-40,50), 20.0f);
	light->addAnimator(anim);
	anim->drop();
	light = smgr->addLightSceneNode(0, vector3df(0,40,0), SColorf(0.2f, 0.2f, 0.2f, 0.1f), 600.0f);

	ICameraSceneNode *camera = smgr->addCameraSceneNodeMaya(NULL, -100.0f, 100.0f, 100.0f);
	camera->setFOV(PI/10.0f);

	while(device->run())
	{

		driver->beginScene(true, true, 0);
		smgr->drawAll();
		guienv->drawAll();
		driver->endScene();
	}
	device->drop();
	return 0;
}
I'll try to do this with a very simple mesh, just in case...
Irrlicht noob =p
TeTine
Posts: 17
Joined: Tue Nov 13, 2007 10:36 pm
Location: Nantes, France
Contact:

Post by TeTine »

Ok I managed to make the normal map work... almost
now all the normals seem to be inverted and only the "hidden faces are rendered
I thought it was a problem with the export from blender but since the model is normal mapped I find it a bit weird
And even with backfaceculling disabled it doesn't work
I'll keep testing and showing some results just in case, as always
Irrlicht noob =p
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post by Halifax »

TeTine wrote:Ok I managed to make the normal map work... almost
now all the normals seem to be inverted and only the "hidden faces are rendered
I thought it was a problem with the export from blender but since the model is normal mapped I find it a bit weird
And even with backfaceculling disabled it doesn't work
I'll keep testing and showing some results just in case, as always
Are you sure your normals are right in Blender? You might want to jump back into the UV editor to see, or try an automated process: Ctrl+N (Recalculate normals outside). Be warned, that process doesn't work for everything, especially if your triangles weren't edited "cleanly". So your best bet is to flip the normals you need to manually. It is somewhere in the special menu: W. I think it might be W, 9 but I forget.
TheQuestion = 2B || !2B
TeTine
Posts: 17
Joined: Tue Nov 13, 2007 10:36 pm
Location: Nantes, France
Contact:

Post by TeTine »

Thanks for sharing the ideas Halifax, I managed to have my mesh look decent in irrlicht without normal maps (even if I have to put a real mess in blender to make it work =p )
i 'll leave normal mapping for later and I'll try to make some more tests when I have time

ciao
Irrlicht noob =p
Post Reply